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

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