15 DrawHistos(
"d0D0_PureBack.root",
"d0D0NoMCSel_SideBand.root",
"hd0D0",ptbin,rebin);
16 SubtractHist(
"d0D0_Signal.root",
"d0D0NoMCSel.root",
"d0D0NoMCSel_SideBand.root",
"hd0D0",ptbin,rebin);
24 if(!nameHist.IsNull())histname.Append(nameHist.Data());
26 Double_t minX,maxX,binwidth,cumul=0.,errcumul=0.;
27 nbins=h1->GetNbinsX();
28 minX=h1->GetBinCenter(1);
29 maxX=h1->GetBinCenter(nbins);
30 binwidth=h1->GetBinWidth(1);
32 TH1F *h1copy=
new TH1F();
36 TH1F *hCumul=
new TH1F(histname.Data(),histname.Data(),
nbins,minX-binwidth/2.,maxX+binwidth/2.);
40 cumul+=h1copy->GetBinContent(j);
41 hCumul->SetBinContent(j,cumul);
44 hCumul->Scale(1./h1copy->Integral(1,nbins));
72 if(file1.IsNull())file1=
"d0D0_PureBack.root";
73 if(file2.IsNull())file2=
"d0D0NoMCSel_SideBand.root";
74 TFile *fSide=TFile::Open(file2.Data());
75 TFile *fmer=TFile::Open(file1.Data());
76 TH1F *h1=(TH1F*)fmer->Get(hist.Data());
77 nameH.Append(
"_Gaus");
78 h1->SetName(nameH.Data());
80 TH1F *h2=(TH1F*)fSide->Get(hist.Data());
81 nameH.Append(
"_SideBands");
82 h2->SetName(nameH.Data());
90 hCumul1->SetDrawOption(
"E4");
92 hCumul2->SetDrawOption(
"E4");
95 TH1F *hDivCumul=
new TH1F();
98 hDivCumul->Divide(hCumul1,hCumul2);
99 hDivCumul->SetName(
"RatioCumulGausSdBands");
100 hDivCumul->SetTitle(
"Ratio Cumulative Gaus Over SideBands");
102 TH1F *hGausComp=
new TH1F();
105 nameH.Append(
"Compare");
106 hGausComp->SetName(nameH.Data());
107 hGausComp->SetLineColor(kRed);
109 integr1=hGausComp->Integral();
111 TH1F *hSideComp=
new TH1F();
114 nameH.Append(
"Compare");
115 hSideComp->SetName(nameH.Data());
116 hSideComp->SetLineColor(kBlue);
118 integr2=hSideComp->Integral();
119 if(integr2>integr1)hSideComp->Scale(integr1/integr2);
120 else hGausComp->Scale(integr2/integr1);
122 TH1F *hDivision=
new TH1F();
124 hDivision->SetName(
"RatioGausSdBands");
125 hDivision->SetTitle(
"Ratio Gaus Over Sd Bands");
127 hDivision->Divide(hGausComp,hSideComp);
130 cCompareSimple=
new TCanvas(
"cCompareSimple",
"Comparison of Under Gaus and Under Side Band background",700,700);
134 hGausComp->Draw(
"Sames");
136 TPaveStats *p=hGausComp->FindObject(
"stats");
137 p->SetTextColor(kRed);
138 p=(TPaveStats*)hSideComp->FindObject(
"stats");
139 p->SetTextColor(kBlue);
144 cCompareCum=
new TCanvas(
"cCompareCum",
"Comparison of cumulative function",700,700);
150 hCumul1->SetLineColor(kRed);
151 hCumul2->SetLineColor(kBlue);
152 hCumul1->SetFillColor(kRed);
153 hCumul2->SetFillColor(kBlue);
155 hCumul2->Draw(
"Sames");
159 p=(TPaveStats*)hCumul1->FindObject(
"stats");
160 p->SetTextColor(kRed);
161 p=(TPaveStats*)hCumul2->FindObject(
"stats");
162 p->SetTextColor(kBlue);
172 cout<<
"Are you satisfied?"<<endl;
208 SubtractHist(
"d0D0_Signal.root",
"d0D0NoMCSel.root",
"d0D0NoMCSel_SideBand.root",
"hd0D0",pt,
rebin);
224 if(
gSystem->AccessPathName(fileSignal.Data())){
225 Printf(
"Wrong signal file! \n");
228 if(
gSystem->AccessPathName(fileNoMC.Data())){
229 Printf(
"Wrong d0distr under inv mass peak file! \n");
232 if(
gSystem->AccessPathName(fileNoMCSB.Data())){
233 Printf(
"Wrong d0distr Side band file! \n");
237 TFile *fSide=TFile::Open(fileNoMCSB.Data());
238 TFile *fNoMCSignal=TFile::Open(fileNoMC.Data());
240 TH1F *h1=(TH1F*)fNoMCSignal->Get(hist.Data());
241 nameH.Append(
"_SelSignal");
242 h1->SetName(nameH.Data());
247 TH1F *h2=(TH1F*)fSide->Get(hist.Data());
248 nameH.Append(
"_SideBands");
249 h2->SetName(nameH.Data());
253 Double_t integrGaus,integrSB,integrSign;
254 integrGaus=h1->Integral();
255 integrSB=h2->Integral();
258 TFile *fSignal=TFile::Open(fileSignal.Data());
259 TH1F *hSign=(TH1F*)fSignal->Get(hist.Data());
261 nameH.Append(
"_MCSignal");
262 hSign->SetName(nameH.Data());
265 Double_t integrGaus,integrSB,integrSign;
266 integrGaus=h1->Integral();
267 integrSB=h2->Integral();
268 integrSign=hSign->Integral();
279 TH1F *hGausSubtract=
new TH1F();
282 hist.Append(
"_Subtracted");
283 hGausSubtract->SetName(hist.Data());
285 hGausSubtract->Add(h1,h2,1.,-1./integrSB*(integrGaus-integrSign));
288 cSubtraction=
new TCanvas(
"cSubtraction",
"cSubtraction",600,700);
290 hGausSubtract->SetLineColor(kRed);
291 hGausSubtract->Draw(
"E0");
292 hSign->SetLineColor(kBlue);
293 hSign->Draw(
"sames");
295 TPaveStats *p=hGausSubtract->FindObject(
"stats");
296 p->SetTextColor(kRed);
298 p=(TPaveStats*)hSign->FindObject(
"stats");
299 p->SetTextColor(kBlue);
324 TH1F *hCumulGausSubtract=
CumulativeHist(hGausSubtract,
"_BackSubtr");
325 hCumulGausSubtract->SetDrawOption(
"E4");
327 hCumulSign->SetDrawOption(
"E4");
330 TH1F *hDivCumul=
new TH1F();
331 *hDivCumul=*hCumulSign;
332 hDivCumul->Divide(hCumulGausSubtract,hCumulSign);
333 hDivCumul->SetName(
"RatioCumulBackSubtr_MCSignal");
334 hDivCumul->SetTitle(
"Ratio Cumulative BackSubtracted Over MCSignal");
336 TH1F *hGausSubComp=
new TH1F();
337 *hGausSubComp=*hGausSubtract;
338 nameH=hGausSubtract->GetName();
339 nameH.Append(
"Compare");
340 hGausSubComp->SetName(nameH.Data());
341 hGausSubComp->SetLineColor(kRed);
342 integr1=hGausSubComp->Integral();
344 TH1F *hSignComp=
new TH1F();
346 nameH=hSign->GetName();
347 nameH.Append(
"Compare");
348 hSignComp->SetName(nameH.Data());
349 hSignComp->SetLineColor(kBlue);
350 integr2=hSignComp->Integral();
351 if(integr2>integr1)hSignComp->Scale(integr1/integr2);
352 else hGausSubComp->Scale(integr2/integr1);
354 TH1F *hDivision=
new TH1F();
355 *hDivision=*hGausSubtract;
356 hDivision->SetName(
"RatioBackSubtr_Signal");
357 hDivision->SetTitle(
"Ratio BackSubtracted Over MCSignal");
358 hDivision->Divide(hGausSubComp,hSignComp);
361 cCompareSubtractSimple=
new TCanvas(
"cCompareSubtractSimple",
"Comparison of BackSubtracted and MCSignal",700,700);
365 hGausSubComp->Draw(
"Sames");
367 hDivision->SetLineColor(1);
370 p=(TPaveStats*)hGausSubComp->FindObject(
"stats");
371 p->SetTextColor(kRed);
372 p=(TPaveStats*)hSignComp->FindObject(
"stats");
373 p->SetTextColor(kBlue);
377 cCompareSubtractCum=
new TCanvas(
"cCompareSubtractCumulative",
"Comparison of cumulative functions",700,700);
383 hCumulGausSubtract->SetLineColor(kRed);
384 hCumulSign->SetLineColor(kBlue);
385 hCumulGausSubtract->SetFillColor(kRed);
386 hCumulSign->SetFillColor(kBlue);
387 hCumulGausSubtract->Draw();
388 hCumulSign->Draw(
"Sames");
390 hDivCumul->SetLineColor(1);
394 p=(TPaveStats*)hCumulGausSubtract->FindObject(
"stats");
395 p->SetTextColor(kRed);
396 p=(TPaveStats*)hCumulSign->FindObject(
"stats");
397 p->SetTextColor(kBlue);
407 cout<<
"Are you satisfied?"<<endl;
413 delete hCumulGausSubtract;
424 printf(
"Side Band integral: %d \n",integrSB);
425 printf(
"Selected Signal integral: %d \n",integrGaus);
426 printf(
"MC Signal integral: %d \n",integrSign);
427 printf(
" -> Background = %d \n",integrGaus-integrSign);
444 histname.Append(
"pt");
446 fileout.Append(
"pt");
449 else fileout.Append(
"ptAll");
451 TFile *fIN=TFile::Open(filename.Data());
453 TH1F *h=(TH1F*)fIN->Get(histname.Data());
456 Int_t binL=1,binR=h->GetNbinsX();
461 Double_t integr=h->Integral(binL,binR);
462 Double_t binwidth=h->GetBinWidth(10);
464 Int_t nbin=h->GetNbinsX();
467 TCanvas *c1=
new TCanvas(
"c1",
"c1",700,600);
475 h->Fit(f->GetName(),
"RI",
"",h->GetBinCenter(binL)-binwidth/2.,h->GetBinCenter(binR)+binwidth/2.);
478 cout<<
"Is it ok?"<<endl;
483 fileout.Append(gausSide.Data());
484 fileout.Append(
"Fit.root");
486 TFile *fOUT=
new TFile(fileout.Data(),
"RECREATE");
495 cout<<
"rebin value= ";
498 cout<<
"Change Interval?"<<endl;
501 cout<<
"Lower value= ";
504 cout<<
"Upper value= ";
508 binL=h->FindBin(minX);
509 binR=h->FindBin(maxX);
527 TF1 *func=
new TF1(
"func",
"[5]*[6]*((1.-[2])*1./2./[1]*TMath::Exp(-TMath::Abs((x-[0])/[1]))+[2]/TMath::Sqrt(2*TMath::Pi())/[4]*TMath::Exp(-1*(x-[3])*(x-[3])/2./[4]/[4]))");
529 func->FixParameter(5,integral);
530 func->SetParName(5,
"histInt");
531 func->FixParameter(6,binw);
532 func->SetParName(6,
"binW");
533 func->SetParLimits(0,-100,100.);
534 func->SetParName(0,
"expMean");
535 func->SetParLimits(1,0.001,1000);
536 func->SetParName(1,
"expDecay");
537 func->SetParLimits(2,0.00001,1.);
538 func->SetParName(2,
"fracGaus");
539 func->SetParLimits(3,-100,100.);
540 func->SetParName(3,
"gausMean");
541 func->SetParLimits(4,5.,200.);
542 func->SetParName(4,
"gausSigma");
544 func->SetParameter(1,50.);
545 func->SetParameter(4,50.);
557 Int_t int1=h1->Integral();
558 Int_t int2=h2->Integral();
560 TH1F **h=
new TH1F*[2];
561 TH1F *hchisq=
new TH1F(
"hChi2",
"Chi2 histo",1000,0.,10.);
576 Int_t nbin=h[0]->GetNbinsX();
580 for(
Int_t j=1;j<=nbin;j++){
582 if(h[1]->GetBinContent(j)==0||h[0]->GetBinContent(j)==0)
continue;
583 fTrue=h[0]->GetBinContent(j)/nM;
584 chi2=(h[1]->GetBinContent(j)-fTrue*nm)*(h[1]->GetBinContent(j)-fTrue*nm)/h[1]->GetBinContent(j);
601 TH1F *h1=
new TH1F(
"h1",
"h1",50,-10.,10.);
602 TH1F *h2=
new TH1F(
"h2",
"h2",50,-10.,10.);
604 h1->FillRandom(
"gaus",50000);
605 h2->FillRandom(
"gaus",80000);
606 TH1F *hchi2=
new TH1F();
610 cout<<
"The chi2 is "<<chi2;
TCanvas * cCompareSubtractCum
TCanvas * cCompareSubtractSimple
TH1F * CumulativeHist(const TH1F *h1, TString nameHist=0x0)
Double_t GetChi2(const TH1F *h1, const TH1F *h2, TH1F *hchi2, Int_t &ndof)
void DoFit(TString filename, TString histo, TString gausSide, Int_t ptbin, Int_t rebin=-1)
void DrawHistos(Int_t pt, Int_t rebin=1)
void SubtractHist(Int_t pt, Int_t rebin=1)
void AnalyzeCharmFractionHists(Int_t ptbin, Int_t rebin)
TF1 * CreateFunc(Double_t integral, Double_t binw)