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

Last change on this file since 3636 was 3622, 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 fChargeNbins (fgChargeNbins)
108// - the default number for fChargeFirst (fgChargeFirst)
109// - the default number for fChargeLast (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 SetChargeNbins();
135 SetChargeFirst();
136 SetChargeLast();
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 following histograms:
281// - fHGausHist.SetBins(fChargeNbins,fChargeFirst,fChargeLast);
282//
283Bool_t MHCalibrationChargeBlindPix::SetupFill(const MParList *pList)
284{
285
286 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
287 if (!fRawEvt)
288 {
289 *fLog << err << "MRawEvtData not found... aborting." << endl;
290 return kFALSE;
291 }
292
293 fSignal = (MExtractedSignalBlindPixel*)pList->FindObject("MExtractedSignalBlindPixel");
294 if (!fSignal)
295 {
296 *fLog << err << "MExtractedSignalBlindPixel not found... aborting " << endl;
297 return kFALSE;
298 }
299
300 fASinglePheFADCSlices(0);
301 fAPedestalFADCSlices(0);
302
303 fHGausHist.SetBins( fChargeNbins, fChargeFirst, fChargeLast);
304
305 return kTRUE;
306}
307
308// --------------------------------------------------------------------------
309//
310// Gets or creates the pointers to:
311// - MCalibrationChargeBlindPix
312//
313Bool_t MHCalibrationChargeBlindPix::ReInit(MParList *pList)
314{
315
316 fBlindPix = (MCalibrationChargeBlindPix*)pList->FindCreateObj("MCalibrationChargeBlindPix");
317 if (!fBlindPix)
318 return kFALSE;
319
320 return kTRUE;
321}
322
323// --------------------------------------------------------------------------
324//
325// Retrieves from MExtractedSignalBlindPixel:
326// - number of FADC samples
327// - extracted signal
328// - blind Pixel ID
329//
330// Resizes (if necessary):
331// - fASinglePheFADCSlices to sum of HiGain and LoGain samples
332// - fAPedestalFADCSlices to sum of HiGain and LoGain samples
333//
334// Fills the following histograms:
335// - MHGausEvents::FillHistAndArray(signal)
336//
337// Creates MRawEvtPixelIter, jumps to blind pixel ID,
338// fills the vectors fASinglePheFADCSlices and fAPedestalFADCSlices
339// with the full FADC slices, depending on the size of the signal w.r.t. fSinglePheCut
340//
341Bool_t MHCalibrationChargeBlindPix::Fill(const MParContainer *par, const Stat_t w)
342{
343
344 const Int_t samples = (Int_t)fRawEvt->GetNumHiGainSamples()+(Int_t)fRawEvt->GetNumLoGainSamples();
345
346 if (fASinglePheFADCSlices.GetNrows() != samples)
347 {
348 fASinglePheFADCSlices.ResizeTo(samples);
349 fAPedestalFADCSlices.ResizeTo(samples);
350 }
351
352 Float_t slices = (Float_t)fSignal->GetNumFADCSamples();
353
354 if (slices == 0.)
355 {
356 *fLog << err << "Number of used signal slices in MExtractedSignalBlindPix is zero ... abort."
357 << endl;
358 return kFALSE;
359 }
360
361 //
362 // Signal extraction and histogram filling
363 //
364 const Float_t signal = (Float_t)fSignal->GetExtractedSignal();
365 FillHistAndArray(signal);
366
367 //
368 // IN order to study the single-phe posistion, we extract the slices
369 //
370 const Int_t blindpixIdx = fSignal->GetBlindPixelIdx();
371
372 MRawEvtPixelIter pixel(fRawEvt);
373 pixel.Jump(blindpixIdx);
374
375 if (signal > fSinglePheCut)
376 FillSinglePheFADCSlices(pixel);
377 else
378 FillPedestalFADCSlices(pixel);
379
380 return kTRUE;
381}
382
383// --------------------------------------------------------------------------
384//
385// Returns kFALSE, if empty
386//
387// - Creates the fourier spectrum and sets bit IsFourierSpectrumOK()
388// - Retrieves the pedestals from MExtractedSignalBlindPixel
389// - Normalizes fASinglePheFADCSlices and fAPedestalFADCSlices
390// - Executes FitPedestal()
391// - Executes FitSinglePhe()
392// - Retrieves fit results and stores them in MCalibrationChargeBlindPix
393//
394Bool_t MHCalibrationChargeBlindPix::Finalize()
395{
396
397 if (IsEmpty())
398 {
399 *fLog << err << GetDescriptor() << ": My histogram has not been filled !! " << endl;
400 return kFALSE;
401 }
402
403 CreateFourierSpectrum();
404 fBlindPix->SetOscillating ( !IsFourierSpectrumOK() );
405
406 fMeanPedestal = fSignal->GetPed();
407 fMeanPedestalErr = fSignal->GetPedErr();
408 fSigmaPedestal = fSignal->GetPedRms();
409 fSigmaPedestalErr = fSignal->GetPedRmsErr();
410
411 if (fNumSinglePhes > 1)
412 for (Int_t i=0;i<fASinglePheFADCSlices.GetNrows();i++)
413 fASinglePheFADCSlices[i] = fASinglePheFADCSlices[i]/fNumSinglePhes;
414 if (fNumPedestals > 1)
415 for (Int_t i=0;i<fAPedestalFADCSlices.GetNrows();i++)
416 fAPedestalFADCSlices[i] = fAPedestalFADCSlices[i]/fNumPedestals;
417
418 FitPedestal();
419
420 if (FitSinglePhe())
421 fBlindPix->SetSinglePheFitOK();
422
423 fBlindPix->SetLambda ( fLambda );
424 fBlindPix->SetMu0 ( fMu0 );
425 fBlindPix->SetMu0Err ( fMu0Err );
426 fBlindPix->SetMu1 ( fMu1 );
427 fBlindPix->SetMu1Err ( fMu1Err );
428 fBlindPix->SetSigma0 ( fSigma0 );
429 fBlindPix->SetSigma0Err ( fSigma0Err );
430 fBlindPix->SetSigma1 ( fSigma1 );
431 fBlindPix->SetSigma1Err ( fSigma1Err );
432 fBlindPix->SetProb ( fProb );
433
434 fBlindPix->SetLambdaCheck ( fLambdaCheck );
435 fBlindPix->SetLambdaCheckErr ( fLambdaCheckErr );
436
437 return kTRUE;
438}
439
440
441// --------------------------------------------------------------------------
442//
443// Checks again for the size and fills fASinglePheFADCSlices with the FADC slice entries
444//
445void MHCalibrationChargeBlindPix::FillSinglePheFADCSlices(const MRawEvtPixelIter &iter)
446{
447
448 const Int_t n = iter.GetNumHiGainSamples() + iter.GetNumLoGainSamples();
449
450 if (fASinglePheFADCSlices.GetNrows() < n)
451 fASinglePheFADCSlices.ResizeTo(n);
452
453 Int_t i=0;
454
455 Byte_t *start = iter.GetHiGainSamples();
456 Byte_t *end = start + iter.GetNumHiGainSamples();
457
458 for (Byte_t *ptr = start; ptr < end; ptr++, i++)
459 fASinglePheFADCSlices(i) = fASinglePheFADCSlices(i) + (Float_t)*ptr;
460
461 start = iter.GetLoGainSamples();
462 end = start + iter.GetNumLoGainSamples();
463
464 for (Byte_t *ptr = start; ptr < end; ptr++, i++)
465 fASinglePheFADCSlices(i) = fASinglePheFADCSlices(i) + (Float_t)*ptr;
466
467 fNumSinglePhes++;
468}
469
470// --------------------------------------------------------------------------
471//
472// Checks again for the size and fills fAPedestalFADCSlices with the FADC slice entries
473//
474void MHCalibrationChargeBlindPix::FillPedestalFADCSlices(const MRawEvtPixelIter &iter)
475{
476
477 const Int_t n = iter.GetNumHiGainSamples() + iter.GetNumLoGainSamples();
478
479 if (fAPedestalFADCSlices.GetNrows() < n)
480 fAPedestalFADCSlices.ResizeTo(n);
481
482 Int_t i = 0;
483 Byte_t *start = iter.GetHiGainSamples();
484 Byte_t *end = start + iter.GetNumHiGainSamples();
485
486 for (Byte_t *ptr = start; ptr < end; ptr++, i++)
487 fAPedestalFADCSlices(i) = fAPedestalFADCSlices(i)+ (Float_t)*ptr;
488
489 start = iter.GetLoGainSamples();
490 end = start + iter.GetNumLoGainSamples();
491
492 for (Byte_t *ptr = start; ptr < end; ptr++, i++)
493 fAPedestalFADCSlices(i) = fAPedestalFADCSlices(i)+ (Float_t)*ptr;
494
495 fNumPedestals++;
496}
497
498
499// --------------------------------------------------------------------------
500//
501// Task to simulate single phe spectrum with the given parameters
502//
503Bool_t MHCalibrationChargeBlindPix::SimulateSinglePhe(Double_t lambda, Double_t mu0, Double_t mu1, Double_t sigma0, Double_t sigma1)
504{
505
506 gRandom->SetSeed();
507
508 if (fHGausHist.GetIntegral() != 0)
509 {
510 *fLog << err << "Histogram " << fHGausHist.GetTitle() << " is already filled. " << endl;
511 *fLog << err << "Create new class MHCalibrationBlindPixel for simulation! " << endl;
512 return kFALSE;
513 }
514
515 if (!InitFit())
516 return kFALSE;
517
518 for (Int_t i=0;i<10000; i++)
519 fHGausHist.Fill(fSinglePheFit->GetRandom());
520
521 return kTRUE;
522}
523
524// --------------------------------------------------------------------------
525//
526// - Get the ranges from the stripped histogram
527// - choose reasonable start values for the fit
528// - initialize the fit function depending on fFitFunc
529// - initialize parameter names and limits depending on fFitFunc
530//
531Bool_t MHCalibrationChargeBlindPix::InitFit()
532{
533
534 //
535 // Get the fitting ranges
536 //
537 Axis_t rmin = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetFirst());
538 Axis_t rmax = fHGausHist.GetBinCenter(fHGausHist.GetXaxis()->GetLast());
539
540 if (rmin < 0.)
541 rmin = 0.;
542
543 //
544 // First guesses for the fit (should be as close to reality as possible,
545 // otherwise the fit goes gaga because of high number of dimensions ...
546 //
547 const Stat_t entries = fHGausHist.Integral("width");
548 const Double_t lambda_guess = 0.1;
549 const Double_t maximum_bin = fHGausHist.GetBinCenter(fHGausHist.GetMaximumBin());
550 const Double_t norm = entries/TMath::Sqrt(TMath::TwoPi());
551
552 //
553 // Initialize the fit function
554 //
555 switch (fFitFunc)
556 {
557 case kEPoisson4:
558 fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto4,rmin,rmax,6);
559 break;
560 case kEPoisson5:
561 fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto5,rmin,rmax,6);
562 break;
563 case kEPoisson6:
564 fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto6,rmin,rmax,6);
565 break;
566 case kEPolya:
567 fSinglePheFit = new TF1("SinglePheFit",&fPolya,rmin,rmax,8);
568 break;
569 case kEMichele:
570 break;
571
572 default:
573 *fLog << warn << "WARNING: Could not find Fit Function for Blind Pixel " << endl;
574 return kFALSE;
575 break;
576 }
577
578 if (!fSinglePheFit)
579 {
580 *fLog << warn << dbginf << "WARNING: Could not create fit function for Single Phe fit" << endl;
581 return kFALSE;
582 }
583
584 const Double_t mu_0_guess = maximum_bin;
585 const Double_t si_0_guess = 40.;
586 const Double_t mu_1_guess = mu_0_guess + 100.;
587 const Double_t si_1_guess = si_0_guess + si_0_guess;
588 // Michele
589// const Double_t lambda_1cat_guess = 0.5;
590 // const Double_t lambda_1dyn_guess = 0.5;
591 // const Double_t mu_1cat_guess = mu_0_guess + 50.;
592 // const Double_t mu_1dyn_guess = mu_0_guess + 20.;
593 // const Double_t si_1cat_guess = si_0_guess + si_0_guess;
594 // const Double_t si_1dyn_guess = si_0_guess;
595 // Polya
596 const Double_t excessPoisson_guess = 0.5;
597 const Double_t delta1_guess = 8.;
598 const Double_t delta2_guess = 5.;
599 const Double_t electronicAmp_guess = gkElectronicAmp;
600 const Double_t electronicAmp_limit = gkElectronicAmpErr;
601
602 //
603 // Initialize boundaries and start parameters
604 //
605 switch (fFitFunc)
606 {
607
608 case kEPoisson4:
609 fSinglePheFit->SetParNames( "#lambda", "#mu_{0}", "#mu_{1}", "#sigma_{0}", "#sigma_{1}","Area");
610 fSinglePheFit->SetParameters(lambda_guess,fMeanPedestal,mu_1_guess,fSigmaPedestal,si_1_guess,norm);
611
612 fSinglePheFit->SetParLimits(0,0.,0.5);
613 fSinglePheFit->SetParLimits(1,
614 fMeanPedestal-5.*fMeanPedestalErr,
615 fMeanPedestal+5.*fMeanPedestalErr);
616 fSinglePheFit->SetParLimits(2,rmin,rmax);
617 fSinglePheFit->SetParLimits(3,
618 fSigmaPedestal-5.*fSigmaPedestalErr,
619 fSigmaPedestal+5.*fSigmaPedestalErr);
620 fSinglePheFit->SetParLimits(4,0.,(rmax-rmin));
621 fSinglePheFit->SetParLimits(5,norm-(0.5*norm),norm+(0.5*norm));
622 break;
623 case kEPoisson5:
624 case kEPoisson6:
625 fSinglePheFit->SetParameters(lambda_guess,mu_0_guess,mu_1_guess,si_0_guess,si_1_guess,norm);
626 fSinglePheFit->SetParNames("#lambda","#mu_{0}","#mu_{1}","#sigma_{0}","#sigma_{1}","Area");
627 fSinglePheFit->SetParLimits(0,0.,1.);
628 fSinglePheFit->SetParLimits(1,rmin,(rmax-rmin)/1.5);
629 fSinglePheFit->SetParLimits(2,(rmax-rmin)/2.,(rmax-0.05*(rmax-rmin)));
630 fSinglePheFit->SetParLimits(3,1.0,(rmax-rmin)/2.0);
631 fSinglePheFit->SetParLimits(4,1.0,(rmax-rmin)/2.5);
632 fSinglePheFit->SetParLimits(5,norm-0.1,norm+0.1);
633 break;
634
635 case kEPolya:
636 fSinglePheFit->SetParameters(lambda_guess, excessPoisson_guess,
637 delta1_guess,delta2_guess,
638 electronicAmp_guess,
639 fSigmaPedestal,
640 norm,
641 fMeanPedestal);
642 fSinglePheFit->SetParNames("#lambda","b_{tot}",
643 "#delta_{1}","#delta_{2}",
644 "amp_{e}","#sigma_{0}",
645 "Area", "#mu_{0}");
646 fSinglePheFit->SetParLimits(0,0.,1.);
647 fSinglePheFit->SetParLimits(1,0.,1.);
648 fSinglePheFit->SetParLimits(2,6.,12.);
649 fSinglePheFit->SetParLimits(3,3.,8.);
650 fSinglePheFit->SetParLimits(4,electronicAmp_guess-electronicAmp_limit,
651 electronicAmp_guess+electronicAmp_limit);
652 fSinglePheFit->SetParLimits(5,
653 fSigmaPedestal-3.*fSigmaPedestalErr,
654 fSigmaPedestal+3.*fSigmaPedestalErr);
655 fSinglePheFit->SetParLimits(6,norm-0.1,norm+0.1);
656 fSinglePheFit->SetParLimits(7,
657 fMeanPedestal-3.*fMeanPedestalErr,
658 fMeanPedestal+3.*fMeanPedestalErr);
659 break;
660 case kEMichele:
661 break;
662
663 default:
664 *fLog << warn << "WARNING: Could not find Fit Function for Blind Pixel " << endl;
665 return kFALSE;
666 break;
667 }
668
669 fSinglePheFit->SetRange(rmin,rmax);
670
671 return kTRUE;
672}
673
674// --------------------------------------------------------------------------
675//
676// - Retrieve the parameters depending on fFitFunc
677// - Retrieve probability, Chisquare and NDF
678//
679void MHCalibrationChargeBlindPix::ExitFit()
680{
681
682
683 //
684 // Finalize
685 //
686 switch (fFitFunc)
687 {
688
689 case kEPoisson4:
690 case kEPoisson5:
691 case kEPoisson6:
692 case kEPoisson7:
693 fLambda = fSinglePheFit->GetParameter(0);
694 fMu0 = fSinglePheFit->GetParameter(1);
695 fMu1 = fSinglePheFit->GetParameter(2);
696 fSigma0 = fSinglePheFit->GetParameter(3);
697 fSigma1 = fSinglePheFit->GetParameter(4);
698
699 fLambdaErr = fSinglePheFit->GetParError(0);
700 fMu0Err = fSinglePheFit->GetParError(1);
701 fMu1Err = fSinglePheFit->GetParError(2);
702 fSigma0Err = fSinglePheFit->GetParError(3);
703 fSigma1Err = fSinglePheFit->GetParError(4);
704 break;
705 case kEPolya:
706 fLambda = fSinglePheFit->GetParameter(0);
707 fMu0 = fSinglePheFit->GetParameter(7);
708 fMu1 = 0.;
709 fSigma0 = fSinglePheFit->GetParameter(5);
710 fSigma1 = 0.;
711
712 fLambdaErr = fSinglePheFit->GetParError(0);
713 fMu0Err = fSinglePheFit->GetParError(7);
714 fMu1Err = 0.;
715 fSigma0Err = fSinglePheFit->GetParError(5);
716 fSigma1Err = 0.;
717 default:
718 break;
719 }
720
721 fProb = fSinglePheFit->GetProb();
722 fChisquare = fSinglePheFit->GetChisquare();
723 fNDF = fSinglePheFit->GetNDF();
724
725 *fLog << all << "Results of the Blind Pixel Fit: " << endl;
726 *fLog << all << "Chisquare: " << fChisquare << endl;
727 *fLog << all << "DoF: " << fNDF << endl;
728 *fLog << all << "Probability: " << fProb << endl;
729
730}
731
732// --------------------------------------------------------------------------
733//
734// - Executes InitFit()
735// - Fits the fHGausHist with fSinglePheFit
736// - Executes ExitFit()
737//
738// The fit result is accepted under condition:
739// 1) The results are not nan's
740// 2) The NDF is not smaller than fNDFLimit (5)
741// 3) The Probability is greater than fProbLimit (default 0.001 == 99.9%)
742// 4) at least fNumSinglePheLimit events are in the single Photo-electron peak
743//
744Bool_t MHCalibrationChargeBlindPix::FitSinglePhe(Option_t *opt)
745{
746
747 if (!InitFit())
748 return kFALSE;
749
750 fHGausHist.Fit(fSinglePheFit,opt);
751
752 ExitFit();
753
754 //
755 // The fit result is accepted under condition:
756 // 1) The results are not nan's
757 // 2) The NDF is not smaller than fNDFLimit (5)
758 // 3) The Probability is greater than fProbLimit (default 0.001 == 99.9%)
759 // 4) at least fNumSinglePheLimit events are in the single Photo-electron peak
760 //
761 if ( TMath::IsNaN(fLambda)
762 || TMath::IsNaN(fLambdaErr)
763 || TMath::IsNaN(fProb)
764 || TMath::IsNaN(fMu0)
765 || TMath::IsNaN(fMu0Err)
766 || TMath::IsNaN(fMu1)
767 || TMath::IsNaN(fMu1Err)
768 || TMath::IsNaN(fSigma0)
769 || TMath::IsNaN(fSigma0Err)
770 || TMath::IsNaN(fSigma1)
771 || TMath::IsNaN(fSigma1Err)
772 || fNDF < fNDFLimit
773 || fProb < fProbLimit )
774 return kFALSE;
775
776 const Stat_t entries = fHGausHist.Integral("width");
777 const Float_t numSinglePhe = TMath::Exp(-1.0*fLambda)*fLambda*entries;
778
779 if (numSinglePhe < fNumSinglePheLimit)
780 {
781 *fLog << warn << "WARNING - Statistics is too low: Only " << numSinglePhe
782 << " in the Single Photo-Electron peak " << endl;
783 return kFALSE;
784 }
785 else
786 *fLog << all << numSinglePhe << " in Single Photo-Electron peak " << endl;
787
788 SetSinglePheFitOK();
789 return kTRUE;
790}
791
792// --------------------------------------------------------------------------
793//
794// - Retrieves limits for the fit
795// - Fits the fHGausHist with Gauss
796// - Retrieves the results to fLambdaCheck and fLambdaCheckErr
797// - Sets a flag IsPedestalFitOK()
798//
799void MHCalibrationChargeBlindPix::FitPedestal (Option_t *opt)
800{
801
802 // Perform the cross-check fitting only the pedestal:
803 const Axis_t rmin = 0.;
804 const Axis_t rmax = fHGausHist.GetBinCenter(fHGausHist.GetMaximumBin());
805
806 FitGaus(opt, rmin, rmax);
807
808 const Stat_t entries = fHGausHist.Integral("width");
809 const Double_t fitarea = fFGausFit->GetParameter(0);
810 const Double_t pedarea = fitarea * TMath::Sqrt(TMath::TwoPi()) * fFGausFit->GetParameter(2);
811
812 fLambdaCheck = TMath::Log(entries/pedarea);
813 fLambdaCheckErr = fFGausFit->GetParError(0)/fFGausFit->GetParameter(0)
814 + fFGausFit->GetParError(2)/fFGausFit->GetParameter(2);
815
816
817 SetPedestalFitOK();
818 return;
819}
820
821
822// -------------------------------------------------------------------------
823//
824// Draw a legend with the fit results
825//
826void MHCalibrationChargeBlindPix::DrawLegend()
827{
828
829 if (!fFitLegend)
830 {
831 fFitLegend = new TPaveText(0.05,0.05,0.95,0.95);
832 fFitLegend->SetLabel(Form("%s%s", "Results of the single PhE Fit (",
833 (fFitFunc = kEPoisson4) ? "Poisson(k=4))" :
834 (fFitFunc = kEPoisson5) ? "Poisson(k=5))" :
835 (fFitFunc = kEPoisson6) ? "Poisson(k=4))" :
836 (fFitFunc = kEPolya ) ? "Polya(k=4))" :
837 (fFitFunc = kEMichele ) ? "Michele)" : " none )" ));
838 fFitLegend->SetTextSize(0.05);
839 }
840 else
841 fFitLegend->Clear();
842
843 const TString line1 =
844 Form("Mean: #lambda = %2.2f #pm %2.2f",fLambda,fLambdaErr);
845 TText *t1 = fFitLegend->AddText(line1.Data());
846 t1->SetBit(kCanDelete);
847
848 const TString line6 =
849 Form("Mean #lambda (check) = %2.2f #pm %2.2f",fLambdaCheck,fLambdaCheckErr);
850 TText *t2 = fFitLegend->AddText(line6.Data());
851 t2->SetBit(kCanDelete);
852
853 const TString line2 =
854 Form("Pedestal: #mu_{0} = %2.2f #pm %2.2f",fMu0,fMu0Err);
855 TText *t3 = fFitLegend->AddText(line2.Data());
856 t3->SetBit(kCanDelete);
857
858 const TString line3 =
859 Form("Width Pedestal: #sigma_{0} = %2.2f #pm %2.2f",fSigma0,fSigma0Err);
860 TText *t4 = fFitLegend->AddText(line3.Data());
861 t4->SetBit(kCanDelete);
862
863 const TString line4 =
864 Form("1^{st} Phe-peak: #mu_{1} = %2.2f #pm %2.2f",fMu1,fMu1Err);
865 TText *t5 = fFitLegend->AddText(line4.Data());
866 t5->SetBit(kCanDelete);
867
868 const TString line5 =
869 Form("Width 1^{st} Phe-peak: #sigma_{1} = %2.2f #pm %2.2f",fSigma1,fSigma1Err);
870 TText *t6 = fFitLegend->AddText(line5.Data());
871 t6->SetBit(kCanDelete);
872
873 const TString line7 =
874 Form("#chi^{2} / N_{dof}: %4.2f / %3i",fChisquare,fNDF);
875 TText *t7 = fFitLegend->AddText(line7.Data());
876 t7->SetBit(kCanDelete);
877
878 const TString line8 =
879 Form("Probability: %4.2f ",fProb);
880 TText *t8 = fFitLegend->AddText(line8.Data());
881 t8->SetBit(kCanDelete);
882
883 if (IsSinglePheFitOK())
884 {
885 TText *t = fFitLegend->AddText(0.,0.,"Result of the Fit: OK");
886 t->SetBit(kCanDelete);
887 }
888 else
889 {
890 TText *t = fFitLegend->AddText("Result of the Fit: NOT OK");
891 t->SetBit(kCanDelete);
892 }
893
894 fFitLegend->SetFillColor(IsSinglePheFitOK() ? 80 : 2);
895 fFitLegend->Draw();
896
897 return;
898}
899
900
901// -------------------------------------------------------------------------
902//
903// Draw the histogram
904//
905// The following options can be chosen:
906//
907// "": displays the fHGausHist, the legend and fASinglePheFADCSlices and fAPedestalFADCSlices
908// "all": executes additionally MHGausEvents::Draw(), with option "fourierevents"
909//
910void MHCalibrationChargeBlindPix::Draw(Option_t *opt)
911{
912
913 TString option(opt);
914 option.ToLower();
915
916 Int_t win = 1;
917
918 TVirtualPad *oldpad = gPad ? gPad : MH::MakeDefCanvas(this,900, 600);
919 TVirtualPad *pad = NULL;
920
921 oldpad->SetBorderMode(0);
922
923 if (option.Contains("all"))
924 {
925 option.ReplaceAll("all","");
926 oldpad->Divide(2,1);
927 win = 2;
928 oldpad->cd(1);
929 TVirtualPad *newpad = gPad;
930 pad = newpad;
931 pad->Divide(2,2);
932 pad->cd(1);
933 }
934 else
935 {
936 pad = oldpad;
937 pad->Divide(2,2);
938 pad->cd(1);
939 }
940
941 if (!IsEmpty())
942 gPad->SetLogy();
943
944 gPad->SetTicks();
945
946 fHGausHist.Draw(opt);
947 if (fFGausFit)
948 {
949 fFGausFit->SetLineColor(kBlue);
950 fFGausFit->Draw("same");
951 }
952 if (fSinglePheFit)
953 {
954 fSinglePheFit->SetLineColor(IsSinglePheFitOK() ? kGreen : kRed);
955 fSinglePheFit->Draw("same");
956 }
957
958 pad->cd(2);
959 DrawLegend();
960
961 pad->cd(3);
962 if (fHSinglePheFADCSlices)
963 delete fHSinglePheFADCSlices;
964
965 fHSinglePheFADCSlices = new TH1F(fASinglePheFADCSlices);
966 fHSinglePheFADCSlices->SetName("SinglePheFADCSlices");
967 fHSinglePheFADCSlices->SetTitle(Form("%s%f","Assumed Single Phe FADC Slices, Sum > ",fSinglePheCut));
968 fHSinglePheFADCSlices->SetXTitle("FADC slice number");
969 fHSinglePheFADCSlices->SetYTitle("FADC counts");
970 fHSinglePheFADCSlices->Draw(opt);
971
972 pad->cd(4);
973 if (fHPedestalFADCSlices)
974 delete fHPedestalFADCSlices;
975
976 fHPedestalFADCSlices = new TH1F(fAPedestalFADCSlices);
977 fHPedestalFADCSlices->SetName("PedestalFADCSlices");
978 fHPedestalFADCSlices->SetTitle(Form("%s%f","Pedestal FADC Slices, Sum < ",fSinglePheCut));
979 fHPedestalFADCSlices->SetXTitle("FADC slice number");
980 fHPedestalFADCSlices->SetYTitle("FADC counts");
981 fHPedestalFADCSlices->Draw(opt);
982
983 if (win < 2)
984 return;
985
986 oldpad->cd(2);
987 MHGausEvents::Draw("fourierevents");
988}
989
990
991
992
993
994
995
996
997
998
999
Note: See TracBrowser for help on using the repository browser.