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

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