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

Last change on this file since 951 was 898, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 5.9 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, float spec, float flux0,
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 fSpecInd=spec;
56 fFlux0=flux0;
57}
58
59// --------------------------------------------------------------------------
60//
61// overloaded constructor I
62//
63// dim: fDimension
64// part: fPartId
65// *trigbg: number of shower from bacground that triggers
66// a given trigger condition.
67// simbg: Number of simulated showers for the bacground
68// rate: rate of incident showers
69//
70
71MMcTriggerRateCalc::MMcTriggerRateCalc(float rate, int dim, int part,
72 float *trigbg, float simbg,
73 const char *name, const char *title)
74{
75 Init(dim, part, trigbg, simbg, rate, 0, name, title);
76}
77
78
79// --------------------------------------------------------------------------
80//
81// overloaded constructor II
82//
83// dim: fDimension
84// part: fPartId
85// *trigbg: number of shower from bacground that triggers
86// a given trigger condition.
87// simbg: Number of simulated showers for the bacground
88// spec: spectral index
89// flux0; fFlux0
90//
91
92MMcTriggerRateCalc::MMcTriggerRateCalc(int dim, int part, float *trigbg,
93 float simbg, float spec, float flux0,
94 const char *name, const char *title)
95{
96 Init(dim, part, trigbg, simbg, spec, flux0, name, title);
97}
98
99
100// --------------------------------------------------------------------------
101//
102// The PreProcess connects the raw data with this task. It checks if the
103// input containers exist, if not a kFalse flag is returned. It also checks
104// if the output contaniers exist, if not they are created.
105// This task can read either Montecarlo files with multiple trigger
106// options, either Montecarlo files with a single trigger option.
107//
108Bool_t MMcTriggerRateCalc::PreProcess (MParList *pList)
109{
110 // connect the raw data with this task
111
112 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
113 if (!fMcEvt)
114 {
115 *fLog << dbginf << "MMcEvt not found... aborting." << endl;
116 return kFALSE;
117 }
118
119 const UInt_t from = fDimension<=0 ? -fDimension : 0;
120
121 if (fDimension<=0)
122 fDimension = -fDimension;
123
124 fMcTrig = new TObjArray(pList->FindObjectList("MMcTrig", from, fDimension));
125 if (fMcTrig->GetEntriesFast() != fDimension)
126 {
127 *fLog << dbginf << "Error: Not all requested MMcTrig objects are available...aborting." << endl;
128 return kFALSE;
129 }
130
131 fMcRate = new TObjArray(pList->FindObjectList("MHMcRate", from, fDimension));
132 if (fMcRate->GetEntriesFast() != fDimension)
133 {
134 *fLog << dbginf << "Error: Not all requested MHMcRate objects are available...aborting." << endl;
135 return kFALSE;
136 }
137
138 for (int i=0; i<fDimension; 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 // Counting analysed and simulated showers
163
164 fShowers++;
165 if (fMcEvt->GetPhotElfromShower())
166 fAnalShow++;
167
168 // Getting angles, energy and impact parameter to set boundaries
169
170 const Float_t theta=fMcEvt->GetTheta();
171 const Float_t phi =fMcEvt->GetPhi();
172 const Float_t param=fMcEvt->GetImpact();
173 const Float_t ener =fMcEvt->GetEnergy()/1000.0;
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 // Computing trigger rate and showing it
194 for(int i=0; i<fDimension; i++)
195 {
196 MHMcRate &rate = *GetRate(i);
197
198 rate.CalcRate(fTrigger[i], fAnalShow, fShowers);
199 rate.Print();
200 rate.Draw("S");
201 }
202
203 return kTRUE;
204}
205
206
207
Note: See TracBrowser for help on using the repository browser.