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

Last change on this file since 3639 was 3639, checked in by gaug, 21 years ago
*** empty log message ***
File size: 30.0 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// Histogram class for the charge calibration of the Blind Pixel.
30// Stores and fits the charges and stores the averaged assumed pedestal and
31// single-phe FADC slice entries. Charges are taken from MExtractedSignalBlindPix.
32// Performs the Single Photo-electron fit to extract the Poisson mean and its errors.
33//
34// Different fits can be chosen with the function ChangeFitFunc().
35//
36// The fit result is accepted under the condition that:
37// 1) the Probability is greater than fProbLimit (default 0.001 == 99.7%)
38// 2) at least fNumSinglePheLimit events are found in the single Photo-electron peak
39//
40// The single FADC slice entries are averaged and stored in fASinglePheFADCSlices, if
41// their sum exceeds fSinglePheCut, otherwise in fAPedestalFADCSlices.
42//
43// Used numbers are the following:
44//
45// Electronic conversion factor:
46// Assume, we have N_e electrons at the anode,
47// thus a charge of N_e*e (e = electron charge) Coulomb.
48//
49// This charge is AC coupled and runs into a R_pre = 50 Ohm resistency.
50// The corresponding current is amplified by a gain factor G_pre = 400
51// (the precision of this value still has to be checked !!!) and again AC coupled to
52// the output.
53// The corresponding signal goes through the whole transmission and
54// amplification chain and is digitized in the FADCs.
55// The conversion Signal Area to FADC counts (Conv_trans) has been measured
56// by David and Oscar to be approx. 3.9 pVs^-1
57//
58// Thus: Conversion FADC counts to Number of Electrons at Anode:
59// FADC counts = (1/Conv_tran) * G_pre * R_pre * e * N_e = 8 * 10^-4 N_e.
60//
61// Also: FADC counts = 8*10^-4 * GAIN * N_phe
62//
63// In the blind pixel, there is an additional pre-amplifier with an amplification of
64// about 10. Therefore, we have for the blind pixel:
65//
66// FADC counts (Blind Pixel) = 8*10^-3 * GAIN * N_phe
67//
68//////////////////////////////////////////////////////////////////////////////
69#include "MHCalibrationChargeBlindPix.h"
70
71#include <TStyle.h>
72#include <TCanvas.h>
73#include <TPaveText.h>
74
75#include <TVector.h>
76#include <TF1.h>
77#include <TH1.h>
78#include <TRandom.h>
79
80#include "MLog.h"
81#include "MLogManip.h"
82
83#include "MParList.h"
84
85#include "MRawEvtData.h"
86#include "MRawEvtPixelIter.h"
87
88#include "MExtractedSignalBlindPixel.h"
89#include "MCalibrationChargeBlindPix.h"
90
91ClassImp(MHCalibrationChargeBlindPix);
92
93using namespace std;
94
95const Double_t MHCalibrationChargeBlindPix::gkElectronicAmp = 0.008;
96const Double_t MHCalibrationChargeBlindPix::gkElectronicAmpErr = 0.002;
97
98const Int_t MHCalibrationChargeBlindPix::fgChargeNbins = 5300;
99const Axis_t MHCalibrationChargeBlindPix::fgChargeFirst = -100.5;
100const Axis_t MHCalibrationChargeBlindPix::fgChargeLast = 5199.5;
101const Float_t MHCalibrationChargeBlindPix::fgSinglePheCut = 200.;
102const Float_t MHCalibrationChargeBlindPix::fgNumSinglePheLimit = 50.;
103// --------------------------------------------------------------------------
104//
105// Default Constructor.
106//
107// Sets:
108// - the default number for fNbins (fgChargeNbins)
109// - the default number for fFirst (fgChargeFirst)
110// - the default number for fLast (fgChargeLast)
111// - the default number for fSinglePheCut (fgSingePheCut)
112// - the default number for fNumSinglePheLimit (fgNumSinglePheLimit)
113// - the default number of bins after stripping (30)
114//
115// - the default name of the fHGausHist ("HCalibrationChargeBlindPix")
116// - the default title of the fHGausHist ("Distribution of Summed FADC slices Blind Pixel ")
117// - the default x-axis title for fHGausHist ("Sum FADC Slices")
118// - the default y-axis title for fHGausHist ("Nr. of events")
119//
120// Initializes:
121// - all pointers to NULL
122//
123// Calls:
124// - Clear()
125//
126MHCalibrationChargeBlindPix::MHCalibrationChargeBlindPix(const char *name, const char *title)
127 : fBlindPix(NULL), fSignal(NULL), fRawEvt(NULL),
128 fSinglePheFit(NULL),
129 fFitLegend(NULL),
130 fHSinglePheFADCSlices(NULL), fHPedestalFADCSlices(NULL)
131{
132
133 fName = name ? name : "MHCalibrationChargeBlindPix";
134 fTitle = title ? title : "Statistics of the FADC sums of Blind Pixel calibration events";
135
136 SetNbins( fgChargeNbins );
137 SetFirst( fgChargeFirst );
138 SetLast ( fgChargeLast );
139
140 SetSinglePheCut();
141 SetNumSinglePheLimit();
142
143 SetBinsAfterStripping(30);
144
145 fHGausHist.SetName("HCalibrationChargeBlindPix");
146 fHGausHist.SetTitle("Distribution of Summed FADC slices Blind Pixel");
147 fHGausHist.SetXTitle("Sum FADC Slices");
148 fHGausHist.SetYTitle("Nr. of events");
149
150 Clear();
151}
152
153// --------------------------------------------------------------------------
154//
155// Default Destructor.
156//
157// Deletes (if Pointer is not NULL):
158//
159// - fSinglePheFit
160// - fFitLegend
161// - fHSinglePheFADCSlices
162// - fHPedestalFADCSlices
163//
164MHCalibrationChargeBlindPix::~MHCalibrationChargeBlindPix()
165{
166
167 if (fSinglePheFit)
168 delete fSinglePheFit;
169
170 if (fFitLegend)
171 delete fFitLegend;
172
173 if (fHSinglePheFADCSlices)
174 delete fHSinglePheFADCSlices;
175
176 if (fHPedestalFADCSlices)
177 delete fHPedestalFADCSlices;
178
179}
180
181// --------------------------------------------------------------------------
182//
183// Sets:
184// - all variables to 0., except the fit result variables to -999.
185// - all flags to kFALSE
186// - all pointers to NULL
187// - the default fit function (kEPoisson5)
188//
189// Deletes:
190// - all pointers unequal NULL
191//
192// Calls:
193// - MHCalibrationChargePix::Clear()
194//
195void MHCalibrationChargeBlindPix::Clear(Option_t *o)
196{
197
198 fLambda = -999.;
199 fMu0 = -999.;
200 fMu1 = -999.;
201 fSigma0 = -999.;
202 fSigma1 = -999.;
203
204 fLambdaErr = -999.;
205 fMu0Err = -999.;
206 fMu1Err = -999.;
207 fSigma0Err = -999.;
208 fSigma1Err = -999.;
209
210 fLambdaCheck = -999.;
211 fLambdaCheckErr = -999.;
212
213 fFitFunc = kEPoisson5;
214
215 fNumSinglePhes = 0;
216 fNumPedestals = 0;
217
218 fChisquare = 0.;
219 fNDF = 0 ;
220 fProb = 0.;
221
222 SetSinglePheFitOK ( kFALSE );
223 SetPedestalFitOK ( kFALSE );
224
225 if (fFitLegend)
226 {
227 delete fFitLegend;
228 fFitLegend = NULL;
229 }
230
231 if (fSinglePheFit)
232 {
233 delete fSinglePheFit;
234 fSinglePheFit = NULL;
235 }
236
237 if (fHSinglePheFADCSlices)
238 {
239 delete fHSinglePheFADCSlices;
240 fHSinglePheFADCSlices = NULL;
241 }
242
243 if (fHPedestalFADCSlices)
244 {
245 delete fHPedestalFADCSlices;
246 fHPedestalFADCSlices = NULL;
247 }
248
249
250 MHCalibrationChargePix::Clear();
251 return;
252}
253
254// --------------------------------------------------------------------------
255//
256// Set bit kSinglePheFitOK from outside
257//
258void MHCalibrationChargeBlindPix::SetSinglePheFitOK (const Bool_t b)
259{
260 b ? SETBIT(fFlags,kSinglePheFitOK) : CLRBIT(fFlags,kSinglePheFitOK);
261}
262
263// --------------------------------------------------------------------------
264//
265// Set bit kPedestalFitOK from outside
266//
267void MHCalibrationChargeBlindPix::SetPedestalFitOK(const Bool_t b)
268{
269 b ? SETBIT(fFlags,kPedestalFitOK) : CLRBIT(fFlags,kPedestalFitOK);
270}
271
272// --------------------------------------------------------------------------
273//
274// Ask for status of bit kSinglePheFitOK
275//
276const Bool_t MHCalibrationChargeBlindPix::IsSinglePheFitOK() const
277{
278 return TESTBIT(fFlags,kSinglePheFitOK);
279}
280
281// --------------------------------------------------------------------------
282//
283// Ask for status of bit kPedestalFitOK
284//
285const Bool_t MHCalibrationChargeBlindPix::IsPedestalFitOK() const
286{
287 return TESTBIT(fFlags,kPedestalFitOK);
288}
289
290// --------------------------------------------------------------------------
291//
292// Gets the pointers to:
293// - MRawEvtData
294// - MExtractedSignalBlindPixel
295//
296// Initializes:
297// - fASinglePheFADCSlices(0);
298// - fAPedestalFADCSlices(0);
299//
300// Calls:
301// - MHGausHist::InitBins()
302//
303Bool_t MHCalibrationChargeBlindPix::SetupFill(const MParList *pList)
304{
305
306 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
307 if (!fRawEvt)
308 {
309 *fLog << err << "MRawEvtData not found... aborting." << endl;
310 return kFALSE;
311 }
312
313 fSignal = (MExtractedSignalBlindPixel*)pList->FindObject("MExtractedSignalBlindPixel");
314 if (!fSignal)
315 {
316 *fLog << err << "MExtractedSignalBlindPixel not found... aborting " << endl;
317 return kFALSE;
318 }
319
320 fASinglePheFADCSlices(0);
321 fAPedestalFADCSlices(0);
322
323 InitBins();
324
325 return kTRUE;
326}
327
328// --------------------------------------------------------------------------
329//
330// Gets or creates the pointers to:
331// - MCalibrationChargeBlindPix
332//
333Bool_t MHCalibrationChargeBlindPix::ReInit(MParList *pList)
334{
335
336 fBlindPix = (MCalibrationChargeBlindPix*)pList->FindCreateObj("MCalibrationChargeBlindPix");
337 if (!fBlindPix)
338 return kFALSE;
339
340 return kTRUE;
341}
342
343// --------------------------------------------------------------------------
344//
345// Retrieves from MExtractedSignalBlindPixel:
346// - number of FADC samples
347// - extracted signal
348// - blind Pixel ID
349//
350// Resizes (if necessary):
351// - fASinglePheFADCSlices to sum of HiGain and LoGain samples
352// - fAPedestalFADCSlices to sum of HiGain and LoGain samples
353//
354// Fills the following histograms:
355// - MHGausEvents::FillHistAndArray(signal)
356//
357// Creates MRawEvtPixelIter, jumps to blind pixel ID,
358// fills the vectors fASinglePheFADCSlices and fAPedestalFADCSlices
359// with the full FADC slices, depending on the size of the signal w.r.t. fSinglePheCut
360//
361Bool_t MHCalibrationChargeBlindPix::Fill(const MParContainer *par, const Stat_t w)
362{
363
364 const Int_t samples = (Int_t)fRawEvt->GetNumHiGainSamples()+(Int_t)fRawEvt->GetNumLoGainSamples();
365
366 if (fASinglePheFADCSlices.GetNrows() != samples)
367 {
368 fASinglePheFADCSlices.ResizeTo(samples);
369 fAPedestalFADCSlices.ResizeTo(samples);
370 }
371
372 Float_t slices = (Float_t)fSignal->GetNumFADCSamples();
373
374 if (slices == 0.)
375 {
376 *fLog << err << "Number of used signal slices in MExtractedSignalBlindPix is zero ... abort."
377 << endl;
378 return kFALSE;
379 }
380
381 //
382 // Signal extraction and histogram filling
383 //
384 const Float_t signal = (Float_t)fSignal->GetExtractedSignal();
385 FillHistAndArray(signal);
386
387 //
388 // IN order to study the single-phe posistion, we extract the slices
389 //
390 const Int_t blindpixIdx = fSignal->GetBlindPixelIdx();
391
392 MRawEvtPixelIter pixel(fRawEvt);
393 pixel.Jump(blindpixIdx);
394
395 if (signal > fSinglePheCut)
396 FillSinglePheFADCSlices(pixel);
397 else
398 FillPedestalFADCSlices(pixel);
399
400 return kTRUE;
401}
402
403// --------------------------------------------------------------------------
404//
405// Returns kFALSE, if empty
406//
407// - Creates the fourier spectrum and sets bit MHGausEvents::IsFourierSpectrumOK()
408// - Retrieves the pedestals from MExtractedSignalBlindPixel
409// - Normalizes fASinglePheFADCSlices and fAPedestalFADCSlices
410// - Executes FitPedestal()
411// - Executes FitSinglePhe()
412// - Retrieves fit results and stores them in MCalibrationChargeBlindPix
413//
414Bool_t MHCalibrationChargeBlindPix::Finalize()
415{
416
417 if (IsEmpty())
418 {
419 *fLog << err << GetDescriptor() << ": My histogram has not been filled !! " << endl;
420 return kFALSE;
421 }
422
423 CreateFourierSpectrum();
424 fBlindPix->SetOscillating ( !IsFourierSpectrumOK() );
425
426 fMeanPedestal = fSignal->GetPed();
427 fMeanPedestalErr = fSignal->GetPedErr();
428 fSigmaPedestal = fSignal->GetPedRms();
429 fSigmaPedestalErr = fSignal->GetPedRmsErr();
430
431 if (fNumSinglePhes > 1)
432 for (Int_t i=0;i<fASinglePheFADCSlices.GetNrows();i++)
433 fASinglePheFADCSlices[i] = fASinglePheFADCSlices[i]/fNumSinglePhes;
434 if (fNumPedestals > 1)
435 for (Int_t i=0;i<fAPedestalFADCSlices.GetNrows();i++)
436 fAPedestalFADCSlices[i] = fAPedestalFADCSlices[i]/fNumPedestals;
437
438 FitPedestal();
439
440 if (FitSinglePhe())
441 fBlindPix->SetSinglePheFitOK();
442
443 fBlindPix->SetLambda ( fLambda );
444 fBlindPix->SetMu0 ( fMu0 );
445 fBlindPix->SetMu0Err ( fMu0Err );
446 fBlindPix->SetMu1 ( fMu1 );
447 fBlindPix->SetMu1Err ( fMu1Err );
448 fBlindPix->SetSigma0 ( fSigma0 );
449 fBlindPix->SetSigma0Err ( fSigma0Err );
450 fBlindPix->SetSigma1 ( fSigma1 );
451 fBlindPix->SetSigma1Err ( fSigma1Err );
452 fBlindPix->SetProb ( fProb );
453
454 fBlindPix->SetLambdaCheck ( fLambdaCheck );
455 fBlindPix->SetLambdaCheckErr ( fLambdaCheckErr );
456
457 return kTRUE;
458}
459
460
461// --------------------------------------------------------------------------
462//
463// Checks again for the size and fills fASinglePheFADCSlices with the FADC slice entries
464//
465void MHCalibrationChargeBlindPix::FillSinglePheFADCSlices(const MRawEvtPixelIter &iter)
466{
467
468 const Int_t n = iter.GetNumHiGainSamples() + iter.GetNumLoGainSamples();
469
470 if (fASinglePheFADCSlices.GetNrows() < n)
471 fASinglePheFADCSlices.ResizeTo(n);
472
473 Int_t i=0;
474
475 Byte_t *start = iter.GetHiGainSamples();
476 Byte_t *end = start + iter.GetNumHiGainSamples();
477
478 for (Byte_t *ptr = start; ptr < end; ptr++, i++)
479 fASinglePheFADCSlices(i) = fASinglePheFADCSlices(i) + (Float_t)*ptr;
480
481 start = iter.GetLoGainSamples();
482 end = start + iter.GetNumLoGainSamples();
483
484 for (Byte_t *ptr = start; ptr < end; ptr++, i++)
485 fASinglePheFADCSlices(i) = fASinglePheFADCSlices(i) + (Float_t)*ptr;
486
487 fNumSinglePhes++;
488}
489
490// --------------------------------------------------------------------------
491//
492// Checks again for the size and fills fAPedestalFADCSlices with the FADC slice entries
493//
494void MHCalibrationChargeBlindPix::FillPedestalFADCSlices(const MRawEvtPixelIter &iter)
495{
496
497 const Int_t n = iter.GetNumHiGainSamples() + iter.GetNumLoGainSamples();
498
499 if (fAPedestalFADCSlices.GetNrows() < n)
500 fAPedestalFADCSlices.ResizeTo(n);
501
502 Int_t i = 0;
503 Byte_t *start = iter.GetHiGainSamples();
504 Byte_t *end = start + iter.GetNumHiGainSamples();
505
506 for (Byte_t *ptr = start; ptr < end; ptr++, i++)
507 fAPedestalFADCSlices(i) = fAPedestalFADCSlices(i)+ (Float_t)*ptr;
508
509 start = iter.GetLoGainSamples();
510 end = start + iter.GetNumLoGainSamples();
511
512 for (Byte_t *ptr = start; ptr < end; ptr++, i++)
513 fAPedestalFADCSlices(i) = fAPedestalFADCSlices(i)+ (Float_t)*ptr;
514
515 fNumPedestals++;
516}
517
518
519// --------------------------------------------------------------------------
520//
521// Task to simulate single phe spectrum with the given parameters
522//
523Bool_t MHCalibrationChargeBlindPix::SimulateSinglePhe(Double_t lambda, Double_t mu0, Double_t mu1, Double_t sigma0, Double_t sigma1)
524{
525
526 gRandom->SetSeed();
527
528 if (fHGausHist.GetIntegral() != 0)
529 {
530 *fLog << err << "Histogram " << fHGausHist.GetTitle() << " is already filled. " << endl;
531 *fLog << err << "Create new class MHCalibrationBlindPixel for simulation! " << endl;
532 return kFALSE;
533 }
534
535 if (!InitFit())
536 return kFALSE;
537
538 for (Int_t i=0;i<10000; i++)
539 fHGausHist.Fill(fSinglePheFit->GetRandom());
540
541 return kTRUE;
542}
543
544// --------------------------------------------------------------------------
545//
546// - Get the ranges from the stripped histogram
547// - choose reasonable start values for the fit
548// - initialize the fit function depending on fFitFunc
549// - initialize parameter names and limits depending on fFitFunc
550//
551Bool_t MHCalibrationChargeBlindPix::InitFit()
552{
553
554 //
555 // Get the fitting ranges
556 //
557 Axis_t rmin = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetFirst());
558 Axis_t rmax = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetLast());
559
560 if (rmin < 0.)
561 rmin = 0.;
562
563 //
564 // First guesses for the fit (should be as close to reality as possible,
565 // otherwise the fit goes gaga because of high number of dimensions ...
566 //
567 const Stat_t entries = fHGausHist.Integral("width");
568 const Double_t lambda_guess = 0.1;
569 const Double_t maximum_bin = fHGausHist.GetBinCenter(fHGausHist.GetMaximumBin());
570 const Double_t norm = entries/TMath::Sqrt(TMath::TwoPi());
571
572 //
573 // Initialize the fit function
574 //
575 switch (fFitFunc)
576 {
577 case kEPoisson4:
578 fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto4,rmin,rmax,6);
579 break;
580 case kEPoisson5:
581 fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto5,rmin,rmax,6);
582 break;
583 case kEPoisson6:
584 fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto6,rmin,rmax,6);
585 break;
586 case kEPolya:
587 fSinglePheFit = new TF1("SinglePheFit",&fPolya,rmin,rmax,8);
588 break;
589 case kEMichele:
590 break;
591
592 default:
593 *fLog << warn << "WARNING: Could not find Fit Function for Blind Pixel " << endl;
594 return kFALSE;
595 break;
596 }
597
598 if (!fSinglePheFit)
599 {
600 *fLog << warn << dbginf << "WARNING: Could not create fit function for Single Phe fit" << endl;
601 return kFALSE;
602 }
603
604 const Double_t mu_0_guess = maximum_bin;
605 const Double_t si_0_guess = 40.;
606 const Double_t mu_1_guess = mu_0_guess + 100.;
607 const Double_t si_1_guess = si_0_guess + si_0_guess;
608 // Michele
609// const Double_t lambda_1cat_guess = 0.5;
610 // const Double_t lambda_1dyn_guess = 0.5;
611 // const Double_t mu_1cat_guess = mu_0_guess + 50.;
612 // const Double_t mu_1dyn_guess = mu_0_guess + 20.;
613 // const Double_t si_1cat_guess = si_0_guess + si_0_guess;
614 // const Double_t si_1dyn_guess = si_0_guess;
615 // Polya
616 const Double_t excessPoisson_guess = 0.5;
617 const Double_t delta1_guess = 8.;
618 const Double_t delta2_guess = 5.;
619 const Double_t electronicAmp_guess = gkElectronicAmp;
620 const Double_t electronicAmp_limit = gkElectronicAmpErr;
621
622 //
623 // Initialize boundaries and start parameters
624 //
625 switch (fFitFunc)
626 {
627
628 case kEPoisson4:
629 fSinglePheFit->SetParNames( "#lambda", "#mu_{0}", "#mu_{1}", "#sigma_{0}", "#sigma_{1}","Area");
630 fSinglePheFit->SetParameters(lambda_guess,fMeanPedestal,mu_1_guess,fSigmaPedestal,si_1_guess,norm);
631
632 fSinglePheFit->SetParLimits(0,0.,0.5);
633 fSinglePheFit->SetParLimits(1,
634 fMeanPedestal-5.*fMeanPedestalErr,
635 fMeanPedestal+5.*fMeanPedestalErr);
636 fSinglePheFit->SetParLimits(2,rmin,rmax);
637 fSinglePheFit->SetParLimits(3,
638 fSigmaPedestal-5.*fSigmaPedestalErr,
639 fSigmaPedestal+5.*fSigmaPedestalErr);
640 fSinglePheFit->SetParLimits(4,0.,(rmax-rmin));
641 fSinglePheFit->SetParLimits(5,norm-(0.5*norm),norm+(0.5*norm));
642 break;
643 case kEPoisson5:
644 case kEPoisson6:
645 fSinglePheFit->SetParameters(lambda_guess,mu_0_guess,mu_1_guess,si_0_guess,si_1_guess,norm);
646 fSinglePheFit->SetParNames("#lambda","#mu_{0}","#mu_{1}","#sigma_{0}","#sigma_{1}","Area");
647 fSinglePheFit->SetParLimits(0,0.,1.);
648 fSinglePheFit->SetParLimits(1,rmin,(rmax-rmin)/1.5);
649 fSinglePheFit->SetParLimits(2,(rmax-rmin)/2.,(rmax-0.05*(rmax-rmin)));
650 fSinglePheFit->SetParLimits(3,1.0,(rmax-rmin)/2.0);
651 fSinglePheFit->SetParLimits(4,1.0,(rmax-rmin)/2.5);
652 fSinglePheFit->SetParLimits(5,norm-0.1,norm+0.1);
653 break;
654
655 case kEPolya:
656 fSinglePheFit->SetParameters(lambda_guess, excessPoisson_guess,
657 delta1_guess,delta2_guess,
658 electronicAmp_guess,
659 fSigmaPedestal,
660 norm,
661 fMeanPedestal);
662 fSinglePheFit->SetParNames("#lambda","b_{tot}",
663 "#delta_{1}","#delta_{2}",
664 "amp_{e}","#sigma_{0}",
665 "Area", "#mu_{0}");
666 fSinglePheFit->SetParLimits(0,0.,1.);
667 fSinglePheFit->SetParLimits(1,0.,1.);
668 fSinglePheFit->SetParLimits(2,6.,12.);
669 fSinglePheFit->SetParLimits(3,3.,8.);
670 fSinglePheFit->SetParLimits(4,electronicAmp_guess-electronicAmp_limit,
671 electronicAmp_guess+electronicAmp_limit);
672 fSinglePheFit->SetParLimits(5,
673 fSigmaPedestal-3.*fSigmaPedestalErr,
674 fSigmaPedestal+3.*fSigmaPedestalErr);
675 fSinglePheFit->SetParLimits(6,norm-0.1,norm+0.1);
676 fSinglePheFit->SetParLimits(7,
677 fMeanPedestal-3.*fMeanPedestalErr,
678 fMeanPedestal+3.*fMeanPedestalErr);
679 break;
680 case kEMichele:
681 break;
682
683 default:
684 *fLog << warn << "WARNING: Could not find Fit Function for Blind Pixel " << endl;
685 return kFALSE;
686 break;
687 }
688
689 fSinglePheFit->SetRange(rmin,rmax);
690
691 return kTRUE;
692}
693
694// --------------------------------------------------------------------------
695//
696// - Retrieve the parameters depending on fFitFunc
697// - Retrieve probability, Chisquare and NDF
698//
699void MHCalibrationChargeBlindPix::ExitFit()
700{
701
702
703 //
704 // Finalize
705 //
706 switch (fFitFunc)
707 {
708
709 case kEPoisson4:
710 case kEPoisson5:
711 case kEPoisson6:
712 case kEPoisson7:
713 fLambda = fSinglePheFit->GetParameter(0);
714 fMu0 = fSinglePheFit->GetParameter(1);
715 fMu1 = fSinglePheFit->GetParameter(2);
716 fSigma0 = fSinglePheFit->GetParameter(3);
717 fSigma1 = fSinglePheFit->GetParameter(4);
718
719 fLambdaErr = fSinglePheFit->GetParError(0);
720 fMu0Err = fSinglePheFit->GetParError(1);
721 fMu1Err = fSinglePheFit->GetParError(2);
722 fSigma0Err = fSinglePheFit->GetParError(3);
723 fSigma1Err = fSinglePheFit->GetParError(4);
724 break;
725 case kEPolya:
726 fLambda = fSinglePheFit->GetParameter(0);
727 fMu0 = fSinglePheFit->GetParameter(7);
728 fMu1 = 0.;
729 fSigma0 = fSinglePheFit->GetParameter(5);
730 fSigma1 = 0.;
731
732 fLambdaErr = fSinglePheFit->GetParError(0);
733 fMu0Err = fSinglePheFit->GetParError(7);
734 fMu1Err = 0.;
735 fSigma0Err = fSinglePheFit->GetParError(5);
736 fSigma1Err = 0.;
737 default:
738 break;
739 }
740
741 fProb = fSinglePheFit->GetProb();
742 fChisquare = fSinglePheFit->GetChisquare();
743 fNDF = fSinglePheFit->GetNDF();
744
745 *fLog << all << "Results of the Blind Pixel Fit: " << endl;
746 *fLog << all << "Chisquare: " << fChisquare << endl;
747 *fLog << all << "DoF: " << fNDF << endl;
748 *fLog << all << "Probability: " << fProb << endl;
749
750}
751
752// --------------------------------------------------------------------------
753//
754// - Executes InitFit()
755// - Fits the fHGausHist with fSinglePheFit
756// - Executes ExitFit()
757//
758// The fit result is accepted under condition:
759// 1) The results are not nan's
760// 2) The NDF is not smaller than fNDFLimit (5)
761// 3) The Probability is greater than fProbLimit (default 0.001 == 99.9%)
762// 4) at least fNumSinglePheLimit events are in the single Photo-electron peak
763//
764Bool_t MHCalibrationChargeBlindPix::FitSinglePhe(Option_t *opt)
765{
766
767 if (!InitFit())
768 return kFALSE;
769
770 fHGausHist.Fit(fSinglePheFit,opt);
771
772 ExitFit();
773
774 //
775 // The fit result is accepted under condition:
776 // 1) The results are not nan's
777 // 2) The NDF is not smaller than fNDFLimit (5)
778 // 3) The Probability is greater than fProbLimit (default 0.001 == 99.9%)
779 // 4) at least fNumSinglePheLimit events are in the single Photo-electron peak
780 //
781 if ( TMath::IsNaN(fLambda)
782 || TMath::IsNaN(fLambdaErr)
783 || TMath::IsNaN(fProb)
784 || TMath::IsNaN(fMu0)
785 || TMath::IsNaN(fMu0Err)
786 || TMath::IsNaN(fMu1)
787 || TMath::IsNaN(fMu1Err)
788 || TMath::IsNaN(fSigma0)
789 || TMath::IsNaN(fSigma0Err)
790 || TMath::IsNaN(fSigma1)
791 || TMath::IsNaN(fSigma1Err)
792 || fNDF < fNDFLimit
793 || fProb < fProbLimit )
794 return kFALSE;
795
796 const Stat_t entries = fHGausHist.Integral("width");
797 const Float_t numSinglePhe = TMath::Exp(-1.0*fLambda)*fLambda*entries;
798
799 if (numSinglePhe < fNumSinglePheLimit)
800 {
801 *fLog << warn << "WARNING - Statistics is too low: Only " << numSinglePhe
802 << " in the Single Photo-Electron peak " << endl;
803 return kFALSE;
804 }
805 else
806 *fLog << all << numSinglePhe << " in Single Photo-Electron peak " << endl;
807
808 SetSinglePheFitOK();
809 return kTRUE;
810}
811
812// --------------------------------------------------------------------------
813//
814// - Retrieves limits for the fit
815// - Fits the fHGausHist with Gauss
816// - Retrieves the results to fLambdaCheck and fLambdaCheckErr
817// - Sets a flag IsPedestalFitOK()
818//
819void MHCalibrationChargeBlindPix::FitPedestal (Option_t *opt)
820{
821
822 // Perform the cross-check fitting only the pedestal:
823 const Axis_t rmin = 0.;
824 const Axis_t rmax = fHGausHist.GetBinCenter(fHGausHist.GetMaximumBin());
825
826 FitGaus(opt, rmin, rmax);
827
828 const Stat_t entries = fHGausHist.Integral("width");
829 const Double_t fitarea = fFGausFit->GetParameter(0);
830 const Double_t pedarea = fitarea * TMath::Sqrt(TMath::TwoPi()) * fFGausFit->GetParameter(2);
831
832 fLambdaCheck = TMath::Log(entries/pedarea);
833 fLambdaCheckErr = fFGausFit->GetParError(0)/fFGausFit->GetParameter(0)
834 + fFGausFit->GetParError(2)/fFGausFit->GetParameter(2);
835
836
837 SetPedestalFitOK();
838 return;
839}
840
841
842// -------------------------------------------------------------------------
843//
844// Draw a legend with the fit results
845//
846void MHCalibrationChargeBlindPix::DrawLegend()
847{
848
849 if (!fFitLegend)
850 {
851 fFitLegend = new TPaveText(0.05,0.05,0.95,0.95);
852 fFitLegend->SetLabel(Form("%s%s", "Results of the single PhE Fit (",
853 (fFitFunc = kEPoisson4) ? "Poisson(k=4))" :
854 (fFitFunc = kEPoisson5) ? "Poisson(k=5))" :
855 (fFitFunc = kEPoisson6) ? "Poisson(k=4))" :
856 (fFitFunc = kEPolya ) ? "Polya(k=4))" :
857 (fFitFunc = kEMichele ) ? "Michele)" : " none )" ));
858 fFitLegend->SetTextSize(0.05);
859 }
860 else
861 fFitLegend->Clear();
862
863 const TString line1 =
864 Form("Mean: #lambda = %2.2f #pm %2.2f",fLambda,fLambdaErr);
865 TText *t1 = fFitLegend->AddText(line1.Data());
866 t1->SetBit(kCanDelete);
867
868 const TString line6 =
869 Form("Mean #lambda (check) = %2.2f #pm %2.2f",fLambdaCheck,fLambdaCheckErr);
870 TText *t2 = fFitLegend->AddText(line6.Data());
871 t2->SetBit(kCanDelete);
872
873 const TString line2 =
874 Form("Pedestal: #mu_{0} = %2.2f #pm %2.2f",fMu0,fMu0Err);
875 TText *t3 = fFitLegend->AddText(line2.Data());
876 t3->SetBit(kCanDelete);
877
878 const TString line3 =
879 Form("Width Pedestal: #sigma_{0} = %2.2f #pm %2.2f",fSigma0,fSigma0Err);
880 TText *t4 = fFitLegend->AddText(line3.Data());
881 t4->SetBit(kCanDelete);
882
883 const TString line4 =
884 Form("1^{st} Phe-peak: #mu_{1} = %2.2f #pm %2.2f",fMu1,fMu1Err);
885 TText *t5 = fFitLegend->AddText(line4.Data());
886 t5->SetBit(kCanDelete);
887
888 const TString line5 =
889 Form("Width 1^{st} Phe-peak: #sigma_{1} = %2.2f #pm %2.2f",fSigma1,fSigma1Err);
890 TText *t6 = fFitLegend->AddText(line5.Data());
891 t6->SetBit(kCanDelete);
892
893 const TString line7 =
894 Form("#chi^{2} / N_{dof}: %4.2f / %3i",fChisquare,fNDF);
895 TText *t7 = fFitLegend->AddText(line7.Data());
896 t7->SetBit(kCanDelete);
897
898 const TString line8 =
899 Form("Probability: %4.2f ",fProb);
900 TText *t8 = fFitLegend->AddText(line8.Data());
901 t8->SetBit(kCanDelete);
902
903 if (IsSinglePheFitOK())
904 {
905 TText *t = fFitLegend->AddText(0.,0.,"Result of the Fit: OK");
906 t->SetBit(kCanDelete);
907 }
908 else
909 {
910 TText *t = fFitLegend->AddText("Result of the Fit: NOT OK");
911 t->SetBit(kCanDelete);
912 }
913
914 fFitLegend->SetFillColor(IsSinglePheFitOK() ? 80 : 2);
915 fFitLegend->Draw();
916
917 return;
918}
919
920
921// -------------------------------------------------------------------------
922//
923// Draw the histogram
924//
925// The following options can be chosen:
926//
927// "": displays the fHGausHist, the legend and fASinglePheFADCSlices and fAPedestalFADCSlices
928// "all": executes additionally MHGausEvents::Draw(), with option "fourierevents"
929//
930void MHCalibrationChargeBlindPix::Draw(Option_t *opt)
931{
932
933 TString option(opt);
934 option.ToLower();
935
936 Int_t win = 1;
937
938 TVirtualPad *oldpad = gPad ? gPad : MH::MakeDefCanvas(this,900, 600);
939 TVirtualPad *pad = NULL;
940
941 oldpad->SetBorderMode(0);
942
943 if (option.Contains("all"))
944 {
945 option.ReplaceAll("all","");
946 oldpad->Divide(2,1);
947 win = 2;
948 oldpad->cd(1);
949 TVirtualPad *newpad = gPad;
950 pad = newpad;
951 pad->Divide(2,2);
952 pad->cd(1);
953 }
954 else
955 {
956 pad = oldpad;
957 pad->Divide(2,2);
958 pad->cd(1);
959 }
960
961 if (!IsEmpty())
962 gPad->SetLogy();
963
964 gPad->SetTicks();
965
966 fHGausHist.Draw(opt);
967 if (fFGausFit)
968 {
969 fFGausFit->SetLineColor(kBlue);
970 fFGausFit->Draw("same");
971 }
972 if (fSinglePheFit)
973 {
974 fSinglePheFit->SetLineColor(IsSinglePheFitOK() ? kGreen : kRed);
975 fSinglePheFit->Draw("same");
976 }
977
978 pad->cd(2);
979 DrawLegend();
980
981 pad->cd(3);
982 if (fHSinglePheFADCSlices)
983 delete fHSinglePheFADCSlices;
984
985 fHSinglePheFADCSlices = new TH1F(fASinglePheFADCSlices);
986 fHSinglePheFADCSlices->SetName("SinglePheFADCSlices");
987 fHSinglePheFADCSlices->SetTitle(Form("%s%f","Assumed Single Phe FADC Slices, Sum > ",fSinglePheCut));
988 fHSinglePheFADCSlices->SetXTitle("FADC slice number");
989 fHSinglePheFADCSlices->SetYTitle("FADC counts");
990 fHSinglePheFADCSlices->Draw(opt);
991
992 pad->cd(4);
993 if (fHPedestalFADCSlices)
994 delete fHPedestalFADCSlices;
995
996 fHPedestalFADCSlices = new TH1F(fAPedestalFADCSlices);
997 fHPedestalFADCSlices->SetName("PedestalFADCSlices");
998 fHPedestalFADCSlices->SetTitle(Form("%s%f","Pedestal FADC Slices, Sum < ",fSinglePheCut));
999 fHPedestalFADCSlices->SetXTitle("FADC slice number");
1000 fHPedestalFADCSlices->SetYTitle("FADC counts");
1001 fHPedestalFADCSlices->Draw(opt);
1002
1003 if (win < 2)
1004 return;
1005
1006 oldpad->cd(2);
1007 MHGausEvents::Draw("fourierevents");
1008}
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
Note: See TracBrowser for help on using the repository browser.