source: trunk/MagicSoft/Mars/mhist/MHCalibrationPixel.cc@ 2662

Last change on this file since 2662 was 2662, checked in by gaug, 21 years ago
*** empty log message ***
File size: 23.0 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 11/2003 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MHCalibrationPixel //
28// //
29// Performs all the necessary fits to extract the mean number of photons //
30// out of the derived light flux //
31// //
32//////////////////////////////////////////////////////////////////////////////
33
34#include "MHCalibrationPixel.h"
35#include "MHCalibrationConfig.h"
36#include "MCalibrationFits.h"
37
38#include <TStyle.h>
39#include <TMath.h>
40
41#include <TFitter.h>
42#include <TGraph.h>
43#include <TAxis.h>
44
45#include <TF1.h>
46#include <TH2.h>
47#include <TProfile.h>
48#include <TCanvas.h>
49#include <TPad.h>
50#include <TPaveText.h>
51
52#include "MParList.h"
53
54#include "MLog.h"
55#include "MLogManip.h"
56
57ClassImp(MHCalibrationPixel);
58
59using namespace std;
60
61// --------------------------------------------------------------------------
62//
63// Default Constructor.
64//
65MHCalibrationPixel::MHCalibrationPixel(const char *name, const char *title)
66 : fPixId(-1),
67 fTotalEntries(0),
68 fHiGains(NULL),
69 fLoGains(NULL),
70 fChargeGausFit(NULL),
71 fTimeGausFit(NULL),
72 fHivsLoGain(NULL),
73 fFitLegend(NULL),
74 fLowerFitRange(-2000.),
75 fChargeFirstHiGain(-2000.5),
76 fChargeLastHiGain(9999.5),
77 fChargeNbinsHiGain(12000),
78 fChargeFirstLoGain(-2000.5),
79 fChargeLastLoGain(9999.5),
80 fChargeNbinsLoGain(1200),
81 fFitOK(kFALSE),
82 fChargeChisquare(-1.),
83 fChargeProb(-1.),
84 fChargeNdf(-1),
85 fTimeChisquare(-1.),
86 fTimeProb(-1.),
87 fTimeNdf(-1),
88 fUseLoGain(kFALSE),
89 fOffset(0.),
90 fSlope(0.)
91{
92
93 fName = name ? name : "MHCalibrationPixel";
94 fTitle = title ? title : "Fill the accumulated charges and times of all events and perform fits";
95
96 // Create a large number of bins, later we will rebin
97 fHChargeHiGain = new TH1F("HChargeHiGain","Distribution of Summed FADC Hi Gain Slices Pixel ",
98 fChargeNbinsHiGain,fChargeFirstHiGain,fChargeLastHiGain);
99 fHChargeHiGain->SetXTitle("Sum FADC Slices (Hi Gain)");
100 fHChargeHiGain->SetYTitle("Nr. of events");
101 fHChargeHiGain->Sumw2();
102
103 fHChargeHiGain->SetDirectory(NULL);
104
105 fHChargeLoGain = new TH1F("HChargeLoGain","Distribution of Summed FADC Lo Gain Slices Pixel ",
106 fChargeNbinsLoGain,fChargeFirstLoGain,fChargeLastLoGain);
107 fHChargeLoGain->SetXTitle("Sum FADC Slices (Lo Gain)");
108 fHChargeLoGain->SetYTitle("Nr. of events");
109 fHChargeLoGain->Sumw2();
110
111 fHChargeLoGain->SetDirectory(NULL);
112
113 Axis_t tfirst = -0.5;
114 Axis_t tlast = 15.5;
115 Int_t ntbins = 16;
116
117 fHTimeHiGain = new TH1I("HTimeHiGain","Distribution of Mean Arrival Hi Gain Times Pixel ",
118 ntbins,tfirst,tlast);
119 fHTimeHiGain->SetXTitle("Mean Arrival Times [Hi Gain FADC slice nr]");
120 fHTimeHiGain->SetYTitle("Nr. of events");
121 // fHTimeHiGain->Sumw2();
122
123 fHTimeHiGain->SetDirectory(NULL);
124
125 fHTimeLoGain = new TH1I("HTimeLoGain","Distribution of Mean Arrival Lo Gain Times Pixel ",
126 ntbins,tfirst,tlast);
127 fHTimeLoGain->SetXTitle("Mean Arrival Times [Lo Gain FADC slice nr]");
128 fHTimeLoGain->SetYTitle("Nr. of events");
129 // fHTimeLoGain->Sumw2();
130
131 fHTimeLoGain->SetDirectory(NULL);
132
133 // We define a reasonable number and later enlarge it if necessary
134 Int_t nqbins = 20000;
135 Axis_t nfirst = -0.5;
136 Axis_t nlast = (Axis_t)nqbins - 0.5;
137
138 fHChargevsNHiGain = new TH1I("HChargevsNHiGain","Sum of Hi Gain Charges vs. Event Number Pixel ",
139 nqbins,nfirst,nlast);
140 fHChargevsNHiGain->SetXTitle("Event Nr.");
141 fHChargevsNHiGain->SetYTitle("Sum of Hi Gain FADC slices");
142
143 fHChargevsNHiGain->SetDirectory(NULL);
144
145 fHChargevsNLoGain = new TH1I("HChargevsNLoGain","Sum of Lo Gain Charges vs. Event Number Pixel ",
146 nqbins,nfirst,nlast);
147 fHChargevsNLoGain->SetXTitle("Event Nr.");
148 fHChargevsNLoGain->SetYTitle("Sum of Lo Gain FADC slices");
149
150 fHChargevsNLoGain->SetDirectory(NULL);
151
152 fHiGains = new TArrayF();
153 fLoGains = new TArrayF();
154
155}
156
157MHCalibrationPixel::~MHCalibrationPixel()
158{
159
160 delete fHChargeHiGain;
161 delete fHTimeHiGain;
162 delete fHChargevsNHiGain;
163
164 delete fHChargeLoGain;
165 delete fHTimeLoGain;
166 delete fHChargevsNLoGain;
167
168 delete fHiGains;
169 delete fLoGains;
170
171 if (fChargeGausFit)
172 delete fChargeGausFit;
173 if (fTimeGausFit)
174 delete fTimeGausFit;
175 if (fFitLegend)
176 delete fFitLegend;
177 if (fHivsLoGain)
178 delete fHivsLoGain;
179
180
181}
182
183
184void MHCalibrationPixel::ChangeHistId(Int_t id)
185{
186
187 fPixId = id;
188
189 //
190 // Names Hi gain Histograms
191 //
192 TString nameQHiGain = TString(fHChargeHiGain->GetName());
193 nameQHiGain += id;
194 fHChargeHiGain->SetName(nameQHiGain.Data());
195
196 TString nameTHiGain = TString(fHTimeHiGain->GetName());
197 nameTHiGain += id;
198 fHTimeHiGain->SetName(nameTHiGain.Data());
199
200 TString nameQvsNHiGain = TString(fHChargevsNHiGain->GetName());
201 nameQvsNHiGain += id;
202 fHChargevsNHiGain->SetName(nameQvsNHiGain.Data());
203
204 //
205 // Title Hi gain Histograms
206 //
207 TString titleQHiGain = TString(fHChargeHiGain->GetTitle());
208 titleQHiGain += id;
209 fHChargeHiGain->SetTitle(titleQHiGain.Data());
210
211 TString titleTHiGain = TString(fHTimeHiGain->GetTitle());
212 titleTHiGain += id;
213 fHTimeHiGain->SetTitle(titleTHiGain.Data());
214
215 TString titleQvsNHiGain = TString(fHChargevsNHiGain->GetTitle());
216 titleQvsNHiGain += id;
217 fHChargevsNHiGain->SetTitle(titleQvsNHiGain.Data());
218
219 //
220 // Names Low Gain Histograms
221 //
222 TString nameQLoGain = TString(fHChargeLoGain->GetName());
223 nameQLoGain += id;
224 fHChargeLoGain->SetName(nameQLoGain.Data());
225
226 TString nameTLoGain = TString(fHTimeLoGain->GetName());
227 nameTLoGain += id;
228 fHTimeLoGain->SetName(nameTLoGain.Data());
229
230 TString nameQvsNLoGain = TString(fHChargevsNLoGain->GetName());
231 nameQvsNLoGain += id;
232 fHChargevsNLoGain->SetName(nameQvsNLoGain.Data());
233
234 //
235 // Titles Low Gain Histograms
236 //
237 TString titleQLoGain = TString(fHChargeLoGain->GetTitle());
238 titleQLoGain += id;
239 fHChargeLoGain->SetTitle(titleQLoGain.Data());
240
241 TString titleTLoGain = TString(fHTimeLoGain->GetTitle());
242 titleTLoGain += id;
243 fHTimeLoGain->SetTitle(titleTLoGain.Data());
244
245 TString titleQvsNLoGain = TString(fHChargevsNLoGain->GetTitle());
246 titleQvsNLoGain += id;
247 fHChargevsNLoGain->SetTitle(titleQvsNLoGain.Data());
248}
249
250
251void MHCalibrationPixel::Reset()
252{
253
254 for (Int_t i = fHChargeHiGain->FindBin(fChargeFirstHiGain);
255 i <= fHChargeHiGain->FindBin(fChargeLastHiGain); i++)
256 fHChargeHiGain->SetBinContent(i, 1.e-20);
257
258 for (Int_t i = 0; i < 16; i++)
259 fHTimeHiGain->SetBinContent(i, 1.e-20);
260
261 fChargeLastHiGain = 9999.5;
262
263 fHChargeHiGain->GetXaxis()->SetRangeUser(0.,fChargeLastHiGain);
264
265 for (Int_t i = fHChargeLoGain->FindBin(fChargeFirstLoGain);
266 i <= fHChargeLoGain->FindBin(fChargeLastLoGain); i++)
267 fHChargeLoGain->SetBinContent(i, 1.e-20);
268
269 for (Int_t i = 0; i < 16; i++)
270 fHTimeLoGain->SetBinContent(i, 1.e-20);
271
272 fChargeLastLoGain = 9999.5;
273
274 fHChargeLoGain->GetXaxis()->SetRangeUser(0.,fChargeLastLoGain);
275
276 return;
277}
278
279
280// -------------------------------------------------------------------------
281//
282// Set the binnings and prepare the filling of the histograms
283//
284Bool_t MHCalibrationPixel::SetupFill(const MParList *plist)
285{
286
287 fHChargeHiGain->Reset();
288 fHTimeHiGain->Reset();
289 fHChargeLoGain->Reset();
290 fHTimeLoGain->Reset();
291
292 return kTRUE;
293}
294
295
296Bool_t MHCalibrationPixel::UseLoGain()
297{
298
299 if (fHChargeHiGain->GetEntries() > fHChargeLoGain->GetEntries())
300 {
301 fUseLoGain = kFALSE;
302 return kFALSE;
303 }
304 else
305 {
306 fUseLoGain = kTRUE;
307 return kTRUE;
308 }
309}
310
311void MHCalibrationPixel::SetPointInGraph(Float_t qhi,Float_t qlo)
312{
313
314 fHiGains->Set(++fTotalEntries);
315 fLoGains->Set(fTotalEntries);
316
317 fHiGains->AddAt(qhi,fTotalEntries-1);
318 fLoGains->AddAt(qlo,fTotalEntries-1);
319
320}
321
322
323// -------------------------------------------------------------------------
324//
325// Draw a legend with the fit results
326//
327void MHCalibrationPixel::DrawLegend()
328{
329
330 fFitLegend = new TPaveText(0.05,0.05,0.95,0.95);
331
332 if (fFitOK)
333 fFitLegend->SetFillColor(80);
334 else
335 fFitLegend->SetFillColor(2);
336
337 fFitLegend->SetLabel("Results of the Gauss Fit:");
338 fFitLegend->SetTextSize(0.05);
339
340 const TString line1 =
341 Form("Mean: Q_{#mu} = %2.2f #pm %2.2f",fChargeMean,fChargeMeanErr);
342
343 fFitLegend->AddText(line1);
344
345
346 const TString line4 =
347 Form("Sigma: #sigma_{Q} = %2.2f #pm %2.2f",fChargeSigma,fChargeSigmaErr);
348
349 fFitLegend->AddText(line4);
350
351
352 const TString line7 =
353 Form("#chi^{2} / N_{dof}: %4.2f / %3i",fChargeChisquare,fChargeNdf);
354
355 fFitLegend->AddText(line7);
356
357
358 const TString line8 =
359 Form("Probability: %4.3f ",fChargeProb);
360
361 fFitLegend->AddText(line8);
362
363 if (fFitOK)
364 fFitLegend->AddText("Result of the Fit: OK");
365 else
366 fFitLegend->AddText("Result of the Fit: NOT OK");
367
368 fFitLegend->SetBit(kCanDelete);
369 fFitLegend->Draw();
370
371}
372
373
374// -------------------------------------------------------------------------
375//
376// Draw the histogram
377//
378void MHCalibrationPixel::Draw(Option_t *opt)
379{
380
381 if (!fHivsLoGain)
382 FitHiGainvsLoGain();
383
384
385 gStyle->SetOptFit(0);
386 gStyle->SetOptStat(1111111);
387
388 TCanvas *c = MakeDefCanvas(this,600,900);
389
390 gROOT->SetSelectedPad(NULL);
391
392 c->Divide(2,4);
393
394 c->cd(1);
395 gPad->SetBorderMode(0);
396 gPad->SetLogy(1);
397 gPad->SetTicks();
398
399 fHChargeHiGain->DrawCopy(opt);
400
401 c->Modified();
402 c->Update();
403
404 if (fUseLoGain)
405 {
406 c->cd(2);
407 gPad->SetLogy(1);
408 gPad->SetTicks();
409 fHChargeLoGain->DrawCopy(opt);
410
411 if (fChargeGausFit)
412 {
413 if (fFitOK)
414 fChargeGausFit->SetLineColor(kGreen);
415 else
416 fChargeGausFit->SetLineColor(kRed);
417
418 fChargeGausFit->DrawCopy("same");
419 }
420 c->Modified();
421 c->Update();
422
423 c->cd(3);
424 gROOT->SetSelectedPad(NULL);
425 gStyle->SetOptFit();
426 fHivsLoGain->Draw("prof");
427
428
429 gPad->Modified();
430 gPad->Update();
431
432 c->cd(4);
433 DrawLegend();
434
435 }
436 else
437 {
438 if (fChargeGausFit)
439 {
440 if (fFitOK)
441 fChargeGausFit->SetLineColor(kGreen);
442 else
443 fChargeGausFit->SetLineColor(kRed);
444
445 fChargeGausFit->DrawCopy("same");
446 }
447 c->cd(2);
448 gPad->SetLogy(1);
449 gPad->SetTicks();
450
451 fHChargeLoGain->DrawCopy(opt);
452 c->Modified();
453 c->Update();
454
455 c->cd(3);
456 DrawLegend();
457
458 c->cd(4);
459
460 gROOT->SetSelectedPad(NULL);
461 gStyle->SetOptFit();
462 fHivsLoGain->Draw("prof");
463 gPad->Modified();
464 gPad->Update();
465
466
467 }
468
469 c->Modified();
470 c->Update();
471
472 c->cd(5);
473 gStyle->SetOptStat(1111111);
474
475 gPad->SetLogy(1);
476 fHTimeHiGain->DrawCopy(opt);
477 c->Modified();
478 c->Update();
479
480 if (fUseLoGain)
481 {
482
483 c->cd(6);
484 gPad->SetLogy(1);
485 fHTimeLoGain->DrawCopy(opt);
486 c->Modified();
487 c->Update();
488
489 if (fTimeGausFit)
490 {
491 if (fTimeChisquare > 20.)
492 fTimeGausFit->SetLineColor(kRed);
493 else
494 fTimeGausFit->SetLineColor(kGreen);
495
496 fTimeGausFit->DrawCopy("same");
497 c->Modified();
498 c->Update();
499 }
500 }
501 else
502 {
503 if (fTimeGausFit)
504 {
505 if (fTimeChisquare > 20.)
506 fTimeGausFit->SetLineColor(kRed);
507 else
508 fTimeGausFit->SetLineColor(kGreen);
509
510 fTimeGausFit->DrawCopy("same");
511 c->Modified();
512 c->Update();
513 }
514
515 c->cd(6);
516 gPad->SetLogy(1);
517 fHTimeLoGain->DrawCopy(opt);
518 c->Modified();
519 c->Update();
520
521 }
522 c->Modified();
523 c->Update();
524
525 c->cd(7);
526 fHChargevsNHiGain->DrawCopy(opt);
527 c->Modified();
528 c->Update();
529
530 c->cd(8);
531 fHChargevsNLoGain->DrawCopy(opt);
532 c->Modified();
533 c->Update();
534
535
536}
537
538void MHCalibrationPixel::FitHiGainvsLoGain()
539{
540
541 if (fHivsLoGain)
542 return;
543
544 gStyle->SetOptFit();
545
546 fHivsLoGain = new TProfile("HiGainvsLoGain","Plot the High Gain vs. Low Gain",100,0.,1000.,0.,1000.);
547 fHivsLoGain->GetXaxis()->SetTitle("Sum of Charges High Gain");
548 fHivsLoGain->GetYaxis()->SetTitle("Sum of Charges Low Gain");
549
550 for (Int_t i=0;i<fTotalEntries;i++)
551 fHivsLoGain->Fill(fHiGains->At(i),fLoGains->At(i),1);
552
553 fHivsLoGain->Fit("pol1","rq","",fHivsLoGain->GetMean()-2.5*fHivsLoGain->GetRMS(),fHivsLoGain->GetMean()+2.*fHivsLoGain->GetRMS());
554
555 fOffset = fHivsLoGain->GetFunction("pol1")->GetParameter(0);
556 fSlope = fHivsLoGain->GetFunction("pol1")->GetParameter(1);
557
558}
559
560
561Bool_t MHCalibrationPixel::FitTimeHiGain(Axis_t rmin, Axis_t rmax, Option_t *option)
562{
563
564 if (fTimeGausFit)
565 return kFALSE;
566
567 rmin = (rmin != 0.) ? rmin : 3.;
568 rmax = (rmax != 0.) ? rmax : 9.;
569
570 const Stat_t entries = fHTimeHiGain->GetEntries();
571 const Double_t mu_guess = fHTimeHiGain->GetBinCenter(fHTimeHiGain->GetMaximumBin());
572 const Double_t sigma_guess = (rmax - rmin)/2.;
573 const Double_t area_guess = entries/gkSq2Pi;
574
575 TString name = TString("GausTime");
576 name += fPixId;
577 fTimeGausFit = new TF1(name.Data(),"gaus",rmin,rmax);
578
579 if (!fTimeGausFit)
580 {
581 *fLog << err << dbginf << "Could not create fit function for Gauss fit" << endl;
582 return kFALSE;
583 }
584
585 fTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
586 fTimeGausFit->SetParNames("Area","#mu","#sigma");
587 fTimeGausFit->SetParLimits(0,0.,entries);
588 fTimeGausFit->SetParLimits(1,rmin,rmax);
589 fTimeGausFit->SetParLimits(2,0.,(rmax-rmin));
590 fTimeGausFit->SetRange(rmin,rmax);
591
592 fHTimeHiGain->Fit(fTimeGausFit,option);
593
594 rmin = fTimeGausFit->GetParameter(1) - 3.*fTimeGausFit->GetParameter(2);
595 rmax = fTimeGausFit->GetParameter(1) + 3.*fTimeGausFit->GetParameter(2);
596 fTimeGausFit->SetRange(rmin,rmax);
597
598 fHTimeHiGain->Fit(fTimeGausFit,option);
599
600 fTimeChisquare = fTimeGausFit->GetChisquare();
601 fTimeNdf = fTimeGausFit->GetNDF();
602 fTimeProb = fTimeGausFit->GetProb();
603
604 fTimeMean = fTimeGausFit->GetParameter(1);
605 fTimeSigma = fTimeGausFit->GetParameter(2);
606
607 if (fTimeChisquare > 20.) // Cannot use Probability because Ndf is sometimes < 1
608 {
609 *fLog << warn << "Fit of the Arrival times failed ! " << endl;
610 return kFALSE;
611 }
612
613 return kTRUE;
614
615}
616
617Bool_t MHCalibrationPixel::FitTimeLoGain(Axis_t rmin, Axis_t rmax, Option_t *option)
618{
619
620 if (fTimeGausFit)
621 return kFALSE;
622
623 rmin = (rmin != 0.) ? rmin : 3.;
624 rmax = (rmax != 0.) ? rmax : 9.;
625
626 const Stat_t entries = fHTimeLoGain->GetEntries();
627 const Double_t mu_guess = fHTimeLoGain->GetBinCenter(fHTimeLoGain->GetMaximumBin());
628 const Double_t sigma_guess = (rmax - rmin)/2.;
629 const Double_t area_guess = entries/gkSq2Pi;
630
631 TString name = TString("GausTime");
632 name += fPixId;
633 fTimeGausFit = new TF1(name.Data(),"gaus",rmin,rmax);
634
635 if (!fTimeGausFit)
636 {
637 *fLog << err << dbginf << "Could not create fit function for Gauss fit" << endl;
638 return kFALSE;
639 }
640
641 fTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
642 fTimeGausFit->SetParNames("Area","#mu","#sigma");
643 fTimeGausFit->SetParLimits(0,0.,entries);
644 fTimeGausFit->SetParLimits(1,rmin,rmax);
645 fTimeGausFit->SetParLimits(2,0.,(rmax-rmin));
646 fTimeGausFit->SetRange(rmin,rmax);
647
648 fHTimeLoGain->Fit(fTimeGausFit,option);
649
650 rmin = fTimeGausFit->GetParameter(1) - 3.*fTimeGausFit->GetParameter(2);
651 rmax = fTimeGausFit->GetParameter(1) + 3.*fTimeGausFit->GetParameter(2);
652 fTimeGausFit->SetRange(rmin,rmax);
653
654 fHTimeLoGain->Fit(fTimeGausFit,option);
655
656 fTimeChisquare = fTimeGausFit->GetChisquare();
657 fTimeNdf = fTimeGausFit->GetNDF();
658 fTimeProb = fTimeGausFit->GetProb();
659
660 fTimeMean = fTimeGausFit->GetParameter(1);
661 fTimeSigma = fTimeGausFit->GetParameter(2);
662
663 if (fTimeChisquare > 20.) // Cannot use Probability because Ndf is sometimes < 1
664 {
665 *fLog << warn << "Fit of the Arrival times failed ! " << endl;
666 return kFALSE;
667 }
668
669 return kTRUE;
670
671}
672
673Bool_t MHCalibrationPixel::FitChargeHiGain(Option_t *option)
674{
675
676 if (fChargeGausFit)
677 return kFALSE;
678
679 //
680 // Get the fitting ranges
681 //
682 Axis_t rmin = (fLowerFitRange != 0.) ? fLowerFitRange : fChargeFirstHiGain;
683 Axis_t rmax = 0.;
684
685 //
686 // First guesses for the fit (should be as close to reality as possible,
687 // otherwise the fit goes gaga because of high number of dimensions ...
688 //
689 const Stat_t entries = fHChargeHiGain->GetEntries();
690 const Double_t area_guess = entries/gkSq2Pi;
691 const Double_t mu_guess = fHChargeHiGain->GetBinCenter(fHChargeHiGain->GetMaximumBin());
692 const Double_t sigma_guess = mu_guess/15.;
693
694 TString name = TString("ChargeGausFit");
695 name += fPixId;
696
697 fChargeGausFit = new TF1(name.Data(),"gaus",rmin,fChargeLastHiGain);
698
699 if (!fChargeGausFit)
700 {
701 *fLog << err << dbginf << "Could not create fit function for Gauss fit" << endl;
702 return kFALSE;
703 }
704
705 fChargeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
706 fChargeGausFit->SetParNames("Area","#mu","#sigma");
707 fChargeGausFit->SetParLimits(0,0.,entries);
708 fChargeGausFit->SetParLimits(1,rmin,fChargeLastHiGain);
709 fChargeGausFit->SetParLimits(2,0.,fChargeLastHiGain-rmin);
710 fChargeGausFit->SetRange(rmin,fChargeLastHiGain);
711
712 fHChargeHiGain->Fit(fChargeGausFit,option);
713
714 Axis_t rtry = fChargeGausFit->GetParameter(1) - 2.0*fChargeGausFit->GetParameter(2);
715
716 rmin = (rtry < rmin ? rmin : rtry);
717 rmax = fChargeGausFit->GetParameter(1) + 3.5*fChargeGausFit->GetParameter(2);
718 fChargeGausFit->SetRange(rmin,rmax);
719
720 fHChargeHiGain->Fit(fChargeGausFit,option);
721
722 fChargeChisquare = fChargeGausFit->GetChisquare();
723 fChargeNdf = fChargeGausFit->GetNDF();
724 fChargeProb = fChargeGausFit->GetProb();
725 fChargeMean = fChargeGausFit->GetParameter(1);
726 fChargeMeanErr = fChargeGausFit->GetParError(1);
727 fChargeSigma = fChargeGausFit->GetParameter(2);
728 fChargeSigmaErr = fChargeGausFit->GetParError(2);
729
730 //
731 // The fit result is accepted under condition
732 // The Probability is greater than gkProbLimit (default 0.01 == 99%)
733 //
734 if (fChargeProb < gkProbLimit)
735 {
736 *fLog << warn << "Prob: " << fChargeProb << " is smaller than the allowed value: " << gkProbLimit << endl;
737 fFitOK = kFALSE;
738 return kFALSE;
739 }
740
741 fFitOK = kTRUE;
742
743 return kTRUE;
744}
745
746
747Bool_t MHCalibrationPixel::FitChargeLoGain(Option_t *option)
748{
749
750 if (fChargeGausFit)
751 return kFALSE;
752
753 //
754 // Get the fitting ranges
755 //
756 Axis_t rmin = (fLowerFitRange != 0.) ? fLowerFitRange : fChargeFirstLoGain;
757 Axis_t rmax = 0.;
758
759 //
760 // First guesses for the fit (should be as close to reality as possible,
761 // otherwise the fit goes gaga because of high number of dimensions ...
762 //
763 const Stat_t entries = fHChargeLoGain->GetEntries();
764 const Double_t area_guess = entries/gkSq2Pi;
765 const Double_t mu_guess = fHChargeLoGain->GetBinCenter(fHChargeLoGain->GetMaximumBin());
766 const Double_t sigma_guess = mu_guess/15.;
767
768 TString name = TString("ChargeGausFit");
769 name += fPixId;
770
771 fChargeGausFit = new TF1(name.Data(),"gaus",rmin,fChargeLastLoGain);
772
773 if (!fChargeGausFit)
774 {
775 *fLog << err << dbginf << "Could not create fit function for Gauss fit" << endl;
776 return kFALSE;
777 }
778
779 fChargeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
780 fChargeGausFit->SetParNames("Area","#mu","#sigma");
781 fChargeGausFit->SetParLimits(0,0.,entries);
782 fChargeGausFit->SetParLimits(1,rmin,fChargeLastLoGain);
783 fChargeGausFit->SetParLimits(2,0.,fChargeLastLoGain-rmin);
784 fChargeGausFit->SetRange(rmin,fChargeLastLoGain);
785
786 fHChargeLoGain->Fit(fChargeGausFit,option);
787
788 Axis_t rtry = fChargeGausFit->GetParameter(1) - 2.*fChargeGausFit->GetParameter(2);
789
790 rmin = (rtry < rmin ? rmin : rtry);
791 rmax = fChargeGausFit->GetParameter(1) + 3.5*fChargeGausFit->GetParameter(2);
792 fChargeGausFit->SetRange(rmin,rmax);
793
794 fHChargeLoGain->Fit(fChargeGausFit,option);
795
796 // rmin = fChargeGausFit->GetParameter(1) - 2.5*fChargeGausFit->GetParameter(2);
797 // rmax = fChargeGausFit->GetParameter(1) + 2.5*fChargeGausFit->GetParameter(2);
798 // fChargeGausFit->SetRange(rmin,rmax);
799
800 // fHChargeLoGain->Fit(fChargeGausFit,option);
801
802 fChargeChisquare = fChargeGausFit->GetChisquare();
803 fChargeNdf = fChargeGausFit->GetNDF();
804 fChargeProb = fChargeGausFit->GetProb();
805 fChargeMean = fChargeGausFit->GetParameter(1);
806 fChargeMeanErr = fChargeGausFit->GetParError(1);
807 fChargeSigma = fChargeGausFit->GetParameter(2);
808 fChargeSigmaErr = fChargeGausFit->GetParError(2);
809
810 //
811 // The fit result is accepted under condition
812 // The Probability is greater than gkProbLimit (default 0.01 == 99%)
813 //
814 if (fChargeProb < gkProbLimit)
815 {
816 *fLog << warn << "Prob: " << fChargeProb << " is smaller than the allowed value: " << gkProbLimit << endl;
817 fFitOK = kFALSE;
818 return kFALSE;
819 }
820
821
822 fFitOK = kTRUE;
823
824 return kTRUE;
825}
826
827
828void MHCalibrationPixel::CutAllEdges()
829{
830
831 Int_t nbins = 30;
832
833 CutEdges(fHChargeHiGain,nbins);
834
835 fChargeFirstHiGain = fHChargeHiGain->GetBinLowEdge(fHChargeHiGain->GetXaxis()->GetFirst());
836 fChargeLastHiGain = fHChargeHiGain->GetBinLowEdge(fHChargeHiGain->GetXaxis()->GetLast())
837 +fHChargeHiGain->GetBinWidth(0);
838 fChargeNbinsHiGain = nbins;
839
840 CutEdges(fHChargeLoGain,nbins);
841
842 fChargeFirstLoGain = fHChargeLoGain->GetBinLowEdge(fHChargeLoGain->GetXaxis()->GetFirst());
843 fChargeLastLoGain = fHChargeLoGain->GetBinLowEdge(fHChargeLoGain->GetXaxis()->GetLast())
844 +fHChargeLoGain->GetBinWidth(0);
845 fChargeNbinsLoGain = nbins;
846
847 CutEdges(fHChargevsNHiGain,0);
848 CutEdges(fHChargevsNLoGain,0);
849
850}
851
852void MHCalibrationPixel::PrintChargeFitResult()
853{
854
855 *fLog << "Results of the Summed Charges Fit: " << endl;
856 *fLog << "Chisquare: " << fChargeChisquare << endl;
857 *fLog << "DoF: " << fChargeNdf << endl;
858 *fLog << "Probability: " << fChargeProb << endl;
859 *fLog << endl;
860
861}
862
863void MHCalibrationPixel::PrintTimeFitResult()
864{
865
866 *fLog << "Results of the Time Slices Fit: " << endl;
867 *fLog << "Chisquare: " << fTimeChisquare << endl;
868 *fLog << "Ndf: " << fTimeNdf << endl;
869 *fLog << "Probability: " << fTimeProb << endl;
870 *fLog << endl;
871
872}
Note: See TracBrowser for help on using the repository browser.