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

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