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

Last change on this file since 5856 was 5835, checked in by gaug, 20 years ago
*** empty log message ***
File size: 14.3 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 45249:
237 case 45253:
238 case 45262:
239 case 45274:
240 case 45275:
241 case 45276:
242 case 45365:
243 case 45366:
244 case 45367:
245 case 45368:
246 case 45369:
247 case 45370:
248 case 45371:
249 case 45382:
250 case 45401:
251 case 45419:
252 case 45432:
253 case 45471:
254 case 45485:
255 case 45489:
256 case 45557:
257 case 45562:
258 case 45571:
259 case 45579:
260 case 45607:
261 // case 31756:
262 color = kBLUE;
263 break;
264
265 case 30090:
266 case 31745:
267 case 31746:
268 case 31747:
269 case 31748:
270 case 20660:
271 case 20661:
272 case 26408:
273 case 26409:
274 case 26412:
275 case 26568:
276 case 26924:
277 case 45227:
278 case 45241:
279 case 45250:
280 case 45254:
281 case 45263:
282 case 45372:
283 case 45373:
284 case 45608:
285 color = kGREEN;
286 break;
287
288 case 45216:
289 case 45218:
290 case 45226:
291 case 45240:
292 case 45251:
293 case 45278:
294 case 45336:
295 case 45341:
296 case 45358:
297 case 45374:
298 case 45375:
299 case 45376:
300 case 45377:
301 case 45381:
302 case 45400:
303 case 45418:
304 case 45431:
305 case 45470:
306 case 45484:
307 case 45490:
308 case 45556:
309 case 45561:
310 case 45570:
311 case 45578:
312 case 45614:
313 case 45618:
314 color = kUV;
315 break;
316
317 case 27474:
318 *fLog << err << "Sorry, run 27474 was taken with CLOSED LIDS. It should not be used! " << endl;
319 return kFALSE;
320 break;
321
322 case 45609:
323 case 45219:
324 *fLog << err << "Sorry, run 45219 was taken with a combination of colours used to flat-field ";
325 *fLog << err << "the camera. It cannot be used for the standard calibration " << endl;
326 return kFALSE;
327 break;
328
329 case 45605:
330 *fLog << err << "Sorry, run 45605 was taken with the continuous light source." << endl;
331 *fLog << err << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
332 return kFALSE;
333 break;
334
335 case 45606:
336 *fLog << err << "Sorry, run 45606 was taken with mal-functionning pulser." << endl;
337 *fLog << err << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
338 return kFALSE;
339 break;
340
341 }
342
343 if (color!=kNONE)
344 {
345 *fLog << inf << "Color determined from the run-number... ";
346 switch (color)
347 {
348 case kGREEN: *fLog << "Green."; fPattern |= k5LedGreen; break;
349 case kBLUE: *fLog << "Blue."; fPattern |= k5LedBlue1; break;
350 case kUV: *fLog << "UV."; fPattern |= k10LedUV; break;
351 }
352 *fLog << endl;
353 fIsValid = kTRUE;
354 return kTRUE;
355 }
356
357 TString proj = header->GetProjectName();
358 proj.ToLower();
359
360 // Possible green combinations
361 CheckAndSet(proj, "0.1led[s]?gree", fPattern, k01LedGreen, color, kGREEN);
362 CheckAndSet(proj, "1led[s]?gree", fPattern, k1LedGreen, color, kGREEN);
363 CheckAndSet(proj, "2led[s]?gree", fPattern, k2LedGreen, color, kGREEN);
364 CheckAndSet(proj, "3led[s]?gree", fPattern, k3LedGreen, color, kGREEN);
365 CheckAndSet(proj, "5led[s]?gree", fPattern, k5LedGreen, color, kGREEN);
366 CheckAndSet(proj, "6led[s]?gree", fPattern, k6LedGreen, color, kGREEN);
367 CheckAndSet(proj, "7led[s]?gree", fPattern, k7LedGreen, color, kGREEN);
368 CheckAndSet(proj, "8led[s]?gree", fPattern, k8LedGreen, color, kGREEN);
369
370 // Possible blue combinations
371 CheckAndSet(proj, "0.1led[s]?blue", fPattern, k01LedBlue, color, kBLUE);
372 CheckAndSet(proj, "1led[s]?blue", fPattern, k1LedBlue, color, kBLUE);
373 CheckAndSet(proj, "2led[s]?blue", fPattern, k2LedBlue, color, kBLUE);
374 CheckAndSet(proj, "3led[s]?blue", fPattern, k3LedBlue, color, kBLUE);
375 CheckAndSet(proj, "5led[s]?blue", fPattern, k5LedBlue1, color, kBLUE);
376 CheckAndSet(proj, "6led[s]?blue", fPattern, k6LedBlue, color, kBLUE);
377 CheckAndSet(proj, "7led[s]?blue", fPattern, k7LedBlue, color, kBLUE);
378 CheckAndSet(proj, "8led[s]?blue", fPattern, k8LedBlue, color, kBLUE);
379 CheckAndSet(proj, "10led[s]?blue", fPattern, k10LedBlue, color, kBLUE);
380 CheckAndSet(proj, "15led[s]?blue", fPattern, k15LedBlue, color, kBLUE);
381 CheckAndSet(proj, "20led[s]?blue", fPattern, k20LedBlue, color, kBLUE);
382 CheckAndSet(proj, "21led[s]?blue", fPattern, k21LedBlue, color, kBLUE);
383 CheckAndSet(proj, "22led[s]?blue", fPattern, k22LedBlue, color, kBLUE);
384 CheckAndSet(proj, "23led[s]?blue", fPattern, k23LedBlue, color, kBLUE);
385
386 // Possible UV combinations
387 CheckAndSet(proj, "1led[s]?uv", fPattern, k1LedUV, color, kUV);
388 CheckAndSet(proj, "2led[s]?uv", fPattern, k2LedUV, color, kUV);
389 CheckAndSet(proj, "3led[s]?uv", fPattern, k3LedUV, color, kUV);
390 CheckAndSet(proj, "5led[s]?uv", fPattern, k5LedUV1, color, kUV);
391 CheckAndSet(proj, "6led[s]?uv", fPattern, k6LedUV, color, kUV);
392 CheckAndSet(proj, "7led[s]?uv", fPattern, k7LedUV, color, kUV);
393 CheckAndSet(proj, "8led[s]?uv", fPattern, k8LedUV, color, kUV);
394 CheckAndSet(proj, "10led[s]?uv", fPattern, k10LedUV, color, kUV);
395 CheckAndSet(proj, "11led[s]?uv", fPattern, k11LedUV, color, kUV);
396 CheckAndSet(proj, "12led[s]?uv", fPattern, k12LedUV, color, kUV);
397 CheckAndSet(proj, "13led[s]?uv", fPattern, k13LedUV, color, kUV);
398
399 // Possible slot combinations
400 TRegexp slot("slot");
401 if (proj.Contains(slot))
402 {
403 proj.ReplaceAll("slot","");
404 UInt_t nr = 0;
405 TRegexp slotnr("^[0-9]");
406
407 if (proj.Contains(slotnr))
408 {
409 fPattern = 0;
410 proj.Replace(2,99,"");
411 proj.ReplaceAll("u","");
412 proj.ReplaceAll("v","");
413 proj.ReplaceAll("g","");
414 nr = atoi(proj.Data())-1;
415
416 fPattern |= BIT(nr);
417
418 color = nr < 2 ? kGREEN :
419 ( nr < 3 ) ? kBLUE :
420 ( nr < 5 ) ? kUV :
421 ( nr < 11 ) ? kBLUE :
422 ( nr < 13 ) ? kUV :
423 ( nr < 14 ) ? kBLUE :
424 ( nr < 16 ) ? kGREEN :
425 kCT1;
426 }
427 }
428
429 if (color == kNONE)
430 {
431 CheckAndSet(proj, "gree", fPattern, k5LedGreen, color, kGREEN);
432 CheckAndSet(proj, "blue", fPattern, k5LedBlue1, color, kBLUE);
433 CheckAndSet(proj, "uv", fPattern, k5LedUV1, color, kUV);
434 CheckAndSet(proj, "ct1", fPattern, kCT1Pulser, color, kCT1);
435
436 if (color != kNONE)
437 *fLog << inf << "Color determined from project-name (" << proj << ")... ";
438 else
439 if (proj.Contains("cl",TString::kIgnoreCase))
440 {
441 *fLog << err;
442 *fLog << "This run has been taken with the continuous light source." << endl;
443 *fLog << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
444 return kFALSE;
445 }
446 }
447 else
448 *fLog << inf << "Color and Intensity determined from project-name (" << proj << ")... ";
449
450 if (color == kNONE)
451 {
452 *fLog << err;
453 *fLog << "Sorry, calibration run " << num << " was taken before the events could be" << endl;
454 *fLog << "flagged with a color by the digital modul and no color" << endl;
455 *fLog << "could be determined... abort." << endl;
456 return kFALSE;
457 }
458
459 switch (color)
460 {
461 case kGREEN: *fLog << "Green."; break;
462 case kBLUE: *fLog << "Blue."; break;
463 case kUV: *fLog << "UV."; break;
464 case kCT1: *fLog << "CT1."; break;
465 }
466 *fLog << endl;
467
468 fIsValid = kTRUE;
469
470 return kTRUE;
471}
472
473// --------------------------------------------------------------------------
474//
475// Sets the pattern to MRawEvtHeader from outside, if fIsValid is set.
476//
477Int_t MCalibColorSet::Process()
478{
479
480 if (fIsValid)
481 {
482 if (fPattern == 0)
483 return kCONTINUE;
484
485 fHeader->SetCalibrationPattern(fPattern);
486 }
487
488 return kTRUE;
489}
Note: See TracBrowser for help on using the repository browser.