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

Last change on this file since 3614 was 3614, 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 fChargeNBins (now set to: 5300 )
30 static const Axis_t fgChargeFirst; // Default for fChargeFirst (now set to: -100.5 )
31 static const Axis_t fgChargeLast; // Default for fChargeLast (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 void Init();
99
100 Bool_t SetupFill(const MParList *pList);
101 Bool_t ReInit ( MParList *pList);
102 Bool_t Fill (const MParContainer *par, const Stat_t w=1);
103 Bool_t Finalize();
104
105 // Setters
106 void SetChargeNbins ( const Int_t bins =fgChargeNbins ) { fChargeNbins = bins; }
107 void SetChargeFirst ( const Axis_t first=fgChargeFirst ) { fChargeFirst = first; }
108 void SetChargeLast ( const Axis_t last =fgChargeLast ) { fChargeLast = last; }
109 void SetSinglePheCut ( const Float_t cut =fgSinglePheCut ) { fSinglePheCut = cut; }
110 void SetNumSinglePheLimit ( const Float_t lim =fgNumSinglePheLimit ) { fNumSinglePheLimit = lim; }
111
112 void SetMeanPedestal ( const Float_t f ) { fMeanPedestal = f; }
113 void SetMeanPedestalErr ( const Float_t f ) { fMeanPedestalErr = f; }
114 void SetSigmaPedestal ( const Float_t f ) { fSigmaPedestal = f; }
115 void SetSigmaPedestalErr ( const Float_t f ) { fSigmaPedestalErr = f; }
116
117 void SetSinglePheFitOK ( const Bool_t b=kTRUE);
118 void SetPedestalFitOK ( const Bool_t b=kTRUE);
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 TVector &GetASinglePheFADCSlices() { return fASinglePheFADCSlices; }
136 const TVector &GetASinglePheFADCSlices() const { return fASinglePheFADCSlices; }
137
138 TVector &GetAPedestalFADCSlices() { return fAPedestalFADCSlices; }
139 const TVector &GetAPedestalFADCSlices() const { return fAPedestalFADCSlices; }
140
141 const Bool_t IsSinglePheFitOK() const;
142 const Bool_t IsPedestalFitOK() const;
143
144 // Draws
145 void Draw(Option_t *opt="");
146
147private:
148 void DrawLegend();
149
150 // Fits
151public:
152 enum FitFunc_t { kEPoisson4, kEPoisson5, kEPoisson6, kEPoisson7, kEPolya, kEMichele }; // The possible fit functions
153
154private:
155 FitFunc_t fFitFunc;
156
157public:
158 Bool_t FitSinglePhe (Option_t *opt="RL0+Q");
159 void FitPedestal (Option_t *opt="RL0+Q");
160
161 void ChangeFitFunc(const FitFunc_t func) { fFitFunc = func; }
162
163 // Simulation
164 Bool_t SimulateSinglePhe(const Double_t lambda,
165 const Double_t mu0, const Double_t mu1,
166 const Double_t sigma0, const Double_t sigma1);
167
168private:
169
170 inline static Double_t fFitFuncMichele(Double_t *x, Double_t *par)
171 {
172
173 Double_t lambda1cat = par[0];
174 Double_t lambda1dyn = par[1];
175 Double_t mu0 = par[2];
176 Double_t mu1cat = par[3];
177 Double_t mu1dyn = par[4];
178 Double_t sigma0 = par[5];
179 Double_t sigma1cat = par[6];
180 Double_t sigma1dyn = par[7];
181
182 Double_t sumcat = 0.;
183 Double_t sumdyn = 0.;
184 Double_t arg = 0.;
185
186 if (mu1cat < mu0)
187 return FLT_MAX;
188
189 if (sigma1cat < sigma0)
190 return FLT_MAX;
191
192 // if (sigma1cat < sigma1dyn)
193 // return NoWay;
194
195 //if (mu1cat < mu1dyn)
196 // return NoWay;
197
198 // if (lambda1cat < lambda1dyn)
199 // return NoWay;
200
201 Double_t mu2cat = (2.*mu1cat)-mu0;
202 Double_t mu2dyn = (2.*mu1dyn)-mu0;
203 Double_t mu3cat = (3.*mu1cat)-(2.*mu0);
204 Double_t mu3dyn = (3.*mu1dyn)-(2.*mu0);
205
206 Double_t sigma2cat = TMath::Sqrt((2.*sigma1cat*sigma1cat) - (sigma0*sigma0));
207 Double_t sigma2dyn = TMath::Sqrt((2.*sigma1dyn*sigma1dyn) - (sigma0*sigma0));
208 Double_t sigma3cat = TMath::Sqrt((3.*sigma1cat*sigma1cat) - (2.*sigma0*sigma0));
209 Double_t sigma3dyn = TMath::Sqrt((3.*sigma1dyn*sigma1dyn) - (2.*sigma0*sigma0));
210
211 Double_t lambda2cat = lambda1cat*lambda1cat;
212 Double_t lambda2dyn = lambda1dyn*lambda1dyn;
213 Double_t lambda3cat = lambda2cat*lambda1cat;
214 Double_t lambda3dyn = lambda2dyn*lambda1dyn;
215
216 // k=0:
217 arg = (x[0] - mu0)/sigma0;
218 sumcat = TMath::Exp(-0.5*arg*arg)/sigma0;
219 sumdyn =sumcat;
220
221 // k=1cat:
222 arg = (x[0] - mu1cat)/sigma1cat;
223 sumcat += lambda1cat*TMath::Exp(-0.5*arg*arg)/sigma1cat;
224 // k=1dyn:
225 arg = (x[0] - mu1dyn)/sigma1dyn;
226 sumdyn += lambda1dyn*TMath::Exp(-0.5*arg*arg)/sigma1dyn;
227
228 // k=2cat:
229 arg = (x[0] - mu2cat)/sigma2cat;
230 sumcat += 0.5*lambda2cat*TMath::Exp(-0.5*arg*arg)/sigma2cat;
231 // k=2dyn:
232 arg = (x[0] - mu2dyn)/sigma2dyn;
233 sumdyn += 0.5*lambda2dyn*TMath::Exp(-0.5*arg*arg)/sigma2dyn;
234
235
236 // k=3cat:
237 arg = (x[0] - mu3cat)/sigma3cat;
238 sumcat += 0.1666666667*lambda3cat*TMath::Exp(-0.5*arg*arg)/sigma3cat;
239 // k=3dyn:
240 arg = (x[0] - mu3dyn)/sigma3dyn;
241 sumdyn += 0.1666666667*lambda3dyn*TMath::Exp(-0.5*arg*arg)/sigma3dyn;
242
243 sumcat = TMath::Exp(-1.*lambda1cat)*sumcat;
244 sumdyn = TMath::Exp(-1.*lambda1dyn)*sumdyn;
245
246 return par[8]*(sumcat+sumdyn)/2.;
247
248 }
249
250 inline static Double_t fPoissonKto4(Double_t *x, Double_t *par)
251 {
252
253 Double_t lambda = par[0];
254
255 Double_t sum = 0.;
256 Double_t arg = 0.;
257
258 Double_t mu0 = par[1];
259 Double_t mu1 = par[2];
260
261 if (mu1 < mu0)
262 return FLT_MAX;
263
264 Double_t sigma0 = par[3];
265 Double_t sigma1 = par[4];
266
267 if (sigma1 < sigma0)
268 return FLT_MAX;
269
270 Double_t mu2 = (2.*mu1)-mu0;
271 Double_t mu3 = (3.*mu1)-(2.*mu0);
272 Double_t mu4 = (4.*mu1)-(3.*mu0);
273
274 Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));
275 Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
276 Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
277
278 Double_t lambda2 = lambda*lambda;
279 Double_t lambda3 = lambda2*lambda;
280 Double_t lambda4 = lambda3*lambda;
281
282 // k=0:
283 arg = (x[0] - mu0)/sigma0;
284 sum = TMath::Exp(-0.5*arg*arg)/sigma0;
285
286 // k=1:
287 arg = (x[0] - mu1)/sigma1;
288 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
289
290 // k=2:
291 arg = (x[0] - mu2)/sigma2;
292 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
293
294 // k=3:
295 arg = (x[0] - mu3)/sigma3;
296 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
297
298 // k=4:
299 arg = (x[0] - mu4)/sigma4;
300 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
301
302 return TMath::Exp(-1.*lambda)*par[5]*sum;
303
304 }
305
306
307 inline static Double_t fPoissonKto5(Double_t *x, Double_t *par)
308 {
309
310 Double_t lambda = par[0];
311
312 Double_t sum = 0.;
313 Double_t arg = 0.;
314
315 Double_t mu0 = par[1];
316 Double_t mu1 = par[2];
317
318 if (mu1 < mu0)
319 return FLT_MAX;
320
321 Double_t sigma0 = par[3];
322 Double_t sigma1 = par[4];
323
324 if (sigma1 < sigma0)
325 return FLT_MAX;
326
327
328 Double_t mu2 = (2.*mu1)-mu0;
329 Double_t mu3 = (3.*mu1)-(2.*mu0);
330 Double_t mu4 = (4.*mu1)-(3.*mu0);
331 Double_t mu5 = (5.*mu1)-(4.*mu0);
332
333 Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));
334 Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
335 Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
336 Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
337
338 Double_t lambda2 = lambda*lambda;
339 Double_t lambda3 = lambda2*lambda;
340 Double_t lambda4 = lambda3*lambda;
341 Double_t lambda5 = lambda4*lambda;
342
343 // k=0:
344 arg = (x[0] - mu0)/sigma0;
345 sum = TMath::Exp(-0.5*arg*arg)/sigma0;
346
347 // k=1:
348 arg = (x[0] - mu1)/sigma1;
349 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
350
351 // k=2:
352 arg = (x[0] - mu2)/sigma2;
353 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
354
355 // k=3:
356 arg = (x[0] - mu3)/sigma3;
357 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
358
359 // k=4:
360 arg = (x[0] - mu4)/sigma4;
361 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
362
363 // k=5:
364 arg = (x[0] - mu5)/sigma5;
365 sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
366
367 return TMath::Exp(-1.*lambda)*par[5]*sum;
368
369 }
370
371
372 inline static Double_t fPoissonKto6(Double_t *x, Double_t *par)
373 {
374
375 Double_t lambda = par[0];
376
377 Double_t sum = 0.;
378 Double_t arg = 0.;
379
380 Double_t mu0 = par[1];
381 Double_t mu1 = par[2];
382
383 if (mu1 < mu0)
384 return FLT_MAX;
385
386 Double_t sigma0 = par[3];
387 Double_t sigma1 = par[4];
388
389 if (sigma1 < sigma0)
390 return FLT_MAX;
391
392
393 Double_t mu2 = (2.*mu1)-mu0;
394 Double_t mu3 = (3.*mu1)-(2.*mu0);
395 Double_t mu4 = (4.*mu1)-(3.*mu0);
396 Double_t mu5 = (5.*mu1)-(4.*mu0);
397 Double_t mu6 = (6.*mu1)-(5.*mu0);
398
399 Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));
400 Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
401 Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
402 Double_t sigma5 = TMath::Sqrt((5.*sigma1*sigma1) - (4.*sigma0*sigma0));
403 Double_t sigma6 = TMath::Sqrt((6.*sigma1*sigma1) - (5.*sigma0*sigma0));
404
405 Double_t lambda2 = lambda*lambda;
406 Double_t lambda3 = lambda2*lambda;
407 Double_t lambda4 = lambda3*lambda;
408 Double_t lambda5 = lambda4*lambda;
409 Double_t lambda6 = lambda5*lambda;
410
411 // k=0:
412 arg = (x[0] - mu0)/sigma0;
413 sum = TMath::Exp(-0.5*arg*arg)/sigma0;
414
415 // k=1:
416 arg = (x[0] - mu1)/sigma1;
417 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
418
419 // k=2:
420 arg = (x[0] - mu2)/sigma2;
421 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
422
423 // k=3:
424 arg = (x[0] - mu3)/sigma3;
425 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
426
427 // k=4:
428 arg = (x[0] - mu4)/sigma4;
429 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
430
431 // k=5:
432 arg = (x[0] - mu5)/sigma5;
433 sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
434
435 // k=6:
436 arg = (x[0] - mu6)/sigma6;
437 sum += 0.001388888888889*lambda6*TMath::Exp(-0.5*arg*arg)/sigma6;
438
439 return TMath::Exp(-1.*lambda)*par[5]*sum;
440
441 }
442
443 inline static Double_t fPolya(Double_t *x, Double_t *par)
444 {
445
446 const Double_t QEcat = 0.247; // mean quantum efficiency
447 const Double_t sqrt2 = 1.4142135623731;
448 const Double_t sqrt3 = 1.7320508075689;
449 const Double_t sqrt4 = 2.;
450
451 const Double_t lambda = par[0]; // mean number of photons
452
453 const Double_t excessPoisson = par[1]; // non-Poissonic noise contribution
454 const Double_t delta1 = par[2]; // amplification first dynode
455 const Double_t delta2 = par[3]; // amplification subsequent dynodes
456
457 const Double_t electronicAmpl = par[4]; // electronic amplification and conversion to FADC charges
458
459 const Double_t pmtAmpl = delta1*delta2*delta2*delta2*delta2*delta2; // total PMT gain
460 const Double_t A = 1. + excessPoisson - QEcat
461 + 1./delta1
462 + 1./delta1/delta2
463 + 1./delta1/delta2/delta2; // variance contributions from PMT and QE
464
465 const Double_t totAmpl = QEcat*pmtAmpl*electronicAmpl; // Total gain and conversion
466
467 const Double_t mu0 = par[7]; // pedestal
468 const Double_t mu1 = totAmpl; // single phe position
469 const Double_t mu2 = 2*totAmpl; // double phe position
470 const Double_t mu3 = 3*totAmpl; // triple phe position
471 const Double_t mu4 = 4*totAmpl; // quadruple phe position
472
473 const Double_t sigma0 = par[5];
474 const Double_t sigma1 = electronicAmpl*pmtAmpl*TMath::Sqrt(QEcat*A);
475 const Double_t sigma2 = sqrt2*sigma1;
476 const Double_t sigma3 = sqrt3*sigma1;
477 const Double_t sigma4 = sqrt4*sigma1;
478
479 const Double_t lambda2 = lambda*lambda;
480 const Double_t lambda3 = lambda2*lambda;
481 const Double_t lambda4 = lambda3*lambda;
482
483 //-- calculate the area----
484 Double_t arg = (x[0] - mu0)/sigma0;
485 Double_t sum = TMath::Exp(-0.5*arg*arg)/sigma0;
486
487 // k=1:
488 arg = (x[0] - mu1)/sigma1;
489 sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
490
491 // k=2:
492 arg = (x[0] - mu2)/sigma2;
493 sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
494
495 // k=3:
496 arg = (x[0] - mu3)/sigma3;
497 sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
498
499 // k=4:
500 arg = (x[0] - mu4)/sigma4;
501 sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
502
503 return TMath::Exp(-1.*lambda)*par[6]*sum;
504 }
505
506
507
508 ClassDef(MHCalibrationChargeBlindPix, 1) // Histogram class for the Calibration Blind Pixel
509};
510
511#endif /* MARS_MHCalibrationChargeBlindPix */
Note: See TracBrowser for help on using the repository browser.