source: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindPix.h@ 7995

Last change on this file since 7995 was 6680, checked in by gaug, 20 years ago
*** empty log message ***
File size: 16.7 KB
Line 
1#ifndef MARS_MHCalibrationChargeBlindPix
2#define MARS_MHCalibrationChargeBlindPix
3
4#ifndef MARS_MHCalibrationPix
5#include "MHCalibrationPix.h"
6#endif
7
8#ifndef ROOT_TF1
9#include <TF1.h>
10#endif
11
12#ifndef ROOT_TVector
13#include <TVector.h>
14#endif
15
16class TH1F;
17class TPaveText;
18class TText;
19class MExtractedSignalBlindPixel;
20class MRawEvtPixelIter;
21
22class MHCalibrationChargeBlindPix : public MHCalibrationPix
23{
24private:
25
26 static const Float_t fgNumSinglePheLimit; //! Default for fNumSinglePheLimit (now set to: 50)
27 static const Float_t gkSignalInitializer; //! Signal initializer (-9999.)
28
29 static const Double_t gkElectronicAmp; // Electronic Amplification after the PMT (in FADC counts/N_e)
30 static const Double_t gkElectronicAmpErr; // Error of the electronic amplification
31
32 Float_t fSinglePheCut; // Value of summed FADC slices upon which event considered as single-phe
33 Float_t fNumSinglePheLimit; // Minimum number of single-phe events
34
35 TVector fASinglePheFADCSlices; //! Averaged FADC slice entries supposed single-phe events
36 TVector fAPedestalFADCSlices; //! Averaged FADC slice entries supposed pedestal events
37
38 TF1 *fSinglePheFit; // Single Phe Fit (Gaussians convoluted with Poisson)
39
40 UInt_t fNumSinglePhes; // Number of entries in fASinglePheFADCSlices
41 UInt_t fNumPedestals; // Number of entries in fAPedestalFADCSlices
42
43 Double_t fLambda; // Poisson mean from Single-phe fit
44 Double_t fLambdaCheck; // Poisson mean from Pedestal fit alone
45 Double_t fMu0; // Mean of the pedestal
46 Double_t fMu1; // Mean of single-phe peak
47 Double_t fSigma0; // Sigma of the pedestal
48 Double_t fSigma1; // Sigma of single-phe peak
49 Double_t fLambdaErr; // Error of Poisson mean from Single-phe fit
50 Double_t fLambdaCheckErr; // Error of Poisson mean from Pedestal fit alone
51 Double_t fMu0Err; // Error of Mean of the pedestal
52 Double_t fMu1Err; // Error of Mean of single-phe peak
53 Double_t fSigma0Err; // Error of Sigma of the pedestal
54 Double_t fSigma1Err; // Error of Sigma of single-phe peak
55 Double_t fChisquare; // Chisquare of single-phe fit
56 Int_t fNDF; // Ndof of single-phe fit
57 Double_t fProb; // Probability of singleo-phe fit
58
59 Byte_t fFlags; // Bit-field for the flags
60 enum { kSinglePheFitOK, kPedestalFitOK }; // Possible bits to be set
61
62public:
63
64 enum FitFunc_t { kEPoisson4, kEPoisson5,
65 kEPoisson6, kEPoisson7,
66 kEPolya, kEMichele }; // Possible fit functions types
67
68private:
69
70 FitFunc_t fFitFunc;
71
72 TPaveText *fFitLegend; //! Some legend to display the fit results
73 TH1F *fHSinglePheFADCSlices; // A histogram created and deleted only in Draw()
74 TH1F *fHPedestalFADCSlices; // A histogram created and deleted only in Draw()
75
76 // Fit
77 Bool_t InitFit();
78 void ExitFit();
79
80 void DrawLegend(Option_t *opt="");
81
82public:
83
84 MHCalibrationChargeBlindPix(const char *name=NULL, const char *title=NULL);
85 ~MHCalibrationChargeBlindPix();
86
87 void Clear(Option_t *o="");
88 void Reset() {}
89
90 // Getters
91 const Double_t GetLambda () const { return fLambda; }
92 const Double_t GetLambdaCheck () const { return fLambdaCheck; }
93 const Double_t GetMu0 () const { return fMu0; }
94 const Double_t GetMu1 () const { return fMu1; }
95 const Double_t GetSigma0 () const { return fSigma0; }
96 const Double_t GetSigma1 () const { return fSigma1; }
97 const Double_t GetLambdaErr () const { return fLambdaErr; }
98 const Double_t GetLambdaCheckErr() const { return fLambdaCheckErr; }
99 const Double_t GetMu0Err () const { return fMu0Err; }
100 const Double_t GetMu1Err () const { return fMu1Err; }
101 const Double_t GetSigma0Err () const { return fSigma0Err; }
102 const Double_t GetSigma1Err () const { return fSigma1Err; }
103 const Float_t GetSinglePheCut () const { return fSinglePheCut; }
104
105 TVector &GetASinglePheFADCSlices() { return fASinglePheFADCSlices; }
106 const TVector &GetASinglePheFADCSlices() const { return fASinglePheFADCSlices; }
107
108 TVector &GetAPedestalFADCSlices() { return fAPedestalFADCSlices; }
109 const TVector &GetAPedestalFADCSlices() const { return fAPedestalFADCSlices; }
110
111 const Bool_t IsSinglePheFitOK() const;
112 const Bool_t IsPedestalFitOK() const;
113
114 // Setters
115 void SetFitFunc ( const FitFunc_t func ) { fFitFunc = func; }
116 void SetSinglePheCut ( const Float_t cut = 0. ) { fSinglePheCut = cut; }
117 void SetNumSinglePheLimit ( const Float_t lim =fgNumSinglePheLimit ) { fNumSinglePheLimit = lim; }
118
119 void SetSinglePheFitOK ( const Bool_t b=kTRUE);
120 void SetPedestalFitOK ( const Bool_t b=kTRUE);
121
122 // Fill histos
123 void FillSinglePheFADCSlices(const MRawEvtPixelIter &iter);
124 void FillPedestalFADCSlices( const MRawEvtPixelIter &iter);
125 void FinalizeSinglePheSpectrum();
126
127 // Draws
128 void Draw(Option_t *opt="");
129
130 // Fits
131 Bool_t FitSinglePhe (Option_t *opt="RL0+Q");
132 void FitPedestal (Option_t *opt="RL0+Q");
133
134 // Simulation
135 Bool_t SimulateSinglePhe(const Double_t lambda,
136 const Double_t mu0, const Double_t mu1,
137 const Double_t sigma0, const Double_t sigma1);
138
139private:
140
141 inline static Double_t fFitFuncMichele(Double_t *x, Double_t *par)
142 {
143
144 Double_t lambda1cat = par[0];
145 Double_t lambda1dyn = par[1];
146 Double_t mu0 = par[2];
147 Double_t mu1cat = par[3];
148 Double_t mu1dyn = par[4];
149 Double_t sigma0 = par[5];
150 Double_t sigma1cat = par[6];
151 Double_t sigma1dyn = par[7];
152
153 Double_t sumcat = 0.;
154 Double_t sumdyn = 0.;
155 Double_t arg = 0.;
156
157 if (lambda1cat < lambda1dyn)
158 return FLT_MAX;
159
160 if (mu1cat < mu0)
161 return FLT_MAX;
162
163 if (mu1dyn < mu0)
164 return FLT_MAX;
165
166 if (mu1cat < mu1dyn)
167 return FLT_MAX;
168
169 if (sigma0 < 0.0001)
170 return FLT_MAX;
171
172 if (sigma1cat < sigma0)
173 return FLT_MAX;
174
175 if (sigma1dyn < sigma0)
176 return FLT_MAX;
177
178 Double_t mu2cat = (2.*mu1cat)-mu0;
179 Double_t mu2dyn = (2.*mu1dyn)-mu0;
180 Double_t mu3cat = (3.*mu1cat)-(2.*mu0);
181 Double_t mu3dyn = (3.*mu1dyn)-(2.*mu0);
182
183 Double_t sigma2cat = TMath::Sqrt((2.*sigma1cat*sigma1cat) - (sigma0*sigma0));
184 Double_t sigma2dyn = TMath::Sqrt((2.*sigma1dyn*sigma1dyn) - (sigma0*sigma0));
185 Double_t sigma3cat = TMath::Sqrt((3.*sigma1cat*sigma1cat) - (2.*sigma0*sigma0));
186 Double_t sigma3dyn = TMath::Sqrt((3.*sigma1dyn*sigma1dyn) - (2.*sigma0*sigma0));
187
188 Double_t lambda2cat = lambda1cat*lambda1cat;
189 Double_t lambda2dyn = lambda1dyn*lambda1dyn;
190 Double_t lambda3cat = lambda2cat*lambda1cat;
191 Double_t lambda3dyn = lambda2dyn*lambda1dyn;
192
193 // k=0:
194 arg = (x[0] - mu0)/sigma0;
195 sumcat = TMath::Exp(-0.5*arg*arg)/sigma0;
196 sumdyn = sumcat;
197
198 // k=1cat:
199 arg = (x[0] - mu1cat)/sigma1cat;
200 sumcat += lambda1cat*TMath::Exp(-0.5*arg*arg)/sigma1cat;
201 // k=1dyn:
202 arg = (x[0] - mu1dyn)/sigma1dyn;
203 sumdyn += lambda1dyn*TMath::Exp(-0.5*arg*arg)/sigma1dyn;
204
205 // k=2cat:
206 arg = (x[0] - mu2cat)/sigma2cat;
207 sumcat += 0.5*lambda2cat*TMath::Exp(-0.5*arg*arg)/sigma2cat;
208 // k=2dyn:
209 arg = (x[0] - mu2dyn)/sigma2dyn;
210 sumdyn += 0.5*lambda2dyn*TMath::Exp(-0.5*arg*arg)/sigma2dyn;
211
212
213 // k=3cat:
214 arg = (x[0] - mu3cat)/sigma3cat;
215 sumcat += 0.1666666667*lambda3cat*TMath::Exp(-0.5*arg*arg)/sigma3cat;
216 // k=3dyn:
217 arg = (x[0] - mu3dyn)/sigma3dyn;
218 sumdyn += 0.1666666667*lambda3dyn*TMath::Exp(-0.5*arg*arg)/sigma3dyn;
219
220 sumcat = TMath::Exp(-1.*lambda1cat)*sumcat;
221 sumdyn = TMath::Exp(-1.*lambda1dyn)*sumdyn;
222
223 return par[8]*(sumcat+sumdyn)/2.;
224
225 }
226
227 inline static Double_t fPoissonKto4(Double_t *x, Double_t *par)
228 {
229
230 Double_t lambda = par[0];
231
232 Double_t sum = 0.;
233 Double_t arg = 0.;
234
235 Double_t mu0 = par[1];
236 Double_t mu1 = par[2];
237
238 if (mu1 < mu0)
239 return FLT_MAX;
240
241 Double_t sigma0 = par[3];
242 Double_t sigma1 = par[4];
243
244 if (sigma0 < 0.0001)
245 return FLT_MAX;
246
247 if (sigma1 < sigma0)
248 return FLT_MAX;
249
250 Double_t mu2 = (2.*mu1)-mu0;
251 Double_t mu3 = (3.*mu1)-(2.*mu0);
252 Double_t mu4 = (4.*mu1)-(3.*mu0);
253
254 Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));
255 Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
256 Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
257
258 Double_t lambda2 = lambda*lambda;
259 Double_t lambda3 = lambda2*lambda;
260 Double_t lambda4 = lambda3*lambda;
261
262 // k=0:
263 arg = (x[0] - mu0)/sigma0;
264 sum = TMath::Exp(-0.5*arg*arg)/sigma0;
265
266 // k=1:
267 arg = (x[0] - mu1)/sigma1;
268 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
269
270 // k=2:
271 arg = (x[0] - mu2)/sigma2;
272 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
273
274 // k=3:
275 arg = (x[0] - mu3)/sigma3;
276 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
277
278 // k=4:
279 arg = (x[0] - mu4)/sigma4;
280 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
281
282 return TMath::Exp(-1.*lambda)*par[5]*sum;
283
284 }
285
286
287 inline static Double_t fPoissonKto5(Double_t *x, Double_t *par)
288 {
289
290 Double_t lambda = par[0];
291
292 Double_t sum = 0.;
293 Double_t arg = 0.;
294
295 Double_t mu0 = par[1];
296 Double_t mu1 = par[2];
297
298 if (mu1 < mu0)
299 return FLT_MAX;
300
301 Double_t sigma0 = par[3];
302 Double_t sigma1 = par[4];
303
304 if (sigma0 < 0.0001)
305 return FLT_MAX;
306
307 if (sigma1 < sigma0)
308 return FLT_MAX;
309
310
311 Double_t mu2 = (2.*mu1)-mu0;
312 Double_t mu3 = (3.*mu1)-(2.*mu0);
313 Double_t mu4 = (4.*mu1)-(3.*mu0);
314 Double_t mu5 = (5.*mu1)-(4.*mu0);
315
316 Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));
317 Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
318 Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
319 Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
320
321 Double_t lambda2 = lambda*lambda;
322 Double_t lambda3 = lambda2*lambda;
323 Double_t lambda4 = lambda3*lambda;
324 Double_t lambda5 = lambda4*lambda;
325
326 // k=0:
327 arg = (x[0] - mu0)/sigma0;
328 sum = TMath::Exp(-0.5*arg*arg)/sigma0;
329
330 // k=1:
331 arg = (x[0] - mu1)/sigma1;
332 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
333
334 // k=2:
335 arg = (x[0] - mu2)/sigma2;
336 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
337
338 // k=3:
339 arg = (x[0] - mu3)/sigma3;
340 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
341
342 // k=4:
343 arg = (x[0] - mu4)/sigma4;
344 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
345
346 // k=5:
347 arg = (x[0] - mu5)/sigma5;
348 sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
349
350 return TMath::Exp(-1.*lambda)*par[5]*sum;
351
352 }
353
354
355 inline static Double_t fPoissonKto6(Double_t *x, Double_t *par)
356 {
357
358 Double_t lambda = par[0];
359
360 Double_t sum = 0.;
361 Double_t arg = 0.;
362
363 Double_t mu0 = par[1];
364 Double_t mu1 = par[2];
365
366 if (mu1 < mu0)
367 return FLT_MAX;
368
369 Double_t sigma0 = par[3];
370 Double_t sigma1 = par[4];
371
372 if (sigma0 < 0.0001)
373 return FLT_MAX;
374
375 if (sigma1 < sigma0)
376 return FLT_MAX;
377
378
379 Double_t mu2 = (2.*mu1)-mu0;
380 Double_t mu3 = (3.*mu1)-(2.*mu0);
381 Double_t mu4 = (4.*mu1)-(3.*mu0);
382 Double_t mu5 = (5.*mu1)-(4.*mu0);
383 Double_t mu6 = (6.*mu1)-(5.*mu0);
384
385 Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));
386 Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
387 Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
388 Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
389 Double_t sigma6 = TMath::Sqrt((6.*sigma1*sigma1) - (5.*sigma0*sigma0));
390
391 Double_t lambda2 = lambda*lambda;
392 Double_t lambda3 = lambda2*lambda;
393 Double_t lambda4 = lambda3*lambda;
394 Double_t lambda5 = lambda4*lambda;
395 Double_t lambda6 = lambda5*lambda;
396
397 // k=0:
398 arg = (x[0] - mu0)/sigma0;
399 sum = TMath::Exp(-0.5*arg*arg)/sigma0;
400
401 // k=1:
402 arg = (x[0] - mu1)/sigma1;
403 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
404
405 // k=2:
406 arg = (x[0] - mu2)/sigma2;
407 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
408
409 // k=3:
410 arg = (x[0] - mu3)/sigma3;
411 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
412
413 // k=4:
414 arg = (x[0] - mu4)/sigma4;
415 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
416
417 // k=5:
418 arg = (x[0] - mu5)/sigma5;
419 sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
420
421 // k=6:
422 arg = (x[0] - mu6)/sigma6;
423 sum += 0.001388888888889*lambda6*TMath::Exp(-0.5*arg*arg)/sigma6;
424
425 return TMath::Exp(-1.*lambda)*par[5]*sum;
426
427 }
428
429 inline static Double_t fPolya(Double_t *x, Double_t *par)
430 {
431
432 const Double_t QEcat = 0.247; // mean quantum efficiency
433 const Double_t sqrt2 = 1.4142135623731;
434 const Double_t sqrt3 = 1.7320508075689;
435 const Double_t sqrt4 = 2.;
436
437 const Double_t lambda = par[0]; // mean number of photons
438
439 const Double_t excessPoisson = par[1]; // non-Poissonic noise contribution
440 const Double_t delta1 = par[2]; // amplification first dynode
441 const Double_t delta2 = par[3]; // amplification subsequent dynodes
442
443 const Double_t electronicAmpl = par[4]; // electronic amplification and conversion to FADC charges
444
445 const Double_t pmtAmpl = delta1*delta2*delta2*delta2*delta2*delta2; // total PMT gain
446 const Double_t A = 1. + excessPoisson - QEcat
447 + 1./delta1
448 + 1./delta1/delta2
449 + 1./delta1/delta2/delta2; // variance contributions from PMT and QE
450
451 const Double_t totAmpl = QEcat*pmtAmpl*electronicAmpl; // Total gain and conversion
452
453 const Double_t mu0 = par[7]; // pedestal
454 const Double_t mu1 = totAmpl; // single phe position
455 const Double_t mu2 = 2*totAmpl; // double phe position
456 const Double_t mu3 = 3*totAmpl; // triple phe position
457 const Double_t mu4 = 4*totAmpl; // quadruple phe position
458
459 const Double_t sigma0 = par[5];
460 const Double_t sigma1 = electronicAmpl*pmtAmpl*TMath::Sqrt(QEcat*A);
461 const Double_t sigma2 = sqrt2*sigma1;
462 const Double_t sigma3 = sqrt3*sigma1;
463 const Double_t sigma4 = sqrt4*sigma1;
464
465 const Double_t lambda2 = lambda*lambda;
466 const Double_t lambda3 = lambda2*lambda;
467 const Double_t lambda4 = lambda3*lambda;
468
469 //-- calculate the area----
470 Double_t arg = (x[0] - mu0)/sigma0;
471 Double_t sum = TMath::Exp(-0.5*arg*arg)/sigma0;
472
473 // k=1:
474 arg = (x[0] - mu1)/sigma1;
475 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
476
477 // k=2:
478 arg = (x[0] - mu2)/sigma2;
479 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
480
481 // k=3:
482 arg = (x[0] - mu3)/sigma3;
483 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
484
485 // k=4:
486 arg = (x[0] - mu4)/sigma4;
487 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
488
489 return TMath::Exp(-1.*lambda)*par[6]*sum;
490 }
491
492 ClassDef(MHCalibrationChargeBlindPix, 1) // Histogram class for Charge Blind Pixel Calibration
493};
494
495#endif /* MARS_MHCalibrationChargeBlindPix */
Note: See TracBrowser for help on using the repository browser.