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

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