source: trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc@ 2777

Last change on this file since 2777 was 2765, checked in by gaug, 21 years ago
*** empty log message ***
File size: 15.4 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Markus Gaug 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
39ClassImp(MCalibrationPix);
40
41using namespace std;
42
43// --------------------------------------------------------------------------
44//
45// Default Constructor.
46//
47MCalibrationPix::MCalibrationPix(const char *name, const char *title)
48 : fPixId(-1),
49 fCharge(-1.),
50 fErrCharge(-1.),
51 fSigmaCharge(-1.),
52 fErrSigmaCharge(-1.),
53 fRSigmaSquare(-1.),
54 fChargeProb(-1.),
55 fPed(-1.),
56 fPedRms(-1.),
57 fErrPedRms(0.),
58 fElectronicPedRms(1.5),
59 fErrElectronicPedRms(0.3),
60 fTime(-1.),
61 fSigmaTime(-1.),
62 fTimeChiSquare(-1.),
63 fFactor(1.3),
64 fPheFFactorMethod(-1.),
65 fConversionFFactorMethod(-1.),
66 fConversionBlindPixelMethod(-1.),
67 fConversionPINDiodeMethod(-1.),
68 fConversionErrorFFactorMethod(-1.),
69 fConversionErrorBlindPixelMethod(-1.),
70 fConversionErrorPINDiodeMethod(-1.),
71 fConversionSigmaFFactorMethod(-1.),
72 fConversionSigmaBlindPixelMethod(-1.),
73 fConversionSigmaPINDiodeMethod(-1.),
74 fHiGainSaturation(kFALSE),
75 fFitValid(kFALSE),
76 fFitted(kFALSE),
77 fBlindPixelMethodValid(kFALSE),
78 fFFactorMethodValid(kFALSE),
79 fPINDiodeMethodValid(kFALSE)
80{
81
82 fName = name ? name : "MCalibrationPixel";
83 fTitle = title ? title : "Container of the MHCalibrationPixels and the fit results";
84
85 //
86 // At the moment, we don't have a database, yet,
87 // so we get it from the configuration file
88 //
89 fConversionHiLo = gkConversionHiLo;
90 fConversionHiLoError = gkConversionHiLoError;
91
92 fHist = new MHCalibrationPixel("MHCalibrationPixel","Calibration Histograms Pixel ");
93
94}
95
96MCalibrationPix::~MCalibrationPix()
97{
98 delete fHist;
99}
100
101
102void MCalibrationPix::DefinePixId(Int_t i)
103{
104
105 fPixId = i;
106 fHist->ChangeHistId(i);
107
108}
109
110
111// ------------------------------------------------------------------------
112//
113// Invalidate values
114//
115void MCalibrationPix::Clear(Option_t *o)
116{
117 fHist->Reset();
118}
119
120
121// --------------------------------------------------------------------------
122//
123// 1) Return if the charge distribution is already succesfully fitted
124// 2) Set a lower Fit range according to 1.5 Pedestal RMS in order to avoid
125// possible remaining cosmics to spoil the fit.
126// 3) Decide if the LoGain Histogram is fitted or the HiGain Histogram
127// 4) Fit the histograms with a Gaussian
128// 5) In case of failure print out the fit results
129// 6) Retrieve the results and store them in this class
130// 7) Calculate the number of photo-electrons after the F-Factor method
131// 8) Calculate the errors of the F-Factor method
132//
133// The fits are declared valid (fFitValid = kTRUE), if:
134//
135// 1) Pixel has a fitted charge greater than 3*PedRMS
136// 2) Pixel has a fit error greater than 0.
137// 3) Pixel has a fit Probability greater than 0.0001
138// 4) Pixel has a charge sigma bigger than its Pedestal RMS
139// 5) If FitTimes is used,
140// the mean arrival time is at least 1.0 slices from the used edge slices
141// (this stage is only performed in the times fit)
142//
143// The conversion factor after the F-Factor method is declared valid, if:
144//
145// 1) fFitValid is kTRUE
146// 2) Conversion Factor is bigger than 0.
147// 3) The error of the conversion factor is smaller than 10%
148//
149Bool_t MCalibrationPix::FitCharge()
150{
151
152 //
153 // 1) Return if the charge distribution is already succesfully fitted
154 //
155 if (fHist->IsFitOK())
156 return kTRUE;
157
158 //
159 // 2) Set a lower Fit range according to 1.5 Pedestal RMS in order to avoid
160 // possible remaining cosmics to spoil the fit.
161 //
162 if (fPed && fPedRms)
163 fHist->SetLowerFitRange(1.5*fPedRms);
164 else
165 *fLog << warn << "Cannot set lower fit range: Pedestals not available" << endl;
166
167 //
168 // 3) Decide if the LoGain Histogram is fitted or the HiGain Histogram
169 //
170 if (fHist->UseLoGain())
171 {
172
173 SetHiGainSaturation();
174
175 //
176 // 4) Fit the Lo Gain histograms with a Gaussian
177 //
178 if(!fHist->FitChargeLoGain())
179 {
180 *fLog << warn << "Could not fit Lo Gain charges of pixel " << fPixId << endl;
181 //
182 // 5) In case of failure print out the fit results
183 //
184 fHist->PrintChargeFitResult();
185 }
186 }
187 else
188 {
189 //
190 // 4) Fit the Hi Gain histograms with a Gaussian
191 //
192 if(!fHist->FitChargeHiGain())
193 {
194 *fLog << warn << "Could not fit Hi Gain charges of pixel " << fPixId << endl;
195 //
196 // 5) In case of failure print out the fit results
197 //
198 fHist->PrintChargeFitResult();
199 }
200 }
201
202
203 //
204 // 6) Retrieve the results and store them in this class
205 //
206 fCharge = fHist->GetChargeMean();
207 fErrCharge = fHist->GetChargeMeanErr();
208 fSigmaCharge = fHist->GetChargeSigma();
209 fErrSigmaCharge = fHist->GetChargeSigmaErr();
210 fChargeProb = fHist->GetChargeProb();
211
212 if (fCharge <= 0.)
213 {
214 *fLog << warn << "Cannot apply calibration: Mean Fitted Charges are smaller than 0 in pixel "
215 << fPixId << endl;
216 return kFALSE;
217 }
218
219 if (fErrCharge > 0.)
220 fFitted = kTRUE;
221
222 if (CheckChargeFitValidity())
223 fFitValid = kTRUE;
224
225
226 //
227 // 7) Calculate the number of photo-electrons after the F-Factor method
228 // 8) Calculate the errors of the F-Factor method
229 //
230 if ((fPed > 0.) && (fPedRms > 0.))
231 {
232
233 //
234 // Square all variables in order to avoid applications of square root
235 //
236 // First the relative error squares
237 //
238 const Float_t chargeSquare = fCharge* fCharge;
239 const Float_t chargeSquareRelErrSquare = 4.*fErrCharge*fErrCharge / chargeSquare;
240
241 const Float_t fFactorRelErrSquare = fFactorError * fFactorError / (fFactor * fFactor);
242 //
243 // Now the absolute error squares
244 //
245 const Float_t sigmaSquare = fSigmaCharge* fSigmaCharge;
246 const Float_t sigmaSquareErrSquare = 4.*fErrSigmaCharge*fErrSigmaCharge * sigmaSquare;
247
248 const Float_t elecRmsSquare = fElectronicPedRms* fElectronicPedRms;
249 const Float_t elecRmsSquareErrSquare = 4.*fErrElectronicPedRms*fErrElectronicPedRms * elecRmsSquare;
250
251 Float_t pedRmsSquare = fPedRms* fPedRms;
252 Float_t pedRmsSquareErrSquare = 4.*fErrPedRms*fErrPedRms * pedRmsSquare;
253
254 if (fHiGainSaturation)
255 {
256
257 //
258 // We do not know the Lo Gain Pedestal RMS, so we have to retrieve it
259 // from the Hi Gain:
260 //
261 // We extract the pure NSB contribution:
262 //
263 Float_t nsbSquare = pedRmsSquare - elecRmsSquare;
264 Float_t nsbSquareRelErrSquare = (pedRmsSquareErrSquare + elecRmsSquareErrSquare)
265 / (nsbSquare * nsbSquare) ;
266
267 if (nsbSquare < 0.)
268 nsbSquare = 0.;
269
270 //
271 // Now, we divide the NSB by the conversion factor and
272 // add it quadratically to the electronic noise
273 //
274 const Float_t conversionSquare = fConversionHiLo *fConversionHiLo;
275 const Float_t conversionSquareRelErrSquare = 4.*fConversionHiLoError*fConversionHiLoError/conversionSquare;
276
277 //
278 // Calculate the new "Pedestal RMS"
279 //
280 const Float_t convertedNsbSquare = nsbSquare / conversionSquare;
281 const Float_t convertedNsbSquareErrSquare = (nsbSquareRelErrSquare + conversionSquareRelErrSquare)
282 * convertedNsbSquare * convertedNsbSquare;
283
284 pedRmsSquare = convertedNsbSquare + elecRmsSquare;
285 pedRmsSquareErrSquare = convertedNsbSquareErrSquare + elecRmsSquareErrSquare;
286
287 } /* if (fHiGainSaturation) */
288
289 //
290 // Calculate the reduced sigmas
291 //
292 fRSigmaSquare = sigmaSquare - pedRmsSquare;
293 if (fRSigmaSquare <= 0.)
294 {
295 *fLog << warn << "Cannot apply F-Factor calibration: Reduced Sigma smaller than 0 in pixel "
296 << fPixId << endl;
297 if (fHiGainSaturation)
298 ApplyLoGainConversion();
299 return kFALSE;
300 }
301
302 const Float_t rSigmaSquareRelErrSquare = (sigmaSquareErrSquare + pedRmsSquareErrSquare)
303 / (fRSigmaSquare * fRSigmaSquare) ;
304
305 //
306 // Calculate the number of phe's from the F-Factor method
307 // (independent on Hi Gain or Lo Gain)
308 //
309 fPheFFactorMethod = fFactor * chargeSquare / fRSigmaSquare;
310
311 const Float_t pheFFactorRelErrSquare = fFactorRelErrSquare
312 + chargeSquareRelErrSquare
313 + rSigmaSquareRelErrSquare ;
314
315 fPheFFactorMethodError = TMath::Sqrt(pheFFactorRelErrSquare) * fPheFFactorMethod;
316
317 //
318 // Calculate the conversion factors
319 //
320 if (fHiGainSaturation)
321 ApplyLoGainConversion();
322
323 const Float_t chargeRelErrSquare = fErrCharge*fErrCharge / (fCharge * fCharge);
324
325 fConversionFFactorMethod = fPheFFactorMethod / fCharge ;
326 fConversionErrorFFactorMethod = ( pheFFactorRelErrSquare + chargeRelErrSquare )
327 * fConversionFFactorMethod * fConversionFFactorMethod;
328
329 if ( IsFitValid() &&
330 (fConversionFFactorMethod > 0.) &&
331 (fConversionErrorFFactorMethod/fConversionFFactorMethod < 0.1) )
332 fFFactorMethodValid = kTRUE;
333
334
335 } /* if ((fPed > 0.) && (fPedRms > 0.)) */
336
337 return kTRUE;
338
339}
340
341//
342// The check return kTRUE if:
343//
344// 1) Pixel has a fitted charge greater than 3*PedRMS
345// 2) Pixel has a fit error greater than 0.
346// 3) Pixel has a fit Probability greater than 0.0001
347// 4) Pixel has a charge sigma bigger than its Pedestal RMS
348//
349Bool_t MCalibrationPix::CheckChargeFitValidity()
350{
351
352 Float_t equivpedestal = GetPedRms();
353
354 if (fHiGainSaturation)
355 equivpedestal /= fConversionHiLo;
356
357 if (fCharge < 3.*equivpedestal)
358 {
359 *fLog << warn << "WARNING: Fitted Charge is smaller than 3 Pedestal RMS in Pixel " << fPixId << endl;
360 return kFALSE;
361 }
362
363 if (fErrCharge < 0.)
364 {
365 *fLog << warn << "WARNING: Error of Fitted Charge is smaller than 0 in Pixel " << fPixId << endl;
366 return kFALSE;
367 }
368
369 if (!fHist->IsFitOK())
370 {
371 *fLog << warn << "WARNING: Probability of Fitted Charge too low in Pixel " << fPixId << endl;
372 return kFALSE;
373 }
374
375 if (fSigmaCharge < equivpedestal)
376 {
377 *fLog << warn << "WARNING: Sigma of Fitted Charge smaller than Pedestal RMS in Pixel " << fPixId << endl;
378 return kFALSE;
379 }
380 return kTRUE;
381}
382
383//
384// The check returns kTRUE if:
385//
386// The mean arrival time is at least 1.0 slices from the used edge slices
387//
388Bool_t MCalibrationPix::CheckTimeFitValidity()
389{
390
391 Float_t lowerrange;
392 Float_t upperrange;
393
394 if (fHiGainSaturation)
395 {
396 lowerrange = (Float_t)fHist->GetTimeLowerFitRangeLoGain()+1.;
397 upperrange = (Float_t)fHist->GetTimeUpperFitRangeLoGain()+1.;
398 }
399 else
400 {
401 lowerrange = (Float_t)fHist->GetTimeLowerFitRangeHiGain()+1.;
402 upperrange = (Float_t)fHist->GetTimeUpperFitRangeHiGain()+1.;
403 }
404
405
406 if (fTime < lowerrange)
407 {
408 *fLog << warn
409 << "WARNING: Mean Fitted Time inside or smaller than first used FADC slice in Pixel "
410 << fPixId << " time: " << fTime << " Range: " << lowerrange << endl;
411 return kFALSE;
412 }
413
414 if (fTime > upperrange)
415 {
416 *fLog << warn
417 << "WARNING: Mean Fitted Time inside or greater than last used FADC slice in Pixel "
418 << fPixId << " time: " << fTime << " Range: " << upperrange << endl;
419 return kFALSE;
420 }
421
422 return kTRUE;
423}
424
425
426
427void MCalibrationPix::ApplyLoGainConversion()
428{
429
430 const Float_t chargeRelErrSquare = fErrCharge*fErrCharge
431 /( fCharge * fCharge);
432 const Float_t sigmaRelErrSquare = fErrSigmaCharge*fErrSigmaCharge
433 /( fSigmaCharge * fSigmaCharge);
434 const Float_t conversionRelErrSquare = fConversionHiLoError*fConversionHiLoError
435 /(fConversionHiLo * fConversionHiLo);
436
437 fCharge *= fConversionHiLo;
438 fErrCharge = TMath::Sqrt(chargeRelErrSquare + conversionRelErrSquare) * fCharge;
439
440 fSigmaCharge *= fConversionHiLo;
441 fErrSigmaCharge = TMath::Sqrt(sigmaRelErrSquare + conversionRelErrSquare) * fSigmaCharge;
442
443}
444
445
446// --------------------------------------------------------------------------
447//
448// Set the pedestals from outside
449//
450void MCalibrationPix::SetPedestal(Float_t ped, Float_t pedrms)
451{
452
453 fPed = ped;
454 fPedRms = pedrms;
455
456}
457
458// --------------------------------------------------------------------------
459//
460// 1) Fit the arrival times
461// 2) Retrieve the results
462// 3) Note that because of the low number of bins, the NDf is sometimes 0, so
463// Root does not give a reasonable Probability, the Chisquare is more significant
464//
465// This fit has to be done AFTER the Charges fit,
466// otherwise only the Hi Gain will be fitted, even if there are no entries
467//
468//
469Bool_t MCalibrationPix::FitTime()
470{
471
472 //
473 // Fit the Low Gain
474 //
475 if (fHiGainSaturation)
476 {
477 if(!fHist->FitTimeLoGain())
478 {
479 *fLog << warn << "Could not fit Lo Gain times of pixel " << fPixId << endl;
480 fHist->PrintTimeFitResult();
481 return kFALSE;
482 }
483 }
484
485 //
486 // Fit the High Gain
487 //
488 else
489 {
490 if(!fHist->FitTimeHiGain())
491 {
492 *fLog << warn << "Could not fit Hi Gain times of pixel " << fPixId << endl;
493 fHist->PrintTimeFitResult();
494 return kFALSE;
495 }
496 }
497
498 fTime = fHist->GetTimeMean();
499 fSigmaTime = fHist->GetTimeSigma();
500 fTimeChiSquare = fHist->GetTimeChiSquare();
501 fTimeProb = fHist->GetTimeProb();
502
503 if (!CheckTimeFitValidity())
504 fFitValid = kFALSE;
505
506 return kTRUE;
507}
508
Note: See TracBrowser for help on using the repository browser.