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

Last change on this file since 7097 was 7095, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 15.9 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 if (header->IsMonteCarloRun())
160 return kTRUE;
161
162 if (header->GetRunNumber() > gkFirstRunWithFinalBits)
163 return kTRUE;
164
165 //
166 // Consider the case that a pedestal run is interleaved in the calibration run sequence ... prepare
167 // to skip this run.
168 //
169 if (header->GetRunType() == MRawRunHeader::kRTPedestal)
170 {
171 *fLog << warn << "New run is a pedestal run... need intensity calibration to treat this case!" << endl;
172 fColor = MCalibrationCam::kNONE;
173 fPattern->SetPulserColor(fColor);
174 fIsValid = kTRUE;
175 return kTRUE;
176 }
177
178 if (fIsExplicitColor)
179 {
180 fPattern->SetPulserColor(fColor);
181 fIsValid = kTRUE;
182 return kTRUE;
183 }
184
185 const Int_t num = header->GetRunNumber();
186
187 if (num<gkIFAEBoxInaugurationRun)
188 {
189 *fLog << inf << "Run taken before inauguration of IFAE-box... using CT1 pulser." << endl;
190 fColor = MCalibrationCam::kCT1;
191 fPattern->SetPulserColor(fColor);
192 fPattern->SetPulserStrength(fStrength);
193 fStrength = 10.;
194 fIsValid = kTRUE;
195 return kTRUE;
196 }
197
198 fColor = MCalibrationCam::kNONE;
199 fStrength = 0.;
200
201 switch (num)
202 {
203 case 22246:
204 case 22253:
205 case 25792:
206 case 26402:
207 case 34814:
208 case 35415:
209 case 39942:
210 case 39944:
211 case 44768:
212 case 44976:
213 case 45082:
214 case 45083:
215 case 45089:
216 case 45090:
217 case 45091:
218 case 45094:
219 case 45119:
220 case 45249:
221 case 45253:
222 case 45262:
223 case 45274:
224 case 45275:
225 case 45276:
226 case 45365:
227 case 45366:
228 case 45367:
229 case 45368:
230 case 45369:
231 case 45370:
232 case 45371:
233 case 45382:
234 case 45401:
235 case 45419:
236 case 45432:
237 case 45471:
238 case 45485:
239 case 45489:
240 case 45490:
241 case 45494:
242 case 45503:
243 case 45526:
244 case 45538:
245 case 45549:
246 case 45557:
247 case 45562:
248 case 45571:
249 case 45579:
250 case 45607:
251 // case 31756:
252 fColor = MCalibrationCam::kBLUE;
253 fStrength = 1.;
254 break;
255
256 case 30090:
257 case 31745:
258 case 31746:
259 case 31747:
260 case 31748:
261 case 34815:
262 case 20660:
263 case 20661:
264 case 26408:
265 case 26409:
266 case 26412:
267 case 26568:
268 case 26924:
269 case 44834:
270 case 45051:
271 case 45084:
272 case 45085:
273 case 45092:
274 case 45227:
275 case 45241:
276 case 45250:
277 case 45254:
278 case 45263:
279 case 45372:
280 case 45373:
281 case 45608:
282 fColor = MCalibrationCam::kGREEN;
283 fStrength = 5.;
284 break;
285
286 case 39941:
287 case 39943:
288 case 44833:
289 case 45086:
290 case 45088:
291 case 45111:
292 case 45115:
293 case 45216:
294 case 45218:
295 case 45226:
296 case 45240:
297 case 45251:
298 case 45278:
299 case 45336:
300 case 45341:
301 case 45358:
302 case 45374:
303 case 45375:
304 case 45376:
305 case 45377:
306 case 45381:
307 case 45400:
308 case 45418:
309 case 45431:
310 case 45470:
311 case 45484:
312 case 45493:
313 case 45502:
314 case 45525:
315 case 45537:
316 case 45548:
317 case 45556:
318 case 45561:
319 case 45570:
320 case 45578:
321 case 45614:
322 case 45618:
323 fColor = MCalibrationCam::kUV;
324 fStrength = 10.;
325 break;
326
327 case 43914:
328 case 43916:
329 case 43918:
330 case 43920:
331 case 43922:
332 fColor = MCalibrationCam::kCT1;
333 fStrength = 20.;
334 break;
335
336 case 27474:
337 *fLog << err << "Sorry, run 27474 was taken with CLOSED LIDS. It should not be used! " << endl;
338 return kFALSE;
339 break;
340
341 case 40493:
342 case 45116:
343 case 45609:
344 case 45219:
345 *fLog << err << dec << "Sorry, run " << num
346 << " was taken with a combination of colours used to flat-field ";
347 *fLog << err << "the camera. It cannot be used for the standard calibration " << endl;
348 return kFALSE;
349 break;
350
351 case 45605:
352 *fLog << err << "Sorry, run 45605 was taken with the continuous light source." << endl;
353 *fLog << err << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
354 return kFALSE;
355 break;
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 break;
362
363 }
364
365 if (fColor != MCalibrationCam::kNONE)
366 {
367 *fLog << inf << "Color determined from the run-number... ";
368 switch (fColor)
369 {
370 case MCalibrationCam::kGREEN: *fLog << "Green."; break;
371 case MCalibrationCam::kBLUE: *fLog << "Blue."; break;
372 case MCalibrationCam::kUV: *fLog << "UV."; break;
373 case MCalibrationCam::kCT1: *fLog << "CT1."; break;
374 default: break;
375 }
376 *fLog << endl;
377 fPattern->SetPulserColor(fColor);
378 fIsValid = kTRUE;
379 return kTRUE;
380 }
381
382 TString proj = header->GetProjectName();
383 proj.ToLower();
384
385 // Possible green combinations
386 CheckAndSet(proj, "0.1led[s]?gree", MCalibrationCam::kGREEN, 0.1);
387 CheckAndSet(proj, "1led[s]?gree", MCalibrationCam::kGREEN, 1. );
388 CheckAndSet(proj, "2led[s]?gree", MCalibrationCam::kGREEN, 2. );
389 CheckAndSet(proj, "3led[s]?gree", MCalibrationCam::kGREEN, 3. );
390 CheckAndSet(proj, "5led[s]?gree", MCalibrationCam::kGREEN, 5. );
391 CheckAndSet(proj, "6led[s]?gree", MCalibrationCam::kGREEN, 6. );
392 CheckAndSet(proj, "7led[s]?gree", MCalibrationCam::kGREEN, 7. );
393 CheckAndSet(proj, "8led[s]?gree", MCalibrationCam::kGREEN, 8. );
394
395 // Possible blue combinations
396 CheckAndSet(proj, "0.1led[s]?blue", MCalibrationCam::kBLUE, 0.1);
397 CheckAndSet(proj, "1led[s]?blue", MCalibrationCam::kBLUE, 1.);
398 CheckAndSet(proj, "2led[s]?blue", MCalibrationCam::kBLUE, 2.);
399 CheckAndSet(proj, "3led[s]?blue", MCalibrationCam::kBLUE, 3.);
400 CheckAndSet(proj, "5led[s]?blue", MCalibrationCam::kBLUE, 5.);
401 CheckAndSet(proj, "6led[s]?blue", MCalibrationCam::kBLUE, 6.);
402 CheckAndSet(proj, "7led[s]?blue", MCalibrationCam::kBLUE, 7.);
403 CheckAndSet(proj, "8led[s]?blue", MCalibrationCam::kBLUE, 8.);
404 CheckAndSet(proj, "10led[s]?blue", MCalibrationCam::kBLUE, 10.);
405 CheckAndSet(proj, "15led[s]?blue", MCalibrationCam::kBLUE, 15.);
406 CheckAndSet(proj, "20led[s]?blue", MCalibrationCam::kBLUE, 20.);
407 CheckAndSet(proj, "21led[s]?blue", MCalibrationCam::kBLUE, 21.);
408 CheckAndSet(proj, "22led[s]?blue", MCalibrationCam::kBLUE, 22.);
409 CheckAndSet(proj, "23led[s]?blue", MCalibrationCam::kBLUE, 23.);
410
411 // Possible UV combinations
412 CheckAndSet(proj, "1led[s]?uv", MCalibrationCam::kUV, 1.);
413 CheckAndSet(proj, "2led[s]?uv", MCalibrationCam::kUV, 2.);
414 CheckAndSet(proj, "3led[s]?uv", MCalibrationCam::kUV, 3.);
415 CheckAndSet(proj, "5led[s]?uv", MCalibrationCam::kUV, 5.);
416 CheckAndSet(proj, "6led[s]?uv", MCalibrationCam::kUV, 6.);
417 CheckAndSet(proj, "7led[s]?uv", MCalibrationCam::kUV, 7.);
418 CheckAndSet(proj, "8led[s]?uv", MCalibrationCam::kUV, 8.);
419 CheckAndSet(proj, "10led[s]?uv", MCalibrationCam::kUV, 10.);
420 CheckAndSet(proj, "11led[s]?uv", MCalibrationCam::kUV, 11.);
421 CheckAndSet(proj, "12led[s]?uv", MCalibrationCam::kUV, 12.);
422 CheckAndSet(proj, "13led[s]?uv", MCalibrationCam::kUV, 13.);
423
424 // Possible slot combinations
425 TRegexp slot("slot");
426 if (proj.Contains(slot))
427 {
428 proj.ReplaceAll("slot","");
429 UInt_t nr = 0;
430 TRegexp slotnr("^[0-9]");
431
432 if (proj.Contains(slotnr))
433 {
434 proj.Replace(2,99,"");
435 proj.ReplaceAll("u","");
436 proj.ReplaceAll("v","");
437 proj.ReplaceAll("g","");
438 nr = atoi(proj.Data())-1;
439
440 fColor = nr < 2 ? MCalibrationCam::kGREEN :
441 ( nr < 3 ) ? MCalibrationCam::kBLUE :
442 ( nr < 5 ) ? MCalibrationCam::kUV :
443 ( nr < 11 ) ? MCalibrationCam::kBLUE :
444 ( nr < 13 ) ? MCalibrationCam::kUV :
445 ( nr < 14 ) ? MCalibrationCam::kBLUE :
446 ( nr < 16 ) ? MCalibrationCam::kGREEN :
447 MCalibrationCam::kCT1;
448
449 switch (nr)
450 {
451 case 0:
452 fStrength = 5;
453 break;
454 case 1:
455 fStrength = 2.;
456 break;
457 case 2:
458 fStrength = 5.1;
459 break;
460 case 3:
461 fStrength = 1.;
462 break;
463 case 4:
464 fStrength = 2.;
465 break;
466 case 5:
467 fStrength = 5.2;
468 break;
469 case 6:
470 fStrength = 5.4;
471 break;
472 case 7:
473 fStrength = 2.;
474 break;
475 case 8:
476 fStrength = 0.2;
477 break;
478 case 9:
479 fStrength = 0.;
480 break;
481 case 10:
482 fStrength = 1.;
483 break;
484 case 11:
485 fStrength = 5.8;
486 break;
487 case 12:
488 fStrength = 5.1;
489 break;
490 case 13:
491 fStrength = 5.2;
492 break;
493 case 14:
494 fStrength = 1;
495 break;
496 case 15:
497 fStrength = 0.2;
498 break;
499 }
500 }
501 }
502
503 if (fColor == MCalibrationCam::kNONE)
504 {
505 CheckAndSet(proj, "gree", MCalibrationCam::kGREEN, 1.);
506 CheckAndSet(proj, "blue", MCalibrationCam::kBLUE, 1.);
507 CheckAndSet(proj, "uv", MCalibrationCam::kUV, 1.);
508 CheckAndSet(proj, "ct1", MCalibrationCam::kCT1, 1.);
509
510 if (fColor != MCalibrationCam::kNONE)
511 *fLog << inf << "Color determined from project-name (" << proj << ")... ";
512 else
513 if (proj.Contains("cl",TString::kIgnoreCase))
514 {
515 *fLog << err;
516 *fLog << "This run has been taken with the continuous light source." << endl;
517 *fLog << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
518 return kFALSE;
519 }
520 }
521 else
522 *fLog << inf << "Color and Intensity determined from project-name (" << proj << ")... ";
523
524 if (fColor == MCalibrationCam::kNONE)
525 {
526 *fLog << err;
527 *fLog << "Sorry, calibration run " << num << " was taken before the events could be" << endl;
528 *fLog << "flagged with a color by the digital modul and no color" << endl;
529 *fLog << "could be determined... abort." << endl;
530 return kFALSE;
531 }
532
533 switch (fColor)
534 {
535 case MCalibrationCam::kGREEN: *fLog << "Green."; break;
536 case MCalibrationCam::kBLUE: *fLog << "Blue."; break;
537 case MCalibrationCam::kUV: *fLog << "UV."; break;
538 case MCalibrationCam::kCT1: *fLog << "CT1."; break;
539 default: break;
540 }
541 *fLog << endl;
542
543 fPattern->SetPulserColor(fColor);
544 fPattern->SetPulserStrength(fStrength);
545
546 fIsValid = kTRUE;
547
548 return kTRUE;
549}
550
551// --------------------------------------------------------------------------
552//
553// Sets the pattern to MCalibrationPattern from outside, if fIsValid is set.
554//
555Int_t MCalibColorSet::Process()
556{
557
558 if (fIsValid)
559 {
560 if (fColor == MCalibrationCam::kNONE)
561 return kCONTINUE;
562
563 fPattern->SetPulserColor(fColor);
564 fPattern->SetPulserStrength(fStrength);
565 }
566
567 return kTRUE;
568}
569
570Int_t MCalibColorSet::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
571{
572
573 Bool_t rc = kFALSE;
574
575 if (IsEnvDefined(env, prefix, "ExplicitColor", print))
576 {
577 TString dat = GetEnvValue(env, prefix, "ExplicitColor", "");
578 if (dat.BeginsWith("green", TString::kIgnoreCase))
579 SetExplicitColor(MCalibrationCam::kGREEN);
580 if (dat.BeginsWith("blue", TString::kIgnoreCase))
581 SetExplicitColor(MCalibrationCam::kBLUE);
582 if (dat.BeginsWith("uv", TString::kIgnoreCase))
583 SetExplicitColor(MCalibrationCam::kUV);
584 if (dat.BeginsWith("ct1", TString::kIgnoreCase))
585 SetExplicitColor(MCalibrationCam::kCT1);
586 rc = kTRUE;
587 }
588
589 return rc;
590}
591
Note: See TracBrowser for help on using the repository browser.