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

Last change on this file since 8430 was 8428, checked in by tbretz, 18 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//
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//
37// Output Containers:
38// MCalibrationIntensityChargeCam
39//
40//////////////////////////////////////////////////////////////////////////////
41#include "MCalibColorSteer.h"
42
43#include "MLog.h"
44#include "MLogManip.h"
45
46#include "MParList.h"
47#include "MTaskList.h"
48
49#include "MGeomCam.h"
50#include "MRawRunHeader.h"
51
52#include "MHCalibrationCam.h"
53#include "MCalibrationChargeCam.h"
54#include "MCalibrationBlindCam.h"
55#include "MBadPixelsCam.h"
56
57#include "MCalibrationIntensityChargeCam.h"
58
59#include "MCalibrationPattern.h"
60#include "MCalibrationQECam.h"
61#include "MCalibrationBlindCam.h"
62
63#include "MCalibrationChargeCam.h"
64#include "MCalibrationChargeCalc.h"
65
66#include "MCalibrationRelTimeCam.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),
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 *fLog << inf << "Found MHCalibrationRelTimeCam ... " << flush;
181
182 fRelTimeCam = (MCalibrationRelTimeCam*)pList->FindCreateObj("MCalibrationRelTimeCam");
183 if (!fRelTimeCam)
184 return kFALSE;
185
186 fRelTimeCalc = (MCalibrationRelTimeCalc*)tlist->FindObject(AddSerialNumber("MCalibrationRelTimeCalc"));
187 if (!fRelTimeCalc)
188 return kFALSE;
189
190 // CALL ITS PrePorcess ???
191 }
192
193 fColor = MCalibrationCam::kNONE;
194 fStrength = 0.;
195
196 return kTRUE;
197}
198
199// --------------------------------------------------------------------------
200//
201// Reads the pattern from MCalibrationPattern and initializes new containers in the
202// Intensity Cams, if the pattern has changed. Executes Finalize of the
203// MCalibration*Calc classes in that case.
204//
205Int_t MCalibColorSteer::Process()
206{
207
208 const MCalibrationCam::PulserColor_t col = fCalibPattern->GetPulserColor();
209 const Float_t strength = fCalibPattern->GetPulserStrength();
210
211 if (fColor ==MCalibrationCam::kNONE)
212 {
213 fColor = col;
214 fStrength = strength;
215 return kTRUE;
216 }
217
218 const Float_t strdiff = TMath::Abs(fStrength-strength);
219
220 if (col == MCalibrationCam::kNONE || (col == fColor && strdiff < 0.05))
221 return kTRUE;
222
223 *fLog << inf << GetDescriptor() << " : Color - old=" << fColor << flush;
224 fColor = col;
225 *fLog << " / new=" << fColor << endl;
226
227 *fLog << inf << GetDescriptor() << " : Strength - old=" << fStrength << flush;
228 fStrength = strength;
229 *fLog << " / new=" << fStrength << endl;
230
231 //
232 // Finalize Possible calibration histogram classes...
233 //
234 *fLog << inf << GetDescriptor() << " : Finalize calibration histograms..." << flush;
235 if (Finalize("MHCalibrationChargeCam")) *fLog << "MHCalibrationChargeCam...";
236 if (Finalize("MHCalibrationChargeBlindCam")) *fLog << "MHCalibrationChargeBlindCam...";
237 if (Finalize("MHCalibrationRelTimeCam")) *fLog << "MHCalibrationRelTimeCam...";
238 if (Finalize("MHCalibrationTestCam")) *fLog << "MHCalibrationChargeCam...";
239 if (Finalize("MHCalibrationTestTimeCam")) *fLog << "MHCalibrationChargeCam...";
240
241 //
242 // Finalize possible calibration calculation tasks
243 //
244 *fLog << endl;
245 *fLog << inf << GetDescriptor() << " : Finalize calibration calculations..." << flush;
246 if (fChargeCalc)
247 fChargeCalc->Finalize();
248 if (fRelTimeCalc)
249 fRelTimeCalc->Finalize();
250
251 ReInitialize();
252
253 return kTRUE;
254}
255
256// --------------------------------------------------------------------------
257//
258// Reads the pattern from MCalibrationPattern and initializes new containers in the
259// Intensity Cams, if the pattern has changed. Executes Finalize of the
260// MCalibration*Calc classes in that case.
261//
262Int_t MCalibColorSteer::PostProcess()
263{
264 //
265 // Finalize Possible calibration histogram classes...
266 //
267 *fLog << inf << "Finalize calibration histograms..." << flush;
268 if (Finalize("MHCalibrationChargeCam")) *fLog << inf << "MHCalibrationChargeCam..." << flush;
269 if (Finalize("MHCalibrationChargeBlindCam")) *fLog << inf << "MHCalibrationChargeBlindCam..." << flush;
270 if (Finalize("MHCalibrationRelTimeCam")) *fLog << inf << "MHCalibrationRelTimeCam..." << flush;
271 if (Finalize("MHCalibrationTestCam")) *fLog << inf << "MHCalibrationChargeCam..." << flush;
272 if (Finalize("MHCalibrationTestTimeCam")) *fLog << inf << "MHCalibrationChargeCam..." << flush;
273 *fLog << inf << "done." << endl;
274
275 return kTRUE;
276}
277
278// --------------------------------------------------------------------------
279//
280// Searches for name in the MParList and calls, if existing:
281// - MHCalibrationCam::Finalize()
282// - MHCalibrationCam::ResetHists()
283//
284Bool_t MCalibColorSteer::Finalize(const char* name)
285{
286
287 MHCalibrationCam *hist = (MHCalibrationCam*)fParList->FindObject(name);
288 if (!hist)
289 return kFALSE;
290
291 hist->Finalize();
292 CopyHist(name);
293 hist->ResetHists();
294 hist->SetColor( fCalibPattern->GetPulserColor());
295 return kTRUE;
296}
297
298// --------------------------------------------------------------------------
299//
300// Re-Intitializes new containers inside the Intensity Cams.
301// From now on, a call to the IntensityCam functions returns pointers
302// to the newly created Containers.
303//
304Bool_t MCalibColorSteer::ReInitialize()
305{
306
307 *fLog << endl;
308
309 TString namep = GetNamePattern();
310
311 fBad->Clear(); // FIXME:::::: MERGE PreExcl!!!!
312 fQECam->Clear();
313
314 fBlindCam->Clear();
315 fBlindCam->SetPulserColor(fCalibPattern->GetPulserColor());
316
317 fRelTimeCam->Clear();
318 fRelTimeCam->SetPulserColor(fCalibPattern->GetPulserColor());
319
320 if (fIntensCharge)
321 {
322 MCalibrationChargeCam *oldcam = (MCalibrationChargeCam*)fIntensCharge->GetCam();
323 fIntensCharge->AddToList(Form("MCalibrationChargeCam%s",namep.Data()),*fGeom);
324 MCalibrationChargeCam *cam = (MCalibrationChargeCam*)fIntensCharge->GetCam();
325 cam->SetPulserColor(fCalibPattern->GetPulserColor());
326 if (!cam->MergeHiLoConversionFactors(*oldcam))
327 return kFALSE;
328 *fLog << inf << "New MCalibrationChargeCam with name: " << cam->GetName() << endl;
329 }
330
331 return kTRUE;
332
333}
334
335TString MCalibColorSteer::GetNamePattern()
336{
337
338 const Float_t strength = fCalibPattern->GetPulserStrength();
339 const MCalibrationCam::PulserColor_t col = fCalibPattern->GetPulserColor();
340
341 TString result = Form("%2.1f",strength);
342
343 switch (col)
344 {
345 case MCalibrationCam::kCT1:
346 result += "CT1";
347 break;
348 case MCalibrationCam::kGREEN:
349 result += "GREEN";
350 break;
351 case MCalibrationCam::kBLUE:
352 result += "BLUE";
353 break;
354 case MCalibrationCam::kUV:
355 result += "UV";
356 break;
357 default:
358 break;
359 }
360 return result;
361}
362
363// --------------------------------------------------------------------------
364//
365// Copies the histogram classes into the intensity cams
366//
367void MCalibColorSteer::CopyHist(const char* name)
368{
369 MHCalibrationCam *hcam = (MHCalibrationCam*)fParList->FindObject(name);
370 TString n(name);
371 if (n.Contains("ChargeCam"))
372 {
373 if (fIntensCharge)
374 fIntensCharge->AddHist((MHCalibrationCam*)hcam->Clone());
375 }
376// if (n.Contains("Blind"))
377// if (fIntensBlind)
378// fIntensBlind->AddHist((MHCalibrationCam*)hcam->Clone());
379
380// if (n.Contains("RelTime"))
381// if (fIntensRelTime)
382// fIntensRelTime->AddHist((MHCalibrationCam*)hcam->Clone());
383}
384
385// --------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.