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

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