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

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