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

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