source: trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc@ 3492

Last change on this file since 3492 was 3445, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 24.6 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Markus Gaug 02/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MHCalibrationChargeBlindPix
28//
29// Performs all the Single Photo-Electron Fit to extract
30// the mean number of photons and to derive the light flux
31//
32// The fit result is accepted under condition that:
33// 1) the Probability is greater than gkProbLimit (default 0.001 == 99.7%)
34// 2) at least 100 events are in the single Photo-electron peak
35//
36// Used numbers are the following:
37//
38// Electronic conversion factor:
39// Assume, we have N_e electrons at the anode,
40// thus a charge of N_e*e (e = electron charge) Coulomb.
41//
42// This charge is AC coupled and runs into a R_pre = 50 Ohm resistency.
43// The corresponding current is amplified by a gain factor G_pre = 400
44// (the precision of this value still has to be checked !!!) and again AC coupled to
45// the output.
46// The corresponding signal goes through the whole transmission and
47// amplification chain and is digitized in the FADCs.
48// The conversion Signal Area to FADC counts (Conv_trans) has been measured
49// by David and Oscar to be approx. 3.9 pVs^-1
50//
51// Thus: Conversion FADC counts to Number of Electrons at Anode:
52// FADC counts = (1/Conv_tran) * G_pre * R_pre * e * N_e = 8 * 10^-4 N_e.
53//
54// Also: FADC counts = 8*10^-4 * GAIN * N_phe
55//
56// In the blind pixel, there is an additional pre-amplifier with an amplification of
57// about 10. Therefore, we have for the blind pixel:
58//
59// FADC counts (Blind Pixel) = 8*10^-3 * GAIN * N_phe
60//
61//////////////////////////////////////////////////////////////////////////////
62#include "MHCalibrationChargeBlindPix.h"
63
64#include <TStyle.h>
65#include <TCanvas.h>
66#include <TPaveText.h>
67
68#include <TVector.h>
69#include <TF1.h>
70#include <TH1.h>
71#include <TRandom.h>
72
73#include "MLog.h"
74#include "MLogManip.h"
75
76#include "MParList.h"
77
78#include "MRawEvtData.h"
79#include "MRawEvtPixelIter.h"
80
81#include "MExtractedSignalBlindPixel.h"
82#include "MCalibrationChargeBlindPix.h"
83
84ClassImp(MHCalibrationChargeBlindPix);
85
86using namespace std;
87
88const Double_t MHCalibrationChargeBlindPix::gkElectronicAmp = 0.008;
89const Double_t MHCalibrationChargeBlindPix::gkElectronicAmpErr = 0.002;
90
91const Int_t MHCalibrationChargeBlindPix::fgChargeNbins = 1400;
92const Axis_t MHCalibrationChargeBlindPix::fgChargeFirst = -200.5;
93const Axis_t MHCalibrationChargeBlindPix::fgChargeLast = 1199.5;
94
95const Float_t MHCalibrationChargeBlindPix::fgSinglePheCut = 200.;
96const Float_t MHCalibrationChargeBlindPix::fgNumSinglePheLimit = 50.;
97// --------------------------------------------------------------------------
98//
99// Default Constructor.
100//
101MHCalibrationChargeBlindPix::MHCalibrationChargeBlindPix(const char *name, const char *title)
102 : fBlindPix(NULL), fSignal(NULL), fRawEvt(NULL),
103 fASinglePheFADCSlices(30), fAPedestalFADCSlices(30),
104 fSinglePheFit(NULL),
105 fFitLegend(NULL),
106 fHSinglePheFADCSlices(NULL), fHPedestalFADCSlices(NULL)
107{
108
109 fName = name ? name : "MHCalibrationChargeBlindPix";
110 fTitle = title ? title : "Fill the accumulated charges and times of all Blind Pixel events and perform fits";
111
112 SetChargeNbins();
113 SetChargeFirst();
114 SetChargeLast();
115
116 SetSinglePheCut();
117 SetNumSinglePheLimit();
118
119 fHGausHist.SetName("HCalibrationChargeBlindPix");
120 fHGausHist.SetTitle("Distribution of Summed FADC slices Blind Pixel");
121 fHGausHist.SetXTitle("Sum FADC Slices");
122 fHGausHist.SetYTitle("Nr. of events");
123
124 Clear();
125}
126
127MHCalibrationChargeBlindPix::~MHCalibrationChargeBlindPix()
128{
129
130 if (fSinglePheFit)
131 delete fSinglePheFit;
132
133 if (fFitLegend)
134 delete fFitLegend;
135
136 if (fHSinglePheFADCSlices)
137 delete fHSinglePheFADCSlices;
138
139 if (fHPedestalFADCSlices)
140 delete fHPedestalFADCSlices;
141
142}
143
144void MHCalibrationChargeBlindPix::Init()
145{
146
147 fHGausHist.SetBins( fChargeNbins, fChargeFirst, fChargeLast);
148}
149
150void MHCalibrationChargeBlindPix::Clear(Option_t *o)
151{
152
153 fLambda = -999.;
154 fMu0 = -999.;
155 fMu1 = -999.;
156 fSigma0 = -999.;
157 fSigma1 = -999.;
158
159 fLambdaErr = -999.;
160 fMu0Err = -999.;
161 fMu1Err = -999.;
162 fSigma0Err = -999.;
163 fSigma1Err = -999.;
164
165 fLambdaCheck = -999.;
166 fLambdaCheckErr = -999.;
167
168 fMeanPedestal = 0.;
169 fMeanPedestalErr = 0.;
170 fSigmaPedestal = 0.;
171 fSigmaPedestalErr = 0.;
172
173 fFitFunc = kEPoisson5;
174
175 fExtractSlices = 0;
176 fNumSinglePhes = 0;
177 fNumPedestals = 0;
178
179 fNumSinglePhes = 0;
180 fNumPedestals = 0;
181
182 fChisquare = 0.;
183 fNDF = 0 ;
184 fProb = 0.;
185
186 SetSinglePheFitOK ( kFALSE );
187 SetPedestalFitOK ( kFALSE );
188
189 if (fFitLegend)
190 {
191 delete fFitLegend;
192 fFitLegend = NULL;
193 }
194
195 if (fSinglePheFit)
196 {
197 delete fSinglePheFit;
198 fSinglePheFit = NULL;
199 }
200
201 if (fHSinglePheFADCSlices)
202 {
203 delete fHSinglePheFADCSlices;
204 fHSinglePheFADCSlices = NULL;
205 }
206
207 if (fHPedestalFADCSlices)
208 {
209 delete fHPedestalFADCSlices;
210 fHPedestalFADCSlices = NULL;
211 }
212
213
214 MHCalibrationChargePix::Clear();
215 return;
216}
217
218void MHCalibrationChargeBlindPix::SetSinglePheFitOK (const Bool_t b)
219{
220 b ? SETBIT(fFlags,kSinglePheFitOK) : CLRBIT(fFlags,kSinglePheFitOK);
221}
222
223void MHCalibrationChargeBlindPix::SetPedestalFitOK(const Bool_t b)
224{
225 b ? SETBIT(fFlags,kPedestalFitOK) : CLRBIT(fFlags,kPedestalFitOK);
226}
227
228const Bool_t MHCalibrationChargeBlindPix::IsSinglePheFitOK() const
229{
230 return TESTBIT(fFlags,kSinglePheFitOK);
231}
232
233const Bool_t MHCalibrationChargeBlindPix::IsPedestalFitOK() const
234{
235 return TESTBIT(fFlags,kPedestalFitOK);
236}
237
238Bool_t MHCalibrationChargeBlindPix::SetupFill(const MParList *pList)
239{
240 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
241 if (!fRawEvt)
242 {
243 *fLog << err << "MRawEvtData not found... aborting." << endl;
244 return kFALSE;
245 }
246
247 fSignal = (MExtractedSignalBlindPixel*)pList->FindObject("MExtractedSignalBlindPixel");
248 if (!fSignal)
249 {
250 *fLog << err << "MExtractedSignalBlindPixel not found... aborting " << endl;
251 return kFALSE;
252 }
253
254 Init();
255
256 return kTRUE;
257}
258
259Bool_t MHCalibrationChargeBlindPix::ReInit(MParList *pList)
260{
261
262 fBlindPix = (MCalibrationChargeBlindPix*)pList->FindCreateObj("MCalibrationChargeBlindPix");
263 if (!fBlindPix)
264 return kFALSE;
265
266 return kTRUE;
267}
268
269Bool_t MHCalibrationChargeBlindPix::Fill(const MParContainer *par, const Stat_t w)
270{
271
272 Float_t slices = (Float_t)fSignal->GetNumFADCSamples();
273
274 if (slices == 0.)
275 {
276 *fLog << err << "Number of used signal slices in MExtractedSignalBlindPix is zero ... abort."
277 << endl;
278 return kFALSE;
279 }
280
281 if (fExtractSlices != 0. && slices != fExtractSlices )
282 {
283 *fLog << err << "Number of used signal slices changed in MExtractedSignalCam ... abort."
284 << endl;
285 return kFALSE;
286 }
287 fExtractSlices = slices;
288
289 //
290 // Signal extraction and histogram filling
291 //
292 const Float_t signal = (Float_t)fSignal->GetExtractedSignal();
293 FillHistAndArray(signal);
294
295 //
296 // IN order to study the single-phe posistion, we extract the slices
297 //
298 MRawEvtPixelIter pixel(fRawEvt);
299 pixel.Jump(fSignal->GetBlindPixelIdx());
300
301 if (signal > fSinglePheCut)
302 FillSinglePheFADCSlices(pixel);
303 else
304 FillPedestalFADCSlices(pixel);
305
306 return kTRUE;
307}
308
309Bool_t MHCalibrationChargeBlindPix::Finalize()
310{
311
312 if (IsEmpty())
313 {
314 *fLog << err << GetDescriptor() << ": My histogram has not been filled !! " << endl;
315 return kFALSE;
316 }
317
318 CreateFourierSpectrum();
319 fBlindPix->SetOscillating ( !IsFourierSpectrumOK() );
320
321 fMeanPedestal = fSignal->GetPed();
322 fMeanPedestalErr = fSignal->GetPedErr();
323 fSigmaPedestal = fSignal->GetPedRms();
324 fSigmaPedestalErr = fSignal->GetPedRmsErr();
325
326 if (fNumSinglePhes > 1)
327 for (Int_t i=0;i<fASinglePheFADCSlices.GetNrows();i++)
328 fASinglePheFADCSlices[i] = fASinglePheFADCSlices[i]/fNumSinglePhes;
329 if (fNumPedestals > 1)
330 for (Int_t i=0;i<fAPedestalFADCSlices.GetNrows();i++)
331 fAPedestalFADCSlices[i] = fAPedestalFADCSlices[i]/fNumPedestals;
332
333 FitPedestal();
334
335 if (FitSinglePhe())
336 fBlindPix->SetSinglePheFitOK();
337
338 fBlindPix->SetLambda ( fLambda );
339 fBlindPix->SetMu0 ( fMu0 );
340 fBlindPix->SetMu0Err ( fMu0Err );
341 fBlindPix->SetMu1 ( fMu1 );
342 fBlindPix->SetMu1Err ( fMu1Err );
343 fBlindPix->SetSigma0 ( fSigma0 );
344 fBlindPix->SetSigma0Err ( fSigma0Err );
345 fBlindPix->SetSigma1 ( fSigma1 );
346 fBlindPix->SetSigma1Err ( fSigma1Err );
347 fBlindPix->SetProb ( fProb );
348
349 fBlindPix->SetLambdaCheck ( fLambdaCheck );
350 fBlindPix->SetLambdaCheckErr ( fLambdaCheckErr );
351
352 return kTRUE;
353}
354
355void MHCalibrationChargeBlindPix::FillSinglePheFADCSlices(const MRawEvtPixelIter &iter)
356{
357
358 const Int_t n = iter.GetNumHiGainSamples() + iter.GetNumLoGainSamples();
359
360 if (fASinglePheFADCSlices.GetNrows() < n)
361 fASinglePheFADCSlices.ResizeTo(n);
362
363 Int_t i=0;
364
365 Byte_t *start = iter.GetHiGainSamples();
366 Byte_t *end = start + iter.GetNumHiGainSamples();
367
368 for (Byte_t *ptr = start; ptr < end; ptr++, i++)
369 fASinglePheFADCSlices(i) = fASinglePheFADCSlices(i) + (Float_t)*ptr;
370
371 start = iter.GetLoGainSamples();
372 end = start + iter.GetNumLoGainSamples();
373
374 for (Byte_t *ptr = start; ptr < end; ptr++, i++)
375 fASinglePheFADCSlices(i) = fASinglePheFADCSlices(i) + (Float_t)*ptr;
376
377 fNumSinglePhes++;
378}
379
380void MHCalibrationChargeBlindPix::FillPedestalFADCSlices(const MRawEvtPixelIter &iter)
381{
382
383 const Int_t n = iter.GetNumHiGainSamples() + iter.GetNumLoGainSamples();
384
385 if (fAPedestalFADCSlices.GetNrows() < n)
386 fAPedestalFADCSlices.ResizeTo(n);
387
388 Int_t i = 0;
389 Byte_t *start = iter.GetHiGainSamples();
390 Byte_t *end = start + iter.GetNumHiGainSamples();
391
392 for (Byte_t *ptr = start; ptr < end; ptr++, i++)
393 fAPedestalFADCSlices(i) = fAPedestalFADCSlices(i)+ (Float_t)*ptr;
394
395 start = iter.GetLoGainSamples();
396 end = start + iter.GetNumLoGainSamples();
397
398 for (Byte_t *ptr = start; ptr < end; ptr++, i++)
399 fAPedestalFADCSlices(i) = fAPedestalFADCSlices(i)+ (Float_t)*ptr;
400
401 fNumPedestals++;
402}
403
404
405
406Bool_t MHCalibrationChargeBlindPix::SimulateSinglePhe(Double_t lambda, Double_t mu0, Double_t mu1, Double_t sigma0, Double_t sigma1)
407{
408
409 gRandom->SetSeed();
410
411 if (fHGausHist.GetIntegral() != 0)
412 {
413 *fLog << err << "Histogram " << fHGausHist.GetTitle() << " is already filled. " << endl;
414 *fLog << err << "Create new class MHCalibrationBlindPixel for simulation! " << endl;
415 return kFALSE;
416 }
417
418 if (!InitFit())
419 return kFALSE;
420
421 for (Int_t i=0;i<10000; i++)
422 fHGausHist.Fill(fSinglePheFit->GetRandom());
423
424 return kTRUE;
425}
426
427Bool_t MHCalibrationChargeBlindPix::InitFit()
428{
429
430 //
431 // Get the fitting ranges
432 //
433 Axis_t rmin = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetFirst());
434 Axis_t rmax = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetLast());
435
436 if (rmin < 0.)
437 rmin = 0.;
438
439 //
440 // First guesses for the fit (should be as close to reality as possible,
441 // otherwise the fit goes gaga because of high number of dimensions ...
442 //
443 const Stat_t entries = fHGausHist.Integral("width");
444 const Double_t lambda_guess = 0.1;
445 const Double_t maximum_bin = fHGausHist.GetBinCenter(fHGausHist.GetMaximumBin());
446 const Double_t norm = entries/TMath::Sqrt(TMath::TwoPi());
447
448 //
449 // Initialize the fit function
450 //
451 switch (fFitFunc)
452 {
453 case kEPoisson4:
454 fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto4,rmin,rmax,6);
455 break;
456 case kEPoisson5:
457 fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto5,rmin,rmax,6);
458 break;
459 case kEPoisson6:
460 fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto6,rmin,rmax,6);
461 break;
462 case kEPolya:
463 fSinglePheFit = new TF1("SinglePheFit",&fPolya,rmin,rmax,8);
464 break;
465 case kEMichele:
466 break;
467
468 default:
469 *fLog << warn << "WARNING: Could not find Fit Function for Blind Pixel " << endl;
470 return kFALSE;
471 break;
472 }
473
474 if (!fSinglePheFit)
475 {
476 *fLog << warn << dbginf << "WARNING: Could not create fit function for Single Phe fit" << endl;
477 return kFALSE;
478 }
479
480 const Double_t mu_0_guess = maximum_bin;
481 const Double_t si_0_guess = 40.;
482 const Double_t mu_1_guess = mu_0_guess + 100.;
483 const Double_t si_1_guess = si_0_guess + si_0_guess;
484 // Michele
485// const Double_t lambda_1cat_guess = 0.5;
486 // const Double_t lambda_1dyn_guess = 0.5;
487 // const Double_t mu_1cat_guess = mu_0_guess + 50.;
488 // const Double_t mu_1dyn_guess = mu_0_guess + 20.;
489 // const Double_t si_1cat_guess = si_0_guess + si_0_guess;
490 // const Double_t si_1dyn_guess = si_0_guess;
491 // Polya
492 const Double_t excessPoisson_guess = 0.5;
493 const Double_t delta1_guess = 8.;
494 const Double_t delta2_guess = 5.;
495 const Double_t electronicAmp_guess = gkElectronicAmp;
496 const Double_t electronicAmp_limit = gkElectronicAmpErr;
497
498 //
499 // Initialize boundaries and start parameters
500 //
501 switch (fFitFunc)
502 {
503
504 case kEPoisson4:
505 fSinglePheFit->SetParNames( "#lambda", "#mu_{0}", "#mu_{1}", "#sigma_{0}", "#sigma_{1}","Area");
506 fSinglePheFit->SetParameters(lambda_guess,fMeanPedestal,mu_1_guess,fSigmaPedestal,si_1_guess,norm);
507
508 fSinglePheFit->SetParLimits(0,0.,0.5);
509 fSinglePheFit->SetParLimits(1,
510 fMeanPedestal-5.*fMeanPedestalErr,
511 fMeanPedestal+5.*fMeanPedestalErr);
512 fSinglePheFit->SetParLimits(2,rmin,rmax);
513 fSinglePheFit->SetParLimits(3,
514 fSigmaPedestal-5.*fSigmaPedestalErr,
515 fSigmaPedestal+5.*fSigmaPedestalErr);
516 fSinglePheFit->SetParLimits(4,0.,(rmax-rmin));
517 fSinglePheFit->SetParLimits(5,norm-(0.5*norm),norm+(0.5*norm));
518 break;
519 case kEPoisson5:
520 case kEPoisson6:
521 fSinglePheFit->SetParameters(lambda_guess,mu_0_guess,mu_1_guess,si_0_guess,si_1_guess,norm);
522 fSinglePheFit->SetParNames("#lambda","#mu_{0}","#mu_{1}","#sigma_{0}","#sigma_{1}","Area");
523 fSinglePheFit->SetParLimits(0,0.,1.);
524 fSinglePheFit->SetParLimits(1,rmin,(rmax-rmin)/1.5);
525 fSinglePheFit->SetParLimits(2,(rmax-rmin)/2.,(rmax-0.05*(rmax-rmin)));
526 fSinglePheFit->SetParLimits(3,1.0,(rmax-rmin)/2.0);
527 fSinglePheFit->SetParLimits(4,1.0,(rmax-rmin)/2.5);
528 fSinglePheFit->SetParLimits(5,norm-0.1,norm+0.1);
529 break;
530
531 case kEPolya:
532 fSinglePheFit->SetParameters(lambda_guess, excessPoisson_guess,
533 delta1_guess,delta2_guess,
534 electronicAmp_guess,
535 fSigmaPedestal,
536 norm,
537 fMeanPedestal);
538 fSinglePheFit->SetParNames("#lambda","b_{tot}",
539 "#delta_{1}","#delta_{2}",
540 "amp_{e}","#sigma_{0}",
541 "Area", "#mu_{0}");
542 fSinglePheFit->SetParLimits(0,0.,1.);
543 fSinglePheFit->SetParLimits(1,0.,1.);
544 fSinglePheFit->SetParLimits(2,6.,12.);
545 fSinglePheFit->SetParLimits(3,3.,8.);
546 fSinglePheFit->SetParLimits(4,electronicAmp_guess-electronicAmp_limit,
547 electronicAmp_guess+electronicAmp_limit);
548 fSinglePheFit->SetParLimits(5,
549 fSigmaPedestal-3.*fSigmaPedestalErr,
550 fSigmaPedestal+3.*fSigmaPedestalErr);
551 fSinglePheFit->SetParLimits(6,norm-0.1,norm+0.1);
552 fSinglePheFit->SetParLimits(7,
553 fMeanPedestal-3.*fMeanPedestalErr,
554 fMeanPedestal+3.*fMeanPedestalErr);
555 break;
556 case kEMichele:
557 break;
558
559 default:
560 *fLog << warn << "WARNING: Could not find Fit Function for Blind Pixel " << endl;
561 return kFALSE;
562 break;
563 }
564
565 fSinglePheFit->SetRange(rmin,rmax);
566
567 return kTRUE;
568}
569
570void MHCalibrationChargeBlindPix::ExitFit()
571{
572
573
574 //
575 // Finalize
576 //
577 switch (fFitFunc)
578 {
579
580 case kEPoisson4:
581 case kEPoisson5:
582 case kEPoisson6:
583 case kEPoisson7:
584 fLambda = fSinglePheFit->GetParameter(0);
585 fMu0 = fSinglePheFit->GetParameter(1);
586 fMu1 = fSinglePheFit->GetParameter(2);
587 fSigma0 = fSinglePheFit->GetParameter(3);
588 fSigma1 = fSinglePheFit->GetParameter(4);
589
590 fLambdaErr = fSinglePheFit->GetParError(0);
591 fMu0Err = fSinglePheFit->GetParError(1);
592 fMu1Err = fSinglePheFit->GetParError(2);
593 fSigma0Err = fSinglePheFit->GetParError(3);
594 fSigma1Err = fSinglePheFit->GetParError(4);
595 break;
596 case kEPolya:
597 fLambda = fSinglePheFit->GetParameter(0);
598 fMu0 = fSinglePheFit->GetParameter(7);
599 fMu1 = 0.;
600 fSigma0 = fSinglePheFit->GetParameter(5);
601 fSigma1 = 0.;
602
603 fLambdaErr = fSinglePheFit->GetParError(0);
604 fMu0Err = fSinglePheFit->GetParError(7);
605 fMu1Err = 0.;
606 fSigma0Err = fSinglePheFit->GetParError(5);
607 fSigma1Err = 0.;
608 default:
609 break;
610 }
611
612 fProb = fSinglePheFit->GetProb();
613 fChisquare = fSinglePheFit->GetChisquare();
614 fNDF = fSinglePheFit->GetNDF();
615
616 *fLog << all << "Results of the Blind Pixel Fit: " << endl;
617 *fLog << all << "Chisquare: " << fChisquare << endl;
618 *fLog << all << "DoF: " << fNDF << endl;
619 *fLog << all << "Probability: " << fProb << endl;
620
621}
622
623
624Bool_t MHCalibrationChargeBlindPix::FitSinglePhe(Option_t *opt)
625{
626
627 if (!InitFit())
628 return kFALSE;
629
630 fHGausHist.Fit(fSinglePheFit,opt);
631
632 ExitFit();
633
634 //
635 // The fit result is accepted under condition:
636 // 1) The results are not nan's
637 // 2) The NDF is not smaller than fNDFLimit (5)
638 // 3) The Probability is greater than fProbLimit (default 0.001 == 99.9%)
639 // 4) at least fNumSinglePheLimit events are in the single Photo-electron peak
640 if ( TMath::IsNaN(fLambda)
641 || TMath::IsNaN(fLambdaErr)
642 || TMath::IsNaN(fProb)
643 || TMath::IsNaN(fMu0)
644 || TMath::IsNaN(fMu0Err)
645 || TMath::IsNaN(fMu1)
646 || TMath::IsNaN(fMu1Err)
647 || TMath::IsNaN(fSigma0)
648 || TMath::IsNaN(fSigma0Err)
649 || TMath::IsNaN(fSigma1)
650 || TMath::IsNaN(fSigma1Err)
651 || fNDF < fNDFLimit
652 || fProb < fProbLimit )
653 return kFALSE;
654
655 const Stat_t entries = fHGausHist.Integral("width");
656 const Float_t numSinglePhe = TMath::Exp(-1.0*fLambda)*fLambda*entries;
657
658 if (numSinglePhe < fNumSinglePheLimit)
659 {
660 *fLog << warn << "WARNING - Statistics is too low: Only " << numSinglePhe
661 << " in the Single Photo-Electron peak " << endl;
662 return kFALSE;
663 }
664 else
665 *fLog << all << numSinglePhe << " in Single Photo-Electron peak " << endl;
666
667 SetSinglePheFitOK();
668 return kTRUE;
669}
670
671void MHCalibrationChargeBlindPix::FitPedestal (Option_t *opt)
672{
673
674 // Perform the cross-check fitting only the pedestal:
675 const Axis_t rmin = 0.;
676 const Axis_t rmax = fHGausHist.GetBinCenter(fHGausHist.GetMaximumBin());
677
678 FitGaus(opt, rmin, rmax);
679
680 const Stat_t entries = fHGausHist.Integral("width");
681 const Double_t fitarea = fFGausFit->GetParameter(0);
682 const Double_t pedarea = fitarea * TMath::Sqrt(TMath::TwoPi()) * fFGausFit->GetParameter(2);
683
684 fLambdaCheck = TMath::Log(entries/pedarea);
685 fLambdaCheckErr = fFGausFit->GetParError(0)/fFGausFit->GetParameter(0)
686 + fFGausFit->GetParError(2)/fFGausFit->GetParameter(2);
687
688
689 SetPedestalFitOK();
690 return;
691}
692
693
694// -------------------------------------------------------------------------
695//
696// Draw a legend with the fit results
697//
698void MHCalibrationChargeBlindPix::DrawLegend()
699{
700
701 if (!fFitLegend)
702 {
703 fFitLegend = new TPaveText(0.05,0.05,0.95,0.95);
704 fFitLegend->SetLabel(Form("%s%s", "Results of the single PhE Fit (",
705 (fFitFunc = kEPoisson4) ? "Poisson(k=4))" :
706 (fFitFunc = kEPoisson5) ? "Poisson(k=5))" :
707 (fFitFunc = kEPoisson6) ? "Poisson(k=4))" :
708 (fFitFunc = kEPolya ) ? "Polya(k=4))" :
709 (fFitFunc = kEMichele ) ? "Michele)" : " none )" ));
710 fFitLegend->SetTextSize(0.05);
711 }
712 else
713 fFitLegend->Clear();
714
715 const TString line1 =
716 Form("Mean: #lambda = %2.2f #pm %2.2f",fLambda,fLambdaErr);
717 TText *t1 = fFitLegend->AddText(line1.Data());
718 t1->SetBit(kCanDelete);
719
720 const TString line6 =
721 Form("Mean #lambda (check) = %2.2f #pm %2.2f",fLambdaCheck,fLambdaCheckErr);
722 TText *t2 = fFitLegend->AddText(line6.Data());
723 t2->SetBit(kCanDelete);
724
725 const TString line2 =
726 Form("Pedestal: #mu_{0} = %2.2f #pm %2.2f",fMu0,fMu0Err);
727 TText *t3 = fFitLegend->AddText(line2.Data());
728 t3->SetBit(kCanDelete);
729
730 const TString line3 =
731 Form("Width Pedestal: #sigma_{0} = %2.2f #pm %2.2f",fSigma0,fSigma0Err);
732 TText *t4 = fFitLegend->AddText(line3.Data());
733 t4->SetBit(kCanDelete);
734
735 const TString line4 =
736 Form("1^{st} Phe-peak: #mu_{1} = %2.2f #pm %2.2f",fMu1,fMu1Err);
737 TText *t5 = fFitLegend->AddText(line4.Data());
738 t5->SetBit(kCanDelete);
739
740 const TString line5 =
741 Form("Width 1^{st} Phe-peak: #sigma_{1} = %2.2f #pm %2.2f",fSigma1,fSigma1Err);
742 TText *t6 = fFitLegend->AddText(line5.Data());
743 t6->SetBit(kCanDelete);
744
745 const TString line7 =
746 Form("#chi^{2} / N_{dof}: %4.2f / %3i",fChisquare,fNDF);
747 TText *t7 = fFitLegend->AddText(line7.Data());
748 t7->SetBit(kCanDelete);
749
750 const TString line8 =
751 Form("Probability: %4.2f ",fProb);
752 TText *t8 = fFitLegend->AddText(line8.Data());
753 t8->SetBit(kCanDelete);
754
755 if (IsSinglePheFitOK())
756 {
757 TText *t = fFitLegend->AddText(0.,0.,"Result of the Fit: OK");
758 t->SetBit(kCanDelete);
759 }
760 else
761 {
762 TText *t = fFitLegend->AddText("Result of the Fit: NOT OK");
763 t->SetBit(kCanDelete);
764 }
765
766 fFitLegend->SetFillColor(IsSinglePheFitOK() ? 80 : 2);
767 fFitLegend->Draw();
768
769 return;
770}
771
772
773// -------------------------------------------------------------------------
774//
775// Draw the histogram
776//
777void MHCalibrationChargeBlindPix::Draw(Option_t *opt)
778{
779
780 TString option(opt);
781 option.ToLower();
782
783 Int_t win = 1;
784
785 TVirtualPad *oldpad = gPad ? gPad : MH::MakeDefCanvas(this,900, 600);
786 TVirtualPad *pad = NULL;
787
788 oldpad->SetBorderMode(0);
789
790 if (option.Contains("all"))
791 {
792 option.ReplaceAll("all","");
793 oldpad->Divide(2,1);
794 win = 2;
795 oldpad->cd(1);
796 TVirtualPad *newpad = gPad;
797 pad = newpad;
798 pad->Divide(2,2);
799 pad->cd(1);
800 }
801 else
802 {
803 pad = oldpad;
804 pad->Divide(2,2);
805 pad->cd(1);
806 }
807
808 if (!IsEmpty())
809 gPad->SetLogy();
810
811 gPad->SetTicks();
812
813 fHGausHist.Draw(opt);
814 if (fFGausFit)
815 {
816 fFGausFit->SetLineColor(kBlue);
817 fFGausFit->Draw("same");
818 }
819 if (fSinglePheFit)
820 {
821 fSinglePheFit->SetLineColor(IsSinglePheFitOK() ? kGreen : kRed);
822 fSinglePheFit->Draw("same");
823 }
824
825 pad->cd(2);
826 DrawLegend();
827
828 pad->cd(3);
829 if (fHSinglePheFADCSlices)
830 delete fHSinglePheFADCSlices;
831
832 fHSinglePheFADCSlices = new TH1F(fASinglePheFADCSlices);
833 fHSinglePheFADCSlices->SetName("SinglePheFADCSlices");
834 fHSinglePheFADCSlices->SetTitle(Form("%s%f","Assumed Single Phe FADC Slices, Sum > ",fSinglePheCut));
835 fHSinglePheFADCSlices->SetXTitle("FADC slice number");
836 fHSinglePheFADCSlices->SetYTitle("FADC counts");
837 fHSinglePheFADCSlices->Draw(opt);
838
839 pad->cd(4);
840 if (fHPedestalFADCSlices)
841 delete fHPedestalFADCSlices;
842
843 fHPedestalFADCSlices = new TH1F(fAPedestalFADCSlices);
844 fHPedestalFADCSlices->SetName("PedestalFADCSlices");
845 fHPedestalFADCSlices->SetTitle(Form("%s%f","Pedestal FADC Slices, Sum < ",fSinglePheCut));
846 fHPedestalFADCSlices->SetXTitle("FADC slice number");
847 fHPedestalFADCSlices->SetYTitle("FADC counts");
848 fHPedestalFADCSlices->Draw(opt);
849
850 if (win < 2)
851 return;
852
853 oldpad->cd(2);
854 MHGausEvents::Draw("fourierevents");
855}
856
857
858
859
860
861
862
863
864
865
866
Note: See TracBrowser for help on using the repository browser.