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

Last change on this file since 6014 was 5340, checked in by moralejo, 20 years ago
*** empty log message ***
File size: 6.6 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 fThetaMin = -1.;
70 fThetaMax = -1.;
71
72}
73
74Int_t MMcCollectionAreaCalc::PreProcess (MParList *pList)
75{
76 // connect the raw data with this task
77
78 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
79 if (!fMcEvt)
80 {
81 *fLog << err << "MMcEvt not found... abort." << endl;
82 return kFALSE;
83 }
84
85 return kTRUE;
86}
87
88Bool_t MMcCollectionAreaCalc::ReInit(MParList *plist)
89{
90 fCollArea=0;
91
92 MMcRunHeader *runheader = (MMcRunHeader*)plist->FindObject("MMcRunHeader");
93 if (!runheader)
94 {
95 *fLog << err << "Error - MMcRunHeader not found... abort." << endl;
96 return kFALSE;
97 }
98
99 fTotalNumSimulatedShowers += runheader->GetNumSimulatedShowers();
100 *fLog << inf << "Total Number of Simulated showers: " << fTotalNumSimulatedShowers << endl;
101
102
103 if ( (fThetaMin >= 0 && fThetaMin != runheader->GetShowerThetaMin()) ||
104 (fThetaMax >= 0 && fThetaMax != runheader->GetShowerThetaMax()) )
105 {
106 *fLog << warn << "Warning - Read files have different Theta ranges (";
107 *fLog << "(" << fThetaMin << ", " << fThetaMax << ") vs (" <<
108 runheader->GetShowerThetaMin() << ", " <<
109 runheader->GetShowerThetaMax() << ")..." << endl;
110 }
111 fThetaMin = runheader->GetShowerThetaMin();
112 fThetaMax = runheader->GetShowerThetaMax();
113
114
115 if (fCorsikaVersion!=0 && fCorsikaVersion!=runheader->GetCorsikaVersion())
116 *fLog << warn << "Warning - Read files have different Corsika versions..." << endl;
117 fCorsikaVersion = runheader->GetCorsikaVersion();
118
119
120 fAllEvtsTriggered |= runheader->GetAllEvtsTriggered();
121 *fLog << inf << "Only triggered events avail: " << (fAllEvtsTriggered?"yes":"no") << endl;
122
123
124 fCollArea = (MHMcCollectionArea*)plist->FindCreateObj("MHMcCollectionArea");
125 if (!fCollArea)
126 return kFALSE;
127
128 if (!fAllEvtsTriggered)
129 {
130 fMcTrig = (MMcTrig*)plist->FindObject(fObjName);
131 if (!fMcTrig)
132 {
133 *fLog << err << fObjName << " [MMcTrig] not found... anort." << endl;
134 return kFALSE;
135 }
136 return kTRUE;
137 }
138
139 MMcCorsikaRunHeader *corrunheader = (MMcCorsikaRunHeader*)plist->FindObject("MMcCorsikaRunHeader");
140 if (!corrunheader)
141 {
142 *fLog << err << "MMcCorsikaRunHeader not found... abort." << endl;
143 return kFALSE;
144 }
145
146 //
147 // Calculate approximately the original number of events in each
148 // energy bin:
149 //
150
151 const Float_t emin = corrunheader->GetELowLim();
152 const Float_t emax = corrunheader->GetEUppLim();
153 const Float_t expo = 1 + corrunheader->GetSlopeSpec();
154 const Float_t k = runheader->GetNumSimulatedShowers() /
155 (pow(emax,expo) - pow(emin,expo)) ;
156
157 TH2 &hall = *fCollArea->GetHistAll();
158
159 const Int_t nbinx = hall.GetNbinsX();
160
161 TAxis &axe = *hall.GetXaxis();
162 for (Int_t i = 1; i <= nbinx; i++)
163 {
164 const Float_t e1 = axe.GetBinLowEdge(i);
165 const Float_t e2 = axe.GetBinLowEdge(i+1);
166
167 if (e1 < emin || e2 > emax)
168 continue;
169
170 const Float_t events = k * (pow(e2, expo) - pow(e1, expo));
171 //
172 // We fill the i-th energy bin, with the total number of events
173 // Second argument of Fill would be impact parameter of each
174 // event, but we don't really need it for the collection area,
175 // so we just put a dummy value (1.)
176 //
177
178 const Float_t energy = (e1+e2)/2.;
179 hall.Fill(energy, 1., events);
180 }
181
182 return kTRUE;
183}
184
185Int_t MMcCollectionAreaCalc::Process()
186{
187 const Double_t energy = fMcEvt->GetEnergy();
188 const Double_t impact = fMcEvt->GetImpact()/100.;
189
190 //
191 // This happens for camera files created with Camera 0.5
192 //
193 if (TMath::IsNaN(impact))
194 {
195 *fLog << err << dbginf << "ERROR - Impact=NaN (Not a number)... abort." << endl;
196 return kERROR;
197 }
198
199 if (!fAllEvtsTriggered)
200 {
201 fCollArea->FillAll(energy, impact);
202
203 if (fMcTrig->GetFirstLevel() <= 0)
204 return kTRUE;
205 }
206
207 fCollArea->FillSel(energy, impact);
208
209 return kTRUE;
210}
211
212Int_t MMcCollectionAreaCalc::PostProcess()
213{
214 if (!fCollArea)
215 return kTRUE;
216
217 //
218 // do the calculation of the effectiv area
219 //
220 *fLog << inf << "Calculation Collection Area..." << endl;
221
222 if (!fAllEvtsTriggered)
223 fCollArea->CalcEfficiency();
224 else
225 {
226 *fLog << inf << "Total number of showers: " << fTotalNumSimulatedShowers << endl;
227 fCollArea->CalcEfficiency2();
228 }
229
230 return kTRUE;
231}
232
Note: See TracBrowser for help on using the repository browser.