source: trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.cc@ 7044

Last change on this file since 7044 was 7013, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 10.1 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): Markus Gaug, 12/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24//////////////////////////////////////////////////////////////////////////////
25//
26// MCalibCalcFromPast
27//
28// Steers the occurrance of interlaced calibration events in one data run
29//
30// Input Containers:
31// MParList
32// MCalibrationIntensityChargeCam
33// MCalibrationIntensityRelTimeCam
34// MBadPixelsIntensityCam
35//
36// Output Containers:
37// MCalibrationIntensityChargeCam
38// MCalibrationIntensityRelTimeCam
39// MBadPixelsIntensityCam
40//
41//////////////////////////////////////////////////////////////////////////////
42#include "MCalibCalcFromPast.h"
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MParList.h"
48
49#include "MRawRunHeader.h"
50
51#include "MHCalibrationCam.h"
52
53#include "MCalibrationIntensityChargeCam.h"
54#include "MCalibrationIntensityBlindCam.h"
55#include "MCalibrationIntensityQECam.h"
56#include "MCalibrationIntensityRelTimeCam.h"
57
58#include "MBadPixelsIntensityCam.h"
59
60#include "MCalibrationChargeCalc.h"
61#include "MCalibrationRelTimeCalc.h"
62#include "MCalibrateData.h"
63
64ClassImp(MCalibCalcFromPast);
65
66using namespace std;
67
68const UInt_t MCalibCalcFromPast::fgNumEventsDump = 500;
69
70// --------------------------------------------------------------------------
71//
72// Default constructor.
73//
74// Sets:
75// - fNumEventsDump to fgNumEventsDump
76//
77MCalibCalcFromPast::MCalibCalcFromPast(const char *name, const char *title)
78 : fGeom(NULL), fParList(NULL), fRunHeader(NULL),
79 fIntensCharge(NULL), fIntensBlind(NULL), fIntensRelTime(NULL), fIntensBad(NULL),
80 fChargeCalc(NULL), fRelTimeCalc(NULL), fCalibrate(NULL),
81 fNumEvents(0), fNumCam(0), fUpdateWithFFactorMethod(kFALSE)
82{
83
84 fName = name ? name : "MCalibCalcFromPast";
85 fTitle = title ? title : "Task to steer the processing of interlaced calibration events";
86
87 SetNumEventsDump();
88}
89
90// -----------------------------------------------------------------------------------
91//
92Int_t MCalibCalcFromPast::PreProcess(MParList *pList)
93{
94
95 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
96 if (!fGeom)
97 {
98 *fLog << err << "MGeomCam not found... abort." << endl;
99 return kFALSE;
100 }
101
102 fParList = pList;
103 if (!fParList)
104 {
105 *fLog << err << "MParList not found... abort." << endl;
106 return kFALSE;
107 }
108
109 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
110 if (!fRunHeader)
111 {
112 *fLog << err << "MRawRunHeader not found... abort." << endl;
113 return kFALSE;
114 }
115
116 //
117 // Look for the MBadPixels Intensity Cam
118 //
119 fIntensBad = (MBadPixelsIntensityCam*)pList->FindCreateObj("MBadPixelsIntensityCam");
120 if (fIntensBad)
121 *fLog << inf << "Found MBadPixelsIntensityCam ... " << flush;
122 else
123 return kFALSE;
124
125 //
126 // Look for the MFillH-class "MHCalibrationBlindCam". In case yes, initialize the
127 // corresponding IntensityCam
128 //
129 if (pList->FindObject(AddSerialNumber("MHCalibrationBlindCam")))
130 {
131
132 *fLog << inf << "Found MHCalibrationBlindCam ... " << flush;
133
134 fIntensBlind = (MCalibrationIntensityBlindCam*)pList->FindCreateObj("MCalibrationIntensityBlindCam");
135 if (!fIntensBlind)
136 {
137 *fLog << err << "Could not find nor create MCalibrationIntensitBlindCam abort... " << endl;
138 return kFALSE;
139 }
140 }
141
142 //
143 // Look for the MFillH-class "MHCalibrationChargeCam". In case yes, initialize the
144 // corresponding IntensityCam
145 //
146 if (pList->FindObject(AddSerialNumber("MHCalibrationChargeCam")))
147 {
148
149 fIntensCharge = (MCalibrationIntensityChargeCam*)pList->FindCreateObj("MCalibrationIntensityChargeCam");
150 fIntensQE = (MCalibrationIntensityQECam*) pList->FindCreateObj("MCalibrationIntensityQECam");
151
152 if (!fChargeCalc)
153 fChargeCalc = (MCalibrationChargeCalc*)pList->FindObject("MCalibrationChargeCalc");
154
155 if (!fCalibrate)
156 fCalibrate = (MCalibrateData*)pList->FindObject("MCalibrateData");
157
158 *fLog << inf << "Found MHCalibrationChargeCam ... " << flush;
159
160 if (!fIntensCharge)
161 {
162 *fLog << err << "Could not find nor create MCalibrationIntensityChargeCam abort... " << endl;
163 return kFALSE;
164 }
165
166 if (!fIntensQE)
167 {
168 *fLog << err << "Could not find nor create MCalibrationIntensityQECam abort... " << endl;
169 return kFALSE;
170 }
171
172 if (!fChargeCalc)
173 {
174 *fLog << err << "Could not find MCalibrationChargeCalc abort... " << endl;
175 return kFALSE;
176 }
177
178 if (!fCalibrate)
179 {
180 *fLog << err << "Could not find MCalibrateData abort... " << endl;
181 return kFALSE;
182 }
183 }
184
185 //
186 // Look for the MFillH name "FillRelTimeCam". In case yes, initialize the
187 // corresponding IntensityCam
188 //
189 if (pList->FindObject(AddSerialNumber("MHCalibrationRelTimeCam")))
190 {
191
192 fIntensRelTime = (MCalibrationIntensityRelTimeCam*)pList->FindCreateObj("MCalibrationIntensityRelTimeCam");
193 if (!fRelTimeCalc)
194 fRelTimeCalc = (MCalibrationRelTimeCalc*)pList->FindObject(AddSerialNumber("MCalibrationRelTimeCalc"));
195
196 *fLog << inf << "Found MHCalibrationRelTimeCam ... " << flush;
197
198 if (!fIntensRelTime)
199 {
200 *fLog << err << "Could not find nor create MCalibrationIntensityRelTimeCam abort... " << endl;
201 return kFALSE;
202 }
203
204 if (!fRelTimeCalc)
205 {
206 *fLog << err << "Could not find MCalibrationRelTimeCalc abort... " << endl;
207 return kFALSE;
208 }
209 }
210
211 fNumCam = 0;
212 fNumEvents = 0;
213
214 return kTRUE;
215}
216
217// --------------------------------------------------------------------------
218//
219// - Initializes new containers in the
220// - Intensity Cams, if the number of calibration events has reach fNumEventsDump.
221// - Executes Finalize() of the MCalibration*Calc classes in that case.
222// - Sets the latest MCalibrationChargeCam as update class into MCalibrateData
223// - Initialize new MCalibration*Cams into the intensity cams.
224//
225Int_t MCalibCalcFromPast::Process()
226{
227
228 if (fNumEvents++ < fNumEventsDump)
229 return kTRUE;
230
231 fNumEvents = 0;
232 //
233 // Finalize Possible calibration histogram classes...
234 //
235 *fLog << inf << GetDescriptor() << ": Finalize calibration histograms: " << flush;
236
237 if (Finalize("MHCalibrationChargeCam")) *fLog << "MHCalibrationChargeCam..." << flush;
238 if (Finalize("MHCalibrationChargeBlindCam")) *fLog << "MHCalibrationChargeBlindCam..." << flush;
239 if (Finalize("MHCalibrationRelTimeCam")) *fLog << "MHCalibrationRelTimeCam..." << flush;
240
241 //
242 // Finalize possible calibration calculation tasks
243 //
244 *fLog << endl;
245 *fLog << inf << "Finalize calibration calculations..." << endl;
246 if (fChargeCalc)
247 fChargeCalc->Finalize();
248 if (fRelTimeCalc)
249 fRelTimeCalc->Finalize();
250 if (fCalibrate)
251 fCalibrate->UpdateConversionFactors(fUpdateWithFFactorMethod ? NULL :
252 (MCalibrationChargeCam*)fIntensCharge->GetCam());
253
254 ReInitialize();
255 return kTRUE;
256}
257
258
259// --------------------------------------------------------------------------
260//
261// Searches for name in the MParList and calls, if existing:
262// - MHCalibrationCam::Finalize()
263// - MHCalibrationCam::ResetHists()
264//
265Bool_t MCalibCalcFromPast::Finalize(const char* name)
266{
267
268 MHCalibrationCam *hist = (MHCalibrationCam*)fParList->FindObject(name);
269 if (hist)
270 {
271 hist->Finalize();
272 hist->ResetHists();
273 return kTRUE;
274 }
275
276 return kFALSE;
277
278}
279
280// --------------------------------------------------------------------------
281//
282// Re-Intitializes new containers inside the Intensity Cams.
283// From now on, a call to the IntensityCam functions returns pointers
284// to the newly created Containers.
285//
286Bool_t MCalibCalcFromPast::ReInitialize()
287{
288 fNumCam++;
289
290 *fLog << inf << "MCalibCalcFromPast::ReInitialize #" << fNumCam << " ";
291
292 const Int_t runnumber = fRunHeader->GetRunNumber();
293
294 if (fIntensBad)
295 {
296 fIntensBad->AddToList(Form("MBadPixelsCam%04d",fNumCam),*fGeom);
297 *fLog << "MBadPixelsCam...";
298 }
299
300 if (fIntensCharge)
301 {
302 fIntensCharge->AddToList(Form("MCalibrationChargeCam%04d",fNumCam),*fGeom);
303 fIntensCharge->GetCam()->SetRunNumber(runnumber);
304 *fLog << "MCalibrationChargeCam...";
305 }
306 if (fIntensQE)
307 {
308 fIntensQE->AddToList(Form("MCalibrationQECam%04d",fNumCam),*fGeom);
309 fIntensQE->GetCam()->SetRunNumber(runnumber);
310 *fLog << "MCalibrationQECam...";
311 }
312 if (fIntensBlind)
313 {
314 fIntensBlind->AddToList(Form("MCalibrationBlindCam%04d",fNumCam),*fGeom);
315 fIntensBlind->GetCam()->SetRunNumber(runnumber);
316 *fLog << "MCalibrationBlindCam...";
317 }
318
319 *fLog << endl;
320
321 return kTRUE;
322
323}
324
325Int_t MCalibCalcFromPast::PostProcess()
326{
327 *fLog << inf << "Number of Calibration Cams: " << fNumCam << endl;
328 return kTRUE;
329
330}
331
332// --------------------------------------------------------------------------
333//
334// Read the setup from a TEnv, eg:
335// MCalibCalcFromPast.UpdateWithFFactorMethod: Off, On
336// MCalibCalcFromPast.NumEventsDump: 500
337//
338Int_t MCalibCalcFromPast::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
339{
340 Bool_t rc = kFALSE;
341 if (IsEnvDefined(env, prefix, "UpdateWithFFactorMethod", print))
342 {
343 rc = kTRUE;
344 SetUpdateWithFFactorMethod(GetEnvValue(env, prefix, "UpdateWithFFactorMethod", fUpdateWithFFactorMethod));
345 }
346
347 if (IsEnvDefined(env, prefix, "NumEventsDump", print))
348 {
349 SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));
350 rc = kTRUE;
351 }
352
353 return rc;
354}
Note: See TracBrowser for help on using the repository browser.