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

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