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

Last change on this file since 7090 was 7005, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 13.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, 09/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MCalibColorSteer
28//
29// Steers the occurrance of different calibration colours in one calibration
30// run.
31//
32// Input Containers:
33// MCalibrationPattern
34// MParList
35// MCalibrationIntensityChargeCam
36// MCalibrationIntensityRelTimeCam
37// MBadPixelsIntensityCam
38//
39// Output Containers:
40// MCalibrationIntensityChargeCam
41// MCalibrationIntensityRelTimeCam
42// MBadPixelsIntensityCam
43//
44//////////////////////////////////////////////////////////////////////////////
45#include "MCalibColorSteer.h"
46
47#include "MLog.h"
48#include "MLogManip.h"
49
50#include "MParList.h"
51#include "MTaskList.h"
52
53#include "MHCalibrationCam.h"
54#include "MCalibrationChargeCam.h"
55#include "MCalibrationBlindCam.h"
56
57#include "MCalibrationIntensityChargeCam.h"
58#include "MCalibrationIntensityBlindCam.h"
59#include "MCalibrationIntensityQECam.h"
60#include "MCalibrationIntensityRelTimeCam.h"
61
62#include "MBadPixelsIntensityCam.h"
63
64#include "MCalibrationChargeCam.h"
65#include "MCalibrationChargeCalc.h"
66#include "MCalibrationRelTimeCalc.h"
67
68#include "MRawRunHeader.h"
69#include "MCalibrationPattern.h"
70
71#include "MGeomCam.h"
72
73ClassImp(MCalibColorSteer);
74
75using namespace std;
76
77// --------------------------------------------------------------------------
78//
79// Default constructor.
80//
81MCalibColorSteer::MCalibColorSteer(const char *name, const char *title)
82 : fCalibPattern(NULL), fGeom(NULL), fParList(NULL),
83 fIntensCharge(NULL), fIntensRelTime(NULL), fIntensBad(NULL),
84 fBad(NULL), fChargeCalc(NULL), fRelTimeCalc(NULL), fHistCopy(kFALSE)
85{
86
87 fName = name ? name : "MCalibColorSteer";
88 fTitle = title ? title : "Task to steer the processing of different colours in the calibration events";
89
90}
91
92// -----------------------------------------------------------------------------------
93//
94// The following container are searched for and execution aborted if not in MParList:
95// - MCalibrationPattern
96// - MTaskList
97//
98Int_t MCalibColorSteer::PreProcess(MParList *pList)
99{
100
101 fCalibPattern = (MCalibrationPattern*)pList->FindObject("MCalibrationPattern");
102 if (!fCalibPattern)
103 {
104 *fLog << err << "MCalibrationPattern not found... abort." << endl;
105 return kFALSE;
106 }
107
108 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
109 if (!fRunHeader)
110 {
111 *fLog << err << "MRawRunHeader not found... abort." << endl;
112 return kFALSE;
113 }
114
115 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
116 if (!fGeom)
117 {
118 *fLog << err << "MGeomCam not found... abort." << endl;
119 return kFALSE;
120 }
121
122 fParList = pList;
123 if (!fParList)
124 {
125 *fLog << err << "MParList not found... abort." << endl;
126 return kFALSE;
127 }
128
129 MTaskList *tlist = (MTaskList*)pList->FindObject("MTaskList");
130 if (!tlist)
131 {
132 *fLog << err << "MTaskList not found... abort." << endl;
133 return kFALSE;
134 }
135
136 //
137 // Look for the MBadPixels Intensity Cam
138 //
139 fIntensBad = (MBadPixelsIntensityCam*)pList->FindCreateObj("MBadPixelsIntensityCam");
140 if (fIntensBad)
141 *fLog << inf << "Found MBadPixelsIntensityCam ... " << flush;
142 else
143 return kFALSE;
144
145 //
146 // Look for the MBadPixels Intensity Cam
147 //
148 fBad = (MBadPixelsCam*)pList->FindObject("MBadPixelsCam");
149 if (fBad)
150 {
151 *fLog << inf << "Found also MBadPixelsCam ... " << flush;
152 fIntensBad->GetCam()->Merge(*fBad);
153 }
154 else
155 return kFALSE;
156
157 //
158 // Look for the MCalibrationIntensityBlindCam
159 //
160 fIntensBlind = (MCalibrationIntensityBlindCam*)pList->FindCreateObj("MCalibrationIntensityBlindCam");
161
162 if (fIntensBlind)
163 *fLog << inf << "Found MCalibrationIntensityBlindCam ... " << flush;
164 else
165 return kFALSE;
166
167 //
168 // Look for the MFillH name "FillChargeCam". In case yes, initialize the
169 // corresponding IntensityCam
170 //
171 if (pList->FindObject(AddSerialNumber("MHCalibrationChargeCam")))
172 {
173
174 fIntensCharge = (MCalibrationIntensityChargeCam*)pList->FindCreateObj("MCalibrationIntensityChargeCam");
175 fIntensQE = (MCalibrationIntensityQECam*) pList->FindCreateObj("MCalibrationIntensityQECam");
176
177 fChargeCalc = (MCalibrationChargeCalc*)tlist->FindObject("MCalibrationChargeCalc");
178
179 *fLog << inf << "Found MHCalibrationChargeCam ... " << flush;
180
181 if (!fIntensCharge)
182 {
183 *fLog << err << "Could not find nor create MCalibrationIntensityChargeCam abort... " << endl;
184 return kFALSE;
185 }
186
187 if (!fIntensQE)
188 {
189 *fLog << err << "Could not find nor create MCalibrationIntensityQECam abort... " << endl;
190 return kFALSE;
191 }
192
193 if (!fChargeCalc)
194 {
195 *fLog << err << "Could not find MCalibrationChargeCalc abort... " << endl;
196 return kFALSE;
197 }
198 }
199
200 //
201 // Look for the MFillH name "FillRelTimeCam". In case yes, initialize the
202 // corresponding IntensityCam
203 //
204 if (pList->FindObject(AddSerialNumber("MHCalibrationRelTimeCam")))
205 {
206
207 fIntensRelTime = (MCalibrationIntensityRelTimeCam*)pList->FindCreateObj("MCalibrationIntensityRelTimeCam");
208 fRelTimeCalc = (MCalibrationRelTimeCalc*)tlist->FindObject(AddSerialNumber("MCalibrationRelTimeCalc"));
209
210 *fLog << inf << "Found MHCalibrationRelTimeCam ... " << flush;
211
212 if (!fIntensRelTime)
213 {
214 *fLog << err << "Could not find nor create MCalibrationIntensityRelTimeCam abort... " << endl;
215 return kFALSE;
216 }
217
218 if (!fRelTimeCalc)
219 {
220 *fLog << err << "Could not find MCalibrationRelTimeCalc abort... " << endl;
221 return kFALSE;
222 }
223 }
224
225 fColor = MCalibrationCam::kNONE;
226 fStrength = 0.;
227
228 return kTRUE;
229}
230
231// --------------------------------------------------------------------------
232//
233// Reads the pattern from MCalibrationPattern and initializes new containers in the
234// Intensity Cams, if the pattern has changed. Executes Finalize of the
235// MCalibration*Calc classes in that case.
236//
237Int_t MCalibColorSteer::Process()
238{
239
240 const MCalibrationCam::PulserColor_t col = fCalibPattern->GetPulserColor();
241 const Float_t strength = fCalibPattern->GetPulserStrength();
242
243 if (fColor ==MCalibrationCam::kNONE)
244 {
245 fColor = col;
246 fStrength = strength;
247 return kTRUE;
248 }
249
250 const Float_t strdiff = TMath::Abs(fStrength-strength);
251
252 if (col == MCalibrationCam::kNONE || (col == fColor && strdiff < 0.05))
253 return kTRUE;
254
255 *fLog << inf << GetDescriptor() << " : Color - old=" << fColor << flush;
256 fColor = col;
257 *fLog << " / new=" << fColor << endl;
258
259 *fLog << inf << GetDescriptor() << " : Strength - old=" << fStrength << flush;
260 fStrength = strength;
261 *fLog << " / new=" << fStrength << endl;
262
263 //
264 // Finalize Possible calibration histogram classes...
265 //
266 *fLog << inf << GetDescriptor() << " : Finalize calibration histograms..." << flush;
267 if (Finalize("MHCalibrationChargeCam")) *fLog << "MHCalibrationChargeCam...";
268 if (Finalize("MHCalibrationChargeBlindCam")) *fLog << "MHCalibrationChargeBlindCam...";
269 if (Finalize("MHCalibrationRelTimeCam")) *fLog << "MHCalibrationRelTimeCam...";
270 if (Finalize("MHCalibrationTestCam")) *fLog << "MHCalibrationChargeCam...";
271 if (Finalize("MHCalibrationTestTimeCam")) *fLog << "MHCalibrationChargeCam...";
272
273 //
274 // Finalize possible calibration calculation tasks
275 //
276 *fLog << endl;
277 *fLog << inf << GetDescriptor() << " : Finalize calibration calculations..." << flush;
278 if (fChargeCalc)
279 fChargeCalc->Finalize();
280 if (fRelTimeCalc)
281 fRelTimeCalc->Finalize();
282
283 ReInitialize();
284
285 return kTRUE;
286}
287
288// --------------------------------------------------------------------------
289//
290// Reads the pattern from MCalibrationPattern and initializes new containers in the
291// Intensity Cams, if the pattern has changed. Executes Finalize of the
292// MCalibration*Calc classes in that case.
293//
294Int_t MCalibColorSteer::PostProcess()
295{
296 //
297 // Finalize Possible calibration histogram classes...
298 //
299 *fLog << inf << "Finalize calibration histograms..." << flush;
300 if (Finalize("MHCalibrationChargeCam")) *fLog << inf << "MHCalibrationChargeCam..." << flush;
301 if (Finalize("MHCalibrationChargeBlindCam")) *fLog << inf << "MHCalibrationChargeBlindCam..." << flush;
302 if (Finalize("MHCalibrationRelTimeCam")) *fLog << inf << "MHCalibrationRelTimeCam..." << flush;
303 if (Finalize("MHCalibrationTestCam")) *fLog << inf << "MHCalibrationChargeCam..." << flush;
304 if (Finalize("MHCalibrationTestTimeCam")) *fLog << inf << "MHCalibrationChargeCam..." << flush;
305 *fLog << inf << "done." << endl;
306
307 return kTRUE;
308}
309
310// --------------------------------------------------------------------------
311//
312// Searches for name in the MParList and calls, if existing:
313// - MHCalibrationCam::Finalize()
314// - MHCalibrationCam::ResetHists()
315//
316Bool_t MCalibColorSteer::Finalize(const char* name)
317{
318
319 MHCalibrationCam *hist = (MHCalibrationCam*)fParList->FindObject(name);
320 if (!hist)
321 return kFALSE;
322
323 hist->Finalize();
324 CopyHist(name);
325 hist->ResetHists();
326 hist->SetColor( fCalibPattern->GetPulserColor());
327 return kTRUE;
328}
329
330// --------------------------------------------------------------------------
331//
332// Re-Intitializes new containers inside the Intensity Cams.
333// From now on, a call to the IntensityCam functions returns pointers
334// to the newly created Containers.
335//
336Bool_t MCalibColorSteer::ReInitialize()
337{
338
339 *fLog << endl;
340
341 TString namep = GetNamePattern();
342
343 if (fIntensBad)
344 {
345 fIntensBad->AddToList(Form("MBadPixelsCam%s",namep.Data()),*fGeom);
346 *fLog << inf << "New MBadPixelsCam with " << namep << endl;
347 fIntensBad->GetCam()->Merge(*fBad);
348 *fLog << inf << "Merged new MBadPixelsCam with first of list" << endl;
349 }
350 if (fIntensCharge)
351 {
352 MCalibrationChargeCam *oldcam = (MCalibrationChargeCam*)fIntensCharge->GetCam();
353 fIntensCharge->AddToList(Form("MCalibrationChargeCam%s",namep.Data()),*fGeom);
354 MCalibrationChargeCam *cam = (MCalibrationChargeCam*)fIntensCharge->GetCam();
355 cam->SetPulserColor(fCalibPattern->GetPulserColor());
356 if (!cam->MergeHiLoConversionFactors(*oldcam))
357 return kFALSE;
358 *fLog << inf << "New MCalibrationChargeCam with name: " << cam->GetName() << endl;
359 }
360 if (fIntensQE)
361 {
362 fIntensQE->AddToList(Form("MCalibrationQECam%s",namep.Data()),*fGeom);
363 *fLog << inf << "New MCalibrationQECam with: " << namep << endl;
364 }
365
366 if (fIntensBlind)
367 {
368 fIntensBlind->AddToList(Form("MCalibrationBlindCam%s",namep.Data()),*fGeom);
369 MCalibrationCam *cam = fIntensBlind->GetCam();
370 cam->SetPulserColor(fCalibPattern->GetPulserColor());
371 *fLog << inf << "New MCalibrationBlindCam with name: " << cam->GetName() << endl;
372 }
373
374 if (fIntensRelTime)
375 {
376 fIntensRelTime->AddToList(Form("MCalibrationRelTimeCam%s",namep.Data()),*fGeom);
377 MCalibrationCam *cam = fIntensRelTime->GetCam();
378 cam->SetPulserColor(fCalibPattern->GetPulserColor());
379 *fLog << inf << "New MCalibrationRelTimeCam with name: " << cam->GetName() << endl;
380 }
381
382 return kTRUE;
383
384}
385
386TString MCalibColorSteer::GetNamePattern()
387{
388
389 const Float_t strength = fCalibPattern->GetPulserStrength();
390 const MCalibrationCam::PulserColor_t col = fCalibPattern->GetPulserColor();
391
392 TString result = Form("%2.1f",strength);
393
394 switch (col)
395 {
396 case MCalibrationCam::kCT1:
397 result += "CT1";
398 break;
399 case MCalibrationCam::kGREEN:
400 result += "GREEN";
401 break;
402 case MCalibrationCam::kBLUE:
403 result += "BLUE";
404 break;
405 case MCalibrationCam::kUV:
406 result += "UV";
407 break;
408 default:
409 break;
410 }
411 return result;
412}
413
414// --------------------------------------------------------------------------
415//
416// Copies the histogram classes into the intensity cams
417//
418void MCalibColorSteer::CopyHist(const char* name)
419{
420 MHCalibrationCam *hcam = (MHCalibrationCam*)fParList->FindObject(name);
421 TString n(name);
422 if (n.Contains("ChargeCam"))
423 {
424 if (fIntensCharge)
425 fIntensCharge->AddHist((MHCalibrationCam*)hcam->Clone());
426 }
427 if (n.Contains("Blind"))
428 if (fIntensBlind)
429 fIntensBlind->AddHist((MHCalibrationCam*)hcam->Clone());
430
431 if (n.Contains("RelTime"))
432 if (fIntensRelTime)
433 fIntensRelTime->AddHist((MHCalibrationCam*)hcam->Clone());
434}
435
436// --------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.