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

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