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

Last change on this file since 983 was 983, checked in by tbretz, 23 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 const UInt_t from = fDimension<=0 ? -fDimension : 0;
114
115 if (fDimension<=0)
116 fDimension = -fDimension;
117
118 if (fDimension==0)
119 fDimension=1;
120
121 fMcTrig = new TObjArray(pList->FindObjectList("MMcTrig", from, fDimension));
122 if (fMcTrig->GetEntriesFast() != fDimension)
123 {
124 *fLog << dbginf << "Error: Not all requested MMcTrig objects are available...aborting." << endl;
125 return kFALSE;
126 }
127
128 fMcRate = new TObjArray(pList->FindObjectList("MHMcRate", from, fDimension));
129 if (fMcRate->GetEntriesFast() != fDimension)
130 {
131 *fLog << dbginf << "Error: Not all requested MHMcRate objects are available...aborting." << endl;
132 return kFALSE;
133 }
134
135 for (int i=0; i<fDimension; i++)
136 {
137 MHMcRate &rate = *GetRate(i);
138
139 rate.SetParticle(fPartId);
140 rate.SetBackground(fTrigger[i], fAnalShow);
141
142 fTrigger[i]=0;
143 }
144
145 fAnalShow=0.0;
146
147 return kTRUE;
148}
149
150// --------------------------------------------------------------------------
151//
152// The Process-function counts the number of simulated showers, the
153// number of analised showers and the number of triggers. It also updates
154// the limits for theta, phi, energy and impact parameter in the
155// MHMcRate container.
156//
157Bool_t MMcTriggerRateCalc::Process()
158{
159 //
160 // Counting analysed and simulated showers
161 //
162 fShowers++;
163 if (fMcEvt->GetPhotElfromShower())
164 fAnalShow++;
165
166 //
167 // Getting angles, energy and impact parameter to set boundaries
168 //
169 const Float_t theta = fMcEvt->GetTheta();
170 const Float_t phi = fMcEvt->GetPhi();
171 const Float_t param = fMcEvt->GetImpact();
172 const Float_t ener = fMcEvt->GetEnergy()/1000.0;
173
174 //
175 // Counting number of triggers
176 //
177 for (int i=0; i<fDimension; i++)
178 {
179 fTrigger[i] += GetTrig(i)->GetFirstLevel();
180
181 GetRate(i)->UpdateBoundaries(ener, theta, phi, param);
182 }
183
184 return kTRUE;
185}
186
187// --------------------------------------------------------------------------
188//
189// The PostProcess-function calculates and shows the trigger rate
190//
191Bool_t MMcTriggerRateCalc::PostProcess()
192{
193 //
194 // Computing trigger rate
195 //
196 for (int i=0; i<fDimension; i++)
197 GetRate(i)->CalcRate(fTrigger[i], fAnalShow, fShowers);
198
199 return kTRUE;
200}
Note: See TracBrowser for help on using the repository browser.