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

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