source: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc@ 5729

Last change on this file since 5729 was 5701, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 74.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): Markus Gaug 02/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24//////////////////////////////////////////////////////////////////////////////
25//
26// MCalibrationChargeCalc
27//
28// Task to calculate the calibration conversion factors and quantum efficiencies
29// from the fit results to the summed FADC slice distributions delivered by
30// MCalibrationChargeCam, MCalibrationChargePix, MCalibrationChargeBlindPix and
31// MCalibrationChargePINDiode, calculated and filled by MHCalibrationChargeCam,
32// MHCalibrationChargePix, MHCalibrationChargeBlindPix and MHCalibrationChargePINDiode.
33//
34// PreProcess(): Initialize pointers to MCalibrationChargeCam, MCalibrationChargeBlindPix
35// MCalibrationChargePINDiode and MCalibrationQECam
36//
37// Initialize pulser light wavelength
38//
39// ReInit(): MCalibrationCam::InitSize(NumPixels) is called from MGeomApply (which allocates
40// memory in a TClonesArray of type MCalibrationChargePix)
41// Initializes pointer to MBadPixelsCam
42//
43// Process(): Nothing to be done, histograms getting filled by MHCalibrationChargeCam
44//
45// PostProcess(): - FinalizePedestals()
46// - FinalizeCharges()
47// - FinalizeFFactorMethod()
48// - FinalizeBadPixels()
49// - FinalizeBlindCam()
50// - FinalizePINDiode()
51// - FinalizeFFactorQECam()
52// - FinalizeBlindPixelQECam()
53// - FinalizePINDiodeQECam()
54//
55// Input Containers:
56// MCalibrationChargeCam
57// MCalibrationChargeBlindPix
58// MCalibrationChargePINDiode
59// MCalibrationQECam
60// MPedestalCam
61// MBadPixelsCam
62// MGeomCam
63// MTime
64//
65// Output Containers:
66// MCalibrationChargeCam
67// MCalibrationChargeBlindPix
68// MCalibrationChargePINDiode
69// MCalibrationQECam
70// MBadPixelsCam
71//
72//
73// Preliminary description of the calibration in photons (email from 12/02/04)
74//
75// Why calibrating in photons:
76// ===========================
77//
78// At the Barcelona meeting in 2002, we decided to calibrate the camera in
79// photons. This for the following reasons:
80//
81// * The physical quantity arriving at the camera are photons. This is
82// the direct physical information from the air shower. The photons
83// have a flux and a spectrum.
84//
85// * The photon fluxes depend mostly on the shower energy (with
86// corrections deriving from the observation conditions), while the photon
87// spectra depend mostly on the observation conditions: zenith angle,
88// quality of the air, also the impact parameter of the shower.
89//
90// * The photomultiplier, in turn, has different response properties
91// (quantum efficiencies) for photons of different colour. (Moreover,
92// different pixels have slightly different quantum efficiencies).
93// The resulting number of photo-electrons is then amplified (linearly)
94// with respect to the photo-electron flux.
95//
96// * In the ideal case, one would like to disentagle the effects
97// of the observation conditions from the primary particle energy (which
98// one likes to measure). To do so, one needs:
99//
100// 1) A reliable calibration relating the FADC counts to the photo-electron
101// flux -> This is accomplished with the F-Factor method.
102//
103// 2) A reliable calibration of the wavelength-dependent quantum efficiency
104// -> This is accomplished with the combination of the three methods,
105// together with QE-measurements performed by David in order to do
106// the interpolation.
107//
108// 3) A reliable calibration of the observation conditions. This means:
109// - Tracing the atmospheric conditions -> LIDAR
110// - Tracing the observation zenith angle -> Drive System
111//
112// 4) Some knowlegde about the impact parameter:
113// - This is the only part which cannot be accomplished well with a
114// single telescope. We would thus need to convolute the spectrum
115// over the distribution of impact parameters.
116//
117//
118// How an ideal calibration would look like:
119// =========================================
120//
121// We know from the combined PIN-Diode and Blind-Pixel Method the response of
122// each pixel to well-measured light fluxes in three representative
123// wavelengths (green, blue, UV). We also know the response to these light
124// fluxes in photo-electrons. Thus, we can derive:
125//
126// - conversion factors to photo-electrons
127// - conversion factors to photons in three wavelengths.
128//
129// Together with David's measurements and some MC-simulation, we should be
130// able to derive tables for typical Cherenkov-photon spectra - convoluted
131// with the impact parameters and depending on the athmospheric conditions
132// and the zenith angle (the "outer parameters").
133//
134// From these tables we can create "calibration tables" containing some
135// effective quantum efficiency depending on these outer parameters and which
136// are different for each pixel.
137//
138// In an ideal MCalibrate, one would thus have to convert first the FADC
139// slices to Photo-electrons and then, depending on the outer parameters,
140// look up the effective quantum efficiency and get the mean number of
141// photons which is then used for the further analysis.
142//
143// How the (first) MAGIC calibration should look like:
144// ===================================================
145//
146// For the moment, we have only one reliable calibration method, although
147// with very large systematic errors. This is the F-Factor method. Knowing
148// that the light is uniform over the whole camera (which I would not at all
149// guarantee in the case of the CT1 pulser), one could in principle already
150// perform a relative calibration of the quantum efficiencies in the UV.
151// However, the spread in QE at UV is about 10-15% (according to the plot
152// that Abelardo sent around last time. The spread in photo-electrons is 15%
153// for the inner pixels, but much larger (40%) for the outer ones.
154//
155// I'm not sure if we can already say that we have measured the relative
156// difference in quantum efficiency for the inner pixels and produce a first
157// QE-table for each pixel. To so, I would rather check in other wavelengths
158// (which we can do in about one-two weeks when the optical transmission of
159// the calibration trigger is installed).
160//
161// Thus, for the moment being, I would join Thomas proposal to calibrate in
162// photo-electrons and apply one stupid average quantum efficiency for all
163// pixels. This keeping in mind that we will have much preciser information
164// in about one to two weeks.
165//
166//
167// What MCalibrate should calculate and what should be stored:
168// ===========================================================
169//
170// It is clear that in the end, MCerPhotEvt will store photons.
171// MCalibrationCam stores the conversionfactors to photo-electrons and also
172// some tables of how to apply the conversion to photons, given the outer
173// parameters. This is not yet implemented and not even discussed.
174//
175// To start, I would suggest that we define the "average quantum efficiency"
176// (maybe something like 25+-3%) and apply them equally to all
177// photo-electrons. Later, this average factor can be easily replaced by a
178// pixel-dependent factor and later by a (pixel-dependent) table.
179//
180//
181//
182//////////////////////////////////////////////////////////////////////////////
183#include "MCalibrationChargeCalc.h"
184
185#include <TSystem.h>
186#include <TH1.h>
187#include <TF1.h>
188
189#include "MLog.h"
190#include "MLogManip.h"
191
192#include "MParList.h"
193
194#include "MStatusDisplay.h"
195
196#include "MRawEvtHeader.h"
197
198#include "MGeomCam.h"
199#include "MGeomPix.h"
200#include "MHCamera.h"
201
202#include "MPedestalCam.h"
203#include "MPedestalPix.h"
204
205#include "MCalibrationIntensityChargeCam.h"
206#include "MCalibrationIntensityQECam.h"
207#include "MCalibrationIntensityBlindCam.h"
208
209#include "MHCalibrationChargeCam.h"
210#include "MHCalibrationChargeBlindCam.h"
211
212#include "MCalibrationChargeCam.h"
213#include "MCalibrationChargePix.h"
214#include "MCalibrationChargePINDiode.h"
215#include "MCalibrationBlindPix.h"
216#include "MCalibrationBlindCam.h"
217
218#include "MExtractedSignalCam.h"
219#include "MExtractedSignalPix.h"
220#include "MExtractedSignalBlindPixel.h"
221#include "MExtractedSignalPINDiode.h"
222
223#include "MBadPixelsIntensityCam.h"
224#include "MBadPixelsCam.h"
225
226#include "MCalibrationQECam.h"
227#include "MCalibrationQEPix.h"
228
229ClassImp(MCalibrationChargeCalc);
230
231using namespace std;
232
233const Float_t MCalibrationChargeCalc::fgChargeLimit = 2.5;
234const Float_t MCalibrationChargeCalc::fgChargeErrLimit = 0.;
235const Float_t MCalibrationChargeCalc::fgChargeRelErrLimit = 1.;
236const Float_t MCalibrationChargeCalc::fgLambdaErrLimit = 0.2;
237const Float_t MCalibrationChargeCalc::fgLambdaCheckLimit = 0.5;
238const Float_t MCalibrationChargeCalc::fgPheErrLimit = 4.5;
239const Float_t MCalibrationChargeCalc::fgFFactorErrLimit = 4.5;
240const TString MCalibrationChargeCalc::fgNamePedestalCam = "MPedestalCam";
241// --------------------------------------------------------------------------
242//
243// Default constructor.
244//
245// Sets the pointer to fQECam and fGeom to NULL
246//
247// Calls AddToBranchList for:
248// - MRawEvtData.fHiGainPixId
249// - MRawEvtData.fLoGainPixId
250// - MRawEvtData.fHiGainFadcSamples
251// - MRawEvtData.fLoGainFadcSamples
252//
253// Initializes:
254// - fChargeLimit to fgChargeLimit
255// - fChargeErrLimit to fgChargeErrLimit
256// - fChargeRelErrLimit to fgChargeRelErrLimit
257// - fFFactorErrLimit to fgFFactorErrLimit
258// - fLambdaCheckLimit to fgLambdaCheckLimit
259// - fLambdaErrLimit to fgLambdaErrLimit
260// - fNamePedestalCam to fgNamePedestalCam
261// - fPheErrLimit to fgPheErrLimit
262// - fPulserColor to MCalibrationCam::kCT1
263// - fOutputPath to "."
264// - fOutputFile to "ChargeCalibStat.txt"
265// - flag debug to kFALSE
266//
267// Sets all checks
268//
269// Calls:
270// - Clear()
271//
272MCalibrationChargeCalc::MCalibrationChargeCalc(const char *name, const char *title)
273 : fGeom(NULL), fSignal(NULL), fHeader(NULL)
274{
275
276 fName = name ? name : "MCalibrationChargeCalc";
277 fTitle = title ? title : "Task to calculate the calibration constants and MCalibrationCam ";
278
279 AddToBranchList("MRawEvtData.fHiGainPixId");
280 AddToBranchList("MRawEvtData.fLoGainPixId");
281 AddToBranchList("MRawEvtData.fHiGainFadcSamples");
282 AddToBranchList("MRawEvtData.fLoGainFadcSamples");
283
284 SetChargeLimit ();
285 SetChargeErrLimit ();
286 SetChargeRelErrLimit ();
287 SetFFactorErrLimit ();
288 SetLambdaCheckLimit ();
289 SetLambdaErrLimit ();
290 SetNamePedestalCam ();
291 SetPheErrLimit ();
292 SetOutputPath ();
293 SetOutputFile ();
294 SetDebug ( kFALSE );
295
296 SetCheckDeadPixels ();
297 SetCheckDeviatingBehavior();
298 SetCheckExtractionWindow ();
299 SetCheckHistOverflow ();
300 SetCheckOscillations ();
301
302 Clear();
303
304}
305
306// --------------------------------------------------------------------------
307//
308// Sets:
309// - all variables to 0.,
310// - all flags to kFALSE
311// - all pointers to NULL
312// - the pulser colour to kNONE
313// - fBlindPixelFlags to 0
314// - fPINDiodeFlags to 0
315//
316void MCalibrationChargeCalc::Clear(const Option_t *o)
317{
318
319 fNumHiGainSamples = 0.;
320 fNumLoGainSamples = 0.;
321 fSqrtHiGainSamples = 0.;
322 fSqrtLoGainSamples = 0.;
323 fNumInnerFFactorMethodUsed = 0;
324
325 fNumProcessed = 0;
326
327 fIntensBad = NULL;
328 fBadPixels = NULL;
329 fIntensCam = NULL;
330 fCam = NULL;
331 fHCam = NULL;
332 fIntensQE = NULL;
333 fQECam = NULL;
334 fIntensBlind = NULL;
335 fBlindCam = NULL;
336 fHBlindCam = NULL;
337 fPINDiode = NULL;
338 fPedestals = NULL;
339
340 SetPulserColor ( MCalibrationCam::kNONE );
341
342 fBlindPixelFlags.Set(0);
343 fPINDiodeFlags .Set(0);
344 fResultFlags .Set(0);
345}
346
347
348// -----------------------------------------------------------------------------------
349//
350// The following container are searched for and execution aborted if not in MParList:
351// - MRawEvtHeader
352// - MPedestalCam
353// - MExtractedSignalCam
354//
355Int_t MCalibrationChargeCalc::PreProcess(MParList *pList)
356{
357
358 fHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
359 if (!fHeader)
360 {
361 *fLog << err << "MRawEvtHeader not found... abort." << endl;
362 return kFALSE;
363 }
364
365 //
366 // Containers that have to be there.
367 //
368 fSignal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
369 if (!fSignal)
370 {
371 *fLog << err << "MExtractedSignalCam not found... aborting" << endl;
372 return kFALSE;
373 }
374
375 if (fPedestals)
376 return kTRUE;
377
378 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCam), "MPedestalCam");
379 if (!fPedestals)
380 {
381 *fLog << err << GetDescriptor() << fNamePedestalCam << " not found... aborting" << endl;
382 return kFALSE;
383 }
384
385 return kTRUE;
386}
387
388
389// --------------------------------------------------------------------------
390//
391// Search for the following input containers and abort if not existing:
392// - MGeomCam
393// - MCalibrationIntensityChargeCam or MCalibrationChargeCam
394// - MCalibrationIntensityQECam or MCalibrationQECam
395// - MBadPixelsIntensityCam or MBadPixelsCam
396//
397// Search for the following input containers and give a warning if not existing:
398// - MCalibrationBlindPix
399// - MCalibrationChargePINDiode
400//
401// It retrieves the following variables from MCalibrationChargeCam:
402//
403// - fNumHiGainSamples
404// - fNumLoGainSamples
405//
406// It defines the PixId of every pixel in:
407//
408// - MCalibrationIntensityChargeCam
409// - MCalibrationChargeCam
410// - MCalibrationQECam
411//
412// It sets all pixels in excluded which have the flag fBadBixelsPix::IsBad() set in:
413//
414// - MCalibrationChargePix
415// - MCalibrationQEPix
416//
417// Sets the pulser colour and tests if it has not changed w.r.t. fPulserColor in:
418//
419// - MCalibrationChargeCam
420// - MCalibrationBlindPix (if existing)
421// - MCalibrationChargePINDiode (if existing)
422//
423Bool_t MCalibrationChargeCalc::ReInit(MParList *pList )
424{
425
426 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
427 if (!fGeom)
428 {
429 *fLog << err << "No MGeomCam found... aborting." << endl;
430 return kFALSE;
431 }
432
433 fIntensCam = (MCalibrationIntensityChargeCam*)pList->FindObject(AddSerialNumber("MCalibrationIntensityChargeCam"));
434 if (fIntensCam)
435 *fLog << inf << "Found MCalibrationIntensityChargeCam ... " << endl;
436 else
437 {
438 fCam = (MCalibrationChargeCam*)pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
439 if (!fCam)
440 {
441 *fLog << err << "Cannot find MCalibrationChargeCam ... abort." << endl;
442 *fLog << err << "Maybe you forget to call an MFillH for the MHCalibrationChargeCam before..." << endl;
443 return kFALSE;
444 }
445 }
446
447 fHCam = (MHCalibrationChargeCam*)pList->FindObject(AddSerialNumber("MHCalibrationChargeCam"));
448 if (!fHCam)
449 {
450 *fLog << err << "Cannot find MHCalibrationChargeCam ... abort." << endl;
451 *fLog << err << "Maybe you forget to call an MFillH for the MHCalibrationChargeCam before..." << endl;
452 return kFALSE;
453 }
454
455 fIntensQE = (MCalibrationIntensityQECam*)pList->FindObject(AddSerialNumber("MCalibrationIntensityQECam"));
456 if (fIntensQE)
457 *fLog << inf << "Found MCalibrationIntensityQECam ... " << endl;
458 else
459 {
460 fQECam = (MCalibrationQECam*)pList->FindObject(AddSerialNumber("MCalibrationQECam"));
461 if (!fQECam)
462 {
463 *fLog << err << "Cannot find MCalibrationQECam ... abort." << endl;
464 *fLog << err << "Maybe you forget to call an MFillH for the MHCalibrationQECam before..." << endl;
465 return kFALSE;
466 }
467 }
468
469 fIntensBlind = (MCalibrationIntensityBlindCam*)pList->FindObject(AddSerialNumber("MCalibrationIntensityBlindCam"));
470 if (fIntensBlind)
471 *fLog << inf << "Found MCalibrationIntensityBlindCam ... " << endl;
472 else
473 {
474 fBlindCam = (MCalibrationBlindCam*)pList->FindObject(AddSerialNumber("MCalibrationBlindCam"));
475 if (!fBlindCam)
476 {
477 *fLog << endl;
478 *fLog << warn << GetDescriptor()
479 << ": No MCalibrationBlindCam found... no Blind Pixel method! " << endl;
480 }
481 }
482
483 fHBlindCam = (MHCalibrationChargeBlindCam*)pList->FindObject(AddSerialNumber("MHCalibrationChargeBlindCam"));
484 if (!fHBlindCam)
485 {
486 *fLog << endl;
487 *fLog << warn << GetDescriptor()
488 << ": No MHCalibrationChargeBlindCam found... no Blind Pixel method! " << endl;
489 }
490
491 fIntensBad = (MBadPixelsIntensityCam*)pList->FindObject(AddSerialNumber("MBadPixelsIntensityCam"));
492 if (fIntensBad)
493 *fLog << inf << "Found MBadPixelsIntensityCam ... " << endl;
494 else
495 {
496 fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
497 if (!fBadPixels)
498 {
499 *fLog << err << "Cannot find MBadPixelsCam ... abort." << endl;
500 return kFALSE;
501 }
502 }
503
504 //
505 // Optional Containers
506 //
507 fPINDiode = (MCalibrationChargePINDiode*)pList->FindObject("MCalibrationChargePINDiode");
508 if (!fPINDiode)
509 {
510 *fLog << endl;
511 *fLog << warn << GetDescriptor()
512 << ": MCalibrationChargePINDiode not found... no PIN Diode method! " << endl;
513 }
514
515 MCalibrationQECam *qecam = fIntensQE
516 ? (MCalibrationQECam*) fIntensQE->GetCam() : fQECam;
517 MCalibrationChargeCam *chargecam = fIntensCam
518 ? (MCalibrationChargeCam*)fIntensCam->GetCam() : fCam;
519 MBadPixelsCam *badcam = fIntensBad
520 ? (MBadPixelsCam*) fIntensBad->GetCam() : fBadPixels;
521
522 UInt_t npixels = fGeom->GetNumPixels();
523
524 for (UInt_t i=0; i<npixels; i++)
525 {
526
527 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[i];
528 MCalibrationQEPix &pqe = (MCalibrationQEPix&) (*qecam) [i];
529 MBadPixelsPix &bad = (*badcam) [i];
530
531 if (bad.IsBad())
532 {
533 pix.SetExcluded();
534 pqe.SetExcluded();
535 continue;
536 }
537
538 if (IsDebug())
539 pix.SetDebug();
540 }
541
542 return kTRUE;
543}
544
545// ----------------------------------------------------------------------------------
546//
547// Set the correct colour to the charge containers
548//
549Int_t MCalibrationChargeCalc::Process()
550{
551
552 const MCalibrationCam::PulserColor_t col = fHeader->GetPulserColor();
553
554 if (col == fPulserColor)
555 {
556 fNumProcessed++;
557 return kTRUE;
558 }
559
560 if (col == MCalibrationCam::kNONE)
561 return kTRUE;
562
563 //
564 // Now retrieve the colour and check if not various colours have been used
565 //
566 if (!fIntensCam)
567 {
568 if (fPulserColor != MCalibrationCam::kNONE)
569 {
570 *fLog << err << "Multiple colours used simultaneously in calibration file. Will reset histograms "
571 << " and merge the MCalibrationQECam!" << endl;
572 fHCam->Finalize();
573 fHBlindCam->Finalize();
574 fHCam->ResetHists();
575 fHBlindCam->ResetHists();
576 Finalize();
577 }
578 }
579
580 fPulserColor = col;
581
582 *fLog << inf << "Found new colour ... " << flush;
583
584 switch (col)
585 {
586 case MCalibrationCam::kGREEN: *fLog << "Green"; break;
587 case MCalibrationCam::kBLUE: *fLog << "Blue"; break;
588 case MCalibrationCam::kUV: *fLog << "UV"; break;
589 case MCalibrationCam::kCT1: *fLog << "CT1"; break;
590 default: break;
591 }
592
593 *fLog << inf << " with strength: " << fHeader->GetPulserStrength() << endl;
594
595 if (fPINDiode)
596 fPINDiode->SetColor( fPulserColor );
597
598 fNumProcessed = 0;
599
600 return kTRUE;
601}
602
603// -----------------------------------------------------------------------
604//
605// Return if number of executions is null.
606//
607Int_t MCalibrationChargeCalc::PostProcess()
608{
609
610 if (GetNumExecutions()==0)
611 return kFALSE;
612
613 if (fPulserColor == MCalibrationCam::kNONE)
614 return kTRUE;
615
616 if (fNumProcessed == 0)
617 return kTRUE;
618
619 *fLog << endl;
620
621 return Finalize();
622}
623
624// -----------------------------------------------------------------------
625//
626// Return kTRUE if fPulserColor is kNONE
627//
628// First loop over pixels, average areas and sectors, call:
629// - FinalizePedestals()
630// - FinalizeCharges()
631// for every entry. Count number of valid pixels in loop and return kFALSE
632// if there are none (the "Michele check").
633//
634// Call FinalizeBadPixels()
635//
636// Call FinalizeFFactorMethod() (second and third loop over pixels and areas)
637//
638// Call FinalizeBlindCam()
639// Call FinalizePINDiode()
640//
641// Call FinalizeFFactorQECam() (fourth loop over pixels and areas)
642// Call FinalizeBlindPixelQECam() (fifth loop over pixels and areas)
643// Call FinalizePINDiodeQECam() (sixth loop over pixels and areas)
644//
645// Call FinalizeUnsuitablePixels()
646//
647// Call MParContainer::SetReadyToSave() for fIntensCam, fCam, fQECam, fBadPixels and
648// fBlindCam and fPINDiode if they exist
649//
650// Print out some statistics
651//
652Int_t MCalibrationChargeCalc::Finalize()
653{
654
655 fNumHiGainSamples = fSignal->GetNumUsedHiGainFADCSlices();
656 fNumLoGainSamples = fSignal->GetNumUsedLoGainFADCSlices();
657
658 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
659 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
660
661 if (fPINDiode)
662 if (!fPINDiode->IsValid())
663 {
664 *fLog << warn << GetDescriptor()
665 << ": MCalibrationChargePINDiode is declared not valid... no PIN Diode method! " << endl;
666 fPINDiode = NULL;
667 }
668
669 MCalibrationBlindCam *blindcam = fIntensBlind
670 ? (MCalibrationBlindCam*)fIntensBlind->GetCam() : fBlindCam;
671 MCalibrationQECam *qecam = fIntensQE
672 ? (MCalibrationQECam*) fIntensQE->GetCam() : fQECam;
673 MCalibrationChargeCam *chargecam = fIntensCam
674 ? (MCalibrationChargeCam*)fIntensCam->GetCam() : fCam;
675 MBadPixelsCam *badcam = fIntensBad
676 ? (MBadPixelsCam*) fIntensBad->GetCam() : fBadPixels;
677
678 //
679 // First loop over pixels, call FinalizePedestals and FinalizeCharges
680 //
681 Int_t nvalid = 0;
682
683 for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
684 {
685
686 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[pixid];
687 //
688 // Check if the pixel has been excluded from the fits
689 //
690 if (pix.IsExcluded())
691 continue;
692
693 MPedestalPix &ped = (*fPedestals)[pixid];
694 MBadPixelsPix &bad = (*badcam) [pixid];
695
696 const Int_t aidx = (*fGeom)[pixid].GetAidx();
697
698 FinalizePedestals(ped,pix,aidx);
699
700 if (FinalizeCharges(pix,bad,"pixel "))
701 nvalid++;
702 }
703
704 *fLog << endl;
705 //
706 // The Michele check ...
707 //
708 if (nvalid == 0)
709 {
710 *fLog << err << GetDescriptor() << ": All pixels have non-valid calibration. "
711 << "Did you forget to fill the histograms "
712 << "(filling MHCalibrationChargeCam from MExtractedSignalCam using MFillH) ? " << endl;
713 *fLog << err << GetDescriptor() << ": Or, maybe, you have used a pedestal run "
714 << "instead of a calibration run " << endl;
715 return kFALSE;
716 }
717
718 for (UInt_t aidx=0; aidx<fGeom->GetNumAreas(); aidx++)
719 {
720
721 const MPedestalPix &ped = fPedestals->GetAverageArea(aidx);
722 MCalibrationChargePix &pix = (MCalibrationChargePix&)chargecam->GetAverageArea(aidx);
723
724 FinalizePedestals(ped,pix,aidx);
725 FinalizeCharges(pix,
726 fIntensCam ? fIntensCam->GetAverageBadArea(aidx) : fCam->GetAverageBadArea(aidx),
727 "area id");
728 }
729
730 *fLog << endl;
731
732 for (UInt_t sector=0; sector<fGeom->GetNumSectors(); sector++)
733 {
734
735 const MPedestalPix &ped = fPedestals->GetAverageSector(sector);
736
737 MCalibrationChargePix &pix = (MCalibrationChargePix&)chargecam->GetAverageSector(sector);
738 FinalizePedestals(ped,pix, 0);
739 }
740
741 *fLog << endl;
742
743 //
744 // Finalize Bad Pixels
745 //
746 FinalizeBadPixels();
747
748 //
749 // Finalize F-Factor method
750 //
751 if (FinalizeFFactorMethod())
752 chargecam->SetFFactorMethodValid(kTRUE);
753 else
754 {
755 *fLog << warn << "Could not calculate the photons flux from the F-Factor method " << endl;
756 chargecam->SetFFactorMethodValid(kFALSE);
757 return kFALSE;
758 }
759
760 *fLog << endl;
761 //
762 // Finalize Blind Pixel
763 //
764 qecam->SetBlindPixelMethodValid(FinalizeBlindCam());
765
766 //
767 // Finalize PIN Diode
768 //
769 qecam->SetBlindPixelMethodValid(FinalizePINDiode());
770
771 //
772 // Finalize QE Cam
773 //
774 FinalizeFFactorQECam();
775 FinalizeBlindPixelQECam();
776 FinalizePINDiodeQECam();
777 FinalizeCombinedQECam();
778
779 //
780 // Re-direct the output to an ascii-file from now on:
781 //
782 MLog *oldlog = fLog;
783 MLog asciilog;
784 if (!fOutputFile.IsNull())
785 {
786 asciilog.SetOutputFile(GetOutputFile(),kTRUE);
787 SetLogStream(&asciilog);
788 }
789
790 //
791 // Finalize calibration statistics
792 //
793 FinalizeUnsuitablePixels();
794
795 chargecam->SetReadyToSave();
796 qecam ->SetReadyToSave();
797 badcam ->SetReadyToSave();
798
799 if (blindcam)
800 blindcam->SetReadyToSave();
801 if (fPINDiode)
802 fPINDiode->SetReadyToSave();
803
804 *fLog << inf << endl;
805 *fLog << GetDescriptor() << ": Fatal errors statistics:" << endl;
806
807 PrintUncalibrated(MBadPixelsPix::kChargeIsPedestal,
808 Form("%s%2.1f%s","Signal less than ",fChargeLimit," Pedestal RMS: "));
809 PrintUncalibrated(MBadPixelsPix::kChargeRelErrNotValid,
810 Form("%s%2.1f%s","Signal Error bigger than ",fChargeRelErrLimit," times Mean Signal: "));
811 PrintUncalibrated(MBadPixelsPix::kLoGainSaturation,
812 "Low Gain Saturation: ");
813 PrintUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin,
814 Form("%s%2.1f%s","Mean Abs. Arr. Time in First ",1.," Bin(s): "));
815 PrintUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins,
816 Form("%s%2.1f%s","Mean Abs. Arr. Time in Last ",2.," Bin(s): "));
817 PrintUncalibrated(MBadPixelsPix::kHiGainOverFlow,
818 "Pixels with High Gain Overflow: ");
819 PrintUncalibrated(MBadPixelsPix::kLoGainOverFlow,
820 "Pixels with Low Gain Overflow : ");
821
822 *fLog << inf << endl;
823 *fLog << GetDescriptor() << ": Unreliable errors statistics:" << endl;
824
825 PrintUncalibrated(MBadPixelsPix::kChargeSigmaNotValid,
826 "Signal Sigma smaller than Pedestal RMS: ");
827 PrintUncalibrated(MBadPixelsPix::kHiGainOscillating,
828 "Changing Hi Gain signal over time: ");
829 PrintUncalibrated(MBadPixelsPix::kLoGainOscillating,
830 "Changing Lo Gain signal over time: ");
831 PrintUncalibrated(MBadPixelsPix::kHiGainNotFitted,
832 "Unsuccesful Gauss fit to the Hi Gain: ");
833 PrintUncalibrated(MBadPixelsPix::kLoGainNotFitted,
834 "Unsuccesful Gauss fit to the Lo Gain: ");
835 PrintUncalibrated(MBadPixelsPix::kDeviatingNumPhes,
836 "Deviating number of phes: ");
837 PrintUncalibrated(MBadPixelsPix::kDeviatingFFactor,
838 "Deviating F-Factor: ");
839
840 if (!fOutputFile.IsNull())
841 SetLogStream(oldlog);
842
843 return kTRUE;
844}
845
846// ----------------------------------------------------------------------------------
847//
848// Retrieves pedestal and pedestal RMS from MPedestalPix
849// Retrieves total entries from MPedestalCam
850// Sets pedestal*fNumHiGainSamples and pedestal*fNumLoGainSamples in MCalibrationChargePix
851// Sets pedRMS *fSqrtHiGainSamples and pedRMS *fSqrtLoGainSamples in MCalibrationChargePix
852//
853// If the flag MCalibrationPix::IsHiGainSaturation() is set, call also:
854// - MCalibrationChargePix::CalcLoGainPedestal()
855//
856void MCalibrationChargeCalc::FinalizePedestals(const MPedestalPix &ped, MCalibrationChargePix &cal, const Int_t aidx)
857{
858
859 //
860 // get the pedestals
861 //
862 const Float_t pedes = ped.GetPedestal();
863 const Float_t prms = ped.GetPedestalRms();
864 const Int_t num = fPedestals->GetTotalEntries();
865
866 //
867 // RMS error set by PedCalcFromLoGain, 0 in case MPedCalcPedRun was used.
868 //
869 const Float_t prmserr = num>0 ? prms/TMath::Sqrt(2.*num) : ped.GetPedestalRmsError();
870
871 //
872 // set them in the calibration camera
873 //
874 if (cal.IsHiGainSaturation())
875 {
876 cal.SetPedestal(pedes * fNumLoGainSamples,
877 prms * fSqrtLoGainSamples,
878 prmserr * fSqrtLoGainSamples);
879 cal.CalcLoGainPedestal(fNumLoGainSamples);
880 }
881 else
882 {
883
884 cal.SetPedestal(pedes * fNumHiGainSamples,
885 prms * fSqrtHiGainSamples,
886 prmserr * fSqrtHiGainSamples);
887 }
888
889}
890
891// ----------------------------------------------------------------------------------------------------
892//
893// Check fit results validity. Bad Pixels flags are set if:
894//
895// 1) Pixel has a mean smaller than fChargeLimit*PedRMS ( Flag: MBadPixelsPix::kChargeIsPedestal)
896// 2) Pixel has a mean error smaller than fChargeErrLimit ( Flag: MBadPixelsPix::kChargeErrNotValid)
897// 3) Pixel has mean smaller than fChargeRelVarLimit times its mean error
898// ( Flag: MBadPixelsPix::kChargeRelErrNotValid)
899// 4) Pixel has a sigma bigger than its Pedestal RMS ( Flag: MBadPixelsPix::kChargeSigmaNotValid )
900//
901// Further returns if flags: MBadPixelsPix::kUnsuitableRun is set
902//
903// Calls MCalibrationChargePix::CalcReducedSigma() and sets flag: MBadPixelsPix::kChargeIsPedestal
904// and returns kFALSE if not succesful.
905//
906// Calls MCalibrationChargePix::CalcFFactor() and sets flag: MBadPixelsPix::kDeviatingNumPhes)
907// and returns kFALSE if not succesful.
908//
909// Calls MCalibrationChargePix::CalcConvFFactor()and sets flag: MBadPixelsPix::kDeviatingNumPhes)
910// and returns kFALSE if not succesful.
911//
912Bool_t MCalibrationChargeCalc::FinalizeCharges(MCalibrationChargePix &cal, MBadPixelsPix &bad, const char* what)
913{
914
915 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
916 return kFALSE;
917
918 if (cal.GetMean() < fChargeLimit*cal.GetPedRms())
919 {
920 *fLog << warn
921 << Form("Fitted Charge: %5.2f < %2.1f",cal.GetMean(),fChargeLimit)
922 << Form(" * Pedestal RMS %5.2f in %s%3i",cal.GetPedRms(),what,cal.GetPixId()) << endl;
923 bad.SetUncalibrated( MBadPixelsPix::kChargeIsPedestal);
924 }
925
926 if (cal.GetMean() < fChargeRelErrLimit*cal.GetMeanErr())
927 {
928 *fLog << warn
929 << Form("Fitted Charge: %4.2f < %2.1f",cal.GetMean(),fChargeRelErrLimit)
930 << Form(" * its error %4.2f in %s%3i",cal.GetMeanErr(),what,cal.GetPixId()) << endl;
931 bad.SetUncalibrated( MBadPixelsPix::kChargeRelErrNotValid );
932 }
933
934 if (cal.GetSigma() < cal.GetPedRms())
935 {
936 *fLog << warn
937 << Form("Sigma of Fitted Charge: %6.2f <",cal.GetSigma())
938 << Form(" Ped. RMS=%5.2f in %s%3i",cal.GetPedRms(),what,cal.GetPixId()) << endl;
939 bad.SetUncalibrated( MBadPixelsPix::kChargeSigmaNotValid );
940 return kFALSE;
941 }
942
943 if (!cal.CalcReducedSigma())
944 {
945 *fLog << warn
946 << Form("Could not calculate the reduced sigma in %s: ",what)
947 << Form(" %4i",cal.GetPixId())
948 << endl;
949 bad.SetUncalibrated( MBadPixelsPix::kChargeSigmaNotValid );
950 return kFALSE;
951 }
952
953 if (!cal.CalcFFactor())
954 {
955 *fLog << warn
956 << Form("Could not calculate the F-Factor in %s: ",what)
957 << Form(" %4i",cal.GetPixId())
958 << endl;
959 bad.SetUncalibrated(MBadPixelsPix::kDeviatingNumPhes);
960 return kFALSE;
961 }
962
963 if (cal.GetPheFFactorMethod() < 0.)
964 {
965 bad.SetUncalibrated(MBadPixelsPix::kDeviatingNumPhes);
966 bad.SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
967 cal.SetFFactorMethodValid(kFALSE);
968 return kFALSE;
969 }
970
971 if (!cal.CalcConvFFactor())
972 {
973 *fLog << warn
974 << Form("Could not calculate the Conv. FADC counts to Phes in %s: ",what)
975 << Form(" %4i",cal.GetPixId())
976 << endl;
977 bad.SetUncalibrated(MBadPixelsPix::kDeviatingNumPhes);
978 return kFALSE;
979 }
980
981 return kTRUE;
982}
983
984
985
986// -----------------------------------------------------------------------------------
987//
988// Sets pixel to MBadPixelsPix::kUnsuitableRun, if one of the following flags is set:
989// - MBadPixelsPix::kChargeIsPedestal
990// - MBadPixelsPix::kChargeRelErrNotValid
991// - MBadPixelsPix::kMeanTimeInFirstBin
992// - MBadPixelsPix::kMeanTimeInLast2Bins
993// - MBadPixelsPix::kDeviatingNumPhes
994// - MBadPixelsPix::kHiGainOverFlow
995// - MBadPixelsPix::kLoGainOverFlow
996//
997// - Call MCalibrationPix::SetExcluded() for the bad pixels
998//
999// Sets pixel to MBadPixelsPix::kUnreliableRun, if one of the following flags is set:
1000// - MBadPixelsPix::kChargeSigmaNotValid
1001//
1002void MCalibrationChargeCalc::FinalizeBadPixels()
1003{
1004
1005 MBadPixelsCam *badcam = fIntensBad
1006 ? (MBadPixelsCam*) fIntensBad->GetCam() : fBadPixels;
1007 MCalibrationChargeCam *chargecam = fIntensCam
1008 ? (MCalibrationChargeCam*)fIntensCam->GetCam() : fCam;
1009
1010 for (Int_t i=0; i<badcam->GetSize(); i++)
1011 {
1012
1013 MBadPixelsPix &bad = (*badcam) [i];
1014 MCalibrationPix &pix = (*chargecam)[i];
1015
1016 if (IsCheckDeadPixels())
1017 {
1018 if (bad.IsUncalibrated( MBadPixelsPix::kChargeIsPedestal))
1019 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
1020
1021 if (bad.IsUncalibrated( MBadPixelsPix::kChargeErrNotValid ))
1022 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
1023
1024 if (bad.IsUncalibrated( MBadPixelsPix::kChargeRelErrNotValid ))
1025 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
1026 }
1027
1028 if (IsCheckExtractionWindow())
1029 {
1030 if (bad.IsUncalibrated( MBadPixelsPix::kMeanTimeInFirstBin ))
1031 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
1032
1033 if (bad.IsUncalibrated( MBadPixelsPix::kMeanTimeInLast2Bins ))
1034 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
1035 }
1036
1037 if (IsCheckDeviatingBehavior())
1038 {
1039 if (bad.IsUncalibrated( MBadPixelsPix::kDeviatingNumPhes ))
1040 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
1041 }
1042
1043 if (IsCheckHistOverflow())
1044 {
1045 if (bad.IsUncalibrated( MBadPixelsPix::kHiGainOverFlow ))
1046 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
1047
1048 if (bad.IsUncalibrated( MBadPixelsPix::kLoGainOverFlow ))
1049 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
1050 }
1051
1052 if (bad.IsUnsuitable( MBadPixelsPix::kUnsuitableRun ))
1053 pix.SetExcluded();
1054
1055 if (bad.IsUncalibrated( MBadPixelsPix::kChargeSigmaNotValid ))
1056 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
1057 }
1058}
1059
1060// ------------------------------------------------------------------------
1061//
1062//
1063// First loop: Calculate a mean and mean RMS of photo-electrons per area index
1064// Include only pixels which are not MBadPixelsPix::kUnsuitableRun nor
1065// MBadPixelsPix::kChargeSigmaNotValid (see FinalizeBadPixels()) and set
1066// MCalibrationChargePix::SetFFactorMethodValid(kFALSE) in that case.
1067//
1068// Second loop: Get mean number of photo-electrons and its RMS including
1069// only pixels with flag MCalibrationChargePix::IsFFactorMethodValid()
1070// and further exclude those deviating by more than fPheErrLimit mean
1071// sigmas from the mean (obtained in first loop). Set
1072// MBadPixelsPix::kDeviatingNumPhes if excluded.
1073//
1074// For the suitable pixels with flag MBadPixelsPix::kChargeSigmaNotValid
1075// set the number of photo-electrons as the mean number of photo-electrons
1076// calculated in that area index.
1077//
1078// Set weighted mean and variance of photo-electrons per area index in:
1079// average area pixels of MCalibrationChargeCam (obtained from:
1080// MCalibrationChargeCam::GetAverageArea() )
1081//
1082// Set weighted mean and variance of photo-electrons per sector in:
1083// average sector pixels of MCalibrationChargeCam (obtained from:
1084// MCalibrationChargeCam::GetAverageSector() )
1085//
1086//
1087// Third loop: Set mean number of photo-electrons and its RMS in the pixels
1088// only excluded as: MBadPixelsPix::kChargeSigmaNotValid
1089//
1090Bool_t MCalibrationChargeCalc::FinalizeFFactorMethod()
1091{
1092
1093 MBadPixelsCam *badcam = fIntensBad
1094 ? (MBadPixelsCam*) fIntensBad->GetCam() : fBadPixels;
1095 MCalibrationChargeCam *chargecam = fIntensCam
1096 ? (MCalibrationChargeCam*)fIntensCam->GetCam() : fCam;
1097
1098 const Int_t npixels = fGeom->GetNumPixels();
1099 const Int_t nareas = fGeom->GetNumAreas();
1100 const Int_t nsectors = fGeom->GetNumSectors();
1101
1102 TArrayF lowlim (nareas);
1103 TArrayF upplim (nareas);
1104 TArrayD areavars (nareas);
1105 TArrayD areaweights (nareas);
1106 TArrayD sectorweights (nsectors);
1107 TArrayD areaphes (nareas);
1108 TArrayD sectorphes (nsectors);
1109 TArrayI numareavalid (nareas);
1110 TArrayI numsectorvalid(nsectors);
1111
1112 //
1113 // First loop: Get mean number of photo-electrons and the RMS
1114 // The loop is only to recognize later pixels with very deviating numbers
1115 //
1116 MHCamera camphes(*fGeom,"Camphes","Phes in Camera");
1117
1118 for (Int_t i=0; i<npixels; i++)
1119 {
1120
1121 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[i];
1122 MBadPixelsPix &bad = (*badcam)[i];
1123
1124 if (!pix.IsFFactorMethodValid())
1125 continue;
1126
1127 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
1128 {
1129 pix.SetFFactorMethodValid(kFALSE);
1130 continue;
1131 }
1132
1133 if (bad.IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid))
1134 continue;
1135
1136 const Float_t nphe = pix.GetPheFFactorMethod();
1137 const Int_t aidx = (*fGeom)[i].GetAidx();
1138
1139 camphes.Fill(i,nphe);
1140 camphes.SetUsed(i);
1141
1142 areaphes [aidx] += nphe;
1143 areavars [aidx] += nphe*nphe;
1144 numareavalid[aidx] ++;
1145 }
1146
1147 for (Int_t i=0; i<nareas; i++)
1148 {
1149 if (numareavalid[i] == 0)
1150 {
1151 *fLog << warn << GetDescriptor() << ": No pixels with valid number of photo-electrons found "
1152 << "in area index: " << i << endl;
1153 continue;
1154 }
1155
1156 if (numareavalid[i] == 1)
1157 areavars[i] = 0.;
1158 else if (numareavalid[i] == 0)
1159 {
1160 areaphes[i] = -1.;
1161 areaweights[i] = -1.;
1162 }
1163 else
1164 {
1165 areavars[i] = (areavars[i] - areaphes[i]*areaphes[i]/numareavalid[i]) / (numareavalid[i]-1);
1166 areaphes[i] = areaphes[i] / numareavalid[i];
1167 }
1168
1169 if (areavars[i] < 0.)
1170 {
1171 *fLog << warn << GetDescriptor() << ": No pixels with valid variance of photo-electrons found "
1172 << "in area index: " << i << endl;
1173 continue;
1174 }
1175
1176 lowlim [i] = areaphes[i] - fPheErrLimit*TMath::Sqrt(areavars[i]);
1177 upplim [i] = areaphes[i] + fPheErrLimit*TMath::Sqrt(areavars[i]);
1178
1179 TH1D *hist = camphes.ProjectionS(TArrayI(),TArrayI(1,&i),"_py",100);
1180 hist->Fit("gaus","Q");
1181 const Float_t mean = hist->GetFunction("gaus")->GetParameter(1);
1182 const Float_t sigma = hist->GetFunction("gaus")->GetParameter(2);
1183 const Int_t ndf = hist->GetFunction("gaus")->GetNDF();
1184
1185 if (IsDebug())
1186 hist->DrawClone();
1187
1188 if (ndf < 2)
1189 {
1190 *fLog << warn << GetDescriptor() << ": Cannot use a Gauss fit to the number of photo-electrons "
1191 << "in the camera with area index: " << i << endl;
1192 *fLog << warn << GetDescriptor() << ": Number of dof.: " << ndf << " is smaller than 2 " << endl;
1193 *fLog << warn << GetDescriptor() << ": Will use the simple mean and rms " << endl;
1194 delete hist;
1195 continue;
1196 }
1197
1198 const Double_t prob = hist->GetFunction("gaus")->GetProb();
1199
1200 if (prob < 0.001)
1201 {
1202 *fLog << warn << GetDescriptor() << ": Cannot use a Gauss fit to the number of photo-electrons "
1203 << "in the camera with area index: " << i << endl;
1204 *fLog << warn << GetDescriptor() << ": Fit probability " << prob
1205 << " is smaller than 0.001 " << endl;
1206 *fLog << warn << GetDescriptor() << ": Will use the simple mean and rms " << endl;
1207 delete hist;
1208 continue;
1209 }
1210
1211 if (mean < 0.)
1212 {
1213 *fLog << inf << GetDescriptor() << ": Fitted mean number of photo-electrons "
1214 << "with area idx " << i << ": " << mean << " is smaller than 0. " << endl;
1215 *fLog << warn << GetDescriptor() << ": Will use the simple mean and rms " << endl;
1216 delete hist;
1217 continue;
1218 }
1219
1220 *fLog << inf << GetDescriptor() << ": Mean number of phes with area idx " << i << ": "
1221 << Form("%7.2f+-%6.2f",mean,sigma) << endl;
1222
1223 lowlim [i] = mean - fPheErrLimit*sigma;
1224 upplim [i] = mean + fPheErrLimit*sigma;
1225
1226 delete hist;
1227 }
1228
1229 *fLog << endl;
1230
1231 numareavalid.Reset();
1232 areaphes .Reset();
1233 areavars .Reset();
1234 //
1235 // Second loop: Get mean number of photo-electrons and its RMS excluding
1236 // pixels deviating by more than fPheErrLimit sigma.
1237 // Set the conversion factor FADC counts to photo-electrons
1238 //
1239 for (Int_t i=0; i<npixels; i++)
1240 {
1241
1242 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[i];
1243
1244 if (!pix.IsFFactorMethodValid())
1245 continue;
1246
1247 MBadPixelsPix &bad = (*badcam)[i];
1248
1249 if (bad.IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid))
1250 continue;
1251
1252 const Float_t nvar = pix.GetPheFFactorMethodVar();
1253 if (nvar <= 0.)
1254 {
1255 pix.SetFFactorMethodValid(kFALSE);
1256 continue;
1257 }
1258
1259 const Int_t aidx = (*fGeom)[i].GetAidx();
1260 const Int_t sector = (*fGeom)[i].GetSector();
1261 const Float_t area = (*fGeom)[i].GetA();
1262 const Float_t nphe = pix.GetPheFFactorMethod();
1263
1264 if ( nphe < lowlim[aidx] || nphe > upplim[aidx] )
1265 {
1266 *fLog << warn << "Number of phes: "
1267 << Form("%7.2f out of %3.1f sigma limit: ",nphe,fPheErrLimit)
1268 << Form("[%7.2f,%7.2f] pixel%4i",lowlim[aidx],upplim[aidx],i) << endl;
1269 bad.SetUncalibrated( MBadPixelsPix::kDeviatingNumPhes );
1270 if (IsCheckDeviatingBehavior())
1271 {
1272 bad.SetUnsuitable ( MBadPixelsPix::kUnsuitableRun );
1273 pix.SetFFactorMethodValid(kFALSE);
1274 }
1275 continue;
1276 }
1277
1278 areaweights [aidx] += nphe*nphe;
1279 areaphes [aidx] += nphe;
1280 numareavalid [aidx] ++;
1281
1282 if (aidx == 0)
1283 fNumInnerFFactorMethodUsed++;
1284
1285 sectorweights [sector] += nphe*nphe/area/area;
1286 sectorphes [sector] += nphe/area;
1287 numsectorvalid[sector] ++;
1288 }
1289
1290 *fLog << endl;
1291
1292 for (Int_t aidx=0; aidx<nareas; aidx++)
1293 {
1294
1295 MCalibrationChargePix &apix = (MCalibrationChargePix&)chargecam->GetAverageArea(aidx);
1296
1297 if (numareavalid[aidx] == 1)
1298 areaweights[aidx] = 0.;
1299 else if (numareavalid[aidx] == 0)
1300 {
1301 areaphes[aidx] = -1.;
1302 areaweights[aidx] = -1.;
1303 }
1304 else
1305 {
1306 areaweights[aidx] = (areaweights[aidx] - areaphes[aidx]*areaphes[aidx]/numareavalid[aidx])
1307 / (numareavalid[aidx]-1);
1308 areaphes[aidx] /= numareavalid[aidx];
1309 }
1310
1311 if (areaweights[aidx] < 0. || areaphes[aidx] <= 0.)
1312 {
1313 *fLog << warn << GetDescriptor()
1314 << ": Mean number phes from area index " << aidx << " could not be calculated: "
1315 << " Mean: " << areaphes[aidx]
1316 << " Variance: " << areaweights[aidx] << endl;
1317 apix.SetFFactorMethodValid(kFALSE);
1318 continue;
1319 }
1320
1321 *fLog << inf << GetDescriptor()
1322 << ": Average total phes for area idx " << aidx << ": "
1323 << Form("%7.2f +- 6.2f",areaphes[aidx],TMath::Sqrt(areaweights[aidx])) << endl;
1324
1325 apix.SetPheFFactorMethod ( areaphes[aidx] );
1326 apix.SetPheFFactorMethodVar( areaweights[aidx] / numareavalid[aidx] );
1327 apix.SetFFactorMethodValid ( kTRUE );
1328
1329 }
1330
1331 *fLog << endl;
1332
1333 for (Int_t sector=0; sector<nsectors; sector++)
1334 {
1335
1336 if (numsectorvalid[sector] == 1)
1337 sectorweights[sector] = 0.;
1338 else if (numsectorvalid[sector] == 0)
1339 {
1340 sectorphes[sector] = -1.;
1341 sectorweights[sector] = -1.;
1342 }
1343 else
1344 {
1345 sectorweights[sector] = (sectorweights[sector]
1346 - sectorphes[sector]*sectorphes[sector]/numsectorvalid[sector]
1347 )
1348 / (numsectorvalid[sector]-1.);
1349 sectorphes[sector] /= numsectorvalid[sector];
1350 }
1351
1352 MCalibrationChargePix &spix = (MCalibrationChargePix&)chargecam->GetAverageSector(sector);
1353
1354 if (sectorweights[sector] < 0. || sectorphes[sector] <= 0.)
1355 {
1356 *fLog << warn << GetDescriptor()
1357 <<": Mean number phes/area for sector " << sector << " could not be calculated: "
1358 << " Mean: " << sectorphes[sector]
1359 << " Variance: " << sectorweights[sector] << endl;
1360 spix.SetFFactorMethodValid(kFALSE);
1361 continue;
1362 }
1363
1364 *fLog << inf << GetDescriptor()
1365 << ": Avg number phes/mm^2 in sector " << sector << ": "
1366 << Form("%5.3f+-%4.3f",sectorphes[sector],TMath::Sqrt(sectorweights[sector]))
1367 << endl;
1368
1369 spix.SetPheFFactorMethod ( sectorphes[sector] );
1370 spix.SetPheFFactorMethodVar( sectorweights[sector] / numsectorvalid[sector]);
1371 spix.SetFFactorMethodValid ( kTRUE );
1372
1373 }
1374
1375 //
1376 // Third loop: Set mean number of photo-electrons and its RMS in the pixels
1377 // only excluded as: MBadPixelsPix::kChargeSigmaNotValid
1378 //
1379 for (Int_t i=0; i<npixels; i++)
1380 {
1381
1382 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[i];
1383 MBadPixelsPix &bad = (*badcam)[i];
1384
1385 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
1386 continue;
1387
1388 if (bad.IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid))
1389 {
1390 const Int_t aidx = (*fGeom)[i].GetAidx();
1391 MCalibrationChargePix &apix = (MCalibrationChargePix&)chargecam->GetAverageArea(aidx);
1392
1393 pix.SetPheFFactorMethod ( apix.GetPheFFactorMethod() );
1394 pix.SetPheFFactorMethodVar( apix.GetPheFFactorMethodVar() );
1395 if (!pix.CalcConvFFactor())
1396 {
1397 *fLog << warn << GetDescriptor()
1398 << ": Could not calculate the Conv. FADC counts to Phes in pixel: "
1399 << Form(" %4i",pix.GetPixId())
1400 << endl;
1401 bad.SetUncalibrated( MBadPixelsPix::kDeviatingNumPhes );
1402 if (IsCheckDeviatingBehavior())
1403 bad.SetUnsuitable ( MBadPixelsPix::kUnsuitableRun );
1404 }
1405 }
1406 }
1407
1408 return kTRUE;
1409}
1410
1411
1412
1413// ------------------------------------------------------------------------
1414//
1415// Returns kFALSE if pointer to MCalibrationBlindCam is NULL
1416//
1417// The check returns kFALSE if:
1418//
1419// 1) fLambda and fLambdaCheck are separated relatively to each other by more than fLambdaCheckLimit
1420// 2) BlindPixel has an fLambdaErr greater than fLambdaErrLimit
1421//
1422// Calls:
1423// - MCalibrationBlindPix::CalcFluxInsidePlexiglass()
1424//
1425Bool_t MCalibrationChargeCalc::FinalizeBlindCam()
1426{
1427
1428 MCalibrationBlindCam *blindcam = fIntensBlind
1429 ? (MCalibrationBlindCam*)fIntensBlind->GetCam() : fBlindCam;
1430
1431 if (!blindcam)
1432 return kFALSE;
1433
1434 Int_t nvalid = 0;
1435
1436 for (Int_t i=0; i<blindcam->GetSize(); i++)
1437 {
1438
1439 MCalibrationBlindPix &blindpix = (MCalibrationBlindPix&)(*blindcam)[i];
1440
1441 if (!blindpix.IsValid())
1442 continue;
1443
1444 const Float_t lambda = blindpix.GetLambda();
1445 const Float_t lambdaerr = blindpix.GetLambdaErr();
1446 const Float_t lambdacheck = blindpix.GetLambdaCheck();
1447
1448 if (2.*(lambdacheck-lambda)/(lambdacheck+lambda) > fLambdaCheckLimit)
1449 {
1450 *fLog << warn << GetDescriptor()
1451 << Form("%s%4.2f%s%4.2f%s%4.2f%s%2i",": Lambda: ",lambda," and Lambda-Check: ",
1452 lambdacheck," differ by more than ",fLambdaCheckLimit," in the Blind Pixel Nr.",i)
1453 << endl;
1454 blindpix.SetValid(kFALSE);
1455 continue;
1456 }
1457
1458 if (lambdaerr > fLambdaErrLimit)
1459 {
1460 *fLog << warn << GetDescriptor()
1461 << Form("%s%4.2f%s%4.2f%s%2i",": Error of Fitted Lambda: ",lambdaerr," is greater than ",
1462 fLambdaErrLimit," in Blind Pixel Nr.",i) << endl;
1463 blindpix.SetValid(kFALSE);
1464 continue;
1465 }
1466
1467 if (!blindpix.CalcFluxInsidePlexiglass())
1468 {
1469 *fLog << warn << "Could not calculate the flux of photons from Blind Pixel Nr." << i << endl;
1470 blindpix.SetValid(kFALSE);
1471 continue;
1472 }
1473
1474 nvalid++;
1475 }
1476
1477 if (!nvalid)
1478 return kFALSE;
1479
1480 return kTRUE;
1481}
1482
1483// ------------------------------------------------------------------------
1484//
1485// Returns kFALSE if pointer to MCalibrationChargePINDiode is NULL
1486//
1487// The check returns kFALSE if:
1488//
1489// 1) PINDiode has a fitted charge smaller than fChargeLimit*PedRMS
1490// 2) PINDiode has a fit error smaller than fChargeErrLimit
1491// 3) PINDiode has a fitted charge smaller its fChargeRelErrLimit times its charge error
1492// 4) PINDiode has a charge sigma smaller than its Pedestal RMS
1493//
1494// Calls:
1495// - MCalibrationChargePINDiode::CalcFluxOutsidePlexiglass()
1496//
1497Bool_t MCalibrationChargeCalc::FinalizePINDiode()
1498{
1499
1500 if (!fPINDiode)
1501 return kFALSE;
1502
1503 if (fPINDiode->GetMean() < fChargeLimit*fPINDiode->GetPedRms())
1504 {
1505 *fLog << warn << GetDescriptor() << ": Fitted Charge is smaller than "
1506 << fChargeLimit << " Pedestal RMS in PINDiode " << endl;
1507 return kFALSE;
1508 }
1509
1510 if (fPINDiode->GetMeanErr() < fChargeErrLimit)
1511 {
1512 *fLog << warn << GetDescriptor() << ": Error of Fitted Charge is smaller than "
1513 << fChargeErrLimit << " in PINDiode " << endl;
1514 return kFALSE;
1515 }
1516
1517 if (fPINDiode->GetMean() < fChargeRelErrLimit*fPINDiode->GetMeanErr())
1518 {
1519 *fLog << warn << GetDescriptor() << ": Fitted Charge is smaller than "
1520 << fChargeRelErrLimit << "* its error in PINDiode " << endl;
1521 return kFALSE;
1522 }
1523
1524 if (fPINDiode->GetSigma() < fPINDiode->GetPedRms())
1525 {
1526 *fLog << warn << GetDescriptor()
1527 << ": Sigma of Fitted Charge smaller than Pedestal RMS in PINDiode " << endl;
1528 return kFALSE;
1529 }
1530
1531
1532 if (!fPINDiode->CalcFluxOutsidePlexiglass())
1533 {
1534 *fLog << warn << "Could not calculate the flux of photons from the PIN Diode, "
1535 << "will skip PIN Diode Calibration " << endl;
1536 return kFALSE;
1537 }
1538
1539 return kTRUE;
1540}
1541
1542// ------------------------------------------------------------------------
1543//
1544// Calculate the average number of photons outside the plexiglass with the
1545// formula:
1546//
1547// av.Num.photons(area index) = av.Num.Phes(area index)
1548// / MCalibrationQEPix::GetDefaultQE(fPulserColor)
1549// / MCalibrationQEPix::GetPMTCollectionEff()
1550// / MCalibrationQEPix::GetLightGuidesEff(fPulserColor)
1551// / MCalibrationQECam::GetPlexiglassQE()
1552//
1553// Calculate the variance on the average number of photons assuming that the error on the
1554// Quantum efficiency is reduced by the number of used inner pixels, but the rest of the
1555// values keeps it ordinary error since it is systematic.
1556//
1557// Loop over pixels:
1558//
1559// - Continue, if not MCalibrationChargePix::IsFFactorMethodValid() and set:
1560// MCalibrationQEPix::SetFFactorMethodValid(kFALSE,fPulserColor)
1561//
1562// - Call MCalibrationChargePix::CalcMeanFFactor(av.Num.photons) and set:
1563// MCalibrationQEPix::SetFFactorMethodValid(kFALSE,fPulserColor) if not succesful
1564//
1565// - Calculate the quantum efficiency with the formula:
1566//
1567// QE = ( Num.Phes / av.Num.photons ) * MGeomCam::GetPixRatio()
1568//
1569// - Set QE in MCalibrationQEPix::SetQEFFactor ( QE, fPulserColor );
1570//
1571// - Set Variance of QE in MCalibrationQEPix::SetQEFFactorVar ( Variance, fPulserColor );
1572// - Set bit MCalibrationQEPix::SetFFactorMethodValid(kTRUE,fPulserColor)
1573//
1574// - Call MCalibrationQEPix::UpdateFFactorMethod()
1575//
1576void MCalibrationChargeCalc::FinalizeFFactorQECam()
1577{
1578
1579 if (fNumInnerFFactorMethodUsed < 2)
1580 {
1581 *fLog << warn << GetDescriptor()
1582 << ": Could not calculate F-Factor Method: Less than 2 inner pixels valid! " << endl;
1583 return;
1584 }
1585
1586 MCalibrationQECam *qecam = fIntensQE
1587 ? (MCalibrationQECam*) fIntensQE->GetCam() : fQECam;
1588 MCalibrationChargeCam *chargecam = fIntensCam
1589 ? (MCalibrationChargeCam*)fIntensCam->GetCam() : fCam;
1590 MBadPixelsCam *badcam = fIntensBad
1591 ? (MBadPixelsCam*) fIntensBad->GetCam() : fBadPixels;
1592
1593 MCalibrationChargePix &avpix = (MCalibrationChargePix&)chargecam->GetAverageArea(0);
1594 MCalibrationQEPix &qepix = (MCalibrationQEPix&) qecam->GetAverageArea(0);
1595
1596 const Float_t avphotons = avpix.GetPheFFactorMethod()
1597 / qepix.GetDefaultQE(fPulserColor)
1598 / qepix.GetPMTCollectionEff()
1599 / qepix.GetLightGuidesEff(fPulserColor)
1600 / qecam->GetPlexiglassQE();
1601
1602 const Float_t avphotrelvar = avpix.GetPheFFactorMethodRelVar()
1603 + qepix.GetDefaultQERelVar(fPulserColor) / fNumInnerFFactorMethodUsed
1604 + qepix.GetPMTCollectionEffRelVar()
1605 + qepix.GetLightGuidesEffRelVar(fPulserColor)
1606 + qecam->GetPlexiglassQERelVar();
1607
1608 const UInt_t nareas = fGeom->GetNumAreas();
1609
1610 //
1611 // Set the results in the MCalibrationChargeCam
1612 //
1613 chargecam->SetNumPhotonsFFactorMethod (avphotons);
1614
1615 if (avphotrelvar > 0.)
1616 chargecam->SetNumPhotonsFFactorMethodErr(TMath::Sqrt( avphotrelvar * avphotons * avphotons));
1617
1618 TArrayF lowlim (nareas);
1619 TArrayF upplim (nareas);
1620 TArrayD avffactorphotons (nareas);
1621 TArrayD avffactorphotvar (nareas);
1622 TArrayI numffactor (nareas);
1623
1624 const UInt_t npixels = fGeom->GetNumPixels();
1625
1626 MHCamera camffactor(*fGeom,"Camffactor","F-Factor in Camera");
1627
1628 for (UInt_t i=0; i<npixels; i++)
1629 {
1630
1631 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[i];
1632 MCalibrationQEPix &qepix = (MCalibrationQEPix&) (*qecam) [i];
1633 MBadPixelsPix &bad = (*badcam) [i];
1634
1635 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
1636 continue;
1637
1638 const Float_t photons = avphotons / fGeom->GetPixRatio(i);
1639 const Float_t qe = pix.GetPheFFactorMethod() / photons ;
1640
1641 const Float_t qerelvar = avphotrelvar + pix.GetPheFFactorMethodRelVar();
1642
1643 qepix.SetQEFFactor ( qe , fPulserColor );
1644 qepix.SetQEFFactorVar ( qerelvar*qe*qe, fPulserColor );
1645 qepix.SetFFactorMethodValid( kTRUE , fPulserColor );
1646
1647 if (!qepix.UpdateFFactorMethod( qecam->GetPlexiglassQE() ))
1648 *fLog << warn << GetDescriptor()
1649 << ": Cannot update Quantum efficiencies with the F-Factor Method" << endl;
1650
1651 //
1652 // The following pixels are those with deviating sigma, but otherwise OK,
1653 // probably those with stars during the pedestal run, but not the cal. run.
1654 //
1655 if (!pix.CalcMeanFFactor( photons , avphotrelvar ))
1656 {
1657 bad.SetUncalibrated( MBadPixelsPix::kDeviatingFFactor );
1658 if (IsCheckDeviatingBehavior())
1659 bad.SetUnsuitable ( MBadPixelsPix::kUnreliableRun );
1660 continue;
1661 }
1662
1663 const Int_t aidx = (*fGeom)[i].GetAidx();
1664 const Float_t ffactor = pix.GetMeanFFactorFADC2Phot();
1665
1666 camffactor.Fill(i,ffactor);
1667 camffactor.SetUsed(i);
1668
1669 avffactorphotons[aidx] += ffactor;
1670 avffactorphotvar[aidx] += ffactor*ffactor;
1671 numffactor[aidx]++;
1672 }
1673
1674 for (UInt_t i=0; i<nareas; i++)
1675 {
1676
1677 if (numffactor[i] == 0)
1678 {
1679 *fLog << warn << GetDescriptor() << ": No pixels with valid total F-Factor found "
1680 << "in area index: " << i << endl;
1681 continue;
1682 }
1683
1684 avffactorphotvar[i] = (avffactorphotvar[i] - avffactorphotons[i]*avffactorphotons[i]/numffactor[i])
1685 / (numffactor[i]-1.);
1686 avffactorphotons[i] = avffactorphotons[i] / numffactor[i];
1687
1688 if (avffactorphotvar[i] < 0.)
1689 {
1690 *fLog << warn << GetDescriptor() << ": No pixels with valid variance of total F-Factor found "
1691 << "in area index: " << i << endl;
1692 continue;
1693 }
1694
1695 lowlim [i] = 1.; // Lowest known F-Factor of a PMT
1696 upplim [i] = avffactorphotons[i] + fFFactorErrLimit*TMath::Sqrt(avffactorphotvar[i]);
1697
1698 TArrayI area(1);
1699 area[0] = i;
1700
1701 TH1D *hist = camffactor.ProjectionS(TArrayI(),area,"_py",100);
1702 hist->Fit("gaus","Q");
1703 const Float_t mean = hist->GetFunction("gaus")->GetParameter(1);
1704 const Float_t sigma = hist->GetFunction("gaus")->GetParameter(2);
1705 const Int_t ndf = hist->GetFunction("gaus")->GetNDF();
1706
1707 if (IsDebug())
1708 camffactor.DrawClone();
1709
1710 if (ndf < 2)
1711 {
1712 *fLog << warn << GetDescriptor() << ": Cannot use a Gauss fit to the F-Factor "
1713 << "in the camera with area index: " << i << endl;
1714 *fLog << warn << GetDescriptor() << ": Number of dof.: " << ndf << " is smaller than 2 " << endl;
1715 *fLog << warn << GetDescriptor() << ": Will use the simple mean and rms " << endl;
1716 delete hist;
1717 continue;
1718 }
1719
1720 const Double_t prob = hist->GetFunction("gaus")->GetProb();
1721
1722 if (prob < 0.001)
1723 {
1724 *fLog << warn << GetDescriptor() << ": Cannot use a Gauss fit to the F-Factor "
1725 << "in the camera with area index: " << i << endl;
1726 *fLog << warn << GetDescriptor() << ": Fit probability " << prob
1727 << " is smaller than 0.001 " << endl;
1728 *fLog << warn << GetDescriptor() << ": Will use the simple mean and rms " << endl;
1729 delete hist;
1730 continue;
1731 }
1732
1733 *fLog << inf << GetDescriptor() << ": Mean F-Factor "
1734 << "with area index #" << i << ": "
1735 << Form("%4.2f+-%4.2f",mean,sigma) << endl;
1736
1737 lowlim [i] = 1.;
1738 upplim [i] = mean + fFFactorErrLimit*sigma;
1739
1740 delete hist;
1741 }
1742
1743 *fLog << endl;
1744
1745 for (UInt_t i=0; i<npixels; i++)
1746 {
1747
1748 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[i];
1749 MBadPixelsPix &bad = (*badcam) [i];
1750
1751 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
1752 continue;
1753
1754 const Float_t ffactor = pix.GetMeanFFactorFADC2Phot();
1755 const Int_t aidx = (*fGeom)[i].GetAidx();
1756
1757 if ( ffactor < lowlim[aidx] || ffactor > upplim[aidx] )
1758 {
1759 *fLog << warn << "Overall F-Factor "
1760 << Form("%5.2f",ffactor) << " out of range ["
1761 << Form("%5.2f,%5.2f",lowlim[aidx],upplim[aidx]) << "] Pixel " << i << endl;
1762
1763 bad.SetUncalibrated( MBadPixelsPix::kDeviatingFFactor );
1764 if (IsCheckDeviatingBehavior())
1765 bad.SetUnsuitable ( MBadPixelsPix::kUnreliableRun );
1766 }
1767 }
1768
1769 for (UInt_t i=0; i<npixels; i++)
1770 {
1771
1772 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[i];
1773 MCalibrationQEPix &qepix = (MCalibrationQEPix&) (*qecam) [i];
1774 MBadPixelsPix &bad = (*badcam) [i];
1775
1776 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
1777 {
1778 qepix.SetFFactorMethodValid(kFALSE,fPulserColor);
1779 pix.SetFFactorMethodValid(kFALSE);
1780 pix.SetExcluded();
1781 continue;
1782 }
1783 }
1784}
1785
1786
1787// ------------------------------------------------------------------------
1788//
1789// Loop over pixels:
1790//
1791// - Continue, if not MCalibrationBlindPix::IsFluxInsidePlexiglassAvailable() and set:
1792// MCalibrationQEPix::SetBlindPixelMethodValid(kFALSE,fPulserColor)
1793//
1794// - Calculate the quantum efficiency with the formula:
1795//
1796// QE = Num.Phes / MCalibrationBlindPix::GetFluxInsidePlexiglass()
1797// / MGeomPix::GetA() * MCalibrationQECam::GetPlexiglassQE()
1798//
1799// - Set QE in MCalibrationQEPix::SetQEBlindPixel ( QE, fPulserColor );
1800// - Set Variance of QE in MCalibrationQEPix::SetQEBlindPixelVar ( Variance, fPulserColor );
1801// - Set bit MCalibrationQEPix::SetBlindPixelMethodValid(kTRUE,fPulserColor)
1802//
1803// - Call MCalibrationQEPix::UpdateBlindPixelMethod()
1804//
1805void MCalibrationChargeCalc::FinalizeBlindPixelQECam()
1806{
1807
1808
1809 MCalibrationBlindCam *blindcam = fIntensBlind
1810 ? (MCalibrationBlindCam*) fIntensBlind->GetCam(): fBlindCam;
1811 MBadPixelsCam *badcam = fIntensBad
1812 ? (MBadPixelsCam*) fIntensBad->GetCam() : fBadPixels;
1813 MCalibrationQECam *qecam = fIntensQE
1814 ? (MCalibrationQECam*) fIntensQE->GetCam() : fQECam;
1815 MCalibrationChargeCam *chargecam = fIntensCam
1816 ? (MCalibrationChargeCam*)fIntensCam->GetCam() : fCam;
1817
1818 //
1819 // Set the results in the MCalibrationChargeCam
1820 //
1821 if (!blindcam || !(blindcam->IsFluxInsidePlexiglassAvailable()))
1822 {
1823
1824 const Float_t photons = blindcam->GetFluxInsidePlexiglass() * (*fGeom)[0].GetA()
1825 / qecam->GetPlexiglassQE();
1826 chargecam->SetNumPhotonsBlindPixelMethod(photons);
1827
1828 const Float_t photrelvar = blindcam->GetFluxInsidePlexiglassRelVar()
1829 + qecam->GetPlexiglassQERelVar();
1830
1831 if (photrelvar > 0.)
1832 chargecam->SetNumPhotonsBlindPixelMethodErr(TMath::Sqrt( photrelvar * photons * photons));
1833 }
1834
1835 //
1836 // With the knowledge of the overall photon flux, calculate the
1837 // quantum efficiencies after the Blind Pixel and PIN Diode method
1838 //
1839 const UInt_t npixels = fGeom->GetNumPixels();
1840 for (UInt_t i=0; i<npixels; i++)
1841 {
1842
1843 MCalibrationQEPix &qepix = (MCalibrationQEPix&) (*qecam) [i];
1844
1845 if (!blindcam || !(blindcam->IsFluxInsidePlexiglassAvailable()))
1846 {
1847 qepix.SetBlindPixelMethodValid(kFALSE, fPulserColor);
1848 continue;
1849 }
1850
1851 MBadPixelsPix &bad = (*badcam) [i];
1852
1853 if (bad.IsUnsuitable (MBadPixelsPix::kUnsuitableRun))
1854 {
1855 qepix.SetBlindPixelMethodValid(kFALSE, fPulserColor);
1856 continue;
1857 }
1858
1859 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[i];
1860 MGeomPix &geo = (*fGeom) [i];
1861
1862 const Float_t qe = pix.GetPheFFactorMethod()
1863 / blindcam->GetFluxInsidePlexiglass()
1864 / geo.GetA()
1865 * qecam->GetPlexiglassQE();
1866
1867 const Float_t qerelvar = blindcam->GetFluxInsidePlexiglassRelVar()
1868 + qecam->GetPlexiglassQERelVar()
1869 + pix.GetPheFFactorMethodRelVar();
1870
1871 qepix.SetQEBlindPixel ( qe , fPulserColor );
1872 qepix.SetQEBlindPixelVar ( qerelvar*qe*qe, fPulserColor );
1873 qepix.SetBlindPixelMethodValid( kTRUE , fPulserColor );
1874
1875 if (!qepix.UpdateBlindPixelMethod( qecam->GetPlexiglassQE()))
1876 *fLog << warn << GetDescriptor()
1877 << ": Cannot update Quantum efficiencies with the Blind Pixel Method" << endl;
1878 }
1879}
1880
1881// ------------------------------------------------------------------------
1882//
1883// Loop over pixels:
1884//
1885// - Continue, if not MCalibrationChargePINDiode::IsFluxOutsidePlexiglassAvailable() and set:
1886// MCalibrationQEPix::SetPINDiodeMethodValid(kFALSE,fPulserColor)
1887//
1888// - Calculate the quantum efficiency with the formula:
1889//
1890// QE = Num.Phes / MCalibrationChargePINDiode::GetFluxOutsidePlexiglass() / MGeomPix::GetA()
1891//
1892// - Set QE in MCalibrationQEPix::SetQEPINDiode ( QE, fPulserColor );
1893// - Set Variance of QE in MCalibrationQEPix::SetQEPINDiodeVar ( Variance, fPulserColor );
1894// - Set bit MCalibrationQEPix::SetPINDiodeMethodValid(kTRUE,fPulserColor)
1895//
1896// - Call MCalibrationQEPix::UpdatePINDiodeMethod()
1897//
1898void MCalibrationChargeCalc::FinalizePINDiodeQECam()
1899{
1900
1901 const UInt_t npixels = fGeom->GetNumPixels();
1902
1903 MCalibrationQECam *qecam = fIntensQE
1904 ? (MCalibrationQECam*) fIntensQE->GetCam() : fQECam;
1905 MCalibrationChargeCam *chargecam = fIntensCam
1906 ? (MCalibrationChargeCam*)fIntensCam->GetCam() : fCam;
1907 MBadPixelsCam *badcam = fIntensBad
1908 ? (MBadPixelsCam*) fIntensBad->GetCam() : fBadPixels;
1909 //
1910 // With the knowledge of the overall photon flux, calculate the
1911 // quantum efficiencies after the PIN Diode method
1912 //
1913 for (UInt_t i=0; i<npixels; i++)
1914 {
1915
1916 MCalibrationQEPix &qepix = (MCalibrationQEPix&) (*qecam) [i];
1917
1918 if (!fPINDiode)
1919 {
1920 qepix.SetPINDiodeMethodValid(kFALSE, fPulserColor);
1921 continue;
1922 }
1923
1924 if (!fPINDiode->IsFluxOutsidePlexiglassAvailable())
1925 {
1926 qepix.SetPINDiodeMethodValid(kFALSE, fPulserColor);
1927 continue;
1928 }
1929
1930 MBadPixelsPix &bad = (*badcam) [i];
1931
1932 if (!bad.IsUnsuitable (MBadPixelsPix::kUnsuitableRun))
1933 {
1934 qepix.SetPINDiodeMethodValid(kFALSE, fPulserColor);
1935 continue;
1936 }
1937
1938 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*chargecam)[i];
1939 MGeomPix &geo = (*fGeom) [i];
1940
1941 const Float_t qe = pix.GetPheFFactorMethod()
1942 / fPINDiode->GetFluxOutsidePlexiglass()
1943 / geo.GetA();
1944
1945 const Float_t qerelvar = fPINDiode->GetFluxOutsidePlexiglassRelVar() + pix.GetPheFFactorMethodRelVar();
1946
1947 qepix.SetQEPINDiode ( qe , fPulserColor );
1948 qepix.SetQEPINDiodeVar ( qerelvar*qe*qe, fPulserColor );
1949 qepix.SetPINDiodeMethodValid( kTRUE , fPulserColor );
1950
1951 if (!qepix.UpdatePINDiodeMethod())
1952 *fLog << warn << GetDescriptor()
1953 << ": Cannot update Quantum efficiencies with the PIN Diode Method" << endl;
1954 }
1955}
1956
1957// ------------------------------------------------------------------------
1958//
1959// Loop over pixels:
1960//
1961// - Call MCalibrationQEPix::UpdateCombinedMethod()
1962//
1963void MCalibrationChargeCalc::FinalizeCombinedQECam()
1964{
1965
1966 const UInt_t npixels = fGeom->GetNumPixels();
1967
1968 MCalibrationQECam *qecam = fIntensQE
1969 ? (MCalibrationQECam*) fIntensQE->GetCam() : fQECam;
1970 MBadPixelsCam *badcam = fIntensBad
1971 ? (MBadPixelsCam*) fIntensBad->GetCam() : fBadPixels;
1972
1973 for (UInt_t i=0; i<npixels; i++)
1974 {
1975
1976 MCalibrationQEPix &qepix = (MCalibrationQEPix&) (*qecam) [i];
1977 MBadPixelsPix &bad = (*badcam) [i];
1978
1979 if (!bad.IsUnsuitable (MBadPixelsPix::kUnsuitableRun))
1980 {
1981 qepix.SetPINDiodeMethodValid(kFALSE, fPulserColor);
1982 continue;
1983 }
1984
1985 qepix.UpdateCombinedMethod();
1986 }
1987}
1988
1989// -----------------------------------------------------------------------------------------------
1990//
1991// - Print out statistics about BadPixels of type UnsuitableType_t
1992// - store numbers of bad pixels of each type in fCam or fIntensCam
1993//
1994void MCalibrationChargeCalc::FinalizeUnsuitablePixels()
1995{
1996
1997 *fLog << inf << endl;
1998 *fLog << GetDescriptor() << ": Charge Calibration status:" << endl;
1999 *fLog << dec << setfill(' ');
2000
2001 const Int_t nareas = fGeom->GetNumAreas();
2002
2003 TArrayI counts(nareas);
2004
2005 MBadPixelsCam *badcam = fIntensBad
2006 ? (MBadPixelsCam*)fIntensBad->GetCam() : fBadPixels;
2007 MCalibrationChargeCam *chargecam = fIntensCam
2008 ? (MCalibrationChargeCam*)fIntensCam->GetCam() : fCam;
2009
2010 for (Int_t i=0; i<badcam->GetSize(); i++)
2011 {
2012 MBadPixelsPix &bad = (*badcam)[i];
2013 if (!bad.IsBad())
2014 {
2015 const Int_t aidx = (*fGeom)[i].GetAidx();
2016 counts[aidx]++;
2017 }
2018 }
2019
2020 if (fGeom->InheritsFrom("MGeomCamMagic"))
2021 *fLog << " " << setw(7) << "Successfully calibrated Pixels: "
2022 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
2023
2024 counts.Reset();
2025
2026 for (Int_t i=0; i<badcam->GetSize(); i++)
2027 {
2028 MBadPixelsPix &bad = (*badcam)[i];
2029
2030 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
2031 {
2032 const Int_t aidx = (*fGeom)[i].GetAidx();
2033 counts[aidx]++;
2034 }
2035 }
2036
2037 for (Int_t aidx=0; aidx<nareas; aidx++)
2038 chargecam->SetNumUnsuitable(counts[aidx], aidx);
2039
2040 if (fGeom->InheritsFrom("MGeomCamMagic"))
2041 *fLog << " " << setw(7) << "Uncalibrated Pixels: "
2042 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
2043
2044 counts.Reset();
2045
2046 for (Int_t i=0; i<badcam->GetSize(); i++)
2047 {
2048
2049 MBadPixelsPix &bad = (*badcam)[i];
2050
2051 if (bad.IsUnsuitable(MBadPixelsPix::kUnreliableRun))
2052 {
2053 const Int_t aidx = (*fGeom)[i].GetAidx();
2054 counts[aidx]++;
2055 }
2056 }
2057
2058 for (Int_t aidx=0; aidx<nareas; aidx++)
2059 chargecam->SetNumUnreliable(counts[aidx], aidx);
2060
2061 *fLog << " " << setw(7) << "Unreliable Pixels: "
2062 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
2063
2064}
2065
2066// -----------------------------------------------------------------------------------------------
2067//
2068// Print out statistics about BadPixels of type UncalibratedType_t
2069//
2070void MCalibrationChargeCalc::PrintUncalibrated(MBadPixelsPix::UncalibratedType_t typ, const char *text) const
2071{
2072
2073 UInt_t countinner = 0;
2074 UInt_t countouter = 0;
2075
2076 MBadPixelsCam *badcam = fIntensBad
2077 ? (MBadPixelsCam*)fIntensBad->GetCam() : fBadPixels;
2078
2079 for (Int_t i=0; i<badcam->GetSize(); i++)
2080 {
2081 MBadPixelsPix &bad = (*badcam)[i];
2082
2083 if (bad.IsUncalibrated(typ))
2084 {
2085 if (fGeom->GetPixRatio(i) == 1.)
2086 countinner++;
2087 else
2088 countouter++;
2089 }
2090 }
2091
2092 *fLog << " " << setw(7) << text
2093 << Form("%s%3i%s%3i","Inner: ",countinner," Outer: ",countouter) << endl;
2094}
2095
2096// --------------------------------------------------------------------------
2097//
2098// Set the path for output file
2099//
2100void MCalibrationChargeCalc::SetOutputPath(TString path)
2101{
2102 fOutputPath = path;
2103 if (fOutputPath.EndsWith("/"))
2104 fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
2105}
2106
2107// --------------------------------------------------------------------------
2108//
2109// Set the output file
2110//
2111void MCalibrationChargeCalc::SetOutputFile(TString file)
2112{
2113 fOutputFile = file;
2114}
2115
2116// --------------------------------------------------------------------------
2117//
2118// Get the output file
2119//
2120const char* MCalibrationChargeCalc::GetOutputFile()
2121{
2122 return Form("%s/%s", (const char*)fOutputPath, (const char*)fOutputFile);
2123}
2124
2125// --------------------------------------------------------------------------
2126//
2127// Read the environment for the following data members:
2128// - fChargeLimit
2129// - fChargeErrLimit
2130// - fChargeRelErrLimit
2131// - fDebug
2132// - fFFactorErrLimit
2133// - fLambdaErrLimit
2134// - fLambdaCheckErrLimit
2135// - fPheErrLimit
2136//
2137Int_t MCalibrationChargeCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
2138{
2139
2140 Bool_t rc = kFALSE;
2141 if (IsEnvDefined(env, prefix, "ChargeLimit", print))
2142 {
2143 SetChargeLimit(GetEnvValue(env, prefix, "ChargeLimit", fChargeLimit));
2144 rc = kTRUE;
2145 }
2146 if (IsEnvDefined(env, prefix, "ChargeErrLimit", print))
2147 {
2148 SetChargeErrLimit(GetEnvValue(env, prefix, "ChargeErrLimit", fChargeErrLimit));
2149 rc = kTRUE;
2150 }
2151 if (IsEnvDefined(env, prefix, "ChargeRelErrLimit", print))
2152 {
2153 SetChargeRelErrLimit(GetEnvValue(env, prefix, "ChargeRelErrLimit", fChargeRelErrLimit));
2154 rc = kTRUE;
2155 }
2156 if (IsEnvDefined(env, prefix, "Debug", print))
2157 {
2158 SetDebug(GetEnvValue(env, prefix, "Debug", IsDebug()));
2159 rc = kTRUE;
2160 }
2161 if (IsEnvDefined(env, prefix, "FFactorErrLimit", print))
2162 {
2163 SetFFactorErrLimit(GetEnvValue(env, prefix, "FFactorErrLimit", fFFactorErrLimit));
2164 rc = kTRUE;
2165 }
2166 if (IsEnvDefined(env, prefix, "LambdaErrLimit", print))
2167 {
2168 SetLambdaErrLimit(GetEnvValue(env, prefix, "LambdaErrLimit", fLambdaErrLimit));
2169 rc = kTRUE;
2170 }
2171 if (IsEnvDefined(env, prefix, "LambdaCheckLimit", print))
2172 {
2173 SetLambdaCheckLimit(GetEnvValue(env, prefix, "LambdaCheckLimit", fLambdaCheckLimit));
2174 rc = kTRUE;
2175 }
2176 if (IsEnvDefined(env, prefix, "PheErrLimit", print))
2177 {
2178 SetPheErrLimit(GetEnvValue(env, prefix, "PheErrLimit", fPheErrLimit));
2179 rc = kTRUE;
2180 }
2181 if (IsEnvDefined(env, prefix, "CheckDeadPixels", print))
2182 {
2183 SetCheckDeadPixels(GetEnvValue(env, prefix, "CheckDeadPixels", IsCheckDeadPixels()));
2184 rc = kTRUE;
2185 }
2186 if (IsEnvDefined(env, prefix, "CheckDeviatingBehavior", print))
2187 {
2188 SetCheckDeviatingBehavior(GetEnvValue(env, prefix, "CheckDeviatingBehavior", IsCheckDeviatingBehavior()));
2189 rc = kTRUE;
2190 }
2191 if (IsEnvDefined(env, prefix, "CheckExtractionWindow", print))
2192 {
2193 SetCheckExtractionWindow(GetEnvValue(env, prefix, "CheckExtractionWindow", IsCheckExtractionWindow()));
2194 rc = kTRUE;
2195 }
2196 if (IsEnvDefined(env, prefix, "CheckHistOverflow", print))
2197 {
2198 SetCheckHistOverflow(GetEnvValue(env, prefix, "CheckHistOverflow", IsCheckHistOverflow()));
2199 rc = kTRUE;
2200 }
2201 if (IsEnvDefined(env, prefix, "CheckOscillations", print))
2202 {
2203 SetCheckOscillations(GetEnvValue(env, prefix, "CheckOscillations", IsCheckOscillations()));
2204 rc = kTRUE;
2205 }
2206
2207 return rc;
2208}
Note: See TracBrowser for help on using the repository browser.