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

Last change on this file since 3712 was 3712, checked in by gaug, 22 years ago
*** empty log message ***
File size: 26.0 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 Square:
404// - If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
405// - Test bit kHiGainSaturation:
406// If yes, return fRSigmaSquare, multiplied with fConversionHiLo^2,
407// If no , return fRSigmaSquare
408//
409Float_t MCalibrationChargePix::GetRSigmaSquare() const
410{
411 if (fRSigmaSquare < 0)
412 return -1;
413
414 return IsHiGainSaturation() ? fRSigmaSquare*fConversionHiLo*fConversionHiLo : fRSigmaSquare ;
415}
416
417// --------------------------------------------------------------------------
418//
419// Get the relative variance of the reduced Sigma:
420// - If fRSigmaSquareVar is smaller than 0 (i.e. has not yet been set), return -1.
421// - Calculate the relative variance of the reduced sigma squares with the formula:
422// reduced sigma rel. variance = 0.25 * fRSigmaSquareVar / fRSigmaSquare / fRSigmaSquare
423// - Test bit kHiGainSaturation:
424// If yes, returns the sum of the relative variances of the reduced sigma and fConversionHiLo
425// Else returns the relative variance of the reduced sigma
426//
427Float_t MCalibrationChargePix::GetRSigmaRelVar() const
428{
429
430 if (fRSigmaSquareVar < 0)
431 return -1;
432
433 //
434 // SigmaSquareVar = 4. * Sigma * Sigma * Var(sigma)
435 // ==> Var(sigma) = 0.25 * SigmaSquareVar / (Sigma * Sigma)
436 //
437 const Float_t rsigmaRelVar = 0.25 * fRSigmaSquareVar / ( fRSigmaSquare * fRSigmaSquare );
438
439 if (IsHiGainSaturation())
440 return rsigmaRelVar + GetConversionHiLoRelVar();
441 else
442 return rsigmaRelVar;
443}
444
445// --------------------------------------------------------------------------
446//
447// Get the error on the number of photo-electrons (F-Factor Method):
448// - If fPheFFactorMethodVar is smaller than 0 (i.e. has not yet been set), return -1.
449// - Else returns the square root of fPheFFactorMethodVar
450//
451Float_t MCalibrationChargePix::GetPheFFactorMethodErr() const
452{
453 if (fPheFFactorMethodVar < 0.)
454 return -1.;
455 return TMath::Sqrt(fPheFFactorMethodVar);
456}
457
458// --------------------------------------------------------------------------
459//
460// Get the error on the mean total F-Factor of the signal readout (F-Factor Method):
461// - If fMeanFFactorFADC2PhotVar is smaller than 0 (i.e. has not yet been set), return -1.
462// - Else returns the square root of fMeanFFactorFADC2PhotVar
463//
464Float_t MCalibrationChargePix::GetMeanFFactorFADC2PhotErr() const
465{
466 if (fMeanFFactorFADC2PhotVar < 0.)
467 return -1.;
468 return TMath::Sqrt(fMeanFFactorFADC2PhotVar);
469}
470
471// --------------------------------------------------------------------------
472//
473// Get the relative variance on the number of photo-electrons (F-Factor Method):
474// - If fPheFFactorMethodVar is smaller than 0 (i.e. has not yet been set), return -1.
475// - If fPheFFactorMethod is 0, return -1.
476// - Else returns fPheFFactorMethodVar / fPheFFactorMethod^2
477//
478Float_t MCalibrationChargePix::GetPheFFactorMethodRelVar() const
479{
480 if (fPheFFactorMethodVar < 0.)
481 return -1.;
482 if (fPheFFactorMethod == 0.)
483 return -1.;
484
485 return fPheFFactorMethodVar / (fPheFFactorMethod * fPheFFactorMethod);
486}
487
488
489// --------------------------------------------------------------------------
490//
491// Get the error on the mean conversion factor (FFactor  Method):
492// - If fMeanConvFADC2PheVar is smaller than 0 (i.e. has not yet been set), return -1.
493// - Else returns the square root of fMeanConvFADC2PheVar
494//
495Float_t MCalibrationChargePix::GetMeanConvFADC2PheErr() const
496{
497 if (fMeanConvFADC2PheVar < 0.)
498 return -1.;
499 return TMath::Sqrt(fMeanConvFADC2PheVar);
500}
501
502// --------------------------------------------------------------------------
503//
504// Test bit kFFactorMethodValid
505//
506Bool_t MCalibrationChargePix::IsFFactorMethodValid() const
507{
508 return TESTBIT(fCalibFlags, kFFactorMethodValid);
509}
510
511
512// ----------------------------------------------------------------------------
513//
514// - If fSigma is smaller than 0 (i.e. has not yet been set), return kFALSE
515// - If fPedRms is smaller than 0 (i.e. has not yet been set), return kFALSE
516//
517// Calculate the reduced sigma of the low-Gain FADC slices:
518// - Test bit IsHiGainSaturation() for the Sigma:
519// If yes, take fLoGainSigma and fLoGainSigmaVar
520// If no , take fHiGainSigma and fHiGainSigmaVar
521//
522// - Test bit IsHiGainSaturation() for the pedRMS:
523// If yes, take fLoGainPedRmsSquare and fLoGainPedRmsSquareVar
524// If no , take fPedRms and fPedVar
525//
526// - Calculate the reduced sigma with the formula:
527// fRSigmaSquare = Sigma*Sigma - pedRMS*pedRMS
528//
529// - If fRSigmaSquare is smaller than 0, give a warning and return kFALSE
530//
531// - Calculate the variance of the reduced sigma with the formula:
532// fRSigmaSquareVar = 4.* (sigmaVar*Sigma*Sigma + pedRmsVar*pedRMS*pedRMS)
533//
534// A back-transformation to the corr. amplification factor of the High-Gain is done
535// in GetRSigma() and GetRSigmaErr()
536//
537Bool_t MCalibrationChargePix::CalcReducedSigma()
538{
539
540 if (GetSigma() < 0.)
541 return kFALSE;
542
543 if (GetPedRms() < 0.)
544 return kFALSE;
545
546 const Float_t sigma = IsHiGainSaturation() ? fLoGainSigma : fHiGainSigma ;
547 const Float_t sigmavar = IsHiGainSaturation() ? fLoGainSigmaVar : fHiGainSigmaVar;
548 const Float_t pedRmsSquare = IsHiGainSaturation() ? fLoGainPedRmsSquare : fPedRms*fPedRms;
549 const Float_t pedRmsSquareVar = IsHiGainSaturation() ? fLoGainPedRmsSquareVar : 0.25*fPedVar*pedRmsSquare;
550
551 const Float_t sigmaSquare = sigma * sigma;
552 const Float_t sigmaSquareVar = 4. * sigmavar * sigmaSquare;
553
554 //
555 // Calculate the reduced sigmas
556 //
557 fRSigmaSquare = sigmaSquare - pedRmsSquare;
558 if (fRSigmaSquare <= 0.)
559 {
560 *fLog << warn
561 << "WARNING: Cannot calculate the reduced sigma: smaller than 0 in pixel "
562 << fPixId << endl;
563 return kFALSE;
564 }
565
566 fRSigmaSquareVar = 4. * (sigmaSquareVar + pedRmsSquareVar);
567
568 return kTRUE;
569}
570
571// ------------------------------------------------------------------
572//
573// If fRSigmaSquare is smaller than 0 (i.e. has not yet been set),
574// set kFFactorMethodValid to kFALSE and return kFALSE
575//
576// Calculate the number of photo-electrons with the F-Factor method:
577// - Test bit IsHiGainSaturation() for the Mean Sum of FADC slices:
578// If yes, take fLoGainMean and fLoGainMeanVar
579// If no , take fHiGainMean and fHiGainMeanVar
580//
581// - Test bit IsHiGainSaturation() for the pedRMS:
582// If yes, take fLoGainPedRmsSquare and fLoGainPedRmsSquareVar
583// If no , take fPedRms and fPedVar
584//
585// - Calculate the number of photo-electrons with the formula:
586// fPheFFactorMethod = gkFFactor*gkFFactor * Mean * Mean / fRSigmaSquare
587//
588// - Calculate the Variance on the photo-electrons with the formula:
589// fPheFFactorMethodVar = ( 4. * gkFFactorErr * gkFFactorErr / ( gkFFactor * gkFFactor )
590// + 4. * Mean Var. / ( Mean * Mean )
591// + fRSigmaSquareVar / fRSigmaSquare
592// ) * fPheFFactorMethod * fPheFFactorMethod
593//
594// - If fPheFFactorMethod is less than fPheFFactorMethodLimit,
595// set kFFactorMethodValid to kFALSE and return kFALSE
596// else: Set kFFactorMethodValid to kTRUE and return kTRUE
597//
598Bool_t MCalibrationChargePix::CalcFFactorMethod()
599{
600
601 if (fRSigmaSquare < 0.)
602 return kFALSE;
603
604 //
605 // Square all variables in order to avoid applications of square root
606 //
607 const Float_t meanSquare = GetMean() * GetMean();
608 const Float_t meanSquareRelVar = 4.* GetMeanRelVar();
609
610 const Float_t ffactorsquare = gkFFactor * gkFFactor;
611 const Float_t ffactorsquareRelVar = 4.* GetFFactorRelVar();
612
613 const Float_t rsigmaSquareRelVar = fRSigmaSquareVar / fRSigmaSquare / fRSigmaSquare;
614 //
615 // Calculate the number of phe's from the F-Factor method
616 // (independent on Hi Gain or Lo Gain)
617 //
618 fPheFFactorMethod = ffactorsquare * meanSquare / fRSigmaSquare;
619
620 if (fPheFFactorMethod < fPheFFactorMethodLimit)
621 return kFALSE;
622
623 //
624 // Calculate the Error of Nphe
625 //
626 const Float_t pheRelVar = ffactorsquareRelVar + meanSquareRelVar + rsigmaSquareRelVar;
627 fPheFFactorMethodVar = pheRelVar * fPheFFactorMethod * fPheFFactorMethod;
628
629 if (fPheFFactorMethodVar < 0. )
630 return kFALSE;
631
632 fMeanConvFADC2Phe = fPheFFactorMethod / GetMean();
633
634 if (fMeanConvFADC2Phe < 0. )
635 return kFALSE;
636
637 //
638 // In the calculation of the number of phe's one mean square has already been used.
639 // Now, we divide by another mean, so one mean calcels out, we cannot directly propagate
640 // the errors, but have to take account of this cancellation:
641 //
642 const Float_t convrelvar = ffactorsquareRelVar + GetMeanRelVar() + rsigmaSquareRelVar;
643
644 if (convrelvar > fConvFFactorRelVarLimit || convrelvar < 0.)
645 {
646 *fLog << warn << GetDescriptor() << ": Conversion F-Factor Method Rel. Variance: "
647 << convrelvar << " above limits of: [0," << Form("%3.2f",fConvFFactorRelVarLimit)
648 << "] in pixel: " << fPixId << endl;
649 return kFALSE;
650 }
651
652 fMeanConvFADC2PheVar = convrelvar * fMeanConvFADC2Phe * fMeanConvFADC2Phe;
653
654 SetFFactorMethodValid(kTRUE);
655 return kTRUE;
656}
657
658// ----------------------------------------------------------------------------------
659//
660// If photflux is smaller or equal 0, return kFALSE
661//
662// Calculate the total F-Factor with the formula:
663// fMeanFFactorFADC2Phot = Sqrt ( fRSigmaSquare ) / GetMean() * sqrt(nphotons)
664//
665// Calculate the error of the total F-Factor
666//
667Bool_t MCalibrationChargePix::CalcMeanFFactor( const Float_t nphotons, const Float_t nphotonsrelvar )
668{
669
670 if (nphotons <= 0.)
671 {
672 *fLog << warn << GetDescriptor() << ": Assumed photon flux is smaller or equal 0." << endl;
673 return kFALSE;
674 }
675
676 if (nphotonsrelvar < 0.)
677 {
678 *fLog << warn << GetDescriptor() << ": Assumed photon flux variance is smaller than 0." << endl;
679 return kFALSE;
680 }
681
682 fMeanFFactorFADC2Phot = TMath::Sqrt(fRSigmaSquare * nphotons) / GetMean() ;
683
684 if (fMeanFFactorFADC2Phot < 0.)
685 {
686 *fLog << warn << GetDescriptor() << ": F-Factor photons to FADC counts smaller than 0." << endl;
687 return kFALSE;
688 }
689
690 const Float_t ffactorrelvar = 0.25 * fRSigmaSquareVar / ( fRSigmaSquare * fRSigmaSquare)
691 + GetMeanRelVar()
692 + 0.25 * nphotonsrelvar;
693
694 fMeanFFactorFADC2PhotVar = ffactorrelvar * fMeanFFactorFADC2Phot * fMeanFFactorFADC2Phot;
695
696 return kTRUE;
697}
698
699
700// ----------------------------------------------------------------------------
701//
702// - If fPed is smaller than 0 (i.e. has not yet been set), return.
703// - If fPedVar is smaller than 0 (i.e. has not yet been set), return.
704//
705// Calculate the electronic pedestal RMS with the formula:
706// - elec. pedestal = gkElectronicPedRms * sqrt(logainsamples)
707//
708// Calculate the night sky background ped. RMS contribution ("NSB") in the high-gain
709// from the high gain Pedestal RMS with the formula:
710// - HiGain NSB square = fPedRms * fPedRms - elec.ped.* elec.ped.
711// - Var(HiGain NSB square) = fPedVar * fPedRms * fPedRms + 4.*elecPedRmsVar * elec.ped.* elec.ped.
712//
713// If HiGain NSB square is smaller than 0., set it to zero. (but not the error!)
714//
715// Convert the NSB ped. RMS contribution to the low-gain with the formula:
716// - LoGain NSB square = - HiGain NSB square / (fConversionHiLo*fConversionHiLo)
717// - Var(LoGain NSB square) = ( Var(HiGain NSB square) / (HiGain NSB square * HiGain NSB square)
718// + GetConversionHiLoRelVar()
719// ) * LoGain NSB square * LoGain NSB square
720//
721// - Low Gain Ped RMS Square = LoGain NSB square + elec.ped. square
722// Var (Low Gain Ped RMS Square) = Var(LoGain NSB square) + Var(elec.ped. square)
723//
724void MCalibrationChargePix::CalcLoGainPedestal(Float_t logainsamples)
725{
726
727 if (fPedRms < 0.)
728 return;
729
730 if (fPedVar < 0.)
731 return;
732
733 const Float_t elecPedRms = gkElectronicPedRms * TMath::Sqrt(logainsamples);
734 const Float_t elecPedRmsVar = gkElectronicPedRmsErr * gkElectronicPedRmsErr * logainsamples;
735
736 Float_t pedRmsSquare = fPedRms * fPedRms;
737 Float_t pedRmsSquareVar = fPedVar * pedRmsSquare; // fPedRmsErr = fPedErr/2.
738
739 //
740 // We do not know the Lo Gain Pedestal RMS, so we have to retrieve it
741 // from the HI GAIN (all calculation per slice up to now):
742 //
743 // We extract the pure NSB contribution:
744 //
745 const Float_t elecRmsSquare = elecPedRms * elecPedRms;
746 const Float_t elecRmsSquareVar = 4.*elecPedRmsVar * elecRmsSquare;
747
748 Float_t higainNsbSquare = pedRmsSquare - elecRmsSquare;
749 Float_t higainNsbSquareRelVar = (pedRmsSquareVar + elecRmsSquareVar)
750 / (higainNsbSquare * higainNsbSquare) ;
751
752 if (higainNsbSquare < 0.)
753 higainNsbSquare = 0.;
754
755 //
756 // Now, we divide the NSB by the conversion factor and
757 // add it quadratically to the electronic noise
758 //
759 const Float_t conversionSquare = fConversionHiLo * fConversionHiLo;
760 const Float_t conversionSquareRelVar = 4.* GetConversionHiLoRelVar();
761
762 const Float_t logainNsbSquare = higainNsbSquare / conversionSquare;
763 const Float_t logainNsbSquareVar = ( higainNsbSquareRelVar + conversionSquareRelVar )
764 * logainNsbSquare * logainNsbSquare;
765
766 fLoGainPedRmsSquare = logainNsbSquare + elecRmsSquare;
767 fLoGainPedRmsSquareVar = logainNsbSquareVar + elecRmsSquareVar;
768}
769
Note: See TracBrowser for help on using the repository browser.