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

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