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

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