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

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