source: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc@ 4179

Last change on this file since 4179 was 4179, checked in by reyes, 21 years ago
*** empty log message ***
File size: 38.5 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): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Markus Gaug, 02/2004 <mailto:markus@ifae.es>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJCalibration
28//
29// Do one calibration loop over serious of runs with the same pulser
30// colour and the same intensity. The following containers (rectangular) and
31// tasks (ellipses) are called to produce an MCalibrationChargeCam and to
32// update the MCalibrationQECam: (MCalibrate is not called from this class)
33//
34//Begin_Html
35/*
36<img src="images/CalibClasses.gif">
37*/
38//End_Html
39//
40// Different signal extractors can be set with the command SetExtractor()
41// Only extractors deriving from MExtractor can be set, default is MExtractSlidingWindow
42//
43// Different arrival time extractors can be set with the command SetTimeExtractor()
44// Only extractors deriving from MExtractTime can be set, default is MExtractTimeSpline
45//
46// At the end of the eventloop, plots and results are displayed, depending on
47// the flags set (see DisplayResult())
48//
49// If the flag SetFullDisplay() is set, all MHCameras will be displayed.
50// if the flag SetDataCheckDisplay() is set, only the most important ones are displayed
51// Otherwise, (default: SetNormalDisplay()), a good selection of plots is given
52//
53// If the flag SetDataCheck() is set, the calibration is used as in the data check at
54// La Palma, which mean especially running on raw data files.
55//
56// The absolute light calibration devices Blind Pixel and PIN Diode can be switched on
57// and off with the commands:
58//
59// - SetUseBlindPixel(Bool_t )
60// - SetUsePINDiode(Bool_t )
61//
62// See also: MHCalibrationChargePix, MHCalibrationChargeCam, MHGausEvents
63// MHCalibrationChargeBlindPix, MHCalibrationChargePINDiode
64// MCalibrationChargePix, MCalibrationChargeCam, MCalibrationChargeCalc
65// MCalibrationChargeBlindPix, MCalibrationChargePINDiode,
66// MCalibrationQECam, MBadPixelsPix, MBadPixelsCam
67//
68// If the flag RelTimeCalibration() is set, a calibration of the relative arrival
69// times is also performed. The following containers (rectangular) and
70// tasks (ellipses) are called to produce an MCalibrationRelTimeCam used by
71// MCalibrateTime to correct timing offset between pixels: (MCalibrateTime is not
72// called from this class)
73//
74//Begin_Html
75/*
76<img src="images/RelTimeClasses.gif">
77*/
78//End_Html
79//
80// Different arrival time extractors can be set directly with the command SetTimeExtractor(MExtractor *)
81//
82// See also: MHCalibrationRelTimePix, MHCalibrationRelTimeCam, MHGausEvents
83// MCalibrationRelTimePix, MCalibrationRelTimeCam
84// MBadPixelsPix, MBadPixelsCam
85//
86/////////////////////////////////////////////////////////////////////////////
87#include "MJCalibration.h"
88
89#include <TFile.h>
90#include <TStyle.h>
91#include <TCanvas.h>
92#include <TSystem.h>
93
94#include "MLog.h"
95#include "MLogManip.h"
96
97#include "MRunIter.h"
98#include "MParList.h"
99#include "MTaskList.h"
100#include "MEvtLoop.h"
101
102#include "MHCamera.h"
103#include "MGeomCam.h"
104
105#include "MPedestalCam.h"
106#include "MCalibrationCam.h"
107#include "MCalibrationQECam.h"
108#include "MCalibrationChargeCam.h"
109#include "MCalibrationChargePINDiode.h"
110#include "MCalibrationChargeBlindPix.h"
111#include "MCalibrationChargeCalc.h"
112
113#include "MHGausEvents.h"
114#include "MHCalibrationCam.h"
115#include "MHCalibrationChargeCam.h"
116#include "MHCalibrationChargeBlindPix.h"
117#include "MHCalibrationRelTimeCam.h"
118#include "MCalibrationRelTimeCam.h"
119#include "MCalibrationRelTimeCalc.h"
120
121#include "MReadMarsFile.h"
122#include "MRawFileRead.h"
123#include "MGeomApply.h"
124#include "MBadPixelsMerge.h"
125#include "MBadPixelsCam.h"
126#include "MExtractTime.h"
127#include "MExtractor.h"
128#include "MExtractPINDiode.h"
129#include "MExtractBlindPixel.h"
130#include "MExtractSlidingWindow.h"
131#include "MExtractTimeSpline.h"
132#include "MFCosmics.h"
133#include "MContinue.h"
134#include "MFillH.h"
135
136#include "MArrivalTimeCam.h"
137
138#include "MStatusDisplay.h"
139
140ClassImp(MJCalibration);
141
142using namespace std;
143
144const Int_t MJCalibration::gkIFAEBoxInaugurationRun = 20113;
145// --------------------------------------------------------------------------
146//
147// Default constructor.
148//
149// - Sets fRuns to 0, fExtractor to NULL, fTimeExtractor to NULL, fColor to kNONE,
150// fDisplay to kNormalDisplay, fRelTime to kFALSE, fDataCheck to kFALSE,
151// - SetUseBlindPixel()
152// - SetUsePINDiode()
153//
154MJCalibration::MJCalibration(const char *name, const char *title)
155 : fRuns(0), fExtractor(NULL), fTimeExtractor(NULL),
156 fColor(MCalibrationCam::kNONE), fDisplayType(kNormalDisplay),
157 fRelTimes(kFALSE), fDataCheck(kFALSE)
158{
159
160 fName = name ? name : "MJCalibration";
161 fTitle = title ? title : "Tool to create the calibration constants for one calibration run";
162
163 SetUseBlindPixel();
164 SetUsePINDiode();
165
166}
167
168
169// --------------------------------------------------------------------------
170//
171// Display the results in MStatusDisplay:
172//
173// - Add "Calibration" to the MStatusDisplay title
174// - Retrieve the MGeomCam from MParList
175// - Initialize the following MHCamera's:
176// 1) MCalibrationPix::GetMean()
177// 2) MCalibrationPix::Sigma()
178// 3) MCalibrationChargePix::GetRSigma()
179// 4) MCalibrationChargePix::GetRSigmaPerCharge()
180// 5) MCalibrationChargePix::GetPheFFactorMethod()
181// 6) MCalibrationChargePix::GetMeanConvFADC2Phe()
182// 7) MCalibrationChargePix::GetMeanFFactorFADC2Phot()
183// 8) MCalibrationQEPix::GetQECascadesFFactor()
184// 9) MCalibrationQEPix::GetQECascadesBlindPixel()
185// 10) MCalibrationQEPix::GetQECascadesPINDiode()
186// 11) MCalibrationQEPix::GetQECascadesCombined()
187// 12) MCalibrationQEPix::IsAverageQEFFactorAvailable()
188// 13) MCalibrationQEPix::IsAverageQEBlindPixelAvailable()
189// 14) MCalibrationQEPix::IsAverageQEPINDiodeAvailable()
190// 15) MCalibrationQEPix::IsAverageQECombinedAvailable()
191// 16) MCalibrationChargePix::IsHiGainSaturation()
192// 17) MCalibrationPix::GetHiLoMeansDivided()
193// 18) MCalibrationPix::GetHiLoSigmasDivided()
194// 19) MCalibrationChargePix::GetHiGainPickup()
195// 20) MCalibrationChargePix::GetLoGainPickup()
196// 21) MCalibrationChargePix::GetHiGainBlackout()
197// 22) MCalibrationChargePix::GetLoGainBlackout()
198// 23) MCalibrationPix::IsExcluded()
199// 24) MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableRun)
200// 25) MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnreliableRun)
201// 26) MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
202// 27) MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
203// 28) MCalibrationChargePix::GetAbsTimeMean()
204// 29) MCalibrationChargePix::GetAbsTimeRms()
205//
206// If the flag SetFullDisplay() is set, all MHCameras will be displayed.
207// if the flag SetDataCheckDisplay() is set, only the most important ones are displayed
208// and otherwise, (default: SetNormalDisplay()), a good selection of plots is given
209//
210void MJCalibration::DisplayResult(MParList &plist)
211{
212 if (!fDisplay)
213 return;
214
215 //
216 // Update display
217 //
218 TString title = fDisplay->GetTitle();
219 title += "-- Calibration ";
220 title += fRuns->GetRunsAsString();
221 title += " --";
222 fDisplay->SetTitle(title);
223
224 //
225 // Get container from list
226 //
227 MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
228
229 // Create histograms to display
230 MHCamera disp1 (geomcam, Form("%s%s","Charge",(fRuns->GetRunsAsFileName()).Data()),
231 "Fitted Mean Charges");
232 MHCamera disp2 (geomcam, Form("%s%s","SigmaCharge",(fRuns->GetRunsAsFileName()).Data()),
233 "Sigma of Fitted Charges");
234 MHCamera disp3 (geomcam, Form("%s%s","RSigma",(fRuns->GetRunsAsFileName()).Data()),
235 "Reduced Sigmas");
236 MHCamera disp4 (geomcam, Form("%s%s","RSigmaPerCharge",(fRuns->GetRunsAsFileName()).Data()),
237 "Reduced Sigma per Charge");
238 MHCamera disp5 (geomcam, Form("%s%s","NumPhes",(fRuns->GetRunsAsFileName()).Data()),
239 "Nr. of Phe's (F-Factor Method)");
240 MHCamera disp6 (geomcam, Form("%s%s","ConvFADC2Phes",(fRuns->GetRunsAsFileName()).Data()),
241 "Conversion Factor (F-Factor Method)");
242 MHCamera disp7 (geomcam, Form("%s%s","TotalFFactor",(fRuns->GetRunsAsFileName()).Data()),
243 "Total F-Factor (F-Factor Method)");
244 MHCamera disp8 (geomcam, Form("%s%s","CascadesQEFFactor",(fRuns->GetRunsAsFileName()).Data()),
245 "Cascades QE (F-Factor Method)");
246 MHCamera disp9 (geomcam, Form("%s%s","CascadesQEBlindPix",(fRuns->GetRunsAsFileName()).Data()),
247 "Cascades QE (Blind Pixel Method)");
248 MHCamera disp10(geomcam, Form("%s%s","CascadesQEPINDiode",(fRuns->GetRunsAsFileName()).Data()),
249 "Cascades QE (PIN Diode Method)");
250 MHCamera disp11(geomcam, Form("%s%s","CascadesQECombined",(fRuns->GetRunsAsFileName()).Data()),
251 "Cascades QE (Combined Method)");
252 MHCamera disp12(geomcam, Form("%s%s","FFactorValid",(fRuns->GetRunsAsFileName()).Data()),
253 "Pixels with valid F-Factor calibration");
254 MHCamera disp13(geomcam, Form("%s%s","BlindPixelValid",(fRuns->GetRunsAsFileName()).Data()),
255 "Pixels with valid BlindPixel calibration");
256 MHCamera disp14(geomcam, Form("%s%s","PINdiodeValid",(fRuns->GetRunsAsFileName()).Data()),
257 "Pixels with valid PINDiode calibration");
258 MHCamera disp15(geomcam, Form("%s%s","CombinedValid",(fRuns->GetRunsAsFileName()).Data()),
259 "Pixels with valid Combined calibration");
260 MHCamera disp16(geomcam, Form("%s%s","Saturation",(fRuns->GetRunsAsFileName()).Data()),
261 "Pixels with saturated Hi Gain");
262 MHCamera disp17(geomcam, Form("%s%s","ConversionMeans",(fRuns->GetRunsAsFileName()).Data()),
263 "Conversion HiGain.vs.LoGain Means");
264 MHCamera disp18(geomcam, Form("%s%s","ConversionSigmas",(fRuns->GetRunsAsFileName()).Data()),
265 "Conversion HiGain.vs.LoGain Sigmas");
266 MHCamera disp19(geomcam, Form("%s%s","HiGainPickup",(fRuns->GetRunsAsFileName()).Data()),
267 "Number Pickup events Hi Gain");
268 MHCamera disp20(geomcam, Form("%s%s","LoGainPickup",(fRuns->GetRunsAsFileName()).Data()),
269 "Number Pickup events Lo Gain");
270 MHCamera disp21(geomcam, Form("%s%s","HiGainBlackout",(fRuns->GetRunsAsFileName()).Data()),
271 "Number Blackout events Hi Gain");
272 MHCamera disp22(geomcam, Form("%s%s","LoGainBlackout",(fRuns->GetRunsAsFileName()).Data()),
273 "Number Blackout events Lo Gain");
274 MHCamera disp23(geomcam, Form("%s%s","Excluded",(fRuns->GetRunsAsFileName()).Data()),
275 "Pixels previously excluded");
276 MHCamera disp24(geomcam, Form("%s%s","UnSuitable",(fRuns->GetRunsAsFileName()).Data()),
277 "Pixels not suited for further analysis");
278 MHCamera disp25(geomcam, Form("%s%s","UnReliable",(fRuns->GetRunsAsFileName()).Data()),
279 "Pixels not reliable for further analysis");
280 MHCamera disp26(geomcam, Form("%s%s","HiGainOscillating",(fRuns->GetRunsAsFileName()).Data()),
281 "Oscillating Pixels High Gain");
282 MHCamera disp27(geomcam, Form("%s%s","LoGainOscillating",(fRuns->GetRunsAsFileName()).Data()),
283 "Oscillating Pixels Low Gain");
284 MHCamera disp28(geomcam, Form("%s%s","AbsTimeMean",(fRuns->GetRunsAsFileName()).Data()),
285 "Abs. Arrival Times");
286 MHCamera disp29(geomcam, Form("%s%s","AbsTimeRms",(fRuns->GetRunsAsFileName()).Data()),
287 "RMS of Arrival Times");
288 MHCamera disp30(geomcam, Form("%s%s","MeanTime",(fRuns->GetRunsAsFileName()).Data()),
289 "Mean Rel. Arrival Times");
290 MHCamera disp31(geomcam, Form("%s%s","SigmaTime",(fRuns->GetRunsAsFileName()).Data()),
291 "Sigma Rel. Arrival Times");
292 MHCamera disp32(geomcam, Form("%s%s","TimeProb",(fRuns->GetRunsAsFileName()).Data()),
293 "Probability of Time Fit");
294 MHCamera disp33(geomcam, Form("%s%s","TimeNotFitValid",(fRuns->GetRunsAsFileName()).Data()),
295 "Pixels with not valid fit results");
296 MHCamera disp34(geomcam, Form("%s%s","TimeOscillating",(fRuns->GetRunsAsFileName()).Data()),
297 "Oscillating Pixels");
298
299 // Fitted charge means and sigmas
300 disp1.SetCamContent(fCalibrationCam, 0);
301 disp1.SetCamError( fCalibrationCam, 1);
302 disp2.SetCamContent(fCalibrationCam, 2);
303 disp2.SetCamError( fCalibrationCam, 3);
304
305 // Reduced Sigmas and reduced sigmas per charge
306 disp3.SetCamContent(fCalibrationCam, 5);
307 disp3.SetCamError( fCalibrationCam, 6);
308 disp4.SetCamContent(fCalibrationCam, 7);
309 disp4.SetCamError( fCalibrationCam, 8);
310
311 // F-Factor Method
312 disp5.SetCamContent(fCalibrationCam, 9);
313 disp5.SetCamError( fCalibrationCam, 10);
314 disp6.SetCamContent(fCalibrationCam, 11);
315 disp6.SetCamError( fCalibrationCam, 12);
316 disp7.SetCamContent(fCalibrationCam, 13);
317 disp7.SetCamError( fCalibrationCam, 14);
318
319 // Quantum Efficiencies
320 disp8.SetCamContent (fQECam, 0 );
321 disp8.SetCamError (fQECam, 1 );
322 disp9.SetCamContent (fQECam, 2 );
323 disp9.SetCamError (fQECam, 3 );
324 disp10.SetCamContent(fQECam, 4 );
325 disp10.SetCamError (fQECam, 5 );
326 disp11.SetCamContent(fQECam, 6 );
327 disp11.SetCamError (fQECam, 7 );
328
329 // Valid flags
330 disp12.SetCamContent(fQECam, 8 );
331 disp13.SetCamContent(fQECam, 9 );
332 disp14.SetCamContent(fQECam, 10);
333 disp15.SetCamContent(fQECam, 11);
334
335 // Conversion Hi-Lo
336 disp16.SetCamContent(fCalibrationCam, 25);
337 disp17.SetCamContent(fCalibrationCam, 16);
338 disp17.SetCamError (fCalibrationCam, 17);
339 disp18.SetCamContent(fCalibrationCam, 18);
340 disp18.SetCamError (fCalibrationCam, 19);
341
342 // Pickup and Blackout
343 disp19.SetCamContent(fCalibrationCam, 21);
344 disp20.SetCamContent(fCalibrationCam, 22);
345 disp21.SetCamContent(fCalibrationCam, 23);
346 disp22.SetCamContent(fCalibrationCam, 24);
347
348 // Pixels with defects
349 disp23.SetCamContent(fCalibrationCam, 20);
350 disp24.SetCamContent(fBadPixels, 1);
351 disp25.SetCamContent(fBadPixels, 3);
352
353 // Oscillations
354 disp26.SetCamContent(fBadPixels, 10);
355 disp27.SetCamContent(fBadPixels, 11);
356
357 // Arrival Times
358 disp28.SetCamContent(fCalibrationCam, 26);
359 disp28.SetCamError( fCalibrationCam, 27);
360 disp29.SetCamContent(fCalibrationCam, 27);
361
362 disp1.SetYTitle("Q [FADC counts]");
363 disp2.SetYTitle("\\sigma_{Q} [FADC counts]");
364
365 disp3.SetYTitle("\\sqrt{\\sigma^{2}_{Q} - RMS^{2}_{Ped}} [FADC Counts]");
366 disp4.SetYTitle("Red.Sigma/<Q> [1]");
367
368 disp5.SetYTitle("Nr. Phe's [1]");
369 disp6.SetYTitle("Conv.Factor [PhE/FADC counts]");
370 disp7.SetYTitle("Total F-Factor [1]");
371
372 disp8.SetYTitle("QE [1]");
373 disp9.SetYTitle("QE [1]");
374 disp10.SetYTitle("QE [1]");
375 disp11.SetYTitle("QE [1]");
376
377 disp12.SetYTitle("[1]");
378 disp13.SetYTitle("[1]");
379 disp14.SetYTitle("[1]");
380 disp15.SetYTitle("[1]");
381 disp16.SetYTitle("[1]");
382
383 disp17.SetYTitle("<Q>(High)/<Q>(Low) [1]");
384 disp18.SetYTitle("\\sigma_{Q}(High)/\\sigma_{Q}(Low) [1]");
385
386 disp19.SetYTitle("[1]");
387 disp20.SetYTitle("[1]");
388 disp21.SetYTitle("[1]");
389 disp22.SetYTitle("[1]");
390 disp23.SetYTitle("[1]");
391 disp24.SetYTitle("[1]");
392 disp25.SetYTitle("[1]");
393 disp26.SetYTitle("[1]");
394 disp27.SetYTitle("[1]");
395
396 disp28.SetYTitle("Mean Abs. Time [FADC slice]");
397 disp29.SetYTitle("RMS Abs. Time [FADC slices]");
398
399 if (fRelTimes)
400 {
401
402 disp30.SetCamContent(fRelTimeCam,0);
403 disp30.SetCamError( fRelTimeCam,1);
404 disp31.SetCamContent(fRelTimeCam,2);
405 disp31.SetCamError( fRelTimeCam,3);
406 disp32.SetCamContent(fRelTimeCam,4);
407 disp33.SetCamContent(fBadPixels,20);
408 disp34.SetCamContent(fBadPixels,21);
409
410 disp30.SetYTitle("Time Offset [FADC units]");
411 disp31.SetYTitle("Timing resolution [FADC units]");
412 disp32.SetYTitle("P_{Time} [1]");
413 disp33.SetYTitle("[1]");
414 disp34.SetYTitle("[1]");
415 }
416
417 if (fDisplayType == kDataCheckDisplay)
418 {
419 TCanvas &c1 = fDisplay->AddTab("Fit.Charge");
420 c1.Divide(3, 3);
421
422 CamDraw(c1, 1, 3, disp1, 2);
423 CamDraw(c1, 2, 3, disp4, 2);
424 CamDraw(c1, 3, 3, disp28, 2);
425
426 // F-Factor
427 TCanvas &c2 = fDisplay->AddTab("Phe's");
428 c2.Divide(3,4);
429
430 CamDraw(c2, 1, 3, disp6, 2, 1);
431 CamDraw(c2, 2, 3, disp7, 2, 1);
432 CamDraw(c2, 3, 3, disp8, 2, 1);
433
434 // QE's
435 TCanvas &c3 = fDisplay->AddTab("QE's");
436 c3.Divide(3,4);
437
438 CamDraw(c3, 1, 3, disp8, 2, 1);
439 CamDraw(c3, 2, 3, disp9, 2, 1);
440 CamDraw(c3, 3, 3, disp10, 2, 1);
441
442 // Defects
443 TCanvas &c4 = fDisplay->AddTab("Defect");
444 // c4.Divide(3,2);
445 c4.Divide(2,2);
446
447 // CamDraw(c4, 1, 3, disp23, 0);
448 // CamDraw(c4, 2, 3, disp24, 0);
449 // CamDraw(c4, 3, 3, disp25, 0);
450 CamDraw(c4, 1, 2, disp24, 0);
451 CamDraw(c4, 2, 2, disp25, 0);
452
453 if (fRelTimes)
454 {
455 // Rel. Times
456 TCanvas &c5 = fDisplay->AddTab("Rel. Times");
457 c5.Divide(2,4);
458
459 CamDraw(c5, 1, 2, disp30, 2);
460 CamDraw(c5, 2, 2, disp31, 2);
461 }
462
463
464 return;
465 }
466
467 if (fDisplayType == kNormalDisplay)
468 {
469
470 // Charges
471 TCanvas &c11 = fDisplay->AddTab("Fit.Charge");
472 c11.Divide(2, 4);
473
474 CamDraw(c11, 1, 2, disp1, 5, 1);
475 CamDraw(c11, 2, 2, disp2, 5, 1);
476
477 // Reduced Sigmas
478 TCanvas &c12 = fDisplay->AddTab("Red.Sigma");
479 c12.Divide(2,4);
480
481 CamDraw(c12, 1, 2, disp3, 5, 1);
482 CamDraw(c12, 2, 2, disp4, 5, 1);
483
484 // F-Factor
485 TCanvas &c13 = fDisplay->AddTab("Phe's");
486 c13.Divide(3,4);
487
488 CamDraw(c13, 1, 3, disp5, 5, 1);
489 CamDraw(c13, 2, 3, disp6, 5, 1);
490 CamDraw(c13, 3, 3, disp7, 5, 1);
491
492 // QE's
493 TCanvas &c14 = fDisplay->AddTab("QE's");
494 c14.Divide(4,4);
495
496 CamDraw(c14, 1, 4, disp8, 5, 1);
497 CamDraw(c14, 2, 4, disp9, 5, 1);
498 CamDraw(c14, 3, 4, disp10, 5, 1);
499 CamDraw(c14, 4, 4, disp11, 5, 1);
500
501 // Defects
502 TCanvas &c15 = fDisplay->AddTab("Defect");
503 // c15.Divide(5,2);
504 c15.Divide(4,2);
505
506 /*
507 CamDraw(c15, 1, 5, disp23, 0);
508 CamDraw(c15, 2, 5, disp24, 0);
509 CamDraw(c15, 3, 5, disp25, 0);
510 CamDraw(c15, 4, 5, disp26, 0);
511 CamDraw(c15, 5, 5, disp27, 0);
512 */
513 CamDraw(c15, 1, 4, disp24, 0);
514 CamDraw(c15, 2, 4, disp25, 0);
515 CamDraw(c15, 3, 4, disp26, 0);
516 CamDraw(c15, 4, 4, disp27, 0);
517
518 // Abs. Times
519 TCanvas &c16 = fDisplay->AddTab("Abs. Times");
520 c16.Divide(2,3);
521
522 CamDraw(c16, 1, 2, disp28, 5);
523 CamDraw(c16, 2, 2, disp29, 5);
524
525 if (fRelTimes)
526 {
527 // Rel. Times
528 TCanvas &c17 = fDisplay->AddTab("Rel. Times");
529 c17.Divide(2,4);
530
531 CamDraw(c17, 1, 2, disp30, 5, 1);
532 CamDraw(c17, 2, 2, disp31, 5, 1);
533 }
534
535 return;
536 }
537
538 if (fDisplayType == kFullDisplay)
539 {
540
541 MHCalibrationChargeBlindPix *blind = (MHCalibrationChargeBlindPix*)plist.FindObject("MHCalibrationChargeBlindPix");
542 blind->DrawClone();
543 gPad->GetCanvas()->SaveAs(Form("%s%s%s",blind->GetName(),(fRuns->GetRunsAsString()).Data(),".root"));
544
545 MHCalibrationChargeCam *ccm = (MHCalibrationChargeCam*)plist.FindObject("MHCalibrationChargeCam");
546 ccm->DrawClone();
547 gPad->GetCanvas()->SaveAs(Form("%s%s%s",ccm->GetName(),(fRuns->GetRunsAsString()).Data(),".root"));
548
549 MHCalibrationRelTimeCam *rel = (MHCalibrationRelTimeCam*)plist.FindObject("MHCalibrationRelTimeCam");
550 rel->DrawClone();
551 gPad->GetCanvas()->SaveAs(Form("%s%s%s",rel->GetName(),(fRuns->GetRunsAsString()).Data(),".root"));
552
553 MHCalibrationCam *cam = (MHCalibrationCam*)plist.FindObject("MHCalibrationChargeCam");
554
555 for (Int_t aidx=0;aidx<cam->GetAverageAreas();aidx++)
556 {
557 cam->GetAverageHiGainArea(aidx).DrawClone("all");
558 cam->GetAverageLoGainArea(aidx).DrawClone("all");
559 }
560
561 for (Int_t sector=1;sector<cam->GetAverageSectors();sector++)
562 {
563 cam->GetAverageHiGainSector(sector).DrawClone("all");
564 cam->GetAverageLoGainSector(sector).DrawClone("all");
565 }
566
567 // Charges
568 TCanvas &c21 = fDisplay->AddTab("Fit.Charge");
569 c21.Divide(2, 4);
570
571 CamDraw(c21, 1, 2, disp1, 2, 1);
572 CamDraw(c21, 2, 2, disp2, 2, 1);
573
574 // Reduced Sigmas
575 TCanvas &c23 = fDisplay->AddTab("Red.Sigma");
576 c23.Divide(2,4);
577
578 CamDraw(c23, 1, 2, disp3, 2, 1);
579 CamDraw(c23, 2, 2, disp4, 2, 1);
580
581 // F-Factor
582 TCanvas &c24 = fDisplay->AddTab("Phe's");
583 c24.Divide(3,4);
584
585 CamDraw(c24, 1, 3, disp5, 2, 1);
586 CamDraw(c24, 2, 3, disp6, 2, 1);
587 CamDraw(c24, 3, 3, disp7, 2, 1);
588
589 // QE's
590 TCanvas &c25 = fDisplay->AddTab("QE's");
591 c25.Divide(4,4);
592
593 CamDraw(c25, 1, 4, disp8, 2, 1);
594 CamDraw(c25, 2, 4, disp9, 2, 1);
595 CamDraw(c25, 3, 4, disp10, 2, 1);
596 CamDraw(c25, 4, 4, disp11, 2, 1);
597
598 // Validity
599 TCanvas &c26 = fDisplay->AddTab("Valid");
600 c26.Divide(4,2);
601
602 CamDraw(c26, 1, 4, disp12, 0);
603 CamDraw(c26, 2, 4, disp13, 0);
604 CamDraw(c26, 3, 4, disp14, 0);
605 CamDraw(c26, 4, 4, disp15, 0);
606
607 // Other info
608 TCanvas &c27 = fDisplay->AddTab("HiLoGain");
609 c27.Divide(3,3);
610
611 CamDraw(c27, 1, 3, disp16, 0);
612 CamDraw(c27, 2, 3, disp17, 1);
613 CamDraw(c27, 3, 3, disp18, 1);
614
615 // Pickup
616 TCanvas &c28 = fDisplay->AddTab("Pickup");
617 c28.Divide(4,2);
618
619 CamDraw(c28, 1, 4, disp19, 0);
620 CamDraw(c28, 2, 4, disp20, 0);
621 CamDraw(c28, 3, 4, disp21, 0);
622 CamDraw(c28, 4, 4, disp22, 0);
623
624 // Defects
625 TCanvas &c29 = fDisplay->AddTab("Defect");
626 // c29.Divide(5,2);
627 c29.Divide(4,2);
628
629 CamDraw(c29, 1, 4, disp24, 0);
630 CamDraw(c29, 2, 4, disp25, 0);
631 CamDraw(c29, 3, 4, disp26, 0);
632 CamDraw(c29, 4, 4, disp27, 0);
633
634 // Abs. Times
635 TCanvas &c30 = fDisplay->AddTab("Abs. Times");
636 c30.Divide(2,3);
637
638 CamDraw(c30, 1, 2, disp28, 2);
639 CamDraw(c30, 2, 2, disp29, 1);
640
641 if (fRelTimes)
642 {
643 // Rel. Times
644 TCanvas &c31 = fDisplay->AddTab("Rel. Times");
645 c31.Divide(3,4);
646
647 CamDraw(c31, 1, 3, disp30, 2, 1);
648 CamDraw(c31, 2, 3, disp31, 2, 1);
649 CamDraw(c31, 3, 3, disp32, 4, 1);
650
651 // Time Defects
652 TCanvas &c32 = fDisplay->AddTab("Time Def.");
653 c32.Divide(2,2);
654
655 CamDraw(c32, 1, 2, disp33,0);
656 CamDraw(c32, 2, 2, disp34,0);
657
658 MHCalibrationCam *cam = (MHCalibrationCam*)plist.FindObject("MHCalibrationRelTimeCam");
659
660 for (Int_t aidx=0;aidx<cam->GetAverageAreas();aidx++)
661 {
662 cam->GetAverageHiGainArea(aidx).DrawClone("fourierevents");
663 cam->GetAverageLoGainArea(aidx).DrawClone("fourierevents");
664 }
665
666 for (Int_t sector=1;sector<cam->GetAverageSectors();sector++)
667 {
668 cam->GetAverageHiGainSector(sector).DrawClone("fourierevents");
669 cam->GetAverageLoGainSector(sector).DrawClone("fourierevents");
670 }
671
672 }
673
674 return;
675 }
676}
677
678
679
680// --------------------------------------------------------------------------
681//
682// Find the colour of the pulsing LED:
683// - If the run number is smaller than gkIFAEBoxInaugurationRun, take MCalibrationCam::kCT1
684// - Otherwise find the colour out of the run name
685// - If no colour is found, return kFALSE
686//
687Bool_t MJCalibration::FindColor()
688{
689
690 const UInt_t nruns = fRuns->GetNumRuns();
691
692 if (nruns == 0)
693 return kFALSE;
694
695 TArrayI arr = fRuns->GetRuns();
696
697 if (arr[nruns-1] < gkIFAEBoxInaugurationRun)
698 {
699 *fLog << "Found colour kCT1 in runs: " << fRuns->GetRunsAsString() << endl;
700 fColor = MCalibrationCam::kCT1;
701 return kTRUE;
702 }
703
704 TString filenames;
705
706 while (!(filenames=((MDirIter*)fRuns)->Next()).IsNull())
707 {
708
709 filenames.ToLower();
710
711 //
712 // Here starts the list of runs where the shifters did not put
713 // a colour, but which have been found out by other means
714 //
715 if (filenames.Contains("_20660_"))
716 if (fColor == MCalibrationCam::kNONE)
717 {
718 *fLog << "Found colour: kGREEN in " << filenames << endl;
719 fColor = MCalibrationCam::kGREEN;
720 }
721 else if (fColor != MCalibrationCam::kGREEN)
722 {
723 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
724 return kFALSE;
725 }
726
727 if (filenames.Contains("_20661_"))
728 if (fColor == MCalibrationCam::kNONE)
729 {
730 *fLog << "Found colour: kGREEN in " << filenames << endl;
731 fColor = MCalibrationCam::kGREEN;
732 }
733 else if (fColor != MCalibrationCam::kGREEN)
734 {
735 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
736 return kFALSE;
737 }
738
739 if (filenames.Contains("_26568_"))
740 if (fColor == MCalibrationCam::kNONE)
741 {
742 *fLog << "Found colour: kGREEN in " << filenames << endl;
743 fColor = MCalibrationCam::kGREEN;
744 }
745 else if (fColor != MCalibrationCam::kGREEN)
746 {
747 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
748 return kFALSE;
749 }
750 //
751 // Here start the runs where the shifter put
752 // the colour
753 //
754 if (filenames.Contains("green"))
755 if (fColor == MCalibrationCam::kNONE)
756 {
757 *fLog << "Found colour: kGREEN in " << filenames << endl;
758 fColor = MCalibrationCam::kGREEN;
759 }
760 else if (fColor != MCalibrationCam::kGREEN)
761 {
762 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
763 return kFALSE;
764 }
765
766 if (filenames.Contains("blue"))
767 if (fColor == MCalibrationCam::kNONE)
768 {
769 *fLog << "Found colour: kBLUE in " << filenames << endl;
770 fColor = MCalibrationCam::kBLUE;
771 }
772 else if (fColor != MCalibrationCam::kBLUE)
773 {
774 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
775 return kFALSE;
776 }
777
778 if (filenames.Contains("uv"))
779 if (fColor == MCalibrationCam::kNONE)
780 {
781 *fLog << "Found colour: kUV in " << filenames << endl;
782 fColor = MCalibrationCam::kUV;
783 }
784 else if (fColor != MCalibrationCam::kUV)
785 {
786 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
787 return kFALSE;
788 }
789
790 if (filenames.Contains("ct1"))
791 if (fColor == MCalibrationCam::kNONE)
792 {
793 *fLog << "Found colour: kCT1 in " << filenames << endl;
794 fColor = MCalibrationCam::kCT1;
795 }
796 else if (fColor != MCalibrationCam::kCT1)
797 {
798 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
799 return kFALSE;
800 }
801
802 }
803
804 if (fColor == MCalibrationCam::kNONE)
805 {
806 *fLog << "No colour found in filenames of runs: " << fRuns->GetRunsAsString()
807 << "... abort" << endl;
808 return kFALSE;
809 }
810
811 return kTRUE;
812}
813
814
815
816
817// --------------------------------------------------------------------------
818//
819// Retrieve the output file written by WriteResult()
820//
821const char* MJCalibration::GetOutputFile() const
822{
823
824 if (!fRuns)
825 return "";
826
827 return Form("%s/%s-F1.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
828}
829
830
831Bool_t MJCalibration::IsUseBlindPixel() const
832{
833 return TESTBIT(fDevices,kUseBlindPixel);
834}
835
836
837Bool_t MJCalibration::IsUsePINDiode() const
838{
839 return TESTBIT(fDevices,kUsePINDiode);
840}
841
842
843
844
845
846// --------------------------------------------------------------------------
847//
848// Call the ProcessFile(MPedestalCam)
849//
850Bool_t MJCalibration::Process(MPedestalCam &pedcam)
851{
852 if (!ReadCalibrationCam())
853 return ProcessFile(pedcam);
854
855 return kTRUE;
856}
857
858// --------------------------------------------------------------------------
859//
860// Execute the task list and the eventloop:
861//
862// - Check if there are fRuns, otherwise return
863// - Check the colour of the files in fRuns (FindColor()), otherwise return
864// - Check for consistency between run numbers and number of files
865// - Add fRuns to MReadMarsFile
866// - Put into MParList:
867// 1) MPedestalCam (pedcam)
868// 2) MCalibrationQECam (fQECam)
869// 3) MCalibrationChargeCam (fCalibrationCam)
870// 4) MCalibrationRelTimeCam (fRelTimeCam) (only if flag fRelTimes is chosen)
871// 5) MBadPixelsCam (fBadPixels)
872// 6) MCalibrationChargePINDiode
873// 7) MCalibrationChargeBlindPix
874// - Put into the MTaskList:
875// 1) MReadMarsFile
876// 2) MBadPixelsMerge
877// 3) MGeomApply
878// 4) MExtractor
879// 5) MExtractPINDiode
880// 6) MExtractBlindPixel
881// 7) MExtractTime (only if flag fRelTimes is chosen)
882// 8) MContinue(MFCosmics)
883// 9) MFillH("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode")
884// 10) MFillH("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPixel")
885// 11) MFillH("MHCalibrationChargeCam", "MExtractedSignalCam")
886// 12) MFillH("MHCalibrationChargeCam", "MExtractedSignalCam")
887// 13) MCalibrationChargeCalc
888// 14) MFillH("MHCalibrationRelTimeCam", "MArrivalTimeCam") (only if flag fRelTimes is chosen)
889// 15) MCalibrationRelTimeCalc
890// - Execute MEvtLoop
891// - DisplayResult()
892// - WriteResult()
893//
894Bool_t MJCalibration::ProcessFile(MPedestalCam &pedcam)
895{
896 if (!fRuns)
897 {
898 *fLog << err << "No Runs choosen... abort." << endl;
899 return kFALSE;
900 }
901
902 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
903 {
904 *fLog << err << "Number of files found doesn't match number of runs... abort."
905 << fRuns->GetNumRuns() << " vs. " << fRuns->GetNumEntries() << endl;
906 return kFALSE;
907 }
908
909 *fLog << inf;
910 fLog->Separator(GetDescriptor());
911
912 if (!FindColor())
913 return kFALSE;
914
915 *fLog << "Calculate MCalibrationCam from Runs " << fRuns->GetRunsAsString() << endl;
916 *fLog << endl;
917
918 // Setup Tasklist
919 MParList plist;
920 MTaskList tlist;
921 plist.AddToList(&tlist);
922
923 MReadMarsFile read("Events");
924 MRawFileRead rawread(NULL);
925
926 if (fDataCheck)
927 {
928 rawread.AddFiles(*fRuns);
929 tlist.AddToList(&rawread);
930 }
931 else
932 {
933 read.DisableAutoScheme();
934 static_cast<MRead&>(read).AddFiles(*fRuns);
935 tlist.AddToList(&read);
936 }
937
938 MCalibrationChargePINDiode pindiode;
939 MCalibrationChargeBlindPix blindpix;
940
941 plist.AddToList(&pedcam);
942 plist.AddToList(&fBadPixels);
943 plist.AddToList(&fQECam);
944 plist.AddToList(&fCalibrationCam);
945 plist.AddToList(&fRelTimeCam);
946 if (IsUsePINDiode())
947 plist.AddToList(&pindiode);
948 if (IsUseBlindPixel())
949 plist.AddToList(&blindpix);
950
951 MGeomApply apply;
952 // MBadPixelsMerge merge(&fBadPixels);
953 MExtractPINDiode pinext;
954 MExtractBlindPixel blindext;
955 MExtractSlidingWindow extract2;
956 MExtractTimeSpline timespline;
957 MCalibrationChargeCalc calcalc;
958 calcalc.SetOutputPath(fOutputPath);
959 calcalc.SetOutputFile(Form("%s-ChargeCalibStat.txt",(const char*)fRuns->GetRunsAsFileName()));
960
961 MCalibrationRelTimeCalc timecalc;
962 timecalc.SetOutputPath(fOutputPath);
963 timecalc.SetOutputFile(Form("%s-TimeCalibStat.txt",(const char*)fRuns->GetRunsAsFileName()));
964
965 //
966 // As long as there are no DM's, have to colour by hand
967 //
968 calcalc.SetPulserColor(fColor);
969
970 MFillH fillpin("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode");
971 MFillH fillbnd("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPixel");
972 MFillH fillcam("MHCalibrationChargeCam", "MExtractedSignalCam");
973 MFillH filltme("MHCalibrationRelTimeCam", "MArrivalTimeCam");
974 fillpin.SetNameTab("PINDiode");
975 fillbnd.SetNameTab("BlindPix");
976 fillcam.SetNameTab("Charge");
977 filltme.SetNameTab("RelTimes");
978
979
980 //
981 // Apply a filter against cosmics
982 // (will have to be needed in the future
983 // when the calibration hardware-trigger is working)
984 //
985 MFCosmics cosmics;
986 MContinue cont(&cosmics);
987
988 // tlist.AddToList(&merge);
989 tlist.AddToList(&apply);
990
991 if (fExtractor)
992 tlist.AddToList(fExtractor);
993 else
994 {
995 *fLog << warn << GetDescriptor()
996 << ": No extractor has been chosen, take default MExtractSlidingWindow " << endl;
997 tlist.AddToList(&extract2);
998 }
999
1000
1001 tlist.AddToList(&pinext);
1002 tlist.AddToList(&blindext);
1003
1004 if (fRelTimes)
1005 {
1006 if (fTimeExtractor)
1007 tlist.AddToList(fTimeExtractor);
1008 else
1009 {
1010 *fLog << warn << GetDescriptor()
1011 << ": No extractor has been chosen, take default MTimeExtractSpline " << endl;
1012 tlist.AddToList(&timespline);
1013 }
1014 }
1015
1016 if (fColor == MCalibrationCam::kCT1)
1017 tlist.AddToList(&cont);
1018
1019 tlist.AddToList(&fillcam);
1020
1021 if (IsUsePINDiode())
1022 tlist.AddToList(&fillpin);
1023 if (IsUseBlindPixel())
1024 tlist.AddToList(&fillbnd);
1025
1026 tlist.AddToList(&calcalc);
1027
1028 if (fRelTimes)
1029 {
1030 tlist.AddToList(&filltme);
1031 tlist.AddToList(&timecalc);
1032 }
1033
1034
1035 // Create and setup the eventloop
1036 MEvtLoop evtloop(fName);
1037 evtloop.SetParList(&plist);
1038 evtloop.SetDisplay(fDisplay);
1039 evtloop.SetLogStream(fLog);
1040
1041 // Execute first analysis
1042 if (!evtloop.Eventloop())
1043 {
1044 *fLog << err << GetDescriptor() << ": Failed." << endl;
1045 return kFALSE;
1046 }
1047
1048 tlist.PrintStatistics();
1049
1050 DisplayResult(plist);
1051
1052 if (!WriteResult())
1053 return kFALSE;
1054
1055 *fLog << inf << GetDescriptor() << ": Done." << endl;
1056
1057 return kTRUE;
1058}
1059
1060// --------------------------------------------------------------------------
1061//
1062// Read the following containers from GetOutputFile()
1063// - MCalibrationChargeCam
1064// - MCalibrationQECam
1065// - MBadPixelsCam
1066//
1067Bool_t MJCalibration::ReadCalibrationCam()
1068{
1069
1070 const TString fname = GetOutputFile();
1071
1072 if (gSystem->AccessPathName(fname, kFileExists))
1073 {
1074 *fLog << err << "Input file " << fname << " doesn't exist." << endl;
1075 return kFALSE;
1076 }
1077
1078 *fLog << inf << "Reading from file: " << fname << endl;
1079
1080 TFile file(fname, "READ");
1081 if (fCalibrationCam.Read()<=0)
1082 {
1083 *fLog << err << "Unable to read MCalibrationChargeCam from " << fname << endl;
1084 return kFALSE;
1085 }
1086
1087 if (fQECam.Read()<=0)
1088 {
1089 *fLog << err << "Unable to read MCalibrationQECam from " << fname << endl;
1090 return kFALSE;
1091 }
1092
1093
1094 if (fRelTimes)
1095 if (fRelTimeCam.Read()<=0)
1096 {
1097 *fLog << err << "Unable to read MCalibrationRelTimeCam from " << fname << endl;
1098 return kFALSE;
1099 }
1100
1101 if (file.FindKey("MBadPixelsCam"))
1102 {
1103 MBadPixelsCam bad;
1104 if (bad.Read()<=0)
1105 {
1106 *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
1107 return kFALSE;
1108 }
1109 fBadPixels.Merge(bad);
1110 }
1111
1112 if (fDisplay /*&& !fDisplay->GetCanvas("Pedestals")*/) // FIXME!
1113 fDisplay->Read();
1114
1115 return kTRUE;
1116}
1117
1118
1119// --------------------------------------------------------------------------
1120//
1121// Set the path for output files, written by WriteResult()
1122//
1123void MJCalibration::SetOutputPath(const char *path)
1124{
1125 fOutputPath = path;
1126 if (fOutputPath.EndsWith("/"))
1127 fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
1128}
1129
1130// --------------------------------------------------------------------------
1131//
1132// Set the useage of the Blind Pixel device
1133//
1134void MJCalibration::SetUseBlindPixel(const Bool_t b)
1135{
1136 b ? SETBIT(fDevices,kUseBlindPixel) : CLRBIT(fDevices,kUseBlindPixel);
1137}
1138
1139// --------------------------------------------------------------------------
1140//
1141// Set the useage of the PIN Diode device
1142//
1143void MJCalibration::SetUsePINDiode(const Bool_t b)
1144{
1145 b ? SETBIT(fDevices,kUsePINDiode) : CLRBIT(fDevices,kUsePINDiode);
1146}
1147
1148// --------------------------------------------------------------------------
1149//
1150// Write the result into the output file GetOutputFile(), if fOutputPath exists.
1151//
1152// The following containers are written:
1153// - MStatusDisplay
1154// - MCalibrationChargeCam
1155// - MCalibrationQECam
1156// - MBadPixelsCam
1157//
1158Bool_t MJCalibration::WriteResult()
1159{
1160 if (fOutputPath.IsNull())
1161 return kTRUE;
1162
1163 const TString oname(GetOutputFile());
1164
1165 *fLog << inf << "Writing to file: " << oname << endl;
1166
1167 TFile file(oname, "UPDATE");
1168
1169 if (fDisplay && fDisplay->Write()<=0)
1170 {
1171 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
1172 return kFALSE;
1173 }
1174
1175 if (fCalibrationCam.Write()<=0)
1176 {
1177 *fLog << err << "Unable to write MCalibrationChargeCam to " << oname << endl;
1178 return kFALSE;
1179 }
1180
1181 if (fQECam.Write()<=0)
1182 {
1183 *fLog << err << "Unable to write MCalibrationQECam to " << oname << endl;
1184 return kFALSE;
1185 }
1186
1187 if (fRelTimes)
1188 if (fRelTimeCam.Write()<=0)
1189 {
1190 *fLog << err << "Unable to write MCalibrationQECam to " << oname << endl;
1191 return kFALSE;
1192 }
1193
1194 if (fBadPixels.Write()<=0)
1195 {
1196 *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
1197 return kFALSE;
1198 }
1199
1200 return kTRUE;
1201
1202}
1203
Note: See TracBrowser for help on using the repository browser.