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

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