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

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