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

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