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

Last change on this file since 4775 was 4743, checked in by gaug, 20 years ago
*** empty log message ***
File size: 13.1 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 "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 "MRunIter.h"
69#include "MStatusDisplay.h"
70#include "MCalibrationQECam.h"
71#include "MHCalibrationTestCam.h"
72#include "MHCalibrationTestPix.h"
73#include "MBadPixelsCam.h"
74#include "MArgs.h"
75#include "MArray.h"
76#include "MLog.h"
77#include "MParContainer.h"
78
79#include "TStyle.h"
80#include "TObject.h"
81#include "TObjectTable.h"
82#include "TSystem.h"
83
84#include <fstream>
85
86using namespace std;
87
88static TString outpath = "./";
89static TString inpath = "/home/rootdata/Calib/2004_07_06/";
90static TString badfile = "";
91//
92// the default pedestal run for the calibration
93//
94static const Int_t pedrun = 31741;
95//
96// the default start calibration run
97//
98static const Int_t calrun1 = 31742;
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// A switch to output debugging information about Objects use
106//
107static Bool_t debug = kFALSE;
108//
109// A switch to use the Blind Pixel
110//
111static Bool_t blindpix = kTRUE;
112// A switch to use the PIN Diode
113//
114static Bool_t pindiode = kFALSE;
115//
116// Tell if you want to calibrate times:
117//
118static Bool_t useTimes = kFALSE;
119//
120// Tell if you want to use the display:
121//
122static Bool_t useDisplay = kTRUE;
123//
124// Tell if you want to test the result afterwards
125//
126static Bool_t useTest = kTRUE;
127//
128Int_t calibration(const Int_t prun=pedrun,
129 const Int_t crun1=calrun1, const Int_t crun2=calrun2)
130{
131
132 if (debug)
133 TObject::SetObjectStat(kTRUE);
134
135 //
136 // Choose the signal Extractor:
137 //
138 // MExtractFixedWindowPeakSearch extractor;
139 // MExtractSlidingWindow extractor;
140 // MExtractFixedWindowSpline extractor;
141 MExtractFixedWindow extractor;
142 // MExtractAmplitudeSpline extractor;
143 // MExtractTimeAndChargeSpline extractor;
144 //
145 // Set Ranges or Windows
146 //
147 extractor.SetRange(3,14,4,13);
148 // extractor.SetWindows(8,8);
149
150 //
151 // Choose the arrival time Extractor:
152 //
153 // MExtractTimeHighestIntegral timeext;
154 MExtractTimeFastSpline timeext;
155 //
156 // Set Ranges or Windows
157 //
158 timeext.SetRange(0,7,3,8);
159
160 MRunIter pruns;
161 MRunIter cruns;
162
163 pruns.AddRun(prun,inpath);
164
165 if (crun2==0)
166 cruns.AddRun(crun1,inpath);
167 else
168 cruns.AddRuns(crun1,crun2,inpath);
169
170 gStyle->SetOptStat(1111);
171 gStyle->SetOptFit();
172 gStyle->SetTitleSize(0.1,"u");
173 gStyle->SetLineWidth(1);
174
175 MStatusDisplay *display = NULL;
176
177 if (useDisplay)
178 {
179 display = new MStatusDisplay;
180 display->SetUpdateTime(3000);
181 display->Resize(850,700);
182 }
183
184 /************************************/
185 /* FIRST LOOP: PEDESTAL COMPUTATION */
186 /************************************/
187
188 MCalibrationQECam qecam;
189 MBadPixelsCam badcam;
190 //
191 // If you want to exclude pixels from the beginning, read
192 // an ascii-file with the corr. pixel numbers (see MBadPixelsCam)
193 //
194 if (!badfile.IsNull())
195 {
196 ifstream f(badfile.Data());
197 badcam.AsciiRead(f);
198 f.close();
199 }
200
201 MJPedestal pedloop;
202 pedloop.SetExtractor(&extractor);
203 pedloop.SetInput(&pruns);
204 pedloop.SetPathOut(outpath.Data());
205 if (useDisplay)
206 {
207 pedloop.SetDisplay(display);
208 pedloop.SetDataCheckDisplay();
209 }
210 pedloop.SetBadPixels(badcam);
211
212 if (!pedloop.Process())
213 return 1;
214
215 /****************************************/
216 /* SECOND LOOP: CALIBRATION COMPUTATION */
217 /****************************************/
218
219 MJCalibration calloop;
220
221 if (debug)
222 calloop.SetDebug();
223 //
224 // If you want to run the data-check on RAW DATA!!!, choose:
225 // calloop.SetDataCheck();
226 //
227 // If you want to see the data-check plots only, choose:
228 calloop.SetDataCheckDisplay();
229 //
230 // For everything, you have ever dreamed of, choose:
231 // calloop.SetFullDisplay();
232
233 //
234 // If you want to calibrate the times as well, choose:
235 //
236 calloop.SetRelTimeCalibration(useTimes);
237 calloop.SetExtractor(&extractor);
238 calloop.SetTimeExtractor(&timeext);
239 calloop.SetInput(&cruns);
240 calloop.SetPathOut(outpath.Data());
241 if (useDisplay)
242 calloop.SetDisplay(display);
243 calloop.SetUseBlindPixel(blindpix);
244 calloop.SetUsePINDiode(pindiode);
245 calloop.SetQECam(qecam);
246 calloop.SetBadPixels(pedloop.GetBadPixels());
247
248 if (!calloop.Process(pedloop.GetPedestalCam()))
249 return 2;
250
251 //
252 // The next lines are the use the Print() function and have
253 // all the results as ascii-tables:
254 //
255 if (debug)
256 {
257 MCalibrationChargeCam &chargecam = calloop.GetCalibrationCam();
258 MCalibrationQECam &nqecam = calloop.GetQECam();
259 MBadPixelsCam &badbad = calloop.GetBadPixels();
260 chargecam.Print();
261 nqecam.Print();
262 badbad.Print();
263 }
264
265 gLog << endl;
266 gLog << "Mean number of photons from pulser Inner pixels (F-Factor Method): "
267 << calloop.GetCalibrationCam().GetNumPhotonsFFactorMethod()
268 << " +- " << calloop.GetCalibrationCam().GetNumPhotonsFFactorMethodErr() << endl;
269 gLog << endl;
270
271 /********************************************************************/
272 /* THIRD LOOP: APPLY CALIBRATION TO THE CALIBRATION FILES FOR TESTS */
273 /********************************************************************/
274
275 if (useTest)
276 {
277
278 MJExtractCalibTest testloop;
279
280 // If you want to see the data-check plots only, choose:
281 testloop.SetDataCheckDisplay();
282
283 testloop.SetExtractor(&extractor);
284 testloop.SetTimeExtractor(&timeext);
285 testloop.SetInput(&cruns);
286 testloop.SetPathOut(outpath);
287 if (useDisplay)
288 testloop.SetDisplay(display);
289 testloop.SetBadPixels(calloop.GetBadPixels());
290
291 if (!testloop.ProcessD(pedloop.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
292 return 3;
293
294 if (useTimes)
295 if (!testloop.ProcessT(pedloop.GetPedestalCam(),calloop.GetRelTimeCam()))
296 return 4;
297
298 }
299
300 /********************************************************************/
301 /* FOURTH LOOP: APPLY CALIBRATION TO THE PEDESTAL FILES */
302 /********************************************************************/
303
304 MJExtractSignal pedphotloop;
305
306 pedphotloop.SetExtractor(&extractor);
307 pedphotloop.SetTimeExtractor(&timeext);
308 pedphotloop.SetInput(&pruns);
309 pedphotloop.SetOutputPath(outpath);
310 if (useDisplay)
311 pedphotloop.SetDisplay(display);
312 pedphotloop.SetBadPixels(calloop.GetBadPixels());
313
314 if (!pedphotloop.ProcessP(pedloop.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
315 return 5;
316
317
318 if (debug)
319 TObject::SetObjectStat(kFALSE);
320
321 //
322 // Debugging at the end:
323 //
324 if (debug)
325 gObjectTable->Print();
326
327 //
328 // List of useful containers:
329 //
330/*
331 MPedestalCam &pedcam = pedloop.GetPedestalCam();
332 MCalibrationChargeCam &chargecam = calloop.GetCalibrationCam();
333 MCalibrationQECam &qecam = calloop.GetCalibrationCam();
334 MBadPixelsCam &badcam = calloop.GetBadPixels();
335 MCalibrationTestCam &testcam = testloop.GetTestCam();
336 MHCalibrationTestTimeCam &testtime = testloop.GetTestTimeCam();
337*/
338
339 return 0;
340
341}
342
343static void Usage()
344{
345 gLog << endl;
346 gLog << "Usage:" << endl;
347 gLog << endl;
348 gLog << " calibration [ped.run nr.] [first cal.run nr.] [last cal.run nr.]" << endl ;
349 gLog << endl;
350 gLog << " ped.run.nr: Run number of the pedestal file." << endl;
351 gLog << " first cal.run nr.: Run number of the first calibration file." << endl;
352 gLog << " last cal.run nr.: Run number of the last calibration file." << endl;
353 gLog << endl;
354 gLog << "All calibration runs between (first cal.run nr.) and (last cal.run nr.) will be used" << endl;
355 gLog << "If last.cal.run.nr is 0 (default), only one calibration run is taken" << endl;
356 gLog << endl;
357 gLog << "Additional Options: " << endl;
358 gLog << " --inpath=# Find the data in inpath" << endl;
359 gLog << " --outpath=# Write the output containers to outpath" << endl;
360 gLog << " --badfile=# Use the file # to exclude pixels from the beginning" << endl;
361 gLog << " --debug Use the TObjectTable for debugging " << endl;
362 gLog << " and write out the pixels as ascii tables" << endl;
363 gLog << " --useTimes Calibrate the relative arrival times" << endl;
364 gLog << " --useTest Use the class MJExtractCalibTest to test the calibration on itself" << endl;
365 gLog << " --skipBlindPix Skip the blind pixel calibration" << endl;
366 gLog << " --skipPINDiode Skip the PIN Diode calibration" << endl;
367}
368
369
370int main(int argc, char **argv)
371{
372 //
373 // Evaluate arguments
374 //
375 MArgs arg(argc, argv);
376
377 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
378 {
379 Usage();
380 return -1;
381 }
382
383 debug = arg.HasOnlyAndRemove("--debug") || arg.HasOnlyAndRemove("-d");
384 useTimes = arg.HasOnlyAndRemove("--useTimes") || arg.HasOnlyAndRemove("-t");
385 useTest = arg.HasOnlyAndRemove("--useTest") || arg.HasOnlyAndRemove("-e");
386 blindpix = !(arg.HasOnlyAndRemove("--skipBlindPix"));
387 pindiode = !(arg.HasOnlyAndRemove("--skipPINDiode"));
388
389 if (arg.HasOption("--inpath="))
390 inpath = arg.GetStringAndRemove("--inpath=");
391
392 if (arg.HasOption("--outpath="))
393 outpath = arg.GetStringAndRemove("--outpath=");
394
395 if (arg.HasOption("--badfile="))
396 badfile = arg.GetStringAndRemove("--badfile=");
397
398 if (gSystem->AccessPathName(badfile,kFileExists))
399 {
400 gLog << "WARNING: the bad pixels file '" << badfile.Data() << "' doesn't exist." << endl;
401 badfile = "";
402 }
403
404 // check for the right usage of the program
405 //
406 if (arg.GetNumArguments()>4)
407 {
408 Usage();
409 return -1;
410 }
411
412 //
413 // Initialize Non-GUI (batch) mode
414 //
415 gROOT->SetBatch();
416
417 //
418 // Switch off the display
419 //
420 useDisplay = kFALSE;
421
422
423 //
424 // check for the arguments
425 //
426 Int_t pedr = 0;
427 Int_t calr1 = 0;
428 Int_t calr2 = 0;
429
430 const Int_t nargs = arg.GetNumArguments();
431
432 if (nargs>=3)
433 {
434 pedr = arg.GetArgumentInt(0);
435 calr1 = arg.GetArgumentInt(1);
436 calr2 = arg.GetArgumentInt(2);
437 return calibration(pedr,calr1,calr2);
438 }
439
440 if (nargs>=2)
441 {
442 pedr = arg.GetArgumentInt(0);
443 calr1 = arg.GetArgumentInt(1);
444 return calibration(pedr,calr1);
445 }
446
447 if (nargs>=1)
448 {
449 pedr = arg.GetArgumentInt(0);
450 gLog << "PEDR: " << pedr << endl;
451 return calibration(pedr);
452 }
453
454 return calibration();
455}
Note: See TracBrowser for help on using the repository browser.