source: trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc@ 3028

Last change on this file since 3028 was 3028, checked in by gaug, 21 years ago
*** empty log message ***
File size: 26.8 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 11/2003 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MCalibrationPix //
28// //
29// This is the storage container to hold informations about the pedestal //
30// (offset) value of one Pixel (PMT). //
31// //
32// The following values are initialized to meaningful values:
33//
34// - The Electronic Rms to 1.5 per FADC slice
35// - The uncertainty about the Electronic RMS to 0.3 per slice
36// - The F-Factor is assumed to have been measured in Munich to 1.13 - 1.17.
37// with the Munich definition of the F-Factor, thus:
38// F = Sigma(Out)/Mean(Out) * Mean(In)/Sigma(In)
39// Mean F-Factor = 1.15
40// Error F-Factor = 0.02
41//
42/////////////////////////////////////////////////////////////////////////////
43#include "MCalibrationPix.h"
44#include "MCalibrationConfig.h"
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49ClassImp(MCalibrationPix);
50
51using namespace std;
52
53const Float_t MCalibrationPix::gkElectronicPedRms = 1.5;
54const Float_t MCalibrationPix::gkErrElectronicPedRms = 0.3;
55const Float_t MCalibrationPix::gkFFactor = 1.15;
56const Float_t MCalibrationPix::gkFFactorError = 0.02;
57const Float_t MCalibrationPix::gkChargeLimit = 3.;
58const Float_t MCalibrationPix::gkChargeErrLimit = 0.;
59const Float_t MCalibrationPix::gkChargeRelErrLimit = 1.;
60const Float_t MCalibrationPix::gkTimeLimit = 1.5;
61const Float_t MCalibrationPix::gkTimeErrLimit = 3.;
62const Float_t MCalibrationPix::gkConvFFactorRelErrorLimit = 0.1;
63
64// --------------------------------------------------------------------------
65//
66// Default Constructor:
67//
68MCalibrationPix::MCalibrationPix(const char *name, const char *title)
69 : fPixId(-1),
70 fFlags(0)
71{
72
73 fName = name ? name : "MCalibrationPixel";
74 fTitle = title ? title : "Container of the MHCalibrationPixels and the fit results";
75
76 //
77 // At the moment, we don't have a database, yet,
78 // so we get it from the configuration file
79 //
80 fConversionHiLo = gkConversionHiLo;
81 fConversionHiLoError = gkConversionHiLoError;
82
83 fHist = new MHCalibrationPixel("MHCalibrationPixel","Calibration Histograms Pixel ");
84
85 if (!fHist)
86 *fLog << warn << dbginf << " Could not create MHCalibrationPixel " << endl;
87
88 Clear();
89}
90
91MCalibrationPix::~MCalibrationPix()
92{
93 delete fHist;
94}
95
96
97// ------------------------------------------------------------------------
98//
99// Invalidate values
100//
101void MCalibrationPix::Clear(Option_t *o)
102{
103
104 fHist->Reset();
105
106 CLRBIT(fFlags, kHiGainSaturation);
107 CLRBIT(fFlags, kExcluded);
108 CLRBIT(fFlags, kChargeFitValid);
109 CLRBIT(fFlags, kTimeFitValid);
110 CLRBIT(fFlags, kFitted);
111 CLRBIT(fFlags, kBlindPixelMethodValid);
112 CLRBIT(fFlags, kFFactorMethodValid);
113 CLRBIT(fFlags, kPINDiodeMethodValid);
114
115 fCharge = -1.;
116 fErrCharge = -1.;
117 fSigmaCharge = -1.;
118 fErrSigmaCharge = -1.;
119 fRSigmaCharge = -1.;
120 fErrRSigmaCharge = -1.;
121
122 fChargeProb = -1.;
123 fPed = -1.;
124 fPedRms = -1.;
125 fErrPedRms = 0.;
126
127 fNumHiGainSamples = -1.;
128 fNumLoGainSamples = -1.;
129
130 fMeanTimeOffset = -1.;
131 fMeanTimeOffsetError = -1.;
132 fTimingPrecision = -1.;
133 fTimeProb = -1.;
134 fTimeFirstHiGain = 0 ;
135 fTimeLastHiGain = 0 ;
136 fTimeFirstLoGain = 0 ;
137 fTimeLastLoGain = 0 ;
138
139 fAbsTimeMean = -1.;
140 fAbsTimeRms = -1.;
141
142 fPheFFactorMethod = -1.;
143 fPheFFactorMethodError = -1.;
144
145 fMeanConversionFFactorMethod = -1.;
146 fMeanConversionBlindPixelMethod = -1.;
147 fMeanConversionPINDiodeMethod = -1.;
148
149 fErrorConversionFFactorMethod = -1.;
150 fErrorConversionBlindPixelMethod = -1.;
151 fErrorConversionPINDiodeMethod = -1.;
152
153 fSigmaConversionFFactorMethod = -1.;
154 fSigmaConversionBlindPixelMethod = -1.;
155 fSigmaConversionPINDiodeMethod = -1.;
156
157 fFactorCalculated = kFALSE;
158
159}
160
161
162void MCalibrationPix::DefinePixId(Int_t i)
163{
164
165 fPixId = i;
166 fHist->ChangeHistId(i);
167
168}
169
170
171// --------------------------------------------------------------------------
172//
173// Set the pedestals from outside
174//
175void MCalibrationPix::SetPedestal(const Float_t ped, const Float_t pedrms,
176 const Float_t higainsamp, const Float_t logainsamp )
177{
178
179 fPed = ped;
180 fPedRms = pedrms;
181
182 fNumHiGainSamples = higainsamp;
183 fNumLoGainSamples = logainsamp;
184
185}
186
187// --------------------------------------------------------------------------
188//
189// Set the conversion factors from outside (only for MC)
190//
191void MCalibrationPix::SetConversionFFactorMethod(Float_t c, Float_t err, Float_t sig)
192{
193 fMeanConversionFFactorMethod = c;
194 fErrorConversionFFactorMethod = err;
195 fSigmaConversionFFactorMethod = sig;
196}
197
198
199// --------------------------------------------------------------------------
200//
201// Set the conversion factors from outside (only for MC)
202//
203void MCalibrationPix::SetConversionBlindPixelMethod(Float_t c, Float_t err, Float_t sig)
204{
205 fMeanConversionBlindPixelMethod = c;
206 fErrorConversionBlindPixelMethod = err;
207 fSigmaConversionBlindPixelMethod = sig;
208}
209
210// --------------------------------------------------------------------------
211//
212// Set the conversion factors from outside (only for MC)
213//
214void MCalibrationPix::SetConversionPINDiodeMethod(Float_t c, Float_t err, Float_t sig)
215{
216 fMeanConversionPINDiodeMethod = c ;
217 fErrorConversionPINDiodeMethod = err;
218 fSigmaConversionPINDiodeMethod = sig;
219}
220
221// --------------------------------------------------------------------------
222//
223// Set the Hi Gain Saturation Bit from outside (only for MC)
224//
225void MCalibrationPix::SetHiGainSaturation(Bool_t b)
226{
227
228 if (b)
229 {
230 SETBIT(fFlags, kHiGainSaturation);
231 fHist->SetUseLoGain(1);
232 }
233 else
234 {
235 CLRBIT(fFlags, kHiGainSaturation);
236 fHist->SetUseLoGain(0);
237 }
238}
239
240// --------------------------------------------------------------------------
241//
242// Set the Excluded Bit from outside
243//
244void MCalibrationPix::SetExcluded(Bool_t b )
245{
246 b ? SETBIT(fFlags, kExcluded) : CLRBIT(fFlags, kExcluded);
247}
248
249
250// --------------------------------------------------------------------------
251//
252// Set the Excluded Bit from outside
253//
254void MCalibrationPix::SetExcludeQualityCheck(Bool_t b )
255{
256 b ? SETBIT(fFlags, kExcludeQualityCheck) : CLRBIT(fFlags, kExcludeQualityCheck);
257}
258
259// --------------------------------------------------------------------------
260//
261// Set the Excluded Bit from outside
262//
263void MCalibrationPix::SetChargeFitValid(Bool_t b )
264{
265 b ? SETBIT(fFlags, kChargeFitValid) : CLRBIT(fFlags, kChargeFitValid);
266}
267
268// --------------------------------------------------------------------------
269//
270// Set the Excluded Bit from outside
271//
272void MCalibrationPix::SetTimeFitValid(Bool_t b )
273{
274 b ? SETBIT(fFlags, kTimeFitValid) : CLRBIT(fFlags, kTimeFitValid);
275}
276
277// --------------------------------------------------------------------------
278//
279// Set the Excluded Bit from outside
280//
281void MCalibrationPix::SetFitted(Bool_t b )
282{
283 b ? SETBIT(fFlags, kFitted) : CLRBIT(fFlags, kFitted);
284}
285
286// --------------------------------------------------------------------------
287//
288// Set the Excluded Bit from outside
289//
290void MCalibrationPix::SetBlindPixelMethodValid(Bool_t b )
291{
292 b ? SETBIT(fFlags, kBlindPixelMethodValid) : CLRBIT(fFlags, kBlindPixelMethodValid);
293}
294
295// --------------------------------------------------------------------------
296//
297// Set the Excluded Bit from outside
298//
299void MCalibrationPix::SetFFactorMethodValid(Bool_t b )
300{
301 b ? SETBIT(fFlags, kFFactorMethodValid) : CLRBIT(fFlags, kFFactorMethodValid);
302}
303
304// --------------------------------------------------------------------------
305//
306// Set the Excluded Bit from outside
307//
308void MCalibrationPix::SetPINDiodeMethodValid(Bool_t b )
309{
310 b ? SETBIT(fFlags, kPINDiodeMethodValid) : CLRBIT(fFlags, kPINDiodeMethodValid);
311}
312
313void MCalibrationPix::SetAbsTimeBordersHiGain(Byte_t f, Byte_t l)
314{
315
316 fTimeFirstHiGain = f;
317 fTimeLastHiGain = l;
318
319}
320
321void MCalibrationPix::SetAbsTimeBordersLoGain(Byte_t f, Byte_t l)
322{
323
324 fTimeFirstLoGain = f;
325 fTimeLastLoGain = l;
326
327}
328
329Float_t MCalibrationPix::GetPheFFactorMethod()
330{
331
332 if (!fFactorCalculated)
333 CalcFFactorMethod();
334
335 return fPheFFactorMethod;
336
337}
338
339Float_t MCalibrationPix::GetPheFFactorMethodError()
340{
341
342 if (!fFactorCalculated)
343 CalcFFactorMethod();
344
345 return fPheFFactorMethodError;
346
347}
348
349
350Float_t MCalibrationPix::GetTotalFFactor()
351{
352 if (!fFactorCalculated)
353 CalcFFactorMethod();
354
355 return (fRSigmaCharge/fCharge)*TMath::Sqrt(fPheFFactorMethod);
356}
357
358Float_t MCalibrationPix::GetTotalFFactorError()
359{
360
361 if (!fFactorCalculated)
362 CalcFFactorMethod();
363
364 const Float_t rsigmaChargeRelErrSquare = fErrRSigmaCharge * fErrRSigmaCharge
365 / (fRSigmaCharge * fRSigmaCharge) ;
366 const Float_t rChargeRelErrSquare = fErrCharge * fErrCharge
367 / (fCharge * fCharge) ;
368 const Float_t rPheRelErrSquare = fPheFFactorMethodError * fPheFFactorMethodError
369 / (fPheFFactorMethod * fPheFFactorMethod) ;
370
371 return TMath::Sqrt(rsigmaChargeRelErrSquare+rChargeRelErrSquare+rPheRelErrSquare);
372}
373
374
375Float_t MCalibrationPix::GetMeanConversionFFactorMethod()
376{
377
378 if (!fFactorCalculated)
379 CalcFFactorMethod();
380
381 return fMeanConversionFFactorMethod;
382
383}
384
385Float_t MCalibrationPix::GetErrorConversionFFactorMethod()
386{
387
388 if (!fFactorCalculated)
389 CalcFFactorMethod();
390
391 return fErrorConversionFFactorMethod;
392
393}
394
395Float_t MCalibrationPix::GetSigmaConversionFFactorMethod()
396{
397
398 if (!fFactorCalculated)
399 CalcFFactorMethod();
400
401 return fSigmaConversionFFactorMethod;
402
403}
404
405
406Float_t MCalibrationPix::GetTimingPrecisionError() const
407{
408 return fMeanTimeOffsetError/2.;
409}
410
411
412Bool_t MCalibrationPix::IsExcluded() const
413 {
414 return TESTBIT(fFlags,kExcluded);
415 }
416
417Bool_t MCalibrationPix::IsChargeFitValid() const
418{
419 return TESTBIT(fFlags, kChargeFitValid);
420}
421
422Bool_t MCalibrationPix::IsTimeFitValid() const
423{
424 return TESTBIT(fFlags, kTimeFitValid);
425}
426
427Bool_t MCalibrationPix::IsFitted() const
428{
429 return TESTBIT(fFlags, kFitted);
430}
431
432Bool_t MCalibrationPix::IsBlindPixelMethodValid() const
433{
434 return TESTBIT(fFlags, kBlindPixelMethodValid);
435}
436
437Bool_t MCalibrationPix::IsFFactorMethodValid()
438{
439
440 if (!fFactorCalculated)
441 CalcFFactorMethod();
442
443 return TESTBIT(fFlags, kFFactorMethodValid);
444}
445
446Bool_t MCalibrationPix::IsPINDiodeMethodValid() const
447{
448 return TESTBIT(fFlags, kPINDiodeMethodValid);
449}
450
451
452// --------------------------------------------------------------------------
453//
454// 1) Return if the charge distribution is already succesfully fitted
455// or if the histogram is empty
456// 2) Set a lower Fit range according to 1.5 Pedestal RMS in order to avoid
457// possible remaining cosmics to spoil the fit.
458// 3) Decide if the LoGain Histogram is fitted or the HiGain Histogram
459// 4) Fit the histograms with a Gaussian
460// 5) In case of failure set the bit kFitted to false
461// 6) Retrieve the results and store them in this class
462// 7) Calculate the number of photo-electrons after the F-Factor method
463// 8) Calculate the errors of the F-Factor method
464//
465// The fits are declared valid (fFitValid = kTRUE), if:
466//
467// 1) Pixel has a fitted charge greater than 3*PedRMS
468// 2) Pixel has a fit error greater than 0.
469// 3) Pixel has a fit Probability greater than 0.0001
470// 4) Pixel has a charge sigma bigger than its Pedestal RMS
471// 5) If FitTimes is used,
472// the mean arrival time is at least 1.0 slices from the used edge slices
473// (this stage is only performed in the times fit)
474//
475// If the histogram is empty, all values are set to -1.
476//
477// The conversion factor after the F-Factor method is declared valid, if:
478//
479// 1) fFitValid is kTRUE
480// 2) Conversion Factor is bigger than 0.
481// 3) The error of the conversion factor is smaller than 10%
482//
483Bool_t MCalibrationPix::FitCharge()
484{
485
486 //
487 // 1) Return if the charge distribution is already succesfully fitted
488 // or if the histogram is empty
489 //
490 if (fHist->IsChargeFitOK() || fHist->IsEmpty())
491 return kTRUE;
492
493 //
494 // 2) Set a lower Fit range according to 1.5 Pedestal RMS in order to avoid
495 // possible remaining cosmics to spoil the fit.
496 //
497 // if (fPed && fPedRms)
498 // fHist->SetLowerFitRange(1.5*fPedRms);
499 // else
500 // *fLog << warn << "WARNING: Cannot set lower fit range: Pedestals not available" << endl;
501
502 //
503 // 3) Decide if the LoGain Histogram is fitted or the HiGain Histogram
504 //
505 if (fHist->UseLoGain())
506 SetHiGainSaturation();
507
508 //
509 // 4) Fit the Lo Gain histograms with a Gaussian
510 //
511 if (fHist->FitCharge())
512 SETBIT(fFlags,kFitted);
513 else
514 {
515 *fLog << warn << "WARNING: Could not fit charges of pixel " << fPixId << endl;
516 //
517 // 5) In case of failure set the bit kFitted to false
518 //
519 CLRBIT(fFlags,kFitted);
520 }
521
522 //
523 // 6) Retrieve the results and store them in this class
524 // If fFitted is false, we get the means and RMS of the histogram!!
525 //
526 fCharge = fHist->GetChargeMean();
527 fErrCharge = fHist->GetChargeMeanErr();
528 fSigmaCharge = fHist->GetChargeSigma();
529 fErrSigmaCharge = fHist->GetChargeSigmaErr();
530 fChargeProb = fHist->GetChargeProb();
531
532 //
533 // Calculate the conversion factors
534 //
535 if (TESTBIT(fFlags,kHiGainSaturation))
536 ApplyLoGainConversion();
537
538 if (CheckChargeFitValidity())
539 SETBIT(fFlags,kChargeFitValid);
540 else
541 {
542 CLRBIT(fFlags,kChargeFitValid);
543 return kFALSE;
544 }
545
546 return kTRUE;
547
548}
549
550//
551// Calculate the number of photo-electrons after the F-Factor method
552// Calculate the errors of the F-Factor method
553//
554Bool_t MCalibrationPix::CalcFFactorMethod()
555{
556
557 if ( (fCharge == -1.)
558 || (fErrCharge < 0.)
559 || (fSigmaCharge < 0.)
560 || (fPedRms < 0.) )
561 {
562 *fLog << warn << GetDescriptor() << "Cannot calculate the FFactor Method! "
563 << "Some of the needed parameters are not available ";
564 CLRBIT(fFlags,kFFactorMethodValid);
565 return kFALSE;
566 }
567
568 //
569 // Square all variables in order to avoid applications of square root
570 //
571 // First the relative error squares
572 //
573 const Float_t chargeSquare = fCharge* fCharge;
574 const Float_t chargeSquareRelErrSquare = 4.*fErrCharge*fErrCharge / chargeSquare;
575
576 const Float_t ffactorsquare = gkFFactor * gkFFactor;
577 const Float_t ffactorsquareRelErrSquare = 4.*gkFFactorError * gkFFactorError / ffactorsquare;
578 //
579 // Now the absolute error squares
580 //
581 const Float_t sigmaSquare = fSigmaCharge*fSigmaCharge;
582 const Float_t sigmaSquareErrSquare = 4.*fErrSigmaCharge*fErrSigmaCharge * sigmaSquare;
583
584 Float_t pedRmsSquare = fPedRms* fPedRms;
585 Float_t pedRmsSquareErrSquare = 4.*fErrPedRms*fErrPedRms * pedRmsSquare;
586
587 if (!TESTBIT(fFlags,kHiGainSaturation))
588 { /* HiGain */
589
590 pedRmsSquare *= fNumHiGainSamples;
591 pedRmsSquareErrSquare *= fNumHiGainSamples*fNumHiGainSamples;
592 }
593 else
594 { /* LoGain */
595
596 //
597 // We do not know the Lo Gain Pedestal RMS, so we have to retrieve it
598 // from the HI GAIN (all calculation per slice up to now):
599 //
600 // We extract the pure NSB contribution:
601 //
602 const Float_t elecRmsSquare = gkElectronicPedRms *gkElectronicPedRms;
603 const Float_t elecRmsSquareErrSquare = 4.*gkErrElectronicPedRms*gkErrElectronicPedRms * elecRmsSquare;
604
605 Float_t nsbSquare = pedRmsSquare - elecRmsSquare;
606 Float_t nsbSquareRelErrSquare = (pedRmsSquareErrSquare + elecRmsSquareErrSquare)
607 / (nsbSquare * nsbSquare) ;
608
609 if (nsbSquare < 0.)
610 nsbSquare = 0.;
611
612 //
613 // Now, we divide the NSB by the conversion factor and
614 // add it quadratically to the electronic noise
615 //
616 const Float_t conversionSquare = fConversionHiLo *fConversionHiLo;
617 const Float_t conversionSquareRelErrSquare = 4.*fConversionHiLoError*fConversionHiLoError/conversionSquare;
618
619 const Float_t convertedNsbSquare = nsbSquare / conversionSquare;
620 const Float_t convertedNsbSquareErrSquare = (nsbSquareRelErrSquare + conversionSquareRelErrSquare)
621 * convertedNsbSquare * convertedNsbSquare;
622
623 pedRmsSquare = convertedNsbSquare + elecRmsSquare;
624 pedRmsSquareErrSquare = convertedNsbSquareErrSquare + elecRmsSquareErrSquare;
625
626 //
627 // Now, correct for the number of used FADC slices in the LoGain:
628 //
629 pedRmsSquare *= fNumLoGainSamples;
630 pedRmsSquareErrSquare *= fNumLoGainSamples*fNumLoGainSamples;
631 //
632 // Correct also for the conversion to Hi-Gain:
633 //
634 pedRmsSquare *= fConversionHiLo*fConversionHiLo;
635 pedRmsSquareErrSquare *= fConversionHiLo*fConversionHiLo*fConversionHiLo*fConversionHiLo;
636
637 } /* if (HiGainSaturation) */
638
639 //
640 // Calculate the reduced sigmas
641 //
642 const Float_t rsigmachargesquare = sigmaSquare - pedRmsSquare;
643 if (rsigmachargesquare <= 0.)
644 {
645 *fLog << warn
646 << "WARNING: Cannot apply F-Factor calibration: Reduced Sigma smaller than 0 in pixel "
647 << fPixId << endl;
648 CLRBIT(fFlags,kFFactorMethodValid);
649 fFactorCalculated = kTRUE;
650 return kFALSE;
651 }
652
653 const Float_t rSigmaSquareRelErrSquare = (sigmaSquareErrSquare + pedRmsSquareErrSquare)
654 / (rsigmachargesquare * rsigmachargesquare) ;
655
656 fRSigmaCharge = TMath::Sqrt(rsigmachargesquare);
657 fErrRSigmaCharge = TMath::Sqrt(sigmaSquareErrSquare + pedRmsSquareErrSquare);
658
659
660 //
661 // Calculate the number of phe's from the F-Factor method
662 // (independent on Hi Gain or Lo Gain)
663 //
664 fPheFFactorMethod = ffactorsquare * chargeSquare / rsigmachargesquare;
665
666 const Float_t pheFFactorRelErrSquare = ffactorsquareRelErrSquare
667 + chargeSquareRelErrSquare
668 + rSigmaSquareRelErrSquare ;
669
670 fPheFFactorMethodError = TMath::Sqrt(pheFFactorRelErrSquare) * fPheFFactorMethod;
671
672 const Float_t chargeRelErrSquare = fErrCharge*fErrCharge / (fCharge * fCharge);
673
674 fMeanConversionFFactorMethod = fPheFFactorMethod / fCharge ;
675 fErrorConversionFFactorMethod = ( pheFFactorRelErrSquare + chargeRelErrSquare )
676 * fMeanConversionFFactorMethod * fMeanConversionFFactorMethod;
677
678 const Float_t convrelerror = fErrorConversionFFactorMethod/fMeanConversionFFactorMethod;
679
680 if ( (fMeanConversionFFactorMethod > 0.) && (convrelerror < gkConvFFactorRelErrorLimit))
681 SETBIT(fFlags,kFFactorMethodValid);
682
683 fFactorCalculated = kTRUE;
684
685 fSigmaConversionFFactorMethod = GetTotalFFactor()*TMath::Sqrt(fMeanConversionFFactorMethod);
686
687 return kTRUE;
688}
689
690
691//
692// The check returns kTRUE if:
693//
694// 0) Pixel has BIT fitted set:
695// This means:
696// a) No result is a nan
697// b) The NDF is not smaller than fNDFLimit (5)
698// c) The Probability is greater than gkProbLimit (default 0.001 == 99.9%)
699// 1) Pixel has a fitted charge greater than 3*PedRMS
700// 2) Pixel has a fit error greater than 0.
701// 3) Pixel has a fitted charge greater its charge error
702// 4) Pixel has a fit Probability greater than 0.0001
703// 5) Pixel has a charge sigma bigger than its Pedestal RMS
704//
705Bool_t MCalibrationPix::CheckChargeFitValidity()
706{
707
708 if (!TESTBIT(fFlags,kFitted))
709 return kFALSE;
710
711 if (TESTBIT(fFlags,kExcludeQualityCheck))
712 return kTRUE;
713
714 Float_t pedestal;
715
716 if (!TESTBIT(fFlags,kHiGainSaturation)) /* higain */
717 pedestal = GetPedRms()*TMath::Sqrt(fNumHiGainSamples);
718 else /* logain */
719 pedestal = GetPedRms()*TMath::Sqrt(fNumLoGainSamples);
720
721
722 if (fCharge < gkChargeLimit*pedestal)
723 {
724 *fLog << warn << "WARNING: Fitted Charge is smaller than "
725 << gkChargeLimit << " Pedestal RMS in Pixel " << fPixId << endl;
726 return kFALSE;
727 }
728
729 if (fErrCharge < gkChargeErrLimit)
730 {
731 *fLog << warn << "WARNING: Error of Fitted Charge is smaller than "
732 << gkChargeErrLimit << " in Pixel " << fPixId << endl;
733 return kFALSE;
734 }
735
736 if (fCharge < gkChargeRelErrLimit*fErrCharge)
737 {
738 *fLog << warn << "WARNING: Fitted Charge is smaller than "
739 << gkChargeRelErrLimit << "* its error in Pixel " << fPixId << endl;
740 return kFALSE;
741 }
742
743 if (!fHist->IsChargeFitOK())
744 {
745 *fLog << warn << "WARNING: Probability of Fitted Charge too low in Pixel "
746 << fPixId << endl;
747 return kFALSE;
748 }
749
750 if (fSigmaCharge < pedestal)
751 {
752 *fLog << warn << "WARNING: Sigma of Fitted Charge smaller than Pedestal RMS in Pixel "
753 << fPixId << endl;
754 return kFALSE;
755 }
756 return kTRUE;
757}
758
759//
760// The check return kTRUE if:
761//
762// 0) No value is nan
763// 1) Pixel has a fitted rel. time smaller than 3*FADC slices
764// 2) Pixel has a fit error greater than 0.
765// 4) Pixel has a fit Probability greater than 0.001
766// 5) The absolute arrival time is at least 1.0 slices from the used edge slices
767//
768Bool_t MCalibrationPix::CheckTimeFitValidity()
769{
770
771 if (TMath::IsNaN(fMeanTimeOffset)
772 || TMath::IsNaN(fMeanTimeOffsetError)
773 || TMath::IsNaN(fTimingPrecision)
774 || TMath::IsNaN(fTimeProb))
775 {
776 *fLog << warn << "WARNING: Some of the time fit values are NAN in Pixel "
777 << fPixId << endl;
778 return kFALSE;
779 }
780
781 if (TESTBIT(fFlags,kExcludeQualityCheck))
782 return kTRUE;
783
784 if (TMath::Abs(fMeanTimeOffset) > gkTimeLimit)
785 {
786 *fLog << warn << "WARNING: Abs(Fitted Rel. Time) " << TMath::Abs(fMeanTimeOffset)
787 << " is greater than " << gkTimeLimit << " in Pixel " << fPixId << endl;
788 return kFALSE;
789 }
790
791 if (fMeanTimeOffsetError > gkTimeErrLimit)
792 {
793 *fLog << warn << "WARNING: Error of Fitted Time " << fMeanTimeOffsetError
794 << " is smaller than " << gkTimeErrLimit << " in Pixel " << fPixId << endl;
795 return kFALSE;
796 }
797
798 if (!fHist->IsTimeFitOK())
799 {
800 *fLog << warn << "WARNING: Probability of Fitted Time too low in Pixel "
801 << fPixId << endl;
802 return kFALSE;
803 }
804
805 if (TESTBIT(fFlags,kHiGainSaturation))
806 {
807
808 if (fAbsTimeMean < (Float_t)fTimeFirstLoGain+1)
809 {
810 *fLog << warn
811 << "WARNING: Some absolute times smaller than limit in Pixel "
812 << fPixId << " time: " << fAbsTimeMean
813 << " Limit: " << (Float_t)fTimeFirstLoGain+1. << endl;
814 return kFALSE;
815 }
816
817 if (fAbsTimeMean > (Float_t)fTimeLastLoGain-1)
818 {
819 *fLog << warn
820 << "WARNING: Some absolute times bigger than limit in Pixel "
821 << fPixId << " time: " << fAbsTimeMean
822 << " Limit: " << (Float_t)fTimeLastLoGain-1. << endl;
823 return kFALSE;
824 }
825
826 }
827 else
828 {
829
830 if (fAbsTimeMean < (Float_t)fTimeFirstHiGain+1.)
831 {
832 *fLog << warn
833 << "WARNING: Some absolute times smaller than limit in Pixel "
834 << fPixId << " time: " << fAbsTimeMean
835 << " Limit: " << (Float_t)fTimeFirstHiGain+1. << endl;
836 // return kFALSE;
837 }
838
839 if (fAbsTimeMean > (Float_t)fTimeLastHiGain-1.)
840 {
841 *fLog << warn
842 << "WARNING: Some absolute times bigger than limit in Pixel "
843 << fPixId << " time: " << fAbsTimeMean
844 << " Limit: " << (Float_t)fTimeLastHiGain-1. << endl;
845 // return kFALSE;
846 }
847
848 }
849
850
851
852 return kTRUE;
853}
854
855
856//
857// The check returns kTRUE if:
858//
859//
860//
861Bool_t MCalibrationPix::CheckOscillations()
862{
863 return kTRUE;
864}
865
866void MCalibrationPix::ApplyLoGainConversion()
867{
868
869 const Float_t chargeRelErrSquare = fErrCharge*fErrCharge
870 /( fCharge * fCharge);
871 const Float_t sigmaRelErrSquare = fErrSigmaCharge*fErrSigmaCharge
872 /( fSigmaCharge * fSigmaCharge);
873 const Float_t conversionRelErrSquare = fConversionHiLoError*fConversionHiLoError
874 /(fConversionHiLo * fConversionHiLo);
875
876 fCharge *= fConversionHiLo;
877 fErrCharge = TMath::Sqrt(chargeRelErrSquare + conversionRelErrSquare) * fCharge;
878
879 fSigmaCharge *= fConversionHiLo;
880 fErrSigmaCharge = TMath::Sqrt(sigmaRelErrSquare + conversionRelErrSquare) * fSigmaCharge;
881
882}
883
884
885
886// --------------------------------------------------------------------------
887//
888// 1) Fit the arrival times
889// 2) Retrieve the results
890//
891// This fit has to be done AFTER the Charges fit,
892// otherwise only the Hi Gain will be fitted, even if there are no entries
893//
894//
895Bool_t MCalibrationPix::FitTime()
896{
897
898
899 if(!fHist->FitTime())
900 {
901 *fLog << warn << "WARNING: Could not fit relative times of pixel " << fPixId << endl;
902 return kFALSE;
903 }
904
905 fMeanTimeOffset = fHist->GetRelTimeMean();
906 fMeanTimeOffsetError = fHist->GetRelTimeMeanErr();
907 fTimingPrecision = fHist->GetRelTimeSigma();
908 fTimeProb = fHist->GetRelTimeProb();
909
910 fAbsTimeMean = fHist->GetAbsTimeMean();
911 fAbsTimeMeanErr = fHist->GetAbsTimeMeanErr();
912 fAbsTimeRms = fHist->GetAbsTimeRms();
913
914 if (CheckTimeFitValidity())
915 SETBIT(fFlags,kTimeFitValid);
916 else
917 CLRBIT(fFlags,kTimeFitValid);
918
919 return kTRUE;
920}
921
Note: See TracBrowser for help on using the repository browser.