source: trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.h@ 3032

Last change on this file since 3032 was 2997, checked in by gaug, 21 years ago
*** empty log message ***
File size: 15.2 KB
Line 
1#ifndef MARS_MHCalibrationBlindPixel
2#define MARS_MHCalibrationBlindPixel
3
4#ifndef MARS_MH
5#include "MH.h"
6#endif
7
8class TH1F;
9class TH1I;
10class TF1;
11class TPaveText;
12
13class TMath;
14class MParList;
15class MHCalibrationBlindPixel : public MH
16{
17private:
18
19 static const Int_t fgBlindPixelChargeNbins;
20 static const Int_t fgBlindPixelTimeNbins;
21 static const Int_t fgBlindPixelChargevsNbins;
22 static const Axis_t fgBlindPixelTimeFirst;
23 static const Axis_t fgBlindPixelTimeLast;
24 static const Double_t fgBlindPixelElectronicAmp;
25 static const Double_t fgBlindPixelElectronicAmpError;
26
27 TH1F* fHBlindPixelCharge; // Histogram with the single Phe spectrum
28 TH1F* fHBlindPixelTime; // Variance of summed FADC slices
29 TH1I* fHBlindPixelChargevsN; // Summed Charge vs. Event Nr.
30 TH1F* fHBlindPixelPSD; // Power spectrum density of fHBlindPixelChargevsN
31
32 TF1 *fSinglePheFit;
33 TF1 *fTimeGausFit;
34 TF1 *fSinglePhePedFit;
35
36 Axis_t fBlindPixelChargefirst;
37 Axis_t fBlindPixelChargelast;
38
39 void DrawLegend();
40
41 TPaveText *fFitLegend;
42 Bool_t fFitOK;
43
44 Double_t fLambda;
45 Double_t fMu0;
46 Double_t fMu1;
47 Double_t fSigma0;
48 Double_t fSigma1;
49
50 Double_t fLambdaErr;
51 Double_t fMu0Err;
52 Double_t fMu1Err;
53 Double_t fSigma0Err;
54 Double_t fSigma1Err;
55
56 Double_t fChisquare;
57 Double_t fProb;
58 Int_t fNdf;
59
60 Double_t fMeanTime;
61 Double_t fMeanTimeErr;
62 Double_t fSigmaTime;
63 Double_t fSigmaTimeErr;
64
65 Double_t fLambdaCheck;
66 Double_t fLambdaCheckErr;
67
68 Double_t fMeanPedestal;
69 Double_t fMeanPedestalErr;
70 Double_t fSigmaPedestal;
71 Double_t fSigmaPedestalErr;
72
73public:
74
75 MHCalibrationBlindPixel(const char *name=NULL, const char *title=NULL);
76 ~MHCalibrationBlindPixel();
77
78 void Clear(Option_t *o="");
79 void Reset();
80
81 Bool_t FillBlindPixelCharge(Float_t q);
82 Bool_t FillBlindPixelTime(Float_t t);
83 Bool_t FillBlindPixelChargevsN(Stat_t rq, Int_t t);
84
85 // Setters
86 void SetMeanPedestal(const Float_t f) { fMeanPedestal = f; }
87 void SetMeanPedestalErr(const Float_t f) { fMeanPedestalErr = f; }
88 void SetSigmaPedestal(const Float_t f) { fSigmaPedestal = f; }
89 void SetSigmaPedestalErr(const Float_t f) { fSigmaPedestalErr = f; }
90
91 // Getters
92 const Double_t GetLambda() const { return fLambda; }
93 const Double_t GetLambdaCheck() const { return fLambdaCheck; }
94 const Double_t GetMu0() const { return fMu0; }
95 const Double_t GetMu1() const { return fMu1; }
96 const Double_t GetSigma0() const { return fSigma0; }
97 const Double_t GetSigma1() const { return fSigma1; }
98
99 const Double_t GetLambdaErr() const { return fLambdaErr; }
100 const Double_t GetLambdaCheckErr() const { return fLambdaCheckErr; }
101 const Double_t GetMu0Err() const { return fMu0Err; }
102 const Double_t GetMu1Err() const { return fMu1Err; }
103 const Double_t GetSigma0Err() const { return fSigma0Err; }
104 const Double_t GetSigma1Err() const { return fSigma1Err; }
105
106 const Double_t GetChiSquare() const { return fChisquare; }
107 const Double_t GetProb() const { return fProb; }
108 const Int_t GetNdf() const { return fNdf; }
109
110 const Double_t GetMeanTime() const { return fMeanTime; }
111 const Double_t GetMeanTimeErr() const { return fMeanTimeErr; }
112 const Double_t GetSigmaTime() const { return fSigmaTime; }
113 const Double_t GetSigmaTimeErr() const { return fSigmaTimeErr; }
114
115 const Bool_t IsFitOK() const { return fFitOK; }
116
117 const TH1I *GetHBlindPixelChargevsN() const { return fHBlindPixelChargevsN; }
118 const TH1F *GetHBlindPixelPSD() const { return fHBlindPixelPSD; }
119
120 // Draws
121 TObject *DrawClone(Option_t *option="") const;
122 void Draw(Option_t *option="");
123
124 // Fits
125 enum FitFunc_t { kEPoisson4, kEPoisson5, kEPoisson6, kEPoisson7, kEPolya, kEMichele };
126
127private:
128 FitFunc_t fFitFunc;
129
130public:
131 Bool_t FitSinglePhe(Axis_t rmin=0, Axis_t rmax=0, Option_t *opt="RL0+Q");
132 Bool_t FitTime(Axis_t rmin=0., Axis_t rmax=0.,Option_t *opt="R0+Q");
133 void ChangeFitFunc(FitFunc_t func) { fFitFunc = func; }
134
135 // Simulation
136 Bool_t SimulateSinglePhe(Double_t lambda,
137 Double_t mu0,Double_t mu1,
138 Double_t sigma0,Double_t sigma1);
139
140 // Others
141 void CutAllEdges();
142
143private:
144
145 const static Double_t fNoWay = 10000000000.0;
146
147 Bool_t InitFit(Axis_t min, Axis_t max);
148 void ExitFit(TF1 *f);
149
150 inline static Double_t fFitFuncMichele(Double_t *x, Double_t *par)
151 {
152
153 Double_t lambda1cat = par[0];
154 Double_t lambda1dyn = par[1];
155 Double_t mu0 = par[2];
156 Double_t mu1cat = par[3];
157 Double_t mu1dyn = par[4];
158 Double_t sigma0 = par[5];
159 Double_t sigma1cat = par[6];
160 Double_t sigma1dyn = par[7];
161
162 Double_t sumcat = 0.;
163 Double_t sumdyn = 0.;
164 Double_t arg = 0.;
165
166 if (mu1cat < mu0)
167 return fNoWay;
168
169 if (sigma1cat < sigma0)
170 return fNoWay;
171
172 // if (sigma1cat < sigma1dyn)
173 // return NoWay;
174
175 //if (mu1cat < mu1dyn)
176 // return NoWay;
177
178 // if (lambda1cat < lambda1dyn)
179 // return NoWay;
180
181 Double_t mu2cat = (2.*mu1cat)-mu0;
182 Double_t mu2dyn = (2.*mu1dyn)-mu0;
183 Double_t mu3cat = (3.*mu1cat)-(2.*mu0);
184 Double_t mu3dyn = (3.*mu1dyn)-(2.*mu0);
185
186 Double_t sigma2cat = TMath::Sqrt((2.*sigma1cat*sigma1cat) - (sigma0*sigma0));
187 Double_t sigma2dyn = TMath::Sqrt((2.*sigma1dyn*sigma1dyn) - (sigma0*sigma0));
188 Double_t sigma3cat = TMath::Sqrt((3.*sigma1cat*sigma1cat) - (2.*sigma0*sigma0));
189 Double_t sigma3dyn = TMath::Sqrt((3.*sigma1dyn*sigma1dyn) - (2.*sigma0*sigma0));
190
191 Double_t lambda2cat = lambda1cat*lambda1cat;
192 Double_t lambda2dyn = lambda1dyn*lambda1dyn;
193 Double_t lambda3cat = lambda2cat*lambda1cat;
194 Double_t lambda3dyn = lambda2dyn*lambda1dyn;
195
196 // k=0:
197 arg = (x[0] - mu0)/sigma0;
198 sumcat = TMath::Exp(-0.5*arg*arg)/sigma0;
199 sumdyn =sumcat;
200
201 // k=1cat:
202 arg = (x[0] - mu1cat)/sigma1cat;
203 sumcat += lambda1cat*TMath::Exp(-0.5*arg*arg)/sigma1cat;
204 // k=1dyn:
205 arg = (x[0] - mu1dyn)/sigma1dyn;
206 sumdyn += lambda1dyn*TMath::Exp(-0.5*arg*arg)/sigma1dyn;
207
208 // k=2cat:
209 arg = (x[0] - mu2cat)/sigma2cat;
210 sumcat += 0.5*lambda2cat*TMath::Exp(-0.5*arg*arg)/sigma2cat;
211 // k=2dyn:
212 arg = (x[0] - mu2dyn)/sigma2dyn;
213 sumdyn += 0.5*lambda2dyn*TMath::Exp(-0.5*arg*arg)/sigma2dyn;
214
215
216 // k=3cat:
217 arg = (x[0] - mu3cat)/sigma3cat;
218 sumcat += 0.1666666667*lambda3cat*TMath::Exp(-0.5*arg*arg)/sigma3cat;
219 // k=3dyn:
220 arg = (x[0] - mu3dyn)/sigma3dyn;
221 sumdyn += 0.1666666667*lambda3dyn*TMath::Exp(-0.5*arg*arg)/sigma3dyn;
222
223 sumcat = TMath::Exp(-1.*lambda1cat)*sumcat;
224 sumdyn = TMath::Exp(-1.*lambda1dyn)*sumdyn;
225
226 return par[8]*(sumcat+sumdyn)/2.;
227
228 }
229
230 inline static Double_t fPoissonKto4(Double_t *x, Double_t *par)
231 {
232
233 Double_t lambda = par[0];
234
235 Double_t sum = 0.;
236 Double_t arg = 0.;
237
238 Double_t mu0 = par[1];
239 Double_t mu1 = par[2];
240
241 if (mu1 < mu0)
242 return fNoWay;
243
244 Double_t sigma0 = par[3];
245 Double_t sigma1 = par[4];
246
247 if (sigma1 < sigma0)
248 return fNoWay;
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 fNoWay;
300
301 Double_t sigma0 = par[3];
302 Double_t sigma1 = par[4];
303
304 if (sigma1 < sigma0)
305 return fNoWay;
306
307
308 Double_t mu2 = (2.*mu1)-mu0;
309 Double_t mu3 = (3.*mu1)-(2.*mu0);
310 Double_t mu4 = (4.*mu1)-(3.*mu0);
311 Double_t mu5 = (5.*mu1)-(4.*mu0);
312
313 Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));
314 Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
315 Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
316 Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
317
318 Double_t lambda2 = lambda*lambda;
319 Double_t lambda3 = lambda2*lambda;
320 Double_t lambda4 = lambda3*lambda;
321 Double_t lambda5 = lambda4*lambda;
322
323 // k=0:
324 arg = (x[0] - mu0)/sigma0;
325 sum = TMath::Exp(-0.5*arg*arg)/sigma0;
326
327 // k=1:
328 arg = (x[0] - mu1)/sigma1;
329 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
330
331 // k=2:
332 arg = (x[0] - mu2)/sigma2;
333 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
334
335 // k=3:
336 arg = (x[0] - mu3)/sigma3;
337 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
338
339 // k=4:
340 arg = (x[0] - mu4)/sigma4;
341 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
342
343 // k=5:
344 arg = (x[0] - mu5)/sigma5;
345 sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
346
347 return TMath::Exp(-1.*lambda)*par[5]*sum;
348
349 }
350
351
352 inline static Double_t fPoissonKto6(Double_t *x, Double_t *par)
353 {
354
355 Double_t lambda = par[0];
356
357 Double_t sum = 0.;
358 Double_t arg = 0.;
359
360 Double_t mu0 = par[1];
361 Double_t mu1 = par[2];
362
363 if (mu1 < mu0)
364 return fNoWay;
365
366 Double_t sigma0 = par[3];
367 Double_t sigma1 = par[4];
368
369 if (sigma1 < sigma0)
370 return fNoWay;
371
372
373 Double_t mu2 = (2.*mu1)-mu0;
374 Double_t mu3 = (3.*mu1)-(2.*mu0);
375 Double_t mu4 = (4.*mu1)-(3.*mu0);
376 Double_t mu5 = (5.*mu1)-(4.*mu0);
377 Double_t mu6 = (6.*mu1)-(5.*mu0);
378
379 Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));
380 Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
381 Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
382 Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
383 Double_t sigma6 = TMath::Sqrt((6.*sigma1*sigma1) - (5.*sigma0*sigma0));
384
385 Double_t lambda2 = lambda*lambda;
386 Double_t lambda3 = lambda2*lambda;
387 Double_t lambda4 = lambda3*lambda;
388 Double_t lambda5 = lambda4*lambda;
389 Double_t lambda6 = lambda5*lambda;
390
391 // k=0:
392 arg = (x[0] - mu0)/sigma0;
393 sum = TMath::Exp(-0.5*arg*arg)/sigma0;
394
395 // k=1:
396 arg = (x[0] - mu1)/sigma1;
397 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
398
399 // k=2:
400 arg = (x[0] - mu2)/sigma2;
401 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
402
403 // k=3:
404 arg = (x[0] - mu3)/sigma3;
405 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
406
407 // k=4:
408 arg = (x[0] - mu4)/sigma4;
409 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
410
411 // k=5:
412 arg = (x[0] - mu5)/sigma5;
413 sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
414
415 // k=6:
416 arg = (x[0] - mu6)/sigma6;
417 sum += 0.001388888888889*lambda6*TMath::Exp(-0.5*arg*arg)/sigma6;
418
419 return TMath::Exp(-1.*lambda)*par[5]*sum;
420
421 }
422
423 inline static Double_t fPolya(Double_t *x, Double_t *par)
424 {
425
426 const Double_t QEcat = 0.247; // mean quantum efficiency
427 const Double_t sqrt2 = 1.4142135623731;
428 const Double_t sqrt3 = 1.7320508075689;
429 const Double_t sqrt4 = 2.;
430
431 const Double_t lambda = par[0]; // mean number of photons
432
433 const Double_t excessPoisson = par[1]; // non-Poissonic noise contribution
434 const Double_t delta1 = par[2]; // amplification first dynode
435 const Double_t delta2 = par[3]; // amplification subsequent dynodes
436
437 const Double_t electronicAmpl = par[4]; // electronic amplification and conversion to FADC charges
438
439 const Double_t pmtAmpl = delta1*delta2*delta2*delta2*delta2*delta2; // total PMT gain
440 const Double_t A = 1. + excessPoisson - QEcat
441 + 1./delta1
442 + 1./delta1/delta2
443 + 1./delta1/delta2/delta2; // variance contributions from PMT and QE
444
445 const Double_t totAmpl = QEcat*pmtAmpl*electronicAmpl; // Total gain and conversion
446
447 const Double_t mu0 = par[7]; // pedestal
448 const Double_t mu1 = totAmpl; // single phe position
449 const Double_t mu2 = 2*totAmpl; // double phe position
450 const Double_t mu3 = 3*totAmpl; // triple phe position
451 const Double_t mu4 = 4*totAmpl; // quadruple phe position
452
453 const Double_t sigma0 = par[5];
454 const Double_t sigma1 = electronicAmpl*pmtAmpl*TMath::Sqrt(QEcat*A);
455 const Double_t sigma2 = sqrt2*sigma1;
456 const Double_t sigma3 = sqrt3*sigma1;
457 const Double_t sigma4 = sqrt4*sigma1;
458
459 const Double_t lambda2 = lambda*lambda;
460 const Double_t lambda3 = lambda2*lambda;
461 const Double_t lambda4 = lambda3*lambda;
462
463 //-- calculate the area----
464 Double_t arg = (x[0] - mu0)/sigma0;
465 Double_t sum = TMath::Exp(-0.5*arg*arg)/sigma0;
466
467 // k=1:
468 arg = (x[0] - mu1)/sigma1;
469 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
470
471 // k=2:
472 arg = (x[0] - mu2)/sigma2;
473 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
474
475 // k=3:
476 arg = (x[0] - mu3)/sigma3;
477 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
478
479 // k=4:
480 arg = (x[0] - mu4)/sigma4;
481 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
482
483 return TMath::Exp(-1.*lambda)*par[6]*sum;
484 }
485
486
487
488 ClassDef(MHCalibrationBlindPixel, 1) // Histograms from the Calibration Blind Pixel
489};
490
491#endif /* MARS_MHCalibrationBlindPixel */
Note: See TracBrowser for help on using the repository browser.