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

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