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

Last change on this file since 6771 was 6771, checked in by gaug, 20 years ago
*** empty log message ***
File size: 70.1 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): 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 MExtractTimeHighestIntegral
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// The absolute light calibration devices Blind Pixel and PIN Diode can be switched on
54// and off with the commands:
55//
56// - SetUseBlindPixel(Bool_t )
57// - SetUsePINDiode(Bool_t )
58//
59// See also: MHCalibrationChargePix, MHCalibrationChargeCam, MHGausEvents
60// MHCalibrationChargeBlindPix, MHCalibrationChargePINDiode
61// MCalibrationChargePix, MCalibrationChargeCam, MCalibrationChargeCalc
62// MCalibrationBlindPix, MCalibrationChargePINDiode,
63// MCalibrationQECam, MBadPixelsPix, MBadPixelsCam
64//
65// If the flag RelTimeCalibration() is set, a calibration of the relative arrival
66// times is also performed. The following containers (rectangular) and
67// tasks (ellipses) are called to produce an MCalibrationRelTimeCam used by
68// MCalibrateTime to correct timing offset between pixels: (MCalibrateTime is not
69// called from this class)
70//
71//Begin_Html
72/*
73<img src="images/RelTimeClasses.gif">
74*/
75//End_Html
76//
77// Different arrival time extractors can be set directly with the command
78// SetTimeExtractor(MExtractor *)
79//
80// Resource file entries are case sensitive!
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 <TF1.h>
91#include <TStyle.h>
92#include <TCanvas.h>
93#include <TSystem.h>
94#include <TLine.h>
95#include <TLatex.h>
96#include <TLegend.h>
97#include <TRegexp.h>
98#include <TPaveText.h>
99#include <TPaveStats.h>
100#include <TEnv.h>
101
102#include "MLog.h"
103#include "MLogManip.h"
104
105#include "MRunIter.h"
106#include "MSequence.h"
107#include "MParList.h"
108#include "MTaskList.h"
109#include "MEvtLoop.h"
110
111#include "MHCamera.h"
112#include "MGeomCam.h"
113
114#include "MPedestalCam.h"
115#include "MCalibColorSteer.h"
116
117#include "MCalibrationIntensityChargeCam.h"
118#include "MCalibrationIntensityBlindCam.h"
119#include "MCalibrationIntensityRelTimeCam.h"
120#include "MCalibrationIntensityQECam.h"
121
122#include "MCalibrationPatternDecode.h"
123#include "MCalibrationCam.h"
124#include "MCalibrationHiLoCam.h"
125#include "MCalibrationHiLoPix.h"
126#include "MCalibrationQECam.h"
127#include "MCalibrationQEPix.h"
128#include "MCalibrationChargeCam.h"
129#include "MCalibrationChargePix.h"
130#include "MCalibrationChargePINDiode.h"
131#include "MCalibrationBlindPix.h"
132#include "MCalibrationBlindCam.h"
133#include "MCalibrationBlindCamOneOldStyle.h"
134#include "MCalibrationBlindCamTwoNewStyle.h"
135#include "MCalibrationBlindCamThreeNewStyle.h"
136#include "MCalibrationChargeCalc.h"
137#include "MCalibColorSet.h"
138#include "MCalibrationRelTimeCam.h"
139#include "MCalibrationRelTimeCalc.h"
140
141#include "MHGausEvents.h"
142#include "MHCalibrationCam.h"
143#include "MHCalibrationChargeCam.h"
144#include "MHCalibrationChargeBlindCam.h"
145#include "MHCalibrationChargePINDiode.h"
146#include "MHCalibrationRelTimeCam.h"
147#include "MHCalibrationPix.h"
148
149#include "MReadMarsFile.h"
150#include "MPedCalcPedRun.h"
151#include "MRawFileRead.h"
152#include "MGeomApply.h"
153#include "MTaskEnv.h"
154#include "MBadPixelsMerge.h"
155#include "MBadPixelsCam.h"
156#include "MExtractTime.h"
157#include "MExtractor.h"
158#include "MExtractPINDiode.h"
159#include "MExtractBlindPixel.h"
160#include "MExtractSlidingWindow.h"
161#include "MExtractTimeHighestIntegral.h"
162#include "MFCosmics.h"
163#include "MContinue.h"
164#include "MFillH.h"
165
166#include "MArrivalTimeCam.h"
167
168#include "MStatusDisplay.h"
169
170ClassImp(MJCalibration);
171
172using namespace std;
173
174const Int_t MJCalibration::gkIFAEBoxInaugurationRun = 20113;
175const Int_t MJCalibration::gkSecondBlindPixelInstallation = 31693;
176const Int_t MJCalibration::gkSpecialPixelsContInstallation = 34057;
177const Int_t MJCalibration::gkThirdBlindPixelInstallation = 43308;
178const TString MJCalibration::fgReferenceFile = "mjobs/calibrationref.rc";
179const TString MJCalibration::fgHiLoCalibFile = "mjobs/hilocalib_df6.root";
180// --------------------------------------------------------------------------
181//
182// Default constructor.
183//
184// - Sets fRuns to 0, fExtractor to NULL, fTimeExtractor to NULL, fColor to kNONE,
185// fDisplay to kNormalDisplay, kRelTimes to kFALSE, kataCheck to kFALSE, kDebug to kFALSE,
186// kIntensity to kFALSE
187// - SetUseBlindPixel()
188// - SetUsePINDiode()
189//
190MJCalibration::MJCalibration(const char *name, const char *title)
191 : fExtractor(NULL), fTimeExtractor(NULL),
192 fColor(MCalibrationCam::kNONE), fDisplayType(kDataCheckDisplay),
193 fGeometry("MGeomCamMagic")
194{
195
196 fName = name ? name : "MJCalibration";
197 fTitle = title ? title : "Tool to create the calibration constants for one calibration run";
198
199 SetUseBlindPixel();
200 SetUsePINDiode();
201
202 SetRelTimeCalibration();
203 SetDebug(kFALSE);
204 SetIntensity(kFALSE);
205
206 SetReferenceFile();
207 SetHiLoCalibFile();
208
209 fConvFADC2PheMin = 0.;
210 fConvFADC2PheMax = 1.5;
211 fConvFADC2PhotMin = 0.;
212 fConvFADC2PhotMax = 10.;
213 fQEMin = 0.;
214 fQEMax = 0.3;
215 fArrivalTimeMin = 1.;
216 fArrivalTimeMax = 10.;
217 fTimeOffsetMin = -3.;
218 fTimeOffsetMax = 3.;
219 fTimeResolutionMin = 0.;
220 fTimeResolutionMax = 1.;
221
222 fRefConvFADC2PheInner = 0.14;
223 fRefConvFADC2PheOuter = 0.4;
224 fRefConvFADC2PhotInner = 0.8;
225 fRefConvFADC2PhotOuter = 3.8;
226 fRefQEInner = 0.18;
227 fRefQEOuter = 0.12;
228 fRefArrivalTimeInner = 4.5;
229 fRefArrivalTimeOuter = 5.0;
230 fRefArrivalTimeRmsInner = 0.5;
231 fRefArrivalTimeRmsOuter = 0.5;
232 fRefTimeOffsetInner = -0.23;
233 fRefTimeOffsetOuter = 0.39;
234 fRefTimeResolutionInner = 0.153;
235 fRefTimeResolutionOuter = 0.128;
236
237}
238
239void MJCalibration::DrawTab(MParList &plist, const char *cont, const char *name, Option_t *opt)
240{
241 TObject *obj = plist.FindObject(cont);
242 if (!obj)
243 return;
244
245 fDisplay->AddTab(name);
246 obj->DrawClone(opt);
247}
248
249// --------------------------------------------------------------------------
250//
251// Display the results in MStatusDisplay:
252//
253// - Add "Calibration" to the MStatusDisplay title
254// - Retrieve the MGeomCam from MParList
255// - Initialize the following MHCamera's:
256// 1) MCalibrationPix::GetMean()
257// 2) MCalibrationPix::Sigma()
258// 3) MCalibrationChargePix::GetRSigma()
259// 4) MCalibrationChargePix::GetRSigmaPerCharge()
260// 5) MCalibrationChargePix::GetPheFFactorMethod()
261// 6) MCalibrationChargePix::GetMeanConvFADC2Phe()
262// 7) MCalibrationChargePix::GetMeanFFactorFADC2Phot()
263// 8) MCalibrationQEPix::GetQECascadesFFactor()
264// 9) MCalibrationQEPix::GetQECascadesBlindPixel()
265// 10) MCalibrationQEPix::GetQECascadesPINDiode()
266// 11) MCalibrationQEPix::GetQECascadesCombined()
267// 12) MCalibrationQEPix::IsAverageQEFFactorAvailable()
268// 13) MCalibrationQEPix::IsAverageQEBlindPixelAvailable()
269// 14) MCalibrationQEPix::IsAverageQEPINDiodeAvailable()
270// 15) MCalibrationQEPix::IsAverageQECombinedAvailable()
271// 16) MCalibrationChargePix::IsHiGainSaturation()
272// 17) MCalibrationPix::GetHiLoMeansDivided()
273// 18) MCalibrationPix::GetHiLoSigmasDivided()
274// 19) MCalibrationChargePix::GetHiGainPickup()
275// 20) MCalibrationChargePix::GetLoGainPickup()
276// 21) MCalibrationChargePix::GetHiGainBlackout()
277// 22) MCalibrationChargePix::GetLoGainBlackout()
278// 23) MCalibrationPix::IsExcluded()
279// 24) MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableRun)
280// 25) MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnreliableRun)
281// 26) MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
282// 27) MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
283// 28) MCalibrationChargePix::GetAbsTimeMean()
284// 29) MCalibrationChargePix::GetAbsTimeRms()
285//
286// If the flag SetFullDisplay() is set, all MHCameras will be displayed.
287// if the flag SetDataCheckDisplay() is set, only the most important ones are displayed
288// and otherwise, (default: SetNormalDisplay()), a good selection of plots is given
289//
290void MJCalibration::DisplayResult(MParList &plist)
291{
292 if (!fDisplay)
293 return;
294
295 TString drawoption = "nonew ";
296 if (fDisplayType == kDataCheckDisplay)
297 drawoption += "datacheck";
298 if (fDisplayType == kFullDisplay)
299 drawoption += "all";
300
301 if (IsUsePINDiode())
302 DrawTab(plist, "MHCalibrationChargePINDiode", "PINDiode", drawoption);
303 if (IsUseBlindPixel())
304 DrawTab(plist, "MHCalibrationChargeBlindCam", "BlindPix", drawoption);
305 if (IsRelTimes())
306 DrawTab(plist, "MHCalibrationRelTimeCam", "Time", drawoption);
307 DrawTab(plist, "MHCalibrationChargeCam", "Charge", drawoption);
308
309 //
310 // Update display
311 //
312 TString title = fDisplay->GetTitle();
313 title += "-- Calibration ";
314 title += fSequence.IsValid() ? Form("calib%08d", fSequence.GetSequence()) : (const char*)fRuns->GetRunsAsString();
315 title += " --";
316 fDisplay->SetTitle(title);
317
318 //
319 // Get container from list
320 //
321 MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
322
323 // Create histograms to display
324 MHCamera disp1 (geomcam, "Charge", "Fitted Mean Signal (Charges)");
325 MHCamera disp2 (geomcam, "SigmaCharge", "Sigma of Fitted Signal");
326 MHCamera disp3 (geomcam, "RSigma", "Reduced Sigmas");
327 MHCamera disp4 (geomcam, "RSigmaPerCharge", "Reduced Sigma per Charge");
328 MHCamera disp5 (geomcam, "NumPhes", "Number Photo-electrons");
329 MHCamera disp6 (geomcam, "ConvFADC2Phes", "Conversion Factor to Phes");
330 MHCamera disp7 (geomcam, "TotalFFactor", "Total F-Factor(F-Factor Method)");
331 MHCamera disp8 (geomcam, "CascadesQEFFactor", "Cascades QE (F-Factor Method)");
332 MHCamera disp9 (geomcam, "CascadesQEBlindPix","Cascades QE (Blind Pixel Method)");
333 MHCamera disp10(geomcam, "CascadesQEPINDiode","Cascades QE (PIN Diode Method)");
334 MHCamera disp11(geomcam, "CascadesQECombined","Cascades QE (Combined Method)");
335 MHCamera disp12(geomcam, "FFactorValid", "Pixels with valid F-Factor calibration");
336 MHCamera disp13(geomcam, "BlindPixelValid", "Pixels with valid BlindPixel calibration");
337 MHCamera disp14(geomcam, "PINdiodeValid", "Pixels with valid PINDiode calibration");
338 MHCamera disp15(geomcam, "CombinedValid", "Pixels with valid Combined calibration");
339 MHCamera disp16(geomcam, "Saturation", "Pixels with saturated Hi Gain");
340 MHCamera disp17(geomcam, "ConversionMeans", "Conversion HiGain.vs.LoGain Means");
341 MHCamera disp18(geomcam, "ConversionSigmas", "Conversion HiGain.vs.LoGain Sigmas");
342 MHCamera disp19(geomcam, "HiGainPickup", "Number Pickup events Hi Gain");
343 MHCamera disp20(geomcam, "LoGainPickup", "Number Pickup events Lo Gain");
344 MHCamera disp21(geomcam, "HiGainBlackout", "Number Blackout events Hi Gain");
345 MHCamera disp22(geomcam, "LoGainBlackout", "Number Blackout events Lo Gain");
346 MHCamera disp23(geomcam, "Excluded", "Pixels previously excluded");
347 MHCamera disp24(geomcam, "UnSuitable", "Pixels not suited for further analysis");
348 MHCamera disp25(geomcam, "UnReliable", "Pixels suitable, but not reliable for further analysis");
349 MHCamera disp26(geomcam, "HiGainOscillating", "Oscillating Pixels High Gain");
350 MHCamera disp27(geomcam, "LoGainOscillating", "Oscillating Pixels Low Gain");
351 MHCamera disp28(geomcam, "AbsTimeMean", "Abs. Arrival Times");
352 MHCamera disp29(geomcam, "AbsTimeRms", "RMS of Arrival Times");
353 MHCamera disp30(geomcam, "MeanTime", "Mean Rel. Arrival Times");
354 MHCamera disp31(geomcam, "SigmaTime", "Sigma Rel. Arrival Times");
355 MHCamera disp32(geomcam, "TimeProb", "Probability of Time Fit");
356 MHCamera disp33(geomcam, "TimeNotFitValid", "Pixels with not valid fit results");
357 MHCamera disp34(geomcam, "TimeOscillating", "Oscillating Pixels");
358 MHCamera disp35(geomcam, "TotalConv", "Conversion Factor to photons");
359 MHCamera disp36(geomcam, "RMSperMean", "Charge histogram RMS per Mean");
360
361 MCalibrationChargeCam *cam = NULL;
362 MCalibrationQECam *qecam = NULL;
363 MCalibrationRelTimeCam *relcam = NULL;
364 MBadPixelsCam *badcam = NULL;
365
366 if (IsIntensity())
367 {
368 cam = (MCalibrationChargeCam*) fIntensCalibCam.GetCam();
369 qecam = (MCalibrationQECam*) fIntensQECam.GetCam();
370 relcam = (MCalibrationRelTimeCam*)fIntensRelTimeCam.GetCam();
371 badcam = (MBadPixelsCam*) fIntensBadCam.GetCam();
372 }
373 else
374 {
375 cam = &fCalibrationCam;
376 qecam = &fQECam;
377 relcam = &fRelTimeCam;
378 badcam = &fBadPixels;
379 }
380
381 // Fitted charge means and sigmas
382 disp1.SetCamContent(*cam, 0);
383 disp1.SetCamError( *cam, 1);
384 disp2.SetCamContent(*cam, 2);
385 disp2.SetCamError( *cam, 3);
386
387 // Reduced Sigmas and reduced sigmas per charge
388 disp3.SetCamContent(*cam, 5);
389 disp3.SetCamError( *cam, 6);
390 disp4.SetCamContent(*cam, 7);
391 disp4.SetCamError( *cam, 8);
392
393 // F-Factor Method
394 disp5.SetCamContent(*cam, 9);
395 disp5.SetCamError( *cam, 10);
396 disp6.SetCamContent(*cam, 11);
397 disp6.SetCamError( *cam, 12);
398 disp7.SetCamContent(*cam, 13);
399 disp7.SetCamError( *cam, 14);
400
401 // Quantum Efficiencies
402 disp8.SetCamContent (*qecam, 0 );
403 disp8.SetCamError (*qecam, 1 );
404 disp9.SetCamContent (*qecam, 2 );
405 disp9.SetCamError (*qecam, 3 );
406 disp10.SetCamContent(*qecam, 4 );
407 disp10.SetCamError (*qecam, 5 );
408 disp11.SetCamContent(*qecam, 6 );
409 disp11.SetCamError (*qecam, 7 );
410
411 // Valid flags
412 disp12.SetCamContent(*qecam, 8 );
413 disp13.SetCamContent(*qecam, 9 );
414 disp14.SetCamContent(*qecam, 10);
415 disp15.SetCamContent(*qecam, 11);
416
417 // Conversion Hi-Lo
418 disp16.SetCamContent(*cam, 25);
419 disp17.SetCamContent(*cam, 16);
420 disp17.SetCamError (*cam, 17);
421 disp18.SetCamContent(*cam, 18);
422 disp18.SetCamError (*cam, 19);
423
424 // Pickup and Blackout
425 disp19.SetCamContent(*cam, 21);
426 disp20.SetCamContent(*cam, 22);
427 disp21.SetCamContent(*cam, 23);
428 disp22.SetCamContent(*cam, 24);
429
430 // Pixels with defects
431 disp23.SetCamContent(*cam, 20);
432 disp24.SetCamContent(*badcam, 6);
433 disp25.SetCamContent(*badcam, 7);
434
435 // Oscillations
436 disp26.SetCamContent(*badcam, 10);
437 disp27.SetCamContent(*badcam, 11);
438
439 // Arrival Times
440 disp28.SetCamContent(*cam, 26);
441 disp28.SetCamError( *cam, 27);
442 disp29.SetCamContent(*cam, 27);
443
444 // RMS and Mean
445 disp36.SetCamContent(*cam,32);
446
447 disp1.SetYTitle("Q [FADC cnts]");
448 disp2.SetYTitle("\\sigma_{Q} [FADC cnts]");
449
450 disp3.SetYTitle("\\sqrt{\\sigma^{2}_{Q} - RMS^{2}_{Ped}} [FADC cnts]");
451 disp4.SetYTitle("Red.Sigma/<Q> [1]");
452
453 disp5.SetYTitle("Photo-electons [1]");
454 disp6.SetYTitle("Conv.Factor [PhE/FADC cnts]");
455 disp7.SetYTitle("Total F-Factor [1]");
456
457 disp8.SetYTitle("QE [1]");
458 disp9.SetYTitle("QE [1]");
459 disp10.SetYTitle("QE [1]");
460 disp11.SetYTitle("QE [1]");
461
462 disp12.SetYTitle("[1]");
463 disp13.SetYTitle("[1]");
464 disp14.SetYTitle("[1]");
465 disp15.SetYTitle("[1]");
466 disp16.SetYTitle("[1]");
467
468 disp17.SetYTitle("<Q>(High)/<Q>(Low) [1]");
469 disp18.SetYTitle("\\sigma_{Q}(High)/\\sigma_{Q}(Low) [1]");
470
471 disp19.SetYTitle("[1]");
472 disp20.SetYTitle("[1]");
473 disp21.SetYTitle("[1]");
474 disp22.SetYTitle("[1]");
475 // disp23.SetYTitle("[1]");
476 // disp24.SetYTitle("[1]");
477 // disp25.SetYTitle("[1]");
478 disp26.SetYTitle("[1]");
479 disp27.SetYTitle("[1]");
480
481 disp28.SetYTitle("Mean Abs. Time [FADC sl.]");
482 disp29.SetYTitle("RMS Abs. Time [FADC sl.]");
483
484 disp35.SetYTitle("Conv.Factor [Ph/FADC cnts]");
485
486 disp36.SetYTitle("Charge RMS/<Q> [1]");
487
488 for (UInt_t i=0;i<geomcam.GetNumPixels();i++)
489 {
490
491 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*cam) [i];
492 MCalibrationQEPix &qe = (MCalibrationQEPix&) (*qecam)[i];
493
494 if (!pix.IsFFactorMethodValid())
495 continue;
496
497 const Float_t convphe = pix.GetMeanConvFADC2Phe();
498 const Float_t quaeff = qe.GetQECascadesFFactor(0.);
499
500 disp35.Fill(i,convphe/quaeff);
501 disp35.SetUsed(i);
502 }
503
504
505 if (IsRelTimes())
506 {
507 disp30.SetCamContent(*relcam,0);
508 disp30.SetCamError( *relcam,1);
509 disp31.SetCamContent(*relcam,2);
510 disp31.SetCamError( *relcam,3);
511 disp32.SetCamContent(*relcam,4);
512 disp33.SetCamContent(fBadPixels,20);
513 disp34.SetCamContent(fBadPixels,21);
514
515 disp30.SetYTitle("Time Offset [FADC units]");
516 disp31.SetYTitle("Timing resolution [FADC units]");
517 disp32.SetYTitle("P_{Time} [1]");
518 disp33.SetYTitle("[1]");
519 disp34.SetYTitle("[1]");
520 }
521
522 if (fDisplayType == kDataCheckDisplay)
523 {
524
525 TCanvas &c1 = fDisplay->AddTab("FitCharge");
526 c1.Divide(3, 3);
527
528 //
529 // MEAN CHARGES
530 //
531
532 c1.cd(1);
533 gPad->SetBorderMode(0);
534 gPad->SetTicks();
535 MHCamera *obj1=(MHCamera*)disp1.DrawCopy("hist");
536 //
537 // for the datacheck, fix the ranges!!
538 //
539 // obj1->SetMinimum(fChargeMin);
540 // obj1->SetMaximum(fChargeMax);
541 //
542 // Set the datacheck sizes:
543 //
544 FixDataCheckHist((TH1D*)obj1);
545 obj1->SetStats(kFALSE);
546 //
547 // set reference lines
548 //
549 // DisplayReferenceLines(obj1,0);
550
551 c1.cd(4);
552 gPad->SetBorderMode(0);
553 obj1->SetPrettyPalette();
554 obj1->Draw();
555
556 c1.cd(7);
557 gPad->SetBorderMode(0);
558 gPad->SetTicks();
559 TH1D *obj2 = (TH1D*)obj1->Projection(obj1->GetName());
560 obj2->Draw();
561 obj2->SetBit(kCanDelete);
562 obj2->Fit("gaus","Q");
563 TF1 *fun2 = obj2->GetFunction("gaus");
564 fun2->SetLineColor(kYellow);
565 gPad->Modified();
566 gPad->Update();
567 TPaveStats *st = (TPaveStats*)obj2->GetListOfFunctions()->FindObject("stats");
568 st->SetY1NDC(0.55);
569 st->SetY2NDC(0.89);
570 st->SetX1NDC(0.65);
571 st->SetX2NDC(0.99);
572 gPad->Modified();
573 gPad->Update();
574 //
575 // Set the datacheck sizes:
576 //
577 FixDataCheckHist(obj2);
578 obj2->SetStats(1);
579
580 //
581 // Display the outliers as dead and noisy pixels
582 //
583 DisplayOutliers(obj2,"low-ampl.","high-ampl.");
584 TLatex flattex;
585 flattex.SetTextSize(0.07);
586 const Double_t minl = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst());
587 const Double_t maxl = obj2->GetBinCenter(obj2->GetXaxis()->GetLast());
588 flattex.DrawLatex(minl+0.015*(maxl-minl),obj2->GetBinContent(obj2->GetMaximumBin())/1.35,
589 Form("Flatfield precision: %4.2f%%",
590 fun2->GetParameter(2)/fun2->GetParameter(1)*100.));
591
592 //
593 // RMS per Charge
594 //
595
596 c1.cd(2);
597 gPad->SetBorderMode(0);
598 gPad->SetTicks();
599 MHCamera *obj3=(MHCamera*)disp36.DrawCopy("hist");
600 //
601 // for the datacheck, fix the ranges!!
602 //
603 // obj3->SetMinimum(0.);
604 // obj3->SetMaximum(fChargeMax);
605 //
606 // Set the datacheck sizes:
607 //
608 FixDataCheckHist((TH1D*)obj3);
609 obj3->SetStats(kFALSE);
610 //
611 // set reference lines
612 //
613 // DisplayReferenceLines(obj3,0);
614
615 c1.cd(5);
616 gPad->SetBorderMode(0);
617 obj3->SetPrettyPalette();
618 obj3->Draw();
619
620 c1.cd(8);
621 gPad->SetBorderMode(0);
622 if (geomcam.InheritsFrom("MGeomCamMagic"))
623 DisplayDoubleProject(&disp36, "dead", "noisy");
624
625 //
626 // PHOTO ELECTRONS
627 //
628
629 c1.cd(3);
630 gPad->SetBorderMode(0);
631 gPad->SetTicks();
632 MHCamera *obj4=(MHCamera*)disp5.DrawCopy("hist");
633 //
634 // for the datacheck, fix the ranges!!
635 //
636 // obj3->SetMinimum(fChargeMin);
637 // obj3->SetMaximum(fChargeMax);
638 //
639 // Set the datacheck sizes:
640 //
641 FixDataCheckHist((TH1D*)obj4);
642 obj4->SetStats(kFALSE);
643 //
644 // set reference lines
645 //
646 // DisplayReferenceLines(obj3,0);
647
648 c1.cd(6);
649 gPad->SetBorderMode(0);
650 obj4->SetPrettyPalette();
651 obj4->Draw();
652
653 c1.cd(9);
654 gPad->SetBorderMode(0);
655 if (geomcam.InheritsFrom("MGeomCamMagic"))
656 DisplayDoubleProject(&disp5, "dead", "noisy");
657
658 //
659 // CONVERSION FACTORS
660 //
661 TCanvas &c2 = fDisplay->AddTab("Conversion");
662 c2.Divide(3,3);
663
664 c2.cd(1);
665 gPad->SetBorderMode(0);
666 gPad->SetTicks();
667 MHCamera *obj5=(MHCamera*)disp6.DrawCopy("hist");
668 //
669 // for the datacheck, fix the ranges!!
670 //
671 obj5->SetMinimum(fConvFADC2PheMin);
672 obj5->SetMaximum(fConvFADC2PheMax);
673 //
674 // Set the datacheck sizes:
675 //
676 FixDataCheckHist((TH1D*)obj5);
677 obj5->SetStats(kFALSE);
678 //
679 // set reference lines
680 //
681 DisplayReferenceLines(obj5,2);
682
683 c2.cd(4);
684 gPad->SetBorderMode(0);
685 obj5->SetPrettyPalette();
686 obj5->Draw();
687
688 c2.cd(7);
689 gPad->SetBorderMode(0);
690 if (geomcam.InheritsFrom("MGeomCamMagic"))
691 DisplayDoubleProject(&disp6, "noisy", "dead");
692
693 //
694 // QUANTUM EFFICIENCY
695 //
696 c2.cd(2);
697 gPad->SetBorderMode(0);
698 gPad->SetTicks();
699 MHCamera *obj6=(MHCamera*)disp8.DrawCopy("hist");
700 //
701 // for the datacheck, fix the ranges!!
702 //
703 obj6->SetMinimum(fQEMin);
704 obj6->SetMaximum(fQEMax);
705 //
706 // Set the datacheck sizes:
707 //
708 FixDataCheckHist((TH1D*)obj6);
709 obj6->SetStats(kFALSE);
710 //
711 // set reference lines
712 //
713 DisplayReferenceLines(obj6,0);
714
715 c2.cd(5);
716 gPad->SetBorderMode(0);
717 obj6->SetPrettyPalette();
718 obj6->Draw();
719
720 c2.cd(8);
721 gPad->SetBorderMode(0);
722 if (geomcam.InheritsFrom("MGeomCamMagic"))
723 DisplayDoubleProject(&disp8, "noisy", "dead");
724
725 //
726 // CONVERSION FADC TO PHOTONS
727 //
728
729 c2.cd(3);
730 gPad->SetBorderMode(0);
731 gPad->SetTicks();
732 MHCamera *obj7=(MHCamera*)disp35.DrawCopy("hist");
733 //
734 // for the datacheck, fix the ranges!!
735 //
736 obj7->SetMinimum(fConvFADC2PhotMin);
737 obj7->SetMaximum(fConvFADC2PhotMax);
738 //
739 // Set the datacheck sizes:
740 //
741 FixDataCheckHist((TH1D*)obj7);
742 obj7->SetStats(kFALSE);
743 //
744 // set reference lines
745 //
746 DisplayReferenceLines(obj7,1);
747
748 c2.cd(6);
749 gPad->SetBorderMode(0);
750 obj7->SetPrettyPalette();
751 obj7->Draw();
752 c2.cd(9);
753 gPad->SetBorderMode(0);
754 if (geomcam.InheritsFrom("MGeomCamMagic"))
755 DisplayDoubleProject(&disp35, "noisy", "dead");
756
757 //
758 // ARRIVAL TIMES
759 //
760 TCanvas &c3 = fDisplay->AddTab("AbsTimes");
761 c3.Divide(2,3);
762
763 c3.cd(1);
764 gPad->SetBorderMode(0);
765 gPad->SetTicks();
766 MHCamera *obj10=(MHCamera*)disp28.DrawCopy("hist");
767 //
768 // for the datacheck, fix the ranges!!
769 //
770 obj10->SetMinimum(fArrivalTimeMin);
771 obj10->SetMaximum(fArrivalTimeMax);
772 //
773 // Set the datacheck sizes:
774 //
775 FixDataCheckHist((TH1D*)obj10);
776 obj10->SetStats(kFALSE);
777 //
778 // set reference lines
779 //
780 DisplayReferenceLines(obj10,3);
781
782 c3.cd(3);
783 gPad->SetBorderMode(0);
784 obj10->SetPrettyPalette();
785 obj10->Draw();
786
787 c3.cd(5);
788 gPad->SetBorderMode(0);
789 if (geomcam.InheritsFrom("MGeomCamMagic"))
790 DisplayDoubleProject(&disp28, "early", "late");
791
792 //
793 // ARRIVAL TIMES JITTER
794 //
795 c3.cd(2);
796 gPad->SetBorderMode(0);
797 gPad->SetTicks();
798 MHCamera *obj11=(MHCamera*)disp29.DrawCopy("hist");
799 //
800 // for the datacheck, fix the ranges!!
801 //
802 // obj11->SetMinimum(fArrivalTimeMin);
803 // obj11->SetMaximum(fArrivalTimeMax);
804 //
805 // Set the datacheck sizes:
806 //
807 FixDataCheckHist((TH1D*)obj11);
808 obj11->SetStats(kFALSE);
809 //
810 // set reference lines
811 //
812 DisplayReferenceLines(obj11,4);
813
814 c3.cd(4);
815 gPad->SetBorderMode(0);
816 obj11->SetPrettyPalette();
817 obj11->Draw();
818
819 c3.cd(6);
820 gPad->SetBorderMode(0);
821 if (geomcam.InheritsFrom("MGeomCamMagic"))
822 DisplayDoubleProject(&disp29, "", "jittering");
823
824 //
825 // UNSUITABLE PIXELS
826 //
827 TCanvas &c4 = fDisplay->AddTab("Defect");
828 c4.Divide(2,2);
829
830 c4.cd(1);
831 gPad->SetBorderMode(0);
832 gPad->SetTicks();
833 MHCamera *obj8=(MHCamera*)disp24.DrawCopy("hist");
834 //
835 // for the datacheck, fix the ranges!!
836 //
837 const Double_t max = 11.;
838 obj8->SetMinimum(0.);
839 obj8->SetMaximum(11.);
840 //
841 // Set the datacheck sizes:
842 //
843 FixDataCheckHist((TH1D*)obj8);
844 obj8->SetStats(kFALSE);
845
846 gStyle->SetPalette(1);
847 const Int_t numcol = gStyle->GetNumberOfColors()-3;
848
849 TPaveText *pave = new TPaveText(0.0,0.0,0.99,0.99);
850 pave->SetBit(kCanDelete);
851 pave->ConvertNDCtoPad();
852 pave->SetTextSize(0.05);
853 pave->AddText(" ");
854 TText *t1 = pave->AddText(Form("Signal smaller 3 Pedestal RMS: %3i pixels",
855 CountBadPixels(&disp24,1)));
856 t1->SetTextColor(gStyle->GetColorPalette(Int_t(1./max*numcol + 1.)));
857 t1->SetTextAlign(12);
858 TText *t2 = pave->AddText(Form("%s%3i%s","Signal Rel. error too large: ",
859 CountBadPixels(&disp24,2)," pixels"));
860 t2->SetTextColor(gStyle->GetColorPalette(Int_t(2./max*numcol + 1.)));
861 t2->SetTextAlign(12);
862 TText *t4 = pave->AddText(Form("Low Gain Saturation: %3i pixels",
863 CountBadPixels(&disp24,3)));
864 t4->SetTextColor(gStyle->GetColorPalette(Int_t(3./max*numcol + 1.)));
865 t4->SetTextAlign(12);
866 TText *t5 = pave->AddText(Form("Mean Arr. Time In First Extraction Bin: %3i pixels",
867 CountBadPixels(&disp24,4)));
868 t5->SetTextColor(gStyle->GetColorPalette(Int_t(4./max*numcol + 1.)));
869 t5->SetTextAlign(12);
870 TText *t6 = pave->AddText(Form("Mean Arr. Time In Last 2 Extraction Bins: %3i pixels",
871 CountBadPixels(&disp24,5)));
872 t6->SetTextColor(gStyle->GetColorPalette(Int_t(5./max*numcol + 1.)));
873 t6->SetTextAlign(12);
874 TText *t9 = pave->AddText(Form("Deviating Number of Photons: %3i pixels",
875 CountBadPixels(&disp24,6)));
876 t9->SetTextColor(gStyle->GetColorPalette(Int_t(6./max*numcol + 1.)));
877 t9->SetTextAlign(12);
878 TText *t10= pave->AddText(Form("High-Gain Histogram Overflow: %3i pixels",
879 CountBadPixels(&disp24,7 )));
880 t10->SetTextColor(gStyle->GetColorPalette(Int_t(7./max*numcol + 1.)));
881 t10->SetTextAlign(12);
882 TText *t11= pave->AddText(Form("Low-Gain Histogram Overflow: %3i pixels",
883 CountBadPixels(&disp24,8 )));
884 t11->SetTextColor(gStyle->GetColorPalette(Int_t(8./max*numcol + 1.)));
885 t11->SetTextAlign(12);
886 TText *t12= pave->AddText(Form("Previously Excluded: %3i pixels",
887 CountBadPixels(&disp24,9)));
888 t12->SetTextColor(gStyle->GetColorPalette(Int_t(9./max*numcol + 1.)));
889 t12->SetTextAlign(12);
890 pave->Draw();
891
892 c4.cd(3);
893 gPad->SetBorderMode(0);
894 obj8->Draw();
895 obj8->SetPrettyPalette();
896
897 //
898 // UNRELIABLE PIXELS
899 //
900
901 c4.cd(2);
902 gPad->SetBorderMode(0);
903 gPad->SetTicks();
904 MHCamera *obj9=(MHCamera*)disp25.DrawCopy("hist");
905 //
906 // for the datacheck, fix the ranges!!
907 //
908 const Double_t max2 = 8.;
909 obj9->SetMinimum(0.);
910 obj9->SetMaximum(max2);
911 //
912 // Set the datacheck sizes:
913 //
914 FixDataCheckHist((TH1D*)obj9);
915 obj9->SetStats(kFALSE);
916
917 gStyle->SetPalette(1);
918
919 TPaveText *pave2 = new TPaveText(0.0,0.0,0.99,0.99);
920 pave2->SetBit(kCanDelete);
921 pave2->ConvertNDCtoPad();
922 pave2->SetTextSize(0.05);
923 pave2->AddText(" ");
924 TText *t3 = pave2->AddText(Form("Signal Sigma smaller Pedestal RMS: %3i pixels",
925 CountBadPixels(&disp25,1)));
926 t3->SetTextColor(gStyle->GetColorPalette(Int_t(1./max*numcol + 1.)));
927 t3->SetTextAlign(12);
928
929 TText *t7 = pave2->AddText(Form("Deviating Number of Photo-electrons: %3i pixels",
930 CountBadPixels(&disp25,2)));
931 t7->SetTextColor(gStyle->GetColorPalette(Int_t(2./max*numcol + 1.)));
932 t7->SetTextAlign(12);
933
934 TText *tt1 = pave2->AddText(Form("High Gain Signals could not be fitted: %3i pixels",
935 CountBadPixels(&disp25,3)));
936 tt1->SetTextColor(gStyle->GetColorPalette(Int_t(3./max2*numcol + 1.)));
937 tt1->SetTextAlign(12);
938 TText *tt2 = pave2->AddText(Form("Low Gain Signals could not be fitted: %3i pixels",
939 CountBadPixels(&disp25,4)));
940 tt2->SetTextColor(gStyle->GetColorPalette(Int_t(4./max2*numcol + 1.)));
941 tt2->SetTextAlign(12);
942 TText *tt3 = pave2->AddText(Form("Relative Arr. Times could not be fitted: %3i pixels",
943 CountBadPixels(&disp25,5)));
944 tt3->SetTextColor(gStyle->GetColorPalette(Int_t(5./max2*numcol + 1.)));
945 tt3->SetTextAlign(12);
946 TText *tt4 = pave2->AddText(Form("High Gain Signals Oscillation: %3i pixels",
947 CountBadPixels(&disp25,6)));
948 tt4->SetTextColor(gStyle->GetColorPalette(Int_t(6./max2*numcol + 1.)));
949 tt4->SetTextAlign(12);
950 TText *tt5 = pave2->AddText(Form("Low Gain Signals Oscillation: %3i pixels",
951 CountBadPixels(&disp25,7)));
952 tt5->SetTextColor(gStyle->GetColorPalette(Int_t(7./max2*numcol + 1.)));
953 tt5->SetTextAlign(12);
954 TText *tt6 = pave2->AddText(Form("Relative Arr. Times Oscillation: %3i pixels",
955 CountBadPixels(&disp25,8)));
956 tt6->SetTextColor(gStyle->GetColorPalette(Int_t(8./max2*numcol + 1.)));
957 tt6->SetTextAlign(12);
958 TText *tt8 = pave2->AddText(Form("Deviating global F-Factor: %3i pixels",
959 CountBadPixels(&disp25,9)));
960 tt8->SetTextColor(gStyle->GetColorPalette(Int_t(9./max2*numcol + 1.)));
961 tt8->SetTextAlign(12);
962 pave2->Draw();
963
964 c4.cd(4);
965 gPad->SetBorderMode(0);
966 obj9->SetPrettyPalette();
967 obj9->Draw();
968
969 if (IsRelTimes())
970 {
971 TCanvas &c5 = fDisplay->AddTab("RelTimes");
972 c5.Divide(2,3);
973
974 //
975 // MEAN REL. ARR. TIMES
976 //
977 c5.cd(1);
978 gPad->SetBorderMode(0);
979 gPad->SetTicks();
980 MHCamera *obj10=(MHCamera*)disp30.DrawCopy("hist");
981 //
982 // for the datacheck, fix the ranges!!
983 //
984 obj10->SetMinimum(fTimeOffsetMin);
985 obj10->SetMaximum(fTimeOffsetMax);
986 //
987 // Set the datacheck sizes:
988 //
989 FixDataCheckHist((TH1D*)obj10);
990 obj10->SetStats(kFALSE);
991 //
992 // set reference lines
993 //
994 DisplayReferenceLines(obj10,5);
995
996 c5.cd(3);
997 gPad->SetBorderMode(0);
998 obj10->SetPrettyPalette();
999 obj10->Draw();
1000
1001 c5.cd(5);
1002 gPad->SetBorderMode(0);
1003 if (geomcam.InheritsFrom("MGeomCamMagic"))
1004 DisplayDoubleProject(&disp30, "early", "late");
1005
1006 //
1007 // JITTER Rel. Arr. Times
1008 //
1009 c5.cd(2);
1010 gPad->SetBorderMode(0);
1011 gPad->SetTicks();
1012 MHCamera *obj11=(MHCamera*)disp31.DrawCopy("hist");
1013 //
1014 // for the datacheck, fix the ranges!!
1015 //
1016 obj11->SetMinimum(fTimeResolutionMin);
1017 obj11->SetMaximum(fTimeResolutionMax);
1018 //
1019 // Set the datacheck sizes:
1020 //
1021 FixDataCheckHist((TH1D*)obj11);
1022 obj11->SetStats(kFALSE);
1023 //
1024 // set reference lines
1025 //
1026 DisplayReferenceLines(obj11,6);
1027
1028 c5.cd(4);
1029 gPad->SetBorderMode(0);
1030 obj11->SetPrettyPalette();
1031 obj11->Draw();
1032
1033 c5.cd(6);
1034 gPad->SetBorderMode(0);
1035 if (geomcam.InheritsFrom("MGeomCamMagic"))
1036 DisplayDoubleProject(&disp31, "too stable", "jittering");
1037
1038 }
1039 return;
1040 }
1041
1042 if (fDisplayType == kNormalDisplay)
1043 {
1044
1045 // Charges
1046 TCanvas &c11 = fDisplay->AddTab("FitCharge");
1047 c11.Divide(2, 4);
1048
1049 disp1.CamDraw(c11, 1, 2, 5, 1);
1050 disp2.CamDraw(c11, 2, 2, 5, 1);
1051
1052 // Reduced Sigmas
1053 TCanvas &c12 = fDisplay->AddTab("RedSigma");
1054 c12.Divide(2,4);
1055
1056 disp3.CamDraw(c12, 1, 2, 5, 1);
1057 disp4.CamDraw(c12, 2, 2, 5, 1);
1058
1059 // F-Factor
1060 TCanvas &c13 = fDisplay->AddTab("Phe's");
1061 c13.Divide(3,4);
1062
1063 disp5.CamDraw(c13, 1, 3, 5, 1);
1064 disp6.CamDraw(c13, 2, 3, 5, 1);
1065 disp7.CamDraw(c13, 3, 3, 5, 1);
1066
1067 // QE's
1068 TCanvas &c14 = fDisplay->AddTab("QE's");
1069 c14.Divide(4,4);
1070
1071 disp8.CamDraw(c14, 1, 4, 5, 1);
1072 disp9.CamDraw(c14, 2, 4, 5, 1);
1073 disp10.CamDraw(c14, 3, 4, 5, 1);
1074 disp11.CamDraw(c14, 4, 4, 5, 1);
1075
1076 // Defects
1077 TCanvas &c15 = fDisplay->AddTab("Defect");
1078 // c15.Divide(5,2);
1079 c15.Divide(4,2);
1080
1081 /*
1082 disp23.CamDraw(c15, 1, 5, 0);
1083 disp24.CamDraw(c15, 2, 5, 0);
1084 disp25.CamDraw(c15, 3, 5, 0);
1085 disp26.CamDraw(c15, 4, 5, 0);
1086 disp27.CamDraw(c15, 5, 5, 0);
1087 */
1088 disp24.CamDraw(c15, 1, 4, 0);
1089 disp25.CamDraw(c15, 2, 4, 0);
1090 disp26.CamDraw(c15, 3, 4, 0);
1091 disp27.CamDraw(c15, 4, 4, 0);
1092
1093 // Abs. Times
1094 TCanvas &c16 = fDisplay->AddTab("AbsTimes");
1095 c16.Divide(2,3);
1096
1097 disp28.CamDraw(c16, 1, 2, 5);
1098 disp29.CamDraw(c16, 2, 2, 5);
1099
1100 if (IsRelTimes())
1101 {
1102 // Rel. Times
1103 TCanvas &c17 = fDisplay->AddTab("RelTimes");
1104 c17.Divide(2,4);
1105
1106 disp30.CamDraw(c17, 1, 2, 5, 1);
1107 disp31.CamDraw(c17, 2, 2, 5, 1);
1108 }
1109
1110 return;
1111 }
1112
1113 if (fDisplayType == kFullDisplay)
1114 {
1115 MHCalibrationCam *cam = (MHCalibrationCam*)plist.FindObject("MHCalibrationChargeCam");
1116
1117 for (Int_t sector=1;sector<cam->GetAverageSectors();sector++)
1118 {
1119 cam->GetAverageHiGainSector(sector).DrawClone("all");
1120 cam->GetAverageLoGainSector(sector).DrawClone("all");
1121 }
1122
1123 // Charges
1124 TCanvas &c21 = fDisplay->AddTab("FitCharge");
1125 c21.Divide(2, 4);
1126
1127 disp1.CamDraw(c21, 1, 2, 2, 1);
1128 disp2.CamDraw(c21, 2, 2, 2, 1);
1129
1130 // Reduced Sigmas
1131 TCanvas &c23 = fDisplay->AddTab("RedSigma");
1132 c23.Divide(2,4);
1133
1134 disp3.CamDraw(c23, 1, 2, 2, 1);
1135 disp4.CamDraw(c23, 2, 2, 2, 1);
1136
1137 // F-Factor
1138 TCanvas &c24 = fDisplay->AddTab("Phe's");
1139 c24.Divide(3,5);
1140
1141 disp5.CamDraw(c24, 1, 3, 2, 1, 1);
1142 disp6.CamDraw(c24, 2, 3, 2, 1, 1);
1143 disp7.CamDraw(c24, 3, 3, 2, 1, 1);
1144
1145 // QE's
1146 TCanvas &c25 = fDisplay->AddTab("QE's");
1147 c25.Divide(4,5);
1148
1149 disp8.CamDraw(c25, 1, 4, 2, 1, 1);
1150 disp9.CamDraw(c25, 2, 4, 2, 1, 1);
1151 disp10.CamDraw(c25, 3, 4, 2, 1, 1);
1152 disp11.CamDraw(c25, 4, 4, 2, 1, 1);
1153
1154 // Validity
1155 TCanvas &c26 = fDisplay->AddTab("Valid");
1156 c26.Divide(4,2);
1157
1158 disp12.CamDraw(c26, 1, 4, 0);
1159 disp13.CamDraw(c26, 2, 4, 0);
1160 disp14.CamDraw(c26, 3, 4, 0);
1161 disp15.CamDraw(c26, 4, 4, 0);
1162
1163 // Other info
1164 TCanvas &c27 = fDisplay->AddTab("HiLoGain");
1165 c27.Divide(3,3);
1166
1167 disp16.CamDraw(c27, 1, 3, 0);
1168 disp17.CamDraw(c27, 2, 3, 1);
1169 disp18.CamDraw(c27, 3, 3, 1);
1170
1171 // Pickup
1172 TCanvas &c28 = fDisplay->AddTab("Pickup");
1173 c28.Divide(4,2);
1174
1175 disp19.CamDraw(c28, 1, 4, 0);
1176 disp20.CamDraw(c28, 2, 4, 0);
1177 disp21.CamDraw(c28, 3, 4, 0);
1178 disp22.CamDraw(c28, 4, 4, 0);
1179
1180 // Defects
1181 TCanvas &c29 = fDisplay->AddTab("Defect");
1182 // c29.Divide(5,2);
1183 c29.Divide(4,2);
1184
1185 disp24.CamDraw(c29, 1, 4, 0);
1186 disp25.CamDraw(c29, 2, 4, 0);
1187 disp26.CamDraw(c29, 3, 4, 0);
1188 disp27.CamDraw(c29, 4, 4, 0);
1189
1190 // Abs. Times
1191 TCanvas &c30 = fDisplay->AddTab("AbsTimes");
1192 c30.Divide(2,3);
1193
1194 disp28.CamDraw(c30, 1, 2, 2);
1195 disp29.CamDraw(c30, 2, 2, 1);
1196
1197 if (IsRelTimes())
1198 {
1199 // Rel. Times
1200 TCanvas &c31 = fDisplay->AddTab("RelTimes");
1201 c31.Divide(3,5);
1202
1203 disp30.CamDraw(c31, 1, 3, 2, 1, 1);
1204 disp31.CamDraw(c31, 2, 3, 2, 1, 1);
1205 disp32.CamDraw(c31, 3, 3, 4, 1, 1);
1206
1207 // Time Defects
1208 TCanvas &c32 = fDisplay->AddTab("DefTime");
1209 c32.Divide(2,2);
1210
1211 disp33.CamDraw(c32, 1, 2, 0);
1212 disp34.CamDraw(c32, 2, 2, 0);
1213
1214 MHCalibrationCam *cam = (MHCalibrationCam*)plist.FindObject("MHCalibrationRelTimeCam");
1215
1216 for (Int_t sector=1;sector<cam->GetAverageSectors();sector++)
1217 {
1218 cam->GetAverageHiGainSector(sector).DrawClone("fourierevents");
1219 cam->GetAverageLoGainSector(sector).DrawClone("fourierevents");
1220 }
1221
1222 }
1223
1224 return;
1225 }
1226}
1227
1228
1229void MJCalibration::DisplayReferenceLines(MHCamera *cam, const Int_t what) const
1230{
1231
1232 const MGeomCam *geom = cam->GetGeometry();
1233
1234 Double_t x = geom->InheritsFrom("MGeomCamMagic") ? 397 : cam->GetNbinsX() ;
1235
1236 TLine line;
1237 line.SetLineStyle(kDashed);
1238 line.SetLineWidth(3);
1239 line.SetLineColor(kBlue);
1240
1241 TLine *l1 = NULL;
1242
1243 switch (what)
1244 {
1245 case 0:
1246 l1 = line.DrawLine(0, fRefQEInner, x, fRefQEInner);
1247 break;
1248 case 1:
1249 l1 = line.DrawLine(0, fRefConvFADC2PhotInner, x, fRefConvFADC2PhotInner);
1250 break;
1251 case 2:
1252 l1 = line.DrawLine(0, fRefConvFADC2PheInner, x, fRefConvFADC2PheInner );
1253 break;
1254 case 3:
1255 l1 = line.DrawLine(0, fRefArrivalTimeInner, x, fRefArrivalTimeInner );
1256 break;
1257 case 4:
1258 l1 = line.DrawLine(0, fRefArrivalTimeRmsInner, x, fRefArrivalTimeRmsInner );
1259 break;
1260 case 5:
1261 l1 = line.DrawLine(0, fRefTimeOffsetInner, x, fRefTimeOffsetInner );
1262 break;
1263 case 6:
1264 l1 = line.DrawLine(0, fRefTimeResolutionInner, x, fRefTimeResolutionInner );
1265 break;
1266 default:
1267 break;
1268 }
1269
1270 if (geom->InheritsFrom("MGeomCamMagic"))
1271 {
1272 const Double_t x2 = cam->GetNbinsX();
1273
1274 switch (what)
1275 {
1276 case 0:
1277 line.DrawLine(x2, fRefQEOuter, 398, fRefQEOuter);
1278 break;
1279 case 1:
1280 line.DrawLine(x2, fRefConvFADC2PhotOuter, 398, fRefConvFADC2PhotOuter );
1281 break;
1282 case 2:
1283 line.DrawLine(x2, fRefConvFADC2PheOuter, 398, fRefConvFADC2PheOuter);
1284 break;
1285 case 3:
1286 line.DrawLine(x2, fRefArrivalTimeOuter, 398, fRefArrivalTimeOuter);
1287 break;
1288 case 4:
1289 line.DrawLine(x2, fRefArrivalTimeRmsOuter, 398, fRefArrivalTimeRmsOuter);
1290 break;
1291 case 5:
1292 line.DrawLine(x2, fRefTimeOffsetOuter, 398, fRefTimeOffsetOuter);
1293 break;
1294 case 6:
1295 line.DrawLine(x2, fRefTimeResolutionOuter, 398, fRefTimeResolutionOuter);
1296 break;
1297 default:
1298 break;
1299 }
1300 }
1301
1302 TLegend *leg = new TLegend(0.6,0.85,0.9 ,0.95);
1303 leg->SetBit(kCanDelete);
1304 leg->AddEntry(l1, "Reference","l");
1305 leg->Draw();
1306}
1307
1308void MJCalibration::DisplayOutliers(TH1D *hist, const char* whatsmall, const char* whatbig) const
1309{
1310
1311 const Int_t kNotDraw = 1<<9;
1312 TF1 *f = hist->GetFunction("gaus");
1313 f->ResetBit(kNotDraw);
1314
1315 const Float_t mean = f->GetParameter(1);
1316 const Float_t lolim = mean - 4.0*f->GetParameter(2);
1317 const Float_t uplim = mean + 4.0*f->GetParameter(2);
1318 const Stat_t dead = hist->Integral(0,hist->FindBin(lolim)-1);
1319 const Stat_t noisy = hist->Integral(hist->FindBin(uplim)+1,hist->GetNbinsX()+1);
1320
1321 const Double_t max = hist->GetBinContent(hist->GetMaximumBin());
1322
1323 const Double_t minl = hist->GetBinCenter(hist->GetXaxis()->GetFirst());
1324 const Double_t maxl = hist->GetBinCenter(hist->GetXaxis()->GetLast());
1325
1326 TLatex deadtex;
1327 deadtex.SetTextSize(0.07);
1328 deadtex.DrawLatex(minl+0.015*(maxl-minl),max/1.1,
1329 Form("%3i %s pixels",(Int_t)dead,whatsmall));
1330
1331 TLatex noisytex;
1332 noisytex.SetTextSize(0.07);
1333 noisytex.DrawLatex(minl+0.015*(maxl-minl),max/1.2,
1334 Form("%3i %s pixels",(Int_t)noisy,whatbig));
1335
1336}
1337
1338void MJCalibration::FixDataCheckHist(TH1D *hist) const
1339{
1340
1341 hist->SetDirectory(NULL);
1342
1343 //
1344 // set the labels bigger
1345 //
1346 TAxis *xaxe = hist->GetXaxis();
1347 TAxis *yaxe = hist->GetYaxis();
1348
1349 xaxe->CenterTitle();
1350 yaxe->CenterTitle();
1351 xaxe->SetTitleSize(0.06);
1352 yaxe->SetTitleSize(0.06);
1353 xaxe->SetTitleOffset(0.8);
1354 yaxe->SetTitleOffset(0.85);
1355 xaxe->SetLabelSize(0.05);
1356 yaxe->SetLabelSize(0.05);
1357
1358}
1359
1360const Int_t MJCalibration::CountBadPixels ( MHCamera *cam , const Int_t what ) const
1361{
1362
1363 Int_t cnt = 0;
1364
1365 for (UInt_t pix=0; pix<cam->GetNumPixels();pix++)
1366 if ((Int_t)cam->GetPixContent(pix) == what)
1367 cnt++;
1368
1369 return cnt;
1370}
1371
1372// --------------------------------------------------------------------------
1373//
1374// Retrieve the output file written by WriteResult()
1375//
1376const char* MJCalibration::GetOutputFile() const
1377{
1378 const TString name(GetOutputFileName());
1379 if (name.IsNull())
1380 return "";
1381
1382 return Form("%s/%s", fPathOut.Data(), name.Data());
1383}
1384
1385const char* MJCalibration::GetOutputFileName() const
1386{
1387
1388 if (fSequence.IsValid())
1389 return Form("calib%08d.root", fSequence.GetSequence());
1390 if (!fRuns)
1391 return "";
1392
1393 return Form("%s-F1.root", (const char*)fRuns->GetRunsAsFileName());
1394}
1395
1396// --------------------------------------------------------------------------
1397//
1398// Read the following values from resource file:
1399//
1400// ConvFADC2PheMin
1401// ConvFADC2PheMax
1402// ConvFADC2PhotMin
1403// ConvFADC2PhotMax
1404//
1405// QEMin
1406// QEMax
1407//
1408// ArrivalTimeMin
1409// ArrivalTimeMax
1410//
1411// TimeOffsetMin
1412// TimeOffsetMax
1413// TimeResolutionMin
1414// TimeResolutionMax
1415//
1416// RefConvFADC2PheInner
1417// RefConvFADC2PheOuter
1418// RefConvFADC2PhotInner
1419// RefConvFADC2PhotOuter
1420//
1421// RefQEInner
1422// RefQEOuter
1423//
1424// RefArrivalTimeInner
1425// RefArrivalTimeOuter
1426// RefArrivalTimeRmsInner
1427// RefArrivalTimeRmsOuter
1428//
1429// RefTimeOffsetInner
1430// RefTimeOffsetOuter
1431// RefTimeResolutionInner
1432// RefTimeResolutionOuter
1433//
1434void MJCalibration::ReadReferenceFile()
1435{
1436 TEnv refenv(fReferenceFile);
1437
1438 fConvFADC2PheMin = refenv.GetValue("ConvFADC2PheMin",fConvFADC2PheMin);
1439 fConvFADC2PheMax = refenv.GetValue("ConvFADC2PheMax",fConvFADC2PheMax);
1440 fConvFADC2PhotMin = refenv.GetValue("ConvFADC2PhotMin",fConvFADC2PhotMin);
1441 fConvFADC2PhotMax = refenv.GetValue("ConvFADC2PhotMax",fConvFADC2PhotMax);
1442 fQEMin = refenv.GetValue("QEMin",fQEMin);
1443 fQEMax = refenv.GetValue("QEMax",fQEMax);
1444 fArrivalTimeMin = refenv.GetValue("ArrivalTimeMin",fArrivalTimeMin);
1445 fArrivalTimeMax = refenv.GetValue("ArrivalTimeMax",fArrivalTimeMax);
1446 fTimeOffsetMin = refenv.GetValue("TimeOffsetMin",fTimeOffsetMin);
1447 fTimeOffsetMax = refenv.GetValue("TimeOffsetMax",fTimeOffsetMax);
1448 fTimeResolutionMin = refenv.GetValue("TimeResolutionMin",fTimeResolutionMin);
1449 fTimeResolutionMax = refenv.GetValue("TimeResolutionMax",fTimeResolutionMax);
1450
1451 fRefConvFADC2PheInner = refenv.GetValue("RefConvFADC2PheInner",fRefConvFADC2PheInner);
1452 fRefConvFADC2PheOuter = refenv.GetValue("RefConvFADC2PheOuter",fRefConvFADC2PheOuter);
1453 fRefConvFADC2PhotInner = refenv.GetValue("RefConvFADC2PhotInner",fRefConvFADC2PhotInner);
1454 fRefConvFADC2PhotOuter = refenv.GetValue("RefConvFADC2PhotOuter",fRefConvFADC2PhotOuter);
1455 fRefQEInner = refenv.GetValue("RefQEInner",fRefQEInner);
1456 fRefQEOuter = refenv.GetValue("RefQEOuter",fRefQEOuter);
1457 fRefArrivalTimeInner = refenv.GetValue("RefArrivalTimeInner",fRefArrivalTimeInner);
1458 fRefArrivalTimeOuter = refenv.GetValue("RefArrivalTimeOuter",fRefArrivalTimeOuter);
1459 fRefArrivalTimeRmsInner = refenv.GetValue("RefArrivalTimeRmsInner",fRefArrivalTimeRmsInner);
1460 fRefArrivalTimeRmsOuter = refenv.GetValue("RefArrivalTimeRmsOuter",fRefArrivalTimeRmsOuter);
1461 fRefTimeOffsetInner = refenv.GetValue("RefTimeOffsetInner",fRefTimeOffsetInner);
1462 fRefTimeOffsetOuter = refenv.GetValue("RefTimeOffsetOuter",fRefTimeOffsetOuter);
1463 fRefTimeResolutionInner = refenv.GetValue("RefTimeResolutionInner",fRefTimeResolutionInner);
1464 fRefTimeResolutionOuter = refenv.GetValue("RefTimeResolutionOuter",fRefTimeResolutionOuter);
1465}
1466
1467// --------------------------------------------------------------------------
1468//
1469// Read the following values from resource file:
1470//
1471// MCalibrationHiLoCam
1472//
1473Bool_t MJCalibration::ReadHiLoCalibFile()
1474{
1475
1476 TFile file(fHiLoCalibFile,"READ");
1477
1478 MCalibrationHiLoCam hilocam;
1479
1480 if (hilocam.Read()<=0)
1481 {
1482 *fLog << err << "Unable to read MCalibrationHiLoCam from " << fHiLoCalibFile << endl;
1483 return kFALSE;
1484 }
1485
1486 if (hilocam.GetSize() < 1)
1487 {
1488 *fLog << err << "MCalibationHiLoCam is un-initialized in file " << fHiLoCalibFile << endl;
1489 return kFALSE;
1490 }
1491
1492 if (fCalibrationCam.GetSize() < 1)
1493 fCalibrationCam.InitSize(hilocam.GetSize());
1494
1495 if (fBadPixels.GetSize() < 1)
1496 fBadPixels.InitSize(hilocam.GetSize());
1497
1498 if (fCalibrationCam.GetSize() != hilocam.GetSize())
1499 {
1500 *fLog << err << "Size mismatch MCalibationHiLoCam and MCalibrationChargeCam " << endl;
1501 return kFALSE;
1502 }
1503
1504 for (Int_t i=0;i<hilocam.GetSize();i++)
1505 {
1506 const MCalibrationHiLoPix &pix = (MCalibrationHiLoPix&)hilocam[i];
1507
1508 const Float_t ratio = pix.GetHiLoChargeRatio();
1509 const Float_t sigma = pix.GetHiLoChargeRatioSigma();
1510
1511 if (ratio < 0.)
1512 {
1513 fBadPixels[i].SetUncalibrated(MBadPixelsPix::kConversionHiLoNotValid);
1514 continue;
1515 }
1516
1517 MCalibrationChargePix &cpix = (MCalibrationChargePix&)fCalibrationCam[i];
1518
1519 cpix.SetConversionHiLo(ratio);
1520 cpix.SetConversionHiLoErr(sigma);
1521 }
1522 return kTRUE;
1523}
1524
1525// --------------------------------------------------------------------------
1526//
1527// MJCalibration allows to setup several option by a resource file:
1528// MJCalibration.Display: full, datacheck, normal
1529// MJCalibration.RelTimeCalibration: yes,no
1530// MJCalibration.DataCheck: yes,no
1531// MJCalibration.Debug: yes,no
1532// MJCalibration.Intensity: yes,no
1533// MJCalibration.UseBlindPixel: yes,no
1534// MJCalibration.UsePINDiode: yes,no
1535// MJCalibration.Geometry: MGeomCamMagic, MGeomCamECO1000
1536//
1537// Name of a file containing reference values (see ReadReferenceFile)
1538// Prefix.ReferenceFile: filename
1539// (see ReadReferenceFile)
1540//
1541// For more details see the class description and the corresponding Getters
1542//
1543Bool_t MJCalibration::CheckEnvLocal()
1544{
1545
1546 TString dis = GetEnv("Display", "");
1547 if (dis.BeginsWith("Full", TString::kIgnoreCase))
1548 SetFullDisplay();
1549 if (dis.BeginsWith("DataCheck", TString::kIgnoreCase))
1550 SetDataCheckDisplay();
1551 if (dis.BeginsWith("Normal", TString::kIgnoreCase))
1552 SetNormalDisplay();
1553
1554 if (!MJCalib::CheckEnvLocal())
1555 return kFALSE;
1556
1557 SetRelTimeCalibration(GetEnv("RelTimeCalibration", IsRelTimes()));
1558 SetIntensity(GetEnv("IntensityCalibration", IsIntensity()));
1559 SetDebug(GetEnv("Debug", IsDebug()));
1560
1561 SetUseBlindPixel(GetEnv("UseBlindPixel", IsUseBlindPixel()));
1562 SetUsePINDiode(GetEnv("UsePINDiode", IsUsePINDiode()));
1563 SetGeometry(GetEnv("Geometry", fGeometry));
1564
1565 fReferenceFile = GetEnv("ReferenceFile",fReferenceFile.Data());
1566 ReadReferenceFile();
1567
1568 fHiLoCalibFile = GetEnv("HiLoCalibFile",fHiLoCalibFile.Data());
1569
1570 return ReadHiLoCalibFile();
1571}
1572
1573// --------------------------------------------------------------------------
1574//
1575// Call the ProcessFile(MPedestalCam)
1576//
1577Bool_t MJCalibration::Process(MPedestalCam &pedcam)
1578{
1579 if (!ReadCalibrationCam())
1580 return ProcessFile(pedcam);
1581
1582 return kTRUE;
1583}
1584
1585void MJCalibration::InitBlindPixel(MExtractBlindPixel &blindext,
1586 MHCalibrationChargeBlindCam &blindcam)
1587{
1588
1589 Int_t run = fSequence.IsValid() ? fSequence.GetLastRun() : fRuns->GetRuns()[fRuns->GetNumRuns()-1];
1590
1591 //
1592 // Initialize the blind pixel. Unfortunately, there is a hardware difference
1593 // in the first blind pixel until run "gkSecondBlindPixelInstallation" and the
1594 // later setup. The first needs to use a filter because of the length of
1595 // spurious NSB photon signals. The latter get better along extracting the amplitude
1596 // from a small window.
1597 //
1598 if (run < gkSecondBlindPixelInstallation)
1599 {
1600 MCalibrationBlindCamOneOldStyle blindresults;
1601 if (IsIntensity())
1602 blindresults.Copy(*fIntensBlindCam.GetCam());
1603 else
1604 blindresults.Copy(fCalibrationBlindCam);
1605
1606 blindext.SetExtractionType(MExtractBlindPixel::kIntegral);
1607 blindext.SetExtractionType(MExtractBlindPixel::kFilter);
1608 blindext.SetRange(10,19,0,6);
1609 blindext.SetNSBFilterLimit(70);
1610 }
1611 else if (run < gkThirdBlindPixelInstallation)
1612 {
1613
1614 MCalibrationBlindCamTwoNewStyle blindresults;
1615
1616 if (IsIntensity())
1617 blindresults.Copy(*fIntensBlindCam.GetCam());
1618 else
1619 blindresults.Copy(fCalibrationBlindCam);
1620
1621 blindext.SetNumBlindPixels(blindresults.GetSize());
1622 for (Int_t i=0;i<blindresults.GetSize();i++)
1623 blindext.SetBlindPixelIdx(blindresults[i].GetPixId(),i);
1624
1625 blindext.SetExtractionType(MExtractBlindPixel::kAmplitude);
1626 blindext.SetExtractionType(MExtractBlindPixel::kFilter);
1627 blindext.SetRange(5,8,0,2);
1628 blindext.SetNSBFilterLimit(38);
1629
1630 }
1631 else
1632 {
1633
1634 MCalibrationBlindCamThreeNewStyle blindresults;
1635
1636 if (IsIntensity())
1637 blindresults.Copy(*fIntensBlindCam.GetCam());
1638 else
1639 blindresults.Copy(fCalibrationBlindCam);
1640
1641 blindext.SetNumBlindPixels(blindresults.GetSize());
1642
1643 for (Int_t i=0;i<blindresults.GetSize();i++)
1644 blindext.SetBlindPixelIdx(blindresults[i].GetPixId(),i);
1645
1646 blindext.SetExtractionType(MExtractBlindPixel::kAmplitude);
1647 blindext.SetExtractionType(MExtractBlindPixel::kFilter);
1648 blindext.SetDataType(MExtractBlindPixel::kRawEvt2);
1649 blindext.SetRange(5,8,0,2);
1650 blindext.SetNSBFilterLimit(38);
1651
1652 }
1653
1654}
1655
1656// --------------------------------------------------------------------------
1657//
1658// Execute the task list and the eventloop:
1659//
1660// - Check if there are fRuns, otherwise return
1661// - Check the colour of the files in fRuns (FindColor()), otherwise return
1662// - Check for consistency between run numbers and number of files
1663// - Add fRuns to MReadMarsFile
1664// - Put into MParList:
1665// 1) MPedestalCam (pedcam)
1666// 2) MCalibrationQECam (fQECam)
1667// 3) MCalibrationChargeCam (fCalibrationCam)
1668// 4) MCalibrationRelTimeCam (fRelTimeCam) (only if flag IsRelTimes() is chosen)
1669// 5) MBadPixelsCam (fBadPixels)
1670// 6) MCalibrationChargePINDiode
1671// 7) MCalibrationBlindPix
1672// - Put into the MTaskList:
1673// 1) MReadMarsFile
1674// 2) MBadPixelsMerge
1675// 3) MGeomApply
1676// 4) MExtractor
1677// 5) MExtractPINDiode
1678// 6) MExtractBlindPixel
1679// 7) MExtractTime (only if flag IsRelTimes() is chosen)
1680// 8) MContinue(MFCosmics)
1681// 9) MFillH("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode", "FillPINDiode")
1682// 10) MFillH("MHCalibrationChargeBlindCam", "MExtractedSignalBlindPixel", "FillBlindCam")
1683// 11) MFillH("MHCalibrationChargeCam", "MExtractedSignalCam", "FillChargeCam")
1684// 12) MFillH("MHCalibrationChargeCam", "MExtractedSignalCam", "FillRelTime")
1685// 13) MCalibrationChargeCalc
1686// 14) MFillH("MHCalibrationRelTimeCam", "MArrivalTimeCam") (only if flag IsRelTimes() is chosen)
1687// 15) MCalibrationRelTimeCalc
1688// - Execute MEvtLoop
1689// - DisplayResult()
1690// - WriteResult()
1691//
1692Bool_t MJCalibration::ProcessFile(MPedestalCam &pedcam)
1693{
1694 if (!fSequence.IsValid())
1695 {
1696 if (!fRuns)
1697 {
1698 *fLog << err << "No Runs choosen... abort." << endl;
1699 return kFALSE;
1700 }
1701
1702 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
1703 {
1704 *fLog << err << "Number of files found doesn't match number of runs... abort."
1705 << fRuns->GetNumRuns() << " vs. " << fRuns->GetNumEntries() << endl;
1706 return kFALSE;
1707 }
1708 }
1709
1710 //if (!CheckEnv())
1711 // return kFALSE;
1712
1713 if (!CheckEnv())
1714 return kFALSE;
1715
1716 // --------------------------------------------------------------------------------
1717
1718 *fLog << inf;
1719 fLog->Separator(GetDescriptor());
1720
1721 *fLog << "Calculate MCalibrationCam from ";
1722 if (fSequence.IsValid())
1723 *fLog << "Sequence #" << fSequence.GetSequence() << endl;
1724 else
1725 *fLog << "Runs " << fRuns->GetRunsAsString() << endl;
1726 *fLog << endl;
1727
1728 // --------------------------------------------------------------------------------
1729
1730 // Setup Tasklist
1731 MParList plist;
1732 MTaskList tlist;
1733 plist.AddToList(&tlist);
1734 plist.AddToList(this); // take care of fDisplay!
1735
1736 MDirIter iter;
1737 if (fSequence.IsValid())
1738 {
1739 const Int_t n0 = fSequence.SetupCalRuns(iter, fPathData, "C", IsUseRawData());
1740 const Int_t n1 = fSequence.GetNumCalRuns();
1741 if (n0==0)
1742 {
1743 *fLog << err << "ERROR - No input files of sequence found!" << endl;
1744 return kFALSE;
1745 }
1746 if (n0!=n1)
1747 {
1748 *fLog << err << "ERROR - Number of files found ("
1749 << n0 << ") doesn't match number of files in sequence ("
1750 << n1 << ")" << endl;
1751 return kFALSE;
1752 }
1753 }
1754
1755 //
1756 // Input containers
1757 //
1758 pedcam.SetName("MPedestalCam"); // MPedestalFundamental
1759 plist.AddToList(&pedcam);
1760 plist.AddToList(&fBadPixels);
1761
1762 //
1763 // Calibration Results containers
1764 //
1765 if (IsIntensity())
1766 {
1767 plist.AddToList(&fIntensQECam);
1768 plist.AddToList(&fIntensCalibCam);
1769 plist.AddToList(&fIntensBlindCam);
1770 // plist.AddToList(&fIntensCalibrationPINDiode);
1771 plist.AddToList(&fIntensRelTimeCam);
1772 plist.AddToList(&fIntensBadCam);
1773 }
1774 else
1775 {
1776 plist.AddToList(&fQECam);
1777 plist.AddToList(&fCalibrationCam);
1778 plist.AddToList(&fCalibrationBlindCam);
1779 plist.AddToList(&fCalibrationPINDiode);
1780 plist.AddToList(&fRelTimeCam);
1781 }
1782
1783 //
1784 // Initialize two histogram containers which could be modified in this class
1785 //
1786 MHCalibrationRelTimeCam reltimecam;
1787 MHCalibrationChargeCam chargecam;
1788 MHCalibrationChargeBlindCam blindcam;
1789 plist.AddToList(&chargecam);
1790 plist.AddToList(&blindcam);
1791 if (IsRelTimes())
1792 plist.AddToList(&reltimecam);
1793 //
1794 // Data Reading tasks
1795 //
1796 MReadMarsFile read("Events");
1797 MRawFileRead rawread(NULL);
1798
1799 if (IsUseRawData())
1800 {
1801 rawread.AddFiles(fSequence.IsValid() ? iter : *fRuns);
1802 tlist.AddToList(&rawread);
1803 }
1804 else
1805 {
1806 read.DisableAutoScheme();
1807 read.AddFiles(fSequence.IsValid() ? iter : *fRuns);
1808 tlist.AddToList(&read);
1809 }
1810
1811 //
1812 // Other Tasks
1813 //
1814 MCalibrationPatternDecode decode;
1815 MGeomApply apply;
1816 apply.SetGeometry(fGeometry);
1817
1818 MBadPixelsMerge merge(&fBadPixels);
1819 MExtractPINDiode pinext;
1820 MExtractBlindPixel blindext;
1821
1822 InitBlindPixel(blindext, blindcam);
1823
1824 MExtractSlidingWindow extract2;
1825 MExtractTimeHighestIntegral timehigh;
1826 MCalibrationChargeCalc calcalc;
1827 MCalibrationRelTimeCalc timecalc;
1828 calcalc.SetOutputFile("");
1829 timecalc.SetOutputFile("");
1830
1831 if (!fSequence.IsValid())
1832 {
1833 calcalc.SetOutputPath(fPathOut);
1834 calcalc.SetOutputFile(Form("%s-ChargeCalibStat.txt",(const char*)fRuns->GetRunsAsFileName()));
1835 timecalc.SetOutputPath(fPathOut);
1836 timecalc.SetOutputFile(Form("%s-ChargeCalibStat.txt",(const char*)fRuns->GetRunsAsFileName()));
1837 }
1838
1839 if (IsDebug())
1840 {
1841 chargecam.SetDebug();
1842 calcalc.SetDebug();
1843 }
1844
1845 //
1846 // Calibration histogramming
1847 //
1848 MFillH fillpin("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode", "FillPINDiode");
1849 MFillH fillbnd("MHCalibrationChargeBlindCam", "MExtractedSignalBlindPixel", "FillBlindCam");
1850 MFillH fillcam("MHCalibrationChargeCam", "MExtractedSignalCam", "FillChargeCam");
1851 MFillH filltme("MHCalibrationRelTimeCam", "MArrivalTimeCam", "FillRelTime");
1852 fillpin.SetBit(MFillH::kDoNotDisplay);
1853 fillbnd.SetBit(MFillH::kDoNotDisplay);
1854 fillcam.SetBit(MFillH::kDoNotDisplay);
1855 filltme.SetBit(MFillH::kDoNotDisplay);
1856
1857 //
1858 // Set default extractors in case, none has been set...
1859 //
1860 if (!fExtractor)
1861 fExtractor = &extract2;
1862 if (!fTimeExtractor)
1863 fTimeExtractor = &timehigh;
1864
1865 const Bool_t istimecharge = fExtractor->InheritsFrom("MExtractTimeAndCharge");
1866 //
1867 // Look if the extractor is a pure charge or also a time extractor
1868 //
1869 if (istimecharge)
1870 {
1871 if (fExtractorCam.GetSize() == pedcam.GetSize())
1872 calcalc.SetPedestals(&fExtractorCam);
1873 else
1874 {
1875 *fLog << err << GetDescriptor() << "ERROR - ";
1876 *fLog << "Used Extractor derives from MExtractTimeAndCharge, " << endl;
1877 *fLog << "but MExtractorCam size " << fExtractorCam.GetSize() << " ";
1878 *fLog << "mismatch pedcam size " << pedcam.GetSize() << "! " << endl;
1879 return kFALSE;
1880 }
1881 }
1882
1883 //
1884 // Setup more tasks and tasklist
1885 //
1886 MTaskEnv taskenv("ExtractSignal");
1887 taskenv.SetDefault(fExtractor);
1888
1889 tlist.AddToList(&decode);
1890 tlist.AddToList(&merge);
1891 tlist.AddToList(&apply);
1892
1893 MPedCalcPedRun pedcalc;
1894 pedcalc.SetExtractWindow(fExtractor->GetHiGainFirst(),TMath::Nint(fExtractor->GetNumHiGainSamples()));
1895
1896 if (IsIntensity())
1897 tlist.AddToList(&pedcalc);
1898
1899 MCalibColorSet colorset;
1900 tlist.AddToList(&colorset);
1901
1902 tlist.AddToList(&taskenv);
1903 tlist.AddToList(&pinext);
1904 tlist.AddToList(&blindext);
1905
1906 MTaskEnv taskenv2("ExtractTime");
1907 if (!istimecharge)
1908 {
1909 taskenv2.SetDefault(fTimeExtractor);
1910
1911 if (IsRelTimes())
1912 tlist.AddToList(&taskenv2);
1913 }
1914
1915 //
1916 // Apply a filter against cosmics
1917 // (will have to be needed in the future
1918 // when the calibration hardware-trigger is working)
1919 //
1920 MFCosmics cosmics;
1921 MContinue cont(&cosmics);
1922
1923 if (fColor == MCalibrationCam::kCT1)
1924 tlist.AddToList(&cont);
1925
1926 MCalibColorSteer steer;
1927 if (IsIntensity())
1928 tlist.AddToList(&steer);
1929
1930 tlist.AddToList(&fillcam);
1931
1932 if (IsRelTimes())
1933 {
1934 tlist.AddToList(&filltme);
1935 tlist.AddToList(&timecalc);
1936 }
1937
1938 if (IsUseBlindPixel())
1939 tlist.AddToList(&fillbnd);
1940 if (IsUsePINDiode())
1941 tlist.AddToList(&fillpin);
1942
1943 tlist.AddToList(&calcalc);
1944
1945 // Create and setup the eventloop
1946 MEvtLoop evtloop(fName);
1947 evtloop.SetParList(&plist);
1948 evtloop.SetDisplay(fDisplay);
1949 evtloop.SetLogStream(fLog);
1950 if (!SetupEnv(evtloop))
1951 return kFALSE;
1952
1953 if (!taskenv.GetTask() && !taskenv2.GetTask())
1954 {
1955 *fLog << err << "ERROR - Neither ExtractSignal nor ExtractTime initialized or both '<dummy>'." << endl;
1956 return kFALSE;
1957 }
1958
1959 if (!WriteTasks(taskenv.GetTask(), istimecharge ? 0 : taskenv2.GetTask()))
1960 return kFALSE;
1961
1962 // Execute first analysis
1963 if (!evtloop.Eventloop())
1964 {
1965 DisplayResult(plist);
1966 WriteResult(plist);
1967 *fLog << err << GetDescriptor() << ": Failed." << endl;
1968 return kFALSE;
1969 }
1970
1971 tlist.PrintStatistics();
1972
1973 if (fPixelCheck)
1974 {
1975 MHCalibrationChargeCam *hcam = (MHCalibrationChargeCam*)plist.FindObject("MHCalibrationChargeCam");
1976 MHCalibrationChargePix &pix1 = (MHCalibrationChargePix&)(*hcam)[fCheckedPixId];
1977 pix1.DrawClone("");
1978
1979 MHCalibrationChargePix &pix2 = (MHCalibrationChargePix&)(*hcam)(fCheckedPixId);
1980 pix2.DrawClone("");
1981
1982 if (IsRelTimes())
1983 {
1984 MHCalibrationRelTimeCam *hccam = (MHCalibrationRelTimeCam*)plist.FindObject("MHCalibrationRelTimeCam");
1985 MHCalibrationPix &pix11 = (*hccam)[fCheckedPixId];
1986 pix11.DrawClone("");
1987 MHCalibrationPix &pix12 = (*hccam)(fCheckedPixId);
1988 pix12.DrawClone("");
1989 }
1990 }
1991
1992 if (!fCalibrationPINDiode.IsValid())
1993 SetUsePINDiode(kFALSE);
1994
1995 DisplayResult(plist);
1996
1997 if (!WriteResult(plist))
1998 return kFALSE;
1999
2000 *fLog << all << GetDescriptor() << ": Done." << endl;
2001
2002 return kTRUE;
2003}
2004
2005// --------------------------------------------------------------------------
2006//
2007// Read the following containers from GetOutputFile()
2008// - MCalibrationChargeCam
2009// - MCalibrationQECam
2010// - MBadPixelsCam
2011//
2012Bool_t MJCalibration::ReadCalibrationCam()
2013{
2014
2015 if (IsNoStorage())
2016 return kFALSE;
2017
2018 const TString fname = GetOutputFile();
2019
2020 if (gSystem->AccessPathName(fname, kFileExists))
2021 {
2022 *fLog << err << "Input file " << fname << " doesn't exist." << endl;
2023 return kFALSE;
2024 }
2025
2026 *fLog << inf << "Reading from file: " << fname << endl;
2027
2028 TFile file(fname, "READ");
2029 if (fCalibrationCam.Read()<=0)
2030 {
2031 *fLog << err << "Unable to read MCalibrationChargeCam from " << fname << endl;
2032 return kFALSE;
2033 }
2034
2035 if (fQECam.Read()<=0)
2036 {
2037 *fLog << err << "Unable to read MCalibrationQECam from " << fname << endl;
2038 return kFALSE;
2039 }
2040
2041
2042 if (file.FindKey("MCalibrationRelTimeCam"))
2043 if (fRelTimeCam.Read()<=0)
2044 {
2045 *fLog << err << "Unable to read MCalibrationRelTimeCam from " << fname << endl;
2046 return kFALSE;
2047 }
2048
2049 if (file.FindKey("MBadPixelsCam"))
2050 {
2051 MBadPixelsCam bad;
2052 if (bad.Read()<=0)
2053 {
2054 *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
2055 return kFALSE;
2056 }
2057 fBadPixels.Merge(bad);
2058 }
2059
2060 if (fDisplay /*&& !fDisplay->GetCanvas("Pedestals")*/) // FIXME!
2061 fDisplay->Read();
2062
2063 return kTRUE;
2064}
2065
2066
2067// --------------------------------------------------------------------------
2068//
2069// Set the useage of the Blind Pixel device
2070//
2071void MJCalibration::SetUseBlindPixel(const Bool_t b)
2072{
2073 b ? SETBIT(fDevices,kUseBlindPixel) : CLRBIT(fDevices,kUseBlindPixel);
2074}
2075
2076// --------------------------------------------------------------------------
2077//
2078// Set the useage of the PIN Diode device
2079//
2080void MJCalibration::SetUsePINDiode(const Bool_t b)
2081{
2082 b ? SETBIT(fDevices,kUsePINDiode) : CLRBIT(fDevices,kUsePINDiode);
2083}
2084
2085/*
2086Bool_t MJCalibration::WriteEventloop(MEvtLoop &evtloop) const
2087{
2088 if (IsNoStorage())
2089 return kTRUE;
2090
2091 if (fPathOut.IsNull())
2092 return kTRUE;
2093
2094 const TString oname(GetOutputFile());
2095
2096 *fLog << inf << "Writing to file: " << oname << endl;
2097
2098 TFile file(oname, fOverwrite?"RECREATE":"NEW", "File created by MJCalibration", 9);
2099 if (!file.IsOpen())
2100 {
2101 *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
2102 return kFALSE;
2103 }
2104
2105 if (evtloop.Write(fName)<=0)
2106 {
2107 *fLog << err << "Unable to write MEvtloop to " << oname << endl;
2108 return kFALSE;
2109 }
2110
2111 return kTRUE;
2112}
2113*/
2114
2115Bool_t MJCalibration::WriteTasks(MTask *t1, MTask *t2) const
2116{
2117 if (IsNoStorage())
2118 return kTRUE;
2119
2120 TObjArray cont;
2121 if (t1)
2122 cont.Add(t1);
2123 if (t2)
2124 cont.Add(t2);
2125
2126 return WriteContainer(cont, GetOutputFileName(), fOverwrite?"RECREATE":"NEW");
2127}
2128
2129// --------------------------------------------------------------------------
2130//
2131// Write the result into the output file GetOutputFile(), if fOutputPath exists.
2132//
2133// The following containers are written:
2134// - MStatusDisplay
2135// - MCalibrationChargeCam or MCalibrationIntensityChargeCam
2136// - MCalibrationBlindCam or MCalibrationIntensityBlindCam
2137// - MCalibrationQECam or MCalibrationIntensityQECam
2138// - MCalibrationChargePINDiode
2139// - MBadPixelsCam
2140// If the flag kRelTimes is set, then also:
2141// - MCalibrationRelTimeCam or MCalibrationIntensityRelTimeCam
2142//
2143Bool_t MJCalibration::WriteResult(MParList &plist)
2144{
2145 TObjArray cont;
2146
2147 if (!IsNoStorage())
2148 {
2149 if (IsIntensity())
2150 {
2151 cont.Add(&fIntensBadCam);
2152 cont.Add(&fIntensCalibCam);
2153 cont.Add(&fIntensQECam);
2154 cont.Add(&fIntensBlindCam);
2155 }
2156 else
2157 {
2158 cont.Add(&fBadPixels);
2159 cont.Add(&fCalibrationCam);
2160 cont.Add(&fQECam);
2161 cont.Add(&fCalibrationBlindCam);
2162 }
2163 cont.Add(&fCalibrationPINDiode);
2164
2165 //if (IsRelTimes())
2166 cont.Add(IsIntensity() ? (TObject*)&fIntensRelTimeCam : (TObject*)&fRelTimeCam);
2167
2168 if (fExtractorCam.GetSize() != 0)
2169 cont.Add(&fExtractorCam);
2170
2171 TObject *pedcam = plist.FindObject("MPedestalCam");
2172 if (!pedcam)
2173 *fLog << warn << " - WARNING - MPedestalCam (fundamental)... not found for writing!" << endl;
2174 else
2175 cont.Add(pedcam);
2176
2177 TObject *geom = plist.FindObject("MGeomCam");
2178 if (!geom)
2179 *fLog << warn << " - WARNING - MGeomCam... not found for writing!" << endl;
2180 else
2181 cont.Add(geom);
2182 }
2183
2184 if (IsHistsStorage())
2185 {
2186 cont.Add(plist.FindObject("MHCalibrationChargeCam"));
2187 cont.Add(plist.FindObject("MHCalibrationChargeBlindCam"));
2188 cont.Add(plist.FindObject("MHCalibrationChargePINDiode"));
2189 if (IsRelTimes())
2190 cont.Add(plist.FindObject("MHCalibrationRelTimeCam"));
2191 }
2192
2193 return WriteContainer(cont, GetOutputFileName(), "UPDATE");
2194}
2195
2196void MJCalibration::DisplayDoubleProject(MHCamera *cam, const char* whatsmall, const char* whatbig) const
2197{
2198
2199 TArrayI inner(1);
2200 inner[0] = 0;
2201
2202 TArrayI outer(1);
2203 outer[0] = 1;
2204
2205 TArrayI s1(3);
2206 s1[0] = 6;
2207 s1[1] = 1;
2208 s1[2] = 2;
2209
2210 TArrayI s2(3);
2211 s2[0] = 3;
2212 s2[1] = 4;
2213 s2[2] = 5;
2214
2215 TVirtualPad *pad = gPad;
2216 pad->Divide(2,1);
2217
2218 TH1D *inout[2];
2219
2220 for (int i=0; i<2; i++)
2221 {
2222 pad->cd(i+1);
2223 gPad->SetBorderMode(0);
2224 gPad->SetTicks();
2225
2226 inout[i] = cam->ProjectionS(TArrayI(), TArrayI(1,&i), i==0 ? "Inner" : "Outer");
2227 FixDataCheckHist(inout[i]);
2228 inout[i]->SetTitle(Form("%s %s",cam->GetTitle(),i==0 ? "Inner" : "Outer"));
2229 inout[i]->SetDirectory(NULL);
2230 inout[i]->SetLineColor(kRed+i);
2231 inout[i]->SetBit(kCanDelete);
2232 inout[i]->Draw();
2233 //
2234 // Display the outliers as dead and noisy pixels
2235 //
2236 if (!inout[i]->Fit("gaus","0Q"))
2237 DisplayOutliers(inout[i],whatsmall,whatbig);
2238
2239 gPad->Modified();
2240 gPad->Update();
2241 TPaveStats *st = (TPaveStats*)inout[i]->GetListOfFunctions()->FindObject("stats");
2242 st->SetY1NDC(0.6);
2243 st->SetY2NDC(0.9);
2244 st->SetX1NDC(0.55);
2245 st->SetX2NDC(0.99);
2246 gPad->Modified();
2247 gPad->Update();
2248
2249 TLegend *leg2 = new TLegend(0.55,0.4,0.99,0.6);
2250
2251 //
2252 // Display the two half of the camera separately
2253 //
2254 TH1D *half[2];
2255 half[0] = cam->ProjectionS(s1, TArrayI(1,&i), "Sector 6-1-2");
2256 half[1] = cam->ProjectionS(s2, TArrayI(1,&i), "Sector 3-4-5");
2257
2258 for (int j=0; j<2; j++)
2259 {
2260 half[j]->SetLineColor(kRed+i+2*j+1);
2261 half[j]->SetDirectory(NULL);
2262 half[j]->SetBit(kCanDelete);
2263 half[j]->Draw("same");
2264 leg2->AddEntry(half[j], half[j]->GetName(), "l");
2265 }
2266 leg2->Draw();
2267 }
2268}
Note: See TracBrowser for help on using the repository browser.