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

Last change on this file since 862 was 862, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 5.3 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, MMcTrig;*
32//
33// Output Containers:
34// MHMcEnergies
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
54// --------------------------------------------------------------------------
55//
56// Default Constructor.
57//
58MMcThresholdCalc::MMcThresholdCalc(const UInt_t dim, const char* name,
59 const char* title) : fDimension(dim)
60{
61 *fName = name ? name : "MMcThresholdCalc";
62 *fTitle = title ? title : "Task to calculate the energy threshold from Monte Carlo";
63
64 // Arrays of MMcTrig* and MHMcEnergy* are created in order to be
65 // able to work with root files with several trigger conditions.
66 fMcTrig = new MMcTrig*[fDimension];
67 fHMcEnergy = new MHMcEnergy*[fDimension];
68 fMustDelete = new Bool_t[fDimension];
69
70 for (unsigned int i=0; i<fDimension; i++)
71 fMustDelete[i]=kFALSE;
72}
73
74// -------------------------------------------------------------------------
75//
76// Default Destructor.
77//
78MMcThresholdCalc::~MMcThresholdCalc()
79{
80 for (unsigned int i=0; i<fDimension; i++)
81 if (fMustDelete[i])
82 delete fHMcEnergy[i];
83
84 delete fMcTrig;
85 delete fHMcEnergy;
86 delete fMustDelete;
87}
88
89// --------------------------------------------------------------------------
90//
91// connect Monte Carlo data with this task
92//
93Bool_t MMcThresholdCalc::PreProcess(MParList* pList)
94{
95 // This task takes into accout if the root file has one trigger
96 // condition (MMcTrig) or severl of them (MMcTrig;#.)
97
98 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
99 if (!fMcEvt)
100 {
101 *fLog << dbginf << "MMcEvt not found... aborting." << endl;
102 return kFALSE;
103 }
104
105 char auxname[15]="MMcTrig"; // string to write container names
106
107 for (unsigned int i=0; i<fDimension; i++)
108 {
109 if (fDimension>1)
110 sprintf(auxname+7, ";%i.", i+1);
111
112 fMcTrig[i] = (MMcTrig*)pList->FindObject(auxname);
113 if (fMcTrig[i])
114 continue;
115
116 *fLog << dbginf << "'MMcTrig";
117 if (fDimension>1)
118 *fLog << ";" << i+1;
119 *fLog << "' not found... aborting." << endl;
120
121 return kFALSE;
122 }
123
124 strcpy(auxname, "MHMcEnergy");
125 for (unsigned int i=0; i<fDimension; i++)
126 {
127 if (fDimension>1&&i!=0)
128 sprintf(auxname+10, ";%i", i);
129
130 fHMcEnergy[i] = (MHMcEnergy*)pList->FindObject(auxname);
131 if (fHMcEnergy[i])
132 continue;
133
134 *fLog << dbginf << "'" << auxname << "' not found in list... creating." << endl;
135
136 fHMcEnergy[i] = new MHMcEnergy(fDimension>1&&i!=0 ? i : 0);
137 fMustDelete[i] = kTRUE;
138 pList->AddToList(fHMcEnergy[i]);
139 }
140
141 return kTRUE;
142}
143
144// --------------------------------------------------------------------------
145//
146// The histograms are filled with log10 of the energy for triggered
147// events and weighted with 1/E because it is needed the dN/dE vs. logE
148// distribution to get the energy threshold.
149//
150Bool_t MMcThresholdCalc::Process()
151{
152 const Float_t energy = fMcEvt->GetEnergy();
153 const Float_t lg10 = log10(energy);
154 const Float_t reciproc = 1./energy;
155
156 for (unsigned int i=0; i<fDimension; i++)
157 if (fMcTrig[i]->GetFirstLevel()>0)
158 fHMcEnergy[i]->Fill(lg10, reciproc);
159
160 return kTRUE;
161}
162
163// --------------------------------------------------------------------------
164//
165// fit the energy distribution to get the threshold
166// Some iterations are done to be sure the fit parameters converge.
167//
168Bool_t MMcThresholdCalc::PostProcess()
169{
170 const Float_t sqrt2 = sqrt(2);
171
172 for (unsigned int i=0; i<fDimension; i++)
173 {
174 Float_t peak;
175 Float_t sigma;
176
177 fHMcEnergy[i]->Fit(1, 3);
178
179 peak = fHMcEnergy[i]->GetGaussPeak();
180 sigma = fHMcEnergy[i]->GetGaussSigma();
181 fHMcEnergy[i]->Fit(peak - 2. *sigma, peak + 2. *sigma);
182
183 peak = fHMcEnergy[i]->GetGaussPeak();
184 sigma = fHMcEnergy[i]->GetGaussSigma();
185 fHMcEnergy[i]->Fit(peak - sqrt2*sigma, peak + sqrt2*sigma);
186 }
187 return kTRUE;
188}
189
Note: See TracBrowser for help on using the repository browser.