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

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