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

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