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

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