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

Last change on this file since 8425 was 8425, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 12.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//
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 "MCalibrationIntensityRelTimeCam.h"
62
63#include "MCalibrationPattern.h"
64#include "MCalibrationQECam.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 *fLog << inf << "Found MHCalibrationChargeCam ... " << flush;
159
160 fIntensCharge = (MCalibrationIntensityChargeCam*)pList->FindCreateObj("MCalibrationIntensityChargeCam");
161 if (!fIntensCharge)
162 return kFALSE;
163
164 fQECam = (MCalibrationQECam*)pList->FindCreateObj("MCalibrationQECam");
165 if (!fQECam)
166 return kFALSE;
167
168 fChargeCalc = (MCalibrationChargeCalc*)tlist->FindObject("MCalibrationChargeCalc");
169 if (!fChargeCalc)
170 {
171 *fLog << err << "Could not find MCalibrationChargeCalc abort... " << endl;
172 return kFALSE;
173 }
174 }
175
176 //
177 // Look for the MFillH name "FillRelTimeCam". In case yes, initialize the
178 // corresponding IntensityCam
179 //
180 if (pList->FindObject(AddSerialNumber("MHCalibrationRelTimeCam")))
181 {
182
183 fIntensRelTime = (MCalibrationIntensityRelTimeCam*)pList->FindCreateObj("MCalibrationIntensityRelTimeCam");
184 fRelTimeCalc = (MCalibrationRelTimeCalc*)tlist->FindObject(AddSerialNumber("MCalibrationRelTimeCalc"));
185
186 *fLog << inf << "Found MHCalibrationRelTimeCam ... " << flush;
187
188 if (!fIntensRelTime)
189 {
190 *fLog << err << "Could not find nor create MCalibrationIntensityRelTimeCam abort... " << endl;
191 return kFALSE;
192 }
193
194 if (!fRelTimeCalc)
195 {
196 *fLog << err << "Could not find MCalibrationRelTimeCalc abort... " << endl;
197 return kFALSE;
198 }
199 }
200
201 fColor = MCalibrationCam::kNONE;
202 fStrength = 0.;
203
204 return kTRUE;
205}
206
207// --------------------------------------------------------------------------
208//
209// Reads the pattern from MCalibrationPattern and initializes new containers in the
210// Intensity Cams, if the pattern has changed. Executes Finalize of the
211// MCalibration*Calc classes in that case.
212//
213Int_t MCalibColorSteer::Process()
214{
215
216 const MCalibrationCam::PulserColor_t col = fCalibPattern->GetPulserColor();
217 const Float_t strength = fCalibPattern->GetPulserStrength();
218
219 if (fColor ==MCalibrationCam::kNONE)
220 {
221 fColor = col;
222 fStrength = strength;
223 return kTRUE;
224 }
225
226 const Float_t strdiff = TMath::Abs(fStrength-strength);
227
228 if (col == MCalibrationCam::kNONE || (col == fColor && strdiff < 0.05))
229 return kTRUE;
230
231 *fLog << inf << GetDescriptor() << " : Color - old=" << fColor << flush;
232 fColor = col;
233 *fLog << " / new=" << fColor << endl;
234
235 *fLog << inf << GetDescriptor() << " : Strength - old=" << fStrength << flush;
236 fStrength = strength;
237 *fLog << " / new=" << fStrength << endl;
238
239 //
240 // Finalize Possible calibration histogram classes...
241 //
242 *fLog << inf << GetDescriptor() << " : Finalize calibration histograms..." << flush;
243 if (Finalize("MHCalibrationChargeCam")) *fLog << "MHCalibrationChargeCam...";
244 if (Finalize("MHCalibrationChargeBlindCam")) *fLog << "MHCalibrationChargeBlindCam...";
245 if (Finalize("MHCalibrationRelTimeCam")) *fLog << "MHCalibrationRelTimeCam...";
246 if (Finalize("MHCalibrationTestCam")) *fLog << "MHCalibrationChargeCam...";
247 if (Finalize("MHCalibrationTestTimeCam")) *fLog << "MHCalibrationChargeCam...";
248
249 //
250 // Finalize possible calibration calculation tasks
251 //
252 *fLog << endl;
253 *fLog << inf << GetDescriptor() << " : Finalize calibration calculations..." << flush;
254 if (fChargeCalc)
255 fChargeCalc->Finalize();
256 if (fRelTimeCalc)
257 fRelTimeCalc->Finalize();
258
259 ReInitialize();
260
261 return kTRUE;
262}
263
264// --------------------------------------------------------------------------
265//
266// Reads the pattern from MCalibrationPattern and initializes new containers in the
267// Intensity Cams, if the pattern has changed. Executes Finalize of the
268// MCalibration*Calc classes in that case.
269//
270Int_t MCalibColorSteer::PostProcess()
271{
272 //
273 // Finalize Possible calibration histogram classes...
274 //
275 *fLog << inf << "Finalize calibration histograms..." << flush;
276 if (Finalize("MHCalibrationChargeCam")) *fLog << inf << "MHCalibrationChargeCam..." << flush;
277 if (Finalize("MHCalibrationChargeBlindCam")) *fLog << inf << "MHCalibrationChargeBlindCam..." << flush;
278 if (Finalize("MHCalibrationRelTimeCam")) *fLog << inf << "MHCalibrationRelTimeCam..." << flush;
279 if (Finalize("MHCalibrationTestCam")) *fLog << inf << "MHCalibrationChargeCam..." << flush;
280 if (Finalize("MHCalibrationTestTimeCam")) *fLog << inf << "MHCalibrationChargeCam..." << flush;
281 *fLog << inf << "done." << endl;
282
283 return kTRUE;
284}
285
286// --------------------------------------------------------------------------
287//
288// Searches for name in the MParList and calls, if existing:
289// - MHCalibrationCam::Finalize()
290// - MHCalibrationCam::ResetHists()
291//
292Bool_t MCalibColorSteer::Finalize(const char* name)
293{
294
295 MHCalibrationCam *hist = (MHCalibrationCam*)fParList->FindObject(name);
296 if (!hist)
297 return kFALSE;
298
299 hist->Finalize();
300 CopyHist(name);
301 hist->ResetHists();
302 hist->SetColor( fCalibPattern->GetPulserColor());
303 return kTRUE;
304}
305
306// --------------------------------------------------------------------------
307//
308// Re-Intitializes new containers inside the Intensity Cams.
309// From now on, a call to the IntensityCam functions returns pointers
310// to the newly created Containers.
311//
312Bool_t MCalibColorSteer::ReInitialize()
313{
314
315 *fLog << endl;
316
317 TString namep = GetNamePattern();
318
319 fBad->Clear(); // FIXME:::::: MERGE PreExcl!!!!
320 fQECam->Clear();
321
322 if (fIntensCharge)
323 {
324 MCalibrationChargeCam *oldcam = (MCalibrationChargeCam*)fIntensCharge->GetCam();
325 fIntensCharge->AddToList(Form("MCalibrationChargeCam%s",namep.Data()),*fGeom);
326 MCalibrationChargeCam *cam = (MCalibrationChargeCam*)fIntensCharge->GetCam();
327 cam->SetPulserColor(fCalibPattern->GetPulserColor());
328 if (!cam->MergeHiLoConversionFactors(*oldcam))
329 return kFALSE;
330 *fLog << inf << "New MCalibrationChargeCam with name: " << cam->GetName() << endl;
331 }
332
333 if (fIntensBlind)
334 {
335 fIntensBlind->AddToList(Form("MCalibrationBlindCam%s",namep.Data()),*fGeom);
336 MCalibrationCam *cam = fIntensBlind->GetCam();
337 cam->SetPulserColor(fCalibPattern->GetPulserColor());
338 *fLog << inf << "New MCalibrationBlindCam with name: " << cam->GetName() << endl;
339 }
340
341 if (fIntensRelTime)
342 {
343 fIntensRelTime->AddToList(Form("MCalibrationRelTimeCam%s",namep.Data()),*fGeom);
344 MCalibrationCam *cam = fIntensRelTime->GetCam();
345 cam->SetPulserColor(fCalibPattern->GetPulserColor());
346 *fLog << inf << "New MCalibrationRelTimeCam with name: " << cam->GetName() << endl;
347 }
348
349 return kTRUE;
350
351}
352
353TString MCalibColorSteer::GetNamePattern()
354{
355
356 const Float_t strength = fCalibPattern->GetPulserStrength();
357 const MCalibrationCam::PulserColor_t col = fCalibPattern->GetPulserColor();
358
359 TString result = Form("%2.1f",strength);
360
361 switch (col)
362 {
363 case MCalibrationCam::kCT1:
364 result += "CT1";
365 break;
366 case MCalibrationCam::kGREEN:
367 result += "GREEN";
368 break;
369 case MCalibrationCam::kBLUE:
370 result += "BLUE";
371 break;
372 case MCalibrationCam::kUV:
373 result += "UV";
374 break;
375 default:
376 break;
377 }
378 return result;
379}
380
381// --------------------------------------------------------------------------
382//
383// Copies the histogram classes into the intensity cams
384//
385void MCalibColorSteer::CopyHist(const char* name)
386{
387 MHCalibrationCam *hcam = (MHCalibrationCam*)fParList->FindObject(name);
388 TString n(name);
389 if (n.Contains("ChargeCam"))
390 {
391 if (fIntensCharge)
392 fIntensCharge->AddHist((MHCalibrationCam*)hcam->Clone());
393 }
394 if (n.Contains("Blind"))
395 if (fIntensBlind)
396 fIntensBlind->AddHist((MHCalibrationCam*)hcam->Clone());
397
398 if (n.Contains("RelTime"))
399 if (fIntensRelTime)
400 fIntensRelTime->AddHist((MHCalibrationCam*)hcam->Clone());
401}
402
403// --------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.