source: trunk/MagicSoft/Mars/mmontecarlo/MMcThresholdCalc.cc@ 860

Last change on this file since 860 was 859, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 4.8 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Javier Lopez 05/2001 (jlopez@ifae.es)
19! Thomas Bretz 06/2001 (tbretz@uni-sw.gwdg.de)
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27// //
28// MMcThresholdCalc //
29// //
30// Input Containers: //
31// MMcEvt //
32// //
33// Output Containers: //
34// MMcTrig;*, MHMcEnergy;* //
35// //
36/////////////////////////////////////////////////////////////////////////////
37
38#include "MMcThresholdCalc.h"
39
40#include <math.h>
41
42#include "MParList.h"
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MMcEvt.hxx"
48#include "MMcTrig.hxx"
49
50#include "MHMcEnergy.h"
51
52ClassImp(MMcThresholdCalc)
53
54MMcThresholdCalc::MMcThresholdCalc(const UInt_t dim, const char* name,
55 const char* title) : fDimension(dim)
56{
57 *fName = name ? name : "MMcThresholdCalc";
58 *fTitle = title ? title : "Task to calculate the energy threshold from Monte Carlo";
59
60 fMcTrig = new MMcTrig*[fDimension];
61 fHMcEnergy = new MHMcEnergy*[fDimension];
62 fMustDelete = new Bool_t[fDimension];
63
64 for (unsigned int i=0; i<fDimension; i++)
65 fMustDelete[i]=kFALSE;
66}
67
68MMcThresholdCalc::~MMcThresholdCalc()
69{
70 for (unsigned int i=0; i<fDimension; i++)
71 if (fMustDelete[i])
72 delete fHMcEnergy[i];
73
74 delete fMcTrig;
75 delete fHMcEnergy;
76 delete fMustDelete;
77}
78
79Bool_t MMcThresholdCalc::PreProcess(MParList* pList)
80{
81 // connect Monte Carlo data with this task
82
83 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
84 if (!fMcEvt)
85 {
86 *fLog << dbginf << "MMcEvt not found... aborting." << endl;
87 return kFALSE;
88 }
89
90 char auxname[15]="MMcTrig"; // string to write container names
91
92 for (unsigned int i=0; i<fDimension; i++)
93 {
94 if (fDimension>1)
95 sprintf(auxname+7, ";%i", i+1);
96
97 fMcTrig[i] = (MMcTrig*)pList->FindObject(auxname);
98 if (fMcTrig[i])
99 continue;
100
101 *fLog << dbginf << "'MMcTrig";
102 if (fDimension>1)
103 *fLog << ";" << i+1;
104 *fLog << "' not found... aborting." << endl;
105
106 return kFALSE;
107 }
108
109 strcpy(auxname, "MHMcEnergy");
110 for (unsigned int i=0; i<fDimension; i++)
111 {
112 if (fDimension>1)
113 sprintf(auxname+10, ";%i", i+1);
114
115 fHMcEnergy[i] = (MHMcEnergy*)pList->FindObject(auxname);
116 if (fHMcEnergy[i])
117 continue;
118
119 *fLog << dbginf << "'" << auxname << "' not found in list... creating." << endl;
120
121 fHMcEnergy[i] = new MHMcEnergy(fDimension>1 ? i+1 : 0);
122 fMustDelete[i] = kTRUE;
123 pList->AddToList(fHMcEnergy[i]);
124 }
125
126 return kTRUE;
127}
128
129Bool_t MMcThresholdCalc::Process()
130{
131 const Float_t energy = fMcEvt->GetEnergy();
132 const Float_t lg10 = log10(energy);
133 const Float_t reciproc = 1./energy;
134
135 for (unsigned int i=0; i<fDimension; i++)
136 {
137 if (fMcTrig[i]->GetFirstLevel()<=0)
138 continue;
139
140 fHMcEnergy[i]->Fill(lg10, reciproc);
141 }
142
143 return kTRUE;
144}
145
146Bool_t MMcThresholdCalc::PostProcess()
147{
148 // fit the energy distribution to get the threshold
149
150 const Float_t sqrt2 = sqrt(2);
151
152 for (unsigned int i=0; i<fDimension; i++)
153 {
154 MHMcEnergy &h = *fHMcEnergy[i];
155
156 const Float_t peak = h.GetGaussPeak();
157 const Float_t sigma = h.GetGaussSigma();
158
159 h.Fit(1, 3);
160 h.Fit(peak - 2. *sigma, peak + 2. *sigma);
161 h.Fit(peak - sqrt2*sigma, peak + sqrt2*sigma);
162 }
163 return kTRUE;
164}
165
Note: See TracBrowser for help on using the repository browser.