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

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