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

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