source: trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc@ 2732

Last change on this file since 2732 was 2725, checked in by gaug, 22 years ago
*** empty log message ***
File size: 13.7 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 fit is 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//
142// The conversion factor after the F-Factor method is declared valid, if:
143//
144// 1) fFitValid is kTRUE
145// 2) Conversion Factor is bigger than 0.
146// 3) The error of the conversion factor is smaller than 10%
147//
148Bool_t MCalibrationPix::FitCharge()
149{
150
151 //
152 // 1) Return if the charge distribution is already succesfully fitted
153 //
154 if (fHist->IsFitOK())
155 return kTRUE;
156
157 //
158 // 2) Set a lower Fit range according to 1.5 Pedestal RMS in order to avoid
159 // possible remaining cosmics to spoil the fit.
160 //
161 if (fPed && fPedRms)
162 fHist->SetLowerFitRange(1.5*fPedRms);
163 else
164 *fLog << warn << "Cannot set lower fit range: Pedestals not available" << endl;
165
166 //
167 // 3) Decide if the LoGain Histogram is fitted or the HiGain Histogram
168 //
169 if (fHist->UseLoGain())
170 {
171
172 SetHiGainSaturation();
173
174 //
175 // 4) Fit the Lo Gain histograms with a Gaussian
176 //
177 if(!fHist->FitChargeLoGain())
178 {
179 *fLog << warn << "Could not fit Lo Gain charges of pixel " << fPixId << endl;
180 //
181 // 5) In case of failure print out the fit results
182 //
183 fHist->PrintChargeFitResult();
184 }
185 }
186 else
187 {
188 //
189 // 4) Fit the Hi Gain histograms with a Gaussian
190 //
191 if(!fHist->FitChargeHiGain())
192 {
193 *fLog << warn << "Could not fit Hi Gain charges of pixel " << fPixId << endl;
194 //
195 // 5) In case of failure print out the fit results
196 //
197 fHist->PrintChargeFitResult();
198 }
199 }
200
201
202 //
203 // 6) Retrieve the results and store them in this class
204 //
205 fCharge = fHist->GetChargeMean();
206 fErrCharge = fHist->GetChargeMeanErr();
207 fSigmaCharge = fHist->GetChargeSigma();
208 fErrSigmaCharge = fHist->GetChargeSigmaErr();
209 fChargeProb = fHist->GetChargeProb();
210
211 if (fCharge <= 0.)
212 {
213 *fLog << warn << "Cannot apply calibration: Mean Fitted Charges are smaller than 0 in pixel "
214 << fPixId << endl;
215 return kFALSE;
216 }
217
218 if (fErrCharge > 0.)
219 fFitted = kTRUE;
220
221
222 if (fHiGainSaturation)
223 {
224 if ( (fCharge > 0.3*GetPedRms()) &&
225 (fErrCharge > 0.) &&
226 (fHist->IsFitOK()) &&
227 (fSigmaCharge > fPedRms/fConversionHiLo) &&
228 (fTime > fHist->GetTimeLowerFitRange()+1.) &&
229 (fTime < fHist->GetTimeUpperFitRange()-1.) )
230 fFitValid = kTRUE;
231 }
232 else
233 {
234 if ( (fCharge > 3.*GetPedRms()) &&
235 (fErrCharge > 0.) &&
236 (fHist->IsFitOK()) &&
237 (fSigmaCharge > fPedRms) &&
238 (fTime > fHist->GetTimeLowerFitRange()+1.) &&
239 (fTime < fHist->GetTimeUpperFitRange()-1.) )
240 fFitValid = kTRUE;
241 }
242
243 //
244 // 7) Calculate the number of photo-electrons after the F-Factor method
245 // 8) Calculate the errors of the F-Factor method
246 //
247 if ((fPed > 0.) && (fPedRms > 0.))
248 {
249
250 //
251 // Square all variables in order to avoid applications of square root
252 //
253 // First the relative error squares
254 //
255 const Float_t chargeSquare = fCharge* fCharge;
256 const Float_t chargeSquareRelErrSquare = 4.*fErrCharge*fErrCharge / chargeSquare;
257
258 const Float_t fFactorRelErrSquare = fFactorError * fFactorError / (fFactor * fFactor);
259 //
260 // Now the absolute error squares
261 //
262 const Float_t sigmaSquare = fSigmaCharge* fSigmaCharge;
263 const Float_t sigmaSquareErrSquare = 4.*fErrSigmaCharge*fErrSigmaCharge * sigmaSquare;
264
265 const Float_t elecRmsSquare = fElectronicPedRms* fElectronicPedRms;
266 const Float_t elecRmsSquareErrSquare = 4.*fErrElectronicPedRms*fErrElectronicPedRms * elecRmsSquare;
267
268 Float_t pedRmsSquare = fPedRms* fPedRms;
269 Float_t pedRmsSquareErrSquare = 4.*fErrPedRms*fErrPedRms * pedRmsSquare;
270
271 if (fHiGainSaturation)
272 {
273
274 //
275 // We do not know the Lo Gain Pedestal RMS, so we have to retrieve it
276 // from the Hi Gain:
277 //
278 // We extract the pure NSB contribution:
279 //
280 Float_t nsbSquare = pedRmsSquare - elecRmsSquare;
281 Float_t nsbSquareRelErrSquare = (pedRmsSquareErrSquare + elecRmsSquareErrSquare)
282 / (nsbSquare * nsbSquare) ;
283
284 if (nsbSquare < 0.)
285 nsbSquare = 0.;
286
287 //
288 // Now, we divide the NSB by the conversion factor and
289 // add it quadratically to the electronic noise
290 //
291 const Float_t conversionSquare = fConversionHiLo *fConversionHiLo;
292 const Float_t conversionSquareRelErrSquare = 4.*fConversionHiLoError*fConversionHiLoError/conversionSquare;
293
294 //
295 // Calculate the new "Pedestal RMS"
296 //
297 const Float_t convertedNsbSquare = nsbSquare / conversionSquare;
298 const Float_t convertedNsbSquareErrSquare = (nsbSquareRelErrSquare + conversionSquareRelErrSquare)
299 * convertedNsbSquare * convertedNsbSquare;
300
301 pedRmsSquare = convertedNsbSquare + elecRmsSquare;
302 pedRmsSquareErrSquare = convertedNsbSquareErrSquare + elecRmsSquareErrSquare;
303
304 } /* if (fHiGainSaturation) */
305
306 //
307 // Calculate the reduced sigmas
308 //
309 fRSigmaSquare = sigmaSquare - pedRmsSquare;
310 if (fRSigmaSquare <= 0.)
311 {
312 *fLog << warn << "Cannot apply F-Factor calibration: Reduced Sigma smaller than 0 in pixel "
313 << fPixId << endl;
314 if (fHiGainSaturation)
315 ApplyLoGainConversion();
316 return kFALSE;
317 }
318
319 const Float_t rSigmaSquareRelErrSquare = (sigmaSquareErrSquare + pedRmsSquareErrSquare)
320 / (fRSigmaSquare * fRSigmaSquare) ;
321
322 //
323 // Calculate the number of phe's from the F-Factor method
324 // (independent on Hi Gain or Lo Gain)
325 //
326 fPheFFactorMethod = fFactor * chargeSquare / fRSigmaSquare;
327
328 const Float_t pheFFactorRelErrSquare = fFactorRelErrSquare
329 + chargeSquareRelErrSquare
330 + rSigmaSquareRelErrSquare ;
331
332 fPheFFactorMethodError = TMath::Sqrt(pheFFactorRelErrSquare) * fPheFFactorMethod;
333
334 //
335 // Calculate the conversion factors
336 //
337 if (fHiGainSaturation)
338 ApplyLoGainConversion();
339
340 const Float_t chargeRelErrSquare = fErrCharge*fErrCharge / (fCharge * fCharge);
341
342 fConversionFFactorMethod = fPheFFactorMethod / fCharge ;
343 fConversionErrorFFactorMethod = ( pheFFactorRelErrSquare + chargeRelErrSquare )
344 * fConversionFFactorMethod * fConversionFFactorMethod;
345
346 if ( IsFitValid() &&
347 (fConversionFFactorMethod > 0.) &&
348 (fConversionErrorFFactorMethod/fConversionFFactorMethod < 0.1) )
349 fFFactorMethodValid = kTRUE;
350
351
352 } /* if ((fPed > 0.) && (fPedRms > 0.)) */
353
354 return kTRUE;
355
356}
357
358
359void MCalibrationPix::ApplyLoGainConversion()
360{
361
362 const Float_t chargeRelErrSquare = fErrCharge*fErrCharge
363 /( fCharge * fCharge);
364 const Float_t sigmaRelErrSquare = fErrSigmaCharge*fErrSigmaCharge
365 /( fSigmaCharge * fSigmaCharge);
366 const Float_t conversionRelErrSquare = fConversionHiLoError*fConversionHiLoError
367 /(fConversionHiLo * fConversionHiLo);
368
369 fCharge *= fConversionHiLo;
370 fErrCharge = TMath::Sqrt(chargeRelErrSquare + conversionRelErrSquare) * fCharge;
371
372 fSigmaCharge *= fConversionHiLo;
373 fErrSigmaCharge = TMath::Sqrt(sigmaRelErrSquare + conversionRelErrSquare) * fSigmaCharge;
374
375}
376
377
378// --------------------------------------------------------------------------
379//
380// Set the pedestals from outside
381//
382void MCalibrationPix::SetPedestal(Float_t ped, Float_t pedrms)
383{
384
385 fPed = ped;
386 fPedRms = pedrms;
387
388}
389
390// --------------------------------------------------------------------------
391//
392// 1) Fit the arrival times
393// 2) Retrieve the results
394// 3) Note that because of the low number of bins, the NDf is sometimes 0, so
395// Root does not give a reasonable Probability, the Chisquare is more significant
396//
397// This fit has to be done AFTER the Charges fit,
398// otherwise only the Hi Gain will be fitted, even if there are no entries
399//
400//
401Bool_t MCalibrationPix::FitTime()
402{
403
404 //
405 // Fit the Low Gain
406 //
407 if (fHiGainSaturation)
408 {
409 if(!fHist->FitTimeLoGain())
410 {
411 *fLog << warn << "Could not fit Lo Gain times of pixel " << fPixId << endl;
412 fHist->PrintTimeFitResult();
413 return kFALSE;
414 }
415 }
416
417 //
418 // Fit the High Gain
419 //
420 else
421 {
422 if(!fHist->FitTimeHiGain())
423 {
424 *fLog << warn << "Could not fit Hi Gain times of pixel " << fPixId << endl;
425 fHist->PrintTimeFitResult();
426 return kFALSE;
427 }
428 }
429
430 fTime = fHist->GetTimeMean();
431 fSigmaTime = fHist->GetTimeSigma();
432 fTimeChiSquare = fHist->GetTimeChiSquare();
433
434 return kTRUE;
435}
436
Note: See TracBrowser for help on using the repository browser.