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

Last change on this file since 4613 was 4613, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 43.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): 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 <TEnv.h>
90#include <TFile.h>
91#include <TStyle.h>
92#include <TCanvas.h>
93#include <TSystem.h>
94
95#include "MLog.h"
96#include "MLogManip.h"
97
98#include "MRunIter.h"
99#include "MSequence.h"
100#include "MParList.h"
101#include "MTaskList.h"
102#include "MEvtLoop.h"
103
104#include "MHCamera.h"
105#include "MGeomCam.h"
106
107#include "MPedestalCam.h"
108#include "MCalibrationCam.h"
109#include "MCalibrationQECam.h"
110#include "MCalibrationChargeCam.h"
111#include "MCalibrationChargePINDiode.h"
112#include "MCalibrationChargeBlindPix.h"
113#include "MCalibrationChargeBlindCam.h"
114#include "MCalibrationChargeBlindPix.h"
115#include "MCalibrationChargeCalc.h"
116
117#include "MHGausEvents.h"
118#include "MHCalibrationCam.h"
119#include "MHCalibrationChargeCam.h"
120#include "MHCalibrationChargeBlindCam.h"
121#include "MHCalibrationChargePINDiode.h"
122#include "MHCalibrationRelTimeCam.h"
123#include "MCalibrationRelTimeCam.h"
124#include "MCalibrationRelTimeCalc.h"
125
126#include "MReadMarsFile.h"
127#include "MRawFileRead.h"
128#include "MGeomApply.h"
129#include "MTaskEnv.h"
130#include "MBadPixelsMerge.h"
131#include "MBadPixelsCam.h"
132#include "MExtractTime.h"
133#include "MExtractor.h"
134#include "MExtractPINDiode.h"
135#include "MExtractBlindPixel.h"
136#include "MExtractSlidingWindow.h"
137#include "MExtractTimeFastSpline.h"
138#include "MFCosmics.h"
139#include "MContinue.h"
140#include "MFillH.h"
141
142#include "MArrivalTimeCam.h"
143
144#include "MStatusDisplay.h"
145
146ClassImp(MJCalibration);
147
148using namespace std;
149
150const Int_t MJCalibration::gkIFAEBoxInaugurationRun = 20113;
151const Int_t MJCalibration::gkSecondBlindPixelInstallation = 31693;
152const Int_t MJCalibration::gkThirdBlindPixelInstallation = 99999;
153// --------------------------------------------------------------------------
154//
155// Default constructor.
156//
157// - Sets fRuns to 0, fExtractor to NULL, fTimeExtractor to NULL, fColor to kNONE,
158// fDisplay to kNormalDisplay, fRelTime to kFALSE, fDataCheck to kFALSE,
159// - SetUseBlindPixel()
160// - SetUsePINDiode()
161//
162MJCalibration::MJCalibration(const char *name, const char *title)
163 : fEnv(0), fRuns(0), fSequence(0), fExtractor(NULL), fTimeExtractor(NULL),
164 fColor(MCalibrationCam::kNONE), fDisplayType(kNormalDisplay),
165 fRelTimes(kFALSE), fDataCheck(kFALSE), fDebug(kFALSE)
166{
167
168 fName = name ? name : "MJCalibration";
169 fTitle = title ? title : "Tool to create the calibration constants for one calibration run";
170
171 SetUseBlindPixel();
172 SetUsePINDiode();
173
174}
175
176MJCalibration::~MJCalibration()
177{
178 if (fEnv)
179 delete fEnv;
180}
181
182// --------------------------------------------------------------------------
183//
184// Display the results in MStatusDisplay:
185//
186// - Add "Calibration" to the MStatusDisplay title
187// - Retrieve the MGeomCam from MParList
188// - Initialize the following MHCamera's:
189// 1) MCalibrationPix::GetMean()
190// 2) MCalibrationPix::Sigma()
191// 3) MCalibrationChargePix::GetRSigma()
192// 4) MCalibrationChargePix::GetRSigmaPerCharge()
193// 5) MCalibrationChargePix::GetPheFFactorMethod()
194// 6) MCalibrationChargePix::GetMeanConvFADC2Phe()
195// 7) MCalibrationChargePix::GetMeanFFactorFADC2Phot()
196// 8) MCalibrationQEPix::GetQECascadesFFactor()
197// 9) MCalibrationQEPix::GetQECascadesBlindPixel()
198// 10) MCalibrationQEPix::GetQECascadesPINDiode()
199// 11) MCalibrationQEPix::GetQECascadesCombined()
200// 12) MCalibrationQEPix::IsAverageQEFFactorAvailable()
201// 13) MCalibrationQEPix::IsAverageQEBlindPixelAvailable()
202// 14) MCalibrationQEPix::IsAverageQEPINDiodeAvailable()
203// 15) MCalibrationQEPix::IsAverageQECombinedAvailable()
204// 16) MCalibrationChargePix::IsHiGainSaturation()
205// 17) MCalibrationPix::GetHiLoMeansDivided()
206// 18) MCalibrationPix::GetHiLoSigmasDivided()
207// 19) MCalibrationChargePix::GetHiGainPickup()
208// 20) MCalibrationChargePix::GetLoGainPickup()
209// 21) MCalibrationChargePix::GetHiGainBlackout()
210// 22) MCalibrationChargePix::GetLoGainBlackout()
211// 23) MCalibrationPix::IsExcluded()
212// 24) MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableRun)
213// 25) MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnreliableRun)
214// 26) MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
215// 27) MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
216// 28) MCalibrationChargePix::GetAbsTimeMean()
217// 29) MCalibrationChargePix::GetAbsTimeRms()
218//
219// If the flag SetFullDisplay() is set, all MHCameras will be displayed.
220// if the flag SetDataCheckDisplay() is set, only the most important ones are displayed
221// and otherwise, (default: SetNormalDisplay()), a good selection of plots is given
222//
223void MJCalibration::DisplayResult(MParList &plist)
224{
225
226 if (!fDisplay)
227 return;
228
229 //
230 // Update display
231 //
232 TString title = fDisplay->GetTitle();
233 title += "-- Calibration ";
234 title += fSequence ? Form("calib%06d", fSequence->GetSequence()) : fRuns->GetRunsAsString();
235 title += " --";
236 fDisplay->SetTitle(title);
237
238 //
239 // Get container from list
240 //
241 MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
242
243 // Create histograms to display
244 MHCamera disp1 (geomcam, "Charge", "Fitted Mean Charges");
245 MHCamera disp2 (geomcam, "SigmaCharge", "Sigma of Fitted Charges");
246 MHCamera disp3 (geomcam, "RSigma", "Reduced Sigmas");
247 MHCamera disp4 (geomcam, "RSigmaPerCharge", "Reduced Sigma per Charge");
248 MHCamera disp5 (geomcam, "NumPhes", "Nr. of Phe's (F-Factor Method)");
249 MHCamera disp6 (geomcam, "ConvFADC2Phes", "Conversion Factor (F-Factor Method)");
250 MHCamera disp7 (geomcam, "TotalFFactor", "Total F-Factor (F-Factor Method)");
251 MHCamera disp8 (geomcam, "CascadesQEFFactor", "Cascades QE (F-Factor Method)");
252 MHCamera disp9 (geomcam, "CascadesQEBlindPix","Cascades QE (Blind Pixel Method)");
253 MHCamera disp10(geomcam, "CascadesQEPINDiode","Cascades QE (PIN Diode Method)");
254 MHCamera disp11(geomcam, "CascadesQECombined","Cascades QE (Combined Method)");
255 MHCamera disp12(geomcam, "FFactorValid", "Pixels with valid F-Factor calibration");
256 MHCamera disp13(geomcam, "BlindPixelValid", "Pixels with valid BlindPixel calibration");
257 MHCamera disp14(geomcam, "PINdiodeValid", "Pixels with valid PINDiode calibration");
258 MHCamera disp15(geomcam, "CombinedValid", "Pixels with valid Combined calibration");
259 MHCamera disp16(geomcam, "Saturation", "Pixels with saturated Hi Gain");
260 MHCamera disp17(geomcam, "ConversionMeans", "Conversion HiGain.vs.LoGain Means");
261 MHCamera disp18(geomcam, "ConversionSigmas", "Conversion HiGain.vs.LoGain Sigmas");
262 MHCamera disp19(geomcam, "HiGainPickup", "Number Pickup events Hi Gain");
263 MHCamera disp20(geomcam, "LoGainPickup", "Number Pickup events Lo Gain");
264 MHCamera disp21(geomcam, "HiGainBlackout", "Number Blackout events Hi Gain");
265 MHCamera disp22(geomcam, "LoGainBlackout", "Number Blackout events Lo Gain");
266 MHCamera disp23(geomcam, "Excluded", "Pixels previously excluded");
267 MHCamera disp24(geomcam, "UnSuitable", "Pixels not suited for further analysis");
268 MHCamera disp25(geomcam, "UnReliable", "Pixels not reliable for further analysis");
269 MHCamera disp26(geomcam, "HiGainOscillating", "Oscillating Pixels High Gain");
270 MHCamera disp27(geomcam, "LoGainOscillating", "Oscillating Pixels Low Gain");
271 MHCamera disp28(geomcam, "AbsTimeMean", "Abs. Arrival Times");
272 MHCamera disp29(geomcam, "AbsTimeRms", "RMS of Arrival Times");
273 MHCamera disp30(geomcam, "MeanTime", "Mean Rel. Arrival Times");
274 MHCamera disp31(geomcam, "SigmaTime", "Sigma Rel. Arrival Times");
275 MHCamera disp32(geomcam, "TimeProb", "Probability of Time Fit");
276 MHCamera disp33(geomcam, "TimeNotFitValid", "Pixels with not valid fit results");
277 MHCamera disp34(geomcam, "TimeOscillating", "Oscillating Pixels");
278
279 // Fitted charge means and sigmas
280 disp1.SetCamContent(fCalibrationCam, 0);
281 disp1.SetCamError( fCalibrationCam, 1);
282 disp2.SetCamContent(fCalibrationCam, 2);
283 disp2.SetCamError( fCalibrationCam, 3);
284
285 // Reduced Sigmas and reduced sigmas per charge
286 disp3.SetCamContent(fCalibrationCam, 5);
287 disp3.SetCamError( fCalibrationCam, 6);
288 disp4.SetCamContent(fCalibrationCam, 7);
289 disp4.SetCamError( fCalibrationCam, 8);
290
291 // F-Factor Method
292 disp5.SetCamContent(fCalibrationCam, 9);
293 disp5.SetCamError( fCalibrationCam, 10);
294 disp6.SetCamContent(fCalibrationCam, 11);
295 disp6.SetCamError( fCalibrationCam, 12);
296 disp7.SetCamContent(fCalibrationCam, 13);
297 disp7.SetCamError( fCalibrationCam, 14);
298
299 // Quantum Efficiencies
300 disp8.SetCamContent (fQECam, 0 );
301 disp8.SetCamError (fQECam, 1 );
302 disp9.SetCamContent (fQECam, 2 );
303 disp9.SetCamError (fQECam, 3 );
304 disp10.SetCamContent(fQECam, 4 );
305 disp10.SetCamError (fQECam, 5 );
306 disp11.SetCamContent(fQECam, 6 );
307 disp11.SetCamError (fQECam, 7 );
308
309 // Valid flags
310 disp12.SetCamContent(fQECam, 8 );
311 disp13.SetCamContent(fQECam, 9 );
312 disp14.SetCamContent(fQECam, 10);
313 disp15.SetCamContent(fQECam, 11);
314
315 // Conversion Hi-Lo
316 disp16.SetCamContent(fCalibrationCam, 25);
317 disp17.SetCamContent(fCalibrationCam, 16);
318 disp17.SetCamError (fCalibrationCam, 17);
319 disp18.SetCamContent(fCalibrationCam, 18);
320 disp18.SetCamError (fCalibrationCam, 19);
321
322 // Pickup and Blackout
323 disp19.SetCamContent(fCalibrationCam, 21);
324 disp20.SetCamContent(fCalibrationCam, 22);
325 disp21.SetCamContent(fCalibrationCam, 23);
326 disp22.SetCamContent(fCalibrationCam, 24);
327
328 // Pixels with defects
329 disp23.SetCamContent(fCalibrationCam, 20);
330 disp24.SetCamContent(fBadPixels, 1);
331 disp25.SetCamContent(fBadPixels, 3);
332
333 // Oscillations
334 disp26.SetCamContent(fBadPixels, 10);
335 disp27.SetCamContent(fBadPixels, 11);
336
337 // Arrival Times
338 disp28.SetCamContent(fCalibrationCam, 26);
339 disp28.SetCamError( fCalibrationCam, 27);
340 disp29.SetCamContent(fCalibrationCam, 27);
341
342 disp1.SetYTitle("Q [FADC counts]");
343 disp2.SetYTitle("\\sigma_{Q} [FADC counts]");
344
345 disp3.SetYTitle("\\sqrt{\\sigma^{2}_{Q} - RMS^{2}_{Ped}} [FADC Counts]");
346 disp4.SetYTitle("Red.Sigma/<Q> [1]");
347
348 disp5.SetYTitle("Nr. Phe's [1]");
349 disp6.SetYTitle("Conv.Factor [PhE/FADC counts]");
350 disp7.SetYTitle("Total F-Factor [1]");
351
352 disp8.SetYTitle("QE [1]");
353 disp9.SetYTitle("QE [1]");
354 disp10.SetYTitle("QE [1]");
355 disp11.SetYTitle("QE [1]");
356
357 disp12.SetYTitle("[1]");
358 disp13.SetYTitle("[1]");
359 disp14.SetYTitle("[1]");
360 disp15.SetYTitle("[1]");
361 disp16.SetYTitle("[1]");
362
363 disp17.SetYTitle("<Q>(High)/<Q>(Low) [1]");
364 disp18.SetYTitle("\\sigma_{Q}(High)/\\sigma_{Q}(Low) [1]");
365
366 disp19.SetYTitle("[1]");
367 disp20.SetYTitle("[1]");
368 disp21.SetYTitle("[1]");
369 disp22.SetYTitle("[1]");
370 disp23.SetYTitle("[1]");
371 disp24.SetYTitle("[1]");
372 disp25.SetYTitle("[1]");
373 disp26.SetYTitle("[1]");
374 disp27.SetYTitle("[1]");
375
376 disp28.SetYTitle("Mean Abs. Time [FADC slice]");
377 disp29.SetYTitle("RMS Abs. Time [FADC slices]");
378
379 if (fRelTimes)
380 {
381 disp30.SetCamContent(fRelTimeCam,0);
382 disp30.SetCamError( fRelTimeCam,1);
383 disp31.SetCamContent(fRelTimeCam,2);
384 disp31.SetCamError( fRelTimeCam,3);
385 disp32.SetCamContent(fRelTimeCam,4);
386 disp33.SetCamContent(fBadPixels,20);
387 disp34.SetCamContent(fBadPixels,21);
388
389 disp30.SetYTitle("Time Offset [FADC units]");
390 disp31.SetYTitle("Timing resolution [FADC units]");
391 disp32.SetYTitle("P_{Time} [1]");
392 disp33.SetYTitle("[1]");
393 disp34.SetYTitle("[1]");
394 }
395
396 if (fDisplayType == kDataCheckDisplay)
397 {
398
399 TCanvas &c1 = fDisplay->AddTab("Fit.Charge");
400 c1.Divide(3, 3);
401
402 disp1.CamDraw( c1, 1, 3, 5);
403 disp4.CamDraw( c1, 2, 3, 5);
404 disp28.CamDraw(c1, 3, 3, 5);
405
406 // F-Factor
407 TCanvas &c2 = fDisplay->AddTab("Phe's");
408 c2.Divide(3,4);
409
410 disp6.CamDraw(c2, 1, 3, 5, 1);
411 disp7.CamDraw(c2, 2, 3, 5, 1);
412 disp8.CamDraw(c2, 3, 3, 5, 1);
413
414 // QE's
415 TCanvas &c3 = fDisplay->AddTab("QE's");
416 c3.Divide(3,4);
417
418 disp8.CamDraw(c3, 1, 3, 5, 1);
419 disp9.CamDraw(c3, 2, 3, 5, 1);
420 disp10.CamDraw(c3, 3, 3, 5, 1);
421
422 // Defects
423 TCanvas &c4 = fDisplay->AddTab("Defect");
424 c4.Divide(2,2);
425
426 disp24.CamDraw(c4, 1, 2, 0);
427 disp25.CamDraw(c4, 2, 2, 0);
428
429 if (fRelTimes)
430 {
431 // Rel. Times
432 TCanvas &c5 = fDisplay->AddTab("Rel. Times");
433 c5.Divide(2,4);
434
435 disp30.CamDraw(c5, 1, 2, 2);
436 disp31.CamDraw(c5, 2, 2, 2);
437 }
438
439 return;
440 }
441
442 if (fDisplayType == kNormalDisplay)
443 {
444
445 // Charges
446 TCanvas &c11 = fDisplay->AddTab("Fit.Charge");
447 c11.Divide(2, 4);
448
449 disp1.CamDraw(c11, 1, 2, 5, 1);
450 disp2.CamDraw(c11, 2, 2, 5, 1);
451
452 // Reduced Sigmas
453 TCanvas &c12 = fDisplay->AddTab("Red.Sigma");
454 c12.Divide(2,4);
455
456 disp3.CamDraw(c12, 1, 2, 5, 1);
457 disp4.CamDraw(c12, 2, 2, 5, 1);
458
459 // F-Factor
460 TCanvas &c13 = fDisplay->AddTab("Phe's");
461 c13.Divide(3,4);
462
463 disp5.CamDraw(c13, 1, 3, 5, 1);
464 disp6.CamDraw(c13, 2, 3, 5, 1);
465 disp7.CamDraw(c13, 3, 3, 5, 1);
466
467 // QE's
468 TCanvas &c14 = fDisplay->AddTab("QE's");
469 c14.Divide(4,4);
470
471 disp8.CamDraw(c14, 1, 4, 5, 1);
472 disp9.CamDraw(c14, 2, 4, 5, 1);
473 disp10.CamDraw(c14, 3, 4, 5, 1);
474 disp11.CamDraw(c14, 4, 4, 5, 1);
475
476 // Defects
477 TCanvas &c15 = fDisplay->AddTab("Defect");
478 // c15.Divide(5,2);
479 c15.Divide(4,2);
480
481 /*
482 disp23.CamDraw(c15, 1, 5, 0);
483 disp24.CamDraw(c15, 2, 5, 0);
484 disp25.CamDraw(c15, 3, 5, 0);
485 disp26.CamDraw(c15, 4, 5, 0);
486 disp27.CamDraw(c15, 5, 5, 0);
487 */
488 disp24.CamDraw(c15, 1, 4, 0);
489 disp25.CamDraw(c15, 2, 4, 0);
490 disp26.CamDraw(c15, 3, 4, 0);
491 disp27.CamDraw(c15, 4, 4, 0);
492
493 // Abs. Times
494 TCanvas &c16 = fDisplay->AddTab("Abs. Times");
495 c16.Divide(2,3);
496
497 disp28.CamDraw(c16, 1, 2, 5);
498 disp29.CamDraw(c16, 2, 2, 5);
499
500 if (fRelTimes)
501 {
502 // Rel. Times
503 TCanvas &c17 = fDisplay->AddTab("Rel. Times");
504 c17.Divide(2,4);
505
506 disp30.CamDraw(c17, 1, 2, 5, 1);
507 disp31.CamDraw(c17, 2, 2, 5, 1);
508 }
509
510 return;
511 }
512
513 if (fDisplayType == kFullDisplay)
514 {
515 MHCalibrationCam *cam = (MHCalibrationCam*)plist.FindObject("MHCalibrationChargeCam");
516
517 for (Int_t sector=1;sector<cam->GetAverageSectors();sector++)
518 {
519 cam->GetAverageHiGainSector(sector).DrawClone("all");
520 cam->GetAverageLoGainSector(sector).DrawClone("all");
521 }
522
523 // Charges
524 TCanvas &c21 = fDisplay->AddTab("Fit.Charge");
525 c21.Divide(2, 4);
526
527 disp1.CamDraw(c21, 1, 2, 2, 1);
528 disp2.CamDraw(c21, 2, 2, 2, 1);
529
530 // Reduced Sigmas
531 TCanvas &c23 = fDisplay->AddTab("Red.Sigma");
532 c23.Divide(2,4);
533
534 disp3.CamDraw(c23, 1, 2, 2, 1);
535 disp4.CamDraw(c23, 2, 2, 2, 1);
536
537 // F-Factor
538 TCanvas &c24 = fDisplay->AddTab("Phe's");
539 c24.Divide(3,5);
540
541 disp5.CamDraw(c24, 1, 3, 2, 1, 1);
542 disp6.CamDraw(c24, 2, 3, 2, 1, 1);
543 disp7.CamDraw(c24, 3, 3, 2, 1, 1);
544
545 // QE's
546 TCanvas &c25 = fDisplay->AddTab("QE's");
547 c25.Divide(4,5);
548
549 disp8.CamDraw(c25, 1, 4, 2, 1, 1);
550 disp9.CamDraw(c25, 2, 4, 2, 1, 1);
551 disp10.CamDraw(c25, 3, 4, 2, 1, 1);
552 disp11.CamDraw(c25, 4, 4, 2, 1, 1);
553
554 // Validity
555 TCanvas &c26 = fDisplay->AddTab("Valid");
556 c26.Divide(4,2);
557
558 disp12.CamDraw(c26, 1, 4, 0);
559 disp13.CamDraw(c26, 2, 4, 0);
560 disp14.CamDraw(c26, 3, 4, 0);
561 disp15.CamDraw(c26, 4, 4, 0);
562
563 // Other info
564 TCanvas &c27 = fDisplay->AddTab("HiLoGain");
565 c27.Divide(3,3);
566
567 disp16.CamDraw(c27, 1, 3, 0);
568 disp17.CamDraw(c27, 2, 3, 1);
569 disp18.CamDraw(c27, 3, 3, 1);
570
571 // Pickup
572 TCanvas &c28 = fDisplay->AddTab("Pickup");
573 c28.Divide(4,2);
574
575 disp19.CamDraw(c28, 1, 4, 0);
576 disp20.CamDraw(c28, 2, 4, 0);
577 disp21.CamDraw(c28, 3, 4, 0);
578 disp22.CamDraw(c28, 4, 4, 0);
579
580 // Defects
581 TCanvas &c29 = fDisplay->AddTab("Defect");
582 // c29.Divide(5,2);
583 c29.Divide(4,2);
584
585 disp24.CamDraw(c29, 1, 4, 0);
586 disp25.CamDraw(c29, 2, 4, 0);
587 disp26.CamDraw(c29, 3, 4, 0);
588 disp27.CamDraw(c29, 4, 4, 0);
589
590 // Abs. Times
591 TCanvas &c30 = fDisplay->AddTab("Abs. Times");
592 c30.Divide(2,3);
593
594 disp28.CamDraw(c30, 1, 2, 2);
595 disp29.CamDraw(c30, 2, 2, 1);
596
597 if (fRelTimes)
598 {
599 // Rel. Times
600 TCanvas &c31 = fDisplay->AddTab("Rel. Times");
601 c31.Divide(3,5);
602
603 disp30.CamDraw(c31, 1, 3, 2, 1, 1);
604 disp31.CamDraw(c31, 2, 3, 2, 1, 1);
605 disp32.CamDraw(c31, 3, 3, 4, 1, 1);
606
607 // Time Defects
608 TCanvas &c32 = fDisplay->AddTab("Time Def.");
609 c32.Divide(2,2);
610
611 disp33.CamDraw(c32, 1, 2, 0);
612 disp34.CamDraw(c32, 2, 2, 0);
613
614 MHCalibrationCam *cam = (MHCalibrationCam*)plist.FindObject("MHCalibrationRelTimeCam");
615
616 for (Int_t sector=1;sector<cam->GetAverageSectors();sector++)
617 {
618 cam->GetAverageHiGainSector(sector).DrawClone("fourierevents");
619 cam->GetAverageLoGainSector(sector).DrawClone("fourierevents");
620 }
621
622 }
623
624 return;
625 }
626}
627
628
629
630// --------------------------------------------------------------------------
631//
632// Find the colour of the pulsing LED:
633// - If the run number is smaller than gkIFAEBoxInaugurationRun, take MCalibrationCam::kCT1
634// - Otherwise find the colour out of the run name
635// - If no colour is found, return kFALSE
636//
637Bool_t MJCalibration::FindColor()
638{
639 if (fSequence)
640 {
641 fColor = MCalibrationCam::kCT1;
642 return kTRUE;
643 }
644
645const UInt_t nruns = fRuns->GetNumRuns();
646
647 if (nruns == 0)
648 return kFALSE;
649
650 TArrayI arr = fRuns->GetRuns();
651
652 if (arr[nruns-1] < gkIFAEBoxInaugurationRun)
653 {
654 *fLog << "Found colour kCT1 in runs: " << fRuns->GetRunsAsString() << endl;
655 fColor = MCalibrationCam::kCT1;
656 return kTRUE;
657 }
658
659 TString filenames;
660 ((MDirIter*)fRuns)->Reset();
661
662 while (!(filenames=((MDirIter*)fRuns)->Next()).IsNull())
663 {
664
665 filenames.ToLower();
666
667 //
668 // Here starts the list of runs where the shifters did not put
669 // a colour, but which have been found out by other means.
670 // FIXME: This list has is only preliminary and has to move into the
671 // database!!
672 //
673 if (filenames.Contains("_30090_"))
674 if (fColor == MCalibrationCam::kNONE)
675 {
676 *fLog << "Found colour: kGREEN in " << filenames << endl;
677 fColor = MCalibrationCam::kGREEN;
678 }
679 else if (fColor != MCalibrationCam::kNONE)
680 {
681 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
682 return kFALSE;
683 }
684
685 if (filenames.Contains("_27474_"))
686 if (fColor == MCalibrationCam::kNONE)
687 {
688 *fLog << "Sorry, run 27474 was taken with CLOSED LIDS. It should not be used! "
689 << "Selected runs were: " << filenames << endl;
690 fColor = MCalibrationCam::kNONE;
691 return kFALSE;
692 }
693 else if (fColor != MCalibrationCam::kNONE)
694 {
695 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
696 return kFALSE;
697 }
698
699 if (filenames.Contains("_26924_"))
700 if (fColor == MCalibrationCam::kNONE)
701 {
702 *fLog << "Found colour: kGREEN in " << filenames << endl;
703 fColor = MCalibrationCam::kGREEN;
704 }
705 else if (fColor != MCalibrationCam::kGREEN)
706 {
707 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
708 return kFALSE;
709 }
710
711
712 if (filenames.Contains("_26568_"))
713 if (fColor == MCalibrationCam::kNONE)
714 {
715 *fLog << "Found colour: kGREEN in " << filenames << endl;
716 fColor = MCalibrationCam::kGREEN;
717 }
718 else if (fColor != MCalibrationCam::kGREEN)
719 {
720 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
721 return kFALSE;
722 }
723
724 if (filenames.Contains("_26412_"))
725 if (fColor == MCalibrationCam::kNONE)
726 {
727 *fLog << "Found colour: kGREEN in " << filenames << endl;
728 fColor = MCalibrationCam::kGREEN;
729 }
730 else if (fColor != MCalibrationCam::kGREEN)
731 {
732 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
733 return kFALSE;
734 }
735
736
737 if (filenames.Contains("_26409_"))
738 if (fColor == MCalibrationCam::kNONE)
739 {
740 *fLog << "Found colour: kGREEN in " << filenames << endl;
741 fColor = MCalibrationCam::kGREEN;
742 }
743 else if (fColor != MCalibrationCam::kGREEN)
744 {
745 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
746 return kFALSE;
747 }
748
749 if (filenames.Contains("_26408_"))
750 if (fColor == MCalibrationCam::kNONE)
751 {
752 *fLog << "Found colour: kGREEN in " << filenames << endl;
753 fColor = MCalibrationCam::kGREEN;
754 }
755 else if (fColor != MCalibrationCam::kGREEN)
756 {
757 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
758 return kFALSE;
759 }
760
761
762 if (filenames.Contains("_26402_"))
763 if (fColor == MCalibrationCam::kNONE)
764 {
765 *fLog << "Found colour: kBLUE in " << filenames << endl;
766 fColor = MCalibrationCam::kBLUE;
767 }
768 else if (fColor != MCalibrationCam::kBLUE)
769 {
770 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
771 return kFALSE;
772 }
773
774 if (filenames.Contains("_20661_"))
775 if (fColor == MCalibrationCam::kNONE)
776 {
777 *fLog << "Found colour: kGREEN in " << filenames << endl;
778 fColor = MCalibrationCam::kGREEN;
779 }
780 else if (fColor != MCalibrationCam::kGREEN)
781 {
782 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
783 return kFALSE;
784 }
785
786 if (filenames.Contains("_20660_"))
787 if (fColor == MCalibrationCam::kNONE)
788 {
789 *fLog << "Found colour: kGREEN in " << filenames << endl;
790 fColor = MCalibrationCam::kGREEN;
791 }
792 else if (fColor != MCalibrationCam::kGREEN)
793 {
794 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
795 return kFALSE;
796 }
797
798 //
799 // Here start the runs where the shifter put
800 // the colour.
801 //
802 if (filenames.Contains("green"))
803 if (fColor == MCalibrationCam::kNONE)
804 {
805 *fLog << "Found colour: kGREEN in " << filenames << endl;
806 fColor = MCalibrationCam::kGREEN;
807 }
808 else if (fColor != MCalibrationCam::kGREEN)
809 {
810 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
811 return kFALSE;
812 }
813
814 if (filenames.Contains("blue"))
815 if (fColor == MCalibrationCam::kNONE)
816 {
817 *fLog << "Found colour: kBLUE in " << filenames << endl;
818 fColor = MCalibrationCam::kBLUE;
819 }
820 else if (fColor != MCalibrationCam::kBLUE)
821 {
822 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
823 return kFALSE;
824 }
825
826 if (filenames.Contains("uv"))
827 if (fColor == MCalibrationCam::kNONE)
828 {
829 *fLog << "Found colour: kUV in " << filenames << endl;
830 fColor = MCalibrationCam::kUV;
831 }
832 else if (fColor != MCalibrationCam::kUV)
833 {
834 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
835 return kFALSE;
836 }
837
838 if (filenames.Contains("ct1"))
839 if (fColor == MCalibrationCam::kNONE)
840 {
841 *fLog << "Found colour: kCT1 in " << filenames << endl;
842 fColor = MCalibrationCam::kCT1;
843 }
844 else if (fColor != MCalibrationCam::kCT1)
845 {
846 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
847 return kFALSE;
848 }
849
850 }
851
852 if (fColor == MCalibrationCam::kNONE)
853 {
854 *fLog << "No colour found in filenames of runs: " << fRuns->GetRunsAsString()
855 << "... abort" << endl;
856 return kFALSE;
857 }
858
859
860 return kTRUE;
861}
862
863// --------------------------------------------------------------------------
864//
865// Retrieve the output file written by WriteResult()
866//
867const char* MJCalibration::GetOutputFile() const
868{
869 if (fSequence)
870 return Form("%s/calib%06d.root", (const char*)fOutputPath, fSequence->GetSequence());
871 if (!fRuns)
872 return "";
873
874 return Form("%s/%s-F1.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
875}
876
877Bool_t MJCalibration::IsUseBlindPixel() const
878{
879 return TESTBIT(fDevices,kUseBlindPixel);
880}
881
882Bool_t MJCalibration::IsUsePINDiode() const
883{
884 return TESTBIT(fDevices,kUsePINDiode);
885}
886
887void MJCalibration::SetEnv(const char *env)
888{
889 if (fEnv)
890 delete fEnv;
891 fEnv = new TEnv(env);
892}
893
894void MJCalibration::CheckEnv()
895{
896 if (!fEnv)
897 return;
898
899 TString e1 = fEnv->GetValue("MJCalibration.OutputPath", "");
900 if (!e1.IsNull())
901 {
902 e1.ReplaceAll("\015", "");
903 SetOutputPath(e1);
904 }
905
906 TString col = fEnv->GetValue("MJCalibration.Color", "");
907 if (!col.IsNull())
908 {
909 }
910
911 TString dis = fEnv->GetValue("MJCalibration.Display", "");
912 if (dis.BeginsWith("Full", TString::kIgnoreCase))
913 SetFullDisplay();
914 if (dis.BeginsWith("DataCheck", TString::kIgnoreCase))
915 SetDataCheckDisplay();
916 if (dis.BeginsWith("Normal", TString::kIgnoreCase))
917 SetNormalDisplay();
918
919 SetRelTimeCalibration(fEnv->GetValue("MJCalibration.RelTimeCalibration", fRelTimes));
920 SetDataCheck(fEnv->GetValue("MJCalibration.Datacheck", fDataCheck));
921 SetDebug(fEnv->GetValue("MJCalibration.Debug", fDebug));
922 SetUseBlindPixel(fEnv->GetValue("MJCalibration.UseBlindPixel", IsUseBlindPixel()));
923 SetUsePINDiode(fEnv->GetValue("MJCalibration.UsePINDiode", IsUsePINDiode()));
924}
925
926// --------------------------------------------------------------------------
927//
928// Call the ProcessFile(MPedestalCam)
929//
930Bool_t MJCalibration::Process(MPedestalCam &pedcam)
931{
932 if (!ReadCalibrationCam())
933 return ProcessFile(pedcam);
934
935 return kTRUE;
936}
937
938void MJCalibration::InitBlindPixel(MExtractBlindPixel &blindext,
939 MHCalibrationChargeBlindCam &blindcam)
940{
941 Int_t run = fSequence ? fSequence->GetLastRun() : fRuns->GetRuns()[fRuns->GetNumRuns()-1];
942
943 //
944 // Initialize the blind pixel. Unfortunately, there is a hardware difference
945 // in the first blind pixel until run "gkSecondBlindPixelInstallation" and the
946 // later setup. The first needs to use a filter because of the length of
947 // spurious NSB photon signals. The latter get better along extracting the amplitude
948 // from a small window.
949 //
950 if (run < gkSecondBlindPixelInstallation)
951 {
952 blindext.SetModified(kFALSE);
953 blindext.SetExtractionType(MExtractBlindPixel::kIntegral);
954 blindext.SetExtractionType(MExtractBlindPixel::kFilter);
955 blindext.SetRange(10,19,0,6);
956 blindext.SetNSBFilterLimit(70);
957 blindcam.SetFitFunc( MHCalibrationChargeBlindPix::kEPoisson5 );
958 }
959 else
960 {
961 blindext.SetModified(kTRUE);
962 blindext.SetExtractionType(MExtractBlindPixel::kAmplitude);
963 blindext.SetExtractionType(MExtractBlindPixel::kFilter);
964 blindext.SetRange(5,8,0,2);
965 blindext.SetNSBFilterLimit(38);
966
967 if (run < gkThirdBlindPixelInstallation)
968 blindext.SetNumBlindPixels(2);
969 else
970 blindext.SetNumBlindPixels(3);
971 }
972}
973
974// --------------------------------------------------------------------------
975//
976// Execute the task list and the eventloop:
977//
978// - Check if there are fRuns, otherwise return
979// - Check the colour of the files in fRuns (FindColor()), otherwise return
980// - Check for consistency between run numbers and number of files
981// - Add fRuns to MReadMarsFile
982// - Put into MParList:
983// 1) MPedestalCam (pedcam)
984// 2) MCalibrationQECam (fQECam)
985// 3) MCalibrationChargeCam (fCalibrationCam)
986// 4) MCalibrationRelTimeCam (fRelTimeCam) (only if flag fRelTimes is chosen)
987// 5) MBadPixelsCam (fBadPixels)
988// 6) MCalibrationChargePINDiode
989// 7) MCalibrationChargeBlindPix
990// - Put into the MTaskList:
991// 1) MReadMarsFile
992// 2) MBadPixelsMerge
993// 3) MGeomApply
994// 4) MExtractor
995// 5) MExtractPINDiode
996// 6) MExtractBlindPixel
997// 7) MExtractTime (only if flag fRelTimes is chosen)
998// 8) MContinue(MFCosmics)
999// 9) MFillH("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode")
1000// 10) MFillH("MHCalibrationChargeBlindCam", "MExtractedSignalBlindPixel")
1001// 11) MFillH("MHCalibrationChargeCam", "MExtractedSignalCam")
1002// 12) MFillH("MHCalibrationChargeCam", "MExtractedSignalCam")
1003// 13) MCalibrationChargeCalc
1004// 14) MFillH("MHCalibrationRelTimeCam", "MArrivalTimeCam") (only if flag fRelTimes is chosen)
1005// 15) MCalibrationRelTimeCalc
1006// - Execute MEvtLoop
1007// - DisplayResult()
1008// - WriteResult()
1009//
1010Bool_t MJCalibration::ProcessFile(MPedestalCam &pedcam)
1011{
1012 if (!fRuns && !fSequence)
1013 {
1014 *fLog << err << "No Runs choosen... abort." << endl;
1015 return kFALSE;
1016 }
1017
1018 if (!fSequence && fRuns->GetNumRuns() != fRuns->GetNumEntries())
1019 {
1020 *fLog << err << "Number of files found doesn't match number of runs... abort."
1021 << fRuns->GetNumRuns() << " vs. " << fRuns->GetNumEntries() << endl;
1022 return kFALSE;
1023 }
1024
1025 *fLog << inf;
1026 fLog->Separator(GetDescriptor());
1027
1028 if (!FindColor())
1029 return kFALSE;
1030
1031 *fLog << "Calculate MCalibrationCam from ";
1032 if (fSequence)
1033 *fLog << "Sequence #" << fSequence->GetSequence() << endl;
1034 else
1035 *fLog << "Runs " << fRuns->GetRunsAsString() << endl;
1036 *fLog << endl;
1037
1038 CheckEnv();
1039
1040 // Setup Tasklist
1041 MParList plist;
1042 MTaskList tlist;
1043 plist.AddToList(&tlist);
1044
1045 MReadMarsFile read("Events");
1046 MRawFileRead rawread(NULL);
1047
1048 MDirIter iter;
1049 if (fSequence)
1050 fSequence->SetupCalRuns(iter);
1051
1052 if (fDataCheck)
1053 {
1054 rawread.AddFiles(fSequence ? iter : *fRuns);
1055 tlist.AddToList(&rawread);
1056 }
1057 else
1058 {
1059 read.DisableAutoScheme();
1060 static_cast<MRead&>(read).AddFiles(fSequence ? iter : *fRuns);
1061 tlist.AddToList(&read);
1062 }
1063
1064 MHCalibrationChargeCam chargecam;
1065 MHCalibrationChargeBlindCam blindcam;
1066
1067 plist.AddToList(&pedcam);
1068 plist.AddToList(&chargecam);
1069 plist.AddToList(&blindcam);
1070 plist.AddToList(&fBadPixels);
1071 plist.AddToList(&fQECam);
1072 plist.AddToList(&fCalibrationCam);
1073 plist.AddToList(&fCalibrationBlindCam);
1074 plist.AddToList(&fCalibrationPINDiode);
1075 plist.AddToList(&fRelTimeCam);
1076
1077 MGeomApply apply;
1078 MBadPixelsMerge merge(&fBadPixels);
1079 MExtractPINDiode pinext;
1080 MExtractBlindPixel blindext;
1081 InitBlindPixel(blindext, blindcam);
1082 MExtractSlidingWindow extract2;
1083 MExtractTimeFastSpline timespline;
1084 MCalibrationChargeCalc calcalc;
1085 if (!fSequence)
1086 {
1087 calcalc.SetOutputPath(fOutputPath);
1088 calcalc.SetOutputFile(Form("%s-ChargeCalibStat.txt",(const char*)fRuns->GetRunsAsFileName()));
1089 }
1090
1091 if (fDebug)
1092 {
1093 chargecam.SetDebug();
1094 calcalc.SetDebug();
1095 }
1096
1097 //
1098 // As long as there are no DM's, have to colour by hand
1099 //
1100 calcalc.SetPulserColor(fColor);
1101
1102 MFillH fillpin("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode");
1103 MFillH fillbnd("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPixel");
1104 MFillH fillcam("MHCalibrationChargeCam", "MExtractedSignalCam");
1105 MFillH filltme("MHCalibrationRelTimeCam", "MArrivalTimeCam");
1106 fillpin.SetNameTab("PINDiode");
1107 fillbnd.SetNameTab("BlindPix");
1108 fillcam.SetNameTab("Charge");
1109 filltme.SetNameTab("RelTimes");
1110
1111 TString drawoption;
1112
1113 if (fDisplayType == kDataCheckDisplay)
1114 drawoption += "datacheck";
1115 if (fDisplayType == kFullDisplay)
1116 drawoption += " all";
1117
1118 fillcam.SetDrawOption(drawoption.Data());
1119 fillbnd.SetDrawOption(drawoption.Data());
1120 fillpin.SetDrawOption(drawoption.Data());
1121 filltme.SetDrawOption(drawoption.Data());
1122
1123 //
1124 // Apply a filter against cosmics
1125 // (will have to be needed in the future
1126 // when the calibration hardware-trigger is working)
1127 //
1128 MFCosmics cosmics;
1129 MContinue cont(&cosmics);
1130
1131 tlist.AddToList(&merge);
1132 tlist.AddToList(&apply);
1133
1134 MTaskEnv taskenv("ExtractSignal");
1135 taskenv.SetDefault(fExtractor ? fExtractor : &extract2);
1136
1137 tlist.AddToList(&taskenv);
1138 tlist.AddToList(&pinext);
1139 tlist.AddToList(&blindext);
1140
1141 MTaskEnv taskenv2("ExtractTime");
1142 taskenv2.SetDefault(fTimeExtractor ? fTimeExtractor : &timespline);
1143
1144 if (fRelTimes)
1145 tlist.AddToList(&taskenv2);
1146
1147 if (fColor == MCalibrationCam::kCT1)
1148 tlist.AddToList(&cont);
1149
1150 tlist.AddToList(&fillcam);
1151 tlist.AddToList(&calcalc);
1152
1153 MCalibrationRelTimeCalc timecalc;
1154 if (fRelTimes)
1155 {
1156 tlist.AddToList(&filltme);
1157 tlist.AddToList(&timecalc);
1158 }
1159
1160
1161 // Create and setup the eventloop
1162 MEvtLoop evtloop(fName);
1163 evtloop.SetParList(&plist);
1164 evtloop.SetDisplay(fDisplay);
1165 evtloop.SetLogStream(fLog);
1166 if (fEnv)
1167 evtloop.ReadEnv(*fEnv);
1168
1169 // Execute first analysis
1170 if (!evtloop.Eventloop())
1171 {
1172 *fLog << err << GetDescriptor() << ": Failed." << endl;
1173 return kFALSE;
1174 }
1175
1176 tlist.PrintStatistics();
1177
1178 //
1179 // The next lines are necessary in order to avoid that
1180 // the last entry drawn by MFillH gets deleted again from
1181 // the display. No idea where this comes from...
1182 //
1183 /*
1184 if (fDisplay)
1185 {
1186 if (IsUsePINDiode())
1187 {
1188 MHCalibrationChargePINDiode *pin =
1189 (MHCalibrationChargePINDiode*)plist.FindObject("MHCalibrationChargePINDiode");
1190 pin->DrawClone(Form("nonew %s",drawoption.Data()));
1191 }
1192 else if (IsUseBlindPixel())
1193 {
1194 MHCalibrationChargeBlindCam *cam =
1195 (MHCalibrationChargeBlindCam*)plist.FindObject("MHCalibrationChargeBlindCam");
1196 cam->DrawClone(Form("nonew %s",drawoption.Data()));
1197 }
1198 else if (fRelTimes)
1199 {
1200 MHCalibrationRelTimeCam *cam =
1201 (MHCalibrationRelTimeCam*)plist.FindObject("MHCalibrationRelTimeCam");
1202 cam->DrawClone(Form("nonew %s",drawoption.Data()));
1203 }
1204 else
1205 {
1206 MHCalibrationChargeCam *cam =
1207 (MHCalibrationChargeCam*)plist.FindObject("MHCalibrationChargeCam");
1208 cam->DrawClone(Form("nonew %s",drawoption.Data()));
1209 }
1210 }
1211 */
1212
1213 DisplayResult(plist);
1214
1215 if (!WriteResult())
1216 return kFALSE;
1217
1218 *fLog << inf << GetDescriptor() << ": Done." << endl;
1219
1220 return kTRUE;
1221}
1222
1223// --------------------------------------------------------------------------
1224//
1225// Read the following containers from GetOutputFile()
1226// - MCalibrationChargeCam
1227// - MCalibrationQECam
1228// - MBadPixelsCam
1229//
1230Bool_t MJCalibration::ReadCalibrationCam()
1231{
1232 const TString fname = GetOutputFile();
1233
1234 if (gSystem->AccessPathName(fname, kFileExists))
1235 {
1236 *fLog << err << "Input file " << fname << " doesn't exist." << endl;
1237 return kFALSE;
1238 }
1239
1240 *fLog << inf << "Reading from file: " << fname << endl;
1241
1242 TFile file(fname, "READ");
1243 if (fCalibrationCam.Read()<=0)
1244 {
1245 *fLog << err << "Unable to read MCalibrationChargeCam from " << fname << endl;
1246 return kFALSE;
1247 }
1248
1249 if (fQECam.Read()<=0)
1250 {
1251 *fLog << err << "Unable to read MCalibrationQECam from " << fname << endl;
1252 return kFALSE;
1253 }
1254
1255
1256 if (file.FindKey("MCalibrationRelTimeCam"))
1257 if (fRelTimeCam.Read()<=0)
1258 {
1259 *fLog << err << "Unable to read MCalibrationRelTimeCam from " << fname << endl;
1260 return kFALSE;
1261 }
1262
1263 if (file.FindKey("MBadPixelsCam"))
1264 {
1265 MBadPixelsCam bad;
1266 if (bad.Read()<=0)
1267 {
1268 *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
1269 return kFALSE;
1270 }
1271 fBadPixels.Merge(bad);
1272 }
1273
1274 if (fDisplay /*&& !fDisplay->GetCanvas("Pedestals")*/) // FIXME!
1275 fDisplay->Read();
1276
1277 return kTRUE;
1278}
1279
1280
1281// --------------------------------------------------------------------------
1282//
1283// Set the path for output files, written by WriteResult()
1284//
1285void MJCalibration::SetOutputPath(const char *path)
1286{
1287 fOutputPath = path;
1288 if (fOutputPath.EndsWith("/"))
1289 fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
1290}
1291
1292// --------------------------------------------------------------------------
1293//
1294// Set the useage of the Blind Pixel device
1295//
1296void MJCalibration::SetUseBlindPixel(const Bool_t b)
1297{
1298 b ? SETBIT(fDevices,kUseBlindPixel) : CLRBIT(fDevices,kUseBlindPixel);
1299}
1300
1301// --------------------------------------------------------------------------
1302//
1303// Set the useage of the PIN Diode device
1304//
1305void MJCalibration::SetUsePINDiode(const Bool_t b)
1306{
1307 b ? SETBIT(fDevices,kUsePINDiode) : CLRBIT(fDevices,kUsePINDiode);
1308}
1309
1310// --------------------------------------------------------------------------
1311//
1312// Write the result into the output file GetOutputFile(), if fOutputPath exists.
1313//
1314// The following containers are written:
1315// - MStatusDisplay
1316// - MCalibrationChargeCam
1317// - MCalibrationChargeBlindPix
1318// - MCalibrationQECam
1319// - MBadPixelsCam
1320//
1321Bool_t MJCalibration::WriteResult()
1322{
1323 if (fOutputPath.IsNull())
1324 return kTRUE;
1325
1326 const TString oname(GetOutputFile());
1327
1328 *fLog << inf << "Writing to file: " << oname << endl;
1329
1330 TFile file(oname, "UPDATE");
1331
1332 if (fDisplay && fDisplay->Write()<=0)
1333 {
1334 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
1335 return kFALSE;
1336 }
1337
1338 if (fCalibrationCam.Write()<=0)
1339 {
1340 *fLog << err << "Unable to write MCalibrationChargeCam to " << oname << endl;
1341 return kFALSE;
1342 }
1343
1344 if (fCalibrationBlindCam.Write()<=0)
1345 {
1346 *fLog << err << "Unable to write MCalibrationChargeBlindCam to " << oname << endl;
1347 return kFALSE;
1348 }
1349
1350 if (fCalibrationPINDiode.Write()<=0)
1351 {
1352 *fLog << err << "Unable to write MCalibrationChargePINDiode to " << oname << endl;
1353 return kFALSE;
1354 }
1355
1356 if (fQECam.Write()<=0)
1357 {
1358 *fLog << err << "Unable to write MCalibrationQECam to " << oname << endl;
1359 return kFALSE;
1360 }
1361
1362 if (fRelTimes)
1363 if (fRelTimeCam.Write()<=0)
1364 {
1365 *fLog << err << "Unable to write MCalibrationRelTimeCam to " << oname << endl;
1366 return kFALSE;
1367 }
1368
1369 if (fBadPixels.Write()<=0)
1370 {
1371 *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
1372 return kFALSE;
1373 }
1374
1375 return kTRUE;
1376
1377}
1378
Note: See TracBrowser for help on using the repository browser.