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

Last change on this file since 6828 was 6828, 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 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 40493:
320 case 45116:
321 case 45609:
322 case 45219:
323 *fLog << err << dec << "Sorry, run " << num
324 << " was taken with a combination of colours used to flat-field ";
325 *fLog << err << "the camera. It cannot be used for the standard calibration " << endl;
326 return kFALSE;
327 break;
328
329 case 45605:
330 *fLog << err << "Sorry, run 45605 was taken with the continuous light source." << endl;
331 *fLog << err << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
332 return kFALSE;
333 break;
334
335 case 45606:
336 *fLog << err << "Sorry, run 45606 was taken with mal-functionning pulser." << endl;
337 *fLog << err << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
338 return kFALSE;
339 break;
340
341 }
342
343 if (fColor != MCalibrationCam::kNONE)
344 {
345 *fLog << inf << "Color determined from the run-number... ";
346 switch (fColor)
347 {
348 case MCalibrationCam::kGREEN: *fLog << "Green."; break;
349 case MCalibrationCam::kBLUE: *fLog << "Blue."; break;
350 case MCalibrationCam::kUV: *fLog << "UV."; break;
351 case MCalibrationCam::kCT1: *fLog << "CT1."; break;
352 default: break;
353 }
354 *fLog << endl;
355 fIsValid = kTRUE;
356 return kTRUE;
357 }
358
359 TString proj = header->GetProjectName();
360 proj.ToLower();
361
362 // Possible green combinations
363 CheckAndSet(proj, "0.1led[s]?gree", MCalibrationCam::kGREEN, 0.1);
364 CheckAndSet(proj, "1led[s]?gree", MCalibrationCam::kGREEN, 1. );
365 CheckAndSet(proj, "2led[s]?gree", MCalibrationCam::kGREEN, 2. );
366 CheckAndSet(proj, "3led[s]?gree", MCalibrationCam::kGREEN, 3. );
367 CheckAndSet(proj, "5led[s]?gree", MCalibrationCam::kGREEN, 5. );
368 CheckAndSet(proj, "6led[s]?gree", MCalibrationCam::kGREEN, 6. );
369 CheckAndSet(proj, "7led[s]?gree", MCalibrationCam::kGREEN, 7. );
370 CheckAndSet(proj, "8led[s]?gree", MCalibrationCam::kGREEN, 8. );
371
372 // Possible blue combinations
373 CheckAndSet(proj, "0.1led[s]?blue", MCalibrationCam::kBLUE, 0.1);
374 CheckAndSet(proj, "1led[s]?blue", MCalibrationCam::kBLUE, 1.);
375 CheckAndSet(proj, "2led[s]?blue", MCalibrationCam::kBLUE, 2.);
376 CheckAndSet(proj, "3led[s]?blue", MCalibrationCam::kBLUE, 3.);
377 CheckAndSet(proj, "5led[s]?blue", MCalibrationCam::kBLUE, 5.);
378 CheckAndSet(proj, "6led[s]?blue", MCalibrationCam::kBLUE, 6.);
379 CheckAndSet(proj, "7led[s]?blue", MCalibrationCam::kBLUE, 7.);
380 CheckAndSet(proj, "8led[s]?blue", MCalibrationCam::kBLUE, 8.);
381 CheckAndSet(proj, "10led[s]?blue", MCalibrationCam::kBLUE, 10.);
382 CheckAndSet(proj, "15led[s]?blue", MCalibrationCam::kBLUE, 15.);
383 CheckAndSet(proj, "20led[s]?blue", MCalibrationCam::kBLUE, 20.);
384 CheckAndSet(proj, "21led[s]?blue", MCalibrationCam::kBLUE, 21.);
385 CheckAndSet(proj, "22led[s]?blue", MCalibrationCam::kBLUE, 22.);
386 CheckAndSet(proj, "23led[s]?blue", MCalibrationCam::kBLUE, 23.);
387
388 // Possible UV combinations
389 CheckAndSet(proj, "1led[s]?uv", MCalibrationCam::kUV, 1.);
390 CheckAndSet(proj, "2led[s]?uv", MCalibrationCam::kUV, 2.);
391 CheckAndSet(proj, "3led[s]?uv", MCalibrationCam::kUV, 3.);
392 CheckAndSet(proj, "5led[s]?uv", MCalibrationCam::kUV, 5.);
393 CheckAndSet(proj, "6led[s]?uv", MCalibrationCam::kUV, 6.);
394 CheckAndSet(proj, "7led[s]?uv", MCalibrationCam::kUV, 7.);
395 CheckAndSet(proj, "8led[s]?uv", MCalibrationCam::kUV, 8.);
396 CheckAndSet(proj, "10led[s]?uv", MCalibrationCam::kUV, 10.);
397 CheckAndSet(proj, "11led[s]?uv", MCalibrationCam::kUV, 11.);
398 CheckAndSet(proj, "12led[s]?uv", MCalibrationCam::kUV, 12.);
399 CheckAndSet(proj, "13led[s]?uv", MCalibrationCam::kUV, 13.);
400
401 // Possible slot combinations
402 TRegexp slot("slot");
403 if (proj.Contains(slot))
404 {
405 proj.ReplaceAll("slot","");
406 UInt_t nr = 0;
407 TRegexp slotnr("^[0-9]");
408
409 if (proj.Contains(slotnr))
410 {
411 proj.Replace(2,99,"");
412 proj.ReplaceAll("u","");
413 proj.ReplaceAll("v","");
414 proj.ReplaceAll("g","");
415 nr = atoi(proj.Data())-1;
416
417 fColor = nr < 2 ? MCalibrationCam::kGREEN :
418 ( nr < 3 ) ? MCalibrationCam::kBLUE :
419 ( nr < 5 ) ? MCalibrationCam::kUV :
420 ( nr < 11 ) ? MCalibrationCam::kBLUE :
421 ( nr < 13 ) ? MCalibrationCam::kUV :
422 ( nr < 14 ) ? MCalibrationCam::kBLUE :
423 ( nr < 16 ) ? MCalibrationCam::kGREEN :
424 MCalibrationCam::kCT1;
425
426 switch (nr)
427 {
428 case 0:
429 fStrength = 5;
430 break;
431 case 1:
432 fStrength = 2.;
433 break;
434 case 2:
435 fStrength = 5.;
436 break;
437 case 3:
438 fStrength = 1.;
439 break;
440 case 4:
441 fStrength = 2.;
442 break;
443 case 5:
444 fStrength = 5.;
445 break;
446 case 6:
447 fStrength = 5.;
448 break;
449 case 7:
450 fStrength = 2.;
451 break;
452 case 8:
453 fStrength = 0.2;
454 break;
455 case 9:
456 fStrength = 0.;
457 break;
458 case 10:
459 fStrength = 1.;
460 break;
461 case 11:
462 fStrength = 5.;
463 break;
464 case 12:
465 fStrength = 5.;
466 break;
467 case 13:
468 fStrength = 5.;
469 break;
470 case 14:
471 fStrength = 1;
472 break;
473 case 15:
474 fStrength = 0.2;
475 break;
476 }
477 }
478 }
479
480 if (fColor == MCalibrationCam::kNONE)
481 {
482 CheckAndSet(proj, "gree", MCalibrationCam::kGREEN, 1.);
483 CheckAndSet(proj, "blue", MCalibrationCam::kBLUE, 1.);
484 CheckAndSet(proj, "uv", MCalibrationCam::kUV, 1.);
485 CheckAndSet(proj, "ct1", MCalibrationCam::kCT1, 1.);
486
487 if (fColor != MCalibrationCam::kNONE)
488 *fLog << inf << "Color determined from project-name (" << proj << ")... ";
489 else
490 if (proj.Contains("cl",TString::kIgnoreCase))
491 {
492 *fLog << err;
493 *fLog << "This run has been taken with the continuous light source." << endl;
494 *fLog << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
495 return kFALSE;
496 }
497 }
498 else
499 *fLog << inf << "Color and Intensity determined from project-name (" << proj << ")... ";
500
501 if (fColor == MCalibrationCam::kNONE)
502 {
503 *fLog << err;
504 *fLog << "Sorry, calibration run " << num << " was taken before the events could be" << endl;
505 *fLog << "flagged with a color by the digital modul and no color" << endl;
506 *fLog << "could be determined... abort." << endl;
507 return kFALSE;
508 }
509
510 switch (fColor)
511 {
512 case MCalibrationCam::kGREEN: *fLog << "Green."; break;
513 case MCalibrationCam::kBLUE: *fLog << "Blue."; break;
514 case MCalibrationCam::kUV: *fLog << "UV."; break;
515 case MCalibrationCam::kCT1: *fLog << "CT1."; break;
516 default: break;
517 }
518 *fLog << endl;
519
520 fIsValid = kTRUE;
521
522 return kTRUE;
523}
524
525// --------------------------------------------------------------------------
526//
527// Sets the pattern to MCalibrationPattern from outside, if fIsValid is set.
528//
529Int_t MCalibColorSet::Process()
530{
531
532 if (fIsValid)
533 {
534 if (fColor == MCalibrationCam::kNONE)
535 return kCONTINUE;
536
537 fPattern->SetPulserColor(fColor);
538 fPattern->SetPulserStrength(fStrength);
539 }
540
541 return kTRUE;
542}
543
544Int_t MCalibColorSet::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
545{
546
547 Bool_t rc = kFALSE;
548
549 if (IsEnvDefined(env, prefix, "ExplicitColor", print))
550 {
551 TString dat = GetEnvValue(env, prefix, "ExplicitColor", "");
552 if (dat.BeginsWith("green", TString::kIgnoreCase))
553 SetExplicitColor(MCalibrationCam::kGREEN);
554 if (dat.BeginsWith("blue", TString::kIgnoreCase))
555 SetExplicitColor(MCalibrationCam::kBLUE);
556 if (dat.BeginsWith("uv", TString::kIgnoreCase))
557 SetExplicitColor(MCalibrationCam::kUV);
558 if (dat.BeginsWith("ct1", TString::kIgnoreCase))
559 SetExplicitColor(MCalibrationCam::kCT1);
560 rc = kTRUE;
561 }
562
563 return rc;
564}
Note: See TracBrowser for help on using the repository browser.