source: trunk/MagicSoft/Mars/mcalib/MCalibColorSteer.cc@ 5064

Last change on this file since 5064 was 5056, checked in by gaug, 21 years ago
*** empty log message ***
File size: 11.2 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, 09/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24//////////////////////////////////////////////////////////////////////////////
25//
26// MCalibColorSteer
27//
28// Steers the occurrance of different calibration colours in one calibration
29// run.
30//
31// Input Containers:
32// MRawEvtHeader
33// MParList
34// MCalibrationIntensityChargeCam
35// MCalibrationIntensityRelTimeCam
36// MBadPixelsIntensityCam
37//
38// Output Containers:
39// MCalibrationIntensityChargeCam
40// MCalibrationIntensityRelTimeCam
41// MBadPixelsIntensityCam
42//
43//////////////////////////////////////////////////////////////////////////////
44#include "MCalibColorSteer.h"
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MParList.h"
50#include "MTaskList.h"
51
52#include "MHCalibrationCam.h"
53
54#include "MCalibrationIntensityChargeCam.h"
55#include "MCalibrationIntensityBlindCam.h"
56#include "MCalibrationIntensityQECam.h"
57#include "MCalibrationIntensityRelTimeCam.h"
58
59#include "MBadPixelsIntensityCam.h"
60
61#include "MCalibrationChargeCalc.h"
62#include "MCalibrationRelTimeCalc.h"
63
64#include "MRawEvtHeader.h"
65
66#include "MGeomCam.h"
67
68ClassImp(MCalibColorSteer);
69
70using namespace std;
71
72// --------------------------------------------------------------------------
73//
74// Default constructor.
75//
76MCalibColorSteer::MCalibColorSteer(const char *name, const char *title)
77 : fHeader(NULL), fGeom(NULL), fParList(NULL),
78 fIntensCharge(NULL), fIntensRelTime(NULL), fIntensBad(NULL),
79 fChargeCalc(NULL), fRelTimeCalc(NULL),
80 fPattern(0)
81{
82
83 fName = name ? name : "MCalibColorSteer";
84 fTitle = title ? title : "Task to steer the processing of different colours in the calibration events";
85
86}
87
88// -----------------------------------------------------------------------------------
89//
90// The following container are searched for and execution aborted if not in MParList:
91// - MRawEvtHeader
92// - MTaskList
93//
94Int_t MCalibColorSteer::PreProcess(MParList *pList)
95{
96
97 fHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
98 if (!fHeader)
99 {
100 *fLog << err << "MRawEvtHeader not found... abort." << endl;
101 return kFALSE;
102 }
103
104 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
105 if (!fGeom)
106 {
107 *fLog << err << "MGeomCam not found... abort." << endl;
108 return kFALSE;
109 }
110
111 fParList = pList;
112 if (!fParList)
113 {
114 *fLog << err << "MParList not found... abort." << endl;
115 return kFALSE;
116 }
117
118 MTaskList *tlist = (MTaskList*)pList->FindObject("MTaskList");
119 if (!tlist)
120 {
121 *fLog << err << "MTaskList not found... abort." << endl;
122 return kFALSE;
123 }
124
125 //
126 // Look for the MBadPixels Intensity Cam
127 //
128 fIntensBad = (MBadPixelsIntensityCam*)pList->FindCreateObj("MBadPixelsIntensityCam");
129
130 *fLog << inf << "Found MBadPixelsIntensityCam ... " << flush;
131 //
132 // Look for the MCalibrationIntensityBlindCam
133 //
134 fIntensBlind = (MCalibrationIntensityBlindCam*)pList->FindCreateObj("MCalibrationIntensityBlindCam");
135
136 *fLog << inf << "Found MCalibrationIntensityBlindCam ... " << flush;
137
138 //
139 // Look for the MFillH name "FillChargeCam". In case yes, initialize the
140 // corresponding IntensityCam
141 //
142 if (pList->FindObject(AddSerialNumber("MHCalibrationChargeCam")))
143 {
144
145 fIntensCharge = (MCalibrationIntensityChargeCam*)pList->FindCreateObj("MCalibrationIntensityChargeCam");
146 fIntensQE = (MCalibrationIntensityQECam*) pList->FindCreateObj("MCalibrationIntensityQECam");
147
148 fChargeCalc = (MCalibrationChargeCalc*)tlist->FindObject("MCalibrationChargeCalc");
149
150 *fLog << inf << "Found MHCalibrationChargeCam ... " << flush;
151
152 if (!fIntensCharge)
153 {
154 *fLog << err << "Could not find nor create MCalibrationIntensityChargeCam abort... " << endl;
155 return kFALSE;
156 }
157
158 if (!fIntensQE)
159 {
160 *fLog << err << "Could not find nor create MCalibrationIntensityQECam abort... " << endl;
161 return kFALSE;
162 }
163
164 if (!fChargeCalc)
165 {
166 *fLog << err << "Could not find MCalibrationChargeCalc abort... " << endl;
167 return kFALSE;
168 }
169 }
170
171 //
172 // Look for the MFillH name "FillRelTimeCam". In case yes, initialize the
173 // corresponding IntensityCam
174 //
175 if (pList->FindObject(AddSerialNumber("MHCalibrationRelTimeCam")))
176 {
177
178 fIntensRelTime = (MCalibrationIntensityRelTimeCam*)pList->FindCreateObj("MCalibrationIntensityRelTimeCam");
179 fRelTimeCalc = (MCalibrationRelTimeCalc*)tlist->FindObject(AddSerialNumber("MCalibrationRelTimeCalc"));
180
181 *fLog << inf << "Found MHCalibrationRelTimeCam ... " << flush;
182
183 if (!fIntensRelTime)
184 {
185 *fLog << err << "Could not find nor create MCalibrationIntensityRelTimeCam abort... " << endl;
186 return kFALSE;
187 }
188
189 if (!fRelTimeCalc)
190 {
191 *fLog << err << "Could not find MCalibrationRelTimeCalc abort... " << endl;
192 return kFALSE;
193 }
194 }
195
196 return kTRUE;
197}
198
199// --------------------------------------------------------------------------
200//
201// Reads the pattern from MRawEvtHeader and initializes new containers in the
202// Intensity Cams, if the pattern has changed
203//
204Int_t MCalibColorSteer::Process()
205{
206
207 const UInt_t pattern = fHeader->GetCalibrationPattern();
208
209 if (pattern == fPattern)
210 return kTRUE;
211
212 if (fPattern == 0)
213 {
214 fPattern = pattern;
215 return kTRUE;
216 }
217
218 fPattern = pattern;
219
220 //
221 // Finalize Possible calibration histogram classes...
222 //
223 *fLog << inf << GetDescriptor() << " : Finalize calibration histograms..." << flush;
224 if (Finalize("MHCalibrationChargeCam")) *fLog << "MHCalibrationChargeCam";
225 if (Finalize("MHCalibrationChargeBlindCam")) *fLog << "MHCalibrationChargeBlindCam";
226 if (Finalize("MHCalibrationRelTimeCam")) *fLog << "MHCalibrationRelTimeCam";
227 if (Finalize("MHCalibrationTestCam")) *fLog << "MHCalibrationChargeCam";
228 if (Finalize("MHCalibrationTestTimeCam")) *fLog << "MHCalibrationChargeCam";
229
230 //
231 // Finalize possible calibration calculation tasks
232 //
233 *fLog << endl;
234 *fLog << inf << GetDescriptor() << " : Finalize calibration calculations..." << flush;
235 if (fChargeCalc)
236 fChargeCalc->CallPostProcess();
237 if (fRelTimeCalc)
238 fRelTimeCalc->CallPostProcess();
239
240 ReInitialize();
241
242 return kTRUE;
243}
244
245// --------------------------------------------------------------------------
246//
247// Searches for name in the MParList and calls, if existing:
248// - MHCalibrationCam::Finalize()
249// - MHCalibrationCam::ResetHists()
250//
251Bool_t MCalibColorSteer::Finalize(const char* name)
252{
253
254 MHCalibrationCam *hist = (MHCalibrationCam*)fParList->FindObject(name);
255 if (hist)
256 {
257 hist->Finalize();
258 hist->ResetHists();
259 return kTRUE;
260 }
261
262 return kFALSE;
263
264}
265
266// --------------------------------------------------------------------------
267//
268// Re-Intitializes new containers inside the Intensity Cams.
269// From now on, a call to the IntensityCam functions returns pointers
270// to the newly created Containers.
271//
272Bool_t MCalibColorSteer::ReInitialize()
273{
274
275 *fLog << endl;
276
277 if (fIntensBad)
278 {
279 fIntensBad->AddToList(Form("MBadPixelsCam%s",GetNamePattern()),*fGeom);
280 *fLog << inf << "New MBadPixelsCam with " << GetNamePattern() << endl;
281 }
282 if (fIntensCharge)
283 {
284 fIntensCharge->AddToList(Form("MCalibrationChargeCam%s",GetNamePattern()),*fGeom);
285 *fLog << inf << "New MCalibrationChargeCam with " << GetNamePattern() << endl;
286 }
287 if (fIntensQE)
288 {
289 fIntensQE->AddToList(Form("MCalibrationQECam%s",GetNamePattern()),*fGeom);
290 *fLog << inf << "New MCalibrationQECam with " << GetNamePattern() << endl;
291 }
292 if (fIntensBlind)
293 {
294 fIntensBlind->AddToList(Form("MCalibrationBlindCam%s",GetNamePattern()),*fGeom);
295 *fLog << inf << "New MCalibrationBlindCam with " << GetNamePattern() << endl;
296 }
297
298 return kTRUE;
299
300}
301
302const char* MCalibColorSteer::GetNamePattern()
303{
304
305 Float_t number[MCalibrationCam::gkNumPulserColors];
306 memset(number,0,MCalibrationCam::gkNumPulserColors*sizeof(Float_t));
307
308 enum ColorCode_t
309 {
310 k5LedGreen = BIT(0 ),
311 k2LedGreen = BIT(1 ),
312 k5LedBlue2 = BIT(2 ),
313 k1LedUV = BIT(3 ),
314 k2LedUV = BIT(4 ),
315 k5LedBlue3 = BIT(5 ),
316 k5LedBlue4 = BIT(6 ),
317 k2LedBlue = BIT(7 ),
318 k01LedBlue = BIT(8 ),
319 k1LedBlue = BIT(10),
320 k5LedUV1 = BIT(11),
321 k5LedUV2 = BIT(12),
322 k5LedBlue1 = BIT(13),
323 k1LedGreen = BIT(14),
324 k01LedGreen = BIT(15),
325 kCT1Pulser = BIT(16)
326 };
327
328 if (fPattern & k5LedGreen)
329 number[MCalibrationCam::kGREEN] += 5;
330 if (fPattern & k2LedGreen)
331 number[MCalibrationCam::kGREEN] += 2;
332 if (fPattern & k5LedBlue2)
333 number[MCalibrationCam::kBLUE] += 2;
334 if (fPattern & k1LedUV)
335 number[MCalibrationCam::kUV] += 1;
336 if (fPattern & k2LedUV)
337 number[MCalibrationCam::kUV] += 2;
338 if (fPattern & k5LedBlue3)
339 number[MCalibrationCam::kBLUE] += 5;
340 if (fPattern & k5LedBlue4)
341 number[MCalibrationCam::kBLUE] += 5;
342 if (fPattern & k2LedBlue)
343 number[MCalibrationCam::kBLUE] += 2;
344 if (fPattern & k01LedBlue)
345 number[MCalibrationCam::kBLUE] += 0.5;
346 if (fPattern & k1LedBlue)
347 number[MCalibrationCam::kBLUE] += 1;
348 if (fPattern & k5LedUV1)
349 number[MCalibrationCam::kUV] += 5;
350 if (fPattern & k5LedUV2)
351 number[MCalibrationCam::kUV] += 5;
352 if (fPattern & k5LedBlue1)
353 number[MCalibrationCam::kBLUE] += 5;
354 if (fPattern & k1LedGreen)
355 number[MCalibrationCam::kGREEN] += 1;
356 if (fPattern & k01LedGreen)
357 number[MCalibrationCam::kGREEN] += 0.5;
358 if (fPattern & kCT1Pulser)
359 number[MCalibrationCam::kCT1] += 1;
360
361 TString result = "";
362
363 for (Int_t i=0; i<MCalibrationCam::gkNumPulserColors; i++)
364 {
365 switch (i)
366 {
367 case MCalibrationCam::kGREEN:
368 if (number[i] > 0.1)
369 {
370 result += number[i];
371 result += "GREEN";
372 }
373 break;
374 case MCalibrationCam::kBLUE:
375 if (number[i] > 0.1)
376 {
377 result += number[i];
378 result += "BLUE";
379 }
380 break;
381 case MCalibrationCam::kUV:
382 if (number[i] > 0.1)
383 {
384 result += number[i];
385 result += "UV";
386 }
387 break;
388 case MCalibrationCam::kCT1:
389 if (number[i] > 0.1)
390 result += "CT1";
391 break;
392 }
393 }
394 return result.Data();
395}
Note: See TracBrowser for help on using the repository browser.