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

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