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

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