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

Last change on this file since 4134 was 4130, checked in by gaug, 21 years ago
*** empty log message ***
File size: 28.2 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: GetConvertedLoGainMean() or GetConvertedLoGainSigma()
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 = 5.;
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 converted to High Gain amplification:
309// Returns fLoGainMean multiplied with fConversionHiLo
310//
311Float_t MCalibrationChargePix::GetConvertedLoGainMean() const
312{
313 return fLoGainMean * fConversionHiLo;
314}
315
316// --------------------------------------------------------------------------
317//
318// Get the Error of the converted Low Gain Mean:
319//
320// Returns -1 if the variable fLoGainMean or fLoGainMeanVar are smaller than 0.
321//
322// Returns the square root of the quadratic sum of the relative variances of
323// the fLoGainMean and fConversionHiLo, mulitplied with GetConvertedLoGainMean()
324//
325Float_t MCalibrationChargePix::GetConvertedLoGainMeanErr() const
326{
327
328 const Float_t logainrelvar = GetLoGainMeanRelVar();
329
330 if (logainrelvar < 0.)
331 return -1.;
332
333 return TMath::Sqrt(logainrelvar + GetConversionHiLoRelVar()) * GetConvertedLoGainMean();
334}
335
336// --------------------------------------------------------------------------
337//
338// Get the Low Gain Sigma converted to High Gain amplification:
339// Returns fLoGainSigma multiplied with fConversionHiLo
340//
341Float_t MCalibrationChargePix::GetConvertedLoGainSigma() const
342{
343 return fLoGainSigma * fConversionHiLo;
344}
345
346// --------------------------------------------------------------------------
347//
348// Get the Error of the converted Low Gain Sigma:
349//
350// Returns -1 if the variable fLoGainSigma or fLoGainSigmaVar are smaller than 0.
351//
352// Returns the square root of the quadratic sum of the relative variances of
353// the fLoGainSigma and fConversionHiLo, mulitplied with GetConvertedLoGainSigma()
354//
355Float_t MCalibrationChargePix::GetConvertedLoGainSigmaErr() const
356{
357
358 if (fLoGainSigmaVar < 0.)
359 return -1.;
360
361 if (fLoGainSigma < 0.)
362 return -1.;
363
364 const Float_t sigmaRelVar = fLoGainSigmaVar
365 /( fLoGainSigma * fLoGainSigma );
366
367 return TMath::Sqrt(sigmaRelVar+GetConversionHiLoRelVar()) * GetConvertedLoGainSigma();
368}
369
370
371
372// --------------------------------------------------------------------------
373//
374// Get the reduced Sigma:
375// - If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
376// - Test bit kHiGainSaturation:
377// If yes, return square root of fRSigmaSquare, multiplied with fConversionHiLo,
378// If no , return square root of fRSigmaSquare
379//
380Float_t MCalibrationChargePix::GetRSigma() const
381{
382 if (fRSigmaSquare < 0)
383 return -1;
384
385 const Float_t rsigma = TMath::Sqrt(fRSigmaSquare);
386
387 return IsHiGainSaturation() ? rsigma*fConversionHiLo : rsigma ;
388}
389
390// --------------------------------------------------------------------------
391//
392// Get the error of the reduced Sigma:
393// - If fRSigmaSquareVar is smaller than 0 (i.e. has not yet been set), return -1.
394// - Calculate the absolute variance of the reduced sigma with the formula:
395// reduced sigma variance = 0.25 * fRSigmaSquareVar / fRSigmaSquare
396// - Test bit kHiGainSaturation:
397// If yes, returns the square root of the quadratic sum of the relative variances of the
398// reduced sigma and fConversionHiLo, mulitplied with GetRSigma()
399// Else returns the square root of rel. (0.25*fRSigmaSquareVar / fRSigmaSquare)
400//
401Float_t MCalibrationChargePix::GetRSigmaErr() const
402{
403
404 if (fRSigmaSquareVar < 0)
405 return -1;
406
407 //
408 // SigmaSquareVar = 4. * Sigma * Sigma * Var(sigma)
409 // ==> Var(sigma) = 0.25 * SigmaSquareVar / (Sigma * Sigma)
410 //
411 const Float_t rsigmaVar = 0.25 * fRSigmaSquareVar / fRSigmaSquare;
412
413 if (IsHiGainSaturation())
414 return TMath::Sqrt(rsigmaVar/fRSigmaSquare + GetConversionHiLoRelVar()) * GetRSigma();
415 else
416 return TMath::Sqrt(rsigmaVar);
417
418}
419
420// --------------------------------------------------------------------------
421//
422// Get the reduced Sigma per Charge:
423// - If GetRSigma() is smaller or equal 0. (i.e. has not yet been set), return -1.
424// - If GetMean() is 0. or -1. (i.e. has not yet been set), return -1.
425// - Return GetRSigma() / GetMean()
426//
427Float_t MCalibrationChargePix::GetRSigmaPerCharge() const
428{
429
430 const Float_t rsigma = GetRSigma();
431
432 if (rsigma <= 0)
433 return -1.;
434
435
436 const Float_t mean = GetMean();
437
438 if (mean == 0. || mean == -1.)
439 return -1.;
440
441 return rsigma / mean;
442}
443
444
445// --------------------------------------------------------------------------
446//
447// Get the error of the reduced Sigma per Charge:
448// - If GetRSigmaRelVar() is smaller or equal 0. (i.e. has not yet been set), return -1.
449// - If GetMeanRelVar() is smaller or equal 0. (i.e. has not yet been set), return -1.
450// - Return the propagated error of GetRSigmaPerCharge()
451//
452Float_t MCalibrationChargePix::GetRSigmaPerChargeErr() const
453{
454
455 const Float_t rsigmarelvar = GetRSigmaRelVar();
456
457 if (rsigmarelvar <= 0)
458 return -1.;
459
460
461 const Float_t meanrelvar = GetMeanRelVar();
462
463 if (meanrelvar <= 0.)
464 return -1.;
465
466 return TMath::Sqrt(rsigmarelvar + meanrelvar) * GetRSigmaPerCharge();
467}
468
469// --------------------------------------------------------------------------
470//
471// Get the reduced Sigma Square:
472// - If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
473// - Test bit kHiGainSaturation:
474// If yes, return fRSigmaSquare, multiplied with fConversionHiLo^2,
475// If no , return fRSigmaSquare
476//
477Float_t MCalibrationChargePix::GetRSigmaSquare() const
478{
479 if (fRSigmaSquare < 0)
480 return -1;
481
482 return IsHiGainSaturation() ? fRSigmaSquare*fConversionHiLo*fConversionHiLo : fRSigmaSquare ;
483}
484
485// --------------------------------------------------------------------------
486//
487// Get the relative variance of the reduced Sigma:
488// - If fRSigmaSquareVar is smaller than 0 (i.e. has not yet been set), return -1.
489// - Calculate the relative variance of the reduced sigma squares with the formula:
490// reduced sigma rel. variance = 0.25 * fRSigmaSquareVar / fRSigmaSquare / fRSigmaSquare
491// - Test bit kHiGainSaturation:
492// If yes, returns the sum of the relative variances of the reduced sigma and fConversionHiLo
493// Else returns the relative variance of the reduced sigma
494//
495Float_t MCalibrationChargePix::GetRSigmaRelVar() const
496{
497
498 if (fRSigmaSquareVar < 0)
499 return -1;
500
501 //
502 // SigmaSquareVar = 4. * Sigma * Sigma * Var(sigma)
503 // ==> Var(sigma) = 0.25 * SigmaSquareVar / (Sigma * Sigma)
504 //
505 const Float_t rsigmaRelVar = 0.25 * fRSigmaSquareVar / ( fRSigmaSquare * fRSigmaSquare );
506
507 if (IsHiGainSaturation())
508 return rsigmaRelVar + GetConversionHiLoRelVar();
509 else
510 return rsigmaRelVar;
511}
512
513// --------------------------------------------------------------------------
514//
515// Get the error on the number of photo-electrons (F-Factor Method):
516// - If fPheFFactorMethodVar is smaller than 0 (i.e. has not yet been set), return -1.
517// - Else returns the square root of fPheFFactorMethodVar
518//
519Float_t MCalibrationChargePix::GetPheFFactorMethodErr() const
520{
521 if (fPheFFactorMethodVar < 0.)
522 return -1.;
523 return TMath::Sqrt(fPheFFactorMethodVar);
524}
525
526// --------------------------------------------------------------------------
527//
528// Get the error on the mean total F-Factor of the signal readout (F-Factor Method):
529// - If fMeanFFactorFADC2PhotVar is smaller than 0 (i.e. has not yet been set), return -1.
530// - Else returns the square root of fMeanFFactorFADC2PhotVar
531//
532Float_t MCalibrationChargePix::GetMeanFFactorFADC2PhotErr() const
533{
534 if (fMeanFFactorFADC2PhotVar < 0.)
535 return -1.;
536 return TMath::Sqrt(fMeanFFactorFADC2PhotVar);
537}
538
539// --------------------------------------------------------------------------
540//
541// Get the relative variance on the number of photo-electrons (F-Factor Method):
542// - If fPheFFactorMethodVar is smaller than 0 (i.e. has not yet been set), return -1.
543// - If fPheFFactorMethod is 0, return -1.
544// - Else returns fPheFFactorMethodVar / fPheFFactorMethod^2
545//
546Float_t MCalibrationChargePix::GetPheFFactorMethodRelVar() const
547{
548 if (fPheFFactorMethodVar < 0.)
549 return -1.;
550 if (fPheFFactorMethod == 0.)
551 return -1.;
552
553 return fPheFFactorMethodVar / (fPheFFactorMethod * fPheFFactorMethod);
554}
555
556
557// --------------------------------------------------------------------------
558//
559// Get the error on the mean conversion factor (FFactor  Method):
560// - If fMeanConvFADC2PheVar is smaller than 0 (i.e. has not yet been set), return -1.
561// - Else returns the square root of fMeanConvFADC2PheVar
562//
563Float_t MCalibrationChargePix::GetMeanConvFADC2PheErr() const
564{
565 if (fMeanConvFADC2PheVar < 0.)
566 return -1.;
567 return TMath::Sqrt(fMeanConvFADC2PheVar);
568}
569
570// --------------------------------------------------------------------------
571//
572// Test bit kFFactorMethodValid
573//
574Bool_t MCalibrationChargePix::IsFFactorMethodValid() const
575{
576 return TESTBIT(fCalibFlags, kFFactorMethodValid);
577}
578
579
580// ----------------------------------------------------------------------------
581//
582// - If fSigma is smaller than 0 (i.e. has not yet been set), return kFALSE
583// - If fPedRms is smaller than 0 (i.e. has not yet been set), return kFALSE
584//
585// Calculate the reduced sigma of the low-Gain FADC slices:
586// - Test bit IsHiGainSaturation() for the Sigma:
587// If yes, take fLoGainSigma and fLoGainSigmaVar
588// If no , take fHiGainSigma and fHiGainSigmaVar
589//
590// - Test bit IsHiGainSaturation() for the pedRMS:
591// If yes, take fLoGainPedRmsSquare and fLoGainPedRmsSquareVar
592// If no , take fPedRms and fPedVar
593//
594// - Calculate the reduced sigma with the formula:
595// fRSigmaSquare = Sigma*Sigma - pedRMS*pedRMS
596//
597// - If fRSigmaSquare is smaller than 0, give a warning and return kFALSE
598//
599// - Calculate the variance of the reduced sigma with the formula:
600// fRSigmaSquareVar = 4.* (sigmaVar*Sigma*Sigma + pedRmsVar*pedRMS*pedRMS)
601//
602// A back-transformation to the corr. amplification factor of the High-Gain is done
603// in GetRSigma() and GetRSigmaErr()
604//
605Bool_t MCalibrationChargePix::CalcReducedSigma()
606{
607
608 if (GetSigma() < 0.)
609 return kFALSE;
610
611 if (GetPedRms() < 0.)
612 return kFALSE;
613
614 const Float_t sigma = IsHiGainSaturation() ? fLoGainSigma : fHiGainSigma ;
615 const Float_t sigmavar = IsHiGainSaturation() ? fLoGainSigmaVar : fHiGainSigmaVar;
616 const Float_t pedRmsSquare = IsHiGainSaturation() ? fLoGainPedRmsSquare : fPedRms*fPedRms;
617 const Float_t pedRmsSquareVar = IsHiGainSaturation() ? fLoGainPedRmsSquareVar : 0.25*fPedVar*pedRmsSquare;
618
619 const Float_t sigmaSquare = sigma * sigma;
620 const Float_t sigmaSquareVar = 4. * sigmavar * sigmaSquare;
621
622 //
623 // Calculate the reduced sigmas
624 //
625 fRSigmaSquare = sigmaSquare - pedRmsSquare;
626
627 if (fRSigmaSquare <= 0.)
628 {
629 *fLog << warn
630 << "WARNING: Cannot calculate the reduced sigma: smaller than 0 in pixel "
631 << fPixId << endl;
632 return kFALSE;
633 }
634
635 fRSigmaSquareVar = 4. * (sigmaSquareVar + pedRmsSquareVar);
636
637 return kTRUE;
638}
639
640// ------------------------------------------------------------------
641//
642// If fRSigmaSquare is smaller than 0 (i.e. has not yet been set),
643// set kFFactorMethodValid to kFALSE and return kFALSE
644//
645// Calculate the number of photo-electrons with the F-Factor method:
646// - Test bit IsHiGainSaturation() for the Mean Sum of FADC slices:
647// If yes, take fLoGainMean and fLoGainMeanVar
648// If no , take fHiGainMean and fHiGainMeanVar
649//
650// - Test bit IsHiGainSaturation() for the pedRMS:
651// If yes, take fLoGainPedRmsSquare and fLoGainPedRmsSquareVar
652// If no , take fPedRms and fPedVar
653//
654// - Calculate the number of photo-electrons with the formula:
655// fPheFFactorMethod = gkFFactor*gkFFactor * Mean * Mean / fRSigmaSquare
656//
657// - Calculate the Variance on the photo-electrons with the formula:
658// fPheFFactorMethodVar = ( 4. * gkFFactorErr * gkFFactorErr / ( gkFFactor * gkFFactor )
659// + 4. * Mean Var. / ( Mean * Mean )
660// + fRSigmaSquareVar / fRSigmaSquare
661// ) * fPheFFactorMethod * fPheFFactorMethod
662//
663// - If fPheFFactorMethod is less than fPheFFactorMethodLimit,
664// set kFFactorMethodValid to kFALSE and return kFALSE
665// else: Set kFFactorMethodValid to kTRUE and return kTRUE
666//
667Bool_t MCalibrationChargePix::CalcFFactorMethod()
668{
669
670 if (fRSigmaSquare < 0.)
671 return kFALSE;
672
673 //
674 // Square all variables in order to avoid applications of square root
675 //
676 const Float_t meanSquare = GetMean() * GetMean();
677 const Float_t meanSquareRelVar = 4.* GetMeanRelVar();
678
679 const Float_t ffactorsquare = gkFFactor * gkFFactor;
680 const Float_t ffactorsquareRelVar = 4.* GetFFactorRelVar();
681
682 const Float_t rsigmaSquareRelVar = fRSigmaSquareVar / fRSigmaSquare / fRSigmaSquare;
683 //
684 // Calculate the number of phe's from the F-Factor method
685 // (independent on Hi Gain or Lo Gain)
686 //
687 fPheFFactorMethod = ffactorsquare * meanSquare / fRSigmaSquare;
688
689 if (fPheFFactorMethod < fPheFFactorMethodLimit)
690 return kFALSE;
691
692 //
693 // Calculate the Error of Nphe
694 //
695 const Float_t pheRelVar = ffactorsquareRelVar + meanSquareRelVar + rsigmaSquareRelVar;
696 fPheFFactorMethodVar = pheRelVar * fPheFFactorMethod * fPheFFactorMethod;
697
698 if (fPheFFactorMethodVar < 0. )
699 return kFALSE;
700
701 fMeanConvFADC2Phe = fPheFFactorMethod / GetMean();
702
703 if (fMeanConvFADC2Phe < 0. )
704 return kFALSE;
705
706 //
707 // In the calculation of the number of phe's one mean square has already been used.
708 // Now, we divide by another mean, so one mean calcels out, we cannot directly propagate
709 // the errors, but have to take account of this cancellation:
710 //
711 const Float_t convrelvar = ffactorsquareRelVar + GetMeanRelVar() + rsigmaSquareRelVar;
712 const Float_t limit = IsHiGainSaturation() ? fConvFFactorRelVarLimit * 4. : fConvFFactorRelVarLimit;
713
714 if (convrelvar > limit || convrelvar < 0.)
715 {
716 *fLog << warn << GetDescriptor() << ": Conversion F-Factor Method Rel. Variance: "
717 << convrelvar << " above limits of: [0," << Form("%3.2f",limit)
718 << "] in pixel: " << fPixId << endl;
719 return kFALSE;
720 }
721
722 fMeanConvFADC2PheVar = convrelvar * fMeanConvFADC2Phe * fMeanConvFADC2Phe;
723
724 SetFFactorMethodValid(kTRUE);
725 return kTRUE;
726}
727
728// ----------------------------------------------------------------------------------
729//
730// If photflux is smaller or equal 0, return kFALSE
731//
732// Calculate the total F-Factor with the formula:
733// fMeanFFactorFADC2Phot = Sqrt ( fRSigmaSquare ) / GetMean() * sqrt(nphotons)
734//
735// Calculate the error of the total F-Factor
736//
737Bool_t MCalibrationChargePix::CalcMeanFFactor( const Float_t nphotons, const Float_t nphotonsrelvar )
738{
739
740 if (nphotons <= 0.)
741 {
742 *fLog << warn << GetDescriptor() << ": Assumed photon flux is smaller or equal 0." << endl;
743 return kFALSE;
744 }
745
746 if (nphotonsrelvar < 0.)
747 {
748 *fLog << warn << GetDescriptor() << ": Assumed photon flux variance is smaller than 0." << endl;
749 return kFALSE;
750 }
751
752 fMeanFFactorFADC2Phot = TMath::Sqrt(fRSigmaSquare * nphotons) / GetMean() ;
753
754 if (fMeanFFactorFADC2Phot < 0.)
755 {
756 *fLog << warn << GetDescriptor() << ": F-Factor photons to FADC counts smaller than 0." << endl;
757 return kFALSE;
758 }
759
760 const Float_t ffactorrelvar = 0.25 * fRSigmaSquareVar / ( fRSigmaSquare * fRSigmaSquare)
761 + GetMeanRelVar()
762 + 0.25 * nphotonsrelvar;
763
764 fMeanFFactorFADC2PhotVar = ffactorrelvar * fMeanFFactorFADC2Phot * fMeanFFactorFADC2Phot;
765
766 return kTRUE;
767}
768
769
770// ----------------------------------------------------------------------------
771//
772// - If fPed is smaller than 0 (i.e. has not yet been set), return.
773// - If fPedVar is smaller than 0 (i.e. has not yet been set), return.
774//
775// Calculate the electronic pedestal RMS with the formula:
776// - elec. pedestal = gkElectronicPedRms * sqrt(logainsamples)
777//
778// Calculate the night sky background ped. RMS contribution ("NSB") in the high-gain
779// from the high gain Pedestal RMS with the formula:
780// - HiGain NSB square = fPedRms * fPedRms - elec.ped.* elec.ped.
781// - Var(HiGain NSB square) = fPedVar * fPedRms * fPedRms + 4.*elecPedRmsVar * elec.ped.* elec.ped.
782//
783// If HiGain NSB square is smaller than 0., set it to zero. (but not the error!)
784//
785// Convert the NSB ped. RMS contribution to the low-gain with the formula:
786// - LoGain NSB square = - HiGain NSB square / (fConversionHiLo*fConversionHiLo)
787// - Var(LoGain NSB square) = ( Var(HiGain NSB square) / (HiGain NSB square * HiGain NSB square)
788// + GetConversionHiLoRelVar()
789// ) * LoGain NSB square * LoGain NSB square
790//
791// - Low Gain Ped RMS Square = LoGain NSB square + elec.ped. square
792// Var (Low Gain Ped RMS Square) = Var(LoGain NSB square) + Var(elec.ped. square)
793//
794void MCalibrationChargePix::CalcLoGainPedestal(Float_t logainsamples, const Int_t aidx)
795{
796
797 if (fPedRms < 0.)
798 return;
799
800 if (fPedVar < 0.)
801 return;
802
803 const Float_t elecPedRms = (aidx == 0 ? gkElectronicPedRmsInner : gkElectronicPedRmsOuter )
804 * TMath::Sqrt(logainsamples) / fConversionHiLo;
805 const Float_t elecPedRmsVar = ( GetElectronicPedRmsRelVar(aidx) + GetConversionHiLoRelVar() )
806 * elecPedRms * elecPedRms;
807
808 Float_t pedRmsSquare = fPedRms * fPedRms;
809 Float_t pedRmsSquareVar = fPedVar * pedRmsSquare; // fPedRmsErr = fPedErr/2.
810
811 //
812 // We do not know the Lo Gain Pedestal RMS, so we have to retrieve it
813 // from the HI GAIN (all calculation per slice up to now):
814 //
815 // We extract the pure NSB contribution:
816 //
817 const Float_t elecRmsSquare = elecPedRms * elecPedRms;
818 const Float_t elecRmsSquareVar = 4.*elecPedRmsVar * elecRmsSquare;
819
820 Float_t higainNsbSquare = pedRmsSquare - elecRmsSquare;
821 Float_t higainNsbSquareRelVar = (pedRmsSquareVar + elecRmsSquareVar)
822 / (higainNsbSquare * higainNsbSquare) ;
823
824 if (higainNsbSquare < 0.)
825 higainNsbSquare = 0.;
826
827 //
828 // Now, we divide the NSB by the conversion factor and
829 // add it quadratically to the electronic noise
830 //
831 const Float_t conversionSquare = fConversionHiLo * fConversionHiLo;
832 const Float_t conversionSquareRelVar = 4.* GetConversionHiLoRelVar();
833
834 const Float_t logainNsbSquare = higainNsbSquare / conversionSquare;
835 const Float_t logainNsbSquareVar = ( higainNsbSquareRelVar + conversionSquareRelVar )
836 * logainNsbSquare * logainNsbSquare;
837
838 fLoGainPedRmsSquare = logainNsbSquare + elecRmsSquare;
839 fLoGainPedRmsSquareVar = logainNsbSquareVar + elecRmsSquareVar;
840
841}
842
Note: See TracBrowser for help on using the repository browser.