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

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