source: trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.cc@ 5073

Last change on this file since 5073 was 5073, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 6.4 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): Thomas Bretz 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Harald Kornmayer 1/2001
20!
21! Copyright: MAGIC Software Development, 2000-2002
22!
23!
24\* ======================================================================== */
25
26//////////////////////////////////////////////////////////////////////////////
27//
28// MHMcCollectionAreaCalc
29//
30// Remark: The initialization is mainly done in the ReInit function.
31// Please make sure, that you don't use MReadTree when processing
32// a file. Use a 'ReInit'-calling task like MReadMarsFile
33//
34//////////////////////////////////////////////////////////////////////////////
35
36#include "MMcCollectionAreaCalc.h"
37
38#include "MParList.h"
39
40#include "MLog.h"
41#include "MLogManip.h"
42
43#include "MMcEvt.hxx"
44#include "MMcTrig.hxx"
45#include "MMcRunHeader.hxx"
46#include "MMcCorsikaRunHeader.h"
47
48#include "MHMcCollectionArea.h"
49
50ClassImp(MMcCollectionAreaCalc);
51
52using namespace std;
53
54MMcCollectionAreaCalc::MMcCollectionAreaCalc(const char *input,
55 const char *name, const char *title)
56{
57 fName = name ? name : "MMcCollectionAreaCalc";
58 fTitle = title ? title : "Task to calculate the collection area";
59
60 fObjName = input ? input : "MMcTrig";
61 AddToBranchList(Form("%s.fNumFirstLevel", input));
62
63 AddToBranchList("MMcEvt.fEnergy");
64 AddToBranchList("MMcEvt.fImpact");
65
66 fCorsikaVersion = 0;
67 fAllEvtsTriggered = kFALSE;
68 fTotalNumSimulatedShowers = 0;
69 fTheta = -1.;
70
71}
72
73Int_t MMcCollectionAreaCalc::PreProcess (MParList *pList)
74{
75 // connect the raw data with this task
76
77 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
78 if (!fMcEvt)
79 {
80 *fLog << err << "MMcEvt not found... abort." << endl;
81 return kFALSE;
82 }
83
84 return kTRUE;
85}
86
87Bool_t MMcCollectionAreaCalc::ReInit(MParList *plist)
88{
89 fCollArea=0;
90
91 MMcRunHeader *runheader = (MMcRunHeader*)plist->FindObject("MMcRunHeader");
92 if (!runheader)
93 {
94 *fLog << err << "Error - MMcRunHeader not found... abort." << endl;
95 return kFALSE;
96 }
97
98 fTotalNumSimulatedShowers += runheader->GetNumSimulatedShowers();
99 *fLog << inf << "Total Number of Simulated showers: " << fTotalNumSimulatedShowers << endl;
100
101
102 if (fTheta>=0 && fTheta!=runheader->GetTelesTheta())
103 {
104 *fLog << warn << "Warning - Read files have different TelesTheta (";
105 *fLog << fTheta << ", " << runheader->GetTelesTheta() << ")..." << endl;
106 }
107 fTheta = runheader->GetTelesTheta();
108
109
110 if (fCorsikaVersion!=0 && fCorsikaVersion!=runheader->GetCorsikaVersion())
111 *fLog << warn << "Warning - Read files have different Corsika versions..." << endl;
112 fCorsikaVersion = runheader->GetCorsikaVersion();
113
114
115 fAllEvtsTriggered |= runheader->GetAllEvtsTriggered();
116 *fLog << inf << "Only triggered events avail: " << (fAllEvtsTriggered?"yes":"no") << endl;
117
118
119 fCollArea = (MHMcCollectionArea*)plist->FindCreateObj("MHMcCollectionArea");
120 if (!fCollArea)
121 return kFALSE;
122
123 if (!fAllEvtsTriggered)
124 {
125 fMcTrig = (MMcTrig*)plist->FindObject(fObjName);
126 if (!fMcTrig)
127 {
128 *fLog << err << fObjName << " [MMcTrig] not found... anort." << endl;
129 return kFALSE;
130 }
131 return kTRUE;
132 }
133
134 MMcCorsikaRunHeader *corrunheader = (MMcCorsikaRunHeader*)plist->FindObject("MMcCorsikaRunHeader");
135 if (!corrunheader)
136 {
137 *fLog << err << "MMcCorsikaRunHeader not found... abort." << endl;
138 return kFALSE;
139 }
140
141 //
142 // Calculate approximately the original number of events in each
143 // energy bin:
144 //
145
146 const Float_t emin = corrunheader->GetELowLim();
147 const Float_t emax = corrunheader->GetEUppLim();
148 const Float_t expo = 1 + corrunheader->GetSlopeSpec();
149 const Float_t k = runheader->GetNumSimulatedShowers() /
150 (pow(emax,expo) - pow(emin,expo)) ;
151
152 TH2 &hall = *fCollArea->GetHistAll();
153
154 const Int_t nbinx = hall.GetNbinsX();
155
156 TAxis &axe = *hall.GetXaxis();
157 for (Int_t i = 1; i <= nbinx; i++)
158 {
159 const Float_t e1 = axe.GetBinLowEdge(i);
160 const Float_t e2 = axe.GetBinLowEdge(i+1);
161
162 if (e1 < emin || e2 > emax)
163 continue;
164
165 const Float_t events = k * (pow(e2, expo) - pow(e1, expo));
166 //
167 // We fill the i-th energy bin, with the total number of events
168 // Second argument of Fill would be impact parameter of each
169 // event, but we don't really need it for the collection area,
170 // so we just put a dummy value (1.)
171 //
172
173 const Float_t energy = (e1+e2)/2.;
174 hall.Fill(energy, 1., events);
175 }
176
177 return kTRUE;
178}
179
180Int_t MMcCollectionAreaCalc::Process()
181{
182 const Double_t energy = fMcEvt->GetEnergy();
183 const Double_t impact = fMcEvt->GetImpact()/100.;
184
185 //
186 // This happens for camera files created with Camera 0.5
187 //
188 if (TMath::IsNaN(impact))
189 {
190 *fLog << err << dbginf << "ERROR - Impact=NaN (Not a number)... abort." << endl;
191 return kERROR;
192 }
193
194 if (!fAllEvtsTriggered)
195 {
196 fCollArea->FillAll(energy, impact);
197
198 if (fMcTrig->GetFirstLevel() <= 0)
199 return kTRUE;
200 }
201
202 fCollArea->FillSel(energy, impact);
203
204 return kTRUE;
205}
206
207Int_t MMcCollectionAreaCalc::PostProcess()
208{
209 if (!fCollArea)
210 return kTRUE;
211
212 //
213 // do the calculation of the effectiv area
214 //
215 *fLog << inf << "Calculation Collection Area..." << endl;
216
217 if (!fAllEvtsTriggered)
218 fCollArea->CalcEfficiency();
219 else
220 {
221 *fLog << inf << "Total number of showers: " << fTotalNumSimulatedShowers << endl;
222 fCollArea->CalcEfficiency2();
223 }
224
225 return kTRUE;
226}
227
Note: See TracBrowser for help on using the repository browser.