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

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