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