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

Last change on this file since 6136 was 6020, checked in by gaug, 20 years ago
*** empty log message ***
File size: 14.6 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)
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 fColor = MCalibrationCam::kNONE;
79 fStrength = -1.;
80 fIsValid = kFALSE;
81
82}
83
84
85// -----------------------------------------------------------------------------------
86//
87// The following container are searched for and execution aborted if not in MParList:
88// - MCalibrationPattern
89//
90Int_t MCalibColorSet::PreProcess(MParList *pList)
91{
92
93 fPattern = (MCalibrationPattern*)pList->FindObject("MCalibrationPattern");
94 if (!fPattern)
95 {
96 *fLog << err << "MCalibrationPattern not found... abort." << endl;
97 return kFALSE;
98 }
99
100 fHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
101 if (!fHeader)
102 {
103 *fLog << err << "MRawEvtHeader not found... abort." << endl;
104 return kFALSE;
105 }
106
107 return kTRUE;
108}
109
110// --------------------------------------------------------------------------
111//
112// Check if str contains regexp.
113// If so or pat to pattern and set color to col.
114// Otherwise do nothing.
115//
116// Normally this function is much to simple (more arguments than lines!)
117// but in this particular case it is worth to have it to avois chaotic
118// repitions of the same piece of code for many many times.
119//
120void MCalibColorSet::CheckAndSet(const TString &str, const char *regexp, MCalibrationCam::PulserColor_t col, Float_t strength)
121{
122 if (!str.Contains(TRegexp(regexp)))
123 return;
124
125 fStrength = strength;
126 fColor = col;
127}
128
129// --------------------------------------------------------------------------
130//
131// Search for the following input containers and abort if not existing:
132// - MRawRunHeader
133//
134// If Runnumber < gkIFAEBoxInaugurationRun, set colour pattern: 0
135//
136// If Runnumber > gkIFAEBoxInaugurationRun, search for colour in
137// the project name: Set colour pattern according to the following
138// convention:
139// Green: assume slot 1 ( 5 Leds Green)
140// Blue: assume slot 14 ( 5 Leds Blue )
141// UV: assume slot 12 ( 5 Leds UV )
142// CT1: take 'slot 17'
143//
144Bool_t MCalibColorSet::ReInit(MParList *pList)
145{
146
147 Clear();
148
149 MRawRunHeader *header = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
150 if (!header)
151 {
152 *fLog << err << "MRawRunHeader not found... abort." << endl;
153 return kFALSE;
154 }
155
156 if (header->GetRunNumber() > gkFirstRunWithFinalBits)
157 return kTRUE;
158
159 //
160 // Consider the case that a pedestal run is interleaved in the calibration run sequence ... prepare
161 // to skip this run.
162 //
163 if (header->GetRunType() == MRawRunHeader::kRTPedestal)
164 {
165 *fLog << warn << "New run is a pedestal run... need intensity calibration to treat this case!" << endl;
166 fColor = MCalibrationCam::kNONE;
167 fIsValid = kTRUE;
168 return kTRUE;
169 }
170
171 const Int_t num = header->GetRunNumber();
172
173 if (num<gkMCRunLimit)
174 {
175 *fLog << inf << "Assumed MC run ... using GREEN pulser." << endl;
176 fColor = MCalibrationCam::kGREEN;
177 fIsValid = kTRUE;
178 return kTRUE;
179 }
180
181 if (num<gkIFAEBoxInaugurationRun)
182 {
183 *fLog << inf << "Run taken before inauguration of IFAE-box... using CT1 pulser." << endl;
184 fColor = MCalibrationCam::kCT1;
185 fStrength = 10.;
186 fIsValid = kTRUE;
187 return kTRUE;
188 }
189
190 fColor = MCalibrationCam::kNONE;
191 fStrength = 0.;
192
193 switch (num)
194 {
195 case 22246:
196 case 22253:
197 case 25792:
198 case 26402:
199 case 35415:
200 case 44768:
201 case 44976:
202 case 45082:
203 case 45083:
204 case 45089:
205 case 45090:
206 case 45091:
207 case 45094:
208 case 45119:
209 case 45249:
210 case 45253:
211 case 45262:
212 case 45274:
213 case 45275:
214 case 45276:
215 case 45365:
216 case 45366:
217 case 45367:
218 case 45368:
219 case 45369:
220 case 45370:
221 case 45371:
222 case 45382:
223 case 45401:
224 case 45419:
225 case 45432:
226 case 45471:
227 case 45485:
228 case 45489:
229 case 45557:
230 case 45562:
231 case 45571:
232 case 45579:
233 case 45607:
234 // case 31756:
235 fColor = MCalibrationCam::kBLUE;
236 break;
237
238 case 30090:
239 case 31745:
240 case 31746:
241 case 31747:
242 case 31748:
243 case 20660:
244 case 20661:
245 case 26408:
246 case 26409:
247 case 26412:
248 case 26568:
249 case 26924:
250 case 45051:
251 case 45084:
252 case 45085:
253 case 45092:
254 case 45227:
255 case 45241:
256 case 45250:
257 case 45254:
258 case 45263:
259 case 45372:
260 case 45373:
261 case 45608:
262 fColor = MCalibrationCam::kGREEN;
263 break;
264
265 case 45086:
266 case 45088:
267 case 45111:
268 case 45115:
269 case 45216:
270 case 45218:
271 case 45226:
272 case 45240:
273 case 45251:
274 case 45278:
275 case 45336:
276 case 45341:
277 case 45358:
278 case 45374:
279 case 45375:
280 case 45376:
281 case 45377:
282 case 45381:
283 case 45400:
284 case 45418:
285 case 45431:
286 case 45470:
287 case 45484:
288 case 45490:
289 case 45556:
290 case 45561:
291 case 45570:
292 case 45578:
293 case 45614:
294 case 45618:
295 fColor = MCalibrationCam::kUV;
296 break;
297
298 case 43914:
299 case 43916:
300 case 43918:
301 case 43920:
302 case 43922:
303 fColor = MCalibrationCam::kCT1;
304 break;
305
306 case 27474:
307 *fLog << err << "Sorry, run 27474 was taken with CLOSED LIDS. It should not be used! " << endl;
308 return kFALSE;
309 break;
310
311 case 45116:
312 case 45609:
313 case 45219:
314 *fLog << err << "Sorry, run " << num << " was taken with a combination of colours used to flat-field ";
315 *fLog << err << "the camera. It cannot be used for the standard calibration " << endl;
316 return kFALSE;
317 break;
318
319 case 45605:
320 *fLog << err << "Sorry, run 45605 was taken with the continuous light source." << endl;
321 *fLog << err << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
322 return kFALSE;
323 break;
324
325 case 45606:
326 *fLog << err << "Sorry, run 45606 was taken with mal-functionning pulser." << endl;
327 *fLog << err << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
328 return kFALSE;
329 break;
330
331 }
332
333 if (fColor != MCalibrationCam::kNONE)
334 {
335 *fLog << inf << "Color determined from the run-number... ";
336 switch (fColor)
337 {
338 case MCalibrationCam::kGREEN: *fLog << "Green."; break;
339 case MCalibrationCam::kBLUE: *fLog << "Blue."; break;
340 case MCalibrationCam::kUV: *fLog << "UV."; break;
341 case MCalibrationCam::kCT1: *fLog << "CT1."; break;
342 default: break;
343 }
344 *fLog << endl;
345 fIsValid = kTRUE;
346 return kTRUE;
347 }
348
349 TString proj = header->GetProjectName();
350 proj.ToLower();
351
352 // Possible green combinations
353 CheckAndSet(proj, "0.1led[s]?gree", MCalibrationCam::kGREEN, 0.1);
354 CheckAndSet(proj, "1led[s]?gree", MCalibrationCam::kGREEN, 1. );
355 CheckAndSet(proj, "2led[s]?gree", MCalibrationCam::kGREEN, 2. );
356 CheckAndSet(proj, "3led[s]?gree", MCalibrationCam::kGREEN, 3. );
357 CheckAndSet(proj, "5led[s]?gree", MCalibrationCam::kGREEN, 5. );
358 CheckAndSet(proj, "6led[s]?gree", MCalibrationCam::kGREEN, 6. );
359 CheckAndSet(proj, "7led[s]?gree", MCalibrationCam::kGREEN, 7. );
360 CheckAndSet(proj, "8led[s]?gree", MCalibrationCam::kGREEN, 8. );
361
362 // Possible blue combinations
363 CheckAndSet(proj, "0.1led[s]?blue", MCalibrationCam::kBLUE, 0.1);
364 CheckAndSet(proj, "1led[s]?blue", MCalibrationCam::kBLUE, 1.);
365 CheckAndSet(proj, "2led[s]?blue", MCalibrationCam::kBLUE, 2.);
366 CheckAndSet(proj, "3led[s]?blue", MCalibrationCam::kBLUE, 3.);
367 CheckAndSet(proj, "5led[s]?blue", MCalibrationCam::kBLUE, 5.);
368 CheckAndSet(proj, "6led[s]?blue", MCalibrationCam::kBLUE, 6.);
369 CheckAndSet(proj, "7led[s]?blue", MCalibrationCam::kBLUE, 7.);
370 CheckAndSet(proj, "8led[s]?blue", MCalibrationCam::kBLUE, 8.);
371 CheckAndSet(proj, "10led[s]?blue", MCalibrationCam::kBLUE, 10.);
372 CheckAndSet(proj, "15led[s]?blue", MCalibrationCam::kBLUE, 15.);
373 CheckAndSet(proj, "20led[s]?blue", MCalibrationCam::kBLUE, 20.);
374 CheckAndSet(proj, "21led[s]?blue", MCalibrationCam::kBLUE, 21.);
375 CheckAndSet(proj, "22led[s]?blue", MCalibrationCam::kBLUE, 22.);
376 CheckAndSet(proj, "23led[s]?blue", MCalibrationCam::kBLUE, 23.);
377
378 // Possible UV combinations
379 CheckAndSet(proj, "1led[s]?uv", MCalibrationCam::kUV, 1.);
380 CheckAndSet(proj, "2led[s]?uv", MCalibrationCam::kUV, 2.);
381 CheckAndSet(proj, "3led[s]?uv", MCalibrationCam::kUV, 3.);
382 CheckAndSet(proj, "5led[s]?uv", MCalibrationCam::kUV, 5.);
383 CheckAndSet(proj, "6led[s]?uv", MCalibrationCam::kUV, 6.);
384 CheckAndSet(proj, "7led[s]?uv", MCalibrationCam::kUV, 7.);
385 CheckAndSet(proj, "8led[s]?uv", MCalibrationCam::kUV, 8.);
386 CheckAndSet(proj, "10led[s]?uv", MCalibrationCam::kUV, 10.);
387 CheckAndSet(proj, "11led[s]?uv", MCalibrationCam::kUV, 11.);
388 CheckAndSet(proj, "12led[s]?uv", MCalibrationCam::kUV, 12.);
389 CheckAndSet(proj, "13led[s]?uv", MCalibrationCam::kUV, 13.);
390
391 // Possible slot combinations
392 TRegexp slot("slot");
393 if (proj.Contains(slot))
394 {
395 proj.ReplaceAll("slot","");
396 UInt_t nr = 0;
397 TRegexp slotnr("^[0-9]");
398
399 if (proj.Contains(slotnr))
400 {
401 proj.Replace(2,99,"");
402 proj.ReplaceAll("u","");
403 proj.ReplaceAll("v","");
404 proj.ReplaceAll("g","");
405 nr = atoi(proj.Data())-1;
406
407 fColor = nr < 2 ? MCalibrationCam::kGREEN :
408 ( nr < 3 ) ? MCalibrationCam::kBLUE :
409 ( nr < 5 ) ? MCalibrationCam::kUV :
410 ( nr < 11 ) ? MCalibrationCam::kBLUE :
411 ( nr < 13 ) ? MCalibrationCam::kUV :
412 ( nr < 14 ) ? MCalibrationCam::kBLUE :
413 ( nr < 16 ) ? MCalibrationCam::kGREEN :
414 MCalibrationCam::kCT1;
415
416 switch (nr)
417 {
418 case 0:
419 fStrength = 5;
420 break;
421 case 1:
422 fStrength = 2.;
423 break;
424 case 2:
425 fStrength = 5.;
426 break;
427 case 3:
428 fStrength = 1.;
429 break;
430 case 4:
431 fStrength = 2.;
432 break;
433 case 5:
434 fStrength = 5.;
435 break;
436 case 6:
437 fStrength = 5.;
438 break;
439 case 7:
440 fStrength = 2.;
441 break;
442 case 8:
443 fStrength = 0.2;
444 break;
445 case 9:
446 fStrength = 0.;
447 break;
448 case 10:
449 fStrength = 1.;
450 break;
451 case 11:
452 fStrength = 5.;
453 break;
454 case 12:
455 fStrength = 5.;
456 break;
457 case 13:
458 fStrength = 5.;
459 break;
460 case 14:
461 fStrength = 1;
462 break;
463 case 15:
464 fStrength = 0.2;
465 break;
466 }
467 }
468 }
469
470 if (fColor == MCalibrationCam::kNONE)
471 {
472 CheckAndSet(proj, "gree", MCalibrationCam::kGREEN, 1.);
473 CheckAndSet(proj, "blue", MCalibrationCam::kBLUE, 1.);
474 CheckAndSet(proj, "uv", MCalibrationCam::kUV, 1.);
475 CheckAndSet(proj, "ct1", MCalibrationCam::kCT1, 1.);
476
477 if (fColor != MCalibrationCam::kNONE)
478 *fLog << inf << "Color determined from project-name (" << proj << ")... ";
479 else
480 if (proj.Contains("cl",TString::kIgnoreCase))
481 {
482 *fLog << err;
483 *fLog << "This run has been taken with the continuous light source." << endl;
484 *fLog << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
485 return kFALSE;
486 }
487 }
488 else
489 *fLog << inf << "Color and Intensity determined from project-name (" << proj << ")... ";
490
491 if (fColor == MCalibrationCam::kNONE)
492 {
493 *fLog << err;
494 *fLog << "Sorry, calibration run " << num << " was taken before the events could be" << endl;
495 *fLog << "flagged with a color by the digital modul and no color" << endl;
496 *fLog << "could be determined... abort." << endl;
497 return kFALSE;
498 }
499
500 switch (fColor)
501 {
502 case MCalibrationCam::kGREEN: *fLog << "Green."; break;
503 case MCalibrationCam::kBLUE: *fLog << "Blue."; break;
504 case MCalibrationCam::kUV: *fLog << "UV."; break;
505 case MCalibrationCam::kCT1: *fLog << "CT1."; break;
506 default: break;
507 }
508 *fLog << endl;
509
510 fIsValid = kTRUE;
511
512 return kTRUE;
513}
514
515// --------------------------------------------------------------------------
516//
517// Sets the pattern to MCalibrationPattern from outside, if fIsValid is set.
518//
519Int_t MCalibColorSet::Process()
520{
521
522 if (fIsValid)
523 {
524 if (fColor == MCalibrationCam::kNONE)
525 return kCONTINUE;
526
527 fPattern->SetPulserColor(fColor);
528 fPattern->SetPulserStrength(fStrength);
529 }
530
531 return kTRUE;
532}
Note: See TracBrowser for help on using the repository browser.