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

Last change on this file since 1038 was 1007, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 6.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): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
19! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
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
58 fFirst = dim>0 ? 1 : -dim;
59 fLast = dim>0 ? dim : -dim;
60
61 fNum = fLast-fFirst+1;
62
63 AddToBranchList("fImpact");
64 AddToBranchList("fEnergy");
65 AddToBranchList("fPhi");
66 AddToBranchList("fTheta");
67 AddToBranchList("fPhotElfromShower");
68 AddToBranchList("MMcTrig", "fNumFirstLevel", fFirst, fLast);
69}
70
71// --------------------------------------------------------------------------
72//
73// overloaded constructor I
74//
75// dim: fDimension
76// part: fPartId
77// *trigbg: number of shower from bacground that triggers
78// a given trigger condition.
79// simbg: Number of simulated showers for the background
80// rate: rate of incident showers
81//
82
83MMcTriggerRateCalc::MMcTriggerRateCalc(float rate, int dim, int part,
84 float *trigbg, float simbg,
85 const char *name, const char *title)
86{
87 Init(dim, part, trigbg, simbg, name, title);
88}
89
90
91// --------------------------------------------------------------------------
92//
93// overloaded constructor II
94//
95// dim: fDimension
96// part: fPartId
97// *trigbg: number of shower from bacground that triggers
98// a given trigger condition.
99// simbg: Number of simulated showers for the background
100//
101MMcTriggerRateCalc::MMcTriggerRateCalc(int dim, int part, float *trigbg,
102 float simbg,
103 const char *name, const char *title)
104{
105 Init(dim, part, trigbg, simbg, name, title);
106}
107
108MMcTriggerRateCalc::~MMcTriggerRateCalc()
109{
110 if (fMcTrig)
111 delete fMcTrig;
112
113 if (fMcRate)
114 delete fMcRate;
115}
116
117
118// --------------------------------------------------------------------------
119//
120// The PreProcess connects the raw data with this task. It checks if the
121// input containers exist, if not a kFalse flag is returned. It also checks
122// if the output contaniers exist, if not they are created.
123// This task can read either Montecarlo files with multiple trigger
124// options, either Montecarlo files with a single trigger option.
125//
126Bool_t MMcTriggerRateCalc::PreProcess (MParList *pList)
127{
128 // connect the raw data with this task
129
130 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
131 if (!fMcEvt)
132 {
133 *fLog << dbginf << "MMcEvt not found... aborting." << endl;
134 return kFALSE;
135 }
136
137 UInt_t num;
138
139 fMcTrig = new TObjArray(pList->FindObjectList("MMcTrig", fFirst, fLast));
140 num = fMcTrig->GetEntriesFast();
141 if (num != fNum)
142 {
143 *fLog << dbginf << fNum << " MMcTrig objects requested, ";
144 *fLog << num << " are available... aborting." << endl;
145 return kFALSE;
146 }
147
148 fMcRate = new TObjArray(pList->FindObjectList("MHMcRate", fFirst, fLast));
149 num = fMcRate->GetEntriesFast();
150 if (num != fNum)
151 {
152 *fLog << dbginf << fNum << " MHMcRate objects requested, ";
153 *fLog << num << " are available... aborting." << endl;
154 return kFALSE;
155 }
156
157 for (UInt_t i=0; i<fNum; i++)
158 {
159 MHMcRate &rate = *GetRate(i);
160
161 rate.SetParticle(fPartId);
162 rate.SetBackground(fTrigger[i], fAnalShow);
163
164 fTrigger[i]=0;
165 }
166
167 fAnalShow=0.0;
168
169 return kTRUE;
170}
171
172// --------------------------------------------------------------------------
173//
174// The Process-function counts the number of simulated showers, the
175// number of analised showers and the number of triggers. It also updates
176// the limits for theta, phi, energy and impact parameter in the
177// MHMcRate container.
178//
179Bool_t MMcTriggerRateCalc::Process()
180{
181 //
182 // Counting analysed and simulated showers
183 //
184 fShowers++;
185 if (fMcEvt->GetPhotElfromShower())
186 fAnalShow++;
187
188 //
189 // Getting angles, energy and impact parameter to set boundaries
190 //
191 const Float_t theta = fMcEvt->GetTheta();
192 const Float_t phi = fMcEvt->GetPhi();
193 const Float_t param = fMcEvt->GetImpact();
194 const Float_t ener = fMcEvt->GetEnergy()/1000.0;
195
196 //
197 // Counting number of triggers
198 //
199 for (UInt_t i=0; i<fNum; i++)
200 {
201 fTrigger[i] += GetTrig(i)->GetFirstLevel();
202
203 GetRate(i)->UpdateBoundaries(ener, theta, phi, param);
204 }
205
206 return kTRUE;
207}
208
209// --------------------------------------------------------------------------
210//
211// The PostProcess-function calculates and shows the trigger rate
212//
213Bool_t MMcTriggerRateCalc::PostProcess()
214{
215 //
216 // Computing trigger rate
217 //
218 for (UInt_t i=0; i<fNum; i++)
219 GetRate(i)->CalcRate(fTrigger[i], fAnalShow, fShowers);
220
221 return kTRUE;
222}
Note: See TracBrowser for help on using the repository browser.