source: tags/Mars-V1.2/mcalib/MCalibrationChargePix.cc

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