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

Last change on this file since 3937 was 3724, checked in by gaug, 21 years ago
*** empty log message ***
File size: 27.2 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: GetConvertedLoGainMean() or GetConvertedLoGainSigma()
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::gkElectronicPedRms = 1.5;
82const Float_t MCalibrationChargePix::gkElectronicPedRmsErr = 0.3;
83const Float_t MCalibrationChargePix::gkFFactor = 1.15;
84const Float_t MCalibrationChargePix::gkFFactorErr = 0.02;
85
86const Float_t MCalibrationChargePix::fgConversionHiLo = 10.;
87const Float_t MCalibrationChargePix::fgConversionHiLoErr = 2.5;
88const Float_t MCalibrationChargePix::fgPheFFactorMethodLimit = 5.;
89const Float_t MCalibrationChargePix::fgConvFFactorRelErrLimit = 0.35;
90// --------------------------------------------------------------------------
91//
92// Default Constructor:
93//
94// Sets:
95// - fCalibFlags to 0
96// - fConversionHiLo to fgConversionHiLo
97// - fConversionHiLoVar to square of fgConversionHiLoErr
98// - fConvFFactorRelErrLimit to fgConvFFactorRelErrLimit*fgConvFFactorRelErrLimit
99// - fPheFFactorLimit to fgPheFFactorLimit
100//
101// Calls:
102// - Clear()
103//
104MCalibrationChargePix::MCalibrationChargePix(const char *name, const char *title)
105 : fCalibFlags(0)
106{
107
108 fName = name ? name : "MCalibrationChargePix";
109 fTitle = title ? title : "Container of the fit results of MHCalibrationChargePixs ";
110
111 //
112 // At the moment, we don't have a database, yet,
113 // so we get it from the configuration file
114 //
115 SetConversionHiLo();
116 SetConversionHiLoErr();
117
118 SetPheFFactorMethodLimit();
119 SetConvFFactorRelErrLimit();
120
121 Clear();
122}
123
124// ------------------------------------------------------------------------
125//
126// Sets:
127// - all flags to kFALSE
128// - all variables to -1.
129//
130// Calls:
131// - MCalibrationPix::Clear()
132//
133void MCalibrationChargePix::Clear(Option_t *o)
134{
135
136 SetFFactorMethodValid ( kFALSE );
137
138 fRSigmaSquare = -1.;
139 fRSigmaSquareVar = -1.;
140
141 fPed = -1.;
142 fPedRms = -1.;
143 fPedVar = -1.;
144
145 fLoGainPedRmsSquare = -1.;
146 fLoGainPedRmsSquareVar = -1.;
147
148 fAbsTimeMean = -1.;
149 fAbsTimeRms = -1.;
150
151 fPheFFactorMethod = -1.;
152 fPheFFactorMethodVar = -1.;
153
154 fMeanConvFADC2Phe = -1.;
155 fMeanConvFADC2PheVar = -1.;
156 fMeanFFactorFADC2Phot = -1.;
157 fMeanFFactorFADC2PhotVar = -1.;
158
159 MCalibrationPix::Clear();
160}
161
162
163// --------------------------------------------------------------------------
164//
165// Set F-Factor Method Validity Bit from outside
166//
167void MCalibrationChargePix::SetFFactorMethodValid(const Bool_t b )
168{
169 b ? SETBIT(fCalibFlags, kFFactorMethodValid) : CLRBIT(fCalibFlags, kFFactorMethodValid);
170}
171
172// --------------------------------------------------------------------------
173//
174// Set pedestals from outside (done by MCalibrationChargeCalc)
175//
176void MCalibrationChargePix::SetPedestal(const Float_t ped, const Float_t pedrms, const Float_t pederr)
177{
178
179 fPed = ped;
180 fPedRms = pedrms;
181 fPedVar = pederr*pederr;
182}
183
184// -------------------------------------------------------------------------------
185//
186// Get the conversion Error Hi-Gain to Low-Gain:
187// - If fConversionHiLoVar is smaller than 0 (i.e. has not yet been set), return -1.
188//
189Float_t MCalibrationChargePix::GetConversionHiLoErr() const
190{
191 if (fConversionHiLoVar < 0.)
192 return -1.;
193
194 return TMath::Sqrt(fConversionHiLoVar);
195}
196
197// --------------------------------------------------------------------------
198//
199// Get the relative variance of the conversion factor between higain and logain:
200// - If fConversionHiLo is 0, return -1.
201// - If fConversionHiLoVar is smaller than 0, return -1.
202// - Else returns: fConversionHiLoVar / fConversionHiLo^2
203//
204const Float_t MCalibrationChargePix::GetConversionHiLoRelVar() const
205{
206
207 if (fConversionHiLoVar < 0.)
208 return -1.;
209
210 if (fConversionHiLo == 0.)
211 return -1.;
212
213 return fConversionHiLoVar / (fConversionHiLo * fConversionHiLo);
214}
215
216
217// --------------------------------------------------------------------------
218//
219// Get the relative variance of the conversion factor between higain and logain:
220// - If gkFFactor is 0, return -1.
221// - If gkFFactorErr is smaller than 0, return -1.
222// - Else returns: gkFFactorErr^2 / gkFFactor*^2
223//
224const Float_t MCalibrationChargePix::GetFFactorRelVar() const
225{
226
227 if (gkFFactorErr < 0.)
228 return -1.;
229
230 if (gkFFactor == 0.)
231 return -1.;
232
233 return gkFFactorErr * gkFFactorErr / (gkFFactor * gkFFactor);
234}
235
236
237//
238// Get the Error of the Mean pedestals:
239// Returns square root of fPedVar
240//
241Float_t MCalibrationChargePix::GetPedErr() const
242{
243 return TMath::Sqrt(fPedVar);
244}
245
246// --------------------------------------------------------------------------
247//
248// Get the pedestals RMS:
249// - Test bit kHiGainSaturation:
250// If yes, return square root of fLoGainPedRmsSquare (if greater than 0, otherwise -1.),
251// If no, return fPedRms
252//
253Float_t MCalibrationChargePix::GetPedRms() const
254{
255
256 if (IsHiGainSaturation())
257 if (fLoGainPedRmsSquare < 0.)
258 return -1.;
259 else
260 return TMath::Sqrt(fLoGainPedRmsSquare);
261
262 return fPedRms;
263}
264
265// --------------------------------------------------------------------------
266//
267// Get the Error of the pedestals RMS:
268// - Test bit kHiGainSaturation:
269// If yes, return square root of (0.25*fLoGainPedRmsSquareVar/ fLoGainPedRmsSquare) (if greater than 0, otherwise -1.)
270// If no , return square root of (fPedVar) (if greater than 0, otherwise -1.), divided by 2.
271//
272Float_t MCalibrationChargePix::GetPedRmsErr() const
273{
274 if (IsHiGainSaturation())
275 if (fLoGainPedRmsSquareVar < 0.)
276 return -1.;
277 else
278 return TMath::Sqrt(0.25*fLoGainPedRmsSquareVar/fLoGainPedRmsSquare);
279 else
280 if (fPedVar < 0.)
281 return -1.;
282 else
283 return TMath::Sqrt(fPedVar)/2.;
284}
285
286
287// --------------------------------------------------------------------------
288//
289// Get the Low Gain Mean converted to High Gain amplification:
290// Returns fLoGainMean multiplied with fConversionHiLo
291//
292Float_t MCalibrationChargePix::GetConvertedLoGainMean() const
293{
294 return fLoGainMean * fConversionHiLo;
295}
296
297// --------------------------------------------------------------------------
298//
299// Get the Error of the converted Low Gain Mean:
300//
301// Returns -1 if the variable fLoGainMean or fLoGainMeanVar are smaller than 0.
302//
303// Returns the square root of the quadratic sum of the relative variances of
304// the fLoGainMean and fConversionHiLo, mulitplied with GetConvertedLoGainMean()
305//
306Float_t MCalibrationChargePix::GetConvertedLoGainMeanErr() const
307{
308
309 const Float_t logainrelvar = GetLoGainMeanRelVar();
310
311 if (logainrelvar < 0.)
312 return -1.;
313
314 return TMath::Sqrt(logainrelvar + GetConversionHiLoRelVar()) * GetConvertedLoGainMean();
315}
316
317// --------------------------------------------------------------------------
318//
319// Get the Low Gain Sigma converted to High Gain amplification:
320// Returns fLoGainSigma multiplied with fConversionHiLo
321//
322Float_t MCalibrationChargePix::GetConvertedLoGainSigma() const
323{
324 return fLoGainSigma * fConversionHiLo;
325}
326
327// --------------------------------------------------------------------------
328//
329// Get the Error of the converted Low Gain Sigma:
330//
331// Returns -1 if the variable fLoGainSigma or fLoGainSigmaVar are smaller than 0.
332//
333// Returns the square root of the quadratic sum of the relative variances of
334// the fLoGainSigma and fConversionHiLo, mulitplied with GetConvertedLoGainSigma()
335//
336Float_t MCalibrationChargePix::GetConvertedLoGainSigmaErr() const
337{
338
339 if (fLoGainSigmaVar < 0.)
340 return -1.;
341
342 if (fLoGainSigma < 0.)
343 return -1.;
344
345 const Float_t sigmaRelVar = fLoGainSigmaVar
346 /( fLoGainSigma * fLoGainSigma );
347
348 return TMath::Sqrt(sigmaRelVar+GetConversionHiLoRelVar()) * GetConvertedLoGainSigma();
349}
350
351
352
353// --------------------------------------------------------------------------
354//
355// Get the reduced Sigma:
356// - If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
357// - Test bit kHiGainSaturation:
358// If yes, return square root of fRSigmaSquare, multiplied with fConversionHiLo,
359// If no , return square root of fRSigmaSquare
360//
361Float_t MCalibrationChargePix::GetRSigma() const
362{
363 if (fRSigmaSquare < 0)
364 return -1;
365
366 const Float_t rsigma = TMath::Sqrt(fRSigmaSquare);
367
368 return IsHiGainSaturation() ? rsigma*fConversionHiLo : rsigma ;
369}
370
371// --------------------------------------------------------------------------
372//
373// Get the error of the reduced Sigma:
374// - If fRSigmaSquareVar is smaller than 0 (i.e. has not yet been set), return -1.
375// - Calculate the absolute variance of the reduced sigma with the formula:
376// reduced sigma variance = 0.25 * fRSigmaSquareVar / fRSigmaSquare
377// - Test bit kHiGainSaturation:
378// If yes, returns the square root of the quadratic sum of the relative variances of the
379// reduced sigma and fConversionHiLo, mulitplied with GetRSigma()
380// Else returns the square root of rel. (0.25*fRSigmaSquareVar / fRSigmaSquare)
381//
382Float_t MCalibrationChargePix::GetRSigmaErr() const
383{
384
385 if (fRSigmaSquareVar < 0)
386 return -1;
387
388 //
389 // SigmaSquareVar = 4. * Sigma * Sigma * Var(sigma)
390 // ==> Var(sigma) = 0.25 * SigmaSquareVar / (Sigma * Sigma)
391 //
392 const Float_t rsigmaVar = 0.25 * fRSigmaSquareVar / fRSigmaSquare;
393
394 if (IsHiGainSaturation())
395 return TMath::Sqrt(rsigmaVar/fRSigmaSquare + GetConversionHiLoRelVar()) * GetRSigma();
396 else
397 return TMath::Sqrt(rsigmaVar);
398
399}
400
401// --------------------------------------------------------------------------
402//
403// Get the reduced Sigma per Charge:
404// - If GetRSigma() is smaller or equal 0. (i.e. has not yet been set), return -1.
405// - If GetMean() is 0. or -1. (i.e. has not yet been set), return -1.
406// - Return GetRSigma() / GetMean()
407//
408Float_t MCalibrationChargePix::GetRSigmaPerCharge() const
409{
410
411 const Float_t rsigma = GetRSigma();
412
413 if (rsigma <= 0)
414 return -1.;
415
416
417 const Float_t mean = GetMean();
418
419 if (mean == 0. || mean == -1.)
420 return -1.;
421
422 return rsigma / mean;
423}
424
425
426// --------------------------------------------------------------------------
427//
428// Get the error of the reduced Sigma per Charge:
429// - If GetRSigmaRelVar() is smaller or equal 0. (i.e. has not yet been set), return -1.
430// - If GetMeanRelVar() is smaller or equal 0. (i.e. has not yet been set), return -1.
431// - Return the propagated error of GetRSigmaPerCharge()
432//
433Float_t MCalibrationChargePix::GetRSigmaPerChargeErr() const
434{
435
436 const Float_t rsigmarelvar = GetRSigmaRelVar();
437
438 if (rsigmarelvar <= 0)
439 return -1.;
440
441
442 const Float_t meanrelvar = GetMeanRelVar();
443
444 if (meanrelvar <= 0.)
445 return -1.;
446
447 return TMath::Sqrt(rsigmarelvar + meanrelvar) * GetRSigmaPerCharge();
448}
449
450// --------------------------------------------------------------------------
451//
452// Get the reduced Sigma Square:
453// - If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
454// - Test bit kHiGainSaturation:
455// If yes, return fRSigmaSquare, multiplied with fConversionHiLo^2,
456// If no , return fRSigmaSquare
457//
458Float_t MCalibrationChargePix::GetRSigmaSquare() const
459{
460 if (fRSigmaSquare < 0)
461 return -1;
462
463 return IsHiGainSaturation() ? fRSigmaSquare*fConversionHiLo*fConversionHiLo : fRSigmaSquare ;
464}
465
466// --------------------------------------------------------------------------
467//
468// Get the relative variance of the reduced Sigma:
469// - If fRSigmaSquareVar is smaller than 0 (i.e. has not yet been set), return -1.
470// - Calculate the relative variance of the reduced sigma squares with the formula:
471// reduced sigma rel. variance = 0.25 * fRSigmaSquareVar / fRSigmaSquare / fRSigmaSquare
472// - Test bit kHiGainSaturation:
473// If yes, returns the sum of the relative variances of the reduced sigma and fConversionHiLo
474// Else returns the relative variance of the reduced sigma
475//
476Float_t MCalibrationChargePix::GetRSigmaRelVar() const
477{
478
479 if (fRSigmaSquareVar < 0)
480 return -1;
481
482 //
483 // SigmaSquareVar = 4. * Sigma * Sigma * Var(sigma)
484 // ==> Var(sigma) = 0.25 * SigmaSquareVar / (Sigma * Sigma)
485 //
486 const Float_t rsigmaRelVar = 0.25 * fRSigmaSquareVar / ( fRSigmaSquare * fRSigmaSquare );
487
488 if (IsHiGainSaturation())
489 return rsigmaRelVar + GetConversionHiLoRelVar();
490 else
491 return rsigmaRelVar;
492}
493
494// --------------------------------------------------------------------------
495//
496// Get the error on the number of photo-electrons (F-Factor Method):
497// - If fPheFFactorMethodVar is smaller than 0 (i.e. has not yet been set), return -1.
498// - Else returns the square root of fPheFFactorMethodVar
499//
500Float_t MCalibrationChargePix::GetPheFFactorMethodErr() const
501{
502 if (fPheFFactorMethodVar < 0.)
503 return -1.;
504 return TMath::Sqrt(fPheFFactorMethodVar);
505}
506
507// --------------------------------------------------------------------------
508//
509// Get the error on the mean total F-Factor of the signal readout (F-Factor Method):
510// - If fMeanFFactorFADC2PhotVar is smaller than 0 (i.e. has not yet been set), return -1.
511// - Else returns the square root of fMeanFFactorFADC2PhotVar
512//
513Float_t MCalibrationChargePix::GetMeanFFactorFADC2PhotErr() const
514{
515 if (fMeanFFactorFADC2PhotVar < 0.)
516 return -1.;
517 return TMath::Sqrt(fMeanFFactorFADC2PhotVar);
518}
519
520// --------------------------------------------------------------------------
521//
522// Get the relative variance on the number of photo-electrons (F-Factor Method):
523// - If fPheFFactorMethodVar is smaller than 0 (i.e. has not yet been set), return -1.
524// - If fPheFFactorMethod is 0, return -1.
525// - Else returns fPheFFactorMethodVar / fPheFFactorMethod^2
526//
527Float_t MCalibrationChargePix::GetPheFFactorMethodRelVar() const
528{
529 if (fPheFFactorMethodVar < 0.)
530 return -1.;
531 if (fPheFFactorMethod == 0.)
532 return -1.;
533
534 return fPheFFactorMethodVar / (fPheFFactorMethod * fPheFFactorMethod);
535}
536
537
538// --------------------------------------------------------------------------
539//
540// Get the error on the mean conversion factor (FFactor  Method):
541// - If fMeanConvFADC2PheVar is smaller than 0 (i.e. has not yet been set), return -1.
542// - Else returns the square root of fMeanConvFADC2PheVar
543//
544Float_t MCalibrationChargePix::GetMeanConvFADC2PheErr() const
545{
546 if (fMeanConvFADC2PheVar < 0.)
547 return -1.;
548 return TMath::Sqrt(fMeanConvFADC2PheVar);
549}
550
551// --------------------------------------------------------------------------
552//
553// Test bit kFFactorMethodValid
554//
555Bool_t MCalibrationChargePix::IsFFactorMethodValid() const
556{
557 return TESTBIT(fCalibFlags, kFFactorMethodValid);
558}
559
560
561// ----------------------------------------------------------------------------
562//
563// - If fSigma is smaller than 0 (i.e. has not yet been set), return kFALSE
564// - If fPedRms is smaller than 0 (i.e. has not yet been set), return kFALSE
565//
566// Calculate the reduced sigma of the low-Gain FADC slices:
567// - Test bit IsHiGainSaturation() for the Sigma:
568// If yes, take fLoGainSigma and fLoGainSigmaVar
569// If no , take fHiGainSigma and fHiGainSigmaVar
570//
571// - Test bit IsHiGainSaturation() for the pedRMS:
572// If yes, take fLoGainPedRmsSquare and fLoGainPedRmsSquareVar
573// If no , take fPedRms and fPedVar
574//
575// - Calculate the reduced sigma with the formula:
576// fRSigmaSquare = Sigma*Sigma - pedRMS*pedRMS
577//
578// - If fRSigmaSquare is smaller than 0, give a warning and return kFALSE
579//
580// - Calculate the variance of the reduced sigma with the formula:
581// fRSigmaSquareVar = 4.* (sigmaVar*Sigma*Sigma + pedRmsVar*pedRMS*pedRMS)
582//
583// A back-transformation to the corr. amplification factor of the High-Gain is done
584// in GetRSigma() and GetRSigmaErr()
585//
586Bool_t MCalibrationChargePix::CalcReducedSigma()
587{
588
589 if (GetSigma() < 0.)
590 return kFALSE;
591
592 if (GetPedRms() < 0.)
593 return kFALSE;
594
595 const Float_t sigma = IsHiGainSaturation() ? fLoGainSigma : fHiGainSigma ;
596 const Float_t sigmavar = IsHiGainSaturation() ? fLoGainSigmaVar : fHiGainSigmaVar;
597 const Float_t pedRmsSquare = IsHiGainSaturation() ? fLoGainPedRmsSquare : fPedRms*fPedRms;
598 const Float_t pedRmsSquareVar = IsHiGainSaturation() ? fLoGainPedRmsSquareVar : 0.25*fPedVar*pedRmsSquare;
599
600 const Float_t sigmaSquare = sigma * sigma;
601 const Float_t sigmaSquareVar = 4. * sigmavar * sigmaSquare;
602
603 //
604 // Calculate the reduced sigmas
605 //
606 fRSigmaSquare = sigmaSquare - pedRmsSquare;
607 if (fRSigmaSquare <= 0.)
608 {
609 *fLog << warn
610 << "WARNING: Cannot calculate the reduced sigma: smaller than 0 in pixel "
611 << fPixId << endl;
612 return kFALSE;
613 }
614
615 fRSigmaSquareVar = 4. * (sigmaSquareVar + pedRmsSquareVar);
616
617 return kTRUE;
618}
619
620// ------------------------------------------------------------------
621//
622// If fRSigmaSquare is smaller than 0 (i.e. has not yet been set),
623// set kFFactorMethodValid to kFALSE and return kFALSE
624//
625// Calculate the number of photo-electrons with the F-Factor method:
626// - Test bit IsHiGainSaturation() for the Mean Sum of FADC slices:
627// If yes, take fLoGainMean and fLoGainMeanVar
628// If no , take fHiGainMean and fHiGainMeanVar
629//
630// - Test bit IsHiGainSaturation() for the pedRMS:
631// If yes, take fLoGainPedRmsSquare and fLoGainPedRmsSquareVar
632// If no , take fPedRms and fPedVar
633//
634// - Calculate the number of photo-electrons with the formula:
635// fPheFFactorMethod = gkFFactor*gkFFactor * Mean * Mean / fRSigmaSquare
636//
637// - Calculate the Variance on the photo-electrons with the formula:
638// fPheFFactorMethodVar = ( 4. * gkFFactorErr * gkFFactorErr / ( gkFFactor * gkFFactor )
639// + 4. * Mean Var. / ( Mean * Mean )
640// + fRSigmaSquareVar / fRSigmaSquare
641// ) * fPheFFactorMethod * fPheFFactorMethod
642//
643// - If fPheFFactorMethod is less than fPheFFactorMethodLimit,
644// set kFFactorMethodValid to kFALSE and return kFALSE
645// else: Set kFFactorMethodValid to kTRUE and return kTRUE
646//
647Bool_t MCalibrationChargePix::CalcFFactorMethod()
648{
649
650 if (fRSigmaSquare < 0.)
651 return kFALSE;
652
653 //
654 // Square all variables in order to avoid applications of square root
655 //
656 const Float_t meanSquare = GetMean() * GetMean();
657 const Float_t meanSquareRelVar = 4.* GetMeanRelVar();
658
659 const Float_t ffactorsquare = gkFFactor * gkFFactor;
660 const Float_t ffactorsquareRelVar = 4.* GetFFactorRelVar();
661
662 const Float_t rsigmaSquareRelVar = fRSigmaSquareVar / fRSigmaSquare / fRSigmaSquare;
663 //
664 // Calculate the number of phe's from the F-Factor method
665 // (independent on Hi Gain or Lo Gain)
666 //
667 fPheFFactorMethod = ffactorsquare * meanSquare / fRSigmaSquare;
668
669 if (fPheFFactorMethod < fPheFFactorMethodLimit)
670 return kFALSE;
671
672 //
673 // Calculate the Error of Nphe
674 //
675 const Float_t pheRelVar = ffactorsquareRelVar + meanSquareRelVar + rsigmaSquareRelVar;
676 fPheFFactorMethodVar = pheRelVar * fPheFFactorMethod * fPheFFactorMethod;
677
678 if (fPheFFactorMethodVar < 0. )
679 return kFALSE;
680
681 fMeanConvFADC2Phe = fPheFFactorMethod / GetMean();
682
683 if (fMeanConvFADC2Phe < 0. )
684 return kFALSE;
685
686 //
687 // In the calculation of the number of phe's one mean square has already been used.
688 // Now, we divide by another mean, so one mean calcels out, we cannot directly propagate
689 // the errors, but have to take account of this cancellation:
690 //
691 const Float_t convrelvar = ffactorsquareRelVar + GetMeanRelVar() + rsigmaSquareRelVar;
692
693 if (convrelvar > fConvFFactorRelVarLimit || convrelvar < 0.)
694 {
695 *fLog << warn << GetDescriptor() << ": Conversion F-Factor Method Rel. Variance: "
696 << convrelvar << " above limits of: [0," << Form("%3.2f",fConvFFactorRelVarLimit)
697 << "] in pixel: " << fPixId << endl;
698 return kFALSE;
699 }
700
701 fMeanConvFADC2PheVar = convrelvar * fMeanConvFADC2Phe * fMeanConvFADC2Phe;
702
703 SetFFactorMethodValid(kTRUE);
704 return kTRUE;
705}
706
707// ----------------------------------------------------------------------------------
708//
709// If photflux is smaller or equal 0, return kFALSE
710//
711// Calculate the total F-Factor with the formula:
712// fMeanFFactorFADC2Phot = Sqrt ( fRSigmaSquare ) / GetMean() * sqrt(nphotons)
713//
714// Calculate the error of the total F-Factor
715//
716Bool_t MCalibrationChargePix::CalcMeanFFactor( const Float_t nphotons, const Float_t nphotonsrelvar )
717{
718
719 if (nphotons <= 0.)
720 {
721 *fLog << warn << GetDescriptor() << ": Assumed photon flux is smaller or equal 0." << endl;
722 return kFALSE;
723 }
724
725 if (nphotonsrelvar < 0.)
726 {
727 *fLog << warn << GetDescriptor() << ": Assumed photon flux variance is smaller than 0." << endl;
728 return kFALSE;
729 }
730
731 fMeanFFactorFADC2Phot = TMath::Sqrt(fRSigmaSquare * nphotons) / GetMean() ;
732
733 if (fMeanFFactorFADC2Phot < 0.)
734 {
735 *fLog << warn << GetDescriptor() << ": F-Factor photons to FADC counts smaller than 0." << endl;
736 return kFALSE;
737 }
738
739 const Float_t ffactorrelvar = 0.25 * fRSigmaSquareVar / ( fRSigmaSquare * fRSigmaSquare)
740 + GetMeanRelVar()
741 + 0.25 * nphotonsrelvar;
742
743 fMeanFFactorFADC2PhotVar = ffactorrelvar * fMeanFFactorFADC2Phot * fMeanFFactorFADC2Phot;
744
745 return kTRUE;
746}
747
748
749// ----------------------------------------------------------------------------
750//
751// - If fPed is smaller than 0 (i.e. has not yet been set), return.
752// - If fPedVar is smaller than 0 (i.e. has not yet been set), return.
753//
754// Calculate the electronic pedestal RMS with the formula:
755// - elec. pedestal = gkElectronicPedRms * sqrt(logainsamples)
756//
757// Calculate the night sky background ped. RMS contribution ("NSB") in the high-gain
758// from the high gain Pedestal RMS with the formula:
759// - HiGain NSB square = fPedRms * fPedRms - elec.ped.* elec.ped.
760// - Var(HiGain NSB square) = fPedVar * fPedRms * fPedRms + 4.*elecPedRmsVar * elec.ped.* elec.ped.
761//
762// If HiGain NSB square is smaller than 0., set it to zero. (but not the error!)
763//
764// Convert the NSB ped. RMS contribution to the low-gain with the formula:
765// - LoGain NSB square = - HiGain NSB square / (fConversionHiLo*fConversionHiLo)
766// - Var(LoGain NSB square) = ( Var(HiGain NSB square) / (HiGain NSB square * HiGain NSB square)
767// + GetConversionHiLoRelVar()
768// ) * LoGain NSB square * LoGain NSB square
769//
770// - Low Gain Ped RMS Square = LoGain NSB square + elec.ped. square
771// Var (Low Gain Ped RMS Square) = Var(LoGain NSB square) + Var(elec.ped. square)
772//
773void MCalibrationChargePix::CalcLoGainPedestal(Float_t logainsamples)
774{
775
776 if (fPedRms < 0.)
777 return;
778
779 if (fPedVar < 0.)
780 return;
781
782 const Float_t elecPedRms = gkElectronicPedRms * TMath::Sqrt(logainsamples);
783 const Float_t elecPedRmsVar = gkElectronicPedRmsErr * gkElectronicPedRmsErr * logainsamples;
784
785 Float_t pedRmsSquare = fPedRms * fPedRms;
786 Float_t pedRmsSquareVar = fPedVar * pedRmsSquare; // fPedRmsErr = fPedErr/2.
787
788 //
789 // We do not know the Lo Gain Pedestal RMS, so we have to retrieve it
790 // from the HI GAIN (all calculation per slice up to now):
791 //
792 // We extract the pure NSB contribution:
793 //
794 const Float_t elecRmsSquare = elecPedRms * elecPedRms;
795 const Float_t elecRmsSquareVar = 4.*elecPedRmsVar * elecRmsSquare;
796
797 Float_t higainNsbSquare = pedRmsSquare - elecRmsSquare;
798 Float_t higainNsbSquareRelVar = (pedRmsSquareVar + elecRmsSquareVar)
799 / (higainNsbSquare * higainNsbSquare) ;
800
801 if (higainNsbSquare < 0.)
802 higainNsbSquare = 0.;
803
804 //
805 // Now, we divide the NSB by the conversion factor and
806 // add it quadratically to the electronic noise
807 //
808 const Float_t conversionSquare = fConversionHiLo * fConversionHiLo;
809 const Float_t conversionSquareRelVar = 4.* GetConversionHiLoRelVar();
810
811 const Float_t logainNsbSquare = higainNsbSquare / conversionSquare;
812 const Float_t logainNsbSquareVar = ( higainNsbSquareRelVar + conversionSquareRelVar )
813 * logainNsbSquare * logainNsbSquare;
814
815 fLoGainPedRmsSquare = logainNsbSquare + elecRmsSquare;
816 fLoGainPedRmsSquareVar = logainNsbSquareVar + elecRmsSquareVar;
817}
818
Note: See TracBrowser for help on using the repository browser.