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

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