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

Last change on this file since 5678 was 5677, checked in by gaug, 20 years ago
*** empty log message ***
File size: 14.8 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 fPattern = 0;
205
206 switch (num)
207 {
208 case 22246:
209 case 22253:
210 case 25792:
211 case 26402:
212 case 35415:
213 case 44768:
214 case 44976:
215 case 45249:
216 case 45253:
217 case 45262:
218 case 45274:
219 case 45275:
220 case 45276:
221 case 45365:
222 case 45366:
223 case 45367:
224 case 45368:
225 case 45369:
226 case 45370:
227 case 45371:
228 case 45382:
229 case 45401:
230 case 45419:
231 case 45432:
232 case 45471:
233 case 45485:
234 case 45489:
235 // case 31756:
236 color = 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 45227:
252 case 45241:
253 case 45250:
254 case 45254:
255 case 45263:
256 case 45372:
257 case 45373:
258 color = kGREEN;
259 break;
260
261 case 45216:
262 case 45218:
263 case 45226:
264 case 45240:
265 case 45251:
266 case 45278:
267 case 45336:
268 case 45341:
269 case 45358:
270 case 45374:
271 case 45375:
272 case 45376:
273 case 45377:
274 case 45381:
275 case 45400:
276 case 45418:
277 case 45431:
278 case 45470:
279 case 45484:
280 case 45490:
281 color = kUV;
282 break;
283
284 case 27474:
285 *fLog << err << "Sorry, run 27474 was taken with CLOSED LIDS. It should not be used! " << endl;
286 return kFALSE;
287 break;
288
289 case 45219:
290 *fLog << err << "Sorry, run 45219 was taken with a combination of colours used to flat-field ";
291 *fLog << err << "the camera. It cannot be used for the standard calibration " << endl;
292 return kFALSE;
293 break;
294 }
295
296 if (color!=kNONE)
297 {
298 *fLog << inf << "Color determined from the run-number... ";
299 switch (color)
300 {
301 case kGREEN: *fLog << "Green."; fPattern |= k5LedGreen; break;
302 case kBLUE: *fLog << "Blue."; fPattern |= k5LedBlue1; break;
303 case kUV: *fLog << "UV."; fPattern |= k10LedUV; break;
304 }
305 *fLog << endl;
306 fIsValid = kTRUE;
307 return kTRUE;
308 }
309 else
310 {
311
312 TString proj = header->GetProjectName();
313 proj.ToLower();
314
315 // Possible green combinations
316 TRegexp gre0("0.1led[sS]?gree");
317 if (proj.Contains(gre0))
318 { fPattern |= k01LedGreen; color = kGREEN; }
319 TRegexp gre1("1led[sS]?gree");
320 if (proj.Contains(gre1))
321 { fPattern |= k1LedGreen; color = kGREEN; }
322 TRegexp gre2("2led[sS]?gree");
323 if (proj.Contains(gre2))
324 { fPattern |= k2LedGreen; color = kGREEN; }
325 TRegexp gre3("3led[sS]?gree");
326 if (proj.Contains(gre3))
327 { fPattern |= k3LedGreen; color = kGREEN; }
328 TRegexp gre5("5led[sS]?gree");
329 if (proj.Contains(gre5))
330 { fPattern |= k5LedGreen; color = kGREEN; }
331 TRegexp gre6("6led[sS]?gree");
332 if (proj.Contains(gre6))
333 { fPattern |= k6LedGreen; color = kGREEN; }
334 TRegexp gre7("7led[sS]?gree");
335 if (proj.Contains(gre7))
336 { fPattern |= k7LedGreen; color = kGREEN; }
337 TRegexp gre8("8led[sS]?gree");
338 if (proj.Contains(gre8))
339 { fPattern |= k8LedGreen; color = kGREEN; }
340
341 // Possible blue combinations
342 TRegexp blu0("0.1led[sS]?blue");
343 if (proj.Contains(blu0))
344 { fPattern |= k01LedBlue; color = kBLUE; }
345 TRegexp blu1("1led[sS]?blue");
346 if (proj.Contains(blu1))
347 { fPattern |= k1LedBlue; color = kBLUE; }
348 TRegexp blu2("2led[sS]?blue");
349 if (proj.Contains(blu2))
350 { fPattern |= k2LedBlue; color = kBLUE; }
351 TRegexp blu3("3led[sS]?blue");
352 if (proj.Contains(blu3))
353 { fPattern |= k3LedBlue; color = kBLUE; }
354 TRegexp blu5("5led[sS]?blue");
355 if (proj.Contains(blu5))
356 { fPattern |= k5LedBlue1; color = kBLUE; }
357 TRegexp blu6("6led[sS]?blue");
358 if (proj.Contains(blu6))
359 { fPattern |= k6LedBlue; color = kBLUE; }
360 TRegexp blu7("7led[sS]?blue");
361 if (proj.Contains(blu7))
362 { fPattern |= k7LedBlue; color = kBLUE; }
363 TRegexp blu8("8led[sS]?blue");
364 if (proj.Contains(blu8))
365 { fPattern |= k8LedBlue; color = kBLUE; }
366 TRegexp blu10("10led[sS]?blue");
367 if (proj.Contains(blu10))
368 { fPattern |= k10LedBlue; color = kBLUE; }
369 TRegexp blu15("15led[sS]?blue");
370 if (proj.Contains(blu15))
371 { fPattern |= k15LedBlue; color = kBLUE; }
372 TRegexp blu20("20led[sS]?blue");
373 if (proj.Contains(blu20))
374 { fPattern |= k20LedBlue; color = kBLUE; }
375 TRegexp blu21("21led[sS]?blue");
376 if (proj.Contains(blu21))
377 { fPattern |= k21LedBlue; color = kBLUE; }
378 TRegexp blu22("22led[sS]?blue");
379 if (proj.Contains(blu22))
380 { fPattern |= k22LedBlue; color = kBLUE; }
381 TRegexp blu23("23led[sS]?blue");
382 if (proj.Contains(blu23))
383 { fPattern |= k23LedBlue; color = kBLUE; }
384
385 // Possible UV combinations
386 TRegexp uv1("1led[sS]?uv");
387 if (proj.Contains(uv1))
388 { fPattern |= k1LedUV; color = kUV; }
389 TRegexp uv2("2led[sS]?uv");
390 if (proj.Contains(uv2))
391 { fPattern |= k2LedUV; color = kUV; }
392 TRegexp uv3("3led[sS]?uv");
393 if (proj.Contains(uv3))
394 { fPattern |= k3LedUV; color = kUV; }
395 TRegexp uv5("5led[sS]?uv");
396 if (proj.Contains(uv5))
397 { fPattern |= k5LedUV1; color = kUV; }
398 TRegexp uv6("6led[sS]?uv");
399 if (proj.Contains(uv6))
400 { fPattern |= k6LedUV; color = kUV; }
401 TRegexp uv7("7led[sS]?uv");
402 if (proj.Contains(uv7))
403 { fPattern |= k7LedUV; color = kUV; }
404 TRegexp uv8("8led[sS]?uv");
405 if (proj.Contains(uv8))
406 { fPattern |= k8LedUV; color = kUV; }
407 TRegexp uv10("10led[sS]?uv");
408 if (proj.Contains(uv10))
409 { fPattern |= k10LedUV; color = kUV; }
410 TRegexp uv11("11led[sS]?uv");
411 if (proj.Contains(uv11))
412 { fPattern |= k11LedUV; color = kUV; }
413 TRegexp uv12("12led[sS]?uv");
414 if (proj.Contains(uv12))
415 { fPattern |= k12LedUV; color = kUV; }
416 TRegexp uv13("13led[sS]?uv");
417 if (proj.Contains(uv13))
418 { fPattern |= k13LedUV; color = kUV; }
419
420 // Possible slot combinations
421 TRegexp slot("slot");
422 if (proj.Contains(slot))
423 {
424 proj.ReplaceAll("slot","");
425 UInt_t nr = 0;
426 TRegexp slotnr("^[0-9]");
427
428 if (proj.Contains(slotnr))
429 { fPattern = 0; proj.Replace(2,99,"");
430 proj.ReplaceAll("u","");
431 proj.ReplaceAll("v","");
432 proj.ReplaceAll("g","");
433 nr = atoi(proj.Data())-1;
434 fPattern |= BIT(nr);
435 color = nr < 2 ? kGREEN :
436 ( nr < 3 ) ? kBLUE :
437 ( nr < 5 ) ? kUV :
438 ( nr < 11 ) ? kBLUE :
439 ( nr < 13 ) ? kUV :
440 ( nr < 14 ) ? kBLUE :
441 ( nr < 16 ) ? kGREEN :
442 kCT1;
443 }
444 }
445
446 if (color != kNONE)
447 *fLog << inf << "Color and Intensity determined from project-name (" << proj << ")... ";
448 else
449 {
450 if (proj.Contains("gree",TString::kIgnoreCase))
451 { fPattern |= k5LedGreen; color = kGREEN; }
452 if (proj.Contains("blue",TString::kIgnoreCase))
453 { fPattern |=k5LedBlue1; color = kBLUE;}
454 if (proj.Contains("uv",TString::kIgnoreCase))
455 { fPattern |=k5LedUV1 ; color = kUV; }
456 if (proj.Contains("ct1",TString::kIgnoreCase))
457 { fPattern |=kCT1Pulser; color = kCT1; }
458 if (color != kNONE)
459 *fLog << inf << "Color determined from project-name (" << proj << ")... ";
460 else if (proj.Contains("cl",TString::kIgnoreCase))
461 {
462 *fLog << warn << "This run has been taken with the continuous light source." << endl;
463 *fLog << warn
464 << "It cannot be used for calibration. Try to run a pedestal extraction on it." << endl;
465 fPattern = 0;
466 fIsValid = kTRUE;
467 return kTRUE;
468 }
469 }
470 }
471
472 if (color==kNONE)
473 {
474 *fLog << err << "Sorry, calibration run " << num << " was taken before the events could be" << endl;
475 *fLog << "flagged with a color by the digital modul and no color" << endl;
476 *fLog << "could be determined... abort." << endl;
477 return kFALSE;
478 }
479
480 switch (color)
481 {
482 case kGREEN: *fLog << "Green."; break;
483 case kBLUE: *fLog << "Blue."; break;
484 case kUV: *fLog << "UV."; break;
485 case kCT1: *fLog << "CT1."; break;
486 }
487 *fLog << endl;
488
489 fIsValid = kTRUE;
490
491 return kTRUE;
492}
493
494// --------------------------------------------------------------------------
495//
496// Sets the pattern to MRawEvtHeader from outside, if fIsValid is set.
497//
498Int_t MCalibColorSet::Process()
499{
500
501 if (fIsValid)
502 {
503 if (fPattern == 0)
504 return kCONTINUE;
505
506 fHeader->SetCalibrationPattern(fPattern);
507 }
508
509 return kTRUE;
510}
Note: See TracBrowser for help on using the repository browser.