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

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