source: trunk/MagicSoft/Mars/mmontecarlo/MMcTriggerRateCalc.cc@ 1350

Last change on this file since 1350 was 1342, checked in by tbretz, 22 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@uni-sw.gwdg.de>
19! Author(s): Harald Kornmayer 1/2001
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26#include "MMcTriggerRateCalc.h"
27
28#include "MLog.h"
29#include "MLogManip.h"
30
31#include "MParList.h"
32#include "MHMcRate.h"
33
34#include "MMcEvt.hxx"
35#include "MMcTrig.hxx"
36
37ClassImp(MMcTriggerRateCalc);
38
39void MMcTriggerRateCalc::Init(int dim, int part, float *trigbg,
40 float simbg,
41 const char *name, const char *title)
42{
43 fName = name ? name : "MMcTriggerRateCalc";
44 fTitle = title ? title : "Task to calc the trigger rate ";
45
46 fMcTrig = NULL;
47 fMcRate = NULL;
48
49 for (int i=0;i<10;i++)
50 fTrigger[i] = dim&&trigbg ? trigbg[i] : 0;
51
52 fShowers = 0;
53 fAnalShow = simbg;
54
55 fPartId=part;
56
57 fFirst = dim>0 ? 1 : -dim;
58 fLast = dim>0 ? dim : -dim;
59
60 fNum = fLast-fFirst+1;
61
62 AddToBranchList("MMcEvt.fImpact");
63 AddToBranchList("MMcEvt.fEnergy");
64 AddToBranchList("MMcEvt.fPhi");
65 AddToBranchList("MMcEvt.fTheta");
66 AddToBranchList("MMcEvt.fPhotElfromShower");
67 AddToBranchList("MMcTrig", "fNumFirstLevel", fFirst, fLast);
68}
69
70// --------------------------------------------------------------------------
71//
72// overloaded constructor I
73//
74// dim: fDimension
75// part: fPartId
76// *trigbg: number of shower from bacground that triggers
77// a given trigger condition.
78// simbg: Number of simulated showers for the background
79// rate: rate of incident showers
80//
81
82MMcTriggerRateCalc::MMcTriggerRateCalc(float rate, int dim, int part,
83 float *trigbg, float simbg,
84 const char *name, const char *title)
85{
86 Init(dim, part, trigbg, simbg, name, title);
87}
88
89
90// --------------------------------------------------------------------------
91//
92// overloaded constructor II
93//
94// dim: fDimension
95// part: fPartId
96// *trigbg: number of shower from bacground that triggers
97// a given trigger condition.
98// simbg: Number of simulated showers for the background
99//
100MMcTriggerRateCalc::MMcTriggerRateCalc(int dim, int part, float *trigbg,
101 float simbg,
102 const char *name, const char *title)
103{
104 Init(dim, part, trigbg, simbg, name, title);
105}
106
107MMcTriggerRateCalc::~MMcTriggerRateCalc()
108{
109 if (fMcTrig)
110 delete fMcTrig;
111
112 if (fMcRate)
113 delete fMcRate;
114}
115
116
117// --------------------------------------------------------------------------
118//
119// The PreProcess connects the raw data with this task. It checks if the
120// input containers exist, if not a kFalse flag is returned. It also checks
121// if the output contaniers exist, if not they are created.
122// This task can read either Montecarlo files with multiple trigger
123// options, either Montecarlo files with a single trigger option.
124//
125Bool_t MMcTriggerRateCalc::PreProcess (MParList *pList)
126{
127 // connect the raw data with this task
128
129 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
130 if (!fMcEvt)
131 {
132 *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
133 return kFALSE;
134 }
135
136 UInt_t num;
137
138 fMcTrig = new TObjArray(pList->FindObjectList("MMcTrig", fFirst, fLast));
139 num = fMcTrig->GetEntriesFast();
140 if (num != fNum)
141 {
142 *fLog << err << dbginf << fNum << " MMcTrig objects requested, ";
143 *fLog << num << " are available... aborting." << endl;
144 return kFALSE;
145 }
146
147 fMcRate = new TObjArray(pList->FindObjectList("MHMcRate", fFirst, fLast));
148 num = fMcRate->GetEntriesFast();
149 if (num != fNum)
150 {
151 *fLog << err << dbginf << fNum << " MHMcRate objects requested, ";
152 *fLog << num << " are available... aborting." << endl;
153 return kFALSE;
154 }
155
156 for (UInt_t i=0; i<fNum; i++)
157 {
158 MHMcRate &rate = *GetRate(i);
159
160 rate.SetParticle(fPartId);
161 switch (fPartId)
162 {
163 case kPROTON:
164 rate.SetFlux(0.1091, 2.75);
165 break;
166 case kHELIUM:
167 rate.SetFlux(0.0660, 2.62);
168 break;
169 default:
170 *fLog << err << dbginf << "Unknown incident flux parameters for ";
171 *fLog << fPartId<< " particle Id ... aborting." << endl;
172 return kFALSE;
173 }
174 rate.SetBackground(fTrigger[i], fAnalShow);
175
176 fTrigger[i]=0;
177 }
178
179 fAnalShow=0.0;
180
181 return kTRUE;
182}
183
184// --------------------------------------------------------------------------
185//
186// The Process-function counts the number of simulated showers, the
187// number of analised showers and the number of triggers. It also updates
188// the limits for theta, phi, energy and impact parameter in the
189// MHMcRate container.
190//
191Bool_t MMcTriggerRateCalc::Process()
192{
193 //
194 // Counting analysed and simulated showers
195 //
196 fShowers++;
197 if (fMcEvt->GetPhotElfromShower())
198 fAnalShow++;
199
200 //
201 // Getting angles, energy and impact parameter to set boundaries
202 //
203 const Float_t theta = fMcEvt->GetTheta();
204 const Float_t phi = fMcEvt->GetPhi();
205 const Float_t param = fMcEvt->GetImpact();
206 const Float_t ener = fMcEvt->GetEnergy()/1000.0;
207
208 //
209 // Counting number of triggers
210 //
211 for (UInt_t i=0; i<fNum; i++)
212 {
213 if (GetTrig(i)->GetFirstLevel())
214 fTrigger[i] ++;
215
216 GetRate(i)->UpdateBoundaries(ener, theta, phi, param);
217 }
218
219 return kTRUE;
220}
221
222// --------------------------------------------------------------------------
223//
224// The PostProcess-function calculates and shows the trigger rate
225//
226Bool_t MMcTriggerRateCalc::PostProcess()
227{
228 //
229 // Computing trigger rate
230 //
231 for (UInt_t i=0; i<fNum; i++)
232 GetRate(i)->CalcRate(fTrigger[i], fAnalShow, fShowers);
233
234 return kTRUE;
235}
Note: See TracBrowser for help on using the repository browser.