source: trunk/Mars/mcalib/MCalibColorSteer.cc@ 16364

Last change on this file since 16364 was 8452, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 9.6 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//
36// Output Containers:
37//
38//////////////////////////////////////////////////////////////////////////////
39#include "MCalibColorSteer.h"
40
41#include "MLog.h"
42#include "MLogManip.h"
43
44#include "MParList.h"
45#include "MTaskList.h"
46
47#include "MGeomCam.h"
48#include "MRawRunHeader.h"
49
50#include "MHCalibrationCam.h"
51#include "MCalibrationChargeCam.h"
52#include "MCalibrationBlindCam.h"
53#include "MBadPixelsCam.h"
54
55#include "MCalibrationPattern.h"
56#include "MCalibrationQECam.h"
57#include "MCalibrationBlindCam.h"
58
59#include "MCalibrationChargeCam.h"
60#include "MCalibrationChargeCalc.h"
61
62#include "MCalibrationRelTimeCam.h"
63#include "MCalibrationRelTimeCalc.h"
64
65ClassImp(MCalibColorSteer);
66
67using namespace std;
68
69// --------------------------------------------------------------------------
70//
71// Default constructor.
72//
73MCalibColorSteer::MCalibColorSteer(const char *name, const char *title)
74 : fCalibPattern(NULL), fGeom(NULL), fParList(NULL), fCharge(NULL),
75 fBad(NULL), fChargeCalc(NULL), fRelTimeCalc(NULL), fHistCopy(kFALSE)
76{
77
78 fName = name ? name : "MCalibColorSteer";
79 fTitle = title ? title : "Task to steer the processing of different colours in the calibration events";
80
81}
82
83// -----------------------------------------------------------------------------------
84//
85// The following container are searched for and execution aborted if not in MParList:
86// - MCalibrationPattern
87// - MTaskList
88//
89Int_t MCalibColorSteer::PreProcess(MParList *pList)
90{
91
92 fCalibPattern = (MCalibrationPattern*)pList->FindObject("MCalibrationPattern");
93 if (!fCalibPattern)
94 {
95 *fLog << err << "MCalibrationPattern not found... abort." << endl;
96 return kFALSE;
97 }
98
99 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
100 if (!fRunHeader)
101 {
102 *fLog << err << "MRawRunHeader not found... abort." << endl;
103 return kFALSE;
104 }
105
106 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
107 if (!fGeom)
108 {
109 *fLog << err << "MGeomCam not found... abort." << endl;
110 return kFALSE;
111 }
112
113 fParList = pList;
114 if (!fParList)
115 {
116 *fLog << err << "MParList not found... abort." << endl;
117 return kFALSE;
118 }
119
120 MTaskList *tlist = (MTaskList*)pList->FindObject("MTaskList");
121 if (!tlist)
122 {
123 *fLog << err << "MTaskList not found... abort." << endl;
124 return kFALSE;
125 }
126
127 //
128 // Look for the MBadPixelsCam
129 //
130 fBad = (MBadPixelsCam*)pList->FindObject("MBadPixelsCam");
131 if (!fBad)
132 {
133 *fLog << err << "MBadPixelsCam not found... abort." << endl;
134 return kFALSE;
135 }
136
137 //
138 // Look for the MCalibrationBlindCam
139 //
140 fBlindCam = (MCalibrationBlindCam*)pList->FindCreateObj("MCalibrationBlindCam");
141 if (!fBlindCam)
142 return kFALSE;
143
144 //
145 // Look for the MFillH name "FillChargeCam".
146 //
147 if (pList->FindObject(AddSerialNumber("MHCalibrationChargeCam")))
148 {
149 *fLog << inf << "Found MHCalibrationChargeCam ... " << flush;
150
151 fCharge = (MCalibrationChargeCam*)pList->FindCreateObj("MCalibrationChargeCam");
152 if (!fCharge)
153 return kFALSE;
154
155 fQECam = (MCalibrationQECam*)pList->FindCreateObj("MCalibrationQECam");
156 if (!fQECam)
157 return kFALSE;
158
159 fChargeCalc = (MCalibrationChargeCalc*)tlist->FindObject("MCalibrationChargeCalc");
160 if (!fChargeCalc)
161 {
162 *fLog << err << "Could not find MCalibrationChargeCalc abort... " << endl;
163 return kFALSE;
164 }
165 }
166
167 //
168 // Look for the MFillH name "FillRelTimeCam".
169 //
170 if (pList->FindObject(AddSerialNumber("MHCalibrationRelTimeCam")))
171 {
172
173 *fLog << inf << "Found MHCalibrationRelTimeCam ... " << flush;
174
175 fRelTimeCam = (MCalibrationRelTimeCam*)pList->FindCreateObj("MCalibrationRelTimeCam");
176 if (!fRelTimeCam)
177 return kFALSE;
178
179 fRelTimeCalc = (MCalibrationRelTimeCalc*)tlist->FindObject(AddSerialNumber("MCalibrationRelTimeCalc"));
180 if (!fRelTimeCalc)
181 return kFALSE;
182
183 // CALL ITS PrePorcess ???
184 }
185
186 fColor = MCalibrationCam::kNONE;
187 fStrength = 0.;
188
189 return kTRUE;
190}
191
192// --------------------------------------------------------------------------
193//
194// Reads the pattern from MCalibrationPattern and clear
195// Cams, if the pattern has changed. Executes Finalize of the
196// MCalibration*Calc classes in that case.
197//
198Int_t MCalibColorSteer::Process()
199{
200
201 const MCalibrationCam::PulserColor_t col = fCalibPattern->GetPulserColor();
202 const Float_t strength = fCalibPattern->GetPulserStrength();
203
204 if (fColor ==MCalibrationCam::kNONE)
205 {
206 fColor = col;
207 fStrength = strength;
208 return kTRUE;
209 }
210
211 const Float_t strdiff = TMath::Abs(fStrength-strength);
212
213 if (col == MCalibrationCam::kNONE || (col == fColor && strdiff < 0.05))
214 return kTRUE;
215
216 *fLog << inf << GetDescriptor() << " : Color - old=" << fColor << flush;
217 fColor = col;
218 *fLog << " / new=" << fColor << endl;
219
220 *fLog << inf << GetDescriptor() << " : Strength - old=" << fStrength << flush;
221 fStrength = strength;
222 *fLog << " / new=" << fStrength << endl;
223
224 //
225 // Finalize Possible calibration histogram classes...
226 //
227 *fLog << inf << GetDescriptor() << " : Finalize calibration histograms..." << flush;
228 if (Finalize("MHCalibrationChargeCam")) *fLog << "MHCalibrationChargeCam...";
229 if (Finalize("MHCalibrationChargeBlindCam")) *fLog << "MHCalibrationChargeBlindCam...";
230 if (Finalize("MHCalibrationRelTimeCam")) *fLog << "MHCalibrationRelTimeCam...";
231 if (Finalize("MHCalibrationTestCam")) *fLog << "MHCalibrationChargeCam...";
232 if (Finalize("MHCalibrationTestTimeCam")) *fLog << "MHCalibrationChargeCam...";
233
234 //
235 // Finalize possible calibration calculation tasks
236 //
237 *fLog << endl;
238 *fLog << inf << GetDescriptor() << " : Finalize calibration calculations..." << flush;
239 if (fChargeCalc)
240 fChargeCalc->Finalize();
241 if (fRelTimeCalc)
242 fRelTimeCalc->Finalize();
243
244 ReInitialize();
245
246 return kTRUE;
247}
248
249// --------------------------------------------------------------------------
250//
251// Reads the pattern from MCalibrationPattern and clear
252// Cams, if the pattern has changed. Executes Finalize of the
253// MCalibration*Calc classes in that case.
254//
255Int_t MCalibColorSteer::PostProcess()
256{
257 //
258 // Finalize Possible calibration histogram classes...
259 //
260 *fLog << inf << "Finalize calibration histograms..." << flush;
261 if (Finalize("MHCalibrationChargeCam")) *fLog << inf << "MHCalibrationChargeCam..." << flush;
262 if (Finalize("MHCalibrationChargeBlindCam")) *fLog << inf << "MHCalibrationChargeBlindCam..." << flush;
263 if (Finalize("MHCalibrationRelTimeCam")) *fLog << inf << "MHCalibrationRelTimeCam..." << flush;
264 if (Finalize("MHCalibrationTestCam")) *fLog << inf << "MHCalibrationChargeCam..." << flush;
265 if (Finalize("MHCalibrationTestTimeCam")) *fLog << inf << "MHCalibrationChargeCam..." << flush;
266 *fLog << inf << "done." << endl;
267
268 return kTRUE;
269}
270
271// --------------------------------------------------------------------------
272//
273// Searches for name in the MParList and calls, if existing:
274// - MHCalibrationCam::Finalize()
275// - MHCalibrationCam::ResetHists()
276//
277Bool_t MCalibColorSteer::Finalize(const char* name)
278{
279
280 MHCalibrationCam *hist = (MHCalibrationCam*)fParList->FindObject(name);
281 if (!hist)
282 return kFALSE;
283
284 hist->Finalize();
285 //CopyHist(name);
286 hist->ResetHists();
287 hist->SetColor( fCalibPattern->GetPulserColor());
288 return kTRUE;
289}
290
291// --------------------------------------------------------------------------
292//
293// Clear cams
294//
295Bool_t MCalibColorSteer::ReInitialize()
296{
297
298 *fLog << endl;
299
300 TString namep = GetNamePattern();
301
302 fBad->Clear(); // FIXME:::::: MERGE PreExcl!!!!
303
304 if (fQECam)
305 fQECam->Clear();
306
307 fBlindCam->Clear();
308 fBlindCam->SetPulserColor(fCalibPattern->GetPulserColor());
309
310 if (fRelTimeCam)
311 {
312 fRelTimeCam->Clear();
313 fRelTimeCam->SetPulserColor(fCalibPattern->GetPulserColor());
314 }
315
316 if (fCharge)
317 {
318 fCharge->Clear();
319 fCharge->SetPulserColor(fCalibPattern->GetPulserColor());
320 }
321
322 return kTRUE;
323
324}
325
326TString MCalibColorSteer::GetNamePattern()
327{
328
329 const Float_t strength = fCalibPattern->GetPulserStrength();
330 const MCalibrationCam::PulserColor_t col = fCalibPattern->GetPulserColor();
331
332 TString result = Form("%2.1f",strength);
333
334 switch (col)
335 {
336 case MCalibrationCam::kCT1:
337 result += "CT1";
338 break;
339 case MCalibrationCam::kGREEN:
340 result += "GREEN";
341 break;
342 case MCalibrationCam::kBLUE:
343 result += "BLUE";
344 break;
345 case MCalibrationCam::kUV:
346 result += "UV";
347 break;
348 default:
349 break;
350 }
351 return result;
352}
Note: See TracBrowser for help on using the repository browser.