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): Markus Gaug, 11/2003 <mailto:markus@ifae.es>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 | /////////////////////////////////////////////////////////////////////////////
|
---|
25 | //
|
---|
26 | // calibration.C
|
---|
27 | //
|
---|
28 | // Needs as arguments the run number of a calibration file ("*_C_*.root") and
|
---|
29 | // the run number of the corresponding pedestal file ("*_P_*.root").
|
---|
30 | //
|
---|
31 | // The TString inpath has to be set correctly.
|
---|
32 | //
|
---|
33 | // The macro searches for the pulser colour which corresponds to the calibration
|
---|
34 | // run number. If the run number is smaller than 20000, pulser colour "CT1"
|
---|
35 | // is assumed, otherwise, it searches for the strings "green", "blue", "uv" or
|
---|
36 | // "ct1" in the filenames. If no colour or multiple colours are found, the
|
---|
37 | // execution is aborted.
|
---|
38 | //
|
---|
39 | // The container MBadPixelsCam is created and followed during the execution of the
|
---|
40 | // rest of the macro.
|
---|
41 | //
|
---|
42 | // A first loop over the pedestal file is performed using the class MJPedestal
|
---|
43 | //
|
---|
44 | // The container MCalibrationQECam is created and followed during the execution of the
|
---|
45 | // rest of the macro.
|
---|
46 | //
|
---|
47 | // A loop over the calibration files is performed using the class MJCalibration.
|
---|
48 | // The results are displayed using the MJCalibration::SetNormalDisplay() facility,
|
---|
49 | // but other displays can easily be uncommented.
|
---|
50 | // The call to MJCalibration skips the relative time calibration, which can be
|
---|
51 | // uncommented as well.
|
---|
52 | //
|
---|
53 | // Last, a third loop is performed over the calibration file again in order to
|
---|
54 | // "calibrate" it and test the resulting outcome.
|
---|
55 | //
|
---|
56 | //////////////////////////////////////////////////////////////////////////////////////////
|
---|
57 | #include "MJPedestal.h"
|
---|
58 | #include "MJCalibration.h"
|
---|
59 | #include "MJExtractSignal.h"
|
---|
60 | #include "MJExtractCalibTest.h"
|
---|
61 | #include "MExtractFixedWindowPeakSearch.h"
|
---|
62 | #include "MExtractSlidingWindow.h"
|
---|
63 | #include "MExtractFixedWindow.h"
|
---|
64 | #include "MExtractFixedWindowSpline.h"
|
---|
65 | #include "MExtractAmplitudeSpline.h"
|
---|
66 | #include "MExtractTimeHighestIntegral.h"
|
---|
67 | #include "MExtractTimeFastSpline.h"
|
---|
68 | #include "MExtractTimeAndChargeDigitalFilter.h"
|
---|
69 | #include "MExtractTimeAndChargeSlidingWindow.h"
|
---|
70 | #include "MExtractTimeAndChargeSpline.h"
|
---|
71 | #include "MRunIter.h"
|
---|
72 | #include "MStatusDisplay.h"
|
---|
73 | #include "MCalibrationQECamMagic.h"
|
---|
74 | #include "MCalibrationQECam.h"
|
---|
75 | #include "MBadPixelsCam.h"
|
---|
76 | #include "MArgs.h"
|
---|
77 | #include "MArray.h"
|
---|
78 | #include "MLog.h"
|
---|
79 | #include "MParContainer.h"
|
---|
80 |
|
---|
81 | #include "TStyle.h"
|
---|
82 | #include "TObject.h"
|
---|
83 | #include "TObjectTable.h"
|
---|
84 | #include "TSystem.h"
|
---|
85 |
|
---|
86 | #include <fstream>
|
---|
87 |
|
---|
88 | using namespace std;
|
---|
89 |
|
---|
90 | static TString outpath = "./";
|
---|
91 | static TString inpath = "/home/rootdata/Calib/2004_07_06";
|
---|
92 | static TString badfile = "";
|
---|
93 | //static TString badfile = "badpixels_only0_559_560.dat";
|
---|
94 | static TString weightfile = "msignal/calibration_weights_UV.dat";
|
---|
95 | //static TString weightfile = "msignal/cosmics_weights.dat";
|
---|
96 | //
|
---|
97 | // the default pedestal run for the calibration
|
---|
98 | //
|
---|
99 | static const Int_t pedrun = 31756;
|
---|
100 | //
|
---|
101 | // the default start calibration run
|
---|
102 | //
|
---|
103 | static const Int_t calrun1 = 31755;
|
---|
104 | //
|
---|
105 | // the default last calibration run (if 0, only one run is taken, otherwise consecutive runs
|
---|
106 | // between calrun1 and calrun2)
|
---|
107 | //
|
---|
108 | static const Int_t calrun2 = 0;
|
---|
109 | //
|
---|
110 | // A switch to output debugging information about Objects use
|
---|
111 | //
|
---|
112 | static Bool_t debug = kFALSE;
|
---|
113 | //
|
---|
114 | // A switch to use the Blind Pixel
|
---|
115 | //
|
---|
116 | static Bool_t blindpix = kTRUE;
|
---|
117 | //
|
---|
118 | // A switch to use the PIN Diode
|
---|
119 | //
|
---|
120 | static Bool_t pindiode = kTRUE;
|
---|
121 | //
|
---|
122 | // Tell if you want to calibrate times:
|
---|
123 | //
|
---|
124 | static Bool_t useTimes = kTRUE;
|
---|
125 | //
|
---|
126 | // Tell if you want to use a combined extractor:
|
---|
127 | //
|
---|
128 | static Bool_t useTimeAndCharge = kTRUE;
|
---|
129 | //
|
---|
130 | // Tell if you want to use the display:
|
---|
131 | //
|
---|
132 | static Bool_t useDisplay = kTRUE;
|
---|
133 | //
|
---|
134 | // Tell if you want to test the result afterwards
|
---|
135 | //
|
---|
136 | static Bool_t useTest = kFALSE;
|
---|
137 | //
|
---|
138 | // Tell if you want to test the intensity calibration
|
---|
139 | //
|
---|
140 | static Bool_t useIntensity = kFALSE;
|
---|
141 | //
|
---|
142 | // Tell if you want to use MPedCalcFromLogain for the pedestal calculation
|
---|
143 | //
|
---|
144 | static Bool_t usedata = kFALSE;
|
---|
145 | //
|
---|
146 | // Tell if you want to store and read the F0 and F1- files
|
---|
147 | //
|
---|
148 | static Bool_t usestorage = kFALSE;
|
---|
149 | //
|
---|
150 | Int_t calibration(const Int_t prun=pedrun,
|
---|
151 | const Int_t crun1=calrun1, const Int_t crun2=calrun2)
|
---|
152 | {
|
---|
153 |
|
---|
154 | if (debug)
|
---|
155 | TObject::SetObjectStat(kTRUE);
|
---|
156 |
|
---|
157 | //
|
---|
158 | // Choose the signal Extractor:
|
---|
159 | //
|
---|
160 | // PURE CHARGE EXTRACTORS:
|
---|
161 | // MExtractFixedWindowPeakSearch extractor;
|
---|
162 | // MExtractSlidingWindow extractor;
|
---|
163 | // MExtractFixedWindow extractor;
|
---|
164 | // MExtractFixedWindowSpline extractor;
|
---|
165 | // MExtractAmplitudeSpline extractor;
|
---|
166 | //
|
---|
167 | // PURE TIME EXTRACTORS:
|
---|
168 | // ATTENTION: If an extractor deriving from MExtractTimeAndCharge is
|
---|
169 | // used, you may want to use the timing calculated directly
|
---|
170 | // from there. Use the flag: "useTimeAndCharge" in this case
|
---|
171 | //
|
---|
172 | // MExtractTimeHighestIntegral timeext;
|
---|
173 | MExtractTimeFastSpline timeext;
|
---|
174 | // MExtractTimeSpline timeext;
|
---|
175 | //
|
---|
176 | // COMBINED TIME AND CHARGE EXTRACTORS:
|
---|
177 | // (You have to set the variable "useTimeAndCharge" in order to use the
|
---|
178 | // time calculated by this extractor!)
|
---|
179 | MExtractTimeAndChargeDigitalFilter extractor;
|
---|
180 | // MExtractTimeAndChargeSpline extractor;
|
---|
181 | // MExtractTimeAndChargeSlidingWindow extractor;
|
---|
182 | //
|
---|
183 | // Set Ranges or Windows
|
---|
184 | //
|
---|
185 | // extractor.SetRange(1,14,4,12);
|
---|
186 | // extractor.SetWindowSize(6,6);
|
---|
187 | // timeext.SetRange(1,14,4,12);
|
---|
188 | // timeext.SetWindowSize(6,6);
|
---|
189 | //
|
---|
190 | // Set additional information for some extractors
|
---|
191 | //
|
---|
192 | // Digital Filter:
|
---|
193 | extractor.ReadWeightsFile(weightfile.Data());
|
---|
194 | // extractor.ReadWeightsFile("");
|
---|
195 | // TimeAndChargeSpline:
|
---|
196 | // extractor.SetChargeType(MExtractTimeAndChargeSpline::kIntegral);
|
---|
197 | // extractor.SetTimeType(MExtractTimeAndChargeSpline::kHalfMaximum);
|
---|
198 |
|
---|
199 | MRunIter pruns;
|
---|
200 | MRunIter cruns;
|
---|
201 |
|
---|
202 | pruns.AddRun(prun,inpath);
|
---|
203 |
|
---|
204 | if (crun2==0)
|
---|
205 | cruns.AddRun(crun1,inpath);
|
---|
206 | else
|
---|
207 | cruns.AddRuns(crun1,crun2,inpath);
|
---|
208 |
|
---|
209 | gStyle->SetOptStat(1111);
|
---|
210 | gStyle->SetOptFit();
|
---|
211 | gStyle->SetTitleSize(0.1,"u");
|
---|
212 | gStyle->SetLineWidth(1);
|
---|
213 |
|
---|
214 | MStatusDisplay *display = NULL;
|
---|
215 |
|
---|
216 | if (useDisplay)
|
---|
217 | {
|
---|
218 | display = new MStatusDisplay;
|
---|
219 | display->SetUpdateTime(3000);
|
---|
220 | display->Resize(850,700);
|
---|
221 | }
|
---|
222 |
|
---|
223 | /************************************/
|
---|
224 | /* FIRST LOOP: PEDESTAL COMPUTATION */
|
---|
225 | /************************************/
|
---|
226 |
|
---|
227 | //
|
---|
228 | // Hand over to the jobs a QE Cam with Cornings initialized
|
---|
229 | //
|
---|
230 | MCalibrationQECamMagic qecam;
|
---|
231 | MBadPixelsCam badcam;
|
---|
232 | //
|
---|
233 | // If you want to exclude pixels from the beginning, read
|
---|
234 | // an ascii-file with the corr. pixel numbers (see MBadPixelsCam)
|
---|
235 | //
|
---|
236 | if (!badfile.IsNull())
|
---|
237 | {
|
---|
238 | ifstream f(badfile.Data());
|
---|
239 | badcam.AsciiRead((istream&)f);
|
---|
240 | f.close();
|
---|
241 | }
|
---|
242 |
|
---|
243 | MJPedestal pedloop;
|
---|
244 | if (usedata)
|
---|
245 | pedloop.SetUseData();
|
---|
246 | pedloop.SetNoStorage(!usestorage);
|
---|
247 | pedloop.SetEnvDebug(debug);
|
---|
248 | pedloop.SetExtractor(&extractor);
|
---|
249 | pedloop.SetInput(&pruns);
|
---|
250 | pedloop.SetPathOut(outpath.Data());
|
---|
251 | if (useDisplay)
|
---|
252 | {
|
---|
253 | pedloop.SetDisplay(display);
|
---|
254 | pedloop.SetDataCheckDisplay();
|
---|
255 | }
|
---|
256 | pedloop.SetBadPixels(badcam);
|
---|
257 |
|
---|
258 | if (!pedloop.Process())
|
---|
259 | return 1;
|
---|
260 |
|
---|
261 | /****************************************/
|
---|
262 | /* SECOND LOOP: CALIBRATION COMPUTATION */
|
---|
263 | /****************************************/
|
---|
264 |
|
---|
265 | MJCalibration calloop;
|
---|
266 |
|
---|
267 | if (debug)
|
---|
268 | calloop.SetDebug();
|
---|
269 | calloop.SetEnvDebug(debug);
|
---|
270 | if (useIntensity)
|
---|
271 | calloop.SetIntensity();
|
---|
272 | // calloop.SetHistsStorage();
|
---|
273 | calloop.SetNoStorage(!usestorage);
|
---|
274 | //
|
---|
275 | // If you want to set a colour explicitely from outside (not recommanded!)
|
---|
276 | // calloop.SetColor(MCalibrationCam::kUV);
|
---|
277 | //
|
---|
278 | // If you want to run the data-check on RAW DATA!!!, choose:
|
---|
279 | // calloop.SetDataCheck();
|
---|
280 | //
|
---|
281 | // If you want to see the data-check plots only, choose:
|
---|
282 | calloop.SetDataCheckDisplay();
|
---|
283 | //calloop.SetNormalDisplay();
|
---|
284 | //
|
---|
285 | // For everything, you have ever dreamed of, choose:
|
---|
286 | // calloop.SetFullDisplay();
|
---|
287 |
|
---|
288 | //
|
---|
289 | // If you want to calibrate the times as well, choose:
|
---|
290 | //
|
---|
291 | calloop.SetRelTimeCalibration(useTimes);
|
---|
292 | calloop.SetExtractor(&extractor);
|
---|
293 | calloop.SetTimeAndCharge(useTimeAndCharge);
|
---|
294 | calloop.SetTimeExtractor(&timeext);
|
---|
295 | calloop.SetInput(&cruns);
|
---|
296 | calloop.SetPathOut(outpath.Data());
|
---|
297 | if (useDisplay)
|
---|
298 | calloop.SetDisplay(display);
|
---|
299 | calloop.SetUseBlindPixel(blindpix);
|
---|
300 | calloop.SetUsePINDiode(pindiode);
|
---|
301 | calloop.SetQECam(qecam);
|
---|
302 | calloop.SetBadPixels(pedloop.GetBadPixels());
|
---|
303 |
|
---|
304 | if (!calloop.Process(pedloop.GetPedestalCam()))
|
---|
305 | return 2;
|
---|
306 |
|
---|
307 | //
|
---|
308 | // The next lines are the use the Print() function and have
|
---|
309 | // all the results as ascii-tables:
|
---|
310 | //
|
---|
311 | if (debug)
|
---|
312 | {
|
---|
313 | MCalibrationChargeCam &chargecam = calloop.GetCalibrationCam();
|
---|
314 | MCalibrationQECam &nqecam = calloop.GetQECam();
|
---|
315 | MBadPixelsCam &badbad = calloop.GetBadPixels();
|
---|
316 | chargecam.Print();
|
---|
317 | nqecam.Print();
|
---|
318 | badbad.Print();
|
---|
319 | }
|
---|
320 |
|
---|
321 | /********************************************************************/
|
---|
322 | /* THIRD LOOP: APPLY CALIBRATION TO THE CALIBRATION FILES FOR TESTS */
|
---|
323 | /********************************************************************/
|
---|
324 |
|
---|
325 | if (useTest)
|
---|
326 | {
|
---|
327 |
|
---|
328 | MJExtractCalibTest testloop;
|
---|
329 |
|
---|
330 | // If you want to see the data-check plots only, choose:
|
---|
331 | testloop.SetDataCheckDisplay();
|
---|
332 |
|
---|
333 | testloop.SetExtractor(&extractor);
|
---|
334 | testloop.SetTimeExtractor(&timeext);
|
---|
335 | testloop.SetInput(&cruns);
|
---|
336 | testloop.SetPathOut(outpath);
|
---|
337 | if (useDisplay)
|
---|
338 | testloop.SetDisplay(display);
|
---|
339 | testloop.SetBadPixels(calloop.GetBadPixels());
|
---|
340 |
|
---|
341 | if (!testloop.ProcessD(pedloop.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
|
---|
342 | return 3;
|
---|
343 |
|
---|
344 | if (useTimes)
|
---|
345 | if (!testloop.ProcessT(pedloop.GetPedestalCam(),calloop.GetRelTimeCam()))
|
---|
346 | return 4;
|
---|
347 |
|
---|
348 | }
|
---|
349 |
|
---|
350 | /********************************************************************/
|
---|
351 | /* FOURTH LOOP: APPLY CALIBRATION TO THE PEDESTAL FILES */
|
---|
352 | /********************************************************************/
|
---|
353 |
|
---|
354 | MJExtractSignal pedphotloop;
|
---|
355 |
|
---|
356 | pedphotloop.SetExtractor(&extractor);
|
---|
357 | pedphotloop.SetTimeExtractor(&timeext);
|
---|
358 | pedphotloop.SetInput(&pruns);
|
---|
359 | pedphotloop.SetOutputPath(outpath);
|
---|
360 | if (useDisplay)
|
---|
361 | pedphotloop.SetDisplay(display);
|
---|
362 | pedphotloop.SetBadPixels(calloop.GetBadPixels());
|
---|
363 |
|
---|
364 | if (!pedphotloop.ProcessP(pedloop.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
|
---|
365 | return 5;
|
---|
366 |
|
---|
367 | if (debug)
|
---|
368 | TObject::SetObjectStat(kFALSE);
|
---|
369 |
|
---|
370 | //
|
---|
371 | // Debugging at the end:
|
---|
372 | //
|
---|
373 | if (debug)
|
---|
374 | gObjectTable->Print();
|
---|
375 |
|
---|
376 | return 0;
|
---|
377 |
|
---|
378 | }
|
---|
379 |
|
---|
380 | static void Usage()
|
---|
381 | {
|
---|
382 | gLog << endl;
|
---|
383 | gLog << "Usage:" << endl;
|
---|
384 | gLog << endl;
|
---|
385 | gLog << " calibration [ped.run nr.] [first cal.run nr.] [last cal.run nr.]" << endl ;
|
---|
386 | gLog << endl;
|
---|
387 | gLog << " ped.run.nr: Run number of the pedestal file." << endl;
|
---|
388 | gLog << " first cal.run nr.: Run number of the first calibration file." << endl;
|
---|
389 | gLog << " last cal.run nr.: Run number of the last calibration file." << endl;
|
---|
390 | gLog << endl;
|
---|
391 | gLog << "All calibration runs between (first cal.run nr.) and (last cal.run nr.) will be used" << endl;
|
---|
392 | gLog << "If last.cal.run.nr is 0 (default), only one calibration run is taken" << endl;
|
---|
393 | gLog << endl;
|
---|
394 | gLog << "Additional Options: " << endl;
|
---|
395 | gLog << " --inpath=# Find the data in inpath" << endl;
|
---|
396 | gLog << " --outpath=# Write the output containers to outpath" << endl;
|
---|
397 | gLog << " --badfile=# Use the file # to exclude pixels from the beginning" << endl;
|
---|
398 | gLog << " --debug Use the TObjectTable for debugging " << endl;
|
---|
399 | gLog << " and write out the pixels as ascii tables" << endl;
|
---|
400 | gLog << " --useTimes Calibrate the relative arrival times" << endl;
|
---|
401 | gLog << " --useTest Use the class MJExtractCalibTest to test the calibration on itself" << endl;
|
---|
402 | gLog << " --skipBlindPix Skip the blind pixel calibration" << endl;
|
---|
403 | gLog << " --skipPINDiode Skip the PIN Diode calibration" << endl;
|
---|
404 | }
|
---|
405 |
|
---|
406 |
|
---|
407 | int main(int argc, char **argv)
|
---|
408 | {
|
---|
409 | //
|
---|
410 | // Evaluate arguments
|
---|
411 | //
|
---|
412 | MArgs arg(argc, argv);
|
---|
413 |
|
---|
414 | if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
|
---|
415 | {
|
---|
416 | Usage();
|
---|
417 | return -1;
|
---|
418 | }
|
---|
419 |
|
---|
420 | debug = arg.HasOnlyAndRemove("--debug") || arg.HasOnlyAndRemove("-d");
|
---|
421 | useTimes = arg.HasOnlyAndRemove("--useTimes") || arg.HasOnlyAndRemove("-t");
|
---|
422 | useTest = arg.HasOnlyAndRemove("--useTest") || arg.HasOnlyAndRemove("-e");
|
---|
423 | blindpix = !(arg.HasOnlyAndRemove("--skipBlindPix"));
|
---|
424 | pindiode = !(arg.HasOnlyAndRemove("--skipPINDiode"));
|
---|
425 |
|
---|
426 | if (arg.HasOption("--inpath="))
|
---|
427 | inpath = arg.GetStringAndRemove("--inpath=");
|
---|
428 |
|
---|
429 | if (arg.HasOption("--outpath="))
|
---|
430 | outpath = arg.GetStringAndRemove("--outpath=");
|
---|
431 |
|
---|
432 | if (arg.HasOption("--badfile="))
|
---|
433 | badfile = arg.GetStringAndRemove("--badfile=");
|
---|
434 |
|
---|
435 | if (gSystem->AccessPathName(badfile,kFileExists))
|
---|
436 | {
|
---|
437 | gLog << "WARNING: the bad pixels file '" << badfile.Data() << "' doesn't exist." << endl;
|
---|
438 | badfile = "";
|
---|
439 | }
|
---|
440 |
|
---|
441 | // check for the right usage of the program
|
---|
442 | //
|
---|
443 | if (arg.GetNumArguments()>4)
|
---|
444 | {
|
---|
445 | Usage();
|
---|
446 | return -1;
|
---|
447 | }
|
---|
448 |
|
---|
449 | //
|
---|
450 | // Initialize Non-GUI (batch) mode
|
---|
451 | //
|
---|
452 | gROOT->SetBatch();
|
---|
453 |
|
---|
454 | //
|
---|
455 | // Switch off the display
|
---|
456 | //
|
---|
457 | useDisplay = kFALSE;
|
---|
458 |
|
---|
459 |
|
---|
460 | //
|
---|
461 | // check for the arguments
|
---|
462 | //
|
---|
463 | Int_t pedr = 0;
|
---|
464 | Int_t calr1 = 0;
|
---|
465 | Int_t calr2 = 0;
|
---|
466 |
|
---|
467 | const Int_t nargs = arg.GetNumArguments();
|
---|
468 |
|
---|
469 | if (nargs>=3)
|
---|
470 | {
|
---|
471 | pedr = arg.GetArgumentInt(0);
|
---|
472 | calr1 = arg.GetArgumentInt(1);
|
---|
473 | calr2 = arg.GetArgumentInt(2);
|
---|
474 | return calibration(pedr,calr1,calr2);
|
---|
475 | }
|
---|
476 |
|
---|
477 | if (nargs>=2)
|
---|
478 | {
|
---|
479 | pedr = arg.GetArgumentInt(0);
|
---|
480 | calr1 = arg.GetArgumentInt(1);
|
---|
481 | return calibration(pedr,calr1);
|
---|
482 | }
|
---|
483 |
|
---|
484 | if (nargs>=1)
|
---|
485 | {
|
---|
486 | pedr = arg.GetArgumentInt(0);
|
---|
487 | gLog << "PEDR: " << pedr << endl;
|
---|
488 | return calibration(pedr);
|
---|
489 | }
|
---|
490 |
|
---|
491 | return calibration();
|
---|
492 | }
|
---|