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