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

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