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