source: trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.h@ 3639

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