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

Last change on this file since 861 was 861, checked in by jlopez, 23 years ago
*** empty log message ***
File size: 5.2 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
89Bool_t MMcThresholdCalc::PreProcess(MParList* pList)
90{
91 // connect Monte Carlo data with this task
92
93 // This task has into accout if the root file has one trigger
94 // condition (MMcTrig) or severl of them (MMcTrig;#.)
95
96 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
97 if (!fMcEvt)
98 {
99 *fLog << dbginf << "MMcEvt not found... aborting." << endl;
100 return kFALSE;
101 }
102
103 char auxname[15]="MMcTrig"; // string to write container names
104
105 for (unsigned int i=0; i<fDimension; i++)
106 {
107 if (fDimension>1)
108 sprintf(auxname+7, ";%i.", i+1);
109
110 fMcTrig[i] = (MMcTrig*)pList->FindObject(auxname);
111 if (fMcTrig[i])
112 continue;
113
114 *fLog << dbginf << "'MMcTrig";
115 if (fDimension>1)
116 *fLog << ";" << i+1;
117 *fLog << "' not found... aborting." << endl;
118
119 return kFALSE;
120 }
121
122 strcpy(auxname, "MHMcEnergy");
123 for (unsigned int i=0; i<fDimension; i++)
124 {
125 if (fDimension>1&&i!=0)
126 sprintf(auxname+10, ";%i", i);
127
128 fHMcEnergy[i] = (MHMcEnergy*)pList->FindObject(auxname);
129 if (fHMcEnergy[i])
130 continue;
131
132 *fLog << dbginf << "'" << auxname << "' not found in list... creating." << endl;
133
134 fHMcEnergy[i] = new MHMcEnergy(fDimension>1&&i!=0 ? i : 0);
135 fMustDelete[i] = kTRUE;
136 pList->AddToList(fHMcEnergy[i]);
137 }
138
139 return kTRUE;
140}
141
142Bool_t MMcThresholdCalc::Process()
143{
144
145 // The histograms are filled with log10 of the energy for triggered
146 // events and weighted with 1/E because it is needed the dN/dE vs. logE
147 // distribution to get the energy threshold.
148
149 const Float_t energy = fMcEvt->GetEnergy();
150 const Float_t lg10 = log10(energy);
151 const Float_t reciproc = 1./energy;
152
153 for (unsigned int i=0; i<fDimension; i++)
154 {
155 if (fMcTrig[i]->GetFirstLevel()<=0)
156 continue;
157
158 fHMcEnergy[i]->Fill(lg10, reciproc);
159 }
160
161 return kTRUE;
162}
163
164Bool_t MMcThresholdCalc::PostProcess()
165{
166 // fit the energy distribution to get the threshold
167 // Some iterations are done to be sure the fit parameters converge.
168
169 const Float_t sqrt2 = sqrt(2);
170
171 for (unsigned int i=0; i<fDimension; i++)
172 {
173 Float_t peak;
174 Float_t sigma;
175
176 fHMcEnergy[i]->Fit(1, 3);
177
178 peak = fHMcEnergy[i]->GetGaussPeak();
179 sigma = fHMcEnergy[i]->GetGaussSigma();
180 fHMcEnergy[i]->Fit(peak - 2. *sigma, peak + 2. *sigma);
181
182 peak = fHMcEnergy[i]->GetGaussPeak();
183 sigma = fHMcEnergy[i]->GetGaussSigma();
184 fHMcEnergy[i]->Fit(peak - sqrt2*sigma, peak + sqrt2*sigma);
185 }
186 return kTRUE;
187}
188
Note: See TracBrowser for help on using the repository browser.