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

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