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

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