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

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