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

Last change on this file since 5138 was 5130, checked in by gaug, 20 years ago
*** empty log message ***
File size: 34.9 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.85;
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//
467Float_t MCalibrationChargePix::GetRSigma() const
468{
469 if (fRSigmaSquare < 0)
470 return -1;
471
472 return TMath::Sqrt(fRSigmaSquare);
473
474}
475
476// --------------------------------------------------------------------------
477//
478// Get the error of the reduced Sigma:
479// - If fRSigmaSquareVar is smaller than 0 (i.e. has not yet been set), return -1.
480// - Calculate the absolute variance of the reduced sigma with the formula:
481// reduced sigma variance = 0.25 * fRSigmaSquareVar / fRSigmaSquare
482//
483Float_t MCalibrationChargePix::GetRSigmaErr() const
484{
485
486 if (fRSigmaSquareVar < 0)
487 return -1;
488
489 //
490 // SigmaSquareVar = 4. * Sigma * Sigma * Var(sigma)
491 // ==> Var(sigma) = 0.25 * SigmaSquareVar / (Sigma * Sigma)
492 //
493 return TMath::Sqrt(0.25 * fRSigmaSquareVar / fRSigmaSquare);
494
495}
496
497// --------------------------------------------------------------------------
498//
499// Get the reduced Sigma per Charge:
500// - If GetRSigma() is smaller or equal 0. (i.e. has not yet been set), return -1.
501// - If GetMean() is 0. or -1. (i.e. has not yet been set), return -1.
502// - Return GetRSigma() / GetMean()
503//
504Float_t MCalibrationChargePix::GetRSigmaPerCharge() const
505{
506
507 const Float_t rsigma = GetRSigma();
508
509 if (rsigma <= 0)
510 return -1.;
511
512
513 const Float_t mean = GetMean();
514
515 if (mean == 0. || mean == -1.)
516 return -1.;
517
518 return rsigma / mean;
519}
520
521
522// --------------------------------------------------------------------------
523//
524// Get the error of the reduced Sigma per Charge:
525// - If GetRSigmaRelVar() is smaller or equal 0. (i.e. has not yet been set), return -1.
526// - If GetMeanRelVar() is smaller or equal 0. (i.e. has not yet been set), return -1.
527// - Return the propagated error of GetRSigmaPerCharge()
528//
529Float_t MCalibrationChargePix::GetRSigmaPerChargeErr() const
530{
531
532 const Float_t rsigmarelvar = GetRSigmaRelVar();
533
534 if (rsigmarelvar <= 0)
535 return -1.;
536
537
538 const Float_t meanrelvar = GetMeanRelVar();
539
540 if (meanrelvar <= 0.)
541 return -1.;
542
543 return TMath::Sqrt(rsigmarelvar + meanrelvar) * GetRSigmaPerCharge();
544}
545
546// --------------------------------------------------------------------------
547//
548// Get the reduced Sigma Square:
549// - If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
550// - Test bit kHiGainSaturation:
551// If yes, return fRSigmaSquare, multiplied with fConversionHiLo^2,
552// If no , return fRSigmaSquare
553//
554Float_t MCalibrationChargePix::GetConvertedRSigmaSquare() const
555{
556 if (fRSigmaSquare < 0)
557 return -1;
558
559 return IsHiGainSaturation() ? fRSigmaSquare*fConversionHiLo*fConversionHiLo : fRSigmaSquare ;
560}
561
562// --------------------------------------------------------------------------
563//
564// Get the relative variance of the reduced Sigma:
565// - If fRSigmaSquareVar is smaller than 0 (i.e. has not yet been set), return -1.
566// - Calculate the relative variance of the reduced sigma squares with the formula:
567// reduced sigma rel. variance = 0.25 * fRSigmaSquareVar / fRSigmaSquare / fRSigmaSquare
568// - Test bit kHiGainSaturation:
569// If yes, returns the sum of the relative variances of the reduced sigma and fConversionHiLo
570// Else returns the relative variance of the reduced sigma
571//
572Float_t MCalibrationChargePix::GetRSigmaRelVar() const
573{
574
575 if (fRSigmaSquareVar < 0)
576 return -1;
577
578 //
579 // SigmaSquareVar = 4. * Sigma * Sigma * Var(sigma)
580 // ==> Var(sigma) = 0.25 * SigmaSquareVar / (Sigma * Sigma)
581 //
582 return 0.25 * fRSigmaSquareVar / ( fRSigmaSquare * fRSigmaSquare );
583
584}
585
586// --------------------------------------------------------------------------
587//
588// Get the error on the number of photo-electrons (F-Factor Method):
589// - If fPheFFactorMethodVar is smaller than 0 (i.e. has not yet been set), return -1.
590// - Else returns the square root of fPheFFactorMethodVar
591//
592Float_t MCalibrationChargePix::GetPheFFactorMethodErr() const
593{
594 if (fPheFFactorMethodVar < 0.)
595 return -1.;
596 return TMath::Sqrt(fPheFFactorMethodVar);
597}
598
599// --------------------------------------------------------------------------
600//
601// Get the error on the mean total F-Factor of the signal readout (F-Factor Method):
602// - If fMeanFFactorFADC2PhotVar is smaller than 0 (i.e. has not yet been set), return -1.
603// - Else returns the square root of fMeanFFactorFADC2PhotVar
604//
605Float_t MCalibrationChargePix::GetMeanFFactorFADC2PhotErr() const
606{
607 if (fMeanFFactorFADC2PhotVar < 0.)
608 return -1.;
609 return TMath::Sqrt(fMeanFFactorFADC2PhotVar);
610}
611
612// --------------------------------------------------------------------------
613//
614// Get the relative variance on the number of photo-electrons (F-Factor Method):
615// - If fPheFFactorMethodVar is smaller than 0 (i.e. has not yet been set), return -1.
616// - If fPheFFactorMethod is 0, return -1.
617// - Else returns fPheFFactorMethodVar / fPheFFactorMethod^2
618//
619Float_t MCalibrationChargePix::GetPheFFactorMethodRelVar() const
620{
621 if (fPheFFactorMethodVar < 0.)
622 return -1.;
623 if (fPheFFactorMethod == 0.)
624 return -1.;
625
626 return fPheFFactorMethodVar / (fPheFFactorMethod * fPheFFactorMethod);
627}
628
629
630// --------------------------------------------------------------------------
631//
632// Get the error on the mean conversion factor (FFactor  Method):
633// - If fMeanConvFADC2PheVar is smaller than 0 (i.e. has not yet been set), return -1.
634// - Else returns the square root of fMeanConvFADC2PheVar
635//
636Float_t MCalibrationChargePix::GetMeanConvFADC2PheErr() const
637{
638 if (fMeanConvFADC2PheVar < 0.)
639 return -1.;
640 return TMath::Sqrt(fMeanConvFADC2PheVar);
641}
642
643// --------------------------------------------------------------------------
644//
645// Test bit kFFactorMethodValid
646//
647Bool_t MCalibrationChargePix::IsFFactorMethodValid() const
648{
649 return TESTBIT(fCalibFlags, kFFactorMethodValid);
650}
651
652
653// ----------------------------------------------------------------------------
654//
655// - If fSigma is smaller than 0 (i.e. has not yet been set), return kFALSE
656// - If fPedRms is smaller than 0 (i.e. has not yet been set), return kFALSE
657//
658// Calculate the reduced sigma of the low-Gain FADC slices:
659// - Test bit IsHiGainSaturation() for the Sigma:
660// If yes, take fLoGainSigma and fLoGainSigmaVar
661// If no , take fHiGainSigma and fHiGainSigmaVar
662//
663// - Test bit IsHiGainSaturation() for the pedRMS:
664// If yes, take fLoGainPedRmsSquare and fLoGainPedRmsSquareVar
665// If no , take fPedRms and fPedVar
666//
667// - Calculate the reduced sigma with the formula:
668// fRSigmaSquare = Sigma*Sigma - pedRMS*pedRMS
669//
670// - If fRSigmaSquare is smaller than 0, give a warning and return kFALSE
671//
672// - Calculate the variance of the reduced sigma with the formula:
673// fRSigmaSquareVar = 4.* (sigmaVar*Sigma*Sigma + pedRmsVar*pedRMS*pedRMS)
674//
675// A back-transformation to the corr. amplification factor of the High-Gain is done
676// in GetRSigma() and GetRSigmaErr()
677//
678Bool_t MCalibrationChargePix::CalcReducedSigma()
679{
680
681 if (GetSigma() < 0.)
682 return kFALSE;
683
684 if (GetPedRms() < 0.)
685 return kFALSE;
686
687 const Float_t sigma = IsHiGainSaturation() ? fLoGainSigma : fHiGainSigma ;
688 const Float_t sigmavar = IsHiGainSaturation() ? fLoGainSigmaVar : fHiGainSigmaVar;
689 const Float_t pedRmsSquare = IsHiGainSaturation() ? fLoGainPedRmsSquare : fPedRms*fPedRms;
690 const Float_t pedRmsSquareVar = IsHiGainSaturation() ? fLoGainPedRmsSquareVar : 0.25*fPedVar*pedRmsSquare;
691
692 if (IsDebug())
693 {
694 *fLog << dbginf << "ID: " << GetPixId()
695 << " HiGainSaturation: " << IsHiGainSaturation()
696 << " Sigma: " << sigma
697 << " Var.Sigma: " << sigmavar
698 << " PedRmsSquare: " << pedRmsSquare
699 << " pedRmsSquareVar: " << pedRmsSquareVar
700 << endl;
701 }
702
703 const Float_t sigmaSquare = sigma * sigma;
704 const Float_t sigmaSquareVar = 4. * sigmavar * sigmaSquare;
705
706 //
707 // Calculate the reduced sigmas
708 //
709 fRSigmaSquare = sigmaSquare - pedRmsSquare;
710
711 if (IsDebug())
712 {
713 *fLog << dbginf << "ID: " << GetPixId()
714 << " Red.Sigma Square: " << fRSigmaSquare
715 << endl;
716 }
717
718 if (fRSigmaSquare <= 0.)
719 {
720 if (IsDebug())
721 *fLog << warn
722 << "WARNING: Cannot calculate the reduced sigma: smaller than 0 in pixel "
723 << fPixId << endl;
724 return kFALSE;
725 }
726
727
728 fRSigmaSquareVar = 4. * (sigmaSquareVar + pedRmsSquareVar);
729
730 if (IsDebug())
731 {
732 *fLog << dbginf << "ID: " << GetPixId()
733 << " Var.Red.Sigma Square: " << fRSigmaSquareVar
734 << endl;
735 }
736
737 return kTRUE;
738}
739
740// ------------------------------------------------------------------
741//
742// If fRSigmaSquare is smaller than 0 (i.e. has not yet been set),
743// return kFALSE
744//
745// Calculate the number of photo-electrons with the F-Factor method:
746// - Test bit IsHiGainSaturation() for the Mean Sum of FADC slices:
747// If yes, take fLoGainMean and fLoGainMeanVar
748// If no , take fHiGainMean and fHiGainMeanVar
749//
750// - Test bit IsHiGainSaturation() for the pedRMS:
751// If yes, take fLoGainPedRmsSquare and fLoGainPedRmsSquareVar
752// If no , take fPedRms and fPedVar
753//
754// - Calculate the number of photo-electrons with the formula:
755// fPheFFactorMethod = gkFFactor*gkFFactor * Mean * Mean / fRSigmaSquare
756//
757// - Calculate the Variance on the photo-electrons with the formula:
758// fPheFFactorMethodVar = ( 4. * gkFFactorErr * gkFFactorErr / ( gkFFactor * gkFFactor )
759// + 4. * Mean Var. / ( Mean * Mean )
760// + fRSigmaSquareVar / fRSigmaSquare
761// ) * fPheFFactorMethod * fPheFFactorMethod
762//
763// - If fPheFFactorMethod is less than fPheFFactorMethodLimit,
764// set kFFactorMethodValid to kFALSE and return kFALSE
765//
766Bool_t MCalibrationChargePix::CalcFFactor()
767{
768
769 if (fRSigmaSquare < 0.)
770 return kFALSE;
771
772 //
773 // Square all variables in order to avoid applications of square root
774 //
775 const Float_t meanSquare = GetMean() * GetMean();
776 const Float_t meanSquareRelVar = 4.* GetMeanRelVar();
777
778 const Float_t ffactorsquare = gkFFactor * gkFFactor;
779 const Float_t ffactorsquareRelVar = 4.* GetFFactorRelVar();
780
781 const Float_t rsigmaSquareRelVar = fRSigmaSquareVar / fRSigmaSquare / fRSigmaSquare;
782 //
783 // Calculate the number of phe's from the F-Factor method
784 // (independent on Hi Gain or Lo Gain)
785 //
786 fPheFFactorMethod = ffactorsquare * meanSquare / fRSigmaSquare;
787
788 if (IsDebug())
789 {
790 *fLog << dbginf << "ID: " << GetPixId()
791 << " F-Factor Square: " << ffactorsquare
792 << " Mean Square: " << meanSquare
793 << " Red.Sigma Square: " << fRSigmaSquare
794 << " Photo-electrons: " << fPheFFactorMethod
795 << endl;
796 }
797
798 if (fPheFFactorMethod < fPheFFactorMethodLimit)
799 return kFALSE;
800
801 //
802 // Calculate the Error of Nphe
803 //
804 const Float_t pheRelVar = ffactorsquareRelVar + meanSquareRelVar + rsigmaSquareRelVar;
805 fPheFFactorMethodVar = pheRelVar * fPheFFactorMethod * fPheFFactorMethod;
806
807 if (IsDebug())
808 {
809 *fLog << dbginf << "ID: " << GetPixId()
810 << " Rel.Var.F-Factor Square: " << ffactorsquareRelVar
811 << " Rel.Var. Mean Square: " << meanSquareRelVar
812 << " Rel.Var. Red.Sigma Square: " << rsigmaSquareRelVar
813 << " Rel.Var. Photo-electrons: " << pheRelVar
814 << endl;
815 }
816
817 if (fPheFFactorMethodVar < 0. )
818 return kFALSE;
819
820 return kTRUE;
821}
822
823// ------------------------------------------------------------------
824//
825// If fPheFFactorMethod is smaller than 0 (i.e. has not yet been set),
826// return kFALSE
827//
828// If GetCovertedMean() is smaller than 0 (i.e. has not yet been set),
829// return kFALSE
830//
831// Calculate fMeanConvFADC2Phe with the following formula:
832//
833// fMeanConvFADC2Phe = fPheFFactorMethod / GetConvMean();
834//
835// Calculate the rel. variance of fMeanConvFADC2Phe, taking into account that
836// in the calculation of the number of phe's one mean square has already been used.
837// Now, dividing by another mean, one mean calcels out, one cannot directly propagate
838// the errors, but instead havs to take into account this cancellation:
839//
840// convrelvar = ffactorsquareRelVar + GetMeanRelVar() + rsigmaSquareRelVar;
841//
842// If confrelvar is smaller than 0. or greater than fConvFFactorRelVarLimit,
843// return kFALSE
844//
845// Calculate the variance of fMeanConvFADC2Phe with the formula:
846//
847// fMeanConvFADC2PheVar = convrelvar * fMeanConvFADC2Phe * fMeanConvFADC2Phe;
848//
849// Set kFFactorMethodValid to kTRUE and
850// return kTRUE
851//
852Bool_t MCalibrationChargePix::CalcConvFFactor()
853{
854
855 if (fPheFFactorMethod <= 0.)
856 return kFALSE;
857
858 const Float_t convmean = GetConvertedMean();
859
860 if (convmean <= 0.)
861 return kFALSE;
862
863 fMeanConvFADC2Phe = fPheFFactorMethod / convmean;
864
865 if (IsDebug())
866 {
867 *fLog << dbginf << "ID: " << GetPixId()
868 << " Converted Mean: " << convmean
869 << " Conversion FADC2Phe: " << fMeanConvFADC2Phe
870 << endl;
871 }
872
873 const Float_t ffactorsquareRelVar = 4.* GetFFactorRelVar();
874 const Float_t rsigmaSquareRelVar = fRSigmaSquareVar / fRSigmaSquare / fRSigmaSquare;
875 //
876 // In the calculation of the number of phe's one mean square has already been used.
877 // Now, we divide by another mean, so one mean calcels out, we cannot directly propagate
878 // the errors, but have to take account of this cancellation:
879 //
880 Float_t convrelvar = ffactorsquareRelVar + GetMeanRelVar() + rsigmaSquareRelVar;
881 const Float_t limit = IsHiGainSaturation() ? fConvFFactorRelVarLimit * 4. : fConvFFactorRelVarLimit;
882
883 //
884 // Also have to take into account the pixels labelled MBadPixelsPix::kChargeSigmaNotValid which do not
885 // have a fRSigmaSquareVar, calculate their error directly!
886 //
887 if (fRSigmaSquareVar < 0.)
888 convrelvar = GetMeanRelVar() + GetPheFFactorMethodRelVar();
889
890 if (IsDebug())
891 {
892 *fLog << dbginf << "ID: " << GetPixId()
893 << " Rel.Var.Red.Sigma: " << rsigmaSquareRelVar
894 << " Rel.Var.Mean: " << GetMeanRelVar()
895 << " Rel.Var.F-Factor: " << ffactorsquareRelVar
896 << " Rel.Var.Conversion FADC2Phe: " << convrelvar
897 << endl;
898 }
899
900 if (convrelvar > limit || convrelvar < 0.)
901 {
902 *fLog << warn << GetDescriptor() << ": Conv. F-Factor Method Rel. Var.: "
903 << Form("%4.3f out of limits: [0,%3.2f] in pixel:%4i",convrelvar,limit,fPixId) << endl;
904 return kFALSE;
905 }
906
907 fMeanConvFADC2PheVar = convrelvar * fMeanConvFADC2Phe * fMeanConvFADC2Phe;
908
909 SetFFactorMethodValid(kTRUE);
910 return kTRUE;
911}
912
913// ----------------------------------------------------------------------------------
914//
915// If photflux is smaller or equal 0, return kFALSE
916//
917// Calculate the total F-Factor with the formula:
918// fMeanFFactorFADC2Phot = Sqrt ( fRSigmaSquare ) / GetMean() * sqrt(nphotons)
919//
920// Calculate the error of the total F-Factor
921//
922Bool_t MCalibrationChargePix::CalcMeanFFactor( const Float_t nphotons, const Float_t nphotonsrelvar )
923{
924
925
926 if (IsDebug())
927 {
928 *fLog << dbginf << "ID: " << GetPixId()
929 << " Number photons: " << nphotons
930 << " Rel.Var.Number photons: " << nphotonsrelvar
931 << " Red.Sigma Square: " << fRSigmaSquare
932 << " Mean: " << GetMean()
933 << endl;
934 }
935
936
937 if (nphotons <= 0.)
938 {
939 *fLog << warn << GetDescriptor() << ": Assumed photon flux is smaller or equal 0." << endl;
940 return kFALSE;
941 }
942
943 if (nphotonsrelvar < 0.)
944 {
945 *fLog << warn << GetDescriptor() << ": Assumed photon flux variance is smaller than 0." << endl;
946 return kFALSE;
947 }
948
949 fMeanFFactorFADC2Phot = TMath::Sqrt(fRSigmaSquare * nphotons) / GetMean() ;
950
951 if (IsDebug())
952 {
953 *fLog << dbginf << "ID: " << GetPixId()
954 << " F-Factor FADC2Phot: " << fMeanFFactorFADC2Phot
955 << endl;
956 }
957
958 if (fMeanFFactorFADC2Phot < 0.)
959 {
960 *fLog << warn << GetDescriptor() << ": F-Factor photons to FADC counts smaller than 0." << endl;
961 return kFALSE;
962 }
963
964 const Float_t ffactorrelvar = 0.25 * fRSigmaSquareVar / ( fRSigmaSquare * fRSigmaSquare)
965 + GetMeanRelVar()
966 + 0.25 * nphotonsrelvar;
967
968 fMeanFFactorFADC2PhotVar = ffactorrelvar * fMeanFFactorFADC2Phot * fMeanFFactorFADC2Phot;
969
970 if (IsDebug())
971 {
972 *fLog << dbginf << "ID: " << GetPixId()
973 << " Rel.Var.Red.Sigma: " << 0.25 * fRSigmaSquareVar / ( fRSigmaSquare * fRSigmaSquare)
974 << " Rel.Var.Mean: " << GetMeanRelVar()
975 << " Rel.Var.photons: " << 0.25 * nphotonsrelvar
976 << " Rel.Var.F-Factor FADC2Phot: " << ffactorrelvar
977 << endl;
978 }
979
980 return kTRUE;
981}
982
983
984// ----------------------------------------------------------------------------
985//
986// - If fPed is smaller than 0 (i.e. has not yet been set), return.
987// - If fPedVar is smaller than 0 (i.e. has not yet been set), return.
988//
989// Calculate the electronic pedestal RMS with the formula:
990// - elec. pedestal = gkElectronicPedRms * sqrt(logainsamples)
991//
992// Calculate the night sky background ped. RMS contribution ("NSB") in the high-gain
993// from the high gain Pedestal RMS with the formula:
994// - HiGain NSB square = fPedRms * fPedRms - elec.ped.* elec.ped.
995// - Var(HiGain NSB square) = fPedVar * fPedRms * fPedRms + 4.*elecPedRmsVar * elec.ped.* elec.ped.
996//
997// If HiGain NSB square is smaller than 0., set it to zero. (but not the error!)
998//
999// Convert the NSB ped. RMS contribution to the low-gain with the formula:
1000// - LoGain NSB square = - HiGain NSB square / (fConversionHiLo*fConversionHiLo)
1001// - Var(LoGain NSB square) = ( Var(HiGain NSB square) / (HiGain NSB square * HiGain NSB square)
1002// + GetConversionHiLoRelVar()
1003// ) * LoGain NSB square * LoGain NSB square
1004//
1005// - Low Gain Ped RMS Square = LoGain NSB square + elec.ped. square
1006// Var (Low Gain Ped RMS Square) = Var(LoGain NSB square) + Var(elec.ped. square)
1007//
1008void MCalibrationChargePix::CalcLoGainPedestal(Float_t logainsamples, const Int_t aidx)
1009{
1010
1011 if (fPedRms < 0.)
1012 return;
1013
1014 if (fPedVar < 0.)
1015 return;
1016
1017 const Float_t elecPedRms = (aidx == 0 ? gkElectronicPedRmsInner : gkElectronicPedRmsOuter )
1018 * TMath::Sqrt(logainsamples) / fConversionHiLo;
1019 const Float_t elecPedRmsVar = ( GetElectronicPedRmsRelVar(aidx) + GetConversionHiLoRelVar() )
1020 * elecPedRms * elecPedRms;
1021
1022 Float_t pedRmsSquare = fPedRms * fPedRms;
1023 Float_t pedRmsSquareVar = fPedVar * pedRmsSquare; // fPedRmsErr = fPedErr/2.
1024
1025 //
1026 // We do not know the Lo Gain Pedestal RMS, so we have to retrieve it
1027 // from the HI GAIN (all calculation per slice up to now):
1028 //
1029 // We extract the pure NSB contribution:
1030 //
1031 const Float_t elecRmsSquare = elecPedRms * elecPedRms;
1032 const Float_t elecRmsSquareVar = 4.*elecPedRmsVar * elecRmsSquare;
1033
1034 if (IsDebug())
1035 {
1036 *fLog << dbginf << "ID: " << GetPixId()
1037 << " Ped.Rms Square: " << pedRmsSquare
1038 << " Elec.Rms Square: " << elecRmsSquare
1039 << " Ped.Rms.Square Var.: " << pedRmsSquareVar
1040 << " Elec.Rms Square Var.: " << elecRmsSquareVar
1041 << endl;
1042 }
1043
1044
1045 Float_t higainNsbSquare = pedRmsSquare - elecRmsSquare;
1046 Float_t higainNsbSquareRelVar = (pedRmsSquareVar + elecRmsSquareVar);
1047
1048
1049 if (higainNsbSquare < 0.001)
1050 higainNsbSquare = 0.;
1051 else
1052 higainNsbSquareRelVar /= (higainNsbSquare * higainNsbSquare) ;
1053
1054 if (IsDebug())
1055 {
1056 *fLog << dbginf << "ID: " << GetPixId()
1057 << " HiGain NSB Square: " << higainNsbSquare
1058 << " Rel.Var.HiGain NSB Square: " << higainNsbSquareRelVar
1059 << endl;
1060 }
1061
1062 //
1063 // Now, we divide the NSB by the conversion factor and
1064 // add it quadratically to the electronic noise
1065 //
1066 const Float_t conversionSquare = fConversionHiLo * fConversionHiLo;
1067 const Float_t conversionSquareRelVar = 4.* GetConversionHiLoRelVar();
1068
1069 const Float_t logainNsbSquare = higainNsbSquare / conversionSquare;
1070 const Float_t logainNsbSquareVar = ( higainNsbSquareRelVar + conversionSquareRelVar )
1071 * logainNsbSquare * logainNsbSquare;
1072
1073 fLoGainPedRmsSquare = logainNsbSquare + elecRmsSquare;
1074 fLoGainPedRmsSquareVar = logainNsbSquareVar + elecRmsSquareVar;
1075
1076 if (IsDebug())
1077 {
1078 *fLog << dbginf << "ID: " << GetPixId()
1079 << " LoGain Ped Rms Square: " << fLoGainPedRmsSquare
1080 << " Var.Ped Rms Square: " << fLoGainPedRmsSquareVar
1081 << endl;
1082 }
1083
1084
1085}
1086
Note: See TracBrowser for help on using the repository browser.