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

Last change on this file since 4240 was 4228, checked in by gaug, 21 years ago
*** empty log message ***
File size: 18.0 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 Double_t offset = par[9];
178
179 Double_t sumcat = 0.;
180 Double_t sumdyn = 0.;
181 Double_t arg = 0.;
182
183 if (lambda1cat < lambda1dyn)
184 return FLT_MAX;
185
186 if (mu1cat < mu0)
187 return FLT_MAX;
188
189 if (mu1dyn < mu0)
190 return FLT_MAX;
191
192 if (mu1cat < mu1dyn)
193 return FLT_MAX;
194
195 if (sigma0 < 0.0001)
196 return FLT_MAX;
197
198 if (sigma1cat < sigma0)
199 return FLT_MAX;
200
201 if (sigma1dyn < sigma0)
202 return FLT_MAX;
203
204 Double_t mu2cat = (2.*mu1cat)-mu0;
205 Double_t mu2dyn = (2.*mu1dyn)-mu0;
206 Double_t mu3cat = (3.*mu1cat)-(2.*mu0);
207 Double_t mu3dyn = (3.*mu1dyn)-(2.*mu0);
208
209 Double_t sigma2cat = TMath::Sqrt((2.*sigma1cat*sigma1cat) - (sigma0*sigma0));
210 Double_t sigma2dyn = TMath::Sqrt((2.*sigma1dyn*sigma1dyn) - (sigma0*sigma0));
211 Double_t sigma3cat = TMath::Sqrt((3.*sigma1cat*sigma1cat) - (2.*sigma0*sigma0));
212 Double_t sigma3dyn = TMath::Sqrt((3.*sigma1dyn*sigma1dyn) - (2.*sigma0*sigma0));
213
214 Double_t lambda2cat = lambda1cat*lambda1cat;
215 Double_t lambda2dyn = lambda1dyn*lambda1dyn;
216 Double_t lambda3cat = lambda2cat*lambda1cat;
217 Double_t lambda3dyn = lambda2dyn*lambda1dyn;
218
219 // k=0:
220 arg = (x[0] - mu0)/sigma0;
221 sumcat = TMath::Exp(-0.5*arg*arg)/sigma0;
222 sumdyn =sumcat;
223
224 // k=1cat:
225 arg = (x[0] - mu1cat)/sigma1cat;
226 sumcat += lambda1cat*TMath::Exp(-0.5*arg*arg)/sigma1cat;
227 // k=1dyn:
228 arg = (x[0] - mu1dyn)/sigma1dyn;
229 sumdyn += lambda1dyn*TMath::Exp(-0.5*arg*arg)/sigma1dyn;
230
231 // k=2cat:
232 arg = (x[0] - mu2cat)/sigma2cat;
233 sumcat += 0.5*lambda2cat*TMath::Exp(-0.5*arg*arg)/sigma2cat;
234 // k=2dyn:
235 arg = (x[0] - mu2dyn)/sigma2dyn;
236 sumdyn += 0.5*lambda2dyn*TMath::Exp(-0.5*arg*arg)/sigma2dyn;
237
238
239 // k=3cat:
240 arg = (x[0] - mu3cat)/sigma3cat;
241 sumcat += 0.1666666667*lambda3cat*TMath::Exp(-0.5*arg*arg)/sigma3cat;
242 // k=3dyn:
243 arg = (x[0] - mu3dyn)/sigma3dyn;
244 sumdyn += 0.1666666667*lambda3dyn*TMath::Exp(-0.5*arg*arg)/sigma3dyn;
245
246 sumcat = TMath::Exp(-1.*lambda1cat)*sumcat;
247 sumdyn = TMath::Exp(-1.*lambda1dyn)*sumdyn;
248
249 return par[8]*(sumcat+sumdyn)/2. + offset;
250
251 }
252
253 inline static Double_t fPoissonKto4(Double_t *x, Double_t *par)
254 {
255
256 Double_t lambda = par[0];
257
258 Double_t sum = 0.;
259 Double_t arg = 0.;
260
261 Double_t mu0 = par[1];
262 Double_t mu1 = par[2];
263
264 if (mu1 < mu0)
265 return FLT_MAX;
266
267 Double_t sigma0 = par[3];
268 Double_t sigma1 = par[4];
269
270 if (sigma0 < 0.0001)
271 return FLT_MAX;
272
273 if (sigma1 < sigma0)
274 return FLT_MAX;
275
276 Double_t mu2 = (2.*mu1)-mu0;
277 Double_t mu3 = (3.*mu1)-(2.*mu0);
278 Double_t mu4 = (4.*mu1)-(3.*mu0);
279
280 Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));
281 Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
282 Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
283
284 Double_t lambda2 = lambda*lambda;
285 Double_t lambda3 = lambda2*lambda;
286 Double_t lambda4 = lambda3*lambda;
287
288 // k=0:
289 arg = (x[0] - mu0)/sigma0;
290 sum = TMath::Exp(-0.5*arg*arg)/sigma0;
291
292 // k=1:
293 arg = (x[0] - mu1)/sigma1;
294 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
295
296 // k=2:
297 arg = (x[0] - mu2)/sigma2;
298 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
299
300 // k=3:
301 arg = (x[0] - mu3)/sigma3;
302 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
303
304 // k=4:
305 arg = (x[0] - mu4)/sigma4;
306 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
307
308 return TMath::Exp(-1.*lambda)*par[5]*sum;
309
310 }
311
312
313 inline static Double_t fPoissonKto5(Double_t *x, Double_t *par)
314 {
315
316 Double_t lambda = par[0];
317
318 Double_t sum = 0.;
319 Double_t arg = 0.;
320
321 Double_t mu0 = par[1];
322 Double_t mu1 = par[2];
323
324 if (mu1 < mu0)
325 return FLT_MAX;
326
327 Double_t sigma0 = par[3];
328 Double_t sigma1 = par[4];
329
330 if (sigma0 < 0.0001)
331 return FLT_MAX;
332
333 if (sigma1 < sigma0)
334 return FLT_MAX;
335
336
337 Double_t mu2 = (2.*mu1)-mu0;
338 Double_t mu3 = (3.*mu1)-(2.*mu0);
339 Double_t mu4 = (4.*mu1)-(3.*mu0);
340 Double_t mu5 = (5.*mu1)-(4.*mu0);
341
342 Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));
343 Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
344 Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
345 Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
346
347 Double_t lambda2 = lambda*lambda;
348 Double_t lambda3 = lambda2*lambda;
349 Double_t lambda4 = lambda3*lambda;
350 Double_t lambda5 = lambda4*lambda;
351
352 // k=0:
353 arg = (x[0] - mu0)/sigma0;
354 sum = TMath::Exp(-0.5*arg*arg)/sigma0;
355
356 // k=1:
357 arg = (x[0] - mu1)/sigma1;
358 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
359
360 // k=2:
361 arg = (x[0] - mu2)/sigma2;
362 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
363
364 // k=3:
365 arg = (x[0] - mu3)/sigma3;
366 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
367
368 // k=4:
369 arg = (x[0] - mu4)/sigma4;
370 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
371
372 // k=5:
373 arg = (x[0] - mu5)/sigma5;
374 sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
375
376 return TMath::Exp(-1.*lambda)*par[5]*sum;
377
378 }
379
380
381 inline static Double_t fPoissonKto6(Double_t *x, Double_t *par)
382 {
383
384 Double_t lambda = par[0];
385
386 Double_t sum = 0.;
387 Double_t arg = 0.;
388
389 Double_t mu0 = par[1];
390 Double_t mu1 = par[2];
391
392 if (mu1 < mu0)
393 return FLT_MAX;
394
395 Double_t sigma0 = par[3];
396 Double_t sigma1 = par[4];
397
398 if (sigma0 < 0.0001)
399 return FLT_MAX;
400
401 if (sigma1 < sigma0)
402 return FLT_MAX;
403
404
405 Double_t mu2 = (2.*mu1)-mu0;
406 Double_t mu3 = (3.*mu1)-(2.*mu0);
407 Double_t mu4 = (4.*mu1)-(3.*mu0);
408 Double_t mu5 = (5.*mu1)-(4.*mu0);
409 Double_t mu6 = (6.*mu1)-(5.*mu0);
410
411 Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));
412 Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
413 Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
414 Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
415 Double_t sigma6 = TMath::Sqrt((6.*sigma1*sigma1) - (5.*sigma0*sigma0));
416
417 Double_t lambda2 = lambda*lambda;
418 Double_t lambda3 = lambda2*lambda;
419 Double_t lambda4 = lambda3*lambda;
420 Double_t lambda5 = lambda4*lambda;
421 Double_t lambda6 = lambda5*lambda;
422
423 // k=0:
424 arg = (x[0] - mu0)/sigma0;
425 sum = TMath::Exp(-0.5*arg*arg)/sigma0;
426
427 // k=1:
428 arg = (x[0] - mu1)/sigma1;
429 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
430
431 // k=2:
432 arg = (x[0] - mu2)/sigma2;
433 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
434
435 // k=3:
436 arg = (x[0] - mu3)/sigma3;
437 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
438
439 // k=4:
440 arg = (x[0] - mu4)/sigma4;
441 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
442
443 // k=5:
444 arg = (x[0] - mu5)/sigma5;
445 sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
446
447 // k=6:
448 arg = (x[0] - mu6)/sigma6;
449 sum += 0.001388888888889*lambda6*TMath::Exp(-0.5*arg*arg)/sigma6;
450
451 return TMath::Exp(-1.*lambda)*par[5]*sum;
452
453 }
454
455 inline static Double_t fPolya(Double_t *x, Double_t *par)
456 {
457
458 const Double_t QEcat = 0.247; // mean quantum efficiency
459 const Double_t sqrt2 = 1.4142135623731;
460 const Double_t sqrt3 = 1.7320508075689;
461 const Double_t sqrt4 = 2.;
462
463 const Double_t lambda = par[0]; // mean number of photons
464
465 const Double_t excessPoisson = par[1]; // non-Poissonic noise contribution
466 const Double_t delta1 = par[2]; // amplification first dynode
467 const Double_t delta2 = par[3]; // amplification subsequent dynodes
468
469 const Double_t electronicAmpl = par[4]; // electronic amplification and conversion to FADC charges
470
471 const Double_t pmtAmpl = delta1*delta2*delta2*delta2*delta2*delta2; // total PMT gain
472 const Double_t A = 1. + excessPoisson - QEcat
473 + 1./delta1
474 + 1./delta1/delta2
475 + 1./delta1/delta2/delta2; // variance contributions from PMT and QE
476
477 const Double_t totAmpl = QEcat*pmtAmpl*electronicAmpl; // Total gain and conversion
478
479 const Double_t mu0 = par[7]; // pedestal
480 const Double_t mu1 = totAmpl; // single phe position
481 const Double_t mu2 = 2*totAmpl; // double phe position
482 const Double_t mu3 = 3*totAmpl; // triple phe position
483 const Double_t mu4 = 4*totAmpl; // quadruple phe position
484
485 const Double_t sigma0 = par[5];
486 const Double_t sigma1 = electronicAmpl*pmtAmpl*TMath::Sqrt(QEcat*A);
487 const Double_t sigma2 = sqrt2*sigma1;
488 const Double_t sigma3 = sqrt3*sigma1;
489 const Double_t sigma4 = sqrt4*sigma1;
490
491 const Double_t lambda2 = lambda*lambda;
492 const Double_t lambda3 = lambda2*lambda;
493 const Double_t lambda4 = lambda3*lambda;
494
495 //-- calculate the area----
496 Double_t arg = (x[0] - mu0)/sigma0;
497 Double_t sum = TMath::Exp(-0.5*arg*arg)/sigma0;
498
499 // k=1:
500 arg = (x[0] - mu1)/sigma1;
501 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
502
503 // k=2:
504 arg = (x[0] - mu2)/sigma2;
505 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
506
507 // k=3:
508 arg = (x[0] - mu3)/sigma3;
509 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
510
511 // k=4:
512 arg = (x[0] - mu4)/sigma4;
513 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
514
515 return TMath::Exp(-1.*lambda)*par[6]*sum;
516 }
517
518
519
520 ClassDef(MHCalibrationChargeBlindPix, 1) // Histogram class for Charge Blind Pixel Calibration
521};
522
523#endif /* MARS_MHCalibrationChargeBlindPix */
Note: See TracBrowser for help on using the repository browser.