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

Last change on this file since 8549 was 6509, 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 *name, const char *title):
57 fBinsTheta(0), fBinsEnergy(0), fSpectrum(0)
58{
59 fName = name ? name : "MMcCollectionAreaCalc";
60 fTitle = title ? title : "Task to calculate the collection area";
61}
62
63////////////////////////////////////////////////////////////////////////////////
64//
65// PreProcess.
66// Create MHMcCollectionArea object if necessary.
67// Search in parameter list for MBinning objects with binning in theta and E.
68// These contain the coarse binning to be used in the analysis. Then search
69// for other necessary input containers:
70// if MMcEvt is found, it means we are in the loop over the Events tree,
71// and so we must fill the histogram MHMcCollectionArea::fHistSel (using
72// MHMcCollectionArea::FillSel). If MMcEvt is not found, it means that we are in
73// the loop over the "OriginalMC" tree, containing all the original Corsika events
74// produced, and hence we must fill the histogram fHistAll through
75// MHMcCollectionArea::FillAll.
76//
77Int_t MMcCollectionAreaCalc::PreProcess (MParList *pList)
78{
79 fCollArea = (MHMcCollectionArea*)pList->FindCreateObj("MHMcCollectionArea");
80
81 // Look for the binnings of the histograms if they have not been already
82 // found in a previous loop.
83
84 if (!fBinsTheta)
85 {
86 fBinsTheta = (MBinning*) pList->FindObject("binsTheta");
87 if (!fBinsTheta)
88 {
89 *fLog << err << "Coarse Theta binning not found... Aborting."
90 << endl;
91 return kFALSE;
92 }
93 }
94
95 if (!fBinsEnergy)
96 {
97 fBinsEnergy = (MBinning*) pList->FindObject("binsEnergy");
98 if (!fBinsEnergy)
99 {
100 *fLog << err << "Coarse Energy binning not found... Aborting."
101 << endl;
102 return kFALSE;
103 }
104 }
105
106 fCollArea->SetCoarseBinnings(*fBinsEnergy, *fBinsTheta);
107
108
109 // Look for the input containers
110
111 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
112 if (fMcEvt)
113 {
114 *fLog << inf << "MMcEvt found... I will fill MHMcCollectionArea.fHistSel..." << endl;
115 return kTRUE;
116 }
117
118 *fLog << inf << "MMcEvt not found... looking for MMcEvtBasic..." << endl;
119
120
121 fMcEvtBasic = (MMcEvtBasic*) pList->FindObject("MMcEvtBasic");
122
123 if (fMcEvtBasic)
124 {
125 *fLog << inf << "MMcEvtBasic found... I will fill MHMcCollectionArea.fHistAll..." << endl;
126 return kTRUE;
127 }
128
129 *fLog << err << "MMcEvtBasic not found. Aborting..." << endl;
130
131 return kFALSE;
132}
133
134////////////////////////////////////////////////////////////////////////////////
135//
136// Process. Depending on whether fMcEvt or fMcEvtBasic are available, fill
137// MHMcCollectionArea::fHistAll, else, if fMcEvt is available, fill
138// MHMcCollectionArea::fHistSel
139//
140Int_t MMcCollectionAreaCalc::Process()
141{
142 Double_t energy = fMcEvt? fMcEvt->GetEnergy() : fMcEvtBasic->GetEnergy();
143 Double_t impact = fMcEvt? fMcEvt->GetImpact()/100. : fMcEvtBasic->GetImpact()/100.; // in m
144 Double_t theta = fMcEvt? fMcEvt->GetTelescopeTheta()*TMath::RadToDeg() :
145 fMcEvtBasic->GetTelescopeTheta()*TMath::RadToDeg(); // in deg
146
147 if (fMcEvt)
148 fCollArea->FillSel(energy, impact, theta);
149 else
150 fCollArea->FillAll(energy, impact, theta);
151
152 return kTRUE;
153}
154
155///////////////////////////////////////////////////////////////////////////////
156//
157// Postprocess. If both fHistAll and fHistSel are already filled, calculate
158// effective areas. Else it means we still have to run one more loop.
159//
160Int_t MMcCollectionAreaCalc::PostProcess()
161{
162 if ( ((TH2D*)fCollArea->GetHistAll())->GetEntries() > 0 &&
163 ((TH2D*)fCollArea->GetHistSel())->GetEntries() > 0)
164 {
165 *fLog << inf << "Calculation Collection Area..." << endl;
166 fCollArea->Calc(fSpectrum);
167 }
168
169 return kTRUE;
170}
Note: See TracBrowser for help on using the repository browser.