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

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