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

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