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

Last change on this file since 3842 was 3838, checked in by gaug, 21 years ago
*** empty log message ***
File size: 50.3 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//
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// - FinalizeBlindPixel()
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
189#include "MLog.h"
190#include "MLogManip.h"
191
192#include "MParList.h"
193
194#include "MRawRunHeader.h"
195#include "MRawEvtPixelIter.h"
196
197#include "MGeomCam.h"
198#include "MGeomPix.h"
199
200#include "MPedestalCam.h"
201#include "MPedestalPix.h"
202
203#include "MCalibrationChargeCam.h"
204#include "MCalibrationChargePix.h"
205#include "MCalibrationChargePINDiode.h"
206#include "MCalibrationChargeBlindPix.h"
207
208#include "MExtractedSignalCam.h"
209#include "MExtractedSignalPix.h"
210#include "MExtractedSignalBlindPixel.h"
211#include "MExtractedSignalPINDiode.h"
212
213#include "MBadPixelsCam.h"
214#include "MBadPixelsPix.h"
215
216#include "MCalibrationQECam.h"
217#include "MCalibrationQEPix.h"
218
219#include "MCalibrationCam.h"
220
221ClassImp(MCalibrationChargeCalc);
222
223using namespace std;
224
225const Float_t MCalibrationChargeCalc::fgChargeLimit = 3.;
226const Float_t MCalibrationChargeCalc::fgChargeErrLimit = 0.;
227const Float_t MCalibrationChargeCalc::fgChargeRelErrLimit = 1.;
228const Float_t MCalibrationChargeCalc::fgLambdaErrLimit = 0.2;
229const Float_t MCalibrationChargeCalc::fgLambdaCheckLimit = 0.2;
230const Float_t MCalibrationChargeCalc::fgPheErrLimit = 5.;
231// --------------------------------------------------------------------------
232//
233// Default constructor.
234//
235// Sets all pointers to NULL
236//
237// Calls AddToBranchList for:
238// - MRawEvtData.fHiGainPixId
239// - MRawEvtData.fLoGainPixId
240// - MRawEvtData.fHiGainFadcSamples
241// - MRawEvtData.fLoGainFadcSamples
242//
243// Initializes:
244// - fChargeLimit to fgChargeLimit
245// - fChargeErrLimit to fgChargeErrLimit
246// - fChargeRelErrLimit to fgChargeRelErrLimit
247// - fLambdaCheckLimit to fgLambdaCheckLimit
248// - fLambdaErrLimit to fgLambdaErrLimit
249// - fPheErrLimit to fgPheErrLimit
250// - fPulserColor to MCalibrationCam::kCT1
251//
252// Calls:
253// - Clear()
254//
255MCalibrationChargeCalc::MCalibrationChargeCalc(const char *name, const char *title)
256 : fBadPixels(NULL), fCam(NULL), fBlindPixel(NULL), fPINDiode(NULL),
257 fQECam(NULL), fGeom(NULL), fPedestals(NULL), fEvtTime(NULL)
258 {
259
260 fName = name ? name : "MCalibrationChargeCalc";
261 fTitle = title ? title : "Task to calculate the calibration constants and MCalibrationCam ";
262
263 AddToBranchList("MRawEvtData.fHiGainPixId");
264 AddToBranchList("MRawEvtData.fLoGainPixId");
265 AddToBranchList("MRawEvtData.fHiGainFadcSamples");
266 AddToBranchList("MRawEvtData.fLoGainFadcSamples");
267
268 SetChargeLimit();
269 SetChargeErrLimit();
270 SetChargeRelErrLimit();
271 SetLambdaCheckLimit();
272 SetLambdaErrLimit();
273 SetPheErrLimit();
274 SetPulserColor(MCalibrationCam::kNONE);
275
276 Clear();
277
278}
279
280// --------------------------------------------------------------------------
281//
282// Sets:
283// - all variables to 0.,
284// - all flags to kFALSE
285//
286void MCalibrationChargeCalc::Clear(const Option_t *o)
287{
288
289 fNumHiGainSamples = 0.;
290 fNumLoGainSamples = 0.;
291 fSqrtHiGainSamples = 0.;
292 fSqrtLoGainSamples = 0.;
293 SkipHiLoGainCalibration( kFALSE );
294}
295
296
297// -----------------------------------------------------------------------------------
298//
299// The following container are searched for and execution aborted if not in MParList:
300// - MPedestalCam
301//
302// The following containers are searched and created if they were not found:
303//
304// - MCalibrationQECam
305// - MBadPixelsCam
306//
307// The following output containers are only searched, but not created. If they
308// cannot be found, the corresponding calibration part is only skipped.
309//
310// - MTime
311//
312Int_t MCalibrationChargeCalc::PreProcess(MParList *pList)
313{
314
315 //
316 // Containers that have to be there.
317 //
318 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
319 if (!fPedestals)
320 {
321 *fLog << err << "MPedestalCam not found... aborting" << endl;
322 return kFALSE;
323 }
324
325 //
326 // Containers that are created in case that they are not there.
327 //
328 fQECam = (MCalibrationQECam*)pList->FindCreateObj("MCalibrationQECam");
329 if (!fQECam)
330 {
331 *fLog << err << "Cannot find nor create MCalibrationQECam... aborting" << endl;
332 return kFALSE;
333 }
334
335 fBadPixels = (MBadPixelsCam*)pList->FindCreateObj("MBadPixelsCam");
336 if (!fBadPixels)
337 {
338 *fLog << err << "Could not find or create MBadPixelsCam ... aborting." << endl;
339 return kFALSE;
340 }
341
342
343 fEvtTime = (MTime*)pList->FindObject("MTime");
344
345 //
346 // Check the pulser colour --> FIXME: this solution is only valid until the arrival of the DM's
347 //
348 if (fPulserColor == MCalibrationCam::kNONE)
349 {
350 *fLog << endl;
351 *fLog << err << GetDescriptor()
352 << ": No Pulser colour has been chosen. Since the installation of the IFAE pulser box,"
353 << " you HAVE to provide the LEDs colour, otherwise there is no calibration. " << endl;
354 *fLog << "See e.g. the macro calibration.C " << endl;
355 return kFALSE;
356 }
357
358 return kTRUE;
359}
360
361
362// --------------------------------------------------------------------------
363//
364// Search for the following input containers and abort if not existing:
365// - MGeomCam
366// - MCalibrationChargeCam
367//
368// Search for the following input containers and give a warning if not existing:
369// - MCalibrationChargeBlindPix
370// - MCalibrationChargePINDiode
371//
372// It retrieves the following variables from MCalibrationChargeCam:
373//
374// - fNumHiGainSamples
375// - fNumLoGainSamples
376//
377// It defines the PixId of every pixel in:
378//
379// - MCalibrationChargeCam
380// - MCalibrationQECam
381//
382// It sets all pixels in excluded which have the flag fBadBixelsPix::IsBad() set in:
383//
384// - MCalibrationChargePix
385// - MCalibrationQEPix
386//
387// Sets the pulser colour and tests if it has not changed w.r.t. fPulserColor in:
388//
389// - MCalibrationChargeCam
390// - MCalibrationChargeBlindPix (if existing)
391// - MCalibrationChargePINDiode (if existing)
392//
393Bool_t MCalibrationChargeCalc::ReInit(MParList *pList )
394{
395
396 fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
397 if (!fGeom)
398 {
399 *fLog << err << "No MGeomCam found... aborting." << endl;
400 return kFALSE;
401 }
402
403 fCam = (MCalibrationChargeCam*)pList->FindObject("MCalibrationChargeCam");
404 if (!fCam)
405 {
406 *fLog << err << "Cannot find MCalibrationChargeCam... aborting" << endl;
407 *fLog << err << "Maybe you forget to call an MFillH for the MHCalibrationChargeCam before..." << endl;
408 return kFALSE;
409 }
410
411 //
412 // Optional Containers
413 //
414 fBlindPixel = (MCalibrationChargeBlindPix*)pList->FindObject("MCalibrationChargeBlindPix");
415 if (!fBlindPixel)
416 *fLog << warn << GetDescriptor()
417 << ": MCalibrationChargeBlindPix not found... no blind pixel method! " << endl;
418
419 fPINDiode = (MCalibrationChargePINDiode*)pList->FindObject("MCalibrationChargePINDiode");
420 if (!fPINDiode)
421 *fLog << warn << GetDescriptor()
422 << "MCalibrationChargePINDiode not found... no PIN Diode method! " << endl;
423
424
425 //
426 // Initialize the pulser colours
427 //
428 if (fCam->GetPulserColor() == MCalibrationCam::kNONE)
429 {
430 fCam->SetPulserColor( fPulserColor );
431
432 if (fBlindPixel)
433 fBlindPixel->SetColor( fPulserColor );
434
435 if (fPINDiode)
436 fPINDiode->SetColor( fPulserColor );
437 }
438
439 if (fPulserColor != fCam->GetPulserColor())
440 {
441 *fLog << err << GetDescriptor()
442 << ": Pulser colour has changed w.r.t. last file in MCalibrationChargeCam" << endl;
443 *fLog << err << "This feature is not yet implemented, sorry ... aborting " << endl;
444 return kFALSE;
445 }
446
447 if (fBlindPixel)
448 if (fPulserColor != fBlindPixel->GetColor())
449 {
450 *fLog << err << GetDescriptor()
451 << ": Pulser colour has changed w.r.t. last file in MCalibrationChargeBlindPix." << endl;
452 *fLog << err << "This feature is not yet implemented, sorry ... aborting " << endl;
453 return kFALSE;
454 }
455
456 if (fPINDiode)
457 if (fPulserColor != fPINDiode->GetColor())
458 {
459 *fLog << err << GetDescriptor()
460 << ": Pulser colour has changed w.r.t. last file in MCalibrationChargePINDiode." << endl;
461 *fLog << err << "This feature is not yet implemented, sorry ... aborting " << endl;
462 return kFALSE;
463 }
464
465
466 fNumHiGainSamples = fCam->GetNumHiGainFADCSlices();
467 fNumLoGainSamples = fCam->GetNumLoGainFADCSlices();
468 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
469 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
470
471 UInt_t npixels = fGeom->GetNumPixels();
472
473 for (UInt_t i=0; i<npixels; i++)
474 {
475
476 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam) [i];
477 MCalibrationQEPix &pqe = (MCalibrationQEPix&) (*fQECam)[i];
478 MBadPixelsPix &bad = (*fBadPixels)[i];
479
480 pix.SetPixId(i);
481 pqe.SetPixId(i);
482
483 if (bad.IsBad())
484 {
485 pix.SetExcluded();
486 pqe.SetExcluded();
487 continue;
488 }
489
490 }
491
492 return kTRUE;
493}
494
495// ----------------------------------------------------------------------------------
496//
497// Nothing to be done in Process, but have a look at MHCalibrationChargeCam, instead
498//
499Int_t MCalibrationChargeCalc::Process()
500{
501 return kTRUE;
502}
503
504// -----------------------------------------------------------------------
505//
506// Return if number of executions is null.
507//
508// First loop over pixels, average areas and sectors, call:
509// - FinalizePedestals()
510// - FinalizeCharges()
511// for every entry. Count number of valid pixels in loop and return kFALSE
512// if there are none (the "Michele check").
513//
514// Call FinalizeBadPixels()
515//
516// Call FinalizeFFactorMethod() (second and third loop over pixels and areas)
517//
518// Call FinalizeBlindPixel()
519// Call FinalizePINDiode()
520//
521// Call FinalizeFFactorQECam() (fourth loop over pixels and areas)
522// Call FinalizeBlindPixelQECam() (fifth loop over pixels and areas)
523// Call FinalizePINDiodeQECam() (sixth loop over pixels and areas)
524//
525// Call MParContainer::SetReadyToSave() for fCam, fQECam, fBadPixels and
526// fBlindPixel and fPINDiode if they exist
527//
528// Print out some statistics
529//
530Int_t MCalibrationChargeCalc::PostProcess()
531{
532
533 if (GetNumExecutions()==0)
534 return kFALSE;
535
536 if (fPINDiode)
537 if (!fPINDiode->IsValid())
538 {
539 *fLog << warn << GetDescriptor()
540 << ": MCalibrationChargePINDiode is declared not valid... no PIN Diode method! " << endl;
541 fPINDiode = NULL;
542 }
543
544 if (fBlindPixel)
545 if (!fBlindPixel->IsValid())
546 {
547 *fLog << warn << GetDescriptor()
548 << ": MCalibrationChargeBlindPix is declared not valid... no Blind Pixel method! " << endl;
549 fBlindPixel = NULL;
550 }
551
552 //
553 // First loop over pixels, call FinalizePedestals and FinalizeCharges
554 //
555 Int_t nvalid = 0;
556
557 for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
558 {
559
560 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[pixid];
561 //
562 // Check if the pixel has been excluded from the fits
563 //
564 if (pix.IsExcluded())
565 continue;
566
567 MPedestalPix &ped = (*fPedestals)[pixid];
568 MBadPixelsPix &bad = (*fBadPixels)[pixid];
569
570 FinalizePedestals(ped,pix);
571
572 if (FinalizeCharges(pix,bad))
573 nvalid++;
574 }
575
576 //
577 // The Michele check ...
578 //
579 if (nvalid == 0)
580 {
581 *fLog << err << GetDescriptor() << ": All pixels have non-valid calibration. "
582 << "Did you forget to fill the histograms "
583 << "(filling MHCalibrationChargeCam from MExtractedSignalCam using MFillH) ? " << endl;
584 *fLog << err << GetDescriptor() << ": Or, maybe, you have used a pedestal run "
585 << "instead of a calibration run " << endl;
586 return kFALSE;
587 }
588
589 for (UInt_t aidx=0; aidx<fGeom->GetNumAreas(); aidx++)
590 {
591
592 const MPedestalPix &ped = fPedestals->GetAverageArea(aidx);
593 MCalibrationChargePix &pix = (MCalibrationChargePix&)fCam->GetAverageArea(aidx);
594
595 FinalizePedestals(ped,pix);
596 FinalizeCharges(pix, fCam->GetAverageBadArea(aidx));
597 }
598
599 for (UInt_t sector=0; sector<fGeom->GetNumSectors(); sector++)
600 {
601
602 const MPedestalPix &ped = fPedestals->GetAverageSector(sector);
603 MCalibrationChargePix &pix = (MCalibrationChargePix&)fCam->GetAverageSector(sector);
604
605 FinalizePedestals(ped,pix);
606 FinalizeCharges(pix, fCam->GetAverageBadSector(sector));
607 }
608
609 //
610 // Finalize Bad Pixels
611 //
612 FinalizeBadPixels();
613
614 //
615 // Finalize F-Factor method
616 //
617 if (!FinalizeFFactorMethod())
618 {
619 *fLog << warn << "Could not calculate the photons flux from the F-Factor method " << endl;
620 fCam->SetFFactorMethodValid(kFALSE);
621 return kFALSE;
622 }
623 else
624 fCam->SetFFactorMethodValid(kTRUE);
625
626 //
627 // Finalize Blind Pixel
628 //
629 if (FinalizeBlindPixel())
630 fQECam->SetBlindPixelMethodValid(kTRUE);
631 else
632 fQECam->SetBlindPixelMethodValid(kFALSE);
633
634 //
635 // Finalize PIN Diode
636 //
637 if (FinalizePINDiode())
638 fQECam->SetPINDiodeMethodValid(kTRUE);
639 else
640 fQECam->SetPINDiodeMethodValid(kFALSE);
641
642 //
643 // Finalize QE Cam
644 //
645 FinalizeFFactorQECam();
646 FinalizeBlindPixelQECam();
647 FinalizePINDiodeQECam();
648
649 //
650 // Finalize calibration statistics
651 //
652 FinalizeUnsuitablePixels();
653
654 fCam ->SetReadyToSave();
655 fQECam ->SetReadyToSave();
656 fBadPixels->SetReadyToSave();
657
658 if (fBlindPixel)
659 fBlindPixel->SetReadyToSave();
660 if (fPINDiode)
661 fPINDiode->SetReadyToSave();
662
663 *fLog << inf << endl;
664 *fLog << GetDescriptor() << ": Errors statistics:" << endl;
665
666 PrintUncalibrated(MBadPixelsPix::kChargeIsPedestal,
667 Form("%s%2.1f%s","Signal less than ",fChargeLimit," Pedestal RMS: "));
668 PrintUncalibrated(MBadPixelsPix::kChargeErrNotValid,
669 Form("%s%2.1f%s","Signal Error smaller than ",fChargeErrLimit,": "));
670 PrintUncalibrated(MBadPixelsPix::kChargeRelErrNotValid,
671 Form("%s%2.1f%s","Signal Error bigger than ",fChargeRelErrLimit," times Mean Signal: "));
672 PrintUncalibrated(MBadPixelsPix::kChargeSigmaNotValid,
673 "Signal Sigma smaller than Pedestal RMS: ");
674 PrintUncalibrated(MBadPixelsPix::kLoGainSaturation,
675 "Pixels with Low Gain Saturation: ");
676 PrintUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin,
677 Form("%s%2.1f%s","Mean Abs. Arr. Time in First ",1.," Bin(s): "));
678 PrintUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins,
679 Form("%s%2.1f%s","Mean Abs. Arr. Time in Last ",2.," Bin(s): "));
680 PrintUncalibrated(MBadPixelsPix::kHiGainOscillating,
681 "Pixels with changing Hi Gain signal over time: ");
682 PrintUncalibrated(MBadPixelsPix::kLoGainOscillating,
683 "Pixels with changing Lo Gain signal over time: ");
684 PrintUncalibrated(MBadPixelsPix::kDeviatingNumPhes,
685 "Pixels with deviating number of phes: ");
686 PrintUncalibrated(MBadPixelsPix::kHiGainNotFitted,
687 "Pixels with unsuccesful Gauss fit to the Hi Gain: ");
688 PrintUncalibrated(MBadPixelsPix::kLoGainNotFitted,
689 "Pixels with unsuccesful Gauss fit to the Lo Gain: ");
690
691 return kTRUE;
692}
693
694// ----------------------------------------------------------------------------------
695//
696// Retrieves pedestal and pedestal RMS from MPedestalPix
697// Retrieves total entries from MPedestalCam
698// Sets pedestal*fNumHiGainSamples and pedestal*fNumLoGainSamples in MCalibrationChargePix
699// Sets pedRMS *fSqrtHiGainSamples and pedRMS *fSqrtLoGainSamples in MCalibrationChargePix
700//
701// If the flag MCalibrationPix::IsHiGainSaturation() is set, call also:
702// - MCalibrationChargePix::CalcLoGainPedestal()
703//
704void MCalibrationChargeCalc::FinalizePedestals(const MPedestalPix &ped, MCalibrationChargePix &cal)
705{
706
707 //
708 // get the pedestals
709 //
710 const Float_t pedes = ped.GetPedestal();
711 const Float_t prms = ped.GetPedestalRms();
712 const Float_t num = TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
713
714 //
715 // set them in the calibration camera
716 //
717 if (cal.IsHiGainSaturation())
718 {
719 cal.SetPedestal(pedes* fNumLoGainSamples,
720 prms * fSqrtLoGainSamples,
721 prms * fNumLoGainSamples / num);
722 cal.CalcLoGainPedestal((Float_t)fNumLoGainSamples);
723 }
724 else
725 {
726 cal.SetPedestal(pedes* fNumHiGainSamples,
727 prms * fSqrtHiGainSamples,
728 prms * fNumHiGainSamples / num);
729 }
730
731}
732
733// ----------------------------------------------------------------------------------------------------
734//
735// Check fit results validity. Bad Pixels flags are set if:
736//
737// 1) Pixel has a mean smaller than fChargeLimit*PedRMS ( Flag: MBadPixelsPix::kChargeIsPedestal)
738// 2) Pixel has a mean error smaller than fChargeErrLimit ( Flag: MBadPixelsPix::kChargeErrNotValid)
739// 3) Pixel has mean smaller than fChargeRelVarLimit times its mean error
740// ( Flag: MBadPixelsPix::kChargeRelErrNotValid)
741// 4) Pixel has a sigma bigger than its Pedestal RMS ( Flag: MBadPixelsPix::kChargeSigmaNotValid )
742//
743// Further returns if flags: MBadPixelsPix::kUnsuitableRun is set
744//
745// Calls MCalibrationChargePix::CalcReducedSigma() and sets flag: MBadPixelsPix::kChargeIsPedestal
746// if not succesful.
747//
748// Calls MCalibrationChargePix::CalcFFactorMethod() and sets flag: MBadPixelsPix::kDeviatingNumPhes)
749// if not succesful.
750//
751Bool_t MCalibrationChargeCalc::FinalizeCharges(MCalibrationChargePix &cal, MBadPixelsPix &bad)
752{
753
754 if (cal.GetMean() < fChargeLimit*cal.GetPedRms())
755 {
756 *fLog << warn << GetDescriptor() << ": Fitted Charge: " << cal.GetMean() << " is smaller than "
757 << fChargeLimit << " Pedestal RMS: " << cal.GetPedRms() << " in Pixel " << cal.GetPixId() << endl;
758 bad.SetUncalibrated( MBadPixelsPix::kChargeIsPedestal);
759 }
760
761 if (cal.GetMeanErr() < fChargeErrLimit)
762 {
763 *fLog << warn << GetDescriptor() << ": Error of Fitted Charge: " << cal.GetMeanErr()
764 << " is smaller than " << fChargeErrLimit << " in Pixel " << cal.GetPixId() << endl;
765 bad.SetUncalibrated( MBadPixelsPix::kChargeErrNotValid );
766 }
767
768 if (cal.GetMean() < fChargeRelErrLimit*cal.GetMeanErr())
769 {
770 *fLog << warn << GetDescriptor() << ": Fitted Charge: " << cal.GetMean() << " is smaller than "
771 << fChargeRelErrLimit << "* its error: " << cal.GetMeanErr()
772 << " in Pixel " << cal.GetPixId() << endl;
773 bad.SetUncalibrated( MBadPixelsPix::kChargeRelErrNotValid );
774 }
775
776 if (cal.GetSigma() < cal.GetPedRms())
777 {
778 *fLog << warn << GetDescriptor() << ": Sigma of Fitted Charge: " << cal.GetSigma()
779 << " smaller than Pedestal RMS: " << cal.GetPedRms() << " in Pixel " << cal.GetPixId() << endl;
780 bad.SetUncalibrated( MBadPixelsPix::kChargeSigmaNotValid );
781 }
782
783 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
784 return kFALSE;
785
786 if (!cal.CalcReducedSigma())
787 {
788 *fLog << warn << GetDescriptor()
789 << ": Could not calculate reduced sigmas of pixel: " << cal.GetPixId() << endl;
790 bad.SetUncalibrated(MBadPixelsPix::kChargeIsPedestal);
791 return kFALSE;
792 }
793
794 if (!cal.CalcFFactorMethod())
795 {
796 *fLog << warn << GetDescriptor()
797 << ": Could not calculate F-Factor of pixel: " << cal.GetPixId() << endl;
798 bad.SetUncalibrated(MBadPixelsPix::kDeviatingNumPhes);
799 return kFALSE;
800 }
801
802 return kTRUE;
803}
804
805
806
807// -----------------------------------------------------------------------------------
808//
809// Sets pixel to MBadPixelsPix::kUnsuitableRun, if one of the following flags is set:
810// - MBadPixelsPix::kChargeIsPedestal
811// - MBadPixelsPix::kChargeErrNotValid
812// - MBadPixelsPix::kChargeRelErrNotValid
813// - MBadPixelsPix::kChargeSigmaNotValid
814// - MBadPixelsPix::kMeanTimeInFirstBin
815// - MBadPixelsPix::kMeanTimeInLast2Bins
816//
817// Sets pixel to MBadPixelsPix::kUnreliableRun, if one of the following flags is set:
818// - MBadPixelsPix::kDeviatingNumPhes
819//
820void MCalibrationChargeCalc::FinalizeBadPixels()
821{
822
823 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
824 {
825
826 MBadPixelsPix &bad = (*fBadPixels)[i];
827
828 if (bad.IsUncalibrated( MBadPixelsPix::kChargeIsPedestal))
829 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
830
831 if (bad.IsUncalibrated( MBadPixelsPix::kChargeErrNotValid ))
832 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
833
834 if (bad.IsUncalibrated( MBadPixelsPix::kChargeRelErrNotValid ))
835 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
836
837 if (bad.IsUncalibrated( MBadPixelsPix::kChargeSigmaNotValid ))
838 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
839
840 if (bad.IsUncalibrated( MBadPixelsPix::kMeanTimeInFirstBin ))
841 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
842
843 if (bad.IsUncalibrated( MBadPixelsPix::kMeanTimeInLast2Bins ))
844 bad.SetUnsuitable( MBadPixelsPix::kUnsuitableRun );
845
846 if (bad.IsUncalibrated( MBadPixelsPix::kDeviatingNumPhes ))
847 bad.SetUnsuitable( MBadPixelsPix::kUnreliableRun );
848 }
849}
850
851// ------------------------------------------------------------------------
852//
853//
854// First loop: Calculate a mean and mean RMS of photo-electrons per area index
855// Include only pixels which are not MBadPixelsPix::kUnsuitableRun or
856// MBadPixelsPix::kUnreliableRun (see FinalizeBadPixels()) and set
857// MCalibrationChargePix::SetFFactorMethodValid(kFALSE) in that case.
858//
859// Second loop: Get weighted mean number of photo-electrons and its RMS including
860// only pixels with flag MCalibrationChargePix::IsFFactorMethodValid()
861// and further exclude those deviating by more than fPheErrLimit mean
862// sigmas from the mean (obtained in first loop). Set
863// MBadPixelsPix::kDeviatingNumPhes if excluded.
864//
865// Set weighted mean and variance of photo-electrons per area index in:
866// average area pixels of MCalibrationChargeCam (obtained from:
867// MCalibrationChargeCam::GetAverageArea() )
868//
869// Set weighted mean and variance of photo-electrons per sector in:
870// average sector pixels of MCalibrationChargeCam (obtained from:
871// MCalibrationChargeCam::GetAverageSector() )
872//
873Bool_t MCalibrationChargeCalc::FinalizeFFactorMethod()
874{
875
876 const UInt_t npixels = fGeom->GetNumPixels();
877 const UInt_t nareas = fGeom->GetNumAreas();
878 const UInt_t nsectors = fGeom->GetNumSectors();
879
880 Float_t lowlim [nareas];
881 Float_t upplim [nareas];
882 Float_t areavars [nareas];
883 Float_t areaweights [nareas], sectorweights [nsectors];
884 Float_t areaphes [nareas], sectorphes [nsectors];
885 Int_t numareavalid[nareas], numsectorvalid[nsectors];
886
887 memset(lowlim ,0, nareas * sizeof(Float_t));
888 memset(upplim ,0, nareas * sizeof(Float_t));
889 memset(areaphes ,0, nareas * sizeof(Float_t));
890 memset(areavars ,0, nareas * sizeof(Float_t));
891 memset(areaweights ,0, nareas * sizeof(Float_t));
892 memset(numareavalid ,0, nareas * sizeof(Int_t ));
893 memset(sectorweights ,0, nsectors * sizeof(Float_t));
894 memset(sectorphes ,0, nsectors * sizeof(Float_t));
895 memset(numsectorvalid,0, nsectors * sizeof(Int_t ));
896
897 //
898 // First loop: Get mean number of photo-electrons and the RMS
899 // The loop is only to recognize later pixels with very deviating numbers
900 //
901 for (UInt_t i=0; i<npixels; i++)
902 {
903
904 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam) [i];
905 MBadPixelsPix &bad = (*fBadPixels)[i];
906
907 if (!pix.IsFFactorMethodValid())
908 continue;
909
910 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
911 {
912 pix.SetFFactorMethodValid(kFALSE);
913 continue;
914 }
915
916 if (bad.IsUnsuitable(MBadPixelsPix::kUnreliableRun))
917 continue;
918
919 const Float_t nphe = pix.GetPheFFactorMethod();
920 const Float_t nvar = pix.GetPheFFactorMethodVar();
921 const Int_t aidx = (*fGeom)[i].GetAidx();
922
923 if (nvar > 0.)
924 {
925 areaphes [aidx] += nphe;
926 areavars [aidx] += nvar;
927 numareavalid[aidx] ++;
928 }
929 }
930
931 for (UInt_t i=0; i<nareas; i++)
932 {
933 if (numareavalid[i] == 0)
934 {
935 *fLog << warn << GetDescriptor() << ": No pixels with valid number of photo-electrons found "
936 << "in area index: " << i << endl;
937 continue;
938 }
939
940 areaphes[i] = areaphes[i] / numareavalid[i];
941 areavars[i] = areavars[i] / numareavalid[i];
942 lowlim [i] = areaphes[i] - fPheErrLimit*TMath::Sqrt(areavars[i]);
943 upplim [i] = areaphes[i] + fPheErrLimit*TMath::Sqrt(areavars[i]);
944 }
945
946 memset(numareavalid,0,nareas*sizeof(Int_t));
947 memset(areaphes ,0,nareas*sizeof(Int_t));
948 memset(areavars ,0,nareas*sizeof(Int_t));
949
950 //
951 // Second loop: Get weighted mean number of photo-electrons and its RMS excluding
952 // pixels deviating by more than fPheErrLimit sigma.
953 // Set the conversion factor FADC counts to photo-electrons
954 //
955 for (UInt_t i=0; i<npixels; i++)
956 {
957
958 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[i];
959
960 if (!pix.IsFFactorMethodValid())
961 continue;
962
963 const Float_t nvar = pix.GetPheFFactorMethodVar();
964
965 if (nvar <= 0.)
966 {
967 pix.SetFFactorMethodValid(kFALSE);
968 continue;
969 }
970
971 MBadPixelsPix &bad = (*fBadPixels)[i];
972
973 const Int_t aidx = (*fGeom)[i].GetAidx();
974 const Int_t sector = (*fGeom)[i].GetSector();
975 const Float_t nphe = pix.GetPheFFactorMethod();
976
977 if ( nphe < lowlim[aidx] || nphe > upplim[aidx] )
978 {
979 *fLog << warn << GetDescriptor() << ": Deviating number of photo-electrons: "
980 << Form("%4.2f",nphe) << " out of accepted limits: ["
981 << Form("%4.2f%s%4.2f",lowlim[aidx],",",upplim[aidx]) << "] in pixel " << i << endl;
982 bad.SetUncalibrated( MBadPixelsPix::kDeviatingNumPhes );
983 bad.SetUnsuitable ( MBadPixelsPix::kUnreliableRun );
984 continue;
985 }
986
987 const Float_t weight = 1./nvar;
988
989 areaweights [aidx] += weight;
990 areaphes [aidx] += weight*nphe;
991 numareavalid [aidx] ++;
992 sectorweights [sector] += weight;
993 sectorphes [sector] += weight*nphe;
994 numsectorvalid[sector] ++;
995 }
996
997 for (UInt_t aidx=0; aidx<nareas; aidx++)
998 {
999
1000 MCalibrationChargePix &apix = (MCalibrationChargePix&)fCam->GetAverageArea(aidx);
1001
1002 if (areaweights[aidx] <= 0. || areaphes[aidx] <= 0.)
1003 {
1004 *fLog << warn << " Mean number of phe's from area index " << aidx << " cannot be calculated: "
1005 << " Sum of weights: " << areaweights[aidx]
1006 << " Sum of weighted phes: " << areaphes[aidx] << endl;
1007 apix.SetFFactorMethodValid(kFALSE);
1008 continue;
1009 }
1010
1011 *fLog << inf << "Replacing number photo-electrons of average area idx " << aidx << ": "
1012 << Form("%5.3f%s%5.3f",apix.GetPheFFactorMethod()," +- ",apix.GetPheFFactorMethodErr()) << endl;
1013 *fLog << inf << " by average number of photo-electrons from area idx " << aidx << ": "
1014 << Form("%5.3f%s%5.3f",areaphes[aidx] / areaweights[aidx]," +- ",
1015 TMath::Sqrt(1./areaweights[aidx])) << endl;
1016
1017 apix.SetPheFFactorMethod ( areaphes[aidx]/ areaweights[aidx] );
1018 apix.SetPheFFactorMethodVar( 1. / areaweights[aidx] );
1019 apix.SetFFactorMethodValid ( kTRUE );
1020
1021 }
1022
1023 for (UInt_t sector=0; sector<nsectors; sector++)
1024 {
1025
1026 MCalibrationChargePix &spix = (MCalibrationChargePix&)fCam->GetAverageSector(sector);
1027
1028 if (sectorweights[sector] <= 0. || sectorphes[sector] <= 0.)
1029 {
1030 *fLog << warn << " Mean number of phe's from sector " << sector << " cannot be calculated: "
1031 << " Sum of weights: " << sectorweights[sector]
1032 << " Sum of weighted phes: " << sectorphes[sector] << endl;
1033 spix.SetFFactorMethodValid(kFALSE);
1034 continue;
1035 }
1036
1037 *fLog << inf << "Replacing number photo-electrons of average sector " << sector << ": "
1038 << Form("%5.3f%s%5.3f",spix.GetPheFFactorMethod()," +- ",spix.GetPheFFactorMethodErr()) << endl;
1039 *fLog << inf << " by average number photo-electrons from sector " << sector << ": "
1040 << Form("%5.3f%s%5.3f",sectorphes[sector]/ sectorweights[sector]," +- ",
1041 TMath::Sqrt(1./sectorweights[sector])) << endl;
1042
1043 spix.SetPheFFactorMethod ( sectorphes[sector]/ sectorweights[sector] );
1044 spix.SetPheFFactorMethodVar( 1. / sectorweights[sector] );
1045 spix.SetFFactorMethodValid ( kTRUE );
1046
1047 }
1048
1049 return kTRUE;
1050}
1051
1052
1053// ------------------------------------------------------------------------
1054//
1055// Returns kFALSE if pointer to MCalibrationChargeBlindPix is NULL
1056//
1057// The check returns kFALSE if:
1058//
1059// 1) fLambda and fLambdaCheck are separated relatively to each other by more than fLambdaCheckLimit
1060// 2) BlindPixel has an fLambdaErr greater than fLambdaErrLimit
1061//
1062// Calls:
1063// - MCalibrationChargeBlindPix::CalcFluxInsidePlexiglass()
1064//
1065Bool_t MCalibrationChargeCalc::FinalizeBlindPixel()
1066{
1067
1068 if (!fBlindPixel)
1069 return kFALSE;
1070
1071 const Float_t lambda = fBlindPixel->GetLambda();
1072 const Float_t lambdaerr = fBlindPixel->GetLambdaErr();
1073 const Float_t lambdacheck = fBlindPixel->GetLambdaCheck();
1074
1075 if (2.*(lambdacheck-lambda)/(lambdacheck+lambda) < fLambdaCheckLimit)
1076 {
1077 *fLog << warn << GetDescriptor() << ": Lambda and Lambda-Check differ by more than "
1078 << fLambdaCheckLimit << " in the Blind Pixel " << endl;
1079 return kFALSE;
1080 }
1081
1082 if (lambdaerr < fLambdaErrLimit)
1083 {
1084 *fLog << warn << GetDescriptor() << ": Error of Fitted Lambda is greater than "
1085 << fLambdaErrLimit << " in Blind Pixel " << endl;
1086 return kFALSE;
1087 }
1088
1089 if (!fBlindPixel->CalcFluxInsidePlexiglass())
1090 {
1091 *fLog << warn << "Could not calculate the flux of photons from the Blind Pixel, "
1092 << "will skip Blind Pixel Calibration " << endl;
1093 return kFALSE;
1094 }
1095
1096 return kTRUE;
1097}
1098
1099// ------------------------------------------------------------------------
1100//
1101// Returns kFALSE if pointer to MCalibrationChargePINDiode is NULL
1102//
1103// The check returns kFALSE if:
1104//
1105// 1) PINDiode has a fitted charge smaller than fChargeLimit*PedRMS
1106// 2) PINDiode has a fit error smaller than fChargeErrLimit
1107// 3) PINDiode has a fitted charge smaller its fChargeRelErrLimit times its charge error
1108// 4) PINDiode has a charge sigma smaller than its Pedestal RMS
1109//
1110// Calls:
1111// - MCalibrationChargePINDiode::CalcFluxOutsidePlexiglass()
1112//
1113Bool_t MCalibrationChargeCalc::FinalizePINDiode()
1114{
1115
1116 if (!fPINDiode)
1117 return kFALSE;
1118
1119 if (fPINDiode->GetMean() < fChargeLimit*fPINDiode->GetPedRms())
1120 {
1121 *fLog << warn << GetDescriptor() << ": Fitted Charge is smaller than "
1122 << fChargeLimit << " Pedestal RMS in PINDiode " << endl;
1123 return kFALSE;
1124 }
1125
1126 if (fPINDiode->GetMeanErr() < fChargeErrLimit)
1127 {
1128 *fLog << warn << GetDescriptor() << ": Error of Fitted Charge is smaller than "
1129 << fChargeErrLimit << " in PINDiode " << endl;
1130 return kFALSE;
1131 }
1132
1133 if (fPINDiode->GetMean() < fChargeRelErrLimit*fPINDiode->GetMeanErr())
1134 {
1135 *fLog << warn << GetDescriptor() << ": Fitted Charge is smaller than "
1136 << fChargeRelErrLimit << "* its error in PINDiode " << endl;
1137 return kFALSE;
1138 }
1139
1140 if (fPINDiode->GetSigma() < fPINDiode->GetPedRms())
1141 {
1142 *fLog << warn << GetDescriptor()
1143 << ": Sigma of Fitted Charge smaller than Pedestal RMS in PINDiode " << endl;
1144 return kFALSE;
1145 }
1146
1147
1148 if (!fPINDiode->CalcFluxOutsidePlexiglass())
1149 {
1150 *fLog << warn << "Could not calculate the flux of photons from the PIN Diode, "
1151 << "will skip PIN Diode Calibration " << endl;
1152 return kFALSE;
1153 }
1154
1155 return kTRUE;
1156}
1157
1158// ------------------------------------------------------------------------
1159//
1160// Calculate the average number of photons outside the plexiglass with the
1161// formula:
1162//
1163// av.Num.photons(area index) = av.Num.Phes(area index)
1164// / MCalibrationQEPix::GetDefaultQE(fPulserColor)
1165// / MCalibrationQECam::GetPlexiglassQE()
1166//
1167// Calculate the variance on the average number of photons.
1168//
1169// Loop over pixels:
1170//
1171// - Continue, if not MCalibrationChargePix::IsFFactorMethodValid() and set:
1172// MCalibrationQEPix::SetFFactorMethodValid(kFALSE,fPulserColor)
1173//
1174// - Call MCalibrationChargePix::CalcMeanFFactor(av.Num.photons) and set:
1175// MCalibrationQEPix::SetFFactorMethodValid(kFALSE,fPulserColor) if not succesful
1176//
1177// - Calculate the quantum efficiency with the formula:
1178//
1179// QE = ( Num.Phes / av.Num.photons ) * MGeomCam::GetPixRatio()
1180//
1181// - Set QE in MCalibrationQEPix::SetQEFFactor ( QE, fPulserColor );
1182// - Set Variance of QE in MCalibrationQEPix::SetQEFFactorVar ( Variance, fPulserColor );
1183// - Set bit MCalibrationQEPix::SetFFactorMethodValid(kTRUE,fPulserColor)
1184//
1185// - Call MCalibrationQEPix::UpdateFFactorMethod()
1186//
1187void MCalibrationChargeCalc::FinalizeFFactorQECam()
1188{
1189
1190 MCalibrationChargePix &avpix = (MCalibrationChargePix&)fCam->GetAverageArea(0);
1191 MCalibrationQEPix &qepix = (MCalibrationQEPix&) fQECam->GetAverageArea(0);
1192
1193 const Float_t avphotons = avpix.GetPheFFactorMethod()
1194 / qepix.GetQEFFactor(fPulserColor)
1195 / fQECam->GetPlexiglassQE();
1196
1197 const Float_t avphotrelvar = avpix.GetPheFFactorMethodRelVar()
1198 + qepix.GetQEFFactorRelVar(fPulserColor)
1199 + fQECam->GetPlexiglassQERelVar();
1200
1201 const UInt_t npixels = fGeom->GetNumPixels();
1202
1203 for (UInt_t i=0; i<npixels; i++)
1204 {
1205
1206 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[i];
1207 MCalibrationQEPix &qepix = (MCalibrationQEPix&) (*fQECam)[i];
1208
1209 if (!pix.IsFFactorMethodValid())
1210 {
1211 qepix.SetFFactorMethodValid(kFALSE,fPulserColor);
1212 continue;
1213 }
1214
1215 const Float_t photons = avphotons / fGeom->GetPixRatio(i);
1216 const Float_t qe = pix.GetPheFFactorMethod() / photons ;
1217
1218 if (!pix.CalcMeanFFactor( photons , avphotrelvar ))
1219 {
1220 pix.SetFFactorMethodValid(kFALSE);
1221 qepix.SetFFactorMethodValid(kFALSE, fPulserColor);
1222 (*fBadPixels)[i].SetUncalibrated( MBadPixelsPix::kDeviatingNumPhes );
1223 }
1224
1225 const Float_t qerelvar = avphotrelvar + pix.GetPheFFactorMethodRelVar();
1226
1227 qepix.SetQEFFactor ( qe , fPulserColor );
1228 qepix.SetQEFFactorVar ( qerelvar*qe*qe, fPulserColor );
1229 qepix.SetFFactorMethodValid( kTRUE , fPulserColor );
1230
1231 if (!qepix.UpdateFFactorMethod())
1232 *fLog << warn << GetDescriptor()
1233 << ": Cannot update Quantum efficiencies with the F-Factor Method" << endl;
1234 }
1235}
1236
1237
1238// ------------------------------------------------------------------------
1239//
1240// Loop over pixels:
1241//
1242// - Continue, if not MCalibrationChargeBlindPix::IsFluxInsidePlexiglassAvailable() and set:
1243// MCalibrationQEPix::SetBlindPixelMethodValid(kFALSE,fPulserColor)
1244//
1245// - Calculate the quantum efficiency with the formula:
1246//
1247// QE = Num.Phes / MCalibrationChargeBlindPix::GetFluxInsidePlexiglass()
1248// / MGeomPix::GetA() * MCalibrationQECam::GetPlexiglassQE()
1249//
1250// - Set QE in MCalibrationQEPix::SetQEBlindPixel ( QE, fPulserColor );
1251// - Set Variance of QE in MCalibrationQEPix::SetQEBlindPixelVar ( Variance, fPulserColor );
1252// - Set bit MCalibrationQEPix::SetBlindPixelMethodValid(kTRUE,fPulserColor)
1253//
1254// - Call MCalibrationQEPix::UpdateBlindPixelMethod()
1255//
1256void MCalibrationChargeCalc::FinalizeBlindPixelQECam()
1257{
1258
1259 const UInt_t npixels = fGeom->GetNumPixels();
1260
1261 //
1262 // With the knowledge of the overall photon flux, calculate the
1263 // quantum efficiencies after the Blind Pixel and PIN Diode method
1264 //
1265 for (UInt_t i=0; i<npixels; i++)
1266 {
1267
1268 MCalibrationQEPix &qepix = (MCalibrationQEPix&) (*fQECam)[i];
1269
1270 if (!fBlindPixel)
1271 {
1272 qepix.SetBlindPixelMethodValid(kFALSE, fPulserColor);
1273 continue;
1274 }
1275
1276 if (!fBlindPixel->IsFluxInsidePlexiglassAvailable())
1277 {
1278 qepix.SetBlindPixelMethodValid(kFALSE, fPulserColor);
1279 continue;
1280 }
1281
1282 MBadPixelsPix &bad = (*fBadPixels)[i];
1283
1284 if (!bad.IsUnsuitable (MBadPixelsPix::kUnsuitableRun))
1285 {
1286 qepix.SetBlindPixelMethodValid(kFALSE, fPulserColor);
1287 continue;
1288 }
1289
1290 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[i];
1291 MGeomPix &geo = (*fGeom)[i];
1292
1293 const Float_t qe = pix.GetPheFFactorMethod()
1294 / fBlindPixel->GetFluxInsidePlexiglass()
1295 / geo.GetA()
1296 * fQECam->GetPlexiglassQE();
1297
1298 const Float_t qerelvar = fBlindPixel->GetFluxInsidePlexiglassRelVar()
1299 + fQECam->GetPlexiglassQERelVar()
1300 + pix.GetPheFFactorMethodRelVar();
1301
1302 qepix.SetQEBlindPixel ( qe , fPulserColor );
1303 qepix.SetQEBlindPixelVar ( qerelvar*qe*qe, fPulserColor );
1304 qepix.UpdateBlindPixelMethod();
1305 }
1306}
1307
1308// ------------------------------------------------------------------------
1309//
1310// Loop over pixels:
1311//
1312// - Continue, if not MCalibrationChargePINDiode::IsFluxOutsidePlexiglassAvailable() and set:
1313// MCalibrationQEPix::SetPINDiodeMethodValid(kFALSE,fPulserColor)
1314//
1315// - Calculate the quantum efficiency with the formula:
1316//
1317// QE = Num.Phes / MCalibrationChargePINDiode::GetFluxOutsidePlexiglass() / MGeomPix::GetA()
1318//
1319// - Set QE in MCalibrationQEPix::SetQEPINDiode ( QE, fPulserColor );
1320// - Set Variance of QE in MCalibrationQEPix::SetQEPINDiodeVar ( Variance, fPulserColor );
1321// - Set bit MCalibrationQEPix::SetPINDiodeMethodValid(kTRUE,fPulserColor)
1322//
1323// - Call MCalibrationQEPix::UpdatePINDiodeMethod()
1324//
1325void MCalibrationChargeCalc::FinalizePINDiodeQECam()
1326{
1327
1328 const UInt_t npixels = fGeom->GetNumPixels();
1329
1330 //
1331 // With the knowledge of the overall photon flux, calculate the
1332 // quantum efficiencies after the PIN Diode method
1333 //
1334 for (UInt_t i=0; i<npixels; i++)
1335 {
1336
1337 MCalibrationQEPix &qepix = (MCalibrationQEPix&) (*fQECam)[i];
1338
1339 if (!fPINDiode)
1340 {
1341 qepix.SetPINDiodeMethodValid(kFALSE, fPulserColor);
1342 continue;
1343 }
1344
1345 if (!fPINDiode->IsFluxOutsidePlexiglassAvailable())
1346 {
1347 qepix.SetPINDiodeMethodValid(kFALSE, fPulserColor);
1348 continue;
1349 }
1350
1351 MBadPixelsPix &bad = (*fBadPixels)[i];
1352
1353 if (!bad.IsUnsuitable (MBadPixelsPix::kUnsuitableRun))
1354 {
1355 qepix.SetPINDiodeMethodValid(kFALSE, fPulserColor);
1356 continue;
1357 }
1358
1359 MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[i];
1360 MGeomPix &geo = (*fGeom)[i];
1361
1362 const Float_t qe = pix.GetPheFFactorMethod()
1363 / fPINDiode->GetFluxOutsidePlexiglass()
1364 / geo.GetA();
1365
1366 const Float_t qerelvar = fPINDiode->GetFluxOutsidePlexiglassRelVar() + pix.GetPheFFactorMethodRelVar();
1367
1368 qepix.SetQEPINDiode ( qe , fPulserColor );
1369 qepix.SetQEPINDiodeVar ( qerelvar*qe*qe, fPulserColor );
1370 qepix.UpdateBlindPixelMethod();
1371 }
1372}
1373
1374// -----------------------------------------------------------------------------------------------
1375//
1376// - Print out statistics about BadPixels of type UnsuitableType_t
1377// - store numbers of bad pixels of each type in fCam
1378//
1379void MCalibrationChargeCalc::FinalizeUnsuitablePixels()
1380{
1381
1382 *fLog << inf << endl;
1383 *fLog << GetDescriptor() << ": Calibration statistics:" << endl;
1384 *fLog << dec << setfill(' ');
1385
1386 const Int_t nareas = fGeom->GetNumAreas();
1387
1388 Int_t counts[nareas];
1389 memset(counts,0,nareas*sizeof(Int_t));
1390
1391 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
1392 {
1393 MBadPixelsPix &bad = (*fBadPixels)[i];
1394 if (bad.IsOK())
1395 {
1396 const Int_t aidx = (*fGeom)[i].GetAidx();
1397 counts[aidx]++;
1398 }
1399 }
1400
1401 if (fGeom->InheritsFrom("MGeomCamMagic"))
1402 *fLog << " " << setw(7) << "Successfully calibrated Pixels: "
1403 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
1404
1405 memset(counts,0,nareas*sizeof(Int_t));
1406
1407 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
1408 {
1409 MBadPixelsPix &bad = (*fBadPixels)[i];
1410 if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
1411 {
1412 const Int_t aidx = (*fGeom)[i].GetAidx();
1413 counts[aidx]++;
1414 }
1415 }
1416
1417 for (Int_t aidx=0; aidx<nareas; aidx++)
1418 fCam->SetNumUncalibrated(counts[aidx], aidx);
1419
1420 if (fGeom->InheritsFrom("MGeomCamMagic"))
1421 *fLog << " " << setw(7) << "Uncalibrated Pixels: "
1422 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
1423
1424 memset(counts,0,nareas*sizeof(Int_t));
1425
1426 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
1427 {
1428 MBadPixelsPix &bad = (*fBadPixels)[i];
1429 if (bad.IsUnsuitable(MBadPixelsPix::kUnreliableRun))
1430 {
1431 const Int_t aidx = (*fGeom)[i].GetAidx();
1432 counts[aidx]++;
1433 }
1434 }
1435
1436 for (Int_t aidx=0; aidx<nareas; aidx++)
1437 fCam->SetNumUnreliable(counts[aidx], aidx);
1438
1439 *fLog << " " << setw(7) << "Unreliable Pixels: "
1440 << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
1441
1442}
1443
1444// -----------------------------------------------------------------------------------------------
1445//
1446// Print out statistics about BadPixels of type UncalibratedType_t
1447//
1448void MCalibrationChargeCalc::PrintUncalibrated(MBadPixelsPix::UncalibratedType_t typ, const char *text) const
1449{
1450
1451 UInt_t countinner = 0;
1452 UInt_t countouter = 0;
1453 for (Int_t i=0; i<fBadPixels->GetSize(); i++)
1454 {
1455 MBadPixelsPix &bad = (*fBadPixels)[i];
1456 if (bad.IsUncalibrated(typ))
1457 {
1458 if (fGeom->GetPixRatio(i) == 1.)
1459 countinner++;
1460 else
1461 countouter++;
1462 }
1463 }
1464
1465 *fLog << " " << setw(7) << text
1466 << Form("%s%3i%s%3i","Inner: ",countinner," Outer: ",countouter) << endl;
1467}
1468
Note: See TracBrowser for help on using the repository browser.