| 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 | // MHCalibrationBlindPixel
|
|---|
| 28 | //
|
|---|
| 29 | // Performs all the Single Photo-Electron Fit to extract
|
|---|
| 30 | // the mean number of photons and to derive the light flux
|
|---|
| 31 | //
|
|---|
| 32 | // The fit result is accepted under condition that:
|
|---|
| 33 | // 1) the Probability is greater than gkProbLimit (default 0.001 == 99.7%)
|
|---|
| 34 | // 2) at least 100 events are in the single Photo-electron peak
|
|---|
| 35 | //
|
|---|
| 36 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 37 | #include "MHCalibrationBlindPixel.h"
|
|---|
| 38 | #include "MHCalibrationConfig.h"
|
|---|
| 39 |
|
|---|
| 40 | #include <TStyle.h>
|
|---|
| 41 | #include <TCanvas.h>
|
|---|
| 42 | #include <TPaveText.h>
|
|---|
| 43 |
|
|---|
| 44 | #include <TF1.h>
|
|---|
| 45 | #include <TH1.h>
|
|---|
| 46 | #include <TRandom.h>
|
|---|
| 47 |
|
|---|
| 48 | #include "MLog.h"
|
|---|
| 49 | #include "MLogManip.h"
|
|---|
| 50 |
|
|---|
| 51 | ClassImp(MHCalibrationBlindPixel);
|
|---|
| 52 |
|
|---|
| 53 | using namespace std;
|
|---|
| 54 |
|
|---|
| 55 | // --------------------------------------------------------------------------
|
|---|
| 56 | //
|
|---|
| 57 | // Default Constructor.
|
|---|
| 58 | //
|
|---|
| 59 | MHCalibrationBlindPixel::MHCalibrationBlindPixel(const char *name, const char *title)
|
|---|
| 60 | : fHBlindPixelCharge(NULL),
|
|---|
| 61 | fHBlindPixelTime(NULL),
|
|---|
| 62 | fHBlindPixelChargevsN(NULL),
|
|---|
| 63 | fHBlindPixelPSD(NULL),
|
|---|
| 64 | fSinglePheFit(NULL),
|
|---|
| 65 | fTimeGausFit(NULL),
|
|---|
| 66 | fSinglePhePedFit(NULL),
|
|---|
| 67 | fBlindPixelChargefirst(0.),
|
|---|
| 68 | fBlindPixelChargelast(0.),
|
|---|
| 69 | fBlindPixelChargenbins(0),
|
|---|
| 70 | fFitLegend(NULL), fFitOK(kFALSE),
|
|---|
| 71 | fLambda(0.), fMu0(0.), fMu1(0.), fSigma0(0.), fSigma1(0.),
|
|---|
| 72 | fLambdaErr(0.), fMu0Err(0.), fMu1Err(0.), fSigma0Err(0.), fSigma1Err(0.),
|
|---|
| 73 | fChisquare(0.), fProb(0.), fNdf(0),
|
|---|
| 74 | fMeanTime(0.), fMeanTimeErr(0.), fSigmaTime(0.), fSigmaTimeErr(0.),
|
|---|
| 75 | fLambdaCheck(0.), fLambdaCheckErr(0.),
|
|---|
| 76 | fFitFunc(kEPoisson4)
|
|---|
| 77 | {
|
|---|
| 78 |
|
|---|
| 79 | fName = name ? name : "MHCalibrationBlindPixel";
|
|---|
| 80 | fTitle = title ? title : "Fill the accumulated charges and times all Blind Pixel events and perform fits";
|
|---|
| 81 |
|
|---|
| 82 | // Create a large number of bins, later we will rebin
|
|---|
| 83 | fBlindPixelChargefirst = -1000.;
|
|---|
| 84 | fBlindPixelChargelast = gkStartBlindPixelBinNr;
|
|---|
| 85 | fBlindPixelChargenbins = gkStartBlindPixelBinNr+(int)fBlindPixelChargefirst;
|
|---|
| 86 |
|
|---|
| 87 | fHBlindPixelCharge = new TH1F("HBlindPixelCharge","Distribution of Summed FADC Slices",
|
|---|
| 88 | fBlindPixelChargenbins,fBlindPixelChargefirst,fBlindPixelChargelast);
|
|---|
| 89 | fHBlindPixelCharge->SetXTitle("Sum FADC Slices");
|
|---|
| 90 | fHBlindPixelCharge->SetYTitle("Nr. of events");
|
|---|
| 91 | fHBlindPixelCharge->Sumw2();
|
|---|
| 92 | fHBlindPixelCharge->SetDirectory(NULL);
|
|---|
| 93 |
|
|---|
| 94 | Axis_t tfirst = -0.5;
|
|---|
| 95 | Axis_t tlast = 15.5;
|
|---|
| 96 | Int_t nbins = 16;
|
|---|
| 97 |
|
|---|
| 98 | fHBlindPixelTime = new TH1F("HBlindPixelTime","Distribution of Mean Arrival Times",nbins,tfirst,tlast);
|
|---|
| 99 | fHBlindPixelTime->SetXTitle("Mean Arrival Times [FADC slice nr]");
|
|---|
| 100 | fHBlindPixelTime->SetYTitle("Nr. of events");
|
|---|
| 101 | fHBlindPixelTime->Sumw2();
|
|---|
| 102 | fHBlindPixelTime->SetDirectory(NULL);
|
|---|
| 103 |
|
|---|
| 104 | // We define a reasonable number and later enlarge it if necessary
|
|---|
| 105 | nbins = 20000;
|
|---|
| 106 | Axis_t nfirst = -0.5;
|
|---|
| 107 | Axis_t nlast = (Axis_t)nbins - 0.5;
|
|---|
| 108 |
|
|---|
| 109 | fHBlindPixelChargevsN = new TH1I("HBlindPixelChargevsN","Sum of Charges vs. Event Number",nbins,nfirst,nlast);
|
|---|
| 110 | fHBlindPixelChargevsN->SetXTitle("Event Nr.");
|
|---|
| 111 | fHBlindPixelChargevsN->SetYTitle("Sum of FADC slices");
|
|---|
| 112 | fHBlindPixelChargevsN->SetDirectory(NULL);
|
|---|
| 113 |
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | MHCalibrationBlindPixel::~MHCalibrationBlindPixel()
|
|---|
| 117 | {
|
|---|
| 118 |
|
|---|
| 119 | if (fFitLegend)
|
|---|
| 120 | delete fFitLegend;
|
|---|
| 121 |
|
|---|
| 122 | delete fHBlindPixelCharge;
|
|---|
| 123 | delete fHBlindPixelTime;
|
|---|
| 124 | delete fHBlindPixelChargevsN;
|
|---|
| 125 |
|
|---|
| 126 | if (fHBlindPixelPSD)
|
|---|
| 127 | delete fHBlindPixelPSD;
|
|---|
| 128 |
|
|---|
| 129 | if (fSinglePheFit)
|
|---|
| 130 | delete fSinglePheFit;
|
|---|
| 131 | if (fTimeGausFit)
|
|---|
| 132 | delete fTimeGausFit;
|
|---|
| 133 | if(fSinglePhePedFit)
|
|---|
| 134 | delete fSinglePhePedFit;
|
|---|
| 135 |
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | Bool_t MHCalibrationBlindPixel::FillBlindPixelCharge(Float_t q)
|
|---|
| 139 | {
|
|---|
| 140 | return fHBlindPixelCharge->Fill(q) > -1;
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | Bool_t MHCalibrationBlindPixel::FillBlindPixelTime(Float_t t)
|
|---|
| 144 | {
|
|---|
| 145 | return fHBlindPixelTime->Fill(t) > -1;
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | Bool_t MHCalibrationBlindPixel::FillBlindPixelChargevsN(Stat_t rq, Int_t t)
|
|---|
| 149 | {
|
|---|
| 150 | return fHBlindPixelChargevsN->Fill(t,rq) > -1;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 | void MHCalibrationBlindPixel::ResetBin(Int_t i)
|
|---|
| 155 | {
|
|---|
| 156 | fHBlindPixelCharge->SetBinContent (i, 1.e-20);
|
|---|
| 157 | fHBlindPixelTime->SetBinContent(i, 1.e-20);
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 | // -------------------------------------------------------------------------
|
|---|
| 162 | //
|
|---|
| 163 | // Draw a legend with the fit results
|
|---|
| 164 | //
|
|---|
| 165 | void MHCalibrationBlindPixel::DrawLegend()
|
|---|
| 166 | {
|
|---|
| 167 |
|
|---|
| 168 | fFitLegend = new TPaveText(0.05,0.05,0.95,0.95);
|
|---|
| 169 |
|
|---|
| 170 | if (fFitOK)
|
|---|
| 171 | fFitLegend->SetFillColor(80);
|
|---|
| 172 | else
|
|---|
| 173 | fFitLegend->SetFillColor(2);
|
|---|
| 174 |
|
|---|
| 175 | fFitLegend->SetLabel("Results of the single PhE Fit (to k=6):");
|
|---|
| 176 | fFitLegend->SetTextSize(0.05);
|
|---|
| 177 |
|
|---|
| 178 | const TString line1 =
|
|---|
| 179 | Form("Mean: #lambda = %2.2f #pm %2.2f",GetLambda(),GetLambdaErr());
|
|---|
| 180 | TText *t1 = fFitLegend->AddText(line1.Data());
|
|---|
| 181 | t1->SetBit(kCanDelete);
|
|---|
| 182 |
|
|---|
| 183 | const TString line6 =
|
|---|
| 184 | Form("Mean #lambda (check) = %2.2f #pm %2.2f",GetLambdaCheck(),GetLambdaCheckErr());
|
|---|
| 185 | TText *t2 = fFitLegend->AddText(line6.Data());
|
|---|
| 186 | t2->SetBit(kCanDelete);
|
|---|
| 187 |
|
|---|
| 188 | const TString line2 =
|
|---|
| 189 | Form("Pedestal: #mu_{0} = %2.2f #pm %2.2f",GetMu0(),GetMu0Err());
|
|---|
| 190 | TText *t3 = fFitLegend->AddText(line2.Data());
|
|---|
| 191 | t3->SetBit(kCanDelete);
|
|---|
| 192 |
|
|---|
| 193 | const TString line3 =
|
|---|
| 194 | Form("Width Pedestal: #sigma_{0} = %2.2f #pm %2.2f",GetSigma0(),GetSigma0Err());
|
|---|
| 195 | TText *t4 = fFitLegend->AddText(line3.Data());
|
|---|
| 196 | t4->SetBit(kCanDelete);
|
|---|
| 197 |
|
|---|
| 198 | const TString line4 =
|
|---|
| 199 | Form("1^{st} Phe-peak: #mu_{1} = %2.2f #pm %2.2f",GetMu1(),GetMu1Err());
|
|---|
| 200 | TText *t5 = fFitLegend->AddText(line4.Data());
|
|---|
| 201 | t5->SetBit(kCanDelete);
|
|---|
| 202 |
|
|---|
| 203 | const TString line5 =
|
|---|
| 204 | Form("Width 1^{st} Phe-peak: #sigma_{1} = %2.2f #pm %2.2f",GetSigma1(),GetSigma1Err());
|
|---|
| 205 | TText *t6 = fFitLegend->AddText(line5.Data());
|
|---|
| 206 | t6->SetBit(kCanDelete);
|
|---|
| 207 |
|
|---|
| 208 | const TString line7 =
|
|---|
| 209 | Form("#chi^{2} / N_{dof}: %4.2f / %3i",GetChiSquare(),GetNdf());
|
|---|
| 210 | TText *t7 = fFitLegend->AddText(line7.Data());
|
|---|
| 211 | t7->SetBit(kCanDelete);
|
|---|
| 212 |
|
|---|
| 213 | const TString line8 =
|
|---|
| 214 | Form("Probability: %4.2f ",GetProb());
|
|---|
| 215 | TText *t8 = fFitLegend->AddText(line8.Data());
|
|---|
| 216 | t8->SetBit(kCanDelete);
|
|---|
| 217 |
|
|---|
| 218 | if (fFitOK)
|
|---|
| 219 | {
|
|---|
| 220 | TText *t = fFitLegend->AddText(0.,0.,"Result of the Fit: OK");
|
|---|
| 221 | t->SetBit(kCanDelete);
|
|---|
| 222 | }
|
|---|
| 223 | else
|
|---|
| 224 | {
|
|---|
| 225 | TText *t = fFitLegend->AddText("Result of the Fit: NOT OK");
|
|---|
| 226 | t->SetBit(kCanDelete);
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | fFitLegend->SetBit(kCanDelete);
|
|---|
| 230 | fFitLegend->Draw();
|
|---|
| 231 |
|
|---|
| 232 | return;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | TObject *MHCalibrationBlindPixel::DrawClone(Option_t *option) const
|
|---|
| 236 | {
|
|---|
| 237 |
|
|---|
| 238 | gROOT->SetSelectedPad(NULL);
|
|---|
| 239 |
|
|---|
| 240 | MHCalibrationBlindPixel *newobj = (MHCalibrationBlindPixel*)Clone();
|
|---|
| 241 |
|
|---|
| 242 | if (!newobj)
|
|---|
| 243 | return 0;
|
|---|
| 244 | newobj->SetBit(kCanDelete);
|
|---|
| 245 |
|
|---|
| 246 | if (strlen(option))
|
|---|
| 247 | newobj->Draw(option);
|
|---|
| 248 | else
|
|---|
| 249 | newobj->Draw(GetDrawOption());
|
|---|
| 250 |
|
|---|
| 251 | return newobj;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 | // -------------------------------------------------------------------------
|
|---|
| 256 | //
|
|---|
| 257 | // Draw the histogram
|
|---|
| 258 | //
|
|---|
| 259 | void MHCalibrationBlindPixel::Draw(Option_t *opt)
|
|---|
| 260 | {
|
|---|
| 261 |
|
|---|
| 262 | gStyle->SetOptFit(1);
|
|---|
| 263 | gStyle->SetOptStat(111111);
|
|---|
| 264 |
|
|---|
| 265 | TCanvas *c = MakeDefCanvas(this,550,700);
|
|---|
| 266 |
|
|---|
| 267 | c->Divide(2,3);
|
|---|
| 268 |
|
|---|
| 269 | gROOT->SetSelectedPad(NULL);
|
|---|
| 270 |
|
|---|
| 271 | c->cd(1);
|
|---|
| 272 | gPad->SetLogx(0);
|
|---|
| 273 | gPad->SetLogy(1);
|
|---|
| 274 | gPad->SetTicks();
|
|---|
| 275 |
|
|---|
| 276 | fHBlindPixelCharge->Draw(opt);
|
|---|
| 277 |
|
|---|
| 278 | if (fFitOK)
|
|---|
| 279 | fSinglePheFit->SetLineColor(kGreen);
|
|---|
| 280 | else
|
|---|
| 281 | fSinglePheFit->SetLineColor(kRed);
|
|---|
| 282 |
|
|---|
| 283 | fSinglePheFit->Draw("same");
|
|---|
| 284 | c->Modified();
|
|---|
| 285 | c->Update();
|
|---|
| 286 |
|
|---|
| 287 | fSinglePhePedFit->SetLineColor(kBlue);
|
|---|
| 288 | fSinglePhePedFit->Draw("same");
|
|---|
| 289 |
|
|---|
| 290 | c->cd(2);
|
|---|
| 291 | DrawLegend();
|
|---|
| 292 | c->Modified();
|
|---|
| 293 | c->Update();
|
|---|
| 294 |
|
|---|
| 295 | c->cd(3);
|
|---|
| 296 | gPad->SetLogy(1);
|
|---|
| 297 | gPad->SetBorderMode(0);
|
|---|
| 298 | fHBlindPixelTime->Draw(opt);
|
|---|
| 299 |
|
|---|
| 300 | c->cd(4);
|
|---|
| 301 |
|
|---|
| 302 | fHBlindPixelChargevsN->Draw(opt);
|
|---|
| 303 |
|
|---|
| 304 | c->Modified();
|
|---|
| 305 | c->Update();
|
|---|
| 306 |
|
|---|
| 307 | c->cd(5);
|
|---|
| 308 |
|
|---|
| 309 | // fHBlindPixelPSD = (TH1F*)MFFT::PowerSpectrumDensity(fHBlindPixelChargevsN);
|
|---|
| 310 | // TH1F *hist = MFFT::PowerSpectrumDensity((*this)->fHBlindPixelChargevsN);
|
|---|
| 311 |
|
|---|
| 312 | // fHBlindPixelPSD->Draw(opt);
|
|---|
| 313 | c->Modified();
|
|---|
| 314 | c->Update();
|
|---|
| 315 |
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 | Bool_t MHCalibrationBlindPixel::SimulateSinglePhe(Double_t lambda, Double_t mu0, Double_t mu1, Double_t sigma0, Double_t sigma1)
|
|---|
| 321 | {
|
|---|
| 322 | gRandom->SetSeed();
|
|---|
| 323 |
|
|---|
| 324 | if (fHBlindPixelCharge->GetIntegral() != 0)
|
|---|
| 325 | {
|
|---|
| 326 | *fLog << err << "Histogram " << fHBlindPixelCharge->GetTitle() << " is already filled. " << endl;
|
|---|
| 327 | *fLog << err << "Create new class MHCalibrationBlindPixel for simulation! " << endl;
|
|---|
| 328 | return kFALSE;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | if (!InitFit(fBlindPixelChargefirst,fBlindPixelChargelast))
|
|---|
| 332 | return kFALSE;
|
|---|
| 333 |
|
|---|
| 334 | for (Int_t i=0;i<10000; i++)
|
|---|
| 335 | fHBlindPixelCharge->Fill(fSinglePheFit->GetRandom());
|
|---|
| 336 |
|
|---|
| 337 | return kTRUE;
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | Bool_t MHCalibrationBlindPixel::InitFit(Axis_t min, Axis_t max)
|
|---|
| 341 | {
|
|---|
| 342 |
|
|---|
| 343 | //
|
|---|
| 344 | // First guesses for the fit (should be as close to reality as possible,
|
|---|
| 345 | // otherwise the fit goes gaga because of high number of dimensions ...
|
|---|
| 346 | //
|
|---|
| 347 | const Stat_t entries = fHBlindPixelCharge->Integral("width");
|
|---|
| 348 | const Double_t lambda_guess = 0.5;
|
|---|
| 349 | const Double_t maximum_bin = fHBlindPixelCharge->GetBinCenter(fHBlindPixelCharge->GetMaximumBin());
|
|---|
| 350 | const Double_t norm = entries/gkSq2Pi;
|
|---|
| 351 |
|
|---|
| 352 | //
|
|---|
| 353 | // Initialize the fit function
|
|---|
| 354 | //
|
|---|
| 355 | switch (fFitFunc)
|
|---|
| 356 | {
|
|---|
| 357 | case kEPoisson4:
|
|---|
| 358 | // fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto4,min,max,5);
|
|---|
| 359 | fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto4,min,max,6);
|
|---|
| 360 | break;
|
|---|
| 361 | case kEPoisson5:
|
|---|
| 362 | fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto5,min,max,6);
|
|---|
| 363 | break;
|
|---|
| 364 | case kEPoisson6:
|
|---|
| 365 | fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto6,min,max,6);
|
|---|
| 366 | break;
|
|---|
| 367 | case kEPolya:
|
|---|
| 368 | fSinglePheFit = new TF1("SinglePheFit",&fPolya,min,max,8);
|
|---|
| 369 | break;
|
|---|
| 370 | case kEMichele:
|
|---|
| 371 | break;
|
|---|
| 372 |
|
|---|
| 373 | default:
|
|---|
| 374 | *fLog << warn << "WARNING: Could not find Fit Function for Blind Pixel " << endl;
|
|---|
| 375 | return kFALSE;
|
|---|
| 376 | break;
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | const Double_t mu_0_guess = maximum_bin;
|
|---|
| 380 | const Double_t si_0_guess = 20.;
|
|---|
| 381 | const Double_t mu_1_guess = mu_0_guess + 50.;
|
|---|
| 382 | const Double_t si_1_guess = si_0_guess + si_0_guess;
|
|---|
| 383 | // Michele
|
|---|
| 384 | const Double_t lambda_1cat_guess = 0.5;
|
|---|
| 385 | const Double_t lambda_1dyn_guess = 0.5;
|
|---|
| 386 | const Double_t mu_1cat_guess = mu_0_guess + 50.;
|
|---|
| 387 | const Double_t mu_1dyn_guess = mu_0_guess + 20.;
|
|---|
| 388 | const Double_t si_1cat_guess = si_0_guess + si_0_guess;
|
|---|
| 389 | const Double_t si_1dyn_guess = si_0_guess;
|
|---|
| 390 | // Polya
|
|---|
| 391 | const Double_t excessPoisson_guess = 0.5;
|
|---|
| 392 | const Double_t delta1_guess = 8.;
|
|---|
| 393 | const Double_t delta2_guess = 5.;
|
|---|
| 394 | const Double_t electronicAmp_guess = 0.0025;
|
|---|
| 395 |
|
|---|
| 396 | //
|
|---|
| 397 | // Initialize boundaries and start parameters
|
|---|
| 398 | //
|
|---|
| 399 | switch (fFitFunc)
|
|---|
| 400 | {
|
|---|
| 401 |
|
|---|
| 402 | case kEPoisson4:
|
|---|
| 403 | fSinglePheFit->SetParameters(lambda_guess,mu_0_guess,mu_1_guess,si_0_guess,si_1_guess,norm);
|
|---|
| 404 | fSinglePheFit->SetParNames("#lambda","#mu_{0}","#mu_{1}","#sigma_{0}","#sigma_{1}","Area");
|
|---|
| 405 | fSinglePheFit->SetParLimits(0,0.,1.);
|
|---|
| 406 | fSinglePheFit->SetParLimits(1,-2.,2.);
|
|---|
| 407 | fSinglePheFit->SetParLimits(2,(max-min)/2.,(max-0.05*(max-min)));
|
|---|
| 408 | fSinglePheFit->SetParLimits(3,1.0,(max-min)/2.0);
|
|---|
| 409 | fSinglePheFit->SetParLimits(4,1.0,(max-min)/2.5);
|
|---|
| 410 | fSinglePheFit->SetParLimits(5,norm-0.5,norm+0.5);
|
|---|
| 411 | break;
|
|---|
| 412 | case kEPoisson5:
|
|---|
| 413 | case kEPoisson6:
|
|---|
| 414 | fSinglePheFit->SetParameters(lambda_guess,mu_0_guess,mu_1_guess,si_0_guess,si_1_guess,norm);
|
|---|
| 415 | fSinglePheFit->SetParNames("#lambda","#mu_{0}","#mu_{1}","#sigma_{0}","#sigma_{1}","Area");
|
|---|
| 416 | fSinglePheFit->SetParLimits(0,0.,1.);
|
|---|
| 417 | fSinglePheFit->SetParLimits(1,min,(max-min)/1.5);
|
|---|
| 418 | fSinglePheFit->SetParLimits(2,(max-min)/2.,(max-0.05*(max-min)));
|
|---|
| 419 | fSinglePheFit->SetParLimits(3,1.0,(max-min)/2.0);
|
|---|
| 420 | fSinglePheFit->SetParLimits(4,1.0,(max-min)/2.5);
|
|---|
| 421 | fSinglePheFit->SetParLimits(5,norm-0.1,norm+0.1);
|
|---|
| 422 | break;
|
|---|
| 423 |
|
|---|
| 424 | case kEPolya:
|
|---|
| 425 | fSinglePheFit->SetParameters(lambda_guess, excessPoisson_guess,
|
|---|
| 426 | delta1_guess,delta2_guess,
|
|---|
| 427 | electronicAmp_guess,
|
|---|
| 428 | si_0_guess,
|
|---|
| 429 | norm, mu_0_guess);
|
|---|
| 430 | fSinglePheFit->SetParNames("#lambda","b_{tot}",
|
|---|
| 431 | "#delta_{1}","#delta_{2}",
|
|---|
| 432 | "amp_{e}","#sigma_{0}",
|
|---|
| 433 | "Area", "#mu_{0}");
|
|---|
| 434 | fSinglePheFit->SetParLimits(0,0.,1.);
|
|---|
| 435 | fSinglePheFit->SetParLimits(1,0.,1.);
|
|---|
| 436 | fSinglePheFit->SetParLimits(2,6.,12.);
|
|---|
| 437 | fSinglePheFit->SetParLimits(3,3.,8.);
|
|---|
| 438 | fSinglePheFit->SetParLimits(4,0.,0.005);
|
|---|
| 439 | fSinglePheFit->SetParLimits(5,min,(max-min)/1.5);
|
|---|
| 440 | fSinglePheFit->SetParLimits(6,norm-0.1,norm+0.1);
|
|---|
| 441 | fSinglePheFit->SetParLimits(7,-35.,15.);
|
|---|
| 442 | break;
|
|---|
| 443 |
|
|---|
| 444 | case kEMichele:
|
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 | break;
|
|---|
| 448 |
|
|---|
| 449 | default:
|
|---|
| 450 | *fLog << warn << "WARNING: Could not find Fit Function for Blind Pixel " << endl;
|
|---|
| 451 | return kFALSE;
|
|---|
| 452 | break;
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | return kTRUE;
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | void MHCalibrationBlindPixel::ExitFit(TF1 *f)
|
|---|
| 459 | {
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 | //
|
|---|
| 463 | // Finalize
|
|---|
| 464 | //
|
|---|
| 465 | switch (fFitFunc)
|
|---|
| 466 | {
|
|---|
| 467 |
|
|---|
| 468 | case kEPoisson4:
|
|---|
| 469 | case kEPoisson5:
|
|---|
| 470 | case kEPoisson6:
|
|---|
| 471 | case kEPoisson7:
|
|---|
| 472 | fLambda = fSinglePheFit->GetParameter(0);
|
|---|
| 473 | fMu0 = fSinglePheFit->GetParameter(1);
|
|---|
| 474 | fMu1 = fSinglePheFit->GetParameter(2);
|
|---|
| 475 | fSigma0 = fSinglePheFit->GetParameter(3);
|
|---|
| 476 | fSigma1 = fSinglePheFit->GetParameter(4);
|
|---|
| 477 |
|
|---|
| 478 | fLambdaErr = fSinglePheFit->GetParError(0);
|
|---|
| 479 | fMu0Err = fSinglePheFit->GetParError(1);
|
|---|
| 480 | fMu1Err = fSinglePheFit->GetParError(2);
|
|---|
| 481 | fSigma0Err = fSinglePheFit->GetParError(3);
|
|---|
| 482 | fSigma1Err = fSinglePheFit->GetParError(4);
|
|---|
| 483 | break;
|
|---|
| 484 | case kEPolya:
|
|---|
| 485 | fLambda = fSinglePheFit->GetParameter(0);
|
|---|
| 486 | fMu0 = fSinglePheFit->GetParameter(7);
|
|---|
| 487 | fMu1 = 0.;
|
|---|
| 488 | fSigma0 = fSinglePheFit->GetParameter(5);
|
|---|
| 489 | fSigma1 = 0.;
|
|---|
| 490 |
|
|---|
| 491 | fLambdaErr = fSinglePheFit->GetParError(0);
|
|---|
| 492 | fMu0Err = fSinglePheFit->GetParError(7);
|
|---|
| 493 | fMu1Err = 0.;
|
|---|
| 494 | fSigma0Err = fSinglePheFit->GetParError(5);
|
|---|
| 495 | fSigma1Err = 0.;
|
|---|
| 496 | default:
|
|---|
| 497 | break;
|
|---|
| 498 | }
|
|---|
| 499 |
|
|---|
| 500 | }
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 | Bool_t MHCalibrationBlindPixel::FitSinglePhe(Axis_t rmin, Axis_t rmax, Option_t *opt)
|
|---|
| 504 | {
|
|---|
| 505 |
|
|---|
| 506 | //
|
|---|
| 507 | // Get the fitting ranges
|
|---|
| 508 | //
|
|---|
| 509 | rmin = (rmin != 0.) ? rmin : fBlindPixelChargefirst;
|
|---|
| 510 | rmax = (rmax != 0.) ? rmax : fBlindPixelChargelast;
|
|---|
| 511 |
|
|---|
| 512 | if (!InitFit(rmin,rmax))
|
|---|
| 513 | return kFALSE;
|
|---|
| 514 |
|
|---|
| 515 | fHBlindPixelCharge->Fit(fSinglePheFit,opt);
|
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 | ExitFit(fSinglePheFit);
|
|---|
| 519 |
|
|---|
| 520 | fProb = fSinglePheFit->GetProb();
|
|---|
| 521 | fChisquare = fSinglePheFit->GetChisquare();
|
|---|
| 522 | fNdf = fSinglePheFit->GetNDF();
|
|---|
| 523 |
|
|---|
| 524 | // Perform the cross-check fitting only the pedestal:
|
|---|
| 525 | fSinglePhePedFit = new TF1("GausPed","gaus",rmin,0.);
|
|---|
| 526 | fHBlindPixelCharge->Fit(fSinglePhePedFit,opt);
|
|---|
| 527 |
|
|---|
| 528 | const Stat_t entries = fHBlindPixelCharge->Integral("width");
|
|---|
| 529 |
|
|---|
| 530 | Double_t pedarea = fSinglePhePedFit->GetParameter(0)*gkSq2Pi*fSinglePhePedFit->GetParameter(2);
|
|---|
| 531 | fLambdaCheck = TMath::Log(entries/pedarea);
|
|---|
| 532 | fLambdaCheckErr = fSinglePhePedFit->GetParError(0)/fSinglePhePedFit->GetParameter(0)
|
|---|
| 533 | + fSinglePhePedFit->GetParError(2)/fSinglePhePedFit->GetParameter(2);
|
|---|
| 534 |
|
|---|
| 535 | *fLog << inf << "Results of the Blind Pixel Fit: " << endl;
|
|---|
| 536 | *fLog << inf << "Chisquare: " << fChisquare << endl;
|
|---|
| 537 | *fLog << inf << "DoF: " << fNdf << endl;
|
|---|
| 538 | *fLog << inf << "Probability: " << fProb << endl;
|
|---|
| 539 |
|
|---|
| 540 | //
|
|---|
| 541 | // The fit result is accepted under condition that:
|
|---|
| 542 | // 1) the Probability is greater than gkProbLimit (default 0.001 == 99.7%)
|
|---|
| 543 | // 2) at least 100 events are in the single Photo-electron peak
|
|---|
| 544 | //
|
|---|
| 545 | if (fProb < gkProbLimit)
|
|---|
| 546 | {
|
|---|
| 547 | *fLog << err << "ERROR: Fit Probability " << fProb
|
|---|
| 548 | << " is smaller than the allowed value: " << gkProbLimit << endl;
|
|---|
| 549 | fFitOK = kFALSE;
|
|---|
| 550 | return kFALSE;
|
|---|
| 551 | }
|
|---|
| 552 |
|
|---|
| 553 | if (fProb < 0.01)
|
|---|
| 554 | *fLog << warn << "WARNING: Fit Probability " << fProb << " is smaller than 1% " << endl;
|
|---|
| 555 |
|
|---|
| 556 | Float_t contSinglePhe = TMath::Exp(-1.0*fLambda)*fLambda*entries;
|
|---|
| 557 |
|
|---|
| 558 | if (contSinglePhe < 100.)
|
|---|
| 559 | {
|
|---|
| 560 | *fLog << err << "ERROR: Statistics is too low: Only " << contSinglePhe
|
|---|
| 561 | << " in the Single Photo-Electron peak " << endl;
|
|---|
| 562 | fFitOK = kFALSE;
|
|---|
| 563 | return kFALSE;
|
|---|
| 564 | }
|
|---|
| 565 | else
|
|---|
| 566 | *fLog << inf << contSinglePhe << " in Single Photo-Electron peak " << endl;
|
|---|
| 567 |
|
|---|
| 568 | fFitOK = kTRUE;
|
|---|
| 569 |
|
|---|
| 570 | return kTRUE;
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 | void MHCalibrationBlindPixel::CutAllEdges()
|
|---|
| 575 | {
|
|---|
| 576 |
|
|---|
| 577 | Int_t nbins = 30;
|
|---|
| 578 |
|
|---|
| 579 | CutEdges(fHBlindPixelCharge,nbins);
|
|---|
| 580 |
|
|---|
| 581 | fBlindPixelChargefirst = fHBlindPixelCharge->GetBinLowEdge(fHBlindPixelCharge->GetXaxis()->GetFirst());
|
|---|
| 582 | fBlindPixelChargelast = fHBlindPixelCharge->GetBinLowEdge(fHBlindPixelCharge->GetXaxis()->GetLast())+fHBlindPixelCharge->GetBinWidth(0);
|
|---|
| 583 | fBlindPixelChargenbins = nbins;
|
|---|
| 584 |
|
|---|
| 585 | CutEdges(fHBlindPixelChargevsN,0);
|
|---|
| 586 |
|
|---|
| 587 | }
|
|---|
| 588 |
|
|---|
| 589 | Bool_t MHCalibrationBlindPixel::FitTime(Axis_t rmin, Axis_t rmax, Option_t *opt)
|
|---|
| 590 | {
|
|---|
| 591 |
|
|---|
| 592 | rmin = (rmin != 0.) ? rmin : 4.;
|
|---|
| 593 | rmax = (rmax != 0.) ? rmax : 9.;
|
|---|
| 594 |
|
|---|
| 595 | const Stat_t entries = fHBlindPixelTime->Integral();
|
|---|
| 596 | const Double_t mu_guess = fHBlindPixelTime->GetBinCenter(fHBlindPixelTime->GetMaximumBin());
|
|---|
| 597 | const Double_t sigma_guess = (rmax - rmin)/2.;
|
|---|
| 598 | const Double_t area_guess = entries/gkSq2Pi;
|
|---|
| 599 |
|
|---|
| 600 | fTimeGausFit = new TF1("GausTime","gaus",rmin,rmax);
|
|---|
| 601 | fTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
|
|---|
| 602 | fTimeGausFit->SetParNames("Area","#mu","#sigma");
|
|---|
| 603 | fTimeGausFit->SetParLimits(0,0.,entries);
|
|---|
| 604 | fTimeGausFit->SetParLimits(1,rmin,rmax);
|
|---|
| 605 | fTimeGausFit->SetParLimits(2,0.,rmax-rmin);
|
|---|
| 606 |
|
|---|
| 607 | fHBlindPixelTime->Fit(fTimeGausFit,opt);
|
|---|
| 608 | rmin = fTimeGausFit->GetParameter(1) - 2.*fTimeGausFit->GetParameter(2);
|
|---|
| 609 | rmax = fTimeGausFit->GetParameter(1) + 2.*fTimeGausFit->GetParameter(2);
|
|---|
| 610 | fTimeGausFit->SetRange(rmin,rmax);
|
|---|
| 611 |
|
|---|
| 612 | fHBlindPixelTime->Fit(fTimeGausFit,opt);
|
|---|
| 613 |
|
|---|
| 614 | fMeanTime = fTimeGausFit->GetParameter(2);
|
|---|
| 615 | fSigmaTime = fTimeGausFit->GetParameter(3);
|
|---|
| 616 | fMeanTimeErr = fTimeGausFit->GetParError(2);
|
|---|
| 617 | fSigmaTimeErr = fTimeGausFit->GetParError(3);
|
|---|
| 618 |
|
|---|
| 619 | *fLog << inf << "Results of the Times Fit: " << endl;
|
|---|
| 620 | *fLog << inf << "Chisquare: " << fTimeGausFit->GetChisquare() << endl;
|
|---|
| 621 | *fLog << inf << "Ndf: " << fTimeGausFit->GetNDF() << endl;
|
|---|
| 622 |
|
|---|
| 623 | return kTRUE;
|
|---|
| 624 |
|
|---|
| 625 | }
|
|---|