source: trunk/MagicSoft/Mars/macros/calibration.C@ 5737

Last change on this file since 5737 was 5737, checked in by gaug, 20 years ago
*** empty log message ***
File size: 19.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): 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 "getExtractor.C"
58
59#include "MJPedestal.h"
60#include "MJCalibration.h"
61#include "MJExtractCalibTest.h"
62#include "MJCalibrateSignalFromOutside.h"
63#include "MRunIter.h"
64#include "MStatusDisplay.h"
65#include "MCalibrationQECamMagic.h"
66#include "MCalibrationQECam.h"
67#include "MBadPixelsCam.h"
68#include "MArgs.h"
69#include "MArray.h"
70#include "MParContainer.h"
71#include "MGeomCamMagic.h"
72
73#include "TStyle.h"
74#include "TObject.h"
75#include "TObjectTable.h"
76#include "TCanvas.h"
77#include "TPad.h"
78#include "TH1.h"
79#include "TPaveStats.h"
80
81using namespace std;
82
83static TString outpath = "./";
84static TString inpath = "/home/rootdata/Calib/2004_09_22";
85static TString badfile;
86//static TString badfile = "badpixels_only0_388_559.dat";
87//
88// the default pedestal run for the calibration
89//
90static const Int_t pedrun = 38995;
91//
92// the default start calibration run
93//
94static const Int_t calrun1 = 38997;
95//
96// the default last calibration run (if 0, only one run is taken, otherwise consecutive runs
97// between calrun1 and calrun2)
98//
99static const Int_t calrun2 = 0;
100//
101// the default start data run
102//
103static const Int_t datrun1 = 39900;
104//
105// the default last calibration run (if 0, only one run is taken, otherwise consecutive runs
106// between calrun1 and calrun2)
107//
108static const Int_t datrun2 = 0;
109//
110// A switch to output debugging information about Objects use
111//
112static Bool_t debug = kFALSE;
113//
114// A switch to use the Blind Pixel
115//
116static Bool_t blindpix = kTRUE;
117//
118// A switch to use the PIN Diode
119//
120static Bool_t pindiode = kTRUE;
121//
122// Tell if you want to use the display:
123//
124static Bool_t useDisplay = kTRUE;
125//
126// Tell if you want to test the result afterwards
127//
128static Bool_t useTest = kFALSE;
129//
130// Tell if you want to test the intensity calibration
131//
132static Bool_t useIntensity = kFALSE;
133//
134// Tell if you want to store and read the F0 and F1- files
135//
136static Bool_t useStorage = kTRUE;
137//
138// Tell which extractor you want to use. The flags are counted according
139// to the extractor-TDAS
140//
141static Int_t extractorflag = 33;
142//
143Int_t calibration(const UInt_t extflag=extractorflag, const Int_t prun=pedrun,
144 const Int_t crun1=calrun1, const Int_t crun2=calrun2,
145 const Int_t drun1=datrun1, const Int_t drun2=datrun2)
146{
147
148 MExtractor *extractor = getExtractor(extflag==33 ? 32 : extflag);
149
150 if (!extractor)
151 return 99;
152
153 extractor->SetName(Form("%s_Run_%05d",extractor->GetName(),prun));
154 const Bool_t timeandcharge = extractor->InheritsFrom("MExtractTimeAndCharge");
155
156 gStyle->SetOptStat(1111);
157 gStyle->SetOptFit();
158 gStyle->SetTitleSize(0.35,"u");
159 gStyle->SetTitleFontSize(0.9);
160 gStyle->SetTitleH(0.12);
161 gStyle->SetTitleW(0.95);
162 gStyle->SetLineWidth(1);
163
164 if (debug)
165 TObject::SetObjectStat(kTRUE);
166
167 MRunIter pruns;
168 MRunIter cruns;
169
170 pruns.AddRun(prun,inpath);
171
172 if (crun1!=0)
173 if (crun2==0)
174 cruns.AddRun(crun1,inpath);
175 else
176 cruns.AddRuns(crun1,crun2,inpath);
177
178 MStatusDisplay *display = NULL;
179
180 if (useDisplay)
181 {
182 display = new MStatusDisplay;
183 display->SetUpdateTime(3000);
184 display->Resize(850,700);
185 }
186
187 /*****************************************/
188 /* FIRST LOOP: PURE PEDESTAL COMPUTATION */
189 /*****************************************/
190 //
191 // Hand over to the jobs a QE Cam with Cornings initialized
192 //
193 MGeomCamMagic geomcam;
194 MCalibrationQECamMagic qecam;
195 MBadPixelsCam badcam;
196 badcam.InitSize(geomcam.GetNumPixels());
197 //
198 // If you want to exclude pixels from the beginning, read
199 // an ascii-file with the corr. pixel numbers (see MBadPixelsCam)
200 //
201 if (!badfile.IsNull())
202 {
203 ifstream f(badfile.Data());
204 badcam.AsciiRead((istream&)f);
205 f.close();
206 }
207
208 MJPedestal pedloop1;
209 pedloop1.SetNoStorage(!useStorage);
210 pedloop1.SetEnvDebug(debug);
211 pedloop1.SetExtractor(extractor);
212 pedloop1.SetInput(&pruns);
213 pedloop1.SetPathOut(outpath.Data());
214 if (useDisplay)
215 {
216 pedloop1.SetDisplay(display);
217 pedloop1.SetDataCheckDisplay();
218 }
219 pedloop1.SetBadPixels(badcam);
220
221 if (!pedloop1.Process())
222 return 1;
223
224 /****************************************/
225 /* SECOND LOOP: CALIBRATION COMPUTATION */
226 /****************************************/
227
228 MJPedestal pedloop2;
229 MJCalibration calloop;
230
231 if (timeandcharge)
232 {
233 /***********************************************************/
234 /* NEEDED FOR SECOND LOOP: EXTRACTOR RESOLUTION COMPUTATION */
235 /***********************************************************/
236
237 pedloop2.SetUseData();
238 pedloop2.SetNoStorage(!useStorage);
239 pedloop2.SetEnvDebug(debug);
240 pedloop2.SetExtractor(extractor);
241 pedloop2.SetExtractorResolution();
242 pedloop2.SetPedestals(pedloop1.GetPedestalCam());
243 pedloop2.SetInput(&pruns);
244 pedloop2.SetPathOut(outpath.Data());
245 if (useDisplay)
246 {
247 pedloop2.SetDisplay(display);
248 pedloop2.SetDataCheckDisplay();
249 }
250 pedloop2.SetBadPixels(badcam);
251
252 if (!pedloop2.Process())
253 return 1;
254
255 calloop.SetExtractorCam(pedloop2.GetPedestalCam());
256 }
257
258 if (crun1 == 0)
259 return 0;
260
261 MPedestalCam &pedcam = pedloop1.GetPedestalCam();
262
263 if (debug)
264 calloop.SetDebug();
265 calloop.SetEnvDebug(debug);
266 if (useIntensity)
267 calloop.SetIntensity();
268 // calloop.SetHistsStorage();
269 calloop.SetNoStorage(!useStorage);
270 calloop.SetRelTimeCalibration(kTRUE);
271 //
272 // If you want to set a colour explicitely from outside (not recommanded!)
273 // calloop.SetColor(MCalibrationCam::kUV);
274 //
275 // If you want to run the data-check on RAW DATA!!!, choose:
276 // calloop.SetDataCheck();
277 //
278 // If you want to see the data-check plots only, choose:
279 calloop.SetDataCheckDisplay();
280 //calloop.SetNormalDisplay();
281 //
282 // For everything, you have ever dreamed of, choose:
283 // calloop.SetFullDisplay();
284
285 //
286 // If you want to calibrate the times as well, choose:
287 //
288 calloop.SetExtractor(extractor);
289 calloop.SetInput(&cruns);
290 calloop.SetPathOut(outpath.Data());
291 if (useDisplay)
292 calloop.SetDisplay(display);
293 calloop.SetUseBlindPixel(blindpix);
294 calloop.SetUsePINDiode(pindiode);
295 calloop.SetQECam(qecam);
296 calloop.SetBadPixels(badcam);
297
298 if (!calloop.Process(pedcam))
299 return 2;
300
301 // return 0;
302 //
303 // The next lines are the use the Print() function and have
304 // all the results as ascii-tables:
305 //
306 if (debug)
307 {
308 MCalibrationQECam &nqecam = calloop.GetQECam();
309 MBadPixelsCam &badbad = calloop.GetBadPixels();
310 MCalibrationChargeCam &chargecam = calloop.GetCalibrationCam();
311 chargecam.Print();
312 nqecam.Print();
313 badbad.Print();
314 }
315
316 /********************************************************************/
317 /* THIRD LOOP: APPLY CALIBRATION TO THE CALIBRATION FILES FOR TESTS */
318 /********************************************************************/
319
320 if (useTest)
321 {
322
323 MJExtractCalibTest testloop;
324
325 // If you want to see the data-check plots only, choose:
326 testloop.SetDataCheckDisplay();
327
328 testloop.SetExtractor(extractor);
329 testloop.SetInput(&cruns);
330 testloop.SetPathOut(outpath);
331 if (useDisplay)
332 testloop.SetDisplay(display);
333 testloop.SetBadPixels(calloop.GetBadPixels());
334
335 if (!testloop.ProcessD(pedloop1.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
336 return 3;
337
338 }
339
340 if (drun1 == 0)
341 return 4;
342
343 MRunIter druns;
344
345 if (drun2==0)
346 druns.AddRun(drun1,inpath);
347 else
348 druns.AddRuns(drun1,drun2,inpath);
349
350
351 /********************************************************************/
352 /* FOURTH LOOP: APPLY CALIBRATION TO THE PEDESTAL FILES */
353 /********************************************************************/
354
355 if (extflag == 33)
356 {
357 delete extractor;
358 extractor = getExtractor(28);
359 }
360
361 MJCalibrateSignalFromOutside calibloop;
362
363 calibloop.SetExtractor(extractor);
364 calibloop.SetInput(&druns);
365 // calibloop.SetOutputPath(outpath);
366 if (useDisplay)
367 calibloop.SetDisplay(display);
368 calibloop.SetBadPixels(calloop.GetBadPixels());
369 calibloop.SetNoStorage(!usestorage);
370
371 if (!calibloop.ProcessFile(pedloop1.GetPedestalCam(),timeandcharge ? pedloop2.GetPedestalCam() : pedloop1.GetPedestalCam(), calloop.GetCalibrationCam(),calloop.GetQECam(), calloop.GetRelTimeCam()))
372 return 5;
373
374 if (debug)
375 TObject::SetObjectStat(kFALSE);
376
377 //
378 // Debugging at the end:
379 //
380 if (debug)
381 gObjectTable->Print();
382
383
384 return 0;
385}
386
387static void Usage()
388{
389 gLog << endl;
390 gLog << "Usage:" << endl;
391 gLog << endl;
392 gLog << " calibration [ped.run nr.] [first cal.run nr.] [last cal.run nr.] [first dat.run nr.] [last dat.run nr.]" << endl ;
393 gLog << endl;
394 gLog << " ped.run.nr: Run number of the pedestal file." << endl;
395 gLog << " first cal.run nr.: Run number of the first calibration file." << endl;
396 gLog << " last cal.run nr.: Run number of the last calibration file." << endl;
397 gLog << " first dat.run nr.: Run number of the first data file to be calibrated." << endl;
398 gLog << " last dat.run nr.: Run number of the last data file to be calibrated." << endl;
399 gLog << endl;
400 gLog << "All calibration runs between (first cal.run nr.) and (last cal.run nr.) will be used" << endl;
401 gLog << "If last.cal.run.nr is 0 (default), only one calibration run is taken" << endl;
402 gLog << endl;
403 gLog << "All data runs between (first dat.run nr.) and (last dat.run nr.) will be used" << endl;
404 gLog << "If last.dat.run.nr is 0 (default), only one data run is taken" << endl;
405 gLog << endl;
406 gLog << "Additional Options: " << endl;
407 gLog << " --extractor=# Choose one of the following possible extractors (integer)" << endl;
408 gLog << " (default: Nr. 33) " << endl;
409 gLog << endl;
410 gLog << " Nr. Extractor Parameters " << endl;
411 gLog << endl;
412 gLog << " MExtractFixedWindow: " << endl;
413 gLog << " with the following parameters: " << endl;
414 gLog << " 1: SetRange(4,7,6,9) " << endl;
415 gLog << " 2: SetRange(4,7,5,10)" << endl;
416 gLog << " 3: SetRange(3,8,5,10)" << endl;
417 gLog << " 4: SetRange(2,9,4,11)" << endl;
418 gLog << " 5: SetRange(0,13,4,13)" << endl;
419 gLog << " MExtractFixedWindowSpline: " << endl;
420 gLog << " 6: SetRange(3,7,5,9)" << endl;
421 gLog << " 7: SetRange(3,7,5,11)" << endl;
422 gLog << " 8: SetRange(3,9,5,11)" << endl;
423 gLog << " 9: SetRange(2,10,4,12)" << endl;
424 gLog << " 10: SetRange(0,14,4,14)" << endl;
425 gLog << " MExtractFixedWindowPeakSearch: " << endl;
426 gLog << " SetRange(0,18,2,14) and the following parameters:" << endl;
427 gLog << " 11: SetWindows(2,2,2)" << endl;
428 gLog << " SetOffsetFromWindow(0)" << endl;
429 gLog << " 12: SetWindows(4,4,2)" << endl;
430 gLog << " SetOffsetFromWindow(1)" << endl;
431 gLog << " 13: SetWindows(4,6,4)" << endl;
432 gLog << " SetOffsetFromWindow(0)" << endl;
433 gLog << " 14: SetWindows(6,6,4)" << endl;
434 gLog << " SetOffsetFromWindow(1)" << endl;
435 gLog << " 15: SetWindows(8,8,4)" << endl;
436 gLog << " SetOffsetFromWindow(1)" << endl;
437 gLog << " 16: SetWindows(14,10,4)" << endl;
438 gLog << " SetOffsetFromWindow(2)" << endl;
439 gLog << " MExtractTimeAndChargeSlidingWindow:" << endl;
440 gLog << " SetRange(0,18,2,14) and the following parameters:" << endl;
441 gLog << " 17: SetWindowSize(2,2)" << endl;
442 gLog << " 18: SetWindowSize(4,4)" << endl;
443 gLog << " 19: SetWindowSize(4,6)" << endl;
444 gLog << " 20: SetWindowSize(6,6)" << endl;
445 gLog << " 21: SetWindowSize(8,8)" << endl;
446 gLog << " 22: SetWindowSize(14,10)" << endl;
447 gLog << " MExtractTimeAndChargeSpline: " << endl;
448 gLog << " 23: SetChargeType(MExtractTimeAndChargeSpline::kAmplitude) and:" << endl;
449 gLog << " SetRange(0,13,2,13) " << endl;
450 gLog << " 24: SetChargeType(MExtractTimeAndChargeSpline::kIntegral) and:" << endl;
451 gLog << " SetRiseTime(0.5); SetFallTime(0.5)" << endl;
452 gLog << " 25: SetRiseTime(0.5); SetFallTime(1.5)" << endl;
453 gLog << " 26: SetRiseTime(1.0); SetFallTime(3.0)" << endl;
454 gLog << " 27 SetRiseTime(1.5); SetFallTime(4.5)" << endl;
455 gLog << " MExtractTimeAndChargeDigitalFilter" << endl;
456 gLog << " SetRange(0,18,2,14) and the following parameters:" << endl;
457 gLog << " 28: SetNameWeightsFile('msignal/cosmics_weights.dat')" << endl;
458 gLog << " 29: SetNameWeightsFile('msignal/cosmics_weights4.dat')" << endl;
459 gLog << " 30: SetNameWeightsFile('msignal/cosmics_weights_logain6.dat')" << endl;
460 gLog << " 31: SetNameWeightsFile('msignal/cosmics_weights_logain4.dat')" << endl;
461 gLog << " 32: SetNameWeightsFile('msignal/calibration_weights_UV.dat')" << endl;
462 gLog << " 33: Use calibration weights for calibration events and cosmics weights for data events" << endl;
463 gLog << endl;
464 gLog << " --inpath=# Find the data in inpath" << endl;
465 gLog << " --outpath=# Write the output containers to outpath" << endl;
466 gLog << " --badfile=# Use the file # to exclude pixels from the beginning" << endl;
467 gLog << " --debug Use the TObjectTable for debugging " << endl;
468 gLog << " and write out the pixels as ascii tables" << endl;
469 gLog << " --useTest Use the class MJExtractCalibTest to test the calibration on itself" << endl;
470 gLog << " --skipBlindPix Skip the blind pixel calibration" << endl;
471 gLog << " --skipPINDiode Skip the PIN Diode calibration" << endl;
472}
473
474
475int main(int argc, char **argv)
476{
477 //
478 // Evaluate arguments
479 //
480 MArgs arg(argc, argv);
481
482 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
483 {
484 Usage();
485 return -1;
486 }
487
488 debug = arg.HasOnlyAndRemove("--debug") || arg.HasOnlyAndRemove("-d");
489 useTest = arg.HasOnlyAndRemove("--useTest") || arg.HasOnlyAndRemove("-e");
490 blindpix = !(arg.HasOnlyAndRemove("--skipBlindPix"));
491 pindiode = !(arg.HasOnlyAndRemove("--skipPINDiode"));
492
493 if (arg.HasOption("--extractor="))
494 extractorflag = arg.GetIntAndRemove("--extractor=");
495
496 if (arg.HasOption("--inpath="))
497 inpath = arg.GetStringAndRemove("--inpath=");
498
499 if (arg.HasOption("--outpath="))
500 outpath = arg.GetStringAndRemove("--outpath=");
501
502 if (arg.HasOption("--badfile="))
503 badfile = arg.GetStringAndRemove("--badfile=");
504
505 if (gSystem->AccessPathName(badfile,kFileExists))
506 {
507 gLog << "WARNING: the bad pixels file '" << badfile.Data() << "' doesn't exist." << endl;
508 badfile = "";
509 }
510
511 // check for the right usage of the program
512 //
513 if (arg.GetNumArguments()>6)
514 {
515 Usage();
516 return -1;
517 }
518
519 //
520 // Initialize Non-GUI (batch) mode
521 //
522 gROOT->SetBatch();
523
524 //
525 // Switch off the display
526 //
527 useDisplay = kTRUE;
528 //
529 // check for the arguments
530 //
531 Int_t pedr = 0;
532 Int_t calr1 = 0;
533 Int_t calr2 = 0;
534 Int_t datr1 = 0;
535 Int_t datr2 = 0;
536
537 const Int_t nargs = arg.GetNumArguments();
538
539 if (nargs>=5)
540 {
541 pedr = arg.GetArgumentInt(0);
542 calr1 = arg.GetArgumentInt(1);
543 calr2 = arg.GetArgumentInt(2);
544 datr1 = arg.GetArgumentInt(3);
545 datr2 = arg.GetArgumentInt(4);
546 return calibration(extractorflag,pedr,calr1,calr2,datr1,datr2);
547 }
548
549 if (nargs>=4)
550 {
551 pedr = arg.GetArgumentInt(0);
552 calr1 = arg.GetArgumentInt(1);
553 calr2 = arg.GetArgumentInt(2);
554 datr1 = arg.GetArgumentInt(3);
555 datr2 = arg.GetArgumentInt(4);
556 return calibration(extractorflag,pedr,calr1,calr2,datr1,0);
557 }
558
559 if (nargs>=3)
560 {
561 pedr = arg.GetArgumentInt(0);
562 calr1 = arg.GetArgumentInt(1);
563 calr2 = arg.GetArgumentInt(2);
564 return calibration(extractorflag,pedr,calr1,calr2,0);
565 }
566
567 if (nargs>=2)
568 {
569 pedr = arg.GetArgumentInt(0);
570 calr1 = arg.GetArgumentInt(1);
571 gLog << "PEDR: " << pedr << " CALR1: " << calr1 << " CALR2 " << calr2 << endl;
572 gLog << "inpath: " << inpath << endl;
573 gLog << "extractor: " << extractorflag << endl;
574 return calibration(extractorflag,pedr,calr1,0,0);
575 }
576
577 if (nargs>=1)
578 {
579 pedr = arg.GetArgumentInt(0);
580 return calibration(extractorflag,pedr,0);
581 }
582
583 return calibration(extractorflag,pedr,calr1,calr2);
584}
585
Note: See TracBrowser for help on using the repository browser.