//#endif void DrawInPad(TVirtualPad* p, Int_t sub, TH1* h, Bool_t logy=false) { TVirtualPad* pp = p->cd(sub); pp->SetRightMargin(0.02); if (logy) pp->SetLogy(); TH1* copy = h->DrawCopy("hist"); copy->GetXaxis()->SetLabelSize(0.13); copy->GetYaxis()->SetLabelSize(0.08); copy->SetDirectory(0); }
/** * Draw final plot for QM2011 * * @param max * * @ingroup pwglf_forward_scripts */ void dndeta_final(Double_t max=6) { gStyle->SetOptTitle(0); gStyle->SetOptFit(0); gStyle->SetTitleFont(132, "xyz"); gStyle->SetTitleSize(0.1, "xyz"); gStyle->SetTitleOffset(0.4, "y"); gStyle->SetTitleOffset(0.8, "x"); gStyle->SetLabelFont(132, "xyz"); gStyle->SetLabelSize(0.08, "xyz"); gStyle->SetNdivisions(212, "x"); gStyle->SetNdivisions(208, "y"); gStyle->SetTextFont(132); gStyle->SetPadColor(0); gStyle->SetPadBorderMode(0); // gStyle->SetFillColor(0); // gStyle->SetFillStyle(0); TCanvas* c = new TCanvas("c", "c", 900, 900); c->SetFillColor(0); c->SetFillStyle(0); c->SetBorderSize(0); c->SetBorderMode(0); c->SetRightMargin(0.02); c->SetTopMargin(0.02); c->SetBottomMargin(0.15); c->Divide(1,3,0,0); // --- INEL -------------------------------------------------------- TVirtualPad* p = c->cd(1); p->SetGridx(); p->SetRightMargin(.01); THStack* inel = new THStack("inel", "INEL"); TLatex* inelT = new TLatex(1-p->GetRightMargin()-.01, 1-p->GetTopMargin()-.01, "INEL"); inelT->SetNDC(); inelT->SetTextAlign(33); inelT->SetTextSize(0.12); TLegend* inelL = new TLegend(.3, .02, .8, .4); inelL->SetBorderSize(0); inelL->SetNColumns(2); inelL->SetFillColor(0); inelL->SetFillStyle(0); TLegendEntry* e = inelL->AddEntry("d1", "Forward", "lp"); e->SetMarkerColor(kRed+2); e->SetMarkerStyle(29); e = inelL->AddEntry("d2", "Central", "lp"); e->SetMarkerColor(kMagenta+2); e->SetMarkerStyle(29); e = inelL->AddEntry("d3", "Data", "lp"); e->SetMarkerStyle(29); e = inelL->AddEntry("d4", "Mirrored data", "lp"); e->SetMarkerStyle(30); e = inelL->AddEntry("d5", "Systematic error", "f"); e->SetFillColor(kGray); e->SetLineColor(kGray); e->SetLineWidth(0); e->SetFillStyle(3001); gROOT->LoadMacro("export_pp_0900GeV_INEL_m10p10cm_000100000ev.C"); export_pp_0900GeV_INEL_m10p10cm_000100000ev(inel, inelL, 20); export_pp_0900GeV_INEL_m10p10cm_000100000ev(inel, inelL, 21); export_pp_0900GeV_INEL_m10p10cm_000100000ev(inel, inelL, 22); inel->Draw("nostack e1"); inel->GetHistogram()->SetYTitle("#frac{1}{N}#frac{dN_{ch}}{d#eta}"); inel->GetHistogram()->SetXTitle("#eta"); inel->GetHistogram()->GetYaxis()->SetDecimals(); inelL->Draw(); inelT->Draw(); // --- INEL>0 ------------------------------------------------------ p = c->cd(2); p->SetGridx(); p->SetRightMargin(.01); THStack* inelgt0 = new THStack("inelgt0", "INEL>0"); TLatex* inelgt0T = new TLatex(1-p->GetRightMargin()-.01, 1-p->GetTopMargin()-.01, "INEL>0"); inelgt0T->SetNDC(); inelgt0T->SetTextAlign(33); inelgt0T->SetTextSize(0.12); gROOT->LoadMacro("export_pp_0900GeV_INEL_m10p10cm_000100000ev.C"); export_pp_0900GeV_INEL_m10p10cm_000100000ev(inelgt0, 0, 20); export_pp_0900GeV_INEL_m10p10cm_000100000ev(inelgt0, 0, 21); export_pp_0900GeV_INEL_m10p10cm_000100000ev(inelgt0, 0, 22); inelgt0->Draw("nostack e1"); inelgt0->GetHistogram()->SetXTitle("#eta"); inelgt0->GetHistogram()->GetYaxis()->SetDecimals(); inelgt0T->Draw(); // --- NSD --------------------------------------------------------- p = c->cd(3); p->SetGridx(); p->SetRightMargin(.01); THStack* nsd = new THStack("nsd", "NSD"); TLatex* nsdT = new TLatex(1-p->GetRightMargin()-.01, 1-p->GetTopMargin()-.01, "NSD"); nsdT->SetNDC(); nsdT->SetTextAlign(33); nsdT->SetTextSize(0.12); gROOT->LoadMacro("export_pp_0900GeV_NSD_m10p10cm_000100000ev.C"); export_pp_0900GeV_NSD_m10p10cm_000100000ev(nsd, 0, 20); export_pp_0900GeV_NSD_m10p10cm_000100000ev(nsd, 0, 21); export_pp_0900GeV_NSD_m10p10cm_000100000ev(nsd, 0, 22); nsd->Draw("nostack e1"); nsd->GetHistogram()->SetXTitle("#eta"); nsd->GetHistogram()->GetYaxis()->SetDecimals(); nsdT->Draw(); c->cd(); c->SaveAs("dndeta_final.png"); }
/** * * * @param o * @param useWeights * @param correct * * @ingroup pwglf_forward_scripts_tests */ void TestPoisson(Double_t o=.3, bool useWeights=false, bool correct=true) { const char* load = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C"; if (!gROOT->GetClass("AliAODForwardMult")) { gROOT->Macro(load); gROOT->GetInterpreter()->UnloadFile(gSystem->ExpandPathName(load)); } // --- Parameters of this script ----------------------------------- Int_t nBin = 5; // Our detector matrix size Int_t nMax = TMath::Max(Int_t(nBin * nBin * o + .5)+nBin/2,nBin); Int_t nEv = 10000; // Number of events Double_t mp = o; // The 'hit' probability TH2D* base = new TH2D("base", "Basic histogram", nBin,-.5, nBin-.5, nBin, -.5, nBin-.5); base->SetXTitle("#eta"); base->SetYTitle("#varphi"); base->SetDirectory(0); base->SetOption("colz"); Int_t tN1=nMax; Double_t tMin1; Double_t tMax1; Int_t tN2=nMax*10; Double_t tMin2; Double_t tMax2=nMax; MakeIntegerAxis(tN1, tMin1, tMax1); MakeIntegerAxis(tN2, tMin2, tMax2); TH2D* corr = new TH2D("comp", "Comparison", tN1, tMin1, tMax1, tN2, tMin2, tMax2); corr->SetXTitle("Input"); corr->SetYTitle("Poisson"); corr->SetDirectory(0); corr->SetOption("colz"); corr->SetStats(0); TLine* lcorr = new TLine(0, 0, tMax2, tMax2); Int_t mm = TMath::Max(Int_t(nBin * o + .5),nBin/2); tN2=mm*10; tMax2 = mm; MakeIntegerAxis(tN2, tMin2, tMax2); Info("", "Making mean w/nbins=%d,range=[%f,%f]", tN2, tMin2, tMax2); TH2D* mean = new TH2D("mean", "Mean comparison", tN2, tMin2, tMax2, tN2, tMin2, tMax2); mean->SetXTitle("Input"); mean->SetYTitle("Poisson"); mean->SetDirectory(0); mean->SetOption("colz"); mean->SetStats(0); TLine* lmean = new TLine(tMin2, tMin2, tMax2, tMax2); TH1D* dist = new TH1D("dist", "Distribution of hits", tN1, tMin1, tMax1); dist->SetXTitle("s"); dist->SetYTitle("P(s)"); dist->SetFillColor(kRed+1); dist->SetFillStyle(3001); dist->SetDirectory(0); TH1D* diff = new TH1D("diff", "P-T", 100, -25, 25); diff->SetXTitle("Difference"); diff->SetFillColor(kRed+1); diff->SetFillStyle(3001); diff->SetYTitle("Prob"); AliPoissonCalculator* c = new AliPoissonCalculator("ignored"); c->Init(nBin ,nBin); for (Int_t i = 0; i < nEv; i++) { c->Reset(base); base->Reset(); for (Int_t iEta = 0; iEta < nBin; iEta++) { for (Int_t iPhi = 0; iPhi < nBin; iPhi++) { // Throw a die Int_t m = gRandom->Poisson(mp); dist->Fill(m); // Fill into our base histogram base->Fill(iEta, iPhi, m); // Fill into poisson calculator c->Fill(iEta, iPhi, m > 0, (useWeights ? m : 1)); } } // Calculate the result TH2D* res = c->Result(correct); // Now loop and compare Double_t mBase = 0; Double_t mPois = 0; for (Int_t iEta = 0; iEta < nBin; iEta++) { for (Int_t iPhi = 0; iPhi < nBin; iPhi++) { Double_t p = res->GetBinContent(iEta, iPhi); Double_t t = base->GetBinContent(iEta, iPhi); mBase += t; mPois += p; corr->Fill(t, p); diff->Fill(p-t); } } Int_t nn = nBin * nBin; mean->Fill(mBase / nn, mPois / nn); } TCanvas* cc = new TCanvas("c", "c", 900, 900); cc->SetFillColor(0); cc->SetFillStyle(0); cc->SetBorderMode(0); cc->SetRightMargin(0.02); cc->SetTopMargin(0.02); cc->Divide(2,2); TVirtualPad* pp = cc->cd(1); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.15); pp->SetTopMargin(0.02); pp->SetLogz(); pp->SetGridx(); pp->SetGridy(); corr->Draw(); lcorr->Draw(); pp = cc->cd(2); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.02); pp->SetTopMargin(0.02); #if 0 c->GetMean()->Draw(); #elif 1 pp->SetLogy(); diff->Draw(); #elif 1 c->GetOccupancy()->Draw(); #else pp->SetLogy(); dist->SetStats(0); dist->Scale(1. / dist->Integral()); dist->Draw(); TH1D* m1 = c->GetMean(); m1->Scale(1. / m1->Integral()); m1->Draw("same"); Double_t eI; Double_t ii = 100 * dist->Integral(2, 0); TLatex* ll = new TLatex(.97, .85, Form("Input #bar{m}: %5.3f", mp)); ll->SetNDC(); ll->SetTextFont(132); ll->SetTextAlign(31); ll->Draw(); ll->DrawLatex(.97, .75, Form("Result #bar{m}: %5.3f", dist->GetMean())); ll->DrawLatex(.97, .65, Form("Occupancy: #int_{1}^{#infty}P(s)ds = %6.2f%%", ii)); #endif pp = cc->cd(3); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.15); pp->SetTopMargin(0.02); pp->SetGridx(); pp->SetGridy(); c->GetCorrection()->Draw(); pp = cc->cd(4); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.15); pp->SetTopMargin(0.02); pp->SetLogz(); pp->SetGridx(); pp->SetGridy(); mean->Draw(); lmean->Draw(); cc->cd(); }
void makeqaplot(int run=0, int plt=0, int save=0){ runnum=run; yearday=run/1000; if(save==0) {png=0; pdf=0;} if(save==1) {png=1; pdf=0;} if(save==2) {png=0; pdf=1;} if(save==3) {png=1; pdf=1;} c1 = new TCanvas("c1","QA",50,50,800,800); gStyle->SetLabelSize(0.04,"xy"); //colortable(); gStyle->SetPalette(1); gStyle->SetStatW(0.4); char fname[50]; if(run==0) {sprintf(fname,"fgtQA.root");} else {sprintf(fname,"%d/fgtQA_%d.root",yearday,run);} cout << "Opening "<<fname<<endl; file=new TFile(fname,""); char c[50]; if(plt==0 || plt==1) { gStyle->SetOptStat(111110); c1->Divide(1,3); for(int i=0; i<3; i++){ TVirtualPad* pad = c1->cd(i+1); int log=0; if(i>0) {log=1;} pad->SetLogy(log); hist0[i]=(TH1F*) file->Get(cHist[i]); hist0[i]->SetFillColor(kBlue); hist0[i]->Draw(); if(i==2){ float ntot = float(hist0[i]->GetEntries()); if(ntot>0.0){ int nbin = hist0[i]->GetNbinsX(); float nofgt = hist0[i]->Integral(1,1); int bin = hist0[i]->FindBin(float(kFgtNumElecIds)); float nonzs = hist0[i]->Integral(bin-1,nbin+1); float zs = hist0[i]->Integral(2,bin-2); hist0[i]->GetXaxis()->SetRange(2, bin-2); float mean = hist0[i]->GetMean() / float(kFgtNumElecIds); char c[100]; sprintf(c,"Total %d",ntot); TText *t1 = new TText(0.3,0.8,c); t1->SetNDC(); t1->SetTextSize(0.06); t1->Draw(); sprintf(c,"NoFGT %d (%5.2f)",nofgt,nofgt/ntot); TText *t2 = new TText(0.3,0.7,c); t2->SetNDC(); t2->SetTextSize(0.06); t2->Draw(); sprintf(c,"NoneZS %d (%5.2f)",nonzs,nonzs/ntot); TText *t3 = new TText(0.3,0.6,c); t3->SetNDC(); t3->SetTextSize(0.06); t3->Draw(); sprintf(c,"ZS %d (%5.2f)",zs,zs/ntot); TText *t4 = new TText(0.3,0.5,c); t4->SetNDC(); t4->SetTextSize(0.06); t4->Draw(); sprintf(c,"Mean ZS data size/fullsize= %5.3f",mean); TText *t5 = new TText(0.3,0.4,c); t5->SetNDC(); t5->SetTextSize(0.06); t5->Draw(); if(mean>0.08) { t5->SetTextColor(2); } else { t5->SetTextColor(4); } } } } c1->Update(); save("plot"); } if(plt==0 || plt==2) { c1->Clear(); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); c1->Divide(1,3); for(int i=3; i<6; i++){ hist0[i]=(TH1F*) file->Get(cHist[i]); } int nevt=hist0[5]->GetEntries(); printf("Nevent=%d\n",nevt); TVirtualPad* pad; pad=c1->cd(1); pad->SetLogy(); pad->SetTopMargin(0.01); pad->SetRightMargin(0.01); hist0[3]->GetXaxis()->SetLabelSize(0.07); hist0[3]->GetYaxis()->SetLabelSize(0.07); hist0[3]->SetFillColor(kRed); hist0[3]->Scale(1/float(nevt)); hist0[3]->Draw(); TText *tx= new TText(0.87,0.0,"EleID"); tx->SetNDC(); tx->SetTextSize(0.1); tx->Draw(); TText *t3= new TText(0.05,0.1,"F3=frac in 3sig/2tb"); t3->SetNDC(); t3->SetTextSize(0.08); t3->SetTextAngle(90); t3->Draw(); pad=c1->cd(2); pad->SetLogy(); pad->SetTopMargin(0.01); pad->SetRightMargin(0.01); hist0[4]->GetXaxis()->SetLabelSize(0.07); hist0[4]->GetYaxis()->SetLabelSize(0.07); hist0[4]->SetFillColor(kBlue); hist0[4]->Scale(1/float(nevt)); hist0[4]->Draw(); tx->Draw(); TText *t4= new TText(0.05,0.1,"F10=frac in 10sig & >500"); t4->SetNDC(); t4->SetTextSize(0.08); t4->SetTextAngle(90); t4->Draw(); float min=-4; int max=hist0[3]->GetNbinsX(); printf("Max=%d\n",max); TH1F *h1 = new TH1F("ZSdataFrac","ZSdataFrac",50,min,0); TH1F *h2 = new TH1F("10SigmaFrac","10SigmaFrac",50,min,0); float f1[kFgtNumElecIds],f2[kFgtNumElecIds]; for(int i=0; i<max; i++){ f1[i] = log10(hist0[3]->GetBinContent(i+1)); if(f1[i]<min) {f1[i]=min;} h1->Fill(f1[i]); f2[i] = log10(hist0[4]->GetBinContent(i+1)); if(f2[i]<min) {f2[i]=min;} h2->Fill(f2[i]); } pad = c1->cd(3); pad->Divide(2,1); TVirtualPad *pad2; pad2 = pad->cd(1); pad2->SetLogy(); pad2->SetTopMargin(0.01); pad2->SetRightMargin(0.01); h1->GetXaxis()->SetLabelSize(0.1); h1->GetYaxis()->SetLabelSize(0.1); h2->GetXaxis()->SetLabelSize(0.1); h2->GetYaxis()->SetLabelSize(0.1); h1->SetLineColor(kRed); h2->SetLineColor(kBlue); if(h1->GetMaximum()>h2->GetMaximum()){ h1->Draw(); h2->Draw("SAME"); }else{ h2->Draw(); h1->Draw("SAME"); } TText *t5= new TText(0.2,0.88,"Log(F3)"); t5->SetNDC(); t5->SetTextSize(0.1); t5->SetTextColor(2); t5->Draw(); TText *t6= new TText(0.6,0.88,"Log(F10)"); t6->SetNDC(); t6->SetTextSize(0.1); t6->SetTextColor(4); t6->Draw(); //read ped file int eid, t; float ped[kFgtNumElecIds],rms[kFgtNumElecIds],p,r; int status[kFgtNumElecIds]; memset(status,0,sizeof(status)); cout<<"Reading Ped File "<<endl; std::ifstream in("ped.txt"); if (!in.is_open()) { cout << "Can't find file!\n"; exit(0); } while (!in.eof()){ in >> eid >> t >> p >> r; ped[eid]=p; rms[eid]=r; } in.close(); TH1F * hr1= new TH1F("RMS","RMS",60,0,120); TH1F * hr2= new TH1F("RMS2","RMS2",60,0,120); TH1F * hr3= new TH1F("RMS3","RMS3",60,0,120); TH1F * hr4= new TH1F("RMS4","RMS4",60,0,120); TH1F * hr5= new TH1F("RMS5","RMS5",60,0,120); float f1l=-3.5, f1h=-0.5; float f2l=-3.5, f2h=-1.2; for(int i=0; i<kFgtNumElecIds; i++){ if(f1[i]<f1l) status[i]+=1; if(f1[i]>f1h) status[i]+=2; if(f1[i]<f2l) status[i]+=4; if(f1[i]>f2h) status[i]+=8; hr1->Fill(rms[i]); if(f1[i]<f1l) {hr2->Fill(rms[i]);} if(f1[i]<f1l || f1[i]>f1h) {hr3->Fill(rms[i]);} if(f1[i]<f1l || f1[i]>f1h || f2[i]<f2l) {hr4->Fill(rms[i]);} if(f1[i]<f1l || f1[i]>f1h || f2[i]<f2l || f2[i]>f2h) {hr5->Fill(rms[i]);} } char filename[150]; if(nevt>=1000){ sprintf(filename,"%d/status/status.%d.txt",yearday,run); }else{ sprintf(filename,"%d/status/status.%d.lowstat.txt",yearday,run); } FILE* pfile=fopen(filename,"w"); if(!pfile){ printf("Couldn't open file %s\n",filename); }else{ printf("Writing %s\n",filename); for(int i=0; i<kFgtNumElecIds; i++){ fprintf(pfile,"%d 0x%d\n",i,status[i]); } fclose(pfile); } pad2 = pad->cd(2); pad2->SetLogy(0); pad2->SetTopMargin(0.01); pad2->SetRightMargin(0.01); hr1->GetXaxis()->SetLabelSize(0.1); hr1->GetYaxis()->SetLabelSize(0.05); hr1->SetFillColor(3); hr1->Draw(); hr5->SetFillColor(9); hr5->Draw("same"); hr4->SetFillColor(4); hr4->Draw("same"); hr3->SetFillColor(6); hr3->Draw("same"); hr2->SetFillColor(2); hr2->Draw("same"); char cc1[100]; sprintf(cc1,"Log(F3)<%4.1f",f1l); char cc2[100]; sprintf(cc2,"Log(F3)>%4.1f",f1h); char cc3[100]; sprintf(cc3,"Log(F10)<%4.1f",f2l); char cc4[100]; sprintf(cc4,"Log(F10)>%4.1f",f2h); TText *t7 = new TText(0.6,0.88,cc1); t7->SetNDC(); t7->SetTextSize(0.07); t7->SetTextColor(2); t7->Draw(); TText *t8 = new TText(0.6,0.78,cc2); t8->SetNDC(); t8->SetTextSize(0.07); t8->SetTextColor(6); t8->Draw(); TText *t9 = new TText(0.6,0.68,cc3); t9->SetNDC(); t9->SetTextSize(0.07); t9->SetTextColor(4); t9->Draw(); TText *t10= new TText(0.6,0.58,cc4); t10->SetNDC(); t10->SetTextSize(0.07); t10->SetTextColor(9); t10->Draw(); TText *t11= new TText(0.6,0.48,"OK"); t11->SetNDC(); t11->SetTextSize(0.07); t11->SetTextColor(3); t11->Draw(); TText *t12= new TText(0.8,0.15,"PedRMS"); t12->SetNDC(); t12->SetTextSize(0.07); t12->Draw(); c1->Update(); save("frac"); }
/** * Draw the Poisson estimate of the occupancy * * @param filename Input file name * @param folder Input folder name in file * * @deprecated Use QATrender instead * @ingroup pwglf_forward_scripts_qa */ void DrawOccupancy(const char* filename="forward.root", const char* folder="ForwardResults") { gStyle->SetPalette(1); gStyle->SetOptFit(0); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetTitleW(.4); gStyle->SetTitleH(.1); gStyle->SetTitleX(.4); // gStyle->SetTitleY(.1); gStyle->SetTitleColor(0); gStyle->SetTitleStyle(0); gStyle->SetTitleBorderSize(0); TFile* file = TFile::Open(filename, "READ"); if (!file) { Error("DrawOccupancy", "failed to open %s", filename); return; } TList* forward = static_cast<TList*>(file->Get(folder)); if (!forward) { Error("DrawOccupancy", "List %s not found in %s", folder, filename); return; } TList* dc = static_cast<TList*>(forward->FindObject("fmdDensityCalculator")); if (!dc) { Error("DrawOccupancy", "List fmdDensityCalculator not found in Forward"); return; } TCanvas* c = new TCanvas("occupancy", "Mean Occupancy", 900, 700); c->SetFillColor(0); c->SetBorderSize(0); c->SetBorderMode(0); c->SetHighLightColor(0); c->SetBottomMargin(.15); c->SetTopMargin(.02); c->SetRightMargin(.02); c->SetLeftMargin(.15); c->Divide(3, 2, 0, 0); Double_t corrs[5]; c->cd(1); corrs[0] = DrawRingOccupancy(dc, 1, 'I'); c->cd(2); corrs[1] = DrawRingOccupancy(dc, 2, 'I'); c->cd(5); corrs[2] = DrawRingOccupancy(dc, 2, 'O'); c->cd(3); corrs[3] = DrawRingOccupancy(dc, 3, 'I'); c->cd(6); corrs[4] = DrawRingOccupancy(dc, 3, 'O'); TVirtualPad* p = c->cd(4); p->SetTopMargin(0.05); p->SetRightMargin(0.10); p->SetLeftMargin(0.15); p->SetBottomMargin(0.15); p->SetFillColor(0); TH1D* hc = new TH1D("occ", "Mean occupancy", 5, .5, 5.5); hc->SetFillColor(kRed+1); hc->SetFillStyle(3001); hc->SetMinimum(0.0); hc->GetXaxis()->SetBinLabel(1,"FMD1i"); hc->SetBinContent(1,corrs[0]); hc->GetXaxis()->SetBinLabel(2,"FMD2i"); hc->SetBinContent(2,corrs[1]); hc->GetXaxis()->SetBinLabel(3,"FMD2o"); hc->SetBinContent(3,corrs[2]); hc->GetXaxis()->SetBinLabel(4,"FMD3i"); hc->SetBinContent(4,corrs[3]); hc->GetXaxis()->SetBinLabel(5,"FMD3o"); hc->SetBinContent(5,corrs[4]); hc->GetXaxis()->SetLabelSize(0.08); hc->GetYaxis()->SetTitle("#bar{occupancy}"); hc->SetMarkerSize(1.5); hc->Draw("text hist"); hc->SetMaximum(hc->GetMaximum()*1.5); // TH2D* highCuts = static_cast<TH2D*>(dc->FindObject("highCuts")); // if (highCuts) highCuts->Draw("colz"); c->cd(); c->SaveAs("occupancy.png"); }
void plot(char* v, int run, int cut, TCanvas* cvs, int fit=0, int bin1=-1, int bin2=-1, float ymax=0.0, int rebin=0){ int bin0=1; char c[100]; char c2[100]; readfile(OPT,run); gStyle->SetOptStat(0); gStyle->SetOptFit(0); gStyle->SetOptTitle(0); cvs->Clear(); int b1=bin1, b2=bin1+1, b3=bin2, b4=b3; if(bin1<0) {cvs->Divide(kNPtBin-bin0,kNPtBin-bin0); b1=bin0; b2=kNPtBin; b3=bin0;} float ptcut[kNPtBin+1]={0.5,1.0,1.5,2.0,2.5,3.0,10.0}; memset(PAR,0,sizeof(PAR)); TText* t; for(int i=b1; i<b2; i++){ if(bin1<0) b4=i; for(int j=b3; j<=b4; j++){ int cc=cut; if(cut==99 && (v=="m1" || v=="m2")) cc=0; if(cut==99 && v=="dphi") cc=1; TH1F *h,*h2,*h3,*h4; TH2F *h2d; //get normalizations float norm0=1.0; float norm1=1.0; float norm2=1.0; float norm3=1.0; if(v=="m0" || v=="phi0"){} else{ sprintf(c,"m0_%1d_c%d",i,cc); TH1F* h0 = (TH1F*)mTFile->Get(c); norm0 = h0->GetEntries(); sprintf(c,"m2_%1d%1d_c%d",i,j,cc); TH1F* h1 = (TH1F*)mTFile->Get(c); norm1 = h1->GetEntries(); printf("n0=%d n1=%d\n",norm0,norm1); norm2=norm1/norm0; norm3=norm2/ZggCut; } int opt=1, log=0; if(v=="mix"){ h3=mix(run,cc,i,j,0,1,h,h2); h1->SetLineColor(1); h2->SetLineColor(6); }else if(v=="corr"){ h = mix(run,cc,i,j,0,1); if(rebin>0) h->Rebin(rebin); if(fit==1) h->GetXaxis()->SetRangeUser(PI/2.0,3.0*PI/2.0); int nbin = h->GetNbinsX(); h->Sumw2(); if(run<20) {h->Scale(1.0/norm0*nbin/2.0/PI/ZggCut);} else {h->Scale(1.0/norm0*nbin/2.0/PI);} }else if(v=="norm"){ sprintf(c,"dphi_%1d%1d_c%d",i,j,cc); h = (TH1F*)mTFile->Get(c); if(rebin>0) h->Rebin(rebin); if(fit==1) h->GetXaxis()->SetRangeUser(PI/2.0,3.0*PI/2.0); int nbin = h->GetNbinsX(); h->Sumw2(); if(run<20) {h->Scale(1.0/norm0*nbin/2.0/PI/ZggCut);} else {h->Scale(1.0/norm0*nbin/2.0/PI);} }else if(v=="mall"){ sprintf(c,"m0_%1d_c%d",i,0); sprintf(c2,"m0_%1d%1d_c%d",i,j,0); h4 = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2); float norm4 = h4->Integral(h4->GetXaxis()->FindBin(MassCut0),h4->GetXaxis()->FindBin(MassCut1)); h4->Scale(norm1/norm4); h = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2); sprintf(c,"m0_%1d_c%d",i,cc); sprintf(c2,"m0_%1d%1d_c%d",i,j,cc); h = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2); h->SetLineColor(6); h->Scale(norm2); sprintf(c,"m1_%1d%1d_c%d",i,j,cc); h2 = (TH1F*)mTFile->Get(c); h2->SetLineColor(2); sprintf(c,"m2_%1d%1d_c%d",i,j,cc); h3 = (TH1F*)mTFile->Get(c); h3->SetLineColor(4); }else if(v=="z12"){ sprintf(c,"z1_%1d%1d_c%d",i,j,cc); h = (TH1F*)mTFile->Get(c); h->SetLineColor(2); sprintf(c,"z2_%1d%1d_c%d",i,j,cc); h2 = (TH1F*)mTFile->Get(c); h2->SetLineColor(4); }else if(v=="m0" || v=="phi0"){ sprintf(c,"%s_%1d_c%d",v,i,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); }else if(v=="bbce"){ opt=1; log=1; sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); h->SetMinimum(0.1); }else if(v=="phi1" || v=="phi2"){ opt=1; sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); }else if(v=="phi1dphi"){ opt=2; sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); }else{ sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); } if(bin1<0){ TVirtualPad *pad = cvs->cd((i-bin0)*(kNPtBin-bin0)+(j-bin0)+1); pad->SetRightMargin(0.01); pad->SetLeftMargin(0); pad->SetTopMargin(0); pad->SetBottomMargin(0.01); pad->Draw(); } h->SetMinimum(0.0); if(ymax>0.0) h->SetMaximum(ymax); if(opt==0) h->Draw("e"); if(opt==1) h->Draw(); if(opt==2) h->Draw("colz"); if(v=="mall"){ h4->Draw("same"); h2->Draw("same"); h3->Draw("same"); } if(v=="z12" || v=="mix") h2->Draw("same"); TF1* f; if((v=="norm" || v=="corr") && fit==1){ f=new TF1("oneGaus",oneGaus,+PI/2.0,+PI*3.0/2.0,3); f->SetParameters(norm3/10.0,norm3/2.0,0.3); f->SetParNames("Const","IntFar","SigFar"); f->SetParLimits(0,0.0,1.0); f->SetParLimits(1,0.0,1.0); f->SetParLimits(2,0.0,3.0); f->SetLineColor(2); f->SetLineWidth(1); h->Fit("oneGaus","Q"); PAR[i][j][0]=f->GetParameter(0); PAR[i][j][1]=f->GetParameter(1); PAR[i][j][2]=f->GetParameter(2); printf("norm=%8.6f Int=%8.6f IntFar=%8.6 SigFar=%6.3f C=%8.6f\n", norm3,PAR[i][j][1]+PAR[i][j][0],PAR[i][j][1],PAR[i][j][2],PAR[i][j][0]); } if((v=="norm" || v="corr") && fit==2){ f=new TF1("twoGaus",twoGaus,-PI/2.0,+PI*3.0/2.0,5); f->SetParameters(norm3/10.0,norm3/2.0,0.3,norm3/2.0,0.3); f->SetParNames("Const","IntNear","SigNear","IntFar","SigFar"); f->SetParLimits(0,0.0,1.0); f->SetParLimits(1,0.0,1.0); f->SetParLimits(2,0.0,3.0); f->SetParLimits(3,0.0,1.0); f->SetParLimits(4,0.0,3.0); f->SetLineColor(2); f->SetLineWidth(1); h->Fit("twoGaus","Q"); PAR[i][j][0]=f->GetParameter(0); PAR[i][j][1]=f->GetParameter(1); PAR[i][j][2]=f->GetParameter(2); PAR[i][j][3]=f->GetParameter(3); PAR[i][j][4]=f->GetParameter(4); printf("norm=%8.6f Int=%8.6f IntNear=%8.6f IntFar=%8.6f SigNear=%6.3f SigFar=%6.3f C=%8.6f\n", norm3,PAR[i][j][1]+PAR[i][j][3]+PAR[i][j][0],PAR[i][j][1],PAR[i][j][3], PAR[i][j][2],PAR[i][j][4],PAR[i][j][0]); } float xx=0.60, yy=0.85, dy=0.04, size=0.04; if(bin1<0){xx=0.45, yy=0.90, dy=0.08, size=0.08;} if(v=="z12") {xx=0.1; yy=0.35;} t = new TText(xx, yy, Form("pT1=%3.1f-%3.1f",ptcut[i],ptcut[i+1])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy, Form("pT2=%3.1f-%3.1f",ptcut[j],ptcut[j+1])); t->SetNDC(); t->SetTextSize(size); t->Draw(); if(norm3>0.0){ t = new TText(xx, yy-dy*2, Form("P=%7.5f",norm3)); t->SetNDC(); t->SetTextSize(size); t->Draw(); } if((v=="norm" || v="corr") && fit==1){ t = new TText(xx, yy-dy*3, Form("PBg=%7.5f", PAR[i][j][0])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*4, Form("Paway=%7.5f",PAR[i][j][1])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*5, Form("Saway=%4.2f",PAR[i][j][2])); t->SetNDC(); t->SetTextSize(size); t->Draw(); } if((v=="norm" || v="corr") && fit==2){ t = new TText(xx, yy-dy*3, Form("Pnear=%7.5f",PAR[i][j][1])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*4, Form("Paway=%7.5f",PAR[i][j][3])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*5, Form("PBg=%7.5f", PAR[i][j][0])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*6, Form("Snear=%4.2f",PAR[i][j][2])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*7, Form("Saway=%4.2f",PAR[i][j][4])); t->SetNDC(); t->SetTextSize(size); t->Draw(); } if(cut==88) h->SetLineColor(2); if(cut==99 && (v=="m1"|| v=="m2")){ sprintf(c,"%s_%1d%1d_c%d",v,i,j,1); h = (TH1F*)mTFile->Get(c); h->SetLineColor(4); h->Draw("same"); sprintf(c,"%s_%1d%1d_c%d",v,i,j,2); h = (TH1F*)mTFile->Get(c); h->SetLineColor(2); h->Draw("same"); } if(cut==99 && v=="dphi"){ h->SetLineColor(4); sprintf(c,"%s_%1d%1d_c%d",v,i,j,2); h = (TH1F*)mTFile->Get(c); h->SetLineColor(2); h->Draw("same"); } if(bin1>0){ t = new TText(0.1, 0.92,Form("%s %s",CBEAM,CCUT[cut])); t->SetNDC(); t->SetTextSize(0.07); t->SetTextColor(1); t->Draw(); if (run==1 || run==11) {sprintf(c,"plot/dipi0_pp_%s_c%d_bin%d%d.png",v,cut,i,j);} else if(run==5 || run==15) {sprintf(c,"plot/dipi0_pau1_%s_c%d_bin%d%d.png",v,cut,i,j);} else if(run==2 || run==12) {sprintf(c,"plot/dipi0_pau2_%s_c%d_bin%d%d.png",v,cut,i,j);} else if(run==3 || run==13) {sprintf(c,"plot/dipi0_pal_%s_c%d_bin%d%d.png",v,cut,i,j);} else {sprintf(c,"plot/dipi0_%d_%s_c%d_bin%d%d.png",run,v,cut,i,j);} printf("Saving %s\n",c); cvs->SaveAs(c); } } } if(bin1<0){ cvs->cd(2); t = new TText(0.0, 0.85,Form("%s %s",CBEAM,CCUT[cut])); t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(1); t->Draw(); } if(v=="mall"){ t = new TText(0.05, 0.65,"M1(no mass, scaled)"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(1); t->Draw(); t = new TText(0.05, 0.55,"M1(without M2)/P"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(6); t->Draw(); t = new TText(0.05, 0.45,"M1(with M2)"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(2); t->Draw(); t = new TText(0.05, 0.35,"M2"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(4); t->Draw(); } if(v=="z12"){ t = new TText(0.05, 0.65,"Zgg1"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(2); t->Draw(); t = new TText(0.05, 0.55,"Zgg2"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(4); t->Draw(); } if(cut==99) { t = new TText(0.0, 0.65, "Inclusive Pair"); t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(4); t->Draw(); t = new TText(0.0, 0.45, "Exclusive Pair"); t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(2); t->Draw(); } if(bin1<0){ if (run==1 || run==11) {sprintf(c,"plot/dipi0_pp_%s_c%d.png",v,cut);} else if(run==5 || run==15) {sprintf(c,"plot/dipi0_pau1_%s_c%d.png",v,cut);} else if(run==2 || run==12) {sprintf(c,"plot/dipi0_pau2_%s_c%d.png",v,cut);} else if(run==3 || run==13) {sprintf(c,"plot/dipi0_pal_%s_c%d.png",v,cut);} else {sprintf(c,"plot/dipi0_%d_%s_c%d.png",run,v,cut);} printf("Saving %s\n",c); cvs->SaveAs(c); } }
void make_v2_graphs(const char* output = "v2_inputs.root") { TFile* fout = new TFile(output,"recreate"); fout->cd(); TGraphErrors* trig_inc_v2[4]; TGraphErrors* trig_inc_sys[4]; TGraphErrors* trig_dec_v2[4]; TGraphErrors* trig_dec_sys[4]; TGraphErrors* trig_pi0_v2[4]; TGraphErrors* trig_pi0_sys[4]; TGraphErrors* hassoc_v2[4]; TGraphErrors* hassoc_sys[4]; //[centrality][pt] double inc_v2[4][4]; double inc_v2_err[4][4]; double inc_v2_sys[4][4]; double dec_v2[4][4]; double dec_v2_err[4][4]; double dec_v2_sys[4][4]; double pi0_v2[4][4]; double pi0_v2_err[4][4]; double pi0_v2_sys[4][4]; double hadron_v2[4][5]; double hadron_v2_err[4][5]; double hadron_v2_sys[4][5]; inc_v2[0][0] = 0.0423226; inc_v2_err[0][0] = 0.00175307; inc_v2_sys[0][0] = 0.0076029; inc_v2[1][0] = 0.0852710; inc_v2_err[1][0] = 0.00207489; inc_v2_sys[1][0] = 0.0179611; inc_v2[2][0] = 0.1379880; inc_v2_err[2][0] = 0.00432101; inc_v2_sys[2][0] = 0.0183026; inc_v2[3][0] = 0.4418120; inc_v2_err[3][0] = 0.01932520; inc_v2_sys[3][0] = 0.0197302; inc_v2[0][1] = 0.0461296; inc_v2_err[0][1] = 0.00454517; inc_v2_sys[0][1] = 0.00432369; inc_v2[1][1] = 0.0738878; inc_v2_err[1][1] = 0.00558803; inc_v2_sys[1][1] = 0.01509860; inc_v2[2][1] = 0.1432810; inc_v2_err[2][1] = 0.01209420; inc_v2_sys[2][1] = 0.01267580; inc_v2[3][1] = 0.5100750; inc_v2_err[3][1] = 0.05529200; inc_v2_sys[3][1] = 0.04872020; inc_v2[0][2] = 0.0398415; inc_v2_err[0][2] = 0.00836215; inc_v2_sys[0][2] = 0.00344175; inc_v2[1][2] = 0.0520371; inc_v2_err[1][2] = 0.01062420; inc_v2_sys[1][2] = 0.02247170; inc_v2[2][2] = 0.1245420; inc_v2_err[2][2] = 0.02340030; inc_v2_sys[2][2] = 0.01237760; inc_v2[3][2] = 0.4952110; inc_v2_err[3][2] = 0.11218300; inc_v2_sys[3][2] = 0.15661100; inc_v2[0][3] = 0.0169588; inc_v2_err[0][3] = 0.0189458; inc_v2_sys[0][3] = 0.00465717; inc_v2[1][3] = 0.0644017; inc_v2_err[1][3] = 0.0252076; inc_v2_sys[1][3] = 0.02599590; inc_v2[2][3] = 0.0260897; inc_v2_err[2][3] = 0.0570124; inc_v2_sys[2][3] = 0.05901420; inc_v2[3][3] = -0.299766; inc_v2_err[3][3] = 0.2958920; inc_v2_sys[3][3] = 0.79791400; pi0_v2[0][0] = 0.0835297; pi0_v2_err[0][0] = 0.00287215; pi0_v2_sys[0][0] = 0.0118235; pi0_v2[1][0] = 0.1335370; pi0_v2_err[1][0] = 0.00330527; pi0_v2_sys[1][0] = 0.0229443; pi0_v2[2][0] = 0.1744460; pi0_v2_err[2][0] = 0.00671865; pi0_v2_sys[2][0] = 0.0244753; pi0_v2[3][0] = 0.4214010; pi0_v2_err[3][0] = 0.02954310; pi0_v2_sys[3][0] = 0.0485074; pi0_v2[0][1] = 0.0755782; pi0_v2_err[0][1] = 0.00531345; pi0_v2_sys[0][1] = 0.00960588; pi0_v2[1][1] = 0.1162020; pi0_v2_err[1][1] = 0.00587208; pi0_v2_sys[1][1] = 0.02417620; pi0_v2[2][1] = 0.1548150; pi0_v2_err[2][1] = 0.01164770; pi0_v2_sys[2][1] = 0.01545110; pi0_v2[3][1] = 0.5469130; pi0_v2_err[3][1] = 0.05027790; pi0_v2_sys[3][1] = 0.03882330; pi0_v2[0][2] = 0.0839048; pi0_v2_err[0][2] = 0.01013930; pi0_v2_sys[0][2] = 0.01805810; pi0_v2[1][2] = 0.1030550; pi0_v2_err[1][2] = 0.01122400; pi0_v2_sys[1][2] = 0.03859360; pi0_v2[2][2] = 0.0801250; pi0_v2_err[2][2] = 0.05710570; pi0_v2_sys[2][2] = 0.02456170; pi0_v2[3][2] = 0.5638220; pi0_v2_err[3][2] = 0.10233000; pi0_v2_sys[3][2] = 0.02597060; pi0_v2[0][3] = 0.1055550; pi0_v2_err[0][3] = 0.0258798; pi0_v2_sys[0][3] = 0.04751440; pi0_v2[1][3] = 0.0861201; pi0_v2_err[1][3] = 0.0290550; pi0_v2_sys[1][3] = 0.02462110; pi0_v2[2][3] = 0.1169110; pi0_v2_err[2][3] = 0.0579355; pi0_v2_sys[2][3] = 0.06628670; pi0_v2[3][3] = 0.4231040; pi0_v2_err[3][3] = 0.3135600; pi0_v2_sys[3][3] = 0.25851400; dec_v2[0][0] = 0.0802729; dec_v2_err[0][0] = 0.00259655; dec_v2_sys[0][0] = 0.0106477; dec_v2[1][0] = 0.1270690; dec_v2_err[1][0] = 0.00292113; dec_v2_sys[1][0] = 0.0236515; dec_v2[2][0] = 0.1708000; dec_v2_err[2][0] = 0.00588472; dec_v2_sys[2][0] = 0.0221000; dec_v2[3][0] = 0.4716660; dec_v2_err[3][0] = 0.02824160; dec_v2_sys[3][0] = 0.0515539; dec_v2[0][1] = 0.0769908; dec_v2_err[0][1] = 0.00440387; dec_v2_sys[0][1] = 0.01112830; dec_v2[1][1] = 0.1142120; dec_v2_err[1][1] = 0.00505774; dec_v2_sys[1][1] = 0.02610160; dec_v2[2][1] = 0.1723320; dec_v2_err[2][1] = 0.01048860; dec_v2_sys[2][1] = 0.01933210; dec_v2[3][1] = 0.5762520; dec_v2_err[3][1] = 0.05424370; dec_v2_sys[3][1] = 0.04244810; //testing old v2 because 9-12 seems high //v2[2][2] = 0.242351; err_v2_pi0[2][2] = 0.0226531; sys_err_v2_pi0[2][2] = 0.0129369; dec_v2[0][2] = 0.0831338; dec_v2_err[0][2] = 0.00951379; dec_v2_sys[0][2] = 0.02080890; dec_v2[1][2] = 0.1005180; dec_v2_err[1][2] = 0.01043080; dec_v2_sys[1][2] = 0.03353270; dec_v2[2][2] = 0.2019460; dec_v2_err[2][2] = 0.02221120; dec_v2_sys[2][2] = 0.01217420; dec_v2[3][2] = 0.5698930; dec_v2_err[3][2] = 0.11125100; dec_v2_sys[3][2] = 0.03953840; dec_v2[0][3] = 0.1026670; dec_v2_err[0][3] = 0.0238731; dec_v2_sys[0][3] = 0.03616490; dec_v2[1][3] = 0.0893677; dec_v2_err[1][3] = 0.0271222; dec_v2_sys[1][3] = 0.03356940; dec_v2[2][3] = 0.1307690; dec_v2_err[2][3] = 0.0609939; dec_v2_sys[2][3] = 0.07152490; dec_v2[3][3] = 0.3373860; dec_v2_err[3][3] = 0.2751690; dec_v2_sys[3][3] = 0.37330200; hadron_v2[0][4]=0.0440219; hadron_v2_err[0][4]=0.000145508; hadron_v2_sys[0][4]=0.00137609; hadron_v2[1][4]=0.0826719; hadron_v2_err[1][4]=0.000171826; hadron_v2_sys[1][4]=0.00296920; hadron_v2[2][4]=0.0980676; hadron_v2_err[2][4]=0.000408317; hadron_v2_sys[2][4]=0.00221491; hadron_v2[3][4]=0.0868451; hadron_v2_err[3][4]=0.001215900; hadron_v2_sys[3][4]=0.00435710; hadron_v2[0][0]=0.0745276; hadron_v2_err[0][0]=7.62922e-05; hadron_v2_sys[0][0]=0.00202200; hadron_v2[1][0]=0.1381520; hadron_v2_err[1][0]=8.20737e-05; hadron_v2_sys[1][0]=0.00419830; hadron_v2[2][0]=0.1646640; hadron_v2_err[2][0]=0.000219383; hadron_v2_sys[2][0]=0.00260620; hadron_v2[3][0]=0.1693740; hadron_v2_err[3][0]=0.001336240; hadron_v2_sys[3][0]=0.00693613; hadron_v2[0][1]=0.1095070; hadron_v2_err[0][1]=0.000216781; hadron_v2_sys[0][1]=0.00307190; hadron_v2[1][1]=0.1933760; hadron_v2_err[1][1]=0.000249992; hadron_v2_sys[1][1]=0.00579030; hadron_v2[2][1]=0.2177190; hadron_v2_err[2][1]=0.000623148; hadron_v2_sys[2][1]=0.00315090; hadron_v2[3][1]=0.2150790; hadron_v2_err[3][1]=0.003462490; hadron_v2_sys[3][1]=0.00682347; hadron_v2[0][2]=0.1103720; hadron_v2_err[0][2]=0.000591522; hadron_v2_sys[0][2]=0.00322900; hadron_v2[1][2]=0.1907190; hadron_v2_err[1][2]=0.000680041; hadron_v2_sys[1][2]=0.00616680; hadron_v2[2][2]=0.2077700; hadron_v2_err[2][2]=0.001614320; hadron_v2_sys[2][2]=0.00375637; hadron_v2[3][2]=0.2052480; hadron_v2_err[3][2]=0.008518280; hadron_v2_sys[3][2]=0.01208620; hadron_v2[0][3]=0.0827500; hadron_v2_err[0][3]=0.00844; hadron_v2_sys[0][3]=0.00500; hadron_v2[1][3]=0.1297000; hadron_v2_err[1][3]=0.01350; hadron_v2_sys[1][3]=0.00830; hadron_v2[2][3]=0.1718000; hadron_v2_err[2][3]=0.01718; hadron_v2_sys[2][3]=0.00858; hadron_v2[3][3]=0.2052480; hadron_v2_err[3][3]=8.52e-4; hadron_v2_sys[3][3]=0.05*hadron_v2[3][4]; double pt_trig[4] = {5.5,7.5,9.5,12.5}; double pt_trig_err[4] = {0,0,0,0}; double pt_assoc[5] = {0.6,1.3,2.3,3.5,5.5}; double pt_assoc_err[5] = {0,0,0,0,0}; std::ostringstream name; for( int i = 0; i < 4; i++ ) { name.str(""); name << "gamma_inc_v2_" << i; trig_inc_v2[i] = new TGraphErrors(4,pt_trig,inc_v2[i],pt_trig_err,inc_v2_err[i]); trig_inc_v2[i]->SetName(name.str().c_str()); trig_inc_v2[i]->SetTitle(name.str().c_str()); trig_inc_v2[i]->Write(); name.str(""); name << "gamma_inc_v2sys_" << i; trig_inc_sys[i] = new TGraphErrors(4,pt_trig,inc_v2[i],pt_trig_err,inc_v2_sys[i]); trig_inc_sys[i]->SetName(name.str().c_str()); trig_inc_sys[i]->SetTitle(name.str().c_str()); trig_inc_sys[i]->Write(); name.str(""); name << "gamma_dec_v2_" << i; trig_dec_v2[i] = new TGraphErrors(4,pt_trig,dec_v2[i],pt_trig_err,dec_v2_err[i]); trig_dec_v2[i]->SetName(name.str().c_str()); trig_dec_v2[i]->SetTitle(name.str().c_str()); trig_dec_v2[i]->Write(); name.str(""); name << "gamma_dec_v2sys_" << i; trig_dec_sys[i] = new TGraphErrors(4,pt_trig,dec_v2[i],pt_trig_err,dec_v2_sys[i]); trig_dec_sys[i]->SetName(name.str().c_str()); trig_dec_sys[i]->SetTitle(name.str().c_str()); trig_dec_sys[i]->Write(); name.str(""); name << "pi0_v2_" << i; trig_pi0_v2[i] = new TGraphErrors(4,pt_trig,pi0_v2[i],pt_trig_err,pi0_v2_err[i]); trig_pi0_v2[i]->SetName(name.str().c_str()); trig_pi0_v2[i]->SetTitle(name.str().c_str()); trig_pi0_v2[i]->Write(); name.str(""); name << "pi0_v2sys_" << i; trig_pi0_sys[i] = new TGraphErrors(4,pt_trig,pi0_v2[i],pt_trig_err,pi0_v2_sys[i]); trig_pi0_sys[i]->SetName(name.str().c_str()); trig_pi0_sys[i]->SetTitle(name.str().c_str()); trig_pi0_sys[i]->Write(); name.str(""); name << "hadron_v2_" << i; hassoc_v2[i] = new TGraphErrors(5,pt_assoc,hadron_v2[i],pt_assoc_err,hadron_v2_err[i]); hassoc_v2[i]->SetName(name.str().c_str()); hassoc_v2[i]->SetTitle(name.str().c_str()); hassoc_v2[i]->Write(); name.str(""); name << "hadron_v2sys_" << i; hassoc_sys[i] = new TGraphErrors(5,pt_assoc,hadron_v2[i],pt_assoc_err,hadron_v2_sys[i]); hassoc_sys[i]->SetName(name.str().c_str()); hassoc_sys[i]->SetTitle(name.str().c_str()); hassoc_sys[i]->Write(); } int cent[5] = {0,20,40,60,90}; int color[4] = {kBlack,kRed,kBlue,kViolet-7}; int sys_color[4] = {kGray,kRed-9,kBlue-9,kViolet-9}; TCanvas* can = new TCanvas("can","can"); can->Divide(2,2,0.001,0.001); TH1D* thisto = new TH1D("thisto",";p^{#gamma}_{T} ;v_{2} ",100,0.0,15.0); thisto->SetAxisRange(0.0,0.75,"Y"); thisto->SetAxisRange(4.5,14.0,"X"); TH1D* ahisto = new TH1D("ahisto",";p^{h}_{T} ;v_{2} ",100,0.0,15.0); ahisto->SetAxisRange(0.0,0.75,"Y"); ahisto->SetAxisRange(0.0,6.0,"X"); for( int i = 0; i < 4; i++ ) { TVirtualPad* pad = can->cd(i+1); pad->SetRightMargin(0.01); pad->SetTopMargin(0.01); if( i < 3 ) thisto->Draw(); else ahisto->Draw(); } TLegend* leg = new TLegend(0.5,0.5,0.9,0.9); leg->SetBorderSize(0); leg->SetFillColor(0); for( int ic = 0; ic < 4; ic++ ) { can->cd(1); trig_inc_sys[ic]->SetMarkerSize(0); trig_inc_sys[ic]->SetLineWidth(10); trig_inc_sys[ic]->SetLineColor(sys_color[ic]); trig_inc_sys[ic]->Draw("E1,Psame"); trig_inc_v2[ic]->SetMarkerColor(color[ic]); trig_inc_v2[ic]->SetLineColor(color[ic]); trig_inc_v2[ic]->Draw("Psame"); // trig_inc_v2[ic]->Write(); // trig_inc_sys[ic]->Write(); can->cd(2); trig_dec_sys[ic]->SetMarkerSize(0); trig_dec_sys[ic]->SetLineWidth(10); trig_dec_sys[ic]->SetLineColor(sys_color[ic]); trig_dec_sys[ic]->Draw("E1,Psame"); trig_dec_v2[ic]->SetMarkerColor(color[ic]); trig_dec_v2[ic]->SetLineColor(color[ic]); trig_dec_v2[ic]->Draw("Psame"); can->cd(3); trig_pi0_sys[ic]->SetMarkerSize(0); trig_pi0_sys[ic]->SetLineWidth(10); trig_pi0_sys[ic]->SetLineColor(sys_color[ic]); trig_pi0_sys[ic]->Draw("E1,Psame"); trig_pi0_v2[ic]->SetMarkerColor(color[ic]); trig_pi0_v2[ic]->SetLineColor(color[ic]); trig_pi0_v2[ic]->Draw("Psame"); can->cd(4); hassoc_sys[ic]->SetMarkerSize(0); hassoc_sys[ic]->SetLineWidth(10); hassoc_sys[ic]->SetLineColor(sys_color[ic]); hassoc_sys[ic]->Draw("E1,Psame"); hassoc_v2[ic]->SetMarkerColor(color[ic]); hassoc_v2[ic]->SetLineColor(color[ic]); hassoc_v2[ic]->Draw("Psame"); name.str(""); name << cent[ic] << " - " << cent[ic+1] << "%"; leg->AddEntry(trig_inc_v2[ic],name.str().c_str(),"P"); } leg->Draw(); can->Write(); }
void EstimateBg_76X(bool save=0, std::string in = "", std::string out = "/afs/cern.ch/user/j/jkarancs/public/NOTES/notes/AN-14-290/trunk/Plots/v1.0/", std::string ext="png") { gStyle->SetOptTitle(0); gStyle->SetOptStat(0); bool latex = save; bool ABCD_prime = 0; bool TT_only = 0; std::stringstream ss, ss2; ss<<DPHI_CUT; ss2<<R_CUT; std::string dphi_cut = ss.str().replace(ss.str().find("."),1,"p"); std::string r_cut = ss2.str().replace(ss2.str().find("."),1,"p"); std::string filename = in.size() ? in : //"results/Plotter_out_2016_05_31_08h48m57_replot.root"; "results/Plotter_out_2016_06_24_14h28m51.root"; std::vector<std::string> samples[4]; //samples[0].push_back("TTJetsMGHT"); //samples[0].push_back("TTJetsMG"); //samples[0].push_back("TTJetsNLOFXFX"); //samples[0].push_back("TTNLO"); //samples[0].push_back("TTNLOHerwig"); //samples[0].push_back("TTPowheg"); //samples[0].push_back("TTPowhegmpiOff"); //samples[0].push_back("TTPowhegnoCR"); //samples[0].push_back("TTPowhegHerwig"); //+data+ samples[1].push_back("SingleElectron"); //+data+ samples[1].push_back("SingleMuon"); if (TT_only) { samples[1].push_back("TTJetsMGHT"); samples[1].push_back("TTJetsMG"); samples[1].push_back("TTJetsNLOFXFX"); samples[1].push_back("TTNLO"); samples[1].push_back("TTNLOHerwig"); samples[1].push_back("TTPowheg"); samples[1].push_back("TTPowhegmpiOFF"); samples[1].push_back("TTPowhegnoCR"); samples[1].push_back("TTPowhegHerwig"); } else { samples[1].push_back("TTJetsMGHT"); //samples[1].push_back("TTJetsMG"); //samples[1].push_back("TTJetsNLOFXFX"); //samples[1].push_back("TTNLO"); //samples[1].push_back("TTNLOHerwig"); //samples[1].push_back("TTPowheg"); //samples[1].push_back("TTPowhegmpiOff"); //samples[1].push_back("TTPowhegnoCR"); //samples[1].push_back("TTPowhegHerwig"); samples[1].push_back("ZJets"); samples[1].push_back("TTX"); samples[1].push_back("WJets"); samples[1].push_back("Diboson"); samples[1].push_back("Top"); samples[1].push_back("QCD"); //ZERO samples[1].push_back("TZQ"); //ZERO samples[1].push_back("ZJetsToQQ"); // Also WJetsToQQ //ZERO samples[1].push_back("GJets"); } //samples[1].push_back("Data"); // NTop Sideband All background summed samples[2].push_back("All Bkg."); // Signal in NTop bins samples[3].push_back("T1tttt"); bool baderror = false; double weight[] = { 0.32686, 0.0505037, 0.00921411, 6.80717, 0.354934, 0.00484915 }; int rebin = /*(R_CUT*10-int(R_CUT*10))==0 ? 10 :*/ (R_CUT*20-int(R_CUT*20))==0 ? 5 : (R_CUT*50-int(R_CUT*50))==0 ? 2 : 1; double sideband_fit_low_range[] = { 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15 }; int i_h_side[] = { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int i_h_signal[] = { 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; double scale_factors[] = { 1, 1, 1, 1, 1, 1, 1}; // All normal //double scale_factors[] = { /* TT */ 1, /* W */ 1, /* Z */ 1, /* T */ 1, /* TTV */ 1, /* QCD */ 2, /* VV */ 1 }; // QCD high //double scale_factors[] = { /* TT */ 5, /* W */ 1, /* Z */ 1, /* T */ 1, /* TTV */ 5, /* QCD */ 1, /* VV */ 1 }; // TT/TTV high //double scale_factors[] = { /* TT */ 1, /* W */ 2, /* Z */ 2, /* T */ 2, /* TTV */ 1, /* QCD */ 1, /* VV */ 2 }; // T/V/VV high Double_t Rranges_ABCD[][4] = { { DPHI_CUT, 3.2, 0.0, DPHI_CUT }, { R_CUT_LOW-1e-10, R_CUT, R_CUT-1e-10, 1.20 }, { R_CUT_LOW-1e-10, R_CUT, R_CUT-1e-10, 1.20 }, { R_CUT_LOW-1e-10, R_CUT, R_CUT-1e-10, 1.20 } }; bool doFitting = false; double sum_a = 0, sum_b = 0, sum_c = 0, sum_d = 0, sum_d_abcd = 0, sum_d_nevt = 0; double sum_a_err = 0, sum_b_err = 0, sum_c_err = 0, sum_d_err = 0, sum_d_abcd_err = 0; double sum_b_fit = 0, sum_d_fit = 0, sum_d_fit_comb = 0; double sum_b_fit_err = 0, sum_d_fit_err = 0, sum_d_fit_comb_err = 0; double comb_d = 0, comb_d_err = 0, comb_d_abcd = 0, comb_d_abcd_err = 0; if (latex) { printf("\\begin{table*}[htbH]\n"); printf("\\small\n"); printf("\\begin{center}\n"); printf("\\topcaption{Estimated Standard Model background yields in ABCD regions. A, B is in the sideband, C and D is the signal band, D is the signal region.\\label{tab:SMBkgEstimate}}\n"); printf("\\begin{tabular}{lrrrrrrrr}\n"); } TFile *f = TFile::Open(filename.c_str()); for (size_t iMethod = 0; iMethod<4; ++iMethod) if (!(iMethod==0&&samples[0].size()==0)){ // Print Top row for each method if (latex) { if (iMethod==0) { printf("\\hline\n"); printf("Method 2 & A & B & C & D = B*C/A & D obs. & Ratio pred./obs. & Pull & KS test\\\\\n"); } else if (iMethod==1){ printf("\\hline\n"); printf("Method 1 & A & B & C & D = B*C/A & D obs. & Ratio pred./obs. & Pull & KS test\\\\\n"); } printf("\\hline\n"); } else { std::stringstream r_sb_cut; if (R_CUT_LOW==0) r_sb_cut<<"R<"<<R_CUT; else r_sb_cut<<R_CUT_LOW<<"<R<"<<R_CUT; const char* prime = ABCD_prime ? "'" : ""; //if (iMethod==0) printf("| *Sample* | *A (DPhi>2.8, SB)* | *B (DPhi<2.8, SB)* | *C (DPhi>2.8, Sig.B.)* | - | *D = B*C/A pred.* | *D (DPhi<2.8, Sig.B.) obs.* | *Ratio pred./obs.* |\n"); //else if (iMethod==1) printf("| *Sample* | *A (R<%1.1f, SB)* | *B (R>%1.1f, SB)* | *C (R<%1.1f, Sig.B.)* | *D = B (R fit, SB) * C/A pred.* | *D = B*C/A pred.* | *D (R>%1.1f, Sig.B.) obs.* | *Ratio pred./obs.* | \n", R_CUT, R_CUT, R_CUT, R_CUT); if (iMethod==0) printf("| *Sample* | *A (DPhi>%1.1f, %s)* | *B (DPhi<%1.1f, %s)* | *C (DPhi>%1.1f, R>0.4)* | *D = B*C/A pred.* | *D (DPhi<%1.1f, R>0.4) obs.* | *Ratio pred./obs.* | *Pull (pred-obs)/error* | *KS test* |\n", DPHI_CUT, r_sb_cut.str().c_str(), DPHI_CUT, r_sb_cut.str().c_str(), DPHI_CUT, DPHI_CUT); else if (iMethod==1) printf("| *Sample* | *A%s (%s, <2 tag)* | *B%s (R>%1.1f, <2 tag)* | *C%s (%s, 2 tag)* | *D%s = B%s*C%s/A%s pred.* | *D%s (R>%1.1f, 2 tag) obs.* | *Ratio pred./obs.* | *Pull (pred-obs)/error* | *KS test* |\n", prime, r_sb_cut.str().c_str(), prime, R_CUT, prime, r_sb_cut.str().c_str(), prime, prime, prime, prime, prime, R_CUT); } TH1D *h_side_sum, *h_signal_sum; for (size_t iSample = 0; iSample<samples[iMethod].size(); ++iSample) { std::string canname = iMethod==0 ? std::string("DPhiBins")+(ABCD_prime ? "/RBins_0To1HadTop_" : "/RBins_2HadTop_")+samples[iMethod][iSample] : iMethod==1 ? std::string("RFine/Tau32Cuts_")+(ABCD_prime ? "Fail" : "Pass")+"DPhiCut_"+samples[iMethod][iSample] : iMethod==2 ? std::string("RFine/Tau32Cuts_")+(ABCD_prime ? "Fail" : "Pass")+"DPhiCut_Background" : iMethod==3 ? std::string("RFine/Tau32Cuts_")+(ABCD_prime ? "Fail" : "Pass")+"DPhiCut_"+samples[iMethod][iSample] : ""; TCanvas *can = (TCanvas*)(f->Get(canname.c_str())); can = (TCanvas*)can->Clone(); can->Draw(); TH1D *h_side = (TH1D*)can->GetListOfPrimitives()->At(i_h_side[iMethod]); TH1D *h_signal = (TH1D*)can->GetListOfPrimitives()->At(i_h_signal[iMethod]); // Simulate different cross section by scaling a certain background if (iMethod==1) { TH1D *h_side_temp_scaled = (TH1D*)h_side->Clone(); h_side_temp_scaled->Scale(scale_factors[iSample]); TH1D *h_signal_temp_scaled = (TH1D*)h_signal->Clone(); h_signal_temp_scaled->Scale(scale_factors[iSample]); if (iSample==0) { h_side_sum = h_side_temp_scaled; h_signal_sum = h_signal_temp_scaled; } else { h_side_sum->Add(h_side_temp_scaled); h_signal_sum->Add(h_signal_temp_scaled); } } else if (iMethod==2) { h_side = h_side_sum; h_signal = h_signal_sum; } TH1D *h_pred =(TH1D*)h_side->Clone(); if (iMethod!=0&&rebin>1) { h_side->Rebin(rebin); h_signal->Rebin(rebin); h_pred->Rebin(rebin); } TLegend *leg = (TLegend*)can->GetListOfPrimitives()->At(can->GetListOfPrimitives()->GetEntries()-1); leg->SetX1(0.35); leg->SetX2(0.65); leg->SetY1(0.6); // Add ratio plot int y1 = 350; int y2 = 150; int mid2 = 10; can->Divide(1,2); // Pad 1 (80+500+20 x 40+500) TVirtualPad* p = can->cd(1); p->SetPad(0,(y2+60+mid2)/(y1+y2+100.0+mid2),1,1); p->SetTopMargin(40.0/(y1+40)); p->SetBottomMargin(0); p->SetRightMargin(0.05); p->SetLogy(1); h_side->GetYaxis()->SetRangeUser(1.00001e-4,1e4); h_side->Draw("HIST"); h_signal->Draw("SAMEHISTE1"); leg->Draw(); // Pad 2 (80+500+20 x 200+60) p = can->cd(2); p->SetGrid(0,1); p->SetPad(0,0,1,(y2+60+mid2)/(y1+y2+100.0+mid2)); p->SetTopMargin(((float)mid2)/(y2+60+mid2)); p->SetBottomMargin(60.0/(y2+60+mid2)); p->SetRightMargin(0.05); TH1D* ratio = (TH1D*)h_signal->Clone(); TH1D* div = (TH1D*)h_side->Clone(); //ratio->Scale(1/ratio->GetSumOfWeights()); double sum_bins_ratio = iMethod==0 ? ratio->Integral(): ratio->Integral(ratio->FindBin(R_CUT_LOW),ratio->FindBin(Rranges_ABCD[iMethod][3])); ratio->Scale(1/sum_bins_ratio); ratio->SetTitleSize(32.0/(y2+60+mid2),"xyz"); ratio->SetLabelSize(20.0/(y2+60+mid2),"xyz"); //ratio->Scale(1/div->GetSumOfWeights()); double sum_bins_div = iMethod==0 ? div->Integral(): div->Integral(div->FindBin(R_CUT_LOW),div->FindBin(Rranges_ABCD[iMethod][3])); div->Scale(1/sum_bins_div); ratio->Divide(div); //ratio->GetYaxis()->SetRangeUser(0,2); ratio->GetXaxis()->SetTitleOffset(0.7); ratio->GetYaxis()->SetNdivisions(305); ratio->GetYaxis()->SetTitle("Ratio (Norm.)"); ratio->GetYaxis()->SetTitleOffset(0.4); ratio->SetTitleSize(24.0/(y2+60+mid2),"y"); ratio->SetTitle(""); ratio->SetMarkerStyle(20); ratio->SetMarkerColor(1); ratio->SetLineColor(1); ratio->GetYaxis()->SetRangeUser(0,4); ratio->Draw("PE1"); TLine* l = new TLine(ratio->GetXaxis()->GetXmin(), 1, ratio->GetXaxis()->GetXmax(), 1); l->SetLineWidth(2); //l->SetLineColor(2); l->SetLineStyle(2); l->Draw(); gPad->Update(); // Fit ratio //TF1 *fit_ratio; //if (iMethod==1) { // fit_ratio = new TF1("fit_ratio","pol0", Rranges_ABCD[iMethod][0], Rranges_ABCD[iMethod][1]); // fit_ratio->SetLineColor(1); // ratio->Fit("fit_ratio","RE"); // fit_ratio->SetRange(Rranges_ABCD[iMethod][0], Rranges_ABCD[iMethod][2]); // fit_ratio->Draw("SAME"); //} p = can->cd(1); // calculate integrals double integral[2][2] = { { 0, 0 }, { 0, 0 } }; double integral_error[2][2] = { { 0, 0 }, { 0, 0 } }; double nevt[2][2] = { { 0, 0 }, { 0, 0 } }; //std::cout<<samples[iMethod][iSample]<<":"<<std::endl; for (int i=0; i<2; ++i) { for (int bin=1; bin<=h_side->GetNbinsX(); ++bin) { if (h_signal->GetXaxis()->GetBinLowEdge(bin)>=Rranges_ABCD[iMethod][i*2] && h_signal->GetXaxis()->GetBinUpEdge(bin)<=Rranges_ABCD[iMethod][i*2+1]) { //std::cout<<bin<<"="<<h_side->GetBinCenter(bin); //if (i==0) std::cout<<" in, "; //else std::cout<<" out, "; double c0 = h_side->GetBinContent(bin), c1 = h_signal->GetBinContent(bin); double e0 = h_side->GetBinError(bin), e1 = h_signal->GetBinError(bin); //std::cout<<h_signal->GetBinError(bin)<<" "<<sqrt(c1*weight[iSample])<<std::endl; if (baderror&&iMethod==1) { e0 = sqrt(c0*weight[iSample]); e1 = sqrt(c1*weight[iSample]); } nevt[0][i] += (int)(c0*c0/(e0*e0) + 0.5); nevt[1][i] += (int)(c1*c1/(e1*e1) + 0.5); integral[0][i] += c0; integral[1][i] += c1; //if (iMethod==1) { // weight bin by projected ratio (correction) // double bincent = h_signal->GetXaxis()->GetBinLowEdge(bin); // integral[0][1] *= fit_ratio->Eval(bincent); //} integral_error[0][i] += e0*e0; integral_error[1][i] += e1*e1; //if (iSample==0&&e1>0) std::cout<<bin<<" "<<c1<<" +- "<<e1*e1<<" nevt = "<<((int)(c1*c1/(e1*e1) + 0.5))<<std::endl; } } //if (iSample==1&&i==1) std::cout<<integral[1][i]<<" +- "<<integral_error[1][i]<<std::endl; integral_error[0][i] = sqrt(integral_error[0][i]); integral_error[1][i] = sqrt(integral_error[1][i]); } //std::cout<<nevt[1][1]<<std::endl; // predict yields using 2 methods (ABCD and constrained R-shape fit method combined) // ABCD method double a = integral[0][0], b = integral[0][1], c = integral[1][0], d = integral[1][1]; double a_err = integral_error[0][0], b_err = integral_error[0][1], c_err = integral_error[1][0], d_err = integral_error[1][1]; // Calculate error // z = x / y -> z_err = sqrt( (x*x*y_err*y_err + y*y*x_err*x_err)/(y*y*y*y) ) // z = x * y -> z_err = sqrt ( x*x*y_err*y_err + y*y*x_err*x_err ) double c_per_a_err = sqrt((c*c*a_err*a_err + a*a*c_err*c_err)/(a*a*a*a)); double d_abcd = b * (c/a), d_abcd_err = sqrt(b*b*c_per_a_err*c_per_a_err + (c/a)*(c/a)*b_err*b_err); double d_nevt = nevt[1][1]; double d_ratio = d_abcd / d; double d_ratio_err = sqrt((d_err/d)*(d_err/d) + (d_abcd_err/d_abcd)*(d_abcd_err/d_abcd))*d_ratio; double d_pull = (d_abcd-d)/sqrt(d_abcd_err*d_abcd_err + d_err*d_err); // Scaled plot h_pred->Scale(c/a); h_pred->SetLineColor(1); h_pred->SetLineStyle(2); h_pred->Draw("SAMEHIST"); leg->AddEntry(h_pred, "Prediction (ABCD)", "l"); double fit_integral[2][2], fit_integral_error[2][2], d_fit_comb = 0, d_fit_comb_err = 0; if (iMethod==1) { // Fit in the full range of NTop Sideband // Do fitting and calculate integrals TF1 *fit_side = new TF1("NTopSide_fit","exp([0]+[1]*x)", iMethod==2 ? 0.2 : sideband_fit_low_range[iSample], Rranges_ABCD[iMethod][3]); fit_side->SetLineColor(h_side->GetLineColor()); h_side->Fit("NTopSide_fit","QRE"); //fit_side->Draw("SAME"); double Rranges_ACfit[3] = { sideband_fit_low_range[iSample], Rranges_ABCD[iMethod][2], Rranges_ABCD[iMethod][3] }; for (int i=0; i<2; ++i) { fit_integral[0][i] = fit_side->Integral(Rranges_ACfit[i], Rranges_ACfit[i+1])/h_signal->GetXaxis()->GetBinWidth(1); fit_integral_error[0][i] = fit_side->IntegralError(Rranges_ACfit[i], Rranges_ACfit[i+1])/h_signal->GetXaxis()->GetBinWidth(1); } double par0 = fit_side->GetParameter(0), par0_error = fit_side->GetParError(0); double par1 = fit_side->GetParameter(1), par1_error = fit_side->GetParError(1); double par1min, par1max; fit_side->GetParLimits(1, par1min, par1max); // Fit in the Signal region // Fitting in sideband, get B area under curve and scale by C/A TF1 *fit_signal = new TF1("NTopSignal_RSide_fit","exp([0]+[1]*x)", Rranges_ACfit[0], Rranges_ABCD[iMethod][3]); fit_signal->SetLineColor(h_signal->GetLineColor()); //fit_signal->SetParameter(1, par1); //fit_signal->SetParLimits(1, par1min, par1max); h_signal->Fit("NTopSignal_RSide_fit","QREB"); //fit_signal->Draw("SAME"); for (int i=0; i<2; ++i) { fit_integral[1][i] = fit_signal->Integral(Rranges_ACfit[i], Rranges_ACfit[i+1])/h_signal->GetXaxis()->GetBinWidth(1); fit_integral_error[1][i] = fit_signal->IntegralError(Rranges_ACfit[i], Rranges_ACfit[i+1])/h_signal->GetXaxis()->GetBinWidth(1); } d_fit_comb = fit_integral[0][1] * (c/a); d_fit_comb_err = sqrt(fit_integral[0][1]*fit_integral[0][1]*c_per_a_err*c_per_a_err + (c/a)*(c/a)*fit_integral_error[0][1]*fit_integral_error[0][1]); TF1 *fit_pred = new TF1("Predicted_fit","exp([0]+[1]*x)", Rranges_ACfit[0], Rranges_ACfit[2]); fit_pred->SetLineColor(1); fit_pred->SetLineStyle(2); fit_pred->FixParameter(0, par0+std::log(c/a)); fit_pred->FixParameter(1, par1); h_signal->Fit("Predicted_fit","QREB+"); //fit_pred->Draw("SAME"); } // Save plot if (iMethod==3) samples[iMethod][iSample] = "T1tttt"; std::string name = samples[iMethod][iSample]; if (iMethod==2) name = "AllBkg"; if (save) can->SaveAs((out+"BkgEst/ABCD_closure_"+name+"."+ext).c_str()); // Check compatibility of prediction to observed distribution double ks_test = h_pred->KolmogorovTest(h_signal); if (iMethod==1) { sum_a += a; sum_b += b; sum_c += c; sum_d += d; sum_a_err += a_err*a_err; sum_b_err += b_err*b_err; sum_c_err += c_err*c_err; sum_d_err += d_err*d_err; sum_d_abcd += d_abcd; sum_d_abcd_err += d_abcd_err*d_abcd_err; sum_b_fit += fit_integral[0][1]; sum_b_fit_err += fit_integral_error[0][1]*fit_integral_error[0][1]; sum_d_fit += fit_integral[1][1]; sum_d_fit_err += fit_integral_error[1][1]*fit_integral_error[1][1]; sum_d_fit_comb += d_fit_comb; sum_d_fit_comb_err += d_fit_comb_err*d_fit_comb_err; sum_d_nevt += d_nevt; //printf(" %.2f +- %.2f | %.2f +- %.2f | %.2f +- %.2f | %.2f +- %.2f |\n", d_fit_comb, d_fit_comb_err, d_abcd, d_abcd_err, d, d_err, d_ratio, d_ratio_err); } if (latex) { printf("%s & $%.2f \\pm %.2f$ & $%.2f \\pm %.2f$ & $%.2f \\pm %.2f$ &", samples[iMethod][iSample].c_str(), a, a_err, b, b_err, c, c_err); printf(" $%.2f \\pm %.2f$ & $%.2f \\pm %.2f$ & $%.2f \\pm %.2f$ & %.2f & %.2f \\\\\n", d_abcd, d_abcd_err, d, d_err, d_ratio, d_ratio_err, d_pull, ks_test); } else { printf("| %s | %.2f +- %.2f | %.2f +- %.2f | %.2f +- %.2f |", samples[iMethod][iSample].c_str(), a, a_err, b, b_err, c, c_err); printf(" %.2f +- %.2f | %.2f +- %.2f | %.2f +- %.2f | %.2f | %.2f |\n", d_abcd, d_abcd_err, d, d_err, d_ratio, d_ratio_err, d_pull, ks_test); } // Combining best methods if ((iMethod==0&&iSample==0)||(iMethod==1&&iSample!=0)) { comb_d_abcd += d_abcd; comb_d += d; comb_d_abcd_err += d_abcd_err*d_abcd_err; comb_d_err += d_err*d_err; } } if (iMethod==1) { sum_a_err = sqrt(sum_a_err); sum_b_err = sqrt(sum_b_err); sum_c_err = sqrt(sum_c_err); sum_d_err = sqrt(sum_d_err); sum_b_fit_err = sqrt(sum_b_fit_err); sum_d_fit_err = sqrt(sum_d_fit_err); sum_d_fit_comb_err = sqrt(sum_d_fit_comb_err); double sum_d_ratio = sum_d_abcd / sum_d; double sum_d_ratio_err = sqrt((sum_d_err/sum_d)*(sum_d_err/sum_d) + (sum_d_abcd_err/sum_d_abcd)*(sum_d_abcd_err/sum_d_abcd))*sum_d_ratio; double sum_d_pull = (sum_d_abcd-sum_d)/sqrt(sum_d_abcd_err*sum_d_abcd_err + sum_d_err*sum_d_err); if (latex) { printf("\\hline\n"); printf("Sum Bkg. & $%.2f \\pm %.2f$ & $%.2f \\pm %.2f$ & $%.2f \\pm %.2f$ &", sum_a, sum_a_err, sum_b, sum_b_err, sum_c, sum_c_err); printf(" $%.2f \\pm %.2f$ & $%.2f \\pm %.2f$ & $%.2f \\pm %.2f$ & %.2f & \\\\\n", sum_d_abcd, sum_d_abcd_err, sum_d, sum_d_err, sum_d_ratio, sum_d_ratio_err, sum_d_pull); } else { //printf("| Sum Bkg.| %.2f +- %.2f | %.2f +- %.2f | %.2f +- %.2f | %.2f +- %.2f |", sum_a, sum_a_err, sum_b_fit, sum_b_fit_err, sum_b, sum_b_err, sum_c, sum_c_err); printf("| Sum Bkg.| %.2f +- %.2f | %.2f +- %.2f | %.2f +- %.2f |", sum_a, sum_a_err, sum_b, sum_b_err, sum_c, sum_c_err); //printf(" %.2f +- %.2f | %.2f +- %.2f | %.2f +- %.2f | %.2f +- %.2f |\n", sum_d_fit_comb, sum_d_fit_comb_err, sum_d_abcd, sum_d_abcd_err, sum_d, sum_d_err, sum_d_ratio, sum_d_ratio_err); printf(" %.2f +- %.2f | %.2f +- %.2f | %.2f +- %.2f | %.2f | - |\n", sum_d_abcd, sum_d_abcd_err, sum_d, sum_d_err, sum_d_ratio, sum_d_ratio_err, sum_d_pull); } } else if (iMethod==2&&samples[0].size()) { double comb_d_ratio = comb_d_abcd / comb_d; double comb_d_ratio_err = sqrt((comb_d_err/comb_d)*(comb_d_err/comb_d) + (comb_d_abcd_err/comb_d_abcd)*(comb_d_abcd_err/comb_d_abcd))*comb_d_ratio; double comb_d_pull = (comb_d_abcd-comb_d)/sqrt(comb_d_abcd_err*comb_d_abcd_err + comb_d_err*comb_d_err); if (latex) { printf("\\hline\n"); printf("\\hline\n"); printf("Combined Bkg. & & & & $%.2f \\pm %.2f$ & $%.2f \\pm %.2f$ & $%.2f \\pm %.2f$ & %.2f & \\\\\n", comb_d_abcd, comb_d_abcd_err, comb_d, comb_d_err, comb_d_ratio, comb_d_ratio_err, comb_d_pull); printf("\\hline\n"); } else { printf("| Combined Bkg.| | | | %.2f +- %.2f | %.2f +- %.2f | %.2f +- %.2f | %.2f | - |\n", comb_d_abcd, comb_d_abcd_err, comb_d, comb_d_err, comb_d_ratio, comb_d_ratio_err, comb_d_pull); } } } if (latex) { printf("\\hline\n"); printf("\\end{tabular}\n"); printf("\\end{center}\n"); printf("\\end{table*}\n"); } if (save) gApplication->Terminate(); }
void DrawTwoInPad(TVirtualPad* p, Int_t sub, TH1* h1, TH1* h2, Bool_t ratio, Bool_t logy=false, Bool_t legend=false) { TVirtualPad* pp = p->cd(sub); pp->SetRightMargin(0.02); pp->SetLeftMargin(0.10); TVirtualPad* ppp = pp; if (ratio) { pp->Divide(1,2,0,0); ppp = pp->cd(1); ppp->SetRightMargin(0.02); } if (logy) ppp->SetLogy(); TH1* hs[] = { h1, h2, 0 }; if (h1->GetMaximum() < h2->GetMaximum()) { hs[0] = h2; hs[1] = h1; } TH1** ph = hs; Double_t size = (ratio ? 0.1 : 0.05); Double_t off = (ratio ? 0.6 : 0.5); h1->SetFillStyle(3004); h2->SetFillStyle(3005); while (*ph) { TString opt("hist"); if (ph != hs) opt.Append(" same"); TH1* copy = (*ph)->DrawCopy(opt); copy->GetXaxis()->SetLabelSize(2*size); copy->GetYaxis()->SetLabelSize(size); copy->GetYaxis()->SetTitleSize(size); copy->GetYaxis()->SetTitleOffset(off); copy->SetYTitle(copy->GetTitle()); copy->SetTitle(""); copy->SetDirectory(0); ph++; } TString s1 = h1->GetYaxis()->GetTitle(); TString s2 = h2->GetYaxis()->GetTitle(); if (legend) { TLegend* l = new TLegend(0.6, 0.1, 0.9, 0.9); l->SetBorderSize(0); TLegendEntry* e = l->AddEntry("dummy", s1, "lf"); l->SetFillColor(kWhite); e->SetFillColor(kBlack); e->SetFillStyle(h1->GetFillStyle()); e = l->AddEntry("dummy", s2, "lf"); e->SetFillColor(kBlack); e->SetFillStyle(h2->GetFillStyle()); l->Draw(); } if (!ratio) return; ppp = pp->cd(2); ppp->SetRightMargin(0.02); TH1* r = static_cast<TH1*>(h1->Clone(Form("ratio%s", h1->GetName()))); r->SetDirectory(0); r->SetTitle(""); r->GetXaxis()->SetLabelSize(size); r->GetYaxis()->SetLabelSize(size); r->GetYaxis()->SetTitleSize(0.9*size); r->GetYaxis()->SetTitleOffset(0.9*off); r->SetMarkerStyle(20); r->SetMarkerColor(h1->GetFillColor()+1); r->SetFillStyle(3007); r->SetYTitle(Form("#frac{%s}{%s}", s1.Data(), s2.Data())); // r->Add(h2, -1); // r->Divide(h1); if (!r->IsA()->InheritsFrom(TProfile::Class())) { r->GetSumw2()->Set(0); // r->Sumw2(false); h2->GetSumw2()->Set(0); // h2->Sumw2(false); } r->Divide(h2); Printf("%s", r->GetName()); for (UShort_t bin = 1; bin <= r->GetNbinsX(); bin++) { Printf(" bin # %2d: Diff=%g+/-%g", bin, r->GetBinContent(bin), r->GetBinError(bin)); r->SetBinError(bin, 0); } r->GetSumw2()->Set(0); //r->Sumw2(false); r->SetMarkerSize(4); r->SetMaximum(r->GetMaximum()*1.2); r->SetMinimum(r->GetMinimum()*0.8); r->Draw("hist text30"); p->Modified(); p->Update(); p->cd(); }