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 11/2003 <mailto:markus@ifae.es>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | // //
|
---|
27 | // MCalibrationPix //
|
---|
28 | // //
|
---|
29 | // This is the storage container to hold informations about the pedestal //
|
---|
30 | // (offset) value of one Pixel (PMT). //
|
---|
31 | // //
|
---|
32 | /////////////////////////////////////////////////////////////////////////////
|
---|
33 | #include "MCalibrationPix.h"
|
---|
34 | #include "MCalibrationConfig.h"
|
---|
35 |
|
---|
36 | #include "MLog.h"
|
---|
37 | #include "MLogManip.h"
|
---|
38 |
|
---|
39 | ClassImp(MCalibrationPix);
|
---|
40 |
|
---|
41 | using namespace std;
|
---|
42 |
|
---|
43 | // --------------------------------------------------------------------------
|
---|
44 | //
|
---|
45 | // Default Constructor:
|
---|
46 | //
|
---|
47 | // The following values are initialized to meaningful values:
|
---|
48 | //
|
---|
49 | // - The Electronic Rms to 1.5 per FADC slice
|
---|
50 | // - The uncertainty about the Electronic RMS to 0.3 per slice
|
---|
51 | // - The F-Factor is assumed to have been measured in Munich to 1.13 - 1.17.
|
---|
52 | // We use here the Square of the Munich definition, thus:
|
---|
53 | // Mean F-Factor = 1.15*1.15 = 1.32
|
---|
54 | // Error F-Factor = 2.*0.02 = 0.04
|
---|
55 | //
|
---|
56 | MCalibrationPix::MCalibrationPix(const char *name, const char *title)
|
---|
57 | : fPixId(-1),
|
---|
58 | fCharge(-1.),
|
---|
59 | fErrCharge(-1.),
|
---|
60 | fSigmaCharge(-1.),
|
---|
61 | fErrSigmaCharge(-1.),
|
---|
62 | fRSigmaSquare(-1.),
|
---|
63 | fChargeProb(-1.),
|
---|
64 | fPed(-1.),
|
---|
65 | fPedRms(-1.),
|
---|
66 | fErrPedRms(0.),
|
---|
67 | fElectronicPedRms(1.5),
|
---|
68 | fErrElectronicPedRms(0.3),
|
---|
69 | fTime(-1.),
|
---|
70 | fSigmaTime(-1.),
|
---|
71 | fTimeChiSquare(-1.),
|
---|
72 | fFactor(1.32),
|
---|
73 | fFactorError(0.04),
|
---|
74 | fPheFFactorMethod(-1.),
|
---|
75 | fPheFFactorMethodError(-1.),
|
---|
76 | fConversionFFactorMethod(-1.),
|
---|
77 | fConversionBlindPixelMethod(-1.),
|
---|
78 | fConversionPINDiodeMethod(-1.),
|
---|
79 | fConversionErrorFFactorMethod(-1.),
|
---|
80 | fConversionErrorBlindPixelMethod(-1.),
|
---|
81 | fConversionErrorPINDiodeMethod(-1.),
|
---|
82 | fConversionSigmaFFactorMethod(-1.),
|
---|
83 | fConversionSigmaBlindPixelMethod(-1.),
|
---|
84 | fConversionSigmaPINDiodeMethod(-1.),
|
---|
85 | fFlags(0),
|
---|
86 | fChargeLimit(3.),
|
---|
87 | fChargeErrLimit(0.),
|
---|
88 | fChargeRelErrLimit(1.)
|
---|
89 | {
|
---|
90 |
|
---|
91 | fName = name ? name : "MCalibrationPixel";
|
---|
92 | fTitle = title ? title : "Container of the MHCalibrationPixels and the fit results";
|
---|
93 |
|
---|
94 | //
|
---|
95 | // At the moment, we don't have a database, yet,
|
---|
96 | // so we get it from the configuration file
|
---|
97 | //
|
---|
98 | fConversionHiLo = gkConversionHiLo;
|
---|
99 | fConversionHiLoError = gkConversionHiLoError;
|
---|
100 |
|
---|
101 | fHist = new MHCalibrationPixel("MHCalibrationPixel","Calibration Histograms Pixel ");
|
---|
102 |
|
---|
103 | if (!fHist)
|
---|
104 | *fLog << warn << dbginf << " Could not create MHCalibrationPixel " << endl;
|
---|
105 |
|
---|
106 | CLRBIT(fFlags, kHiGainSaturation);
|
---|
107 | CLRBIT(fFlags, kExcluded);
|
---|
108 | CLRBIT(fFlags, kFitValid);
|
---|
109 | CLRBIT(fFlags, kFitted);
|
---|
110 | CLRBIT(fFlags, kBlindPixelMethodValid);
|
---|
111 | CLRBIT(fFlags, kFFactorMethodValid);
|
---|
112 | CLRBIT(fFlags, kPINDiodeMethodValid);
|
---|
113 |
|
---|
114 | }
|
---|
115 |
|
---|
116 | MCalibrationPix::~MCalibrationPix()
|
---|
117 | {
|
---|
118 | delete fHist;
|
---|
119 | }
|
---|
120 |
|
---|
121 |
|
---|
122 |
|
---|
123 |
|
---|
124 | void MCalibrationPix::DefinePixId(Int_t i)
|
---|
125 | {
|
---|
126 |
|
---|
127 | fPixId = i;
|
---|
128 | fHist->ChangeHistId(i);
|
---|
129 |
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | // ------------------------------------------------------------------------
|
---|
134 | //
|
---|
135 | // Invalidate values
|
---|
136 | //
|
---|
137 | void MCalibrationPix::Clear(Option_t *o)
|
---|
138 | {
|
---|
139 |
|
---|
140 | fHist->Reset();
|
---|
141 |
|
---|
142 | CLRBIT(fFlags, kHiGainSaturation);
|
---|
143 | CLRBIT(fFlags, kExcluded);
|
---|
144 | CLRBIT(fFlags, kFitValid);
|
---|
145 | CLRBIT(fFlags, kFitted);
|
---|
146 | CLRBIT(fFlags, kBlindPixelMethodValid);
|
---|
147 | CLRBIT(fFlags, kFFactorMethodValid);
|
---|
148 | CLRBIT(fFlags, kPINDiodeMethodValid);
|
---|
149 |
|
---|
150 | }
|
---|
151 |
|
---|
152 | // --------------------------------------------------------------------------
|
---|
153 | //
|
---|
154 | // Set the pedestals from outside
|
---|
155 | //
|
---|
156 | void MCalibrationPix::SetPedestal(Float_t ped, Float_t pedrms)
|
---|
157 | {
|
---|
158 |
|
---|
159 | fPed = ped;
|
---|
160 | fPedRms = pedrms;
|
---|
161 |
|
---|
162 | }
|
---|
163 |
|
---|
164 | // --------------------------------------------------------------------------
|
---|
165 | //
|
---|
166 | // Set the conversion factors from outside (only for MC)
|
---|
167 | //
|
---|
168 | void MCalibrationPix::SetConversionFFactorMethod(Float_t c, Float_t err, Float_t sig)
|
---|
169 | {
|
---|
170 | fConversionFFactorMethod = c;
|
---|
171 | fConversionErrorFFactorMethod = err;
|
---|
172 | fConversionSigmaFFactorMethod = sig;
|
---|
173 | }
|
---|
174 |
|
---|
175 |
|
---|
176 | // --------------------------------------------------------------------------
|
---|
177 | //
|
---|
178 | // Set the conversion factors from outside (only for MC)
|
---|
179 | //
|
---|
180 | void MCalibrationPix::SetConversionBlindPixelMethod(Float_t c, Float_t err, Float_t sig)
|
---|
181 | {
|
---|
182 | fConversionBlindPixelMethod = c;
|
---|
183 | fConversionErrorBlindPixelMethod = err;
|
---|
184 | fConversionSigmaBlindPixelMethod = sig;
|
---|
185 | }
|
---|
186 |
|
---|
187 | // --------------------------------------------------------------------------
|
---|
188 | //
|
---|
189 | // Set the conversion factors from outside (only for MC)
|
---|
190 | //
|
---|
191 | void MCalibrationPix::SetConversionPINDiodeMethod(Float_t c, Float_t err, Float_t sig)
|
---|
192 | {
|
---|
193 | fConversionPINDiodeMethod = c ;
|
---|
194 | fConversionErrorPINDiodeMethod = err;
|
---|
195 | fConversionSigmaPINDiodeMethod = sig;
|
---|
196 | }
|
---|
197 |
|
---|
198 | // --------------------------------------------------------------------------
|
---|
199 | //
|
---|
200 | // Set the Hi Gain Saturation Bit from outside (only for MC)
|
---|
201 | //
|
---|
202 | void MCalibrationPix::SetHiGainSaturation(Bool_t b)
|
---|
203 | {
|
---|
204 |
|
---|
205 | if (b)
|
---|
206 | {
|
---|
207 | SETBIT(fFlags, kHiGainSaturation);
|
---|
208 | fHist->SetUseLoGain(1);
|
---|
209 | }
|
---|
210 | else
|
---|
211 | {
|
---|
212 | CLRBIT(fFlags, kHiGainSaturation);
|
---|
213 | fHist->SetUseLoGain(0);
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | // --------------------------------------------------------------------------
|
---|
218 | //
|
---|
219 | // Set the Excluded Bit from outside
|
---|
220 | //
|
---|
221 | void MCalibrationPix::SetExcluded(Bool_t b )
|
---|
222 | {
|
---|
223 | b ? SETBIT(fFlags, kExcluded) : CLRBIT(fFlags, kExcluded);
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | // --------------------------------------------------------------------------
|
---|
228 | //
|
---|
229 | // Set the Excluded Bit from outside
|
---|
230 | //
|
---|
231 | void MCalibrationPix::SetExcludeQualityCheck(Bool_t b )
|
---|
232 | {
|
---|
233 | b ? SETBIT(fFlags, kExcludeQualityCheck) : CLRBIT(fFlags, kExcludeQualityCheck);
|
---|
234 | }
|
---|
235 |
|
---|
236 | // --------------------------------------------------------------------------
|
---|
237 | //
|
---|
238 | // Set the Excluded Bit from outside
|
---|
239 | //
|
---|
240 | void MCalibrationPix::SetFitValid(Bool_t b )
|
---|
241 | {
|
---|
242 | b ? SETBIT(fFlags, kFitValid) : CLRBIT(fFlags, kFitValid);
|
---|
243 | }
|
---|
244 |
|
---|
245 | // --------------------------------------------------------------------------
|
---|
246 | //
|
---|
247 | // Set the Excluded Bit from outside
|
---|
248 | //
|
---|
249 | void MCalibrationPix::SetFitted(Bool_t b )
|
---|
250 | {
|
---|
251 | b ? SETBIT(fFlags, kFitted) : CLRBIT(fFlags, kFitted);
|
---|
252 | }
|
---|
253 |
|
---|
254 | // --------------------------------------------------------------------------
|
---|
255 | //
|
---|
256 | // Set the Excluded Bit from outside
|
---|
257 | //
|
---|
258 | void MCalibrationPix::SetBlindPixelMethodValid(Bool_t b )
|
---|
259 | {
|
---|
260 | b ? SETBIT(fFlags, kBlindPixelMethodValid) : CLRBIT(fFlags, kBlindPixelMethodValid);
|
---|
261 | }
|
---|
262 |
|
---|
263 | // --------------------------------------------------------------------------
|
---|
264 | //
|
---|
265 | // Set the Excluded Bit from outside
|
---|
266 | //
|
---|
267 | void MCalibrationPix::SetFFactorMethodValid(Bool_t b )
|
---|
268 | {
|
---|
269 | b ? SETBIT(fFlags, kFFactorMethodValid) : CLRBIT(fFlags, kFFactorMethodValid);
|
---|
270 | }
|
---|
271 |
|
---|
272 | // --------------------------------------------------------------------------
|
---|
273 | //
|
---|
274 | // Set the Excluded Bit from outside
|
---|
275 | //
|
---|
276 | void MCalibrationPix::SetPINDiodeMethodValid(Bool_t b )
|
---|
277 | {
|
---|
278 | b ? SETBIT(fFlags, kPINDiodeMethodValid) : CLRBIT(fFlags, kPINDiodeMethodValid);
|
---|
279 | }
|
---|
280 |
|
---|
281 |
|
---|
282 | Bool_t MCalibrationPix::IsExcluded() const
|
---|
283 | {
|
---|
284 | return TESTBIT(fFlags,kExcluded);
|
---|
285 | }
|
---|
286 |
|
---|
287 | Bool_t MCalibrationPix::IsFitValid() const
|
---|
288 | {
|
---|
289 | return TESTBIT(fFlags, kFitValid);
|
---|
290 | }
|
---|
291 |
|
---|
292 | Bool_t MCalibrationPix::IsFitted() const
|
---|
293 | {
|
---|
294 | return TESTBIT(fFlags, kFitted);
|
---|
295 | }
|
---|
296 |
|
---|
297 | Bool_t MCalibrationPix::IsBlindPixelMethodValid() const
|
---|
298 | {
|
---|
299 | return TESTBIT(fFlags, kBlindPixelMethodValid);
|
---|
300 | }
|
---|
301 |
|
---|
302 | Bool_t MCalibrationPix::IsFFactorMethodValid() const
|
---|
303 | {
|
---|
304 | return TESTBIT(fFlags, kFFactorMethodValid);
|
---|
305 | }
|
---|
306 |
|
---|
307 | Bool_t MCalibrationPix::IsPINDiodeMethodValid() const
|
---|
308 | {
|
---|
309 | return TESTBIT(fFlags, kPINDiodeMethodValid);
|
---|
310 | }
|
---|
311 |
|
---|
312 |
|
---|
313 | // --------------------------------------------------------------------------
|
---|
314 | //
|
---|
315 | // 1) Return if the charge distribution is already succesfully fitted
|
---|
316 | // or if the histogram is empty
|
---|
317 | // 2) Set a lower Fit range according to 1.5 Pedestal RMS in order to avoid
|
---|
318 | // possible remaining cosmics to spoil the fit.
|
---|
319 | // 3) Decide if the LoGain Histogram is fitted or the HiGain Histogram
|
---|
320 | // 4) Fit the histograms with a Gaussian
|
---|
321 | // 5) In case of failure print out the fit results
|
---|
322 | // 6) Retrieve the results and store them in this class
|
---|
323 | // 7) Calculate the number of photo-electrons after the F-Factor method
|
---|
324 | // 8) Calculate the errors of the F-Factor method
|
---|
325 | //
|
---|
326 | // The fits are declared valid (fFitValid = kTRUE), if:
|
---|
327 | //
|
---|
328 | // 1) Pixel has a fitted charge greater than 5*PedRMS
|
---|
329 | // 2) Pixel has a fit error greater than 0.
|
---|
330 | // 3) Pixel has a fit Probability greater than 0.0001
|
---|
331 | // 4) Pixel has a charge sigma bigger than its Pedestal RMS
|
---|
332 | // 5) If FitTimes is used,
|
---|
333 | // the mean arrival time is at least 1.0 slices from the used edge slices
|
---|
334 | // (this stage is only performed in the times fit)
|
---|
335 | //
|
---|
336 | // If the histogram is empty, all values are set to -1.
|
---|
337 | //
|
---|
338 | // The conversion factor after the F-Factor method is declared valid, if:
|
---|
339 | //
|
---|
340 | // 1) fFitValid is kTRUE
|
---|
341 | // 2) Conversion Factor is bigger than 0.
|
---|
342 | // 3) The error of the conversion factor is smaller than 10%
|
---|
343 | //
|
---|
344 | Bool_t MCalibrationPix::FitCharge()
|
---|
345 | {
|
---|
346 |
|
---|
347 | //
|
---|
348 | // 1) Return if the charge distribution is already succesfully fitted
|
---|
349 | // or if the histogram is empty
|
---|
350 | //
|
---|
351 | if (fHist->IsFitOK() || fHist->IsEmpty())
|
---|
352 | return kTRUE;
|
---|
353 |
|
---|
354 | //
|
---|
355 | // 2) Set a lower Fit range according to 1.5 Pedestal RMS in order to avoid
|
---|
356 | // possible remaining cosmics to spoil the fit.
|
---|
357 | //
|
---|
358 | if (fPed && fPedRms)
|
---|
359 | fHist->SetLowerFitRange(1.5*fPedRms);
|
---|
360 | else
|
---|
361 | *fLog << warn << "WARNING: Cannot set lower fit range: Pedestals not available" << endl;
|
---|
362 |
|
---|
363 | //
|
---|
364 | // 3) Decide if the LoGain Histogram is fitted or the HiGain Histogram
|
---|
365 | //
|
---|
366 | if (fHist->UseLoGain())
|
---|
367 | {
|
---|
368 |
|
---|
369 | SetHiGainSaturation();
|
---|
370 |
|
---|
371 | //
|
---|
372 | // 4) Fit the Lo Gain histograms with a Gaussian
|
---|
373 | //
|
---|
374 | if(!fHist->FitChargeLoGain())
|
---|
375 | {
|
---|
376 | *fLog << warn << "WARNING: Could not fit Lo Gain charges of pixel " << fPixId << endl;
|
---|
377 | //
|
---|
378 | // 5) In case of failure print out the fit results
|
---|
379 | //
|
---|
380 | // fHist->PrintChargeFitResult();
|
---|
381 | CLRBIT(fFlags,kFitted);
|
---|
382 | }
|
---|
383 | else
|
---|
384 | SETBIT(fFlags,kFitted);
|
---|
385 | }
|
---|
386 | else
|
---|
387 | {
|
---|
388 | //
|
---|
389 | // 4) Fit the Hi Gain histograms with a Gaussian
|
---|
390 | //
|
---|
391 | if(!fHist->FitChargeHiGain())
|
---|
392 | {
|
---|
393 | *fLog << warn << "WARNING: Could not fit Hi Gain charges of pixel " << fPixId << endl;
|
---|
394 | //
|
---|
395 | // 5) In case of failure print out the fit results
|
---|
396 | //
|
---|
397 | // fHist->PrintChargeFitResult();
|
---|
398 | CLRBIT(fFlags,kFitted);
|
---|
399 | }
|
---|
400 | else
|
---|
401 | SETBIT(fFlags,kFitted);
|
---|
402 | }
|
---|
403 |
|
---|
404 |
|
---|
405 | //
|
---|
406 | // 6) Retrieve the results and store them in this class
|
---|
407 | //
|
---|
408 | fCharge = fHist->GetChargeMean();
|
---|
409 | fErrCharge = fHist->GetChargeMeanErr();
|
---|
410 | fSigmaCharge = fHist->GetChargeSigma();
|
---|
411 | fErrSigmaCharge = fHist->GetChargeSigmaErr();
|
---|
412 | fChargeProb = fHist->GetChargeProb();
|
---|
413 |
|
---|
414 | if (CheckChargeFitValidity())
|
---|
415 | SETBIT(fFlags,kFitValid);
|
---|
416 | else
|
---|
417 | {
|
---|
418 | CLRBIT(fFlags,kFitValid);
|
---|
419 | return kFALSE;
|
---|
420 | }
|
---|
421 |
|
---|
422 | //
|
---|
423 | // 7) Calculate the number of photo-electrons after the F-Factor method
|
---|
424 | // 8) Calculate the errors of the F-Factor method
|
---|
425 | //
|
---|
426 | if ((fPed > 0.) && (fPedRms > 0.))
|
---|
427 | {
|
---|
428 |
|
---|
429 | //
|
---|
430 | // Square all variables in order to avoid applications of square root
|
---|
431 | //
|
---|
432 | // First the relative error squares
|
---|
433 | //
|
---|
434 | const Float_t chargeSquare = fCharge* fCharge;
|
---|
435 | const Float_t chargeSquareRelErrSquare = 4.*fErrCharge*fErrCharge / chargeSquare;
|
---|
436 |
|
---|
437 | const Float_t fFactorRelErrSquare = fFactorError * fFactorError / (fFactor * fFactor);
|
---|
438 | //
|
---|
439 | // Now the absolute error squares
|
---|
440 | //
|
---|
441 | const Float_t sigmaSquare = fSigmaCharge* fSigmaCharge;
|
---|
442 | const Float_t sigmaSquareErrSquare = 4.*fErrSigmaCharge*fErrSigmaCharge * sigmaSquare;
|
---|
443 |
|
---|
444 | const Float_t elecRmsSquare = fElectronicPedRms* fElectronicPedRms;
|
---|
445 | const Float_t elecRmsSquareErrSquare = 4.*fErrElectronicPedRms*fErrElectronicPedRms * elecRmsSquare;
|
---|
446 |
|
---|
447 | Float_t pedRmsSquare = fPedRms* fPedRms;
|
---|
448 | Float_t pedRmsSquareErrSquare = 4.*fErrPedRms*fErrPedRms * pedRmsSquare;
|
---|
449 |
|
---|
450 | if (TESTBIT(fFlags,kHiGainSaturation))
|
---|
451 | {
|
---|
452 |
|
---|
453 | //
|
---|
454 | // We do not know the Lo Gain Pedestal RMS, so we have to retrieve it
|
---|
455 | // from the Hi Gain:
|
---|
456 | //
|
---|
457 | // We extract the pure NSB contribution:
|
---|
458 | //
|
---|
459 | Float_t nsbSquare = pedRmsSquare - elecRmsSquare;
|
---|
460 | Float_t nsbSquareRelErrSquare = (pedRmsSquareErrSquare + elecRmsSquareErrSquare)
|
---|
461 | / (nsbSquare * nsbSquare) ;
|
---|
462 |
|
---|
463 | if (nsbSquare < 0.)
|
---|
464 | nsbSquare = 0.;
|
---|
465 |
|
---|
466 | //
|
---|
467 | // Now, we divide the NSB by the conversion factor and
|
---|
468 | // add it quadratically to the electronic noise
|
---|
469 | //
|
---|
470 | const Float_t conversionSquare = fConversionHiLo *fConversionHiLo;
|
---|
471 | const Float_t conversionSquareRelErrSquare = 4.*fConversionHiLoError*fConversionHiLoError/conversionSquare;
|
---|
472 |
|
---|
473 | //
|
---|
474 | // Calculate the new "Pedestal RMS"
|
---|
475 | //
|
---|
476 | const Float_t convertedNsbSquare = nsbSquare / conversionSquare;
|
---|
477 | const Float_t convertedNsbSquareErrSquare = (nsbSquareRelErrSquare + conversionSquareRelErrSquare)
|
---|
478 | * convertedNsbSquare * convertedNsbSquare;
|
---|
479 |
|
---|
480 | pedRmsSquare = convertedNsbSquare + elecRmsSquare;
|
---|
481 | pedRmsSquareErrSquare = convertedNsbSquareErrSquare + elecRmsSquareErrSquare;
|
---|
482 |
|
---|
483 | } /* if (kHiGainSaturation) */
|
---|
484 |
|
---|
485 | //
|
---|
486 | // Calculate the reduced sigmas
|
---|
487 | //
|
---|
488 | fRSigmaSquare = sigmaSquare - pedRmsSquare;
|
---|
489 | if (fRSigmaSquare <= 0.)
|
---|
490 | {
|
---|
491 | *fLog << warn
|
---|
492 | << "WARNING: Cannot apply F-Factor calibration: Reduced Sigma smaller than 0 in pixel "
|
---|
493 | << fPixId << endl;
|
---|
494 | if (TESTBIT(fFlags,kHiGainSaturation))
|
---|
495 | ApplyLoGainConversion();
|
---|
496 | return kFALSE;
|
---|
497 | }
|
---|
498 |
|
---|
499 | const Float_t rSigmaSquareRelErrSquare = (sigmaSquareErrSquare + pedRmsSquareErrSquare)
|
---|
500 | / (fRSigmaSquare * fRSigmaSquare) ;
|
---|
501 |
|
---|
502 | //
|
---|
503 | // Calculate the number of phe's from the F-Factor method
|
---|
504 | // (independent on Hi Gain or Lo Gain)
|
---|
505 | //
|
---|
506 | fPheFFactorMethod = fFactor * chargeSquare / fRSigmaSquare;
|
---|
507 |
|
---|
508 | const Float_t pheFFactorRelErrSquare = fFactorRelErrSquare
|
---|
509 | + chargeSquareRelErrSquare
|
---|
510 | + rSigmaSquareRelErrSquare ;
|
---|
511 |
|
---|
512 | fPheFFactorMethodError = TMath::Sqrt(pheFFactorRelErrSquare) * fPheFFactorMethod;
|
---|
513 |
|
---|
514 | //
|
---|
515 | // Calculate the conversion factors
|
---|
516 | //
|
---|
517 | if (TESTBIT(fFlags,kHiGainSaturation))
|
---|
518 | ApplyLoGainConversion();
|
---|
519 |
|
---|
520 | const Float_t chargeRelErrSquare = fErrCharge*fErrCharge / (fCharge * fCharge);
|
---|
521 |
|
---|
522 | fConversionFFactorMethod = fPheFFactorMethod / fCharge ;
|
---|
523 | fConversionErrorFFactorMethod = ( pheFFactorRelErrSquare + chargeRelErrSquare )
|
---|
524 | * fConversionFFactorMethod * fConversionFFactorMethod;
|
---|
525 |
|
---|
526 | if ( IsFitValid() &&
|
---|
527 | (fConversionFFactorMethod > 0.) &&
|
---|
528 | (fConversionErrorFFactorMethod/fConversionFFactorMethod < 0.1) )
|
---|
529 | SETBIT(fFlags,kFFactorMethodValid);
|
---|
530 | else
|
---|
531 | CLRBIT(fFlags,kFFactorMethodValid);
|
---|
532 |
|
---|
533 | } /* if ((fPed > 0.) && (fPedRms > 0.)) */
|
---|
534 |
|
---|
535 | return kTRUE;
|
---|
536 |
|
---|
537 | }
|
---|
538 |
|
---|
539 | //
|
---|
540 | // The check return kTRUE if:
|
---|
541 | //
|
---|
542 | // 1) Pixel has a fitted charge greater than 5*PedRMS
|
---|
543 | // 2) Pixel has a fit error greater than 0.
|
---|
544 | // 3) Pixel has a fitted charge greater its charge error
|
---|
545 | // 4) Pixel has a fit Probability greater than 0.0001
|
---|
546 | // 5) Pixel has a charge sigma bigger than its Pedestal RMS
|
---|
547 | //
|
---|
548 | Bool_t MCalibrationPix::CheckChargeFitValidity()
|
---|
549 | {
|
---|
550 |
|
---|
551 | if (TESTBIT(fFlags,kExcludeQualityCheck))
|
---|
552 | return kTRUE;
|
---|
553 |
|
---|
554 | Float_t equivpedestal = GetPedRms();
|
---|
555 |
|
---|
556 | if (TESTBIT(fFlags,kHiGainSaturation))
|
---|
557 | equivpedestal /= fConversionHiLo;
|
---|
558 |
|
---|
559 | if (fCharge < fChargeLimit*equivpedestal)
|
---|
560 | {
|
---|
561 | *fLog << warn << "WARNING: Fitted Charge is smaller than "
|
---|
562 | << fChargeLimit << " Pedestal RMS in Pixel " << fPixId << endl;
|
---|
563 | return kFALSE;
|
---|
564 | }
|
---|
565 |
|
---|
566 | if (fErrCharge < fChargeErrLimit)
|
---|
567 | {
|
---|
568 | *fLog << warn << "WARNING: Error of Fitted Charge is smaller than "
|
---|
569 | << fChargeErrLimit << " in Pixel " << fPixId << endl;
|
---|
570 | return kFALSE;
|
---|
571 | }
|
---|
572 |
|
---|
573 | if (fCharge < fChargeRelErrLimit*fErrCharge)
|
---|
574 | {
|
---|
575 | *fLog << warn << "WARNING: Error of Fitted Charge is greater than "
|
---|
576 | << fChargeRelErrLimit << "* Fitted Charges itself in Pixel " << fPixId << endl;
|
---|
577 | return kFALSE;
|
---|
578 | }
|
---|
579 |
|
---|
580 | if (!fHist->IsFitOK())
|
---|
581 | {
|
---|
582 | *fLog << warn << "WARNING: Probability of Fitted Charge too low in Pixel " << fPixId << endl;
|
---|
583 | return kFALSE;
|
---|
584 | }
|
---|
585 |
|
---|
586 | if (fSigmaCharge < equivpedestal)
|
---|
587 | {
|
---|
588 | *fLog << warn << "WARNING: Sigma of Fitted Charge smaller than Pedestal RMS in Pixel " << fPixId << endl;
|
---|
589 | return kFALSE;
|
---|
590 | }
|
---|
591 | return kTRUE;
|
---|
592 | }
|
---|
593 |
|
---|
594 | //
|
---|
595 | // The check returns kTRUE if:
|
---|
596 | //
|
---|
597 | // The mean arrival time is at least 1.0 slices from the used edge slices
|
---|
598 | //
|
---|
599 | Bool_t MCalibrationPix::CheckTimeFitValidity()
|
---|
600 | {
|
---|
601 |
|
---|
602 | if (TESTBIT(fFlags,kExcludeQualityCheck))
|
---|
603 | return kTRUE;
|
---|
604 |
|
---|
605 | Float_t lowerrange;
|
---|
606 | Float_t upperrange;
|
---|
607 |
|
---|
608 | if (TESTBIT(fFlags,kHiGainSaturation))
|
---|
609 | {
|
---|
610 | lowerrange = (Float_t)fHist->GetTimeLowerFitRangeLoGain()+1.;
|
---|
611 | upperrange = (Float_t)fHist->GetTimeUpperFitRangeLoGain()+1.;
|
---|
612 | }
|
---|
613 | else
|
---|
614 | {
|
---|
615 | lowerrange = (Float_t)fHist->GetTimeLowerFitRangeHiGain()+1.;
|
---|
616 | upperrange = (Float_t)fHist->GetTimeUpperFitRangeHiGain()+1.;
|
---|
617 | }
|
---|
618 |
|
---|
619 |
|
---|
620 | if (fTime < lowerrange)
|
---|
621 | {
|
---|
622 | *fLog << warn
|
---|
623 | << "WARNING: Mean Fitted Time inside or smaller than first used FADC slice in Pixel "
|
---|
624 | << fPixId << " time: " << fTime << " Range: " << lowerrange << endl;
|
---|
625 | return kFALSE;
|
---|
626 | }
|
---|
627 |
|
---|
628 | if (fTime > upperrange)
|
---|
629 | {
|
---|
630 | *fLog << warn
|
---|
631 | << "WARNING: Mean Fitted Time inside or greater than last used FADC slice in Pixel "
|
---|
632 | << fPixId << " time: " << fTime << " Range: " << upperrange << endl;
|
---|
633 | return kFALSE;
|
---|
634 | }
|
---|
635 |
|
---|
636 | return kTRUE;
|
---|
637 | }
|
---|
638 |
|
---|
639 |
|
---|
640 | //
|
---|
641 | // The check returns kTRUE if:
|
---|
642 | //
|
---|
643 | //
|
---|
644 | //
|
---|
645 | Bool_t MCalibrationPix::CheckOscillations()
|
---|
646 | {
|
---|
647 |
|
---|
648 |
|
---|
649 | return kTRUE;
|
---|
650 | }
|
---|
651 |
|
---|
652 |
|
---|
653 |
|
---|
654 | void MCalibrationPix::ApplyLoGainConversion()
|
---|
655 | {
|
---|
656 |
|
---|
657 | const Float_t chargeRelErrSquare = fErrCharge*fErrCharge
|
---|
658 | /( fCharge * fCharge);
|
---|
659 | const Float_t sigmaRelErrSquare = fErrSigmaCharge*fErrSigmaCharge
|
---|
660 | /( fSigmaCharge * fSigmaCharge);
|
---|
661 | const Float_t conversionRelErrSquare = fConversionHiLoError*fConversionHiLoError
|
---|
662 | /(fConversionHiLo * fConversionHiLo);
|
---|
663 |
|
---|
664 | fCharge *= fConversionHiLo;
|
---|
665 | fErrCharge = TMath::Sqrt(chargeRelErrSquare + conversionRelErrSquare) * fCharge;
|
---|
666 |
|
---|
667 | fSigmaCharge *= fConversionHiLo;
|
---|
668 | fErrSigmaCharge = TMath::Sqrt(sigmaRelErrSquare + conversionRelErrSquare) * fSigmaCharge;
|
---|
669 |
|
---|
670 | }
|
---|
671 |
|
---|
672 |
|
---|
673 |
|
---|
674 | // --------------------------------------------------------------------------
|
---|
675 | //
|
---|
676 | // 1) Fit the arrival times
|
---|
677 | // 2) Retrieve the results
|
---|
678 | // 3) Note that because of the low number of bins, the NDf is sometimes 0, so
|
---|
679 | // Root does not give a reasonable Probability, the Chisquare is more significant
|
---|
680 | //
|
---|
681 | // This fit has to be done AFTER the Charges fit,
|
---|
682 | // otherwise only the Hi Gain will be fitted, even if there are no entries
|
---|
683 | //
|
---|
684 | //
|
---|
685 | Bool_t MCalibrationPix::FitTime()
|
---|
686 | {
|
---|
687 |
|
---|
688 | //
|
---|
689 | // Fit the Low Gain
|
---|
690 | //
|
---|
691 | if (TESTBIT(fFlags,kHiGainSaturation))
|
---|
692 | {
|
---|
693 | if(!fHist->FitTimeLoGain())
|
---|
694 | {
|
---|
695 | *fLog << warn << "WARNING: Could not fit Lo Gain times of pixel " << fPixId << endl;
|
---|
696 | // fHist->PrintTimeFitResult();
|
---|
697 | return kFALSE;
|
---|
698 | }
|
---|
699 | }
|
---|
700 |
|
---|
701 | //
|
---|
702 | // Fit the High Gain
|
---|
703 | //
|
---|
704 | else
|
---|
705 | {
|
---|
706 | if(!fHist->FitTimeHiGain())
|
---|
707 | {
|
---|
708 | *fLog << warn << "WARNING: Could not fit Hi Gain times of pixel " << fPixId << endl;
|
---|
709 | // fHist->PrintTimeFitResult();
|
---|
710 | return kFALSE;
|
---|
711 | }
|
---|
712 | }
|
---|
713 |
|
---|
714 | fTime = fHist->GetTimeMean();
|
---|
715 | fSigmaTime = fHist->GetTimeSigma();
|
---|
716 | fTimeChiSquare = fHist->GetTimeChiSquare();
|
---|
717 | fTimeProb = fHist->GetTimeProb();
|
---|
718 |
|
---|
719 | if (CheckTimeFitValidity())
|
---|
720 | SETBIT(fFlags,kFitValid);
|
---|
721 | else
|
---|
722 | CLRBIT(fFlags,kFitValid);
|
---|
723 |
|
---|
724 | return kTRUE;
|
---|
725 | }
|
---|
726 |
|
---|