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

Last change on this file since 1902 was 1715, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 5.0 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 maily 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
47#include "MHMcCollectionArea.h"
48
49ClassImp(MMcCollectionAreaCalc);
50
51MMcCollectionAreaCalc::MMcCollectionAreaCalc(const char *input,
52 const char *name, const char *title)
53{
54 fName = name ? name : "MMcCollectionAreaCalc";
55 fTitle = title ? title : "Task to calculate the collection area";
56
57 fObjName = input ? input : "MMcTrig";
58 AddToBranchList(Form("%s.fNumFirstLevel", input));
59
60 AddToBranchList("MMcEvt.fEnergy");
61 AddToBranchList("MMcEvt.fImpact");
62}
63
64Bool_t MMcCollectionAreaCalc::PreProcess (MParList *pList)
65{
66 // connect the raw data with this task
67
68 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
69 if (!fMcEvt)
70 {
71 *fLog << err << dbginf << "MMcEvt not found... exit." << endl;
72 return kFALSE;
73 }
74
75 fCollArea = (MHMcCollectionArea*)pList->FindCreateObj("MHMcCollectionArea");
76 if (!fCollArea)
77 return kFALSE;
78
79 fTheta = -1;
80 fTotalNumSimulatedShowers = 0;
81 fCorsikaVersion = 0;
82 fAllEvtsTriggered = kFALSE;
83
84 return kTRUE;
85}
86
87Bool_t MMcCollectionAreaCalc::ReInit(MParList *plist)
88{
89 MMcRunHeader *runheader = (MMcRunHeader*)plist->FindObject("MMcRunHeader");
90 if (!runheader)
91 {
92 *fLog << err << dbginf << "Error - MMcRunHeader not found... exit." << endl;
93 return kFALSE;
94 }
95
96 fTotalNumSimulatedShowers += runheader->GetNumSimulatedShowers();
97
98 *fLog << inf << "Total Number of Simulated showers: " << fTotalNumSimulatedShowers << endl;
99
100 if (fTheta>=0 && fTheta!=runheader->GetTelesTheta())
101 {
102 *fLog << warn << dbginf << "Warning - Read files have different TelesTheta (";
103 *fLog << fTheta << ", " << runheader->GetTelesTheta() << ")..." << endl;
104 }
105
106 fTheta = runheader->GetTelesTheta();
107
108 if (fCorsikaVersion!=0 && fCorsikaVersion!=runheader->GetCorsikaVersion())
109 *fLog << warn << dbginf << "Warning - Read files have different Corsika versions..." << endl;
110
111 fCorsikaVersion = runheader->GetCorsikaVersion();
112
113 fAllEvtsTriggered |= runheader->GetAllEvtsTriggered();
114
115 *fLog << inf << "Only triggered events avail: " << (fAllEvtsTriggered?"yes":"no") << endl;
116
117 if (fAllEvtsTriggered)
118 return kTRUE;
119
120 fMcTrig = (MMcTrig*)plist->FindObject(fObjName);
121 if (!fMcTrig)
122 {
123 *fLog << err << dbginf << fObjName << " [MMcTrig] not found... exit." << endl;
124 return kFALSE;
125 }
126
127 return kTRUE;
128}
129
130Bool_t MMcCollectionAreaCalc::Process()
131{
132 const Double_t energy = fMcEvt->GetEnergy();
133 const Double_t impact = fMcEvt->GetImpact()/100.;
134
135 //
136 // This happens for camera files created with Camera 0.5
137 //
138 if (TMath::IsNaN(impact))
139 {
140 *fLog << err << dbginf << "ERROR - Impact=NaN (Not a number)... abort." << endl;
141 return kERROR;
142 }
143
144 if (!fAllEvtsTriggered)
145 {
146 fCollArea->FillAll(energy, impact);
147
148 if (fMcTrig->GetFirstLevel() <= 0)
149 return kTRUE;
150 }
151
152 fCollArea->FillSel(energy, impact);
153
154 return kTRUE;
155}
156
157Bool_t MMcCollectionAreaCalc::PostProcess()
158{
159 //
160 // do the calculation of the effectiv area
161 //
162 *fLog << inf << "Calculation Collection Area..." << endl;
163
164 if (!fAllEvtsTriggered)
165 fCollArea->CalcEfficiency();
166 else
167 {
168 *fLog << inf << "Total number of showers: " << fTotalNumSimulatedShowers << endl;
169 fCollArea->CalcEfficiency(fTotalNumSimulatedShowers,
170 fCorsikaVersion == 5200 ? fTheta : 0);
171 }
172
173 return kTRUE;
174}
175
Note: See TracBrowser for help on using the repository browser.