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

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