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

Last change on this file since 5895 was 5885, 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// 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 27474:
333 *fLog << err << "Sorry, run 27474 was taken with CLOSED LIDS. It should not be used! " << endl;
334 return kFALSE;
335 break;
336
337 case 45116:
338 case 45609:
339 case 45219:
340 *fLog << err << "Sorry, run " << num << " was taken with a combination of colours used to flat-field ";
341 *fLog << err << "the camera. It cannot be used for the standard calibration " << endl;
342 return kFALSE;
343 break;
344
345 case 45605:
346 *fLog << err << "Sorry, run 45605 was taken with the continuous light source." << endl;
347 *fLog << err << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
348 return kFALSE;
349 break;
350
351 case 45606:
352 *fLog << err << "Sorry, run 45606 was taken with mal-functionning pulser." << endl;
353 *fLog << err << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
354 return kFALSE;
355 break;
356
357 }
358
359 if (color!=kNONE)
360 {
361 *fLog << inf << "Color determined from the run-number... ";
362 switch (color)
363 {
364 case kGREEN: *fLog << "Green."; fPattern |= k5LedGreen; break;
365 case kBLUE: *fLog << "Blue."; fPattern |= k5LedBlue1; break;
366 case kUV: *fLog << "UV."; fPattern |= k10LedUV; break;
367 }
368 *fLog << endl;
369 fIsValid = kTRUE;
370 return kTRUE;
371 }
372
373 TString proj = header->GetProjectName();
374 proj.ToLower();
375
376 // Possible green combinations
377 CheckAndSet(proj, "0.1led[s]?gree", fPattern, k01LedGreen, color, kGREEN);
378 CheckAndSet(proj, "1led[s]?gree", fPattern, k1LedGreen, color, kGREEN);
379 CheckAndSet(proj, "2led[s]?gree", fPattern, k2LedGreen, color, kGREEN);
380 CheckAndSet(proj, "3led[s]?gree", fPattern, k3LedGreen, color, kGREEN);
381 CheckAndSet(proj, "5led[s]?gree", fPattern, k5LedGreen, color, kGREEN);
382 CheckAndSet(proj, "6led[s]?gree", fPattern, k6LedGreen, color, kGREEN);
383 CheckAndSet(proj, "7led[s]?gree", fPattern, k7LedGreen, color, kGREEN);
384 CheckAndSet(proj, "8led[s]?gree", fPattern, k8LedGreen, color, kGREEN);
385
386 // Possible blue combinations
387 CheckAndSet(proj, "0.1led[s]?blue", fPattern, k01LedBlue, color, kBLUE);
388 CheckAndSet(proj, "1led[s]?blue", fPattern, k1LedBlue, color, kBLUE);
389 CheckAndSet(proj, "2led[s]?blue", fPattern, k2LedBlue, color, kBLUE);
390 CheckAndSet(proj, "3led[s]?blue", fPattern, k3LedBlue, color, kBLUE);
391 CheckAndSet(proj, "5led[s]?blue", fPattern, k5LedBlue1, color, kBLUE);
392 CheckAndSet(proj, "6led[s]?blue", fPattern, k6LedBlue, color, kBLUE);
393 CheckAndSet(proj, "7led[s]?blue", fPattern, k7LedBlue, color, kBLUE);
394 CheckAndSet(proj, "8led[s]?blue", fPattern, k8LedBlue, color, kBLUE);
395 CheckAndSet(proj, "10led[s]?blue", fPattern, k10LedBlue, color, kBLUE);
396 CheckAndSet(proj, "15led[s]?blue", fPattern, k15LedBlue, color, kBLUE);
397 CheckAndSet(proj, "20led[s]?blue", fPattern, k20LedBlue, color, kBLUE);
398 CheckAndSet(proj, "21led[s]?blue", fPattern, k21LedBlue, color, kBLUE);
399 CheckAndSet(proj, "22led[s]?blue", fPattern, k22LedBlue, color, kBLUE);
400 CheckAndSet(proj, "23led[s]?blue", fPattern, k23LedBlue, color, kBLUE);
401
402 // Possible UV combinations
403 CheckAndSet(proj, "1led[s]?uv", fPattern, k1LedUV, color, kUV);
404 CheckAndSet(proj, "2led[s]?uv", fPattern, k2LedUV, color, kUV);
405 CheckAndSet(proj, "3led[s]?uv", fPattern, k3LedUV, color, kUV);
406 CheckAndSet(proj, "5led[s]?uv", fPattern, k5LedUV1, color, kUV);
407 CheckAndSet(proj, "6led[s]?uv", fPattern, k6LedUV, color, kUV);
408 CheckAndSet(proj, "7led[s]?uv", fPattern, k7LedUV, color, kUV);
409 CheckAndSet(proj, "8led[s]?uv", fPattern, k8LedUV, color, kUV);
410 CheckAndSet(proj, "10led[s]?uv", fPattern, k10LedUV, color, kUV);
411 CheckAndSet(proj, "11led[s]?uv", fPattern, k11LedUV, color, kUV);
412 CheckAndSet(proj, "12led[s]?uv", fPattern, k12LedUV, color, kUV);
413 CheckAndSet(proj, "13led[s]?uv", fPattern, k13LedUV, color, kUV);
414
415 // Possible slot combinations
416 TRegexp slot("slot");
417 if (proj.Contains(slot))
418 {
419 proj.ReplaceAll("slot","");
420 UInt_t nr = 0;
421 TRegexp slotnr("^[0-9]");
422
423 if (proj.Contains(slotnr))
424 {
425 fPattern = 0;
426 proj.Replace(2,99,"");
427 proj.ReplaceAll("u","");
428 proj.ReplaceAll("v","");
429 proj.ReplaceAll("g","");
430 nr = atoi(proj.Data())-1;
431
432 fPattern |= BIT(nr);
433
434 color = nr < 2 ? kGREEN :
435 ( nr < 3 ) ? kBLUE :
436 ( nr < 5 ) ? kUV :
437 ( nr < 11 ) ? kBLUE :
438 ( nr < 13 ) ? kUV :
439 ( nr < 14 ) ? kBLUE :
440 ( nr < 16 ) ? kGREEN :
441 kCT1;
442 }
443 }
444
445 if (color == kNONE)
446 {
447 CheckAndSet(proj, "gree", fPattern, k5LedGreen, color, kGREEN);
448 CheckAndSet(proj, "blue", fPattern, k5LedBlue1, color, kBLUE);
449 CheckAndSet(proj, "uv", fPattern, k5LedUV1, color, kUV);
450 CheckAndSet(proj, "ct1", fPattern, kCT1Pulser, color, kCT1);
451
452 if (color != kNONE)
453 *fLog << inf << "Color determined from project-name (" << proj << ")... ";
454 else
455 if (proj.Contains("cl",TString::kIgnoreCase))
456 {
457 *fLog << err;
458 *fLog << "This run has been taken with the continuous light source." << endl;
459 *fLog << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
460 return kFALSE;
461 }
462 }
463 else
464 *fLog << inf << "Color and Intensity determined from project-name (" << proj << ")... ";
465
466 if (color == kNONE)
467 {
468 *fLog << err;
469 *fLog << "Sorry, calibration run " << num << " was taken before the events could be" << endl;
470 *fLog << "flagged with a color by the digital modul and no color" << endl;
471 *fLog << "could be determined... abort." << endl;
472 return kFALSE;
473 }
474
475 switch (color)
476 {
477 case kGREEN: *fLog << "Green."; break;
478 case kBLUE: *fLog << "Blue."; break;
479 case kUV: *fLog << "UV."; break;
480 case kCT1: *fLog << "CT1."; break;
481 }
482 *fLog << endl;
483
484 fIsValid = kTRUE;
485
486 return kTRUE;
487}
488
489// --------------------------------------------------------------------------
490//
491// Sets the pattern to MRawEvtHeader from outside, if fIsValid is set.
492//
493Int_t MCalibColorSet::Process()
494{
495
496 if (fIsValid)
497 {
498 if (fPattern == 0)
499 return kCONTINUE;
500
501 fHeader->SetCalibrationPattern(fPattern);
502 }
503
504 return kTRUE;
505}
Note: See TracBrowser for help on using the repository browser.