source: trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc@ 6937

Last change on this file since 6937 was 5200, checked in by gaug, 20 years ago
*** empty log message ***
File size: 34.5 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// MCalibrationChargePix
27//
28// Storage container of the calibrated Charge of one pixel.
29//
30// The following values are initialized to meaningful values:
31//
32// - The Electronic Rms to 1.5 per FADC slice
33// - The uncertainty about the Electronic RMS to 0.3 per slice
34// - The F-Factor is assumed to have been measured in Munich to 1.13 - 1.17.
35// with the Munich definition of the F-Factor, thus:
36// F = Sigma(Out)/Mean(Out) * Mean(In)/Sigma(In)
37// Mean F-Factor (gkFFactor) = 1.15
38// Error F-Factor (gkFFactorErr) = 0.02
39//
40// The following variables are calculated inside this class:
41// - fLoGainPedRmsSquare and fLoGainPedRmsSquareVar (see CalcLoGainPedestal())
42// - fRSigmaSquare and fRSigmaSquareVar (see CalcReducedSigma() )
43// - fPheFFactorMethod and fPheFFactorMethodVar (see CalcFFactor() )
44// - fMeanConvFADC2Phe and fMeanConvFADC2PheVar (see CalcConvFFactor() )
45//
46// The following variables are set by MHCalibrationChargeCam:
47// - fAbsTimeMean and fAbsTimeRms
48// - all variables in MCalibrationPix
49//
50// The following variables are set by MCalibrationChargeCalc:
51// - fPed, fPedVar and fPedRms
52// - fMeanConvFADC2Phe
53// - fConvFADC2PheVar
54// - fSigmaConvFADC2Phe
55// - fTotalFFactorFFactorMethod
56// - fTotalFFactorFFactorMethodVar
57//
58// The following variables are not yet implemented:
59// - fConversionHiLo and fConversionHiLoVar (now set fixed to 10. +- 2.5)
60//
61// Error of all variables are calculated by error-propagation. Note that internally,
62// all error variables contain Variances in order to save the CPU-intensive square rooting
63//
64// Low-Gain variables are stored internally unconverted, i.e. directly from the summed
65// FADC slices extraction results, but can be retrieved converted to High-Gain amplifications
66// by calls to: GetConvertedMean() or GetConvertedSigma()
67//
68// See also: MCalibrationChargeCam, MCalibrationChargeCalc,
69// MHCalibrationChargeCam, MHCalibrationChargePix
70//
71/////////////////////////////////////////////////////////////////////////////
72#include "MCalibrationChargePix.h"
73
74#include "MLog.h"
75#include "MLogManip.h"
76
77#include "MBadPixelsPix.h"
78
79ClassImp(MCalibrationChargePix);
80
81using namespace std;
82
83const Float_t MCalibrationChargePix::gkElectronicPedRms = 1.0;
84const Float_t MCalibrationChargePix::gkElectronicPedRmsErr = 0.35;
85const Float_t MCalibrationChargePix::gkFFactor = 1.15;
86const Float_t MCalibrationChargePix::gkFFactorErr = 0.02;
87
88const Float_t MCalibrationChargePix::fgConversionHiLo = 10.;
89const Float_t MCalibrationChargePix::fgConversionHiLoErr = 2.5;
90const Float_t MCalibrationChargePix::fgPheFFactorMethodLimit = 1.;
91const Float_t MCalibrationChargePix::fgConvFFactorRelErrLimit = 0.85;
92// --------------------------------------------------------------------------
93//
94// Default Constructor:
95//
96// Sets:
97// - fCalibFlags to 0
98// - fConversionHiLo to fgConversionHiLo
99// - fConversionHiLoVar to square of fgConversionHiLoErr
100// - fConvFFactorelErrLimit to fgConvFFactorRelErrLimit*fgConvFFactorelErrLimit
101// - fPheFFactorLimit to fgPheFFactorLimit
102//
103// Calls:
104// - Clear()
105//
106MCalibrationChargePix::MCalibrationChargePix(const char *name, const char *title)
107 : fCalibFlags(0)
108{
109
110 fName = name ? name : "MCalibrationChargePix";
111 fTitle = title ? title : "Container of the fit results of MHCalibrationChargePixs ";
112
113 //
114 // At the moment, we don't have a database, yet,
115 // so we get it from the configuration file
116 //
117 SetConversionHiLo();
118 SetConversionHiLoErr();
119
120 SetPheFFactorMethodLimit();
121 SetConvFFactorRelErrLimit();
122
123 Clear();
124}
125
126// ------------------------------------------------------------------------
127//
128// Sets:
129// - all flags to kFALSE
130// - all variables to -1.
131//
132// Calls:
133// - MCalibrationPix::Clear()
134//
135void MCalibrationChargePix::Clear(Option_t *o)
136{
137
138 SetFFactorMethodValid ( kFALSE );
139
140 fRSigmaSquare = -1.;
141 fRSigmaSquareVar = -1.;
142
143 fPed = -1.;
144 fPedRms = -1.;
145 fPedVar = -1.;
146
147 fLoGainPedRmsSquare = -1.;
148 fLoGainPedRmsSquareVar = -1.;
149
150 fAbsTimeMean = -1.;
151 fAbsTimeRms = -1.;
152
153 fPheFFactorMethod = -1.;
154 fPheFFactorMethodVar = -1.;
155
156 fMeanConvFADC2Phe = -1.;
157 fMeanConvFADC2PheVar = -1.;
158 fMeanFFactorFADC2Phot = -1.;
159 fMeanFFactorFADC2PhotVar = -1.;
160
161 MCalibrationPix::Clear();
162}
163
164
165// --------------------------------------------------------------------------
166//
167// Set F-Factor Method Validity Bit from outside
168//
169void MCalibrationChargePix::SetFFactorMethodValid(const Bool_t b )
170{
171 b ? SETBIT(fCalibFlags, kFFactorMethodValid) : CLRBIT(fCalibFlags, kFFactorMethodValid);
172}
173
174// --------------------------------------------------------------------------
175//
176// Set pedestals from outside (done by MCalibrationChargeCalc)
177//
178void MCalibrationChargePix::SetPedestal(const Float_t ped, const Float_t pedrms, const Float_t pederr)
179{
180
181 fPed = ped;
182 fPedRms = pedrms;
183 fPedVar = pederr*pederr;
184}
185
186// --------------------------------------------------------------------------
187//
188// Set pedestals from outside (done by MCalibrationChargeCalc)
189//
190void MCalibrationChargePix::SetPed(const Float_t ped, const Float_t pederr)
191{
192
193 fPed = ped;
194 fPedVar = pederr*pederr;
195}
196
197// --------------------------------------------------------------------------
198//
199// Set pedestals RMS from outside (done by MHCalibrationChargeCam)
200//
201void MCalibrationChargePix::SetPedRMS( const Float_t pedrms, const Float_t pedrmserr)
202{
203
204 fPedRms = pedrms;
205 fPedRmsVar = pedrmserr*pedrmserr;
206
207}
208
209
210// -------------------------------------------------------------------------------
211//
212// Get the conversion Error Hi-Gain to Low-Gain:
213// - If fConversionHiLoVar is smaller than 0 (i.e. has not yet been set), return -1.
214//
215Float_t MCalibrationChargePix::GetConversionHiLoErr() const
216{
217 if (fConversionHiLoVar < 0.)
218 return -1.;
219
220 return TMath::Sqrt(fConversionHiLoVar);
221}
222
223// --------------------------------------------------------------------------
224//
225// Get the relative variance of the conversion factor between higain and logain:
226// - If fConversionHiLo is 0, return -1.
227// - If fConversionHiLoVar is smaller than 0, return -1.
228// - Else returns: fConversionHiLoVar / fConversionHiLo^2
229//
230const Float_t MCalibrationChargePix::GetConversionHiLoRelVar() const
231{
232
233 if (fConversionHiLoVar < 0.)
234 return -1.;
235
236 if (fConversionHiLo == 0.)
237 return -1.;
238
239 return fConversionHiLoVar / (fConversionHiLo * fConversionHiLo);
240}
241
242// --------------------------------------------------------------------------
243//
244// Get the relative variance of the electronics pedestal RMS
245// - returns rel. variance of gkElectronicPedRms
246//
247const Float_t MCalibrationChargePix::GetElectronicPedRmsRelVar() const
248{
249 return gkElectronicPedRmsErr * gkElectronicPedRmsErr / gkElectronicPedRms / gkElectronicPedRms;
250}
251
252
253// --------------------------------------------------------------------------
254//
255// Get the relative variance of the conversion factor between higain and logain:
256// - If gkFFactor is 0, return -1.
257// - If gkFFactorErr is smaller than 0, return -1.
258// - Else returns: gkFFactorErr^2 / gkFFactor*^2
259//
260const Float_t MCalibrationChargePix::GetFFactorRelVar() const
261{
262
263 if (gkFFactorErr < 0.)
264 return -1.;
265
266 if (gkFFactor == 0.)
267 return -1.;
268
269 return gkFFactorErr * gkFFactorErr / (gkFFactor * gkFFactor);
270}
271
272
273// --------------------------------------------------------------------------
274//
275// Get the pedestals RMS:
276// - Test bit kHiGainSaturation:
277// If yes, return square root of fLoGainPedRmsSquare (if greater than 0, otherwise -1.),
278// If no, return fPedRms
279//
280Float_t MCalibrationChargePix::GetPedRms() const
281{
282
283 if (IsHiGainSaturation())
284 if (fLoGainPedRmsSquare < 0.)
285 return -1.;
286 else
287 return TMath::Sqrt(fLoGainPedRmsSquare);
288
289 return fPedRms;
290}
291
292// --------------------------------------------------------------------------
293//
294// Get the Error of the pedestals RMS:
295// - Test bit kHiGainSaturation:
296// If yes, return square root of (0.25*fLoGainPedRmsSquareVar/ fLoGainPedRmsSquare) (if greater than 0, otherwise -1.)
297// If no , return square root of (fPedVar) (if greater than 0, otherwise -1.), divided by 2.
298//
299Float_t MCalibrationChargePix::GetPedRmsErr() const
300{
301 if (IsHiGainSaturation())
302 if (fLoGainPedRmsSquareVar < 0.)
303 return -1.;
304 else
305 return TMath::Sqrt(0.25*fLoGainPedRmsSquareVar/fLoGainPedRmsSquare);
306 else
307 if (fPedVar < 0.)
308 return -1.;
309 else
310 return TMath::Sqrt(fPedVar)/2.;
311}
312
313
314// --------------------------------------------------------------------------
315//
316// Get the Low Gain Mean Charge converted to High Gain amplification:
317// Returns fLoGainMean multiplied with fConversionHiLo if IsHiGainSaturation(),
318// else return fHiGainMean
319//
320Float_t MCalibrationChargePix::GetConvertedMean() const
321{
322
323 if (IsHiGainSaturation())
324 return fLoGainMean * fConversionHiLo;
325
326 return fHiGainMean;
327}
328
329// --------------------------------------------------------------------------
330//
331// Get the Error of the converted Low Gain Mean:
332//
333// Returns -1 if the variable fLoGainMean or fLoGainMeanVar are smaller than 0.
334//
335// Returns the square root of the quadratic sum of the relative variances of
336// the fLoGainMean and fConversionHiLo, mulitplied with GetConvertedMean()
337// in case of HiGain Saturation,
338// else return GetMeanErr()
339//
340Float_t MCalibrationChargePix::GetConvertedMeanErr() const
341{
342
343 if (IsHiGainSaturation())
344 {
345 const Float_t logainrelvar = GetLoGainMeanRelVar();
346
347 if (logainrelvar < 0.)
348 return -1.;
349
350 return TMath::Sqrt(logainrelvar + GetConversionHiLoRelVar()) * GetConvertedMean();
351 }
352 else
353 return GetMeanErr();
354
355}
356
357// --------------------------------------------------------------------------
358//
359// Get the Low Gain Sigma converted to High Gain amplification:
360// Returns fLoGainSigma multiplied with fConversionHiLo if IsHiGainSaturation()
361// else return fHiGainSigma
362//
363Float_t MCalibrationChargePix::GetConvertedSigma() const
364{
365
366 if (IsHiGainSaturation())
367 return fLoGainSigma * fConversionHiLo;
368 else
369 return fHiGainSigma;
370}
371
372// --------------------------------------------------------------------------
373//
374// Get the Error of the converted Sigma:
375//
376// Returns -1 if the variable fLoGainSigma or fLoGainSigmaVar are smaller than 0.
377//
378// if IsHiGainSaturatio()
379// returns the square root of the quadratic sum of the relative variances of
380// the fLoGainSigma and fConversionHiLo, mulitplied with GetConvertedSigma()
381// else returns GetSigmaErr()
382//
383Float_t MCalibrationChargePix::GetConvertedSigmaErr() const
384{
385
386 if (IsHiGainSaturation())
387 {
388 if (fLoGainSigmaVar < 0.)
389 return -1.;
390
391 if (fLoGainSigma < 0.)
392 return -1.;
393
394 const Float_t sigmaRelVar = fLoGainSigmaVar
395 /( fLoGainSigma * fLoGainSigma );
396
397 return TMath::Sqrt(sigmaRelVar+GetConversionHiLoRelVar()) * GetConvertedSigma();
398 }
399 else
400 return GetSigmaErr();
401
402
403}
404
405// --------------------------------------------------------------------------
406//
407// Get the converted reduced Sigma:
408// - If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
409// - Test bit kHiGainSaturation:
410// If yes, return square root of fRSigmaSquare, multiplied with fConversionHiLo,
411// If no , return square root of fRSigmaSquare
412//
413Float_t MCalibrationChargePix::GetConvertedRSigma() const
414{
415 if (fRSigmaSquare < 0)
416 return -1;
417
418 const Float_t rsigma = TMath::Sqrt(fRSigmaSquare);
419
420 return IsHiGainSaturation() ? rsigma*fConversionHiLo : rsigma ;
421}
422
423// --------------------------------------------------------------------------
424//
425// Get the error of the converted reduced Sigma:
426// - If fRSigmaSquareVar is smaller than 0 (i.e. has not yet been set), return -1.
427// - Calculate the absolute variance of the reduced sigma with the formula:
428// reduced sigma variance = 0.25 * fRSigmaSquareVar / fRSigmaSquare
429// - Test bit kHiGainSaturation:
430// If yes, returns the square root of the quadratic sum of the relative variances of the
431// reduced sigma and fConversionHiLo, mulitplied with GetRSigma()
432// Else returns the square root of rel. (0.25*fRSigmaSquareVar / fRSigmaSquare)
433//
434Float_t MCalibrationChargePix::GetConvertedRSigmaErr() const
435{
436
437 if (fRSigmaSquareVar < 0)
438 return -1;
439
440 //
441 // SigmaSquareVar = 4. * Sigma * Sigma * Var(sigma)
442 // ==> Var(sigma) = 0.25 * SigmaSquareVar / (Sigma * Sigma)
443 //
444 const Float_t rsigmaVar = 0.25 * fRSigmaSquareVar / fRSigmaSquare;
445
446 if (IsHiGainSaturation())
447 return TMath::Sqrt(rsigmaVar/fRSigmaSquare + GetConversionHiLoRelVar()) * GetRSigma();
448 else
449 return TMath::Sqrt(rsigmaVar);
450
451}
452
453// --------------------------------------------------------------------------
454//
455// Get the reduced Sigma:
456// - If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
457//
458Float_t MCalibrationChargePix::GetRSigma() const
459{
460 if (fRSigmaSquare < 0)
461 return -1;
462
463 return TMath::Sqrt(fRSigmaSquare);
464
465}
466
467// --------------------------------------------------------------------------
468//
469// Get the error of the reduced Sigma:
470// - If fRSigmaSquareVar is smaller than 0 (i.e. has not yet been set), return -1.
471// - Calculate the absolute variance of the reduced sigma with the formula:
472// reduced sigma variance = 0.25 * fRSigmaSquareVar / fRSigmaSquare
473//
474Float_t MCalibrationChargePix::GetRSigmaErr() const
475{
476
477 if (fRSigmaSquareVar < 0)
478 return -1;
479
480 //
481 // SigmaSquareVar = 4. * Sigma * Sigma * Var(sigma)
482 // ==> Var(sigma) = 0.25 * SigmaSquareVar / (Sigma * Sigma)
483 //
484 return TMath::Sqrt(0.25 * fRSigmaSquareVar / fRSigmaSquare);
485
486}
487
488// --------------------------------------------------------------------------
489//
490// Get the reduced Sigma per Charge:
491// - If GetRSigma() is smaller or equal 0. (i.e. has not yet been set), return -1.
492// - If GetMean() is 0. or -1. (i.e. has not yet been set), return -1.
493// - Return GetRSigma() / GetMean()
494//
495Float_t MCalibrationChargePix::GetRSigmaPerCharge() const
496{
497
498 const Float_t rsigma = GetRSigma();
499
500 if (rsigma <= 0)
501 return -1.;
502
503
504 const Float_t mean = GetMean();
505
506 if (mean == 0. || mean == -1.)
507 return -1.;
508
509 return rsigma / mean;
510}
511
512
513// --------------------------------------------------------------------------
514//
515// Get the error of the reduced Sigma per Charge:
516// - If GetRSigmaRelVar() is smaller or equal 0. (i.e. has not yet been set), return -1.
517// - If GetMeanRelVar() is smaller or equal 0. (i.e. has not yet been set), return -1.
518// - Return the propagated error of GetRSigmaPerCharge()
519//
520Float_t MCalibrationChargePix::GetRSigmaPerChargeErr() const
521{
522
523 const Float_t rsigmarelvar = GetRSigmaRelVar();
524
525 if (rsigmarelvar <= 0)
526 return -1.;
527
528
529 const Float_t meanrelvar = GetMeanRelVar();
530
531 if (meanrelvar <= 0.)
532 return -1.;
533
534 return TMath::Sqrt(rsigmarelvar + meanrelvar) * GetRSigmaPerCharge();
535}
536
537// --------------------------------------------------------------------------
538//
539// Get the reduced Sigma Square:
540// - If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
541// - Test bit kHiGainSaturation:
542// If yes, return fRSigmaSquare, multiplied with fConversionHiLo^2,
543// If no , return fRSigmaSquare
544//
545Float_t MCalibrationChargePix::GetConvertedRSigmaSquare() const
546{
547 if (fRSigmaSquare < 0)
548 return -1;
549
550 return IsHiGainSaturation() ? fRSigmaSquare*fConversionHiLo*fConversionHiLo : fRSigmaSquare ;
551}
552
553// --------------------------------------------------------------------------
554//
555// Get the relative variance of the reduced Sigma:
556// - If fRSigmaSquareVar is smaller than 0 (i.e. has not yet been set), return -1.
557// - Calculate the relative variance of the reduced sigma squares with the formula:
558// reduced sigma rel. variance = 0.25 * fRSigmaSquareVar / fRSigmaSquare / fRSigmaSquare
559// - Test bit kHiGainSaturation:
560// If yes, returns the sum of the relative variances of the reduced sigma and fConversionHiLo
561// Else returns the relative variance of the reduced sigma
562//
563Float_t MCalibrationChargePix::GetRSigmaRelVar() const
564{
565
566 if (fRSigmaSquareVar < 0)
567 return -1;
568
569 //
570 // SigmaSquareVar = 4. * Sigma * Sigma * Var(sigma)
571 // ==> Var(sigma) = 0.25 * SigmaSquareVar / (Sigma * Sigma)
572 //
573 return 0.25 * fRSigmaSquareVar / ( fRSigmaSquare * fRSigmaSquare );
574
575}
576
577// --------------------------------------------------------------------------
578//
579// Get the error on the number of photo-electrons (F-Factor Method):
580// - If fPheFFactorMethodVar is smaller than 0 (i.e. has not yet been set), return -1.
581// - Else returns the square root of fPheFFactorMethodVar
582//
583Float_t MCalibrationChargePix::GetPheFFactorMethodErr() const
584{
585 if (fPheFFactorMethodVar < 0.)
586 return -1.;
587 return TMath::Sqrt(fPheFFactorMethodVar);
588}
589
590// --------------------------------------------------------------------------
591//
592// Get the error on the mean total F-Factor of the signal readout (F-Factor Method):
593// - If fMeanFFactorFADC2PhotVar is smaller than 0 (i.e. has not yet been set), return -1.
594// - Else returns the square root of fMeanFFactorFADC2PhotVar
595//
596Float_t MCalibrationChargePix::GetMeanFFactorFADC2PhotErr() const
597{
598 if (fMeanFFactorFADC2PhotVar < 0.)
599 return -1.;
600 return TMath::Sqrt(fMeanFFactorFADC2PhotVar);
601}
602
603// --------------------------------------------------------------------------
604//
605// Get the relative variance on the number of photo-electrons (F-Factor Method):
606// - If fPheFFactorMethodVar is smaller than 0 (i.e. has not yet been set), return -1.
607// - If fPheFFactorMethod is 0, return -1.
608// - Else returns fPheFFactorMethodVar / fPheFFactorMethod^2
609//
610Float_t MCalibrationChargePix::GetPheFFactorMethodRelVar() const
611{
612 if (fPheFFactorMethodVar < 0.)
613 return -1.;
614 if (fPheFFactorMethod == 0.)
615 return -1.;
616
617 return fPheFFactorMethodVar / (fPheFFactorMethod * fPheFFactorMethod);
618}
619
620
621// --------------------------------------------------------------------------
622//
623// Get the error on the mean conversion factor (FFactor  Method):
624// - If fMeanConvFADC2PheVar is smaller than 0 (i.e. has not yet been set), return -1.
625// - Else returns the square root of fMeanConvFADC2PheVar
626//
627Float_t MCalibrationChargePix::GetMeanConvFADC2PheErr() const
628{
629 if (fMeanConvFADC2PheVar < 0.)
630 return -1.;
631 return TMath::Sqrt(fMeanConvFADC2PheVar);
632}
633
634// --------------------------------------------------------------------------
635//
636// Test bit kFFactorMethodValid
637//
638Bool_t MCalibrationChargePix::IsFFactorMethodValid() const
639{
640 return TESTBIT(fCalibFlags, kFFactorMethodValid);
641}
642
643
644// ----------------------------------------------------------------------------
645//
646// - If fSigma is smaller than 0 (i.e. has not yet been set), return kFALSE
647// - If fPedRms is smaller than 0 (i.e. has not yet been set), return kFALSE
648//
649// Calculate the reduced sigma of the low-Gain FADC slices:
650// - Test bit IsHiGainSaturation() for the Sigma:
651// If yes, take fLoGainSigma and fLoGainSigmaVar
652// If no , take fHiGainSigma and fHiGainSigmaVar
653//
654// - Test bit IsHiGainSaturation() for the pedRMS:
655// If yes, take fLoGainPedRmsSquare and fLoGainPedRmsSquareVar
656// If no , take fPedRms and fPedVar
657//
658// - Calculate the reduced sigma with the formula:
659// fRSigmaSquare = Sigma*Sigma - pedRMS*pedRMS
660//
661// - If fRSigmaSquare is smaller than 0, give a warning and return kFALSE
662//
663// - Calculate the variance of the reduced sigma with the formula:
664// fRSigmaSquareVar = 4.* (sigmaVar*Sigma*Sigma + pedRmsVar*pedRMS*pedRMS)
665//
666// A back-transformation to the corr. amplification factor of the High-Gain is done
667// in GetRSigma() and GetRSigmaErr()
668//
669Bool_t MCalibrationChargePix::CalcReducedSigma()
670{
671
672 if (GetSigma() < 0.)
673 return kFALSE;
674
675 if (GetPedRms() < 0.)
676 return kFALSE;
677
678 const Float_t sigma = IsHiGainSaturation() ? fLoGainSigma : fHiGainSigma ;
679 const Float_t sigmavar = IsHiGainSaturation() ? fLoGainSigmaVar : fHiGainSigmaVar;
680 const Float_t pedRmsSquare = IsHiGainSaturation() ? fLoGainPedRmsSquare : fPedRms*fPedRms;
681 const Float_t pedRmsSquareVar = IsHiGainSaturation() ? fLoGainPedRmsSquareVar : 0.25*fPedVar*pedRmsSquare;
682
683 if (IsDebug())
684 {
685 *fLog << dbginf << "ID: " << GetPixId()
686 << " HiGainSaturation: " << IsHiGainSaturation()
687 << " Sigma: " << sigma
688 << " Var.Sigma: " << sigmavar
689 << " PedRmsSquare: " << pedRmsSquare
690 << " pedRmsSquareVar: " << pedRmsSquareVar
691 << endl;
692 }
693
694 const Float_t sigmaSquare = sigma * sigma;
695 const Float_t sigmaSquareVar = 4. * sigmavar * sigmaSquare;
696
697 //
698 // Calculate the reduced sigmas
699 //
700 fRSigmaSquare = sigmaSquare - pedRmsSquare;
701
702 if (IsDebug())
703 {
704 *fLog << dbginf << "ID: " << GetPixId()
705 << " Red.Sigma Square: " << fRSigmaSquare
706 << endl;
707 }
708
709 if (fRSigmaSquare <= 0.)
710 {
711 if (IsDebug())
712 *fLog << warn
713 << "WARNING: Cannot calculate the reduced sigma: smaller than 0 in pixel "
714 << fPixId << endl;
715 return kFALSE;
716 }
717
718
719 fRSigmaSquareVar = 4. * (sigmaSquareVar + pedRmsSquareVar);
720
721 if (IsDebug())
722 {
723 *fLog << dbginf << "ID: " << GetPixId()
724 << " Var.Red.Sigma Square: " << fRSigmaSquareVar
725 << endl;
726 }
727
728 return kTRUE;
729}
730
731// ------------------------------------------------------------------
732//
733// If fRSigmaSquare is smaller than 0 (i.e. has not yet been set),
734// return kFALSE
735//
736// Calculate the number of photo-electrons with the F-Factor method:
737// - Test bit IsHiGainSaturation() for the Mean Sum of FADC slices:
738// If yes, take fLoGainMean and fLoGainMeanVar
739// If no , take fHiGainMean and fHiGainMeanVar
740//
741// - Test bit IsHiGainSaturation() for the pedRMS:
742// If yes, take fLoGainPedRmsSquare and fLoGainPedRmsSquareVar
743// If no , take fPedRms and fPedVar
744//
745// - Calculate the number of photo-electrons with the formula:
746// fPheFFactorMethod = gkFFactor*gkFFactor * Mean * Mean / fRSigmaSquare
747//
748// - Calculate the Variance on the photo-electrons with the formula:
749// fPheFFactorMethodVar = ( 4. * gkFFactorErr * gkFFactorErr / ( gkFFactor * gkFFactor )
750// + 4. * Mean Var. / ( Mean * Mean )
751// + fRSigmaSquareVar / fRSigmaSquare
752// ) * fPheFFactorMethod * fPheFFactorMethod
753//
754// - If fPheFFactorMethod is less than fPheFFactorMethodLimit,
755// set kFFactorMethodValid to kFALSE and return kFALSE
756//
757Bool_t MCalibrationChargePix::CalcFFactor()
758{
759
760 if (fRSigmaSquare < 0.)
761 return kFALSE;
762
763 //
764 // Square all variables in order to avoid applications of square root
765 //
766 const Float_t meanSquare = GetMean() * GetMean();
767 const Float_t meanSquareRelVar = 4.* GetMeanRelVar();
768
769 const Float_t ffactorsquare = gkFFactor * gkFFactor;
770 const Float_t ffactorsquareRelVar = 4.* GetFFactorRelVar();
771
772 const Float_t rsigmaSquareRelVar = fRSigmaSquareVar / fRSigmaSquare / fRSigmaSquare;
773 //
774 // Calculate the number of phe's from the F-Factor method
775 // (independent on Hi Gain or Lo Gain)
776 //
777 fPheFFactorMethod = ffactorsquare * meanSquare / fRSigmaSquare;
778
779 if (IsDebug())
780 {
781 *fLog << dbginf << "ID: " << GetPixId()
782 << " F-Factor Square: " << ffactorsquare
783 << " Mean Square: " << meanSquare
784 << " Red.Sigma Square: " << fRSigmaSquare
785 << " Photo-electrons: " << fPheFFactorMethod
786 << endl;
787 }
788
789 if (fPheFFactorMethod < fPheFFactorMethodLimit)
790 return kFALSE;
791
792 //
793 // Calculate the Error of Nphe
794 //
795 const Float_t pheRelVar = ffactorsquareRelVar + meanSquareRelVar + rsigmaSquareRelVar;
796 fPheFFactorMethodVar = pheRelVar * fPheFFactorMethod * fPheFFactorMethod;
797
798 if (IsDebug())
799 {
800 *fLog << dbginf << "ID: " << GetPixId()
801 << " Rel.Var.F-Factor Square: " << ffactorsquareRelVar
802 << " Rel.Var. Mean Square: " << meanSquareRelVar
803 << " Rel.Var. Red.Sigma Square: " << rsigmaSquareRelVar
804 << " Rel.Var. Photo-electrons: " << pheRelVar
805 << endl;
806 }
807
808 if (fPheFFactorMethodVar < 0. )
809 return kFALSE;
810
811 return kTRUE;
812}
813
814// ------------------------------------------------------------------
815//
816// If fPheFFactorMethod is smaller than 0 (i.e. has not yet been set),
817// return kFALSE
818//
819// If GetCovertedMean() is smaller than 0 (i.e. has not yet been set),
820// return kFALSE
821//
822// Calculate fMeanConvFADC2Phe with the following formula:
823//
824// fMeanConvFADC2Phe = fPheFFactorMethod / GetConvMean();
825//
826// Calculate the rel. variance of fMeanConvFADC2Phe, taking into account that
827// in the calculation of the number of phe's one mean square has already been used.
828// Now, dividing by another mean, one mean calcels out, one cannot directly propagate
829// the errors, but instead havs to take into account this cancellation:
830//
831// convrelvar = ffactorsquareRelVar + GetMeanRelVar() + rsigmaSquareRelVar;
832//
833// If confrelvar is smaller than 0. or greater than fConvFFactorRelVarLimit,
834// return kFALSE
835//
836// Calculate the variance of fMeanConvFADC2Phe with the formula:
837//
838// fMeanConvFADC2PheVar = convrelvar * fMeanConvFADC2Phe * fMeanConvFADC2Phe;
839//
840// Set kFFactorMethodValid to kTRUE and
841// return kTRUE
842//
843Bool_t MCalibrationChargePix::CalcConvFFactor()
844{
845
846 if (fPheFFactorMethod <= 0.)
847 return kFALSE;
848
849 const Float_t convmean = GetConvertedMean();
850
851 if (convmean <= 0.)
852 return kFALSE;
853
854 fMeanConvFADC2Phe = fPheFFactorMethod / convmean;
855
856 if (IsDebug())
857 {
858 *fLog << dbginf << "ID: " << GetPixId()
859 << " Converted Mean: " << convmean
860 << " Conversion FADC2Phe: " << fMeanConvFADC2Phe
861 << endl;
862 }
863
864 const Float_t ffactorsquareRelVar = 4.* GetFFactorRelVar();
865 const Float_t rsigmaSquareRelVar = fRSigmaSquareVar / fRSigmaSquare / fRSigmaSquare;
866 //
867 // In the calculation of the number of phe's one mean square has already been used.
868 // Now, we divide by another mean, so one mean calcels out, we cannot directly propagate
869 // the errors, but have to take account of this cancellation:
870 //
871 Float_t convrelvar = ffactorsquareRelVar + GetMeanRelVar() + rsigmaSquareRelVar;
872 const Float_t limit = IsHiGainSaturation() ? fConvFFactorRelVarLimit * 4. : fConvFFactorRelVarLimit;
873
874 //
875 // Also have to take into account the pixels labelled MBadPixelsPix::kChargeSigmaNotValid which do not
876 // have a fRSigmaSquareVar, calculate their error directly!
877 //
878 if (fRSigmaSquareVar < 0.)
879 convrelvar = GetMeanRelVar() + GetPheFFactorMethodRelVar();
880
881 if (IsDebug())
882 {
883 *fLog << dbginf << "ID: " << GetPixId()
884 << " Rel.Var.Red.Sigma: " << rsigmaSquareRelVar
885 << " Rel.Var.Mean: " << GetMeanRelVar()
886 << " Rel.Var.F-Factor: " << ffactorsquareRelVar
887 << " Rel.Var.Conversion FADC2Phe: " << convrelvar
888 << endl;
889 }
890
891 if (convrelvar > limit || convrelvar < 0.)
892 {
893 *fLog << warn << GetDescriptor() << ": Conv. F-Factor Method Rel. Var.: "
894 << Form("%4.3f out of limits: [0,%3.2f] in pixel:%4i",convrelvar,limit,fPixId) << endl;
895 return kFALSE;
896 }
897
898 fMeanConvFADC2PheVar = convrelvar * fMeanConvFADC2Phe * fMeanConvFADC2Phe;
899
900 SetFFactorMethodValid(kTRUE);
901 return kTRUE;
902}
903
904// ----------------------------------------------------------------------------------
905//
906// If photflux is smaller or equal 0, return kFALSE
907//
908// Calculate the total F-Factor with the formula:
909// fMeanFFactorFADC2Phot = Sqrt ( fRSigmaSquare ) / GetMean() * sqrt(nphotons)
910//
911// Calculate the error of the total F-Factor
912//
913Bool_t MCalibrationChargePix::CalcMeanFFactor( const Float_t nphotons, const Float_t nphotonsrelvar )
914{
915
916
917 if (IsDebug())
918 {
919 *fLog << dbginf << "ID: " << GetPixId()
920 << " Number photons: " << nphotons
921 << " Rel.Var.Number photons: " << nphotonsrelvar
922 << " Red.Sigma Square: " << fRSigmaSquare
923 << " Mean: " << GetMean()
924 << endl;
925 }
926
927
928 if (nphotons <= 0.)
929 {
930 *fLog << warn << GetDescriptor() << ": Assumed photon flux is smaller or equal 0." << endl;
931 return kFALSE;
932 }
933
934 if (nphotonsrelvar < 0.)
935 {
936 *fLog << warn << GetDescriptor() << ": Assumed photon flux variance is smaller than 0." << endl;
937 return kFALSE;
938 }
939
940 fMeanFFactorFADC2Phot = TMath::Sqrt(fRSigmaSquare * nphotons) / GetMean() ;
941
942 if (IsDebug())
943 {
944 *fLog << dbginf << "ID: " << GetPixId()
945 << " F-Factor FADC2Phot: " << fMeanFFactorFADC2Phot
946 << endl;
947 }
948
949 if (fMeanFFactorFADC2Phot < 0.)
950 {
951 *fLog << warn << GetDescriptor() << ": F-Factor photons to FADC counts smaller than 0." << endl;
952 return kFALSE;
953 }
954
955 const Float_t ffactorrelvar = 0.25 * fRSigmaSquareVar / ( fRSigmaSquare * fRSigmaSquare)
956 + GetMeanRelVar()
957 + 0.25 * nphotonsrelvar;
958
959 fMeanFFactorFADC2PhotVar = ffactorrelvar * fMeanFFactorFADC2Phot * fMeanFFactorFADC2Phot;
960
961 if (IsDebug())
962 {
963 *fLog << dbginf << "ID: " << GetPixId()
964 << " Rel.Var.Red.Sigma: " << 0.25 * fRSigmaSquareVar / ( fRSigmaSquare * fRSigmaSquare)
965 << " Rel.Var.Mean: " << GetMeanRelVar()
966 << " Rel.Var.photons: " << 0.25 * nphotonsrelvar
967 << " Rel.Var.F-Factor FADC2Phot: " << ffactorrelvar
968 << endl;
969 }
970
971 return kTRUE;
972}
973
974
975// ----------------------------------------------------------------------------
976//
977// - If fPed is smaller than 0 (i.e. has not yet been set), return.
978// - If fPedVar is smaller than 0 (i.e. has not yet been set), return.
979//
980// Calculate the electronic pedestal RMS with the formula:
981// - elec. pedestal = gkElectronicPedRms * sqrt(logainsamples)
982//
983// Calculate the night sky background ped. RMS contribution ("NSB") in the high-gain
984// from the high gain Pedestal RMS with the formula:
985// - HiGain NSB square = fPedRms * fPedRms - elec.ped.* elec.ped.
986// - Var(HiGain NSB square) = fPedVar * fPedRms * fPedRms + 4.*elecPedRmsVar * elec.ped.* elec.ped.
987//
988// If HiGain NSB square is smaller than 0., set it to zero. (but not the error!)
989//
990// Convert the NSB ped. RMS contribution to the low-gain with the formula:
991// - LoGain NSB square = HiGain NSB square / (fConversionHiLo*fConversionHiLo)
992// - Var(LoGain NSB square) = ( Var(HiGain NSB square) / (HiGain NSB square * HiGain NSB square)
993// + GetConversionHiLoRelVar()
994// ) * LoGain NSB square * LoGain NSB square
995//
996// - Low Gain Ped RMS Square = LoGain NSB square + elec.ped. square
997// Var (Low Gain Ped RMS Square) = Var(LoGain NSB square) + Var(elec.ped. square)
998//
999void MCalibrationChargePix::CalcLoGainPedestal(Float_t logainsamples)
1000{
1001
1002 if (fPedRms < 0.)
1003 return;
1004
1005 if (fPedVar < 0.)
1006 return;
1007
1008 const Float_t elecPedRms = gkElectronicPedRms * TMath::Sqrt(logainsamples);
1009 const Float_t elecPedRmsVar = GetElectronicPedRmsRelVar() * elecPedRms * elecPedRms;
1010
1011 Float_t pedRmsSquare = fPedRms * fPedRms;
1012 Float_t pedRmsSquareVar = fPedVar * pedRmsSquare; // fPedRmsErr = fPedErr/2.
1013
1014 //
1015 // We do not know the Low Gain Pedestal RMS, so we have to retrieve it
1016 // from the High Gain:
1017 //
1018 // We extract the pure NSB contribution:
1019 //
1020 const Float_t elecRmsSquare = elecPedRms * elecPedRms;
1021 const Float_t elecRmsSquareVar = 4.*elecPedRmsVar * elecRmsSquare;
1022
1023 if (IsDebug())
1024 {
1025 *fLog << dbginf << "ID: " << GetPixId()
1026 << " Ped.Rms Square: " << pedRmsSquare
1027 << " Elec.Rms Square: " << elecRmsSquare
1028 << " Ped.Rms.Square Var.: " << pedRmsSquareVar
1029 << " Elec.Rms Square Var.: " << elecRmsSquareVar
1030 << endl;
1031 }
1032
1033
1034 Float_t higainNsbSquare = pedRmsSquare - elecRmsSquare;
1035 Float_t higainNsbSquareVar = (pedRmsSquareVar + elecRmsSquareVar);
1036
1037 if (higainNsbSquare < 0.001)
1038 higainNsbSquare = 0.;
1039
1040 if (IsDebug())
1041 {
1042 *fLog << dbginf << "ID: " << GetPixId()
1043 << " HiGain NSB Square: " << higainNsbSquare
1044 << " Var.HiGain NSB Square: " << higainNsbSquareVar
1045 << endl;
1046 }
1047
1048 //
1049 // Now, we divide the NSB by the conversion factor and
1050 // add it quadratically to the electronic noise
1051 //
1052 const Float_t conversionSquare = fConversionHiLo * fConversionHiLo;
1053 const Float_t conversionSquareRelVar = 4.* GetConversionHiLoRelVar();
1054
1055 const Float_t logainNsbSquare = higainNsbSquare / conversionSquare;
1056 //
1057 // Calculation of variance of: c = a/b
1058 // Delta(c)^2 = ( Delta(a)^2 + a^2/b^2*(Delta(b)^2 ) / b^2
1059 //
1060 const Float_t logainNsbSquareVar = ( higainNsbSquareVar
1061 + conversionSquareRelVar * higainNsbSquare * higainNsbSquare )
1062 / conversionSquare / conversionSquare;
1063
1064 fLoGainPedRmsSquare = logainNsbSquare + elecRmsSquare;
1065 fLoGainPedRmsSquareVar = logainNsbSquareVar + elecRmsSquareVar;
1066
1067 if (IsDebug())
1068 {
1069 *fLog << dbginf << "ID: " << GetPixId()
1070 << " LoGain Ped Rms Square: " << fLoGainPedRmsSquare
1071 << " Var.Ped Rms Square: " << fLoGainPedRmsSquareVar
1072 << endl;
1073 }
1074
1075
1076}
1077
Note: See TracBrowser for help on using the repository browser.