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

Last change on this file since 6491 was 6491, checked in by moralejo, 20 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): Thomas Bretz 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Harald Kornmayer 1/2001
20! Author(s): Abelardo Moralejo 2/2005 <mailto:moralejo@pd.infn.it>
21!
22! Copyright: MAGIC Software Development, 2000-2002
23!
24!
25\* ======================================================================== */
26
27//////////////////////////////////////////////////////////////////////////////
28//
29// MMcCollectionAreaCalc
30//
31//////////////////////////////////////////////////////////////////////////////
32
33#include "MMcCollectionAreaCalc.h"
34
35#include "MParList.h"
36
37#include "MLog.h"
38#include "MLogManip.h"
39
40#include "MMcEvt.hxx"
41#include "MMcEvtBasic.h"
42
43#include "MMcRunHeader.hxx"
44#include "MMcCorsikaRunHeader.h"
45
46#include "MHMcCollectionArea.h"
47
48ClassImp(MMcCollectionAreaCalc);
49
50using namespace std;
51
52////////////////////////////////////////////////////////////////////////////////
53//
54// Constructor
55//
56MMcCollectionAreaCalc::MMcCollectionAreaCalc(const char *input, const char *name,
57 const char *title):
58 fBinsTheta(0), fBinsEnergy(0), fSpectrum(0)
59{
60 fName = name ? name : "MMcCollectionAreaCalc";
61 fTitle = title ? title : "Task to calculate the collection area";
62}
63
64////////////////////////////////////////////////////////////////////////////////
65//
66// PreProcess.
67// Create MHMcCollectionArea object if necessary.
68// Search in parameter list for MBinning objects with binning in theta and E.
69// These contain the coarse binning to be used in the analysis. Then search
70// for other necessary input containers:
71// if MMcEvt is found, it means we are in the loop over the Events tree,
72// and so we must fill the histogram MHMcCollectionArea::fHistSel (using
73// MHMcCollectionArea::FillSel). If MMcEvt is not found, it means that we are in
74// the loop over the "OriginalMC" tree, containing all the original Corsika events
75// produced, and hence we must fill the histogram fHistAll through
76// MHMcCollectionArea::FillAll.
77//
78Int_t MMcCollectionAreaCalc::PreProcess (MParList *pList)
79{
80 fCollArea = (MHMcCollectionArea*)pList->FindCreateObj("MHMcCollectionArea");
81
82 // Look for the binnings of the histograms if they have not been already
83 // found in a previous loop.
84
85 if (!fBinsTheta)
86 {
87 fBinsTheta = (MBinning*) pList->FindObject("binsTheta");
88 if (!fBinsTheta)
89 {
90 *fLog << err << "Coarse Theta binning not found... Aborting."
91 << endl;
92 return kFALSE;
93 }
94 }
95
96 if (!fBinsEnergy)
97 {
98 fBinsEnergy = (MBinning*) pList->FindObject("binsEnergy");
99 if (!fBinsEnergy)
100 {
101 *fLog << err << "Coarse Energy binning not found... Aborting."
102 << endl;
103 return kFALSE;
104 }
105 }
106
107 fCollArea->SetCoarseBinnings(*fBinsEnergy, *fBinsTheta);
108
109
110 // Look for the input containers
111
112 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
113 if (fMcEvt)
114 {
115 *fLog << inf << "MMcEvt found... I will fill MHMcCollectionArea.fHistSel..." << endl;
116 return kTRUE;
117 }
118
119 *fLog << inf << "MMcEvt not found... looking for MMcEvtBasic..." << endl;
120
121
122 fMcEvtBasic = (MMcEvtBasic*) pList->FindObject("MMcEvtBasic");
123
124 if (fMcEvtBasic)
125 {
126 *fLog << inf << "MMcEvtBasic found... I will fill MHMcCollectionArea.fHistAll..." << endl;
127 return kTRUE;
128 }
129
130 *fLog << err << "MMcEvtBasic not found. Aborting..." << endl;
131
132 return kFALSE;
133}
134
135////////////////////////////////////////////////////////////////////////////////
136//
137// Process. Depending on whether fMcEvt or fMcEvtBasic are available, fill
138// MHMcCollectionArea::fHistAll, else, if fMcEvt is available, fill
139// MHMcCollectionArea::fHistSel
140//
141Int_t MMcCollectionAreaCalc::Process()
142{
143 Double_t energy = fMcEvt? fMcEvt->GetEnergy() : fMcEvtBasic->GetEnergy();
144 Double_t impact = fMcEvt? fMcEvt->GetImpact()/100. : fMcEvtBasic->GetImpact()/100.; // in m
145 Double_t theta = fMcEvt? fMcEvt->GetTelescopeTheta()*TMath::RadToDeg() :
146 fMcEvtBasic->GetTelescopeTheta()*TMath::RadToDeg(); // in deg
147
148 if (fMcEvt)
149 fCollArea->FillSel(energy, impact, theta);
150 else
151 fCollArea->FillAll(energy, impact, theta);
152
153 return kTRUE;
154}
155
156///////////////////////////////////////////////////////////////////////////////
157//
158// Postprocess. If both fHistAll and fHistSel are already filled, calculate
159// effective areas. Else it means we still have to run one more loop.
160//
161Int_t MMcCollectionAreaCalc::PostProcess()
162{
163 if ( ((TH2D*)fCollArea->GetHistAll())->GetEntries() > 0 &&
164 ((TH2D*)fCollArea->GetHistSel())->GetEntries() > 0)
165 {
166 *fLog << inf << "Calculation Collection Area..." << endl;
167 fCollArea->Calc(fSpectrum);
168 }
169
170 return kTRUE;
171}
Note: See TracBrowser for help on using the repository browser.