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

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