source: trunk/MagicSoft/Mars/mcalib/MCalibColorSet.cc@ 6188

Last change on this file since 6188 was 6185, checked in by gaug, 20 years ago
*** empty log message ***
File size: 14.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): Thomas Bretz, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24//////////////////////////////////////////////////////////////////////////////
25//
26// MCalibColorSet
27//
28// Sets the color for events depending on the color which was used for
29// the run. This is a workaround for runs which were taken before the
30// digital module could deliver the color 'per event'
31//
32// Input Containers:
33// MRawRunHeader
34//
35// Output Containers:
36// MCalibrationPattern
37//
38//////////////////////////////////////////////////////////////////////////////
39#include "MCalibColorSet.h"
40
41#include <stdlib.h> // needed for atoi on some platforms
42
43#include <TRegexp.h>
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48#include "MParList.h"
49
50#include "MCalibrationCam.h"
51#include "MCalibrationPattern.h"
52#include "MRawRunHeader.h"
53
54ClassImp(MCalibColorSet);
55
56using namespace std;
57
58const Int_t MCalibColorSet::gkIFAEBoxInaugurationRun = 20113;
59const Int_t MCalibColorSet::gkMCRunLimit = 1000;
60const UInt_t MCalibColorSet::gkFirstRunWithFinalBits = 45626;
61
62// --------------------------------------------------------------------------
63//
64// Default constructor. MGeomCamMagic is the default geometry.
65//
66MCalibColorSet::MCalibColorSet(const char *name, const char *title)
67 : fPattern(0), fHeader(0)
68{
69 fName = name ? name : "MCalibColorSet";
70 fTitle = title ? title : "Task to set workaround missing colors calibration events";
71
72 Clear();
73}
74
75void MCalibColorSet::Clear(const Option_t *o)
76{
77
78 fColor = MCalibrationCam::kNONE;
79 fStrength = -1.;
80 fIsValid = kFALSE;
81
82}
83
84
85// -----------------------------------------------------------------------------------
86//
87// The following container are searched for and execution aborted if not in MParList:
88// - MCalibrationPattern
89//
90Int_t MCalibColorSet::PreProcess(MParList *pList)
91{
92
93 fPattern = (MCalibrationPattern*)pList->FindObject("MCalibrationPattern");
94 if (!fPattern)
95 {
96 *fLog << err << "MCalibrationPattern not found... abort." << endl;
97 return kFALSE;
98 }
99
100 fHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
101 if (!fHeader)
102 {
103 *fLog << err << "MRawEvtHeader not found... abort." << endl;
104 return kFALSE;
105 }
106
107 return kTRUE;
108}
109
110// --------------------------------------------------------------------------
111//
112// Check if str contains regexp.
113// If so or pat to pattern and set color to col.
114// Otherwise do nothing.
115//
116// Normally this function is much to simple (more arguments than lines!)
117// but in this particular case it is worth to have it to avois chaotic
118// repitions of the same piece of code for many many times.
119//
120void MCalibColorSet::CheckAndSet(const TString &str, const char *regexp, MCalibrationCam::PulserColor_t col, Float_t strength)
121{
122 if (!str.Contains(TRegexp(regexp)))
123 return;
124
125 fStrength = strength;
126 fColor = col;
127}
128
129// --------------------------------------------------------------------------
130//
131// Search for the following input containers and abort if not existing:
132// - MRawRunHeader
133//
134// If Runnumber < gkIFAEBoxInaugurationRun, set colour pattern: 0
135//
136// If Runnumber > gkIFAEBoxInaugurationRun, search for colour in
137// the project name: Set colour pattern according to the following
138// convention:
139// Green: assume slot 1 ( 5 Leds Green)
140// Blue: assume slot 14 ( 5 Leds Blue )
141// UV: assume slot 12 ( 5 Leds UV )
142// CT1: take 'slot 17'
143//
144Bool_t MCalibColorSet::ReInit(MParList *pList)
145{
146
147 Clear();
148
149 MRawRunHeader *header = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
150 if (!header)
151 {
152 *fLog << err << "MRawRunHeader not found... abort." << endl;
153 return kFALSE;
154 }
155
156 if (header->GetRunNumber() > gkFirstRunWithFinalBits)
157 return kTRUE;
158
159 //
160 // Consider the case that a pedestal run is interleaved in the calibration run sequence ... prepare
161 // to skip this run.
162 //
163 if (header->GetRunType() == MRawRunHeader::kRTPedestal)
164 {
165 *fLog << warn << "New run is a pedestal run... need intensity calibration to treat this case!" << endl;
166 fColor = MCalibrationCam::kNONE;
167 fIsValid = kTRUE;
168 return kTRUE;
169 }
170
171 const Int_t num = header->GetRunNumber();
172
173 if (num<gkMCRunLimit)
174 {
175 *fLog << inf << "Assumed MC run ... using GREEN pulser." << endl;
176 fColor = MCalibrationCam::kGREEN;
177 fIsValid = kTRUE;
178 return kTRUE;
179 }
180
181 if (num<gkIFAEBoxInaugurationRun)
182 {
183 *fLog << inf << "Run taken before inauguration of IFAE-box... using CT1 pulser." << endl;
184 fColor = MCalibrationCam::kCT1;
185 fStrength = 10.;
186 fIsValid = kTRUE;
187 return kTRUE;
188 }
189
190 fColor = MCalibrationCam::kNONE;
191 fStrength = 0.;
192
193 switch (num)
194 {
195 case 22246:
196 case 22253:
197 case 25792:
198 case 26402:
199 case 35415:
200 case 44768:
201 case 44976:
202 case 45082:
203 case 45083:
204 case 45089:
205 case 45090:
206 case 45091:
207 case 45094:
208 case 45119:
209 case 45249:
210 case 45253:
211 case 45262:
212 case 45274:
213 case 45275:
214 case 45276:
215 case 45365:
216 case 45366:
217 case 45367:
218 case 45368:
219 case 45369:
220 case 45370:
221 case 45371:
222 case 45382:
223 case 45401:
224 case 45419:
225 case 45432:
226 case 45471:
227 case 45485:
228 case 45489:
229 case 45557:
230 case 45562:
231 case 45571:
232 case 45579:
233 case 45607:
234 // case 31756:
235 fColor = MCalibrationCam::kBLUE;
236 fStrength = 1.;
237 break;
238
239 case 30090:
240 case 31745:
241 case 31746:
242 case 31747:
243 case 31748:
244 case 20660:
245 case 20661:
246 case 26408:
247 case 26409:
248 case 26412:
249 case 26568:
250 case 26924:
251 case 45051:
252 case 45084:
253 case 45085:
254 case 45092:
255 case 45227:
256 case 45241:
257 case 45250:
258 case 45254:
259 case 45263:
260 case 45372:
261 case 45373:
262 case 45608:
263 fColor = MCalibrationCam::kGREEN;
264 fStrength = 5.;
265 break;
266
267 case 45086:
268 case 45088:
269 case 45111:
270 case 45115:
271 case 45216:
272 case 45218:
273 case 45226:
274 case 45240:
275 case 45251:
276 case 45278:
277 case 45336:
278 case 45341:
279 case 45358:
280 case 45374:
281 case 45375:
282 case 45376:
283 case 45377:
284 case 45381:
285 case 45400:
286 case 45418:
287 case 45431:
288 case 45470:
289 case 45484:
290 case 45490:
291 case 45556:
292 case 45561:
293 case 45570:
294 case 45578:
295 case 45614:
296 case 45618:
297 fColor = MCalibrationCam::kUV;
298 fStrength = 10.;
299 break;
300
301 case 43914:
302 case 43916:
303 case 43918:
304 case 43920:
305 case 43922:
306 fColor = MCalibrationCam::kCT1;
307 fStrength = 20.;
308 break;
309
310 case 27474:
311 *fLog << err << "Sorry, run 27474 was taken with CLOSED LIDS. It should not be used! " << endl;
312 return kFALSE;
313 break;
314
315 case 45116:
316 case 45609:
317 case 45219:
318 *fLog << err << "Sorry, run " << num << " was taken with a combination of colours used to flat-field ";
319 *fLog << err << "the camera. It cannot be used for the standard calibration " << endl;
320 return kFALSE;
321 break;
322
323 case 45605:
324 *fLog << err << "Sorry, run 45605 was taken with the continuous light source." << endl;
325 *fLog << err << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
326 return kFALSE;
327 break;
328
329 case 45606:
330 *fLog << err << "Sorry, run 45606 was taken with mal-functionning pulser." << endl;
331 *fLog << err << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
332 return kFALSE;
333 break;
334
335 }
336
337 if (fColor != MCalibrationCam::kNONE)
338 {
339 *fLog << inf << "Color determined from the run-number... ";
340 switch (fColor)
341 {
342 case MCalibrationCam::kGREEN: *fLog << "Green."; break;
343 case MCalibrationCam::kBLUE: *fLog << "Blue."; break;
344 case MCalibrationCam::kUV: *fLog << "UV."; break;
345 case MCalibrationCam::kCT1: *fLog << "CT1."; break;
346 default: break;
347 }
348 *fLog << endl;
349 fIsValid = kTRUE;
350 return kTRUE;
351 }
352
353 TString proj = header->GetProjectName();
354 proj.ToLower();
355
356 // Possible green combinations
357 CheckAndSet(proj, "0.1led[s]?gree", MCalibrationCam::kGREEN, 0.1);
358 CheckAndSet(proj, "1led[s]?gree", MCalibrationCam::kGREEN, 1. );
359 CheckAndSet(proj, "2led[s]?gree", MCalibrationCam::kGREEN, 2. );
360 CheckAndSet(proj, "3led[s]?gree", MCalibrationCam::kGREEN, 3. );
361 CheckAndSet(proj, "5led[s]?gree", MCalibrationCam::kGREEN, 5. );
362 CheckAndSet(proj, "6led[s]?gree", MCalibrationCam::kGREEN, 6. );
363 CheckAndSet(proj, "7led[s]?gree", MCalibrationCam::kGREEN, 7. );
364 CheckAndSet(proj, "8led[s]?gree", MCalibrationCam::kGREEN, 8. );
365
366 // Possible blue combinations
367 CheckAndSet(proj, "0.1led[s]?blue", MCalibrationCam::kBLUE, 0.1);
368 CheckAndSet(proj, "1led[s]?blue", MCalibrationCam::kBLUE, 1.);
369 CheckAndSet(proj, "2led[s]?blue", MCalibrationCam::kBLUE, 2.);
370 CheckAndSet(proj, "3led[s]?blue", MCalibrationCam::kBLUE, 3.);
371 CheckAndSet(proj, "5led[s]?blue", MCalibrationCam::kBLUE, 5.);
372 CheckAndSet(proj, "6led[s]?blue", MCalibrationCam::kBLUE, 6.);
373 CheckAndSet(proj, "7led[s]?blue", MCalibrationCam::kBLUE, 7.);
374 CheckAndSet(proj, "8led[s]?blue", MCalibrationCam::kBLUE, 8.);
375 CheckAndSet(proj, "10led[s]?blue", MCalibrationCam::kBLUE, 10.);
376 CheckAndSet(proj, "15led[s]?blue", MCalibrationCam::kBLUE, 15.);
377 CheckAndSet(proj, "20led[s]?blue", MCalibrationCam::kBLUE, 20.);
378 CheckAndSet(proj, "21led[s]?blue", MCalibrationCam::kBLUE, 21.);
379 CheckAndSet(proj, "22led[s]?blue", MCalibrationCam::kBLUE, 22.);
380 CheckAndSet(proj, "23led[s]?blue", MCalibrationCam::kBLUE, 23.);
381
382 // Possible UV combinations
383 CheckAndSet(proj, "1led[s]?uv", MCalibrationCam::kUV, 1.);
384 CheckAndSet(proj, "2led[s]?uv", MCalibrationCam::kUV, 2.);
385 CheckAndSet(proj, "3led[s]?uv", MCalibrationCam::kUV, 3.);
386 CheckAndSet(proj, "5led[s]?uv", MCalibrationCam::kUV, 5.);
387 CheckAndSet(proj, "6led[s]?uv", MCalibrationCam::kUV, 6.);
388 CheckAndSet(proj, "7led[s]?uv", MCalibrationCam::kUV, 7.);
389 CheckAndSet(proj, "8led[s]?uv", MCalibrationCam::kUV, 8.);
390 CheckAndSet(proj, "10led[s]?uv", MCalibrationCam::kUV, 10.);
391 CheckAndSet(proj, "11led[s]?uv", MCalibrationCam::kUV, 11.);
392 CheckAndSet(proj, "12led[s]?uv", MCalibrationCam::kUV, 12.);
393 CheckAndSet(proj, "13led[s]?uv", MCalibrationCam::kUV, 13.);
394
395 // Possible slot combinations
396 TRegexp slot("slot");
397 if (proj.Contains(slot))
398 {
399 proj.ReplaceAll("slot","");
400 UInt_t nr = 0;
401 TRegexp slotnr("^[0-9]");
402
403 if (proj.Contains(slotnr))
404 {
405 proj.Replace(2,99,"");
406 proj.ReplaceAll("u","");
407 proj.ReplaceAll("v","");
408 proj.ReplaceAll("g","");
409 nr = atoi(proj.Data())-1;
410
411 fColor = nr < 2 ? MCalibrationCam::kGREEN :
412 ( nr < 3 ) ? MCalibrationCam::kBLUE :
413 ( nr < 5 ) ? MCalibrationCam::kUV :
414 ( nr < 11 ) ? MCalibrationCam::kBLUE :
415 ( nr < 13 ) ? MCalibrationCam::kUV :
416 ( nr < 14 ) ? MCalibrationCam::kBLUE :
417 ( nr < 16 ) ? MCalibrationCam::kGREEN :
418 MCalibrationCam::kCT1;
419
420 switch (nr)
421 {
422 case 0:
423 fStrength = 5;
424 break;
425 case 1:
426 fStrength = 2.;
427 break;
428 case 2:
429 fStrength = 5.;
430 break;
431 case 3:
432 fStrength = 1.;
433 break;
434 case 4:
435 fStrength = 2.;
436 break;
437 case 5:
438 fStrength = 5.;
439 break;
440 case 6:
441 fStrength = 5.;
442 break;
443 case 7:
444 fStrength = 2.;
445 break;
446 case 8:
447 fStrength = 0.2;
448 break;
449 case 9:
450 fStrength = 0.;
451 break;
452 case 10:
453 fStrength = 1.;
454 break;
455 case 11:
456 fStrength = 5.;
457 break;
458 case 12:
459 fStrength = 5.;
460 break;
461 case 13:
462 fStrength = 5.;
463 break;
464 case 14:
465 fStrength = 1;
466 break;
467 case 15:
468 fStrength = 0.2;
469 break;
470 }
471 }
472 }
473
474 if (fColor == MCalibrationCam::kNONE)
475 {
476 CheckAndSet(proj, "gree", MCalibrationCam::kGREEN, 1.);
477 CheckAndSet(proj, "blue", MCalibrationCam::kBLUE, 1.);
478 CheckAndSet(proj, "uv", MCalibrationCam::kUV, 1.);
479 CheckAndSet(proj, "ct1", MCalibrationCam::kCT1, 1.);
480
481 if (fColor != MCalibrationCam::kNONE)
482 *fLog << inf << "Color determined from project-name (" << proj << ")... ";
483 else
484 if (proj.Contains("cl",TString::kIgnoreCase))
485 {
486 *fLog << err;
487 *fLog << "This run has been taken with the continuous light source." << endl;
488 *fLog << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
489 return kFALSE;
490 }
491 }
492 else
493 *fLog << inf << "Color and Intensity determined from project-name (" << proj << ")... ";
494
495 if (fColor == MCalibrationCam::kNONE)
496 {
497 *fLog << err;
498 *fLog << "Sorry, calibration run " << num << " was taken before the events could be" << endl;
499 *fLog << "flagged with a color by the digital modul and no color" << endl;
500 *fLog << "could be determined... abort." << endl;
501 return kFALSE;
502 }
503
504 switch (fColor)
505 {
506 case MCalibrationCam::kGREEN: *fLog << "Green."; break;
507 case MCalibrationCam::kBLUE: *fLog << "Blue."; break;
508 case MCalibrationCam::kUV: *fLog << "UV."; break;
509 case MCalibrationCam::kCT1: *fLog << "CT1."; break;
510 default: break;
511 }
512 *fLog << endl;
513
514 fIsValid = kTRUE;
515
516 return kTRUE;
517}
518
519// --------------------------------------------------------------------------
520//
521// Sets the pattern to MCalibrationPattern from outside, if fIsValid is set.
522//
523Int_t MCalibColorSet::Process()
524{
525
526 if (fIsValid)
527 {
528 if (fColor == MCalibrationCam::kNONE)
529 return kCONTINUE;
530
531 fPattern->SetPulserColor(fColor);
532 fPattern->SetPulserStrength(fStrength);
533 }
534
535 return kTRUE;
536}
Note: See TracBrowser for help on using the repository browser.