void ptDependence() { TFile *inf = new TFile("histos/ppMC.root"); TTree *t = (TTree*) inf->Get("nt"); const int nBins = 4; double ptBin[nBins+1] = {100,120,140,160,200}; // const int nBins = 1; // double ptBin[nBins+1] = {100,400}; TH1D *hProb = new TH1D("hProb","",nBins,ptBin); TH1D *hCSV = new TH1D("hCSV","",nBins,ptBin); TH1D *hSVTXM = new TH1D("hSVTXM","",nBins,ptBin); TProfile *pGen = new TProfile("pGen","",nBins,ptBin); for (int n=0; n<nBins;n++) { RooRealVar f1 = bfractionFit("discr_prob",0,3.5,ptBin[n],ptBin[n+1]); RooRealVar f2 = bfractionFit("discr_csvSimple",0,1,ptBin[n],ptBin[n+1]); RooRealVar f3 = bfractionFit("svtxm",0,6,ptBin[n],ptBin[n+1]); hProb->SetBinContent(n+1,f1.getVal()); hProb->SetBinError(n+1,f1.getError()); hCSV->SetBinContent(n+1,f2.getVal()); hCSV->SetBinError(n+1,f2.getError()); hSVTXM->SetBinContent(n+1,f3.getVal()); hSVTXM->SetBinError(n+1,f3.getError()); } TCanvas *c2 = new TCanvas("c2","",600,600); hProb->SetAxisRange(0,0.05,"Y"); hProb->SetXTitle("Jet p_{T} (GeV/c)"); hProb->SetYTitle("b-jet fraction"); hProb->SetTitleOffset(1.5,"Y"); hProb->Draw(); hCSV->SetLineColor(2); hCSV->SetMarkerColor(2); hCSV->SetMarkerStyle(24); hCSV->Draw("same"); hSVTXM->SetLineColor(4); hSVTXM->SetMarkerColor(4); hSVTXM->SetMarkerStyle(24); // hSVTXM->Draw("same"); t->Draw("abs(refparton_flavorForB)==5:jtpt","","prof same"); TLegend *leg = new TLegend(0.2,0.7,0.5,0.9); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->SetFillColor(0); leg->AddEntry(hProb,"Jet Probability","pl"); leg->AddEntry(hCSV,"CSV","pl"); // leg->AddEntry(hSVTXM,"SV mass","pl"); leg->Draw(); }
// Draw 1D histos TH1D *plot1Dhisto(double intLumi,TFile *fileName,TString folderName,TString histoName,int color,int rebin,float xMin,float xMax,TString xName, TString yName,TString sampleName,bool mc) { TH1D *hTemp = (TH1D*)fileName->Get(folderName+"/"+histoName); hTemp->SetName(histoName+"_"+sampleName); if (mc){ hTemp->Scale(intLumi/100.); } hTemp->Rebin(rebin); hTemp->SetLineColor(color); hTemp->SetLineWidth(5); hTemp->GetXaxis()->SetRangeUser(xMin,xMax); hTemp->GetXaxis()->SetTitle(xName); hTemp->GetXaxis()->SetTitleSize(0.06); hTemp->GetXaxis()->SetLabelSize(0.06); hTemp->GetYaxis()->SetTitle(yName); hTemp->GetYaxis()->SetTitleSize(0.06); hTemp->GetYaxis()->SetLabelSize(0.06); hTemp->SetTitleOffset(1.5, "Y"); // last/first bin: put over/underflow hTemp->SetBinContent(hTemp->FindBin(xMax),hTemp->Integral(hTemp->FindBin(xMax),hTemp->GetNbinsX()+1)); hTemp->SetBinContent(hTemp->FindBin(xMin),hTemp->Integral(-1,hTemp->FindBin(xMin))); hTemp->SetBinError(hTemp->FindBin(xMax),sqrt(hTemp->Integral(hTemp->FindBin(xMax),hTemp->GetNbinsX()+1))); hTemp->SetBinError(hTemp->FindBin(xMin),sqrt(hTemp->Integral(-1,hTemp->FindBin(xMin)))); //fileName->Close(); /* if (histoName != "LP_tot") { if (histoName != "SumLepPt_tot") { if ((folderName == "ANplots150_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,300.); } if ((folderName == "ANplots250_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,400.); } if ((folderName == "ANplots350_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,500.); } if ((folderName == "ANplots450_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,1000.); } } else { if ((folderName == "ANplots150_NOLP")) { hTemp->GetXaxis()->SetRangeUser(100.,300.); } if ((folderName == "ANplots250_NOLP")) { hTemp->GetXaxis()->SetRangeUser(200.,400.); } if ((folderName == "ANplots350_NOLP")) { hTemp->GetXaxis()->SetRangeUser(300.,500.); } if ((folderName == "ANplots450_NOLP")) { hTemp->GetXaxis()->SetRangeUser(400.,1000.); } } } */ return hTemp; } // ~ end of plot1Dhisto function
void doControlPlotsMET(){ setTDRStyle(); gROOT->SetBatch(); gStyle->SetErrorX(0.5); //loop over variables for(int i = 0; i<N; i++){ double MinX = MinXs[i]; double MaxX = MaxXs[i]; Variable = Variables[i]; TString Xtitle = XTitles[i]; int RebinFact = RebinFacts[i]; //Data TH1D* data; if(Obj == "MuMu/") data = getSample("DoubleMu", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); if(Obj == "EE/") data = getSample("DoubleElectron", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); if(Obj == "EMu/") data = getSample("MuEG", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); //MC TH1D* ttgamma = getSample("TTGamma", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); //this to get all ttbar TH1D* tt; TH1D* tt_lep; TH1D* tt_sig; if(inclTop == false){ //fake ttgamma tt = getSample("TTJet", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut, "fake"); tt_lep = getSample("TTJet", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut, "lep"); tt_sig = getSample("TTJet", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut, "sig"); }else{ tt = getSample("TTJet", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); } TH1D* wjets = getSample("WJetsToLNu", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* DY1 = getSample("DYJetsToLL_M-10To50", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* DY2 = getSample("DYJetsToLL_M-50", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* T_tW = getSample("T_tW-channel", 1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* Tbar_tW = getSample("Tbar_tW-channel",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* ZZ = getSample("ZZtoAnything",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* WW = getSample("WWtoAnything",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* WZ = getSample("WZtoAnything",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); //QCD TH1D* QCD_Pt_20_30_BCtoE = getSample("QCD_Pt_20_30_BCtoE",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* QCD_Pt_20_30_EMEnriched = getSample("QCD_Pt_20_30_EMEnriched",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); //TH1D* QCD_Pt_20_MuEnrichedPt_15 = getSample("QCD_Pt_20_MuEnrichedPt_15",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* QCD_Pt_30_80_BCtoE = getSample("QCD_Pt_30_80_BCtoE",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* QCD_Pt_30_80_EMEnriched = getSample("QCD_Pt_30_80_EMEnriched",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* QCD_Pt_80_170_BCtoE = getSample("QCD_Pt_80_170_BCtoE",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* QCD_Pt_80_170_EMEnriched = getSample("QCD_Pt_80_170_EMEnriched",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); TH1D* QCD_all = getSample("QCD_Pt_20_MuEnrichedPt_15",1, Obj, RefSelection, Type, Next, Variable, RebinFact, Systematic, Cut); QCD_all->Add(QCD_Pt_20_30_BCtoE); QCD_all->Add(QCD_Pt_20_30_EMEnriched); QCD_all->Add(QCD_Pt_30_80_BCtoE); QCD_all->Add(QCD_Pt_30_80_EMEnriched); QCD_all->Add(QCD_Pt_80_170_BCtoE); QCD_all->Add(QCD_Pt_80_170_EMEnriched); TH1D* allMC = (TH1D*)ttgamma->Clone("ratio"); allMC->Add(tt); if(inclTop == false){ allMC->Add(tt_lep); allMC->Add(tt_sig); } allMC->Add(wjets); allMC->Add(DY1); allMC->Add(DY2); allMC->Add(T_tW); allMC->Add(Tbar_tW); allMC->Add(ZZ); allMC->Add(WW); allMC->Add(WZ); allMC->Add(QCD_all); allMC->SetFillColor(kBlack); allMC->SetFillStyle(3354); allMC->SetMarkerSize(0.); allMC->SetStats(0); THStack *hs = new THStack("hs","test"); hs->Add(QCD_all); hs->Add(wjets); hs->Add(WZ); hs->Add(WW); hs->Add(ZZ); hs->Add(DY1); hs->Add(DY2); hs->Add(T_tW); hs->Add(Tbar_tW); hs->Add(tt); if(inclTop == false){ hs->Add(tt_lep); hs->Add(tt_sig); } hs->Add(ttgamma); std::cout << "Total number of events" << std::endl; std::cout << "Data: " << data->Integral() << std::endl; std::cout << "ttbar + gamma: " << ttgamma->Integral() << std::endl; std::cout << "Inclusive ttbar: " << tt->Integral() << std::endl; std::cout << "W+Jets: " << wjets->Integral() << std::endl; std::cout << "Drell-Yan1: " << DY1->Integral() << std::endl; std::cout << "Drell-Yan2: " << DY2->Integral() << std::endl; std::cout << "Single top: " << T_tW->Integral() << std::endl; std::cout << "Anti-Single top: " << Tbar_tW->Integral() << std::endl; std::cout << "ZZ: " << ZZ->Integral() << std::endl; std::cout << "WW: " << WW->Integral() << std::endl; std::cout << "WZ: " << WZ->Integral() << std::endl; std::cout << "QCD: " << QCD_all->Integral() << std::endl; //draw histos to files TCanvas *c1 = new TCanvas("Plot","Plot",900, 600); TPad *pad1 = new TPad("pad1","pad1",0,0.3,1,1); pad1->SetBottomMargin(0); pad1->Draw(); pad1->cd(); data->Draw("e x0"); data->SetAxisRange(MinX, MaxX, "X"); hs->Draw("hist"); allMC->Draw("same e2"); hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3); data->Draw("E same"); data->SetMarkerStyle(20); hs->GetXaxis()->SetLimits(MinX, MaxX); hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05); hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05); TLegend *tleg2; tleg2 = new TLegend(0.7, 0.6, 0.8, 0.9); tleg2->SetTextSize(0.04); tleg2->SetBorderSize(0); tleg2->SetFillColor(10); tleg2->AddEntry(data , "2012 data", "lpe"); tleg2->AddEntry(ttgamma , "t#bar{t}#gamma", "lf"); if(inclTop == false){ tleg2->AddEntry(tt_sig , "t#bar{t}#gamma (MG)", "lf"); tleg2->AddEntry(tt_lep , "t#bar{t} l #rightarrow #gamma (MG)", "lf"); tleg2->AddEntry(tt , "t#bar{t} fake (MG)", "lf"); }else{ tleg2->AddEntry(tt , "t#bar{t}", "lf"); } tleg2->AddEntry(T_tW, "Single Top" , "lf"); // tleg2->AddEntry(Tbar_tW, "anti-single-tW" , "lf"); tleg2->AddEntry(DY1 , "Z+Jets", "lf"); // tleg2->AddEntry(DY2 , "DYJetsToLL", "lf"); tleg2->AddEntry(ZZ, "Diboson", "lf"); // tleg2->AddEntry(WW, "WW", "lf"); // tleg2->AddEntry(WZ , "WZ", "lf"); tleg2->AddEntry(wjets , "W+Jets", "lf"); tleg2->AddEntry(QCD_all, "QCD", "lf"); tleg2->Draw("same"); TText* textPrelim = doPrelim(0.20, 0.96, Cut, Obj); textPrelim->Draw(); c1->cd(); if(logPlot == true){ c1->SetLogy(); } TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3); pad2->SetTopMargin(0); pad2->SetBottomMargin(0.4); pad2->Draw(); pad2->cd(); TH1D * ratio = (TH1D*)data->Clone("ratio plot"); //ratio->Sumw2(); ratio->SetStats(0); ratio->Divide(allMC); ratio->SetMinimum(0); ratio->SetMaximum(2); ratio->SetFillColor(kBlack); ratio->SetFillStyle(3354); ratio->SetMarkerSize(0.); cout << "width: " << ratio->GetBinWidth(1) << std::endl; if(MaxX <= 0.1){ ratio->SetAxisRange(MinX, MaxX); }else{ ratio->SetAxisRange(MinX, MaxX-ratio->GetBinWidth(1)); } ratio->SetLabelSize(0.1, "X"); ratio->SetTitleOffset(0.5, "Y"); ratio->GetYaxis()->SetTitle("data/MC");ratio->GetYaxis()->SetTitleSize(0.1); ratio->GetXaxis()->SetTitle(Xtitle);ratio->GetXaxis()->SetTitleSize(0.15); ratio->Draw("ep"); TLine *line; if(MaxX <= 0.1){ line = new TLine(MinX,1,MaxX,1); }else{ line = new TLine(MinX,1,MaxX-ratio->GetBinWidth(1),1); } line->Draw(); TString plotName("plots/Control/"+ Obj + Cut + Type + Next ); if(logPlot == true){ plotName += Variable+"ge1b_Log.pdf"; }else{ plotName += Variable+"ge1b"; } c1->SaveAs(plotName+".pdf"); c1->SaveAs(plotName+".png"); delete c1; } }
TCanvas *drawRatioPlot(TH1D *prediction, TH1D *sr, TH1D *data, TString xTitle, TString filename, double ecaloCut){ gStyle -> SetPadLeftMargin(0.20); data->SetMarkerStyle(20); data->SetMarkerColor(kGreen); data->SetLineColor(kGreen); TCanvas *c = new TCanvas("c"+filename,"c",0,0,500,500); float y = 0.3; TPad *pad1 = new TPad("pad1", "Control Plots 1", 0.01, y, 0.99, 0.99); TPad *padRatio = new TPad("rp1", "Ratio1", 0.01, 0.01, 0.99, y-0.01); pad1->SetNumber(100); pad1->SetTicks(0,1); cout<<"number pad1 = "<<pad1->GetNumber()<<endl; cout<<"number padRatio = "<<padRatio->GetNumber()<<endl; TH1D *ratio = 0; //ratio = (TH1D*) sr->Clone(); //ratio->Divide(prediction); ratio = (TH1D*) prediction->Clone(); ratio->Divide(data); for(int i=1; i<=ratio->GetNbinsX();i++){ if(ratio->GetBinContent(i) != 0){ cout<<"N in CR in "<<i<<". bin ="<<prediction->GetBinContent(i)<<endl; cout<<"N in SR in "<<i<<". bin ="<<sr->GetBinContent(i)<<endl; cout<<"Rel. difference in "<<i<<". bin ="<<(1./ratio->GetBinContent(i)-1.)*100<<"%"<<endl; } else if(sr->GetBinContent(i) == 0 && prediction->GetBinContent(i) !=0) cout<<"Scaling Factor in "<<i<<". bin <"<<prediction->GetBinContent(i)/1.15<<" +/- "<<ratio->GetBinError(i)<<endl; else if(sr->GetBinContent(i) != 0 && prediction->GetBinContent(i) ==0) cout<<"Scaling Factor in "<<i<<". bin <"<<(sr->GetEntries()/prediction->GetEntries())/sr->GetBinContent(i)<<" +/- "<<ratio->GetBinError(i)<<endl; } ratio->GetYaxis()->SetTitle("#frac{CR (MC)}{CR (data)}"); ratio->SetTitle(""); ratio->SetLabelSize(0.1,"X"); ratio->SetLabelSize(0.1,"Y"); ratio->SetTitleOffset(0.5,"Y"); ratio->SetTitleSize(0.15,"Y"); padRatio->cd(); //ratio->GetYaxis()->SetRangeUser(0,2); ratio->Draw("e"); // Draw line at one! float xmin = ratio->GetXaxis()->GetXmin(); float xmax = ratio->GetXaxis()->GetXmax(); TLine *line = new TLine(xmin,1,xmax,1); line->SetLineWidth(2); line->Draw("same"); padRatio->Modified(); TLegend *leg = new TLegend(0.5,0.7,0.9,0.9); leg->AddEntry(sr,"SR (MC)","l"); leg->AddEntry(prediction,"lepton CR (MC)","pel"); pad1->cd(); pad1->SetLogy(); // pad1->SetLogx(); sr->SetLineColor(kRed); sr->SetMarkerColor(kRed); sr->SetMarkerStyle(20); sr->SetTitle(""); prediction->SetMarkerStyle(20); prediction->SetTitle(""); prediction->GetXaxis()->SetTitle(xTitle); sr->GetXaxis()->SetTitle(xTitle); prediction->SetTitleSize(0.07,"X"); prediction->GetXaxis()->SetTitleOffset(0.7); sr->SetTitleSize(0.07,"X"); sr->GetXaxis()->SetTitleOffset(0.7); double maximum = 0; double minimum = 1000000; if(sr->GetMinimum()!=0 && sr->GetMinimum()<minimum){ minimum=sr->GetMinimum()*0.5; } if(prediction->GetMinimum()!=0 && prediction->GetMinimum()<minimum){ minimum=prediction->GetMinimum()*0.5; } if(data->GetMinimum()!=0 && data->GetMinimum()<minimum){ minimum=data->GetMinimum()*0.5; } if(sr->GetMaximum()>maximum){ maximum=sr->GetMaximum()*2.5; } if(prediction->GetMaximum()>maximum){ maximum=prediction->GetMaximum()*2.5; } if(data->GetMaximum()>maximum){ maximum=data->GetMaximum()*2.5; } prediction->GetYaxis()->SetRangeUser(minimum,maximum); ratio->GetYaxis()->SetRangeUser(0,2); prediction->Draw("e"); sr->Draw("e same"); leg->AddEntry(data,"lepton CR (data)","pel"); data->Draw("e same"); leg->Draw("same"); TLatex* info1 = new TLatex(); info1->SetTextFont(132); info1-> SetNDC(); info1->SetTextSize(0.06); info1->DrawLatex(0.55,0.62,Form("E_{calo}<%.0fGeV",ecaloCut)); // Draw both pads to canvas c->cd(); pad1->Draw(); padRatio->SetGridy(); padRatio->Draw(); c->SaveAs(filename); return c; }
void plot(TString var, TString varlatex, TString varname, Int_t nbins, Double_t vmin, Double_t vmax) { cout<<"---- Processing - "<<var<<endl; cout<<" -- Fill histograms"<<endl; TFile* ifBkg = new TFile(infnameBkg[isChannel]); TTree* ntBkg = (TTree*)ifBkg->Get(texNtuple[isChannel]); ntBkg->AddFriend("ntHlt"); TFile* ifSgl = new TFile(infnameSgl[isChannel]); TTree* ntSgl = (TTree*)ifSgl->Get(texNtuple[isChannel]); ntSgl->AddFriend("ntHlt"); ntSgl->AddFriend("ntHi"); TH1D* hBkg = new TH1D(Form("hBkg_%s",varname.Data()),"",nbins,vmin,vmax); TH1D* hSgl = new TH1D(Form("hSgl_%s",varname.Data()),"",nbins,vmin,vmax); ntBkg->Project(Form("hBkg_%s",varname.Data()),var,Form("%s&&%s",selTriggerBkg[isChannel].Data(),selBkg[isChannel].Data())); ntSgl->Project(Form("hSgl_%s",varname.Data()),var,TCut(weight[isChannel])*Form("%s&&%s",selTriggerSgl[isChannel].Data(),selSgl[isChannel].Data())); cout<<" -- Calculate normalization"<<endl; Double_t normBkg=0,normSgl=0; //normBkg = hBkg->GetEntries(); //normSgl = hSgl->GetEntries(); normBkg = hBkg->Integral(vmin,vmax); normSgl = hSgl->Integral(vmin,vmax); cout<<" normBkg: "<<normBkg<<" ; normSgl: "<<normSgl<<endl; cout<<" -- Normalize histograms"<<endl; hBkg->Scale(1./normBkg); hSgl->Scale(1./normSgl); cout<<" -- Plot"<<endl; hBkg->SetXTitle(varlatex); hBkg->SetYTitle("#Probability"); hBkg->SetTitleOffset(1.5,"Y"); Double_t hisMax = (hBkg->GetMaximum()>hSgl->GetMaximum())?hBkg->GetMaximum():hSgl->GetMaximum(); hBkg->SetMaximum(hisMax*1.2); hBkg->SetLineColor(kBlue+1); hBkg->SetFillStyle(1001); hBkg->SetFillColor(kBlue-9); hBkg->SetLineWidth(3); hBkg->SetStats(0); TH1D* hSglplot = new TH1D(Form("hSglplot_%s",varname.Data()),"",nbins,vmin,vmax); for(int ib=0;ib<nbins;ib++) hSglplot->SetBinContent(ib+1,hSgl->GetBinContent(ib+1)); hSglplot->SetLineColor(kRed); hSglplot->SetFillStyle(3004); hSglplot->SetFillColor(kRed); hSglplot->SetLineWidth(3); hSglplot->SetStats(0); TCanvas* c = new TCanvas(Form("c_%s",varname.Data()),"",600,600); hBkg->Draw(); hSglplot->Draw("same"); cout<<" -- Plot legends"<<endl; TLatex* tex = new TLatex(0.18,0.935,Form("5.02TeV %s",texPP[isChannel].Data())); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.055); tex->Draw(); TLatex* texp; texp = new TLatex(0.68,0.935,texDecay[isChannel]); texp->SetNDC(); texp->SetTextFont(42); texp->SetTextSize(0.055); texp->Draw(); TLegend* leg = new TLegend(0.56,0.70,0.86,0.86); leg->AddEntry(hBkg,"Background","f"); leg->AddEntry(hSglplot,"Signal","f"); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->Draw("same"); cout<<" -- Save plots"<<endl; c->SaveAs(Form("plots/%s_%s/c_%s.pdf",texPP[isChannel].Data(),texNtuple[isChannel].Data(),varname.Data())); cout<<endl; }
void dimuonLoop(float ptmin, float ptmax, float ymin, float ymax, int i) { TFile *infData = new TFile(inputdata); TFile *infMC = new TFile(inputmc); TTree *ntData = (TTree*) infData->Get("ntKp"); TTree *ntMC = (TTree*) infMC->Get("ntKp"); TCanvas *c = new TCanvas(Form("c%i",i),"",600,600); //if (logy) c->SetLogy(); TH1D* hData = new TH1D("hData","",50,2.85,3.35); TH1D* hMC = new TH1D("hMC","",50,2.85,3.35); ntData->Project("hData","mumumass",Form("%s&&(pt>%f&&pt<%f)&&(y>%f&&y<%f)",cut.Data(),ptmin,ptmax,ymin,ymax)); ntMC->Project("hMC","mumumass",Form("%s&&(pt>%f&&pt<%f)&&(y>%f&&y<%f)",cut.Data(),ptmin,ptmax,ymin,ymax)); hData->Sumw2(); double normData=0,normMC=0; normData = hData->GetEntries(); normMC = hMC->GetEntries(); cout<<normData<<" "<<normMC<<endl; hData->Scale(1./normData); hMC->Scale(1./normMC); hData->Sumw2(); hMC->SetXTitle("#mu#mu mass"); hMC->SetYTitle("#Probability"); hMC->SetTitleOffset(1.5,"Y"); if(hData->GetMaximum()>hMC->GetMaximum()) hMC->SetMaximum(hData->GetMaximum()*1.1); else hMC->SetMaximum(hMC->GetMaximum()*1.1); //hData->SetLineColor(kBlue+1); //hData->SetFillStyle(1001); //hData->SetFillColor(kBlue-9); //hData->SetLineWidth(3); hData->SetMarkerStyle(8); hData->SetStats(0); hMC->SetLineColor(kRed); hMC->SetFillStyle(3004); hMC->SetFillColor(kRed); hMC->SetLineWidth(3); hMC->SetStats(0); hMC->Draw(); hData->Draw("same lep"); TLegend *leg = new TLegend(0.11,0.75,0.50,0.9); leg->AddEntry(hData,"data","lep"); leg->AddEntry(hMC,"MC","f"); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->Draw("same"); TLegend *leg1 = new TLegend(0.60,0.7,0.90,0.9); leg1->AddEntry((TObject*)0,Form("%s",particle.Data()),""); leg1->AddEntry((TObject*)0,Form("%.0f<p_{T}<%.0f GeV",ptmin,ptmax),""); leg1->AddEntry((TObject*)0,Form("%.1f<y_{CM}<%.1f",ymin,ymax),""); leg1->SetBorderSize(0); leg1->SetFillStyle(0); leg1->Draw("same"); c->SaveAs(Form("MuonResult/plot_Bplus_chi2_trkPt/dimuon_yDM_%i.pdf",i)); //c->SaveAs(Form("MuonResult/plot_Bplus_chi2_trkPt/dimuon_DM_%i.pdf",i)); //c->SaveAs("MuonResult/plot_Bplus_chi2_trkPt/dimuon_DM_incl_1.pdf"); }
//################################################################################################################################ //################################################################################################################################ //################################################################################################################################ TCanvas *drawRatioPlot(TH1D *prediction, TH1D *sr, TString xTitle, TString filename){ TCanvas *c = new TCanvas("c"+filename,"c",0,0,500,500); c->cd(); float y = 0.3; TPad *pad1 = new TPad("pad1", "Control Plots 1", 0.01, y, 0.99, 0.99); TPad *padRatio = new TPad("rp1", "Ratio1", 0.01, 0.01, 0.99, y-0.01); TH1D *ratio = 0; ratio = (TH1D*) sr->Clone(); ratio->Divide(prediction); ratio->GetYaxis()->SetTitle((TString) sr->GetName() + "/" + (TString) prediction->GetName()); ratio->SetTitle(""); ratio->SetLabelSize(0.1,"X"); ratio->SetLabelSize(0.1,"Y"); ratio->SetTitleOffset(0.5,"Y"); ratio->SetTitleSize(0.15,"Y"); padRatio->cd(); ratio->GetYaxis()->SetRangeUser(0,2); ratio->Draw(); // Draw line at one! float xmin = ratio->GetXaxis()->GetXmin(); float xmax = ratio->GetXaxis()->GetXmax(); TLine *line = new TLine(xmin,1,xmax,1); line->SetLineWidth(2); line->Draw("same"); padRatio->Modified(); TLegend *leg = new TLegend(0.6,0.8,0.9,0.9); leg->AddEntry(sr,"bkg","l"); leg->AddEntry(prediction,prediction->GetName(),"pel"); pad1->cd(); //pad1->SetLogy(); sr->SetLineColor(kRed); sr->SetMarkerColor(kRed); sr->SetTitle(""); prediction->SetTitle(""); prediction->GetXaxis()->SetTitle(xTitle); sr->GetXaxis()->SetTitle(xTitle); prediction->SetTitleSize(0.07,"X"); prediction->GetXaxis()->SetTitleOffset(0.7); sr->SetTitleSize(0.07,"X"); sr->GetXaxis()->SetTitleOffset(0.7); prediction->Draw("e"); sr->Draw("e same"); if(sr->GetMaximum()>prediction->GetMaximum()){ sr->Draw("e"); prediction->Draw("e same"); } leg->Draw("same"); // Draw both pads to canvas c->cd(); pad1->Draw(); padRatio->SetGridy(); padRatio->Draw(); c->SaveAs(filename); return c; }
void compareDataStackMC(std::string histoName, std::string inputFile="inputFile.txt", bool update=false, double xmin=-9999.0, double xmax=-9999.0,int rebin=1) { //--------------------------------------------------------------------------- // read in the MC root files //--------------------------------------------------------------------------- std::string mcName[]= { "Dimuon Data", "DY+jets", "t#bar{t} +jets", "WW", "WZ" }; std::string leptonName="test"; double lumi =5000; if(inputFile.find("electron")!= std::string::npos) { leptonName="electron"; lumi = 5200.7; mcName[0]="DiElectron Data"; } else if(inputFile.find("muon")!= std::string::npos) { leptonName="muon"; lumi = 5204.7; } cout << "Data luminosity = " << lumi << endl; std::vector<MCFile> myMCFiles; std::string dataFile; FILE *fTable = fopen(inputFile.data(),"r"); int flag=1; while (flag!=-1) { // first reading input file char filename[500]; flag=fscanf(fTable,"%s",filename); char tmp[1000]; // read in x-section flag=fscanf(fTable,"%s",tmp); double cross=atof(tmp); // read in number of events flag=fscanf(fTable,"%s",tmp); double nevt=atof(tmp); double scale =lumi*cross/nevt; MCFile tempMCfile; tempMCfile.filename = filename; tempMCfile.scaleFactor = scale; if(flag!=-1 && cross>1e-6) { myMCFiles.push_back(tempMCfile); cout << tempMCfile.filename << "\t" << tempMCfile.scaleFactor << endl; } else if(flag!=-1) // is data { dataFile = filename; } } const unsigned int nfiles = myMCFiles.size(); cout << "Data file = " << dataFile << endl; cout << "Reading " << nfiles << " files" << endl; if(nfiles==0) { cout << "There is no file for me to process!" << endl; return; } //------------------------------------------------------------------------------- // Declaring histograms to be used //------------------------------------------------------------------------------- // local histograms THStack *hs = new THStack(Form("%s_stack",histoName.data()),""); // for local debugging TH1D* h_deno[nfiles]; int COLORCODE[]= { kRed-7, kRed-10, kRed-6, kMagenta-2, kMagenta-6, kBlue-7, kBlue-9 }; cout << "opening " << myMCFiles[0].filename << endl; TFile *f1 = TFile::Open(myMCFiles[0].filename.data()); TH1D* h_template = (TH1D*)(f1->Get(Form("%s",histoName.data()))); h_template->Reset(); TH1D* h_all = (TH1D*)h_template->Clone(Form("%s_all",histoName.data())); h_all -> Reset(); TFile *fdata = TFile::Open(dataFile.data()); TH1D* h_data= (TH1D*)(fdata->Get(Form("%s",histoName.data()))); h_data-> SetName(Form("%s_data",histoName.data())); h_data->Draw(); //------------------------------------------------------------------------------- // combine //------------------------------------------------------------------------------- for(int ifile=nfiles-1; ifile>=0; ifile--) { cout << "File " << ifile << endl; TFile *f_temp = TFile::Open(myMCFiles[ifile].filename.data()); cout << "opening " << myMCFiles[ifile].filename << endl; h_deno[ifile] = (TH1D*)(f_temp->Get(Form("%s",histoName.data()))); h_deno[ifile] -> SetName(Form("h_deno_%d",ifile)); h_deno[ifile] -> SetTitle(f_temp->GetName()); h_deno[ifile] -> Rebin(rebin); h_deno[ifile] -> SetLineColor(COLORCODE[ifile]); h_deno[ifile] -> SetFillColor(COLORCODE[ifile]); h_deno[ifile] -> SetFillStyle(1001); h_deno[ifile] -> SetMarkerColor(COLORCODE[ifile]); h_deno[ifile] -> Sumw2(); double weight = myMCFiles[ifile].scaleFactor; h_deno[ifile] -> Scale(weight); if(ifile==nfiles-1) { h_all -> Rebin(rebin); h_all -> Sumw2(); } h_all -> Add(h_deno[ifile]); hs -> Add(h_deno[ifile]); // to be used with TEfficiency methods cout << h_deno[ifile]->GetEntries() << endl; } // end of loop over files float x1NDC = 0.620968; float y1NDC = 0.684322; float x2NDC = 0.762097; float y2NDC = 0.898305; TLegend* leg = new TLegend(x1NDC,y1NDC,x2NDC,y2NDC); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetTextSize(0.04); leg->SetBorderSize(0); leg->AddEntry(h_data,mcName[0].data()); for(int i=0; i < nfiles; i++) leg->AddEntry(h_deno[i], mcName[i+1].data()); int maxBin = h_data->GetMaximumBin(); double max = h_data->GetMaximum()+h_data->GetBinError(maxBin); double maxmc = hs->GetMaximum(); if(maxmc>max)max=maxmc; h_data->SetMaximum(1.1*max); TCanvas* c1 = new TCanvas("c1",inputFile.data(),0,0,500,500); h_data->SetMarkerSize(1); h_data->SetMarkerStyle(24); h_data->SetTitle(""); h_data->Draw("e"); if(xmin>-9999 && xmax>-9999) { h_data->GetXaxis()->SetRangeUser(xmin,xmax); } cout << "Data integral = " << h_data->Integral() << endl; hs->Draw("histsame"); h_data->Draw("esame"); leg->Draw("same"); std::string dirName = "compareDataMC_" + leptonName; gSystem->mkdir(dirName.data()); std::string filename; std::string psname ; psname = dirName+ "/overlay_" + histoName; filename = psname + ".eps"; c1->Print(filename.data()); filename = psname + ".gif"; c1->Print(filename.data()); filename = psname + ".pdf"; c1->Print(filename.data()); // study the ratios TCanvas* c2 = new TCanvas("c2","",700,0,700,1000); c2->Divide(1,2,0.01,0); c2->cd(1); gPad->SetTopMargin(0.01); gPad->SetBottomMargin(0); gPad->SetRightMargin(0.04); h_data->Draw("e"); if(xmin>-9999 && xmax>-9999) { h_data->GetXaxis()->SetRangeUser(xmin,xmax); } cout << h_data->GetName() << " integral = " << h_data->Integral() << endl; hs->Draw("histsame"); h_data->Draw("esame"); leg->Draw("same"); c2->cd(2); gStyle->SetStatW (0.3); gStyle->SetStatH (0.3); gStyle->SetStatX (0.879447); gStyle->SetStatY (0.939033); gStyle->SetStatFontSize(0.05); gStyle->SetStatBorderSize(0); gPad->SetRightMargin(0.04); gPad->SetTopMargin(0); gPad->SetBottomMargin(0.2); gPad->SetTickx(); gStyle->SetOptFit(1); TH1D* hratio = (TH1D*)h_data->Clone("hratio"); hratio->Reset(); hratio->Divide(h_data,h_all,1.0,1.0); hratio->SetTitle(""); hratio->SetMaximum(1.5); hratio->SetMinimum(0.5); hratio->SetTitleOffset(1.2,"Y"); hratio->GetXaxis()->SetTitle(h_data->GetXaxis()->GetTitle()); hratio->Draw("e1"); cout << "( " << h_data->GetBinContent(maxBin) << "+-" << h_data->GetBinError(maxBin) << " )/(" << h_all->GetBinContent(maxBin) << "+-" << h_all->GetBinError(maxBin) << ")= " << hratio->GetBinContent(maxBin) << "+-" << hratio->GetBinError(maxBin) << endl; psname = dirName+ "/ratio_" + histoName; filename = psname + ".eps"; c2->Print(filename.data()); filename = psname + ".gif"; c2->Print(filename.data()); filename = psname + ".pdf"; c2->Print(filename.data()); std::string remword =".txt"; size_t pos = inputFile.find(remword); if(pos!= std::string::npos) inputFile.replace(pos,remword.length(),""); std::string command = "recreate"; if(update)command ="update"; TFile* outFile = new TFile(Form("combined_%s.root",inputFile.data()),command.data()); h_all->Write(); hs->Write(); h_data->Write(); outFile->Close(); }
TF1 *fit(TTree *nt,TTree *ntMC,double ptmin,double ptmax, bool ispPb, int count){ //cout<<cut.Data()<<endl; //static int count=0; //count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",50,5,6); TH1D *hMC = new TH1D(Form("hMC%d",count),"",50,5,6); TString iNP="7.26667e+00*Gaus(x,5.10472e+00,2.63158e-02)/(sqrt(2*3.14159)*2.63158e-02)+4.99089e+01*Gaus(x,4.96473e+00,9.56645e-02)/(sqrt(2*3.14159)*9.56645e-02)+3.94417e-01*(3.74282e+01*Gaus(x,5.34796e+00,3.11510e-02)+1.14713e+01*Gaus(x,5.42190e+00,1.00544e-01))"; TF1 *f = new TF1(Form("f%d",count),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*("+iNP+")"); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); clean0(h); TH1D *hraw = new TH1D(Form("hraw%d",count),"",50,5,6); clean0(hraw); hraw = (TH1D*)h->Clone(Form("hraw%d",count)); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.05); f->SetParLimits(7,0,1); f->SetParLimits(5,0,1000); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi%d",count),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(5)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); // Bkpi->SetRange(5.00,5.28); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass%d",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (20 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.5,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); hraw->Draw("same"); double yield = mass->Integral(5,6)/0.02; double yieldErr = mass->Integral(5,6)/0.02*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"pPb #sqrt{s_{NN}} = 5.02 TeV",""); leg->AddEntry(h,Form("%.0f < p_{T}^{B} < %.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B} = %.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B} = %.0f #pm %.0f", yield, yieldErr),""); leg2->Draw(); if(ispPb)c->SaveAs(Form("../ResultsBplus/BMass-%d.pdf",count)); else c->SaveAs(Form("../ResultsBplus_pp/BMass-%d.pdf",count)); h->Write(); hMC->Write(); f->Write(); background->Write(); Bkpi->Write(); mass->Write(); hraw->Write(); return mass; }
void compareSherpaMadgraph(std::string sherpafile, std::string madgraphfile, std::string var, float xmin=-9999.0, float xmax=-9999.0, bool logScale=false, std::string output="test") { setTDRStyle(); gStyle->SetOptStat(0); TH1F* hsherpa; TH1F* hmadgraph; char tempName[300]; // first get the histogram files TFile *fsherpa = TFile::Open(sherpafile.data()); TFile *fmadgraph = TFile::Open(madgraphfile.data()); hsherpa = (TH1F*)(fsherpa->Get(var.data())); hmadgraph = (TH1F*)(fmadgraph->Get(var.data())); TH1D* hscale =(TH1D*) hsherpa->Clone("hscale"); hscale->SetYTitle("SHERPA/MADGRAPH"); int nREBIN=2; if(var.find("pt")!= std::string::npos) nREBIN=4; hsherpa->GetXaxis()->SetNdivisions(5); hsherpa->GetYaxis()->SetDecimals(); hsherpa->Rebin(nREBIN); hmadgraph->GetXaxis()->SetNdivisions(5); hmadgraph->GetYaxis()->SetDecimals(); hmadgraph->Rebin(nREBIN); hscale->GetXaxis()->SetNdivisions(5); hscale->GetYaxis()->SetDecimals(); hscale->Rebin(nREBIN); hsherpa->SetLineColor(2); hsherpa->SetMarkerColor(2); hsherpa->SetMarkerSize(1); hsherpa->SetMarkerStyle(24); hmadgraph->SetLineColor(4); hmadgraph->SetMarkerColor(4); hmadgraph->SetMarkerSize(1); hmadgraph->SetMarkerStyle(21); // if normalizing to the same area, set the scale int binLo = -1; int binHi = -1; int nbins = hsherpa->GetNbinsX(); if(xmin>-9999.0 && xmax>-9999.0) { binLo = hsherpa->FindBin(xmin); binHi = hsherpa->FindBin(xmax)-1; } else { binLo = 1; binHi = nbins; xmin = hsherpa->GetBinLowEdge(1); xmax = hsherpa->GetBinLowEdge(nbins+1); } // float scale_mc = (float)hsherpa->Integral(binLo,binHi)/(float)hmadgraph->Integral(binLo,binHi); // cout << "binLo = " << binLo << ", binHi = " << binHi << endl; // cout << "xmin = " << xmin << "xmax = " << xmax << endl; // hmadgraph->Sumw2(); // hmadgraph->Scale(scale_mc); float scale_sherpa = 1000.0*4.890*3048.0/4.71644910071102437e+06; float scale_madgraph = 1000.0*4.890*3048.0/3.59644320000000000e+07; hsherpa->Sumw2(); hsherpa->Scale(scale_sherpa); hmadgraph->Sumw2(); hmadgraph->Scale(scale_madgraph); cout << "hmadgraph integral = " << hmadgraph->Integral() << endl; cout << "hsherpa integral = " << hsherpa->Integral() << endl;; // get the ratio double chi2 = 0; int realbin = 0; for(int i=1; i<= nbins; i++) { double nmc=hmadgraph->GetBinContent(i); double ndata=hsherpa->GetBinContent(i); double nmcerr=hmadgraph->GetBinError(i); double ndataerr=hsherpa->GetBinError(i); if(nmc<0 || ndata<0)continue; if(nmcerr==0 && ndataerr==0)continue; if(nmc==0 && ndata==0)continue; double chi2ndef = (nmc-ndata)*(nmc-ndata)/ ( nmcerr*nmcerr+ ndataerr*ndataerr); chi2 += chi2ndef; realbin++; cout << "Bin " << i << " : " << ndata << ", " << nmc; cout << " " << chi2ndef << endl; // now calculate the ratio if(nmc==0 || nmcerr==0 || ndata==0 || ndataerr==0)continue; cout << "Bin " << i << " ratio = " << ndata/nmc << endl; hscale->SetBinContent(i,ndata/nmc); double err = 0; err= (ndata/nmc)*sqrt(pow(nmcerr/nmc,2)+pow(ndataerr/ndata,2)); hscale->SetBinError(i,err); } hsherpa->GetXaxis()->SetRangeUser(xmin,xmax); hmadgraph->GetXaxis()->SetRangeUser(xmin,xmax); hscale->GetXaxis()->SetRangeUser(xmin,xmax); TCanvas* c1 = new TCanvas("c1","",700,1000); c1->Divide(1,2,0.01,0); c1->cd(1); if(logScale) gPad->SetLogy(1); gPad->SetTopMargin(0.01); gPad->SetBottomMargin(0); gPad->SetRightMargin(0.04); float max_data = hsherpa->GetBinError(hsherpa->GetMaximumBin()) + hsherpa->GetMaximum(); float max_mc = hmadgraph->GetBinError(hmadgraph->GetMaximumBin()) + hmadgraph->GetMaximum(); if(max_data > max_mc) { hsherpa->Draw("e"); hmadgraph->Draw("hesame"); } else { hmadgraph->Draw("he"); hsherpa->Draw("esame"); } float x1NDC = 0.691; float y1NDC = 0.757; float x2NDC = 0.894; float y2NDC = 0.973; TLegend* leg = new TLegend(x1NDC,y1NDC,x2NDC,y2NDC); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetTextSize(0.04); leg->SetBorderSize(0); leg->AddEntry(hsherpa, "SHERPA"); leg->AddEntry(hmadgraph, "MADGRAPH"); leg->Draw("same"); c1->cd(2); gStyle->SetStatW (0.3); gStyle->SetStatH (0.3); gStyle->SetStatX (0.879447); gStyle->SetStatY (0.939033); gStyle->SetStatFontSize(0.05); gStyle->SetStatBorderSize(0); gPad->SetRightMargin(0.04); gPad->SetTopMargin(0); gPad->SetBottomMargin(0.2); gPad->SetTickx(); gStyle->SetOptFit(1); hscale->SetTitle(""); hscale->SetMaximum(3.0); hscale->SetMinimum(-0.5); hscale->SetTitleOffset(1.2,"Y"); hscale->Draw("e1"); TF1* fline = new TF1("fline","pol1"); TLine* l2 = new TLine(xmin,1.,xmax,1.); l2->SetLineColor(4); l2->SetLineStyle(3); fline->SetLineWidth(3); fline->SetLineColor(6); fline->SetNpx(2500); hscale->Fit("fline","",""); l2->Draw("same"); string dirName = "compareSherpaMadgraph"; gSystem->mkdir(dirName.data()); std::string filename; std::string psname = dirName + "/" + var; if(output !="test") psname = dirName+ "/" + output; else psname = dirName+ "/" + var; filename = psname + ".eps"; c1->Print(filename.data()); filename = psname + ".gif"; c1->Print(filename.data()); filename = psname + ".pdf"; c1->Print(filename.data()); // c1->Close(); }
void compare_emu(std::string mcfile1, std::string mcfile2, std::string var1, std::string var2="", float xmin=-9999.0, float xmax=-9999.0, std::string output="test", std::string header="Before unfolding", std::string mcName1="e", std::string mcName2="#mu", bool logScale=false ) { setTDRStyle(); gStyle->SetOptStat(0); TH1F* h1; TH1F* h2; char tempName[300]; if(var2 == "" )var2=var1; // first get the histogram files TFile *fmc1 = TFile::Open(mcfile1.data()); TFile *fmc2 = TFile::Open(mcfile2.data()); h1 = (TH1F*)(fmc1->Get(var1.data())); h2 = (TH1F*)(fmc2->Get(var2.data())); TH1D* hscale =(TH1D*) h1->Clone("hscale"); hscale->SetYTitle(Form("%s/%s",mcName1.data(),mcName2.data())); h1->GetXaxis()->SetNdivisions(5); h1->GetYaxis()->SetDecimals(); h2->GetXaxis()->SetNdivisions(5); h2->GetYaxis()->SetDecimals(); hscale->GetXaxis()->SetNdivisions(5); hscale->GetYaxis()->SetDecimals(); h1->SetLineColor(2); h1->SetMarkerColor(2); h1->SetMarkerSize(1); h1->SetMarkerStyle(24); h2->SetLineColor(4); h2->SetMarkerColor(4); h2->SetMarkerSize(1); h2->SetMarkerStyle(21); // if normalizing to the same area, set the scale int binLo = -1; int binHi = -1; int nbins = h1->GetNbinsX(); if(xmin>-9999.0 && xmax>-9999.0) { binLo = h1->FindBin(xmin); binHi = h1->FindBin(xmax)-1; } else { binLo = 1; binHi = nbins; xmin = h1->GetBinLowEdge(1); xmax = h1->GetBinLowEdge(nbins+1); } h1->Sumw2(); h1->Scale(1.0/h1->Integral(binLo, binHi)); h2->Sumw2(); h2->Scale(1.0/h2->Integral(binLo, binHi)); cout << "h2 integral = " << h2->Integral() << endl; cout << "h1 integral = " << h1->Integral() << endl;; // get the ratio hscale->Divide(h1, h2, 1,1); cout << "===========================================================" << endl; cout << "Central value " << endl; for(int i=1;i<=hscale->GetNbinsX();i++) cout << "Bin " << i << " ( " << hscale->GetBinLowEdge(i) << "~" << hscale->GetBinLowEdge(i+1) << " ): " << h1->GetBinContent(i) << "/" << h2->GetBinContent(i) << " = " << hscale->GetBinContent(i) << " +- " << hscale->GetBinError(i) << endl; cout << "Uncertainty " << endl; for(int i=1;i<=hscale->GetNbinsX();i++) cout << "Bin " << i << " ( " << hscale->GetBinLowEdge(i) << "~" << hscale->GetBinLowEdge(i+1) << " ): " << h1->GetBinError(i) << "/" << h2->GetBinError(i) << " = " << h1->GetBinError(i) / h2->GetBinError(i) << endl; cout << "===========================================================" << endl; cout << "Relative uncertainty is " << endl; for(int i=1;i<=hscale->GetNbinsX();i++) if(hscale->GetBinContent(i)>1e-6) cout << "Bin " << i << " ( " << hscale->GetBinLowEdge(i) << "~" << hscale->GetBinLowEdge(i+1) << " ): " << hscale->GetBinError(i)/hscale->GetBinContent(i) << endl; h1->GetXaxis()->SetRangeUser(xmin,xmax); h2->GetXaxis()->SetRangeUser(xmin,xmax); hscale->GetXaxis()->SetRangeUser(xmin,xmax); TCanvas* c1 = new TCanvas("c1","",700,1000); c1->Divide(1,2,0.01,0); c1->cd(1); if(logScale) gPad->SetLogy(1); gPad->SetTopMargin(0.01); gPad->SetBottomMargin(0); gPad->SetRightMargin(0.04); float max_data = h1->GetBinError(h1->GetMaximumBin()) + h1->GetMaximum(); float max_mc = h2->GetBinError(h2->GetMaximumBin()) + h2->GetMaximum(); if(max_data > max_mc) { h1->Draw("e"); h2->Draw("hesame"); } else { h2->Draw("he"); h1->Draw("esame"); } float x1NDC = 0.798232; float y1NDC = 0.811949; float x2NDC = 0.877295; float y2NDC = 0.953398; TLegend* leg = new TLegend(x1NDC,y1NDC,x2NDC,y2NDC); // leg->SetHeader(header.data()); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetTextSize(0.06); leg->SetBorderSize(0); leg->AddEntry(h1, mcName1.data()); leg->AddEntry(h2, mcName2.data()); leg->Draw("same"); c1->cd(2); gStyle->SetStatW (0.3); gStyle->SetStatH (0.3); gStyle->SetStatX (0.879447); gStyle->SetStatY (0.939033); gStyle->SetStatFontSize(0.05); gStyle->SetStatBorderSize(0); gPad->SetRightMargin(0.04); gPad->SetTopMargin(0); gPad->SetBottomMargin(0.2); gPad->SetTickx(); gStyle->SetOptFit(1); hscale->SetTitle(""); hscale->SetMaximum(1.2); hscale->SetMinimum(0.8); hscale->SetTitleOffset(1.2,"Y"); hscale->Draw("e1"); TF1* fline = new TF1("fline","pol1"); TLine* l2 = new TLine(xmin,1.,xmax,1.); l2->SetLineColor(4); l2->SetLineStyle(3); fline->SetLineWidth(3); fline->SetLineColor(6); fline->SetNpx(2500); // hscale->Fit("fline","",""); l2->Draw("same"); string dirName = "unfolding"; gSystem->mkdir(dirName.data()); std::string filename; std::string psname = dirName + "/" + var1; if(output !="test") psname = dirName+ "/" + output; else psname = dirName+ "/" + var1; filename = psname + ".eps"; c1->Print(filename.data()); filename = psname + ".gif"; c1->Print(filename.data()); filename = psname + ".pdf"; c1->Print(filename.data()); // c1->Close(); }
void sysError( TString inFileName="jfh_HCPR_J50U_Cent30to100_Aj0to100_SubEtaRefl.root", Int_t compMode = 0, // Compare mode: 0 reco-genSig, 1 reco-genAll, 3 genAll-genSig, 4 calo_genp-allGen Int_t sysMode = 0, // Plot mode: 0 for simple plot, 1 for difference TString outdir = ".", TString title = "test" ) { // =============================================== // Inputs // =============================================== TFile *f = new TFile(inFileName); TString inFileNameStrip(inFileName); inFileNameStrip.ReplaceAll(".root",""); TString inFileNameGen(inFileName); if (compMode==0) { inFileNameGen.ReplaceAll("djcalo","djcalo_genp"); inFileNameGen.ReplaceAll("HydjetAll","HydjetSig"); } if (compMode==1) inFileNameGen.ReplaceAll("djcalo","djcalo_genp"); else if (compMode==3) inFileNameGen.ReplaceAll("HydjetAll","HydjetSig"); else if (compMode==5) inFileNameGen.ReplaceAll("djcalo_genp","djgen"); TFile *fgen = new TFile(inFileNameGen); TString inFileNameStripGen(inFileNameGen); inFileNameStripGen.ReplaceAll(".root",""); cout << "==========================================================" << endl; cout << "Compare: " << inFileName << endl << " vs " << endl << " " << inFileNameGen << endl; cout << "==========================================================" << endl; // =============================================== // Setup // =============================================== TString tag=Form("sysError_%s_%s_%d_%d",inFileNameStrip.Data(),title.Data(),compMode,sysMode); // =============================================== // Analyze // =============================================== TH2D * hPtPNDR = (TH2D*) f->Get("hPtPNDR"); TH2D * hPtPADR = (TH2D*) f->Get("hPtPADR"); TH2D * hPtPNDRBg = (TH2D*) f->Get("hPtPNDRBg"); TH2D * hPtPADRBg = (TH2D*) f->Get("hPtPADRBg"); TH2D * hPtPNDRSub = (TH2D*)hPtPNDR->Clone(tag+"hPtPNDRSub"); TH2D * hPtPADRSub = (TH2D*)hPtPADR->Clone(tag+"hPtPADRSub"); hPtPNDRSub->Add(hPtPNDR,hPtPNDRBg,1,-1); hPtPADRSub->Add(hPtPADR,hPtPADRBg,1,-1); TH2D * hPtPNDRGen = (TH2D*) fgen->Get("hPtPNDR"); TH2D * hPtPADRGen = (TH2D*) fgen->Get("hPtPADR"); TH2D * hPtPNDRBgGen = (TH2D*) fgen->Get("hPtPNDRBg"); TH2D * hPtPADRBgGen = (TH2D*) fgen->Get("hPtPADRBg"); TH2D * hPtPNDRSubGen = (TH2D*)hPtPNDRGen->Clone(tag+"hPtPNDRSub"); TH2D * hPtPADRSubGen = (TH2D*)hPtPADRGen->Clone(tag+"hPtPADRSub"); hPtPNDRSubGen->Add(hPtPNDRGen,hPtPNDRBgGen,1,-1); hPtPADRSubGen->Add(hPtPADRGen,hPtPADRBgGen,1,-1); // =============================================== // Draw // =============================================== // Get Pt info Int_t numPtBins=hPtPNDR->GetNbinsX(); TH1D * hPt = (TH1D*)hPtPNDR->ProjectionX("hPt"); /* cout << "Pt bins: " << numPtBins << endl; for (Int_t i=0; i<numPtBins+2; ++i) { cout << "Pt Bin " << i << " Low Edge: " << hPt->GetBinLowEdge(i) << endl; } */ // What pt bins to draw const Int_t numPtBinsDraw=3; TCanvas * c6 = new TCanvas("c"+tag,"c"+tag,1400,500); c6->Divide(3,1); for (Int_t i=0; i<numPtBinsDraw; ++i) { Int_t iBeg,iEnd; if (i==0) { iBeg=2; iEnd=3;} if (i==1) { iBeg=4; iEnd=4;} if (i==2) { iBeg=5; iEnd=numPtBins;} cout << "Bin: " << iBeg << " to " << iEnd << endl; TH1D * hNr = (TH1D*)hPtPNDRSub->ProjectionY(tag+Form("hPNDRSub_%d_%d",iBeg,iEnd),iBeg,iEnd); TH1D * hAw = (TH1D*)hPtPADRSub->ProjectionY(tag+Form("hPADRSub_%d_%d",iBeg,iEnd),iBeg,iEnd); TH1D * hNrGen = (TH1D*)hPtPNDRSubGen->ProjectionY(tag+Form("hPNDRSubGen_%d_%d",iBeg,iEnd),iBeg,iEnd); TH1D * hAwGen = (TH1D*)hPtPADRSubGen->ProjectionY(tag+Form("hPADRSubGen_%d_%d",iBeg,iEnd),iBeg,iEnd); if (sysMode==1) { hNr->Add(hNrGen,-1); hAw->Add(hAwGen,-1); } if (sysMode==2) { hNr->Divide(hNrGen); hAw->Divide(hAwGen); } // Print cout << Form("%.1f < P_{T} < %.1f GeV: ",hPt->GetBinLowEdge(iBeg),hPt->GetBinLowEdge(iEnd+1)) << " SigSubBkg Integral - Nr: " << hNr->Integral() << " Aw: " << hAw->Integral() << endl << " Gen - Nr: " << hNrGen->Integral() << " Aw: " << hAwGen->Integral() << endl; // Styles hNr->SetMarkerColor(kRed); hNr->SetLineColor(kRed); hAw->SetMarkerColor(kBlue); hAw->SetLineColor(kBlue); hAwGen->SetLineStyle(2); // Axis Range if (sysMode==0) { hNr->SetYTitle("Background Subtracted Signal (GeV/c)"); hNr->SetAxisRange(-5,60,"Y"); } if (sysMode==2) { hNr->SetAxisRange(-2,6,"Y"); } // Axis Label if (compMode==0) { if (sysMode==1) { hNr->SetYTitle("(Reco Trk)-(Sig GenP) (GeV/c)"); //hNr->SetAxisRange(-20,20,"Y"); } if (sysMode==2) { hNr->SetYTitle("(Reco Trk)/(Sig GenP) (GeV/c)"); } } if (compMode==3) { if (sysMode==1) { hNr->SetYTitle("All GenP - Sig GenP (GeV/c)"); //hNr->SetAxisRange(-3,3,"Y"); } if (sysMode==2) { hNr->SetYTitle("(All GenP)/(Sig GenP) (GeV/c)"); } } hNr->SetXTitle("#Delta R"); hNr->SetAxisRange(0,0.79999,"X"); hNr->SetTitleOffset(1.5,"X"); hNr->GetXaxis()->CenterTitle(); hNr->GetYaxis()->CenterTitle(); c6->cd(i+1); // Fit if (sysMode>0) { TF1 * f0 = new TF1("f0","pol0"); f0->SetLineStyle(2); f0->SetLineWidth(1); hNr->Fit("f0"); hAw->Fit("f0"); } // Draw to Inspect hNr->Draw(); hAw->Draw("same"); if (sysMode==0) { hNrGen->Draw("hist same"); hAwGen->Draw("hist same"); } if (sysMode==0||sysMode==1) { TLine *l = new TLine(0,0,0.8,0); l->Draw(); } if (sysMode==2) { TLine *l = new TLine(0,1,0.8,1); l->Draw(); } TLegend *leg = new TLegend(0.35,0.7,0.85,0.94); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->AddEntry(hNr,Form("%.1f < P_{T} < %.1f GeV",hPt->GetBinLowEdge(iBeg),hPt->GetBinLowEdge(iEnd+1)),""); if (sysMode==0) { if (compMode==0) { leg->AddEntry(hNr,"Leading (RecoTrk)","pl"); leg->AddEntry(hNrGen,"Leading (Sig. GenP)","l"); leg->AddEntry(hAw,"SubLeading (RecoTrk)","pl"); leg->AddEntry(hAwGen,"SubLeading (Sig. GenP)","l"); } if (compMode==1) { leg->AddEntry(hNr,"Leading (RecoTrk)","pl"); leg->AddEntry(hNrGen,"Leading (All GenP)","l"); leg->AddEntry(hAw,"SubLeading (RecoTrk)","pl"); leg->AddEntry(hAwGen,"SubLeading (All GenP)","l"); } } if (sysMode>0) { leg->AddEntry(hNr,"Leading","pl"); leg->AddEntry(hAw,"SubLeading","pl"); } leg->SetTextSize(0.05); leg->Draw(); } // =============================================== // Save // =============================================== c6->Print(Form("%s/%s.gif",outdir.Data(),tag.Data())); c6->Print(Form("%s/%s.eps",outdir.Data(),tag.Data())); c6->Print(Form("%s/%s.C",outdir.Data(),tag.Data())); }
TCanvas *drawRatioPlot(TH1D *prediction, TH1D *sr, TString xTitle, TString filename){ TCanvas *c = new TCanvas("c"+filename,"c",0,0,500,500); float y = 0.3; TPad *pad1 = new TPad("pad1", "Control Plots 1", 0.01, y, 0.99, 0.99); TPad *padRatio = new TPad("rp1", "Ratio1", 0.01, 0.01, 0.99, y-0.01); TH1D *ratio = 0; //ratio = (TH1D*) sr->Clone(); //ratio->Divide(prediction); ratio = (TH1D*) prediction->Clone(); ratio->Divide(sr); for(int i=1; i<=ratio->GetNbinsX();i++){ cout<<"Scaling Factor in "<<i<<". bin ="<<ratio->GetBinContent(i)<<" +/- "<<ratio->GetBinError(i)<<endl; } ratio->GetYaxis()->SetTitle("Pred/Bkg"); ratio->SetTitle(""); ratio->SetLabelSize(0.1,"X"); ratio->SetLabelSize(0.1,"Y"); ratio->SetTitleOffset(0.5,"Y"); ratio->SetTitleSize(0.15,"Y"); padRatio->cd(); //ratio->GetYaxis()->SetRangeUser(0,2); ratio->Draw(); // Draw line at one! float xmin = ratio->GetXaxis()->GetXmin(); float xmax = ratio->GetXaxis()->GetXmax(); TLine *line = new TLine(xmin,1,xmax,1); line->SetLineWidth(2); line->Draw("same"); padRatio->Modified(); TLegend *leg = new TLegend(0.6,0.8,0.9,0.9); leg->AddEntry(sr,"bkg","l"); leg->AddEntry(prediction,"bkg prediction","pel"); pad1->cd(); pad1->SetLogy(); sr->SetLineColor(kRed); sr->SetMarkerColor(kRed); sr->SetMarkerStyle(20); sr->SetTitle(""); prediction->SetMarkerStyle(20); prediction->SetTitle(""); prediction->GetXaxis()->SetTitle(xTitle); sr->GetXaxis()->SetTitle(xTitle); prediction->SetTitleSize(0.07,"X"); prediction->GetXaxis()->SetTitleOffset(0.7); sr->SetTitleSize(0.07,"X"); sr->GetXaxis()->SetTitleOffset(0.7); prediction->Draw("e"); sr->Draw("e same"); double maximum =prediction->GetMaximum()*2.5; double minimum = 0.00001; if(sr->GetMinimum()!=0) minimum=sr->GetMinimum()*0.5; if(prediction->GetMinimum()!=0) minimum=prediction->GetMinimum()*0.5; if(sr->GetMaximum()>prediction->GetMaximum()){ maximum=sr->GetMaximum()*2.5; } prediction->GetYaxis()->SetRangeUser(minimum,maximum); leg->Draw("same"); // Draw both pads to canvas c->cd(); pad1->Draw(); padRatio->SetGridy(); padRatio->Draw(); c->SaveAs(filename); return c; }
void control(TString var,TString bin, TCut cuts, TCut cutsA, TString cutpoint,bool log,Double_t ymax){ setstyle(); TH1::SetDefaultSumw2(true); TCanvas *c2 = new TCanvas("canvas"+var+cutpoint,"canname"+var+cutpoint,700,800); TPad *mainPad = new TPad("","",0.01,0.25,0.99,0.99); mainPad->SetNumber(1); mainPad->Draw(); TPad *ratioPad = new TPad("","",0.01,0.01,0.99,0.25); ratioPad->SetNumber(2); ratioPad->Draw(); c2->cd(1); TCut lo = cuts && mu_pt_lo; TCut hi = cuts && mu_pt_hi; // TH1D *Ctrl_lo = GetHist("AS",kBlack,var,lo,bin,astQCD,cutpoint); // TH1D *Sig_lo = GetHist("S",kRed,var,lo,bin,stQCD,cutpoint); TH1D *Ctrl_hi = GetHist("AS",kBlack,var,cuts,bin,astQCD,cutpoint); TH1D *Sig_hi = GetHist("S",kRed,var,cuts,bin,stQCD,cutpoint); // Ctrl_lo->Scale(1.94); // Sig_lo->Scale(1.94); TH1D *Ctrl = Ctrl_hi->Clone(); TH1D *Sig = Sig_hi->Clone(); // Ctrl->Add(Ctrl_hi); // Sig->Add(Sig_hi); Sig->Scale(intlumi); // TH1D *Ctrl = GetHist("AS",kBlack,var,cuts,bin,astQCD,cutpoint); if(Ctrl->Integral()!=0){ Ctrl->Scale(Sig->Integral()/Ctrl->Integral()); } if(log){ c2->cd(1)->SetLogy();} TLegend *leg = new TLegend(0.564,0.719,0.775,0.875); leg->SetTextSize(0.054); leg->SetFillColor(0); leg->SetLineColor(0); // leg->AddEntry(Ctrl,"Anti-Selected","LF"); leg->AddEntry(Sig,"Selected","LF"); leg->AddEntry(Ctrl,"Anti-Selected","LF"); Ctrl->Draw("EHIST9"); Sig->Draw("E9same"); Sig->SetMarkerStyle(20); Sig->SetMarkerColor(kRed); leg->Draw("same"); Ctrl->SetTitle(); Ctrl->GetXaxis()->SetTitle(var); if(log){ Ctrl->GetYaxis()->SetRangeUser(0.001,ymax); } else{ ymax=(Ctrl->GetMaximum()*1.6); Ctrl->GetYaxis()->SetRangeUser(0.,ymax); } TH1D *RatioBottom = (TH1D*)Ctrl->Clone("Ratiob"); TH1D *RatioTop = (TH1D*)Sig->Clone("Ratiot"); RatioTop->GetYaxis()->SetTitle("Selected / Anti-Selected"); RatioTop->GetXaxis()->SetTitle(); RatioTop->SetTitle(); RatioTop->Divide(RatioBottom); c2->cd(2); gPad->SetGridx(); gPad->SetGridy(); RatioTop->SetTitleSize(0.1, "XYZ"); RatioTop->SetTitleOffset(0.55, "X"); RatioTop->SetTitleOffset(0.3, "Y"); RatioTop->SetLabelSize(0.06,"XY"); RatioTop->GetYaxis()->SetRangeUser(-2.,5.0); RatioTop->SetLineColor(kBlack); RatioTop->Draw(); TBox *unity = new TBox(RatioTop->GetXaxis()->GetBinLowEdge(RatioTop->GetXaxis()->GetFirst()), 0.79,RatioTop->GetXaxis()->GetBinLowEdge(RatioTop->GetXaxis()->GetLast()), 1.21); unity->SetLineWidth(2); unity->SetLineColor(2); unity->SetFillColor(2); unity->SetFillStyle(3002); unity->Draw(); c2->Update(); c2->SaveAs(plots+"SAS_Muon_10to25"+var+"_"+cutpoint+".png"); // c2->Close(); }
void figure2_0_generate(){ TFile* f; const int NAchBins = 7; const double correction = 1.0; //185-220 correction //const double correction = 0.675; //30-40% correction //const double correction = 0.641; TH1D* c2_pos_case1[100][4][2]; TH1D* c2_neg_case1[100][4][2]; TH1D* c2_tot_case1[100][4][2]; TH1D* c2_pos_case2[100][4][2]; TH1D* c2_neg_case2[100][4][2]; TH1D* c2_tot_case2[100][4][2]; TH1D* ach_hist[100]; TH1D* c2_pos[100][4]; TH1D* c2_neg[100][4]; double x[NAchBins]; double v2_pos[NAchBins]; double v2_neg[NAchBins]; double err_pos[NAchBins]; double err_neg[NAchBins]; double v2_diff[NAchBins]; double err_diff[NAchBins]; double numerator; double denominator; double q0,q1,q2,q3; double esquared; double v2_pos_sample[100][10]; double v2_neg_sample[100][10]; double v2_diff_sample[100][10]; for (int m = 0; m < 10; ++m) { f = new TFile(Form("~/Summer2016/rootfiles/FinalResult_pPb/leaveout%d.root",m+1)); for (Int_t i = 0; i < NAchBins; i++){ for(Int_t j = 0 ; j < 4; j++){ c2_tot_case1[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_cos_case1",i,j)); c2_tot_case1[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_sin_case1",i,j)); c2_pos_case1[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_cos_case1",i,j)); c2_pos_case1[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_sin_case1",i,j)); c2_neg_case1[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_cos_case1",i,j)); c2_neg_case1[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_sin_case1",i,j)); c2_tot_case2[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_cos_case2",i,j)); c2_tot_case2[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_sin_case2",i,j)); c2_pos_case2[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_cos_case2",i,j)); c2_pos_case2[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_sin_case2",i,j)); c2_neg_case2[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_cos_case2",i,j)); c2_neg_case2[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_sin_case2",i,j)); } } for (int i = 0; i < NAchBins; ++i) { c2_pos[i][0] = new TH1D(*c2_pos_case1[i][0][0]); c2_pos[i][0] -> Add(c2_pos_case2[i][0][0],1.); c2_pos[i][1] = new TH1D(*c2_pos_case1[i][1][0]); c2_pos[i][1] -> Add(c2_pos_case2[i][2][0],1.); c2_pos[i][2] = new TH1D(*c2_pos_case1[i][2][0]); c2_pos[i][2] -> Add(c2_pos_case2[i][1][0],1.); c2_pos[i][3] = new TH1D(*c2_pos_case1[i][3][0]); c2_pos[i][3] -> Add(c2_pos_case2[i][3][0],1.); c2_neg[i][0] = new TH1D(*c2_neg_case1[i][0][0]); c2_neg[i][0] -> Add(c2_neg_case2[i][0][0],1.); c2_neg[i][1] = new TH1D(*c2_neg_case1[i][1][0]); c2_neg[i][1] -> Add(c2_neg_case2[i][2][0],1.); c2_neg[i][2] = new TH1D(*c2_neg_case1[i][2][0]); c2_neg[i][2] -> Add(c2_neg_case2[i][1][0],1.); c2_neg[i][3] = new TH1D(*c2_neg_case1[i][3][0]); c2_neg[i][3] -> Add(c2_neg_case2[i][3][0],1.); } for(Int_t i=0; i<NAchBins; i++){ //positive q0 = c2_pos[i][0]->GetMean(); q1 = c2_pos[i][1]->GetMean(); q2 = c2_pos[i][2]->GetMean(); q3 = c2_pos[i][3]->GetMean(); numerator = q0; denominator = sqrt((q1*q2)/q3); v2_pos_sample[i][m] = numerator/denominator; //negative q0 = c2_neg[i][0]->GetMean(); q1 = c2_neg[i][1]->GetMean(); q2 = c2_neg[i][2]->GetMean(); q3 = c2_neg[i][3]->GetMean(); numerator = q0; denominator = sqrt((q1*q2)/q3); v2_neg_sample[i][m] = numerator/denominator; v2_diff_sample[i][m] = (v2_neg_sample[i][m] - v2_pos_sample[i][m])/(v2_neg_sample[i][m] + v2_pos_sample[i][m]); } } f = new TFile("~/Summer2016/rootfiles/FinalResult_pPb/Merged.root"); for (Int_t i = 0; i < NAchBins; i++){ ach_hist[i] = (TH1D*)f->Get(Form("demo_n3/ach_%d",i+1)); for(Int_t j = 0 ; j < 4; j++){ c2_tot_case1[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_cos_case1",i,j)); c2_tot_case1[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_sin_case1",i,j)); c2_pos_case1[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_cos_case1",i,j)); c2_pos_case1[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_sin_case1",i,j)); c2_neg_case1[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_cos_case1",i,j)); c2_neg_case1[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_sin_case1",i,j)); c2_tot_case2[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_cos_case2",i,j)); c2_tot_case2[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2tot_%d_%d_sin_case2",i,j)); c2_pos_case2[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_cos_case2",i,j)); c2_pos_case2[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_%d_sin_case2",i,j)); c2_neg_case2[i][j][0] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_cos_case2",i,j)); c2_neg_case2[i][j][1] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_%d_sin_case2",i,j)); //c2_pos_case2[i][j][0] ->Sumw2(); //c2_neg_case2[i][j][0] ->Sumw2(); } } for (int i = 0; i < NAchBins; ++i) { c2_pos[i][0] = new TH1D(*c2_pos_case1[i][0][0]); c2_pos[i][0] -> Add(c2_pos_case2[i][0][0],1.); c2_pos[i][1] = new TH1D(*c2_pos_case1[i][1][0]); c2_pos[i][1] -> Add(c2_pos_case2[i][2][0],1.); c2_pos[i][2] = new TH1D(*c2_pos_case1[i][2][0]); c2_pos[i][2] -> Add(c2_pos_case2[i][1][0],1.); c2_pos[i][3] = new TH1D(*c2_pos_case1[i][3][0]); c2_pos[i][3] -> Add(c2_pos_case2[i][3][0],1.); c2_neg[i][0] = new TH1D(*c2_neg_case1[i][0][0]); c2_neg[i][0] -> Add(c2_neg_case2[i][0][0],1.); c2_neg[i][1] = new TH1D(*c2_neg_case1[i][1][0]); c2_neg[i][1] -> Add(c2_neg_case2[i][2][0],1.); c2_neg[i][2] = new TH1D(*c2_neg_case1[i][2][0]); c2_neg[i][2] -> Add(c2_neg_case2[i][1][0],1.); c2_neg[i][3] = new TH1D(*c2_neg_case1[i][3][0]); c2_neg[i][3] -> Add(c2_neg_case2[i][3][0],1.); } for(Int_t i=0; i<NAchBins; i++){ //x coordinates x[i]=ach_hist[i]->GetMean(); x[i]*=correction; //positive q0 = c2_pos[i][0]->GetMean(); q1 = c2_pos[i][1]->GetMean(); q2 = c2_pos[i][2]->GetMean(); q3 = c2_pos[i][3]->GetMean(); numerator = q0; denominator = sqrt((q1*q2)/q3); v2_pos[i] = numerator/denominator; //negative q0 = c2_neg[i][0]->GetMean(); q1 = c2_neg[i][1]->GetMean(); q2 = c2_neg[i][2]->GetMean(); q3 = c2_neg[i][3]->GetMean(); numerator = q0; denominator = sqrt((q1*q2)/q3); v2_neg[i] = numerator/denominator; //difference v2_diff[i] = (v2_neg[i]-v2_pos[i])/(v2_neg[i]+v2_pos[i]); //error bars double variance_pos = 0.0; double variance_neg = 0.0; double variance_diff = 0.0; double sum; for (int k = 0; k < 10; ++k) { variance_pos += (v2_pos_sample[i][k]-v2_pos[i])*(v2_pos_sample[i][k]-v2_pos[i]); variance_neg += (v2_neg_sample[i][k]-v2_neg[i])*(v2_neg_sample[i][k]-v2_neg[i]); variance_diff += (v2_diff_sample[i][k]-v2_diff[i])*(v2_diff_sample[i][k]-v2_diff[i]); } sum = v2_pos[i] + v2_neg[i]; variance_pos *= 0.9; variance_neg *= 0.9; variance_diff *= 0.9; //variance_diff = (4*v2_neg[i]*v2_neg[i]*variance_pos)/(sum*sum*sum*sum)+(4*v2_pos[i]*v2_pos[i]*variance_neg)/(sum*sum*sum*sum); err_pos[i] = sqrt(variance_pos); err_neg[i] = sqrt(variance_neg); err_diff[i] = sqrt(variance_diff); } TGraphErrors *gr_pos = new TGraphErrors(NAchBins,x,v2_pos,NULL,err_pos); TGraphErrors *gr_neg = new TGraphErrors(NAchBins,x,v2_neg,NULL,err_neg); TGraphErrors *gr_diff = new TGraphErrors(NAchBins,x,v2_diff,NULL,err_diff); TFile *rebinned = new TFile("~/Summer2016/root_forgraphs/figure2_0_notcorrected.root","RECREATE"); gr_pos->Write(); gr_neg->Write(); gr_diff->Write(); /* gr_pos->RemovePoint(0); gr_pos->RemovePoint(5); gr_neg->RemovePoint(0); gr_neg->RemovePoint(5); gr_diff->RemovePoint(0); gr_diff->RemovePoint(5); */ gStyle->SetLegendFont(42); TH1D* base = new TH1D("base","base",1,-0.20,0.20); //pPb //base->GetYaxis()->SetRangeUser(0.065, 0.075); base->GetYaxis()->SetRangeUser(0.06, 0.12); //PbPb //base->GetYaxis()->SetRangeUser(0.093, 0.103); base->GetXaxis()->SetTitle("Observed A_{ch}"); base->GetYaxis()->SetTitle("v_{2}{2}"); base->GetXaxis()->CenterTitle(); base->GetYaxis()->CenterTitle(); base->SetTitleSize (0.040,"X"); base->SetTitleOffset(1.4,"X"); base->SetTitleFont (42,"X"); base->SetLabelOffset(0.006,"X"); base->SetLabelSize (0.040,"X"); base->SetLabelFont (42 ,"X"); base->SetTitleSize (0.040,"Y"); base->SetTitleOffset(2.2,"Y"); base->SetTitleFont (42,"Y"); base->SetLabelOffset(0.006,"Y"); base->SetLabelSize (0.040,"Y"); base->SetLabelFont (42 ,"Y"); base->SetLineWidth(0); TH1D* base2 = new TH1D("base2","base2",1,-0.2,0.2); base2->GetYaxis()->SetRangeUser(-0.03, 0.03); base2->GetXaxis()->SetTitle("Observed A_{ch}"); base2->GetYaxis()->SetTitle(" (v^{#minus}_{2} #minus v^{#plus}_{2})/(v^{#minus}_{2} #plus v^{#plus}_{2}) "); base2->GetXaxis()->CenterTitle(); base2->GetYaxis()->CenterTitle(); base2->SetTitleSize (0.040,"X"); base2->SetTitleOffset(1.4,"X"); base2->SetTitleFont (42,"X"); base2->SetLabelOffset(0.006,"X"); base2->SetLabelSize (0.040,"X"); base2->SetLabelFont (42 ,"X"); base2->SetTitleSize (0.040,"Y"); base2->SetTitleOffset(2.0,"Y"); base2->SetTitleFont (42,"Y"); base2->SetLabelOffset(0.006,"Y"); base2->SetLabelSize (0.040,"Y"); base2->SetLabelFont (42 ,"Y"); base2->SetLineWidth(0); // TCanvas* c1 = new TCanvas("c1","c1"); // TCanvas* c2 = new TCanvas("c2","c2"); TCanvas* c3 = new TCanvas("c3","c3",1,1,1200,600); c3->Divide(2,1,0.01,0.01); gr_neg -> SetMarkerStyle(20); gr_neg -> SetMarkerColor(kBlue); gr_pos -> SetMarkerStyle(34); gr_pos -> SetMarkerColor(kRed); TLatex* text_a = makeLatex("CMS PbPb #sqrt{s_{NN}}=5.02TeV",0.25,0.85) ; //TLatex* text_b = makeLatex("185 #leq N_{trk}^{offline} < 220",0.25,0.80) ; TLatex* text_b = makeLatex("30-40%",0.25,0.80) ; TLatex* text_c = makeLatex("0.3 < p_{T} < 3.0 GeV/c",0.25,0.75) ; TLatex* text_d = makeLatex("|#Delta#eta| > 2",0.25,0.70) ; text_a->SetTextFont(42); text_b->SetTextFont(42); text_c->SetTextFont(42); text_d->SetTextFont(42); TLegend* leg = new TLegend(0.76,0.80,0.94,.88); leg->SetLineColor(kWhite); leg->SetFillColor(0); leg->SetFillStyle(0); leg->AddEntry(gr_pos, "v_{2}^{#plus}{2}","p"); leg->AddEntry(gr_neg , "v_{2}^{#minus}{2}","p"); c3->cd(1); base->Draw(""); gr_pos->Draw("PSame"); gr_neg->Draw("PSame"); text_a->DrawClone("Same"); text_b->DrawClone("Same"); text_c->DrawClone("Same"); text_d->DrawClone("Same"); leg->DrawClone("Same"); //Define a linear function TF1* fit1 = new TF1("f1", "[0]+x*[1]", -0.13, 0.13); fit1->SetLineColor(kRed); fit1->SetLineStyle(2); gr_diff->Fit(fit1,"RN0"); fit1->Write(); rebinned->Close(); c3->cd(2); TLatex* text2 = makeLatex(Form("Intercept : %f #pm %f",fit1->GetParameter(0),fit1->GetParError(0)),0.45,0.30) ; TLatex* text1 = makeLatex(Form("slope : %.4f #pm %.4f",fit1->GetParameter(1),fit1->GetParError(1)),0.45,0.25) ; text1->SetTextFont(42); text2->SetTextFont(42); base2->Draw(""); fit1->DrawClone("Same"); gr_diff->SetMarkerStyle(20); gr_diff->Draw("PSame"); text_a->DrawClone("Same"); text_b->DrawClone("Same"); text1->DrawClone("Same"); text2->DrawClone("Same"); TF1 *fa1 = new TF1("fa1","0",-10,10); fa1->SetLineColor(kBlack); fa1->SetLineWidth(0); fa1->DrawClone("Same"); TLegend* leg2 = new TLegend(0.25,0.68,0.5,0.78); leg2->SetLineColor(kWhite); leg2->SetFillColor(0); leg2->SetFillStyle(0); leg2->AddEntry(fit1, "Linear fit","l"); leg2->AddEntry(gr_diff , "data","p"); leg2->DrawClone("Same"); //SaveCanvas(c3,"pics",Form("30-40SP")); }
TF1 *fitSignal(TTree *ntMC,double ptmin,double ptmax){ //cout<<cut.Data()<<endl; TCanvas *cSignal= new TCanvas("cSignal","",600,600); TH1D *hMC = new TH1D("hMC","",50,5,6); // TString iNP="7.26667e+00*Gaus(x,5.10472e+00,2.63158e-02)/(sqrt(2*3.14159)*2.63158e-02)+4.99089e+01*Gaus(x,4.96473e+00,9.56645e-02)/(sqrt(2*3.14159)*9.56645e-02)+3.94417e-01*(3.74282e+01*Gaus(x,5.34796e+00,3.11510e-02)+1.14713e+01*Gaus(x,5.42190e+00,1.00544e-01))"; TF1 *f = new TF1("f1","[0]*([5]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[5])*Gaus(x,[1],[6])/(sqrt(2*3.14159)*[6]))+[3]+[4]*x"); ntMC->Project("hMC","mass",Form("%s&&pt>%f&&pt<%f",selmc.Data(),ptmin,ptmax)); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(6,0.01,0.05); f->SetParLimits(5,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(6,setparam3); f->FixParameter(1,fixparam1); hMC->Fit("f1","q","",5,6); hMC->Fit("f1","q","",5,6); f->ReleaseParameter(1); hMC->Fit("f1","L q","",5,6); hMC->Fit("f1","L q","",5,6); hMC->Fit("f1","L q","",5,6); hMC->Fit("f1","L m","",5,6); // function for background shape plotting. take the fit result from f TF1 *background = new TF1("backgroundSignal","[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1("fmassSignal","[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(5),f->GetParameter(6)); cout<<"[0]Signal: "<<f->GetParameter(0)<<endl; mass->SetLineColor(2); mass->SetLineStyle(2); hMC->SetMarkerStyle(24); hMC->SetStats(0); hMC->Draw("e"); hMC->SetXTitle("M_{B} (GeV/c^{2})"); hMC->SetYTitle("Entries / (20 MeV/c^{2})"); hMC->GetXaxis()->CenterTitle(); hMC->GetYaxis()->CenterTitle(); hMC->SetTitleOffset(1.,"Y"); hMC->SetAxisRange(0,hMC->GetMaximum()*1.2,"Y"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); double yield = mass->Integral(5,6)/0.02; // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.92); leg->AddEntry(hMC,"CMS Preliminary",""); leg->AddEntry(hMC,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(hMC,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(hMC,"B meson",""); leg2->AddEntry(hMC,Form("N_{B}=%.0f", yield),""); leg2->Draw(); cSignal->SaveAs("NonpromptBplus/BMassSignal.gif"); return mass; }
void bfractionVsCent(char *tagger="discr_ssvHighEff", double workingPoint=2., int fixCL=0, char *taggerName="ssvHighEff", float ptlo=80, float pthi=100, float etalo=0., float etahi=2.) { gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetLabelFont(43,"xyz"); gStyle->SetLabelSize(20,"xyz"); gStyle->SetTitleFont(43,"xyz"); gStyle->SetTitleSize(26,"xyz"); gStyle->SetTitleOffset(1.0,"xy"); gROOT->ForceStyle(1); int doLTJP=1; int doLTCSV=0; const int nBins = 2; double centBin[nBins+1] = {0,30,100}; //const int nBins = 3; //double centBin[nBins+1] = {0,20,50,100}; Double_t bPurMC, bPurData, bEffMC, bEffDataLTJP, bEffDataLTCSV, taggedFracData, bFracMC, bFracData, bFracDataLTJP, bFracDataLTCSV, bFracJPdirect; Double_t bPurMCError, bPurDataError, bEffMCError, bEffDataLTJPError, bEffDataLTCSVError, taggedFracDataError, bFracMCError, bFracDataError, bFracDataLTJPError, bFracDataLTCSVError, bFracJPdirectError; Enumerations numbers; TH1D *hBPurityData = new TH1D("hBPurityData","hBPurityData;Centrality;B-Tagging purity",nBins,centBin); TH1D *hBPurityMC = new TH1D("hBPurityMC","hBPurityMC;Centrality;B-Tagging purity",nBins,centBin); TH1D *hBEfficiencyMC = new TH1D("hBEfficiencyMC","hBEfficiencyMC;Centrality;B-Tagging efficiency",nBins,centBin); TH1D *hBEfficiencyDataLTJP = new TH1D("hBEfficiencyDataLTJP","hBEfficiencyDataLTJP;Centrality;B-Tagging efficiency",nBins,centBin); TH1D *hBEfficiencyDataLTCSV = new TH1D("hBEfficiencyDataLTCSV","hBEfficiencyDataLTCSV;Centrality;B-Tagging efficiency",nBins,centBin); TH1D *hBFractionMC = new TH1D("hBFractionMC","hBFractionMC;Centrality;B-jet fraction",nBins,centBin); TH1D *hBFractionData = new TH1D("hBFractionData","hBFractionData;Centrality;B-jet fraction",nBins,centBin); TH1D *hBFractionDataLTJP = new TH1D("hBFractionDataLTJP","hBFractionDataLTJP;Centrality;B-jet fraction",nBins,centBin); TH1D *hBFractionDataLTCSV = new TH1D("hBFractionDataLTCSV","hBFractionDataLTCSV;Centrality;B-jet fraction",nBins,centBin); TH1D *hBFractionJPdirect = new TH1D("hBFractionJPdirect","hBFractionJPdirect;Centrality;B-jet fraction",nBins,centBin); int ncol=1; int nrow=1; if(nBins==3||nBins==2){ ncol=nBins; } if(nBins==4){ ncol=nBins/2; nrow=nBins/2; } TCanvas *c1=new TCanvas("c1","c1",1200,600); //c1->Divide(ncol,nrow,0,0); c1->Divide(ncol,nrow); TCanvas *c2=new TCanvas("c2","c2",1200,600); //c2->Divide(ncol,nrow,0,0); c2->Divide(ncol,nrow); TCanvas *c3=new TCanvas("c3","c3",1200,600); //c3->Divide(ncol,nrow,0,0); c3->Divide(ncol,nrow); TCanvas *c4=new TCanvas("c4","c4",1200,600); //c4->Divide(ncol,nrow,0,0); c4->Divide(ncol,nrow); TCanvas *cCount = new TCanvas("cCount","cCount",600,600); for (int n=0;n<nBins;n++) { cout<<"Processing jet centrality bin ["<<centBin[n]<<","<<centBin[n+1]<<"] ..."<<endl; cCount->cd(); cout<<"centBin[n]: "<<centBin[n]<<" centBin[n+1]: "<<centBin[n+1]<<" tagger: "<<tagger<<" workingPoint: "<<workingPoint<<" ptlo: "<<ptlo<<" pthi: "<<pthi<<" etalo: "<<etalo<<" etahi: "<<etahi<<endl; numbers = count(centBin[n],centBin[n+1],tagger,workingPoint,ptlo,pthi,etalo,etahi); c1->cd(n+1); c1->GetPad(n+1)->SetLogy(); RooRealVar fitSvtxmTag = bfractionFit(fixCL,"svtxm",0,6,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,tagger,workingPoint,6,"b-tagged sample (SSVHE > 2)",9e3); //RooRealVar fitSvtxmTag = bfractionFit(fixCL,"svtxm",0,6,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,tagger,workingPoint,10,Form("b-tagged sample (%s at %.1f)",taggerName,workingPoint)); //RooRealVar fitJpDirect = bfractionFit(fixCL,"discr_prob",0,3,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,tagger,-2,10,"inclusive sample",5e4); c2->cd(n+1); c2->GetPad(n+1)->SetLogy(); RooRealVar fitJpDirect = bfractionFit(fixCL,"discr_prob",0.0,3.,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,"discr_prob",0.,3.,"inclusive sample",4e5); if (doLTJP) { c3->cd(n+1); c3->GetPad(n+1)->SetLogy(); RooRealVar fitJpBeforetag = bfractionFit(fixCL,"discr_prob",0.0,3.,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,"discr_prob",0,3.,"jets with JP info",4e5); c4->cd(n+1); c4->GetPad(n+1)->SetLogy(); RooRealVar fitJpTag = bfractionFit(fixCL,"discr_prob",0.0,3.,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,tagger,workingPoint,6,"b-tagged sample (SSVHE > 2)",4e5); } if (doLTCSV) { RooRealVar fitCsvBeforetag = bfractionFit(fixCL,"discr_csvSimple",0,1,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,tagger,-2,10,"jets with CSV info",4e5); RooRealVar fitCsvTag = bfractionFit(fixCL,"discr_csvSimple",0,1,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,tagger,workingPoint,10,"b-tagged sample (SSVHE > 2)",4e5); } taggedFracData = numbers.nTaggedJetsData / (numbers.nTaggedJetsData+numbers.nUntaggedJetsData); taggedFracDataError = fracError(numbers.nTaggedJetsData,numbers.nUntaggedJetsData,numbers.nTaggedJetsDataError,numbers.nUntaggedJetsDataError); //* --- b-tagging purity --- bPurMC = numbers.nTaggedBjetsMC / numbers.nTaggedJetsMC; cout<<" bPurMC "<<bPurMC<<" numbers.nTaggedBjetsMC "<<numbers.nTaggedBjetsMC<<" numbers.nTaggedJetsMC "<<numbers.nTaggedJetsMC<<endl; bPurMCError = fracError(numbers.nTaggedBjetsMC,numbers.nTaggedNonBjetsMC,numbers.nTaggedBjetsMCError,numbers.nTaggedNonBjetsMCError); bPurData = fitSvtxmTag.getVal(); bPurDataError = fitSvtxmTag.getError(); hBPurityMC->SetBinContent(n+1,bPurMC); hBPurityMC->SetBinError(n+1,bPurMCError); hBPurityData->SetBinContent(n+1,bPurData); hBPurityData->SetBinError(n+1,bPurDataError); //*/ //* --- b-tagging efficiency --- bEffMC = numbers.nTaggedBjetsMC / numbers.nBjetsMC; bEffMCError = fracError(numbers.nTaggedBjetsMC,numbers.nUntaggedBjetsMC,numbers.nTaggedBjetsMCError,numbers.nUntaggedBjetsMCError); hBEfficiencyMC->SetBinContent(n+1,bEffMC); hBEfficiencyMC->SetBinError(n+1,bEffMCError); if (doLTJP) { bEffDataLTJP = taggedFracData * numbers.cbForJP * fitJpTag.getVal() / fitJpBeforetag.getVal(); bEffDataLTJPError = prodError(taggedFracData,fitJpTag.getVal(),taggedFracDataError,fitJpTag.getError()) * numbers.cbForJP / fitJpBeforetag.getVal(); hBEfficiencyDataLTJP->SetBinContent(n+1,bEffDataLTJP); hBEfficiencyDataLTJP->SetBinError(n+1,bEffDataLTJPError); } if (doLTCSV) { bEffDataLTCSV = taggedFracData * numbers.cbForCSV * fitCsvTag.getVal() / fitCsvBeforetag.getVal(); bEffDataLTCSVError = prodError(taggedFracData,fitCsvTag.getVal(),taggedFracDataError,fitCsvTag.getError()) * numbers.cbForCSV / fitCsvBeforetag.getVal(); hBEfficiencyDataLTCSV->SetBinContent(n+1,bEffDataLTCSV); hBEfficiencyDataLTCSV->SetBinError(n+1,bEffDataLTCSVError); } //* --- b fraction --- bFracMC = numbers.nBjetsMC / numbers.nJetsMC; //bFracMC = numbers.nTaggedJetsMC * bPurMC / (bEffMC * numbers.nJetsMC); // for check : same as previous bFracMCError = fracError(numbers.nBjetsMC,numbers.nNonBjetsMC,numbers.nBjetsMCError,numbers.nNonBjetsMCError); hBFractionMC->SetBinContent(n+1,bFracMC); hBFractionMC->SetBinError(n+1,bFracMCError); bFracData = taggedFracData * bPurData / bEffMC; // efficiency from MC bFracDataError = prodError(taggedFracData,bPurData,taggedFracDataError,bPurDataError) / bEffMC; // stat.error from purity and tagged-fraction (assumed independent) //bFracDataError = bFracData * bPurDataError / bPurData; // stat.error only from purity hBFractionData->SetBinContent(n+1,bFracData); hBFractionData->SetBinError(n+1,bFracDataError); if (doLTJP) { bFracDataLTJP = taggedFracData * bPurData / bEffDataLTJP ; // efficiency from LTJP method bFracDataLTJPError = prodError(taggedFracData,bPurData,taggedFracDataError,bPurDataError) / bEffDataLTJP; // stat.error from purity and tagged-fraction (assumed independent) //bFracDataLTJPError = bFracDataLTJP * bPurDataError / bPurData; // stat.error only from purity hBFractionDataLTJP->SetBinContent(n+1,bFracDataLTJP); hBFractionDataLTJP->SetBinError(n+1,bFracDataLTJPError); } if (doLTCSV) { bFracDataLTCSV = taggedFracData * bPurData / bEffDataLTCSV; // efficiency from LTCSV method bFracDataLTCSVError = prodError(taggedFracData,bPurData,taggedFracDataError,bPurDataError) / bEffDataLTCSV; // stat.error from purity and tagged-fraction (assumed independent) //bFracDataLTCSVError = bFracDataLTCSV * bPurDataError / bPurData; // stat.error only from purity hBFractionDataLTCSV->SetBinContent(n+1,bFracDataLTCSV); hBFractionDataLTCSV->SetBinError(n+1,bFracDataLTCSVError); } bFracJPdirect = fitJpDirect.getVal(); bFracJPdirectError = fitJpDirect.getError(); hBFractionJPdirect->SetBinContent(n+1,bFracJPdirect); hBFractionJPdirect->SetBinError(n+1,bFracJPdirectError); //*/ //* cout<<"nTaggedJetsMC "<<numbers.nTaggedJetsMC<<endl; cout<<"nUntaggedJetsMC "<<numbers.nUntaggedJetsMC<<endl; cout<<"nJetsMC "<<numbers.nJetsMC<<endl; cout<<"nTaggedBjetsMC "<<numbers.nTaggedBjetsMC<<endl; cout<<"nUntaggedBjetsMC "<<numbers.nUntaggedBjetsMC<<endl; cout<<"nBjetsMC "<<numbers.nBjetsMC<<endl; cout<<"nNonBjetsMC "<<numbers.nNonBjetsMC<<endl; cout<<"nTaggedNonBjetsMC "<<numbers.nTaggedNonBjetsMC<<endl; cout<<"nTaggedJetsData "<<numbers.nTaggedJetsData<<endl; cout<<"nUntaggedJetsData "<<numbers.nUntaggedJetsData<<endl; cout<<"bPurMC "<<bPurMC<<endl; cout<<"bPurData "<<bPurData<<endl; cout<<"bEffMC "<<bEffMC<<endl; cout<<"CbForJP "<<numbers.cbForJP<<endl; cout<<"bEffDataLTJP "<<bEffDataLTJP<<endl; cout<<"CbForCSV "<<numbers.cbForCSV<<endl; cout<<"bEffDataLTCSV "<<bEffDataLTCSV<<endl; cout<<"bFracMC "<<bFracMC<<endl; cout<<"bFracData "<<bFracData<<endl; cout<<"bFracDataLTJP "<<bFracDataLTJP<<endl; cout<<"bFracDataLTCSV "<<bFracDataLTCSV<<endl; cout<<"bFracJPdirect "<<bFracJPdirect<<endl; cout<<endl; //*/ } TLegend *legPur = new TLegend(0.4,0.15,0.85,0.3,Form("Purity of b-tagged sample (%s at %.1f)",taggerName,workingPoint)); legPur->SetBorderSize(0); //legPur->SetFillColor(kGray); legPur->SetFillStyle(0); legPur->AddEntry(hBPurityMC,"MC Input","pl"); legPur->AddEntry(hBPurityData,"Data","pl"); TCanvas *cBPurity = new TCanvas("cBPurity","b purity",600,600); hBPurityMC->SetAxisRange(0,1,"Y"); hBPurityMC->SetTitleOffset(1.3,"Y"); hBPurityMC->SetLineColor(2); hBPurityMC->SetMarkerColor(2); hBPurityMC->SetMarkerStyle(21); hBPurityMC->Draw(); hBPurityData->SetLineColor(1); hBPurityData->SetMarkerColor(1); hBPurityData->SetMarkerStyle(20); hBPurityData->Draw("same"); legPur->Draw(); //cBPurity->SaveAs("purity.gif"); TLegend *legEff = new TLegend(0.4,0.65,0.85,0.8,Form("Efficiency for tagging b-jets (%s at %.1f)",taggerName,workingPoint)); legEff->SetBorderSize(0); //legEff->SetFillColor(kGray); legEff->SetFillStyle(0); legEff->AddEntry(hBEfficiencyMC,"MC Efficiency","pl"); if (doLTJP) legEff->AddEntry(hBEfficiencyDataLTJP,"LT method (JP)","pl"); if (doLTCSV) legEff->AddEntry(hBEfficiencyDataLTCSV,"LT method (CSV)","pl"); TCanvas *cBEfficiency = new TCanvas("cBEfficiency","B-Tagging efficiency",600,600); hBEfficiencyMC->SetAxisRange(0,1,"Y"); hBEfficiencyMC->SetTitleOffset(1.3,"Y"); hBEfficiencyMC->SetLineColor(2); hBEfficiencyMC->SetMarkerColor(2); hBEfficiencyMC->SetMarkerStyle(21); hBEfficiencyMC->Draw(); if (doLTJP) { hBEfficiencyDataLTJP->SetLineColor(8); hBEfficiencyDataLTJP->SetMarkerColor(8); hBEfficiencyDataLTJP->SetMarkerStyle(20); hBEfficiencyDataLTJP->Draw("same"); } if (doLTCSV) { hBEfficiencyDataLTCSV->SetLineColor(7); hBEfficiencyDataLTCSV->SetMarkerColor(7); hBEfficiencyDataLTCSV->SetMarkerStyle(20); hBEfficiencyDataLTCSV->Draw("same"); } legEff->Draw(); //cBEfficiency->SaveAs("efficiency.gif"); TLegend *legFrac = new TLegend(0.25,0.15,0.85,0.3); legFrac->SetBorderSize(0); //legFrac->SetFillColor(kGray); legFrac->SetFillStyle(0); legFrac->AddEntry(hBFractionMC,"MC Input","pl"); legFrac->AddEntry(hBFractionData,Form("%s at %.1f + pur. from SV mass + eff. from MC",taggerName,workingPoint),"pl"); if (doLTJP) legFrac->AddEntry(hBFractionDataLTJP,Form("%s at %.1f + pur. from SV mass + eff. from LT (JP)",taggerName,workingPoint),"pl"); if (doLTCSV) legFrac->AddEntry(hBFractionDataLTCSV,Form("%s at %.1f + pur. from SV mass + eff. from LT (CSV)",taggerName,workingPoint),"pl"); legFrac->AddEntry(hBFractionJPdirect,"Direct fit to JP","pl"); TCanvas *cBFraction = new TCanvas("cBFraction","B-jet fraction",600,600); hBFractionMC->SetAxisRange(0,0.03,"Y"); hBFractionMC->SetTitleOffset(1.8,"Y"); hBFractionMC->SetLineColor(2); hBFractionMC->SetMarkerColor(2); hBFractionMC->SetMarkerStyle(21); hBFractionMC->Draw(); hBFractionData->SetLineColor(1); hBFractionData->SetMarkerColor(1); hBFractionData->SetMarkerStyle(20); hBFractionData->Draw("same"); if (doLTJP) { hBFractionDataLTJP->SetLineColor(8); hBFractionDataLTJP->SetMarkerColor(8); hBFractionDataLTJP->SetMarkerStyle(20); hBFractionDataLTJP->Draw("same"); } if (doLTCSV) { hBFractionDataLTCSV->SetLineColor(7); hBFractionDataLTCSV->SetMarkerColor(7); hBFractionDataLTCSV->SetMarkerStyle(20); hBFractionDataLTCSV->Draw("same"); } hBFractionJPdirect->SetLineColor(4); hBFractionJPdirect->SetMarkerColor(4); hBFractionJPdirect->SetMarkerStyle(20); hBFractionJPdirect->Draw("same"); legFrac->Draw(); //cBFraction->SaveAs("bfraction.gif"); TFile *fout = new TFile(Form("output/bFractionMerged_%sat%.1fFixCL%d_centDep.root",taggerName,workingPoint,fixCL),"recreate"); hBFractionMC->Write(); hBFractionData->Write(); if (doLTJP) hBFractionDataLTJP->Write(); if (doLTCSV) hBFractionDataLTCSV->Write(); hBFractionJPdirect->Write(); fout->Close(); //c1->SaveAs(Form("gifs/svtxMassFit_%s.gif",fixCL?"CLfixed":"CLfree")); //c2->SaveAs(Form("gifs/jpDirectFit_%s.gif",fixCL?"CLfixed":"CLfree")); //c3->SaveAs(Form("gifs/jpBeforeTag_%s.gif",fixCL?"CLfixed":"CLfree")); //c4->SaveAs(Form("gifs/jpAfterTag_%s.gif",fixCL?"CLfixed":"CLfree")); }
void CumulantErrGraph_v2_allgraphs_cent(){ TFile *f; const int NAchBins = 7; //const double correction = 0.7463; //const double correction = 1.0; TH1D* c2_pos[NAchBins][2]; TH1D* c2_neg[NAchBins][2]; TH1D* ach_hist[NAchBins]; double x[NAchBins]; double v2_pos[NAchBins]; double v2_neg[NAchBins]; double v2_diff[NAchBins]; double err_neg[NAchBins]; double err_pos[NAchBins]; double err_diff[NAchBins]; double cmean; double errmean; double sum; double variance_pos; double variance_neg; double variance_diff; int index_v2_mult; int index_v3_mult; int index_v2_cent; int index_v3_cent; int mult_start[6] = {30,40,50,60,70,80}; int mult_end[6] = {40,50,60,70,80,90}; double correction[6] = {0.645, 0.663, 0.673, 0.689, 0.699, 0.623}; int mult_index[6] = {9,10,11,12,13,14}; double setrange_low[6] = {0.0965, 0.105, 0.1038, 0.0945, 0.076, 0.06}; double setrange_upp[6] = {0.101, 0.11, 0.108 ,0.101 ,0.088,0.072}; double range_start = 0.06; double range_end = 0.072; int num = 5; range_start = setrange_low[num]; range_end = setrange_upp[num]; f = new TFile("~/Summer2016/rootfiles/FinalResult_0106/Main_PbPb_Merged.root"); // = new TFile("../../../rootfiles/closure/pPb/185_220/Merged.root"); for (Int_t i = 0; i < NAchBins; i++){ ach_hist[i] = (TH1D*)f->Get(Form("demo_n%d/ach_%d",mult_index[num],i+1)); c2_pos[i][0] = (TH1D*)f->Get(Form("demo_n%d/c2pos_%d_cos",mult_index[num],i)); c2_pos[i][1] = (TH1D*)f->Get(Form("demo_n%d/c2pos_%d_sin",mult_index[num],i)); c2_neg[i][0] = (TH1D*)f->Get(Form("demo_n%d/c2neg_%d_cos",mult_index[num],i)); c2_neg[i][1] = (TH1D*)f->Get(Form("demo_n%d/c2neg_%d_sin",mult_index[num],i)); } for(Int_t i=0; i<NAchBins; i++){ x[i]=ach_hist[i]->GetMean(); x[i] *= correction[num]; //v2 positive cmean = c2_pos[i][0] -> GetMean(); v2_pos[i] = sqrt(cmean); errmean = c2_pos[i][0] -> GetMeanError(); variance_pos = (errmean*errmean)/(4*cmean); //negative cmean = c2_neg[i][0] -> GetMean(); v2_neg[i] = sqrt(cmean); errmean = c2_neg[i][0] -> GetMeanError(); variance_neg = (errmean*errmean)/(4*cmean); //difference v2_diff[i] = (v2_neg[i] - v2_pos[i])/(v2_neg[i] + v2_pos[i]); sum = v2_pos[i] + v2_neg[i]; variance_diff = (4*v2_neg[i]*v2_neg[i]*variance_pos)/(sum*sum*sum*sum)+(4*v2_pos[i]*v2_pos[i]*variance_neg)/(sum*sum*sum*sum); //error bars cout << "xcoord " << x[i] << endl; err_pos[i] = sqrt(variance_pos); err_neg[i] = sqrt(variance_neg); err_diff[i] = sqrt(variance_diff); } gStyle->SetLegendFont(42); TH1D* base = new TH1D("base","base",1,-0.12,0.12); //pPb //base->GetYaxis()->SetRangeUser(0.065, 0.075); base->GetYaxis()->SetRangeUser(range_start, range_end); //PbPb //base->GetYaxis()->SetRangeUser(0.093, 0.103); base->GetXaxis()->SetTitle("Corrected A_{ch}"); base->GetYaxis()->SetTitle("v_{2}{2}"); base->GetXaxis()->CenterTitle(); base->GetYaxis()->CenterTitle(); base->SetTitleSize (0.040,"X"); base->SetTitleOffset(1.4,"X"); base->SetTitleFont (42,"X"); base->SetLabelOffset(0.006,"X"); base->SetLabelSize (0.040,"X"); base->SetLabelFont (42 ,"X"); base->SetTitleSize (0.040,"Y"); base->SetTitleOffset(2.2,"Y"); base->SetTitleFont (42,"Y"); base->SetLabelOffset(0.006,"Y"); base->SetLabelSize (0.040,"Y"); base->SetLabelFont (42 ,"Y"); base->SetLineWidth(0); TH1D* base2 = new TH1D("base2","base2",1,-0.12,0.12); base2->GetYaxis()->SetRangeUser(-0.03, 0.03); base2->GetXaxis()->SetTitle("Corrected A_{ch}"); base2->GetYaxis()->SetTitle(" (v^{#minus}_{2} #minus v^{#plus}_{2})/(v^{#minus}_{2} #plus v^{#plus}_{2}) "); base2->GetXaxis()->CenterTitle(); base2->GetYaxis()->CenterTitle(); base2->SetTitleSize (0.040,"X"); base2->SetTitleOffset(1.4,"X"); base2->SetTitleFont (42,"X"); base2->SetLabelOffset(0.006,"X"); base2->SetLabelSize (0.040,"X"); base2->SetLabelFont (42 ,"X"); base2->SetTitleSize (0.040,"Y"); base2->SetTitleOffset(2.0,"Y"); base2->SetTitleFont (42,"Y"); base2->SetLabelOffset(0.006,"Y"); base2->SetLabelSize (0.040,"Y"); base2->SetLabelFont (42 ,"Y"); base2->SetLineWidth(0); TFile *rebinned = new TFile(Form("~/Summer2016/root_forgraphs/v2_cent_%d_%d.root",mult_start[num],mult_end[num]),"RECREATE"); TGraphErrors *gr_pos = new TGraphErrors(NAchBins,x,v2_pos,NULL,err_pos); TGraphErrors *gr_neg = new TGraphErrors(NAchBins,x,v2_neg,NULL,err_neg); TGraphErrors *gr_diff = new TGraphErrors(NAchBins,x,v2_diff,NULL,err_diff); if(num==0){ gr_pos->RemovePoint(0); gr_pos->RemovePoint(5); gr_neg->RemovePoint(0); gr_neg->RemovePoint(5); gr_diff->RemovePoint(0); gr_diff->RemovePoint(5); } gr_pos->Write(); gr_neg->Write(); gr_diff->Write(); // TCanvas* c1 = new TCanvas("c1","c1"); // TCanvas* c2 = new TCanvas("c2","c2"); TCanvas* c3 = new TCanvas("c3","c3",1,1,1200,600); c3->Divide(2,1,0.01,0.01); gr_neg -> SetMarkerStyle(20); gr_neg -> SetMarkerColor(kBlue); gr_pos -> SetMarkerStyle(34); gr_pos -> SetMarkerColor(kRed); TLatex* text_a = makeLatex("CMS PbPb #sqrt{s_{NN}}=5.02TeV",0.25,0.85) ; //TLatex* text_b = makeLatex("185 #leq N_{trk}^{offline} < 220",0.25,0.80) ; TLatex* text_b = makeLatex(Form("%d-%d centrality",mult_start[num],mult_end[num]),0.25,0.80) ; TLatex* text_c = makeLatex("0.3 < p_{T} < 3.0 GeV/c",0.25,0.75) ; TLatex* text_d = makeLatex("|#Delta#eta| > 1",0.25,0.70) ; text_a->SetTextFont(42); text_b->SetTextFont(42); text_c->SetTextFont(42); text_d->SetTextFont(42); TLegend* leg = new TLegend(0.76,0.80,0.94,.88); leg->SetLineColor(kWhite); leg->SetFillColor(0); leg->SetFillStyle(0); leg->AddEntry(gr_pos, "v_{2}^{#plus}{2}","p"); leg->AddEntry(gr_neg , "v_{2}^{#minus}{2}","p"); c3->cd(1); base->Draw(""); gr_pos->Draw("PSame"); gr_neg->Draw("PSame"); text_a->DrawClone("Same"); text_b->DrawClone("Same"); text_c->DrawClone("Same"); text_d->DrawClone("Same"); leg->DrawClone("Same"); //Define a linear function TF1* fit1 = new TF1("f1", "[0]+x*[1]", -0.13, 0.13); fit1->SetLineColor(kRed); fit1->SetLineStyle(2); gr_diff->Fit(fit1,"RN0"); fit1->Write(); rebinned->Close(); c3->cd(2); TLatex* text2 = makeLatex(Form("Intercept : %f #pm %f",fit1->GetParameter(0),fit1->GetParError(0)),0.45,0.30) ; TLatex* text1 = makeLatex(Form("slope : %.4f #pm %.4f",fit1->GetParameter(1),fit1->GetParError(1)),0.45,0.25) ; text1->SetTextFont(42); text2->SetTextFont(42); base2->Draw(""); fit1->DrawClone("Same"); gr_diff->SetMarkerStyle(20); gr_diff->Draw("PSame"); text_a->DrawClone("Same"); text_b->DrawClone("Same"); text1->DrawClone("Same"); text2->DrawClone("Same"); TF1 *fa1 = new TF1("fa1","0",-10,10); fa1->SetLineColor(kBlack); fa1->SetLineWidth(0); fa1->DrawClone("Same"); TLegend* leg2 = new TLegend(0.25,0.68,0.5,0.78); leg2->SetLineColor(kWhite); leg2->SetFillColor(0); leg2->SetFillStyle(0); leg2->AddEntry(fit1, "Linear fit","l"); leg2->AddEntry(gr_diff , "data","p"); leg2->DrawClone("Same"); cout << mult_start[num] << endl; cout << mult_end[num] << endl; c3->Print(Form("~/Summer2016/pics/v2_cent_%d_%d.pdf",mult_start[num],mult_end[num])); c3->Print(Form("~/Summer2016/pics/v2_cent_%d_%d.gif",mult_start[num],mult_end[num])); }
void slopevscentrality(){ TFile *f; TH1D* c2_pos[5][2]; TH1D* c2_neg[5][2]; TH1D* ach_hist[5]; TH1D* cbinHist; TGraphErrors* gr_diff; TF1* fit1; double x_centrality[6] = {35, 45, 55, 65, 75, 85}; double y_slope[6]; double statErr[6]; double variance_pos = 0.0; double variance_neg = 0.0; double variance_diff = 0.0; double err_neg[5]; double err_pos[5]; double err_diff[5]; double cmean; double errmean; double sum; for (int n = 0; n <6; ++n) { f = new TFile(Form("../../../rootfiles/slope_vs_centrality/PbPb502_%d.root",n+1)); for (Int_t i = 0; i < 5; i++){ ach_hist[i] = (TH1D*)f->Get(Form("demo/ach_%d",i+1)); c2_pos[i][0] = (TH1D*)f->Get(Form("demo/c2pos_%d_cos",i)); c2_pos[i][1] = (TH1D*)f->Get(Form("demo/c2pos_%d_sin",i)); c2_neg[i][0] = (TH1D*)f->Get(Form("demo/c2neg_%d_cos",i)); c2_neg[i][1] = (TH1D*)f->Get(Form("demo/c2neg_%d_sin",i)); } cbinHist = (TH1D*)f->Get("demo/cbinHist"); double x[5]; double v2_pos[5]; double v2_neg[5]; double v2_diff[5]; double r; for(Int_t i=0; i<5; i++){ x[i]=ach_hist[i]->GetMean(); cmean = c2_pos[i][0] -> GetMean(); v2_pos[i] = sqrt(cmean); errmean = c2_pos[i][0] -> GetMeanError(); variance_pos = (errmean*errmean)/(4*cmean); cmean = c2_neg[i][0] -> GetMean(); v2_neg[i] = sqrt(cmean); errmean = c2_neg[i][0] -> GetMeanError(); variance_neg = (errmean*errmean)/(4*cmean); v2_diff[i] = (v2_neg[i] - v2_pos[i]); sum = v2_pos[i] + v2_neg[i]; variance_diff = variance_pos+variance_neg; //error calculation err_pos[i] = sqrt(variance_pos); err_neg[i] = sqrt(variance_neg); err_diff[i] = sqrt(variance_diff); } gr_diff = new TGraphErrors(5,x,v2_diff,NULL, err_diff); fit1 = new TF1("Linear fitting case 1", "[0]+x*[1]", -0.09, 0.09); gr_diff->Fit(fit1); r = fit1->GetParameter(1); statErr[n] = fit1->GetParError(1); cout << "slope is: " << r << endl; y_slope[n] = r; } double x_alice[] = {5,15,25,35,45,55,65,75}; double y_alice[] = { 0.0188127, 0.0252774, 0.0290478, 0.0315681, 0.0313678, 0.0334533, 0.0326948, 0.027709 }; double alice_statErrors[] = { 0.00276672, 0.00491256, 0.00542907, 0.00499819, 0.00427076, 0.00421142, 0.00436631, 0.00480683 }; double alice_sysminus[] = { 0.003345731066792428, 0.005524736668946313, 0.006157316616294797, 0.00591162859559022, 0.0052989413797474684, 0.0053784097301432885, 0.0054547376184835876, 0.005548288155719744 }; double alice_sysplus[] = { 0.003345731066792428, 0.005524736668946313, 0.006157316616294797, 0.00591162859559022, 0.0052989413797474684, 0.0053784097301432885, 0.0054547376184835876, 0.005548288155719744 }; double xsysalice[] = {1,1,1,1,1,1,1,1}; double x_star[] = {2.5,7.5,15.0,25.0,35.0,45.0,55.0,65.0,75.0}; double y_star[] = {-0.033529,0.001979,0.015917,0.028232,0.031986,0.026516,0.028016,0.012459,-0.02195}; double star_statErrors[] = { 0.0010554, 0.00701, 0.003874, 0.003091, 0.002903, 0.002921, 0.003657, 0.005119, 0.009593 }; double star_sysminus[] = { 2.156594920238847, 1.1474282374074642, 0.41413973487218053, 0.40721102637330436, 0.46464817873311415, 0.48750025641018896, 1.2743975557101481, 0.6065696744810114, 0.9645708786812922 }; double star_sysplus[] = { 3.152323796820371, 1.1348034014753392, 0.6881948851887814, 0.3091, 0.3775553601791398, 0.6362180836788593, 0.39244649316817704, 1.060086081410373, 4.931994052105091 }; double xsysstar[] = {1,1,1,1,1,1,1,1,1}; for(i=0;i<9;i++){ star_sysminus[i]/=100; star_sysplus[i]/=100; } gStyle->SetLegendFont(42); TGraphErrors* slopevscent = new TGraphErrors(6,x_centrality,y_slope,NULL,statErr); TGraphErrors* ALICE = new TGraphErrors(8,x_alice,y_alice,NULL,alice_statErrors); TGraphErrors* STAR = new TGraphErrors(9,x_star,y_star,NULL,star_statErrors); TGraphAsymmErrors* ALICE_sys = new TGraphAsymmErrors(8, x_alice, y_alice, xsysalice, xsysalice, alice_sysminus, alice_sysplus); TGraphAsymmErrors* STAR_sys = new TGraphAsymmErrors(9, x_star, y_star, xsysstar, xsysstar, star_sysminus, star_sysplus); slopevscent -> SetMarkerStyle(20); slopevscent -> SetMarkerColor(kBlack); ALICE -> SetMarkerStyle(25); ALICE -> SetMarkerColor(kRed); ALICE -> SetLineColor(kRed); STAR -> SetMarkerStyle(kOpenStar); STAR -> SetMarkerColor(kBlue); STAR -> SetLineColor(kBlue); TH1D* base = new TH1D("base","base",1,0,100); base->GetYaxis()->SetRangeUser(0.00,0.06); base->GetXaxis()->SetTitle("Centrality(%)"); base->GetYaxis()->SetTitle("Slope parameter(v_{2})"); base->GetXaxis()->CenterTitle(); base->GetYaxis()->CenterTitle(); base->SetTitleSize (0.040,"X"); base->SetTitleOffset(1.4,"X"); base->SetTitleFont (42,"X"); base->SetLabelOffset(0.006,"X"); base->SetLabelSize (0.040,"X"); base->SetLabelFont (42 ,"X"); base->SetTitleSize (0.040,"Y"); base->SetTitleOffset(2.2,"Y"); base->SetTitleFont (42,"Y"); base->SetLabelOffset(0.006,"Y"); base->SetLabelSize (0.040,"Y"); base->SetLabelFont (42 ,"Y"); base->SetLineWidth(0); TCanvas* c3 = MakeCanvas("c3","c3"); TLatex* text_a = makeLatex("CMS pPb #sqrt{s_{NN}}=5.02TeV",0.25,0.85) ; TLatex* text_b = makeLatex("185 #leq N_{trk}^{offline} < 260",0.25,0.80) ; TLatex* text_c = makeLatex("0.3 < p_{T} < 3 GeV/c",0.25,0.85) ; TLatex* text_d = makeLatex("|#Delta#eta| > 2",0.25,0.80) ; text_a->SetTextFont(42); text_b->SetTextFont(42); text_c->SetTextFont(42); text_d->SetTextFont(42); slopevscent->SetFillStyle(0); slopevscent->SetFillColor(0); slopevscent->SetFillStyle(0); slopevscent->SetFillColor(0); gStyle->SetOptTitle(0); TLegend* leg = new TLegend(.58,.70,.93,.90); leg->SetLineColor(kWhite); leg->SetFillColor(0); leg->SetFillStyle(0); leg->AddEntry(slopevscent, "CMS, Pb-Pb 5.02TeV","p"); leg->AddEntry(ALICE, "ALICE, Pb-Pb 2.76TeV","p"); leg->AddEntry(STAR, "STAR, Au-Au 200GeV","p"); //leg->AddEntry(gr_neg, "neg","p"); c3->cd(); base->Draw(""); ALICE->Draw("PSame"); STAR->Draw("PSame"); slopevscent->Draw("PSame"); // STAR_sys->Draw("2Same"); leg->DrawClone("PSame"); // text_c->DrawClone("Same"); // text_d->DrawClone("Same"); //Define a linear function //SaveCanvas(c3,"pics","slopevscent_comparison"); }
TF1 *fit(TTree *nt,TTree *ntMC,double ptmin,double ptmax) { //cout<<cut.Data()<<endl; static int count=0; count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",24,5.03,5.99); TH1D *hMC = new TH1D(Form("hMC%d",count),"",24,5.03,5.99); // Fit function TString iNP="Gaus(x,5.36800e+00,5.77122e-02)/(sqrt(2*3.14159)*abs(5.77122e-02))"; TF1 *f = new TF1(Form("f%d",count),"[0]*(Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]))+ [3]+[4]*x+[5]*x*x + [11]*("+iNP+")"); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); clean0(h); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->FixParameter(1,fixparam1); f->SetParLimits(11,0,1000); f->SetParameter(11,10); f->FixParameter(11,0); f->FixParameter(9,0); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi",count),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(11)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); // Bkpi->SetRange(5.00,5.28); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass",count),"[0]*(Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (40 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); double yield = mass->Integral(5,6)/0.040; double yieldErr = mass->Integral(5,6)/0.04*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); // leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f", yield, yieldErr),""); leg2->Draw(); c->SaveAs(Form("PDFVariation/data/2Gto1G/ResultsBs/BMass-%d.pdf",count)); return mass; }
TF1 *fit(TTree *nt,TTree *ntMC,double ptmin,double ptmax){ //cout<<cut.Data()<<endl; static int count=0; count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",50,5,6); TH1D *hMC = new TH1D(Form("hMC%d",count),"",50,5,6); TString iNP="(7.26667e+00*Gaus(x,5.10472e+00,2.63158e-02)/(sqrt(2*3.14159)*2.63158e-02)+4.99089e+01*Gaus(x,4.96473e+00,9.56645e-02)/(sqrt(2*3.14159)*9.56645e-02)+3.94417e-01*(3.74282e+01*Gaus(x,5.34796e+00,3.11510e-02)+1.14713e+01*Gaus(x,5.42190e+00,1.00544e-01)))"; TF1* fNP = new TF1("fNP",iNP); float normNP = fNP->Integral(5,6); TString signal = "([5]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[5])*Gaus(x,[1],[6])/(sqrt(2*3.14159)*[6]))"; TF1 *f = new TF1(Form("f%d",count),Form("[0]*%s+[3]+[4]*x+(%s/%f)*([0]/%f)",signal.Data(),iNP.Data(),Ratio*(1+Change),normNP)); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); clean0(h); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(6,0.01,0.05); f->SetParLimits(5,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(6,setparam3); f->FixParameter(1,fixparam1); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(5,f->GetParameter(5)); f->FixParameter(6,f->GetParameter(6)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); //cout<<"======="<<normNP<<"======="<<endl; // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi",count),Form("([0]/(%f*%f))*%s",Ratio*(1+Change),normNP,iNP.Data())); Bkpi->SetParameter(0,f->GetParameter(0)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); // Bkpi->SetRange(5.00,5.28); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(5),f->GetParameter(6)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); double yield = mass->Integral(5,6)/0.02; double yieldErr = mass->Integral(5,6)/0.02*mass->GetParError(0)/mass->GetParameter(0); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (20 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.5,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B^{+} meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f", yield, yieldErr),""); leg2->Draw(); TLegend *leg3 = myLegend(0.02,0.83,0.37,0.92); if(Change==0) leg3->AddEntry((TObject*)0,Form("Ratio=%.2f",Ratio),""); else leg3->AddEntry((TObject*)0,Form("Ratio=%.2f(%.1f%)",Ratio*(1+Change),Change*100),""); leg3->Draw(); if(Change==0) c->SaveAs("BplusApplyRatio.pdf"); if(Change>0) c->SaveAs("BplusApplyRatioPlus.pdf"); if(Change<0) c->SaveAs("BplusApplyRatioMinus.pdf"); return mass; }
void CutFlow::ratioCutFlowPlot(TH1D* data, THStack *hs, AllSamples samples, Variable variable){ //draw histos with ratio plot float r = 0.3; float epsilon = 0.02; TCanvas *c2 = new TCanvas("Plot","Plot",635, 600); c2->SetFillColor(0); c2->SetFrameFillStyle(0); TPad *pad1 = new TPad("pad1","pad1",0,r-epsilon,1,1); pad1->SetBottomMargin(epsilon); c2->cd(); pad1->Draw(); pad1->cd(); hs->Draw("hist"); hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3); hs->GetXaxis()->SetLimits(variable.minX, variable.maxX); hs->GetXaxis()->SetTitle(variable.xTitle); hs->GetXaxis()->SetTitleSize(0.05); hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05); if(Globals::addHashErrors){ TH1D* hashErrs = hashErrors(samples, variable); hashErrs->Draw("same e2"); } data->Draw("E same"); //data->SetMarkerStyle(20); data->SetMarkerSize(0.5); TLegend* leg = legend(samples); leg->Draw(); TText* textChan = doChan(0.12,0.96); textChan->Draw(); TText* textPrelim = doPrelim(0.58,0.96); textPrelim->Draw(); TPad *pad2 = new TPad("pad2","pad2",0,0,1,r*(1-epsilon)); pad2->SetTopMargin(0); pad2->SetFrameFillStyle(4000); pad2->SetBottomMargin(0.4); c2->cd(); pad2->Draw(); pad2->cd(); TH1D * allMC = allMChisto(samples, variable); TH1D * ratio = (TH1D*)data->Clone("ratio plot"); ratio->Sumw2(); ratio->SetStats(0); cout << "ratio bins: " << ratio->GetNbinsX() << endl; cout << "all mc bins: " << allMC->GetNbinsX() << endl; ratio->Divide(allMC); ratio->SetMaximum(2); ratio->SetMinimum(0.); setBinLabels(hs, ratio); // Will need to see if this works in other situations ratio->SetLabelSize(0.1, "X"); ratio->SetTitleOffset(0.5, "Y"); ratio->SetTitleOffset(0.8, "X"); ratio->GetYaxis()->SetTitle("data/MC");ratio->GetYaxis()->SetTitleSize(0.1); ratio->GetXaxis()->SetTitle(variable.xTitle);ratio->GetXaxis()->SetTitleSize(0.15); ratio->Draw("ep"); TLine *line = new TLine(variable.minX,1,variable.maxX,1); line->Draw(); pad1->cd(); pad1->SetLogy(); c2->SaveAs("Plots/ControlPlots/"+objName+"/Log/"+variable.name+"_ratio.png"); c2->SaveAs("Plots/ControlPlots/"+objName+"/Log/"+variable.name+"_ratio.pdf"); delete c2; delete leg; delete textChan; delete textPrelim; }
//################################################################################################################################ TCanvas *drawRatioPlotWithPurity(TH1D *prediction, TH1D *sr, TString xTitle, TString filename, double purity, bool LowECaloRegion){ TCanvas *c = new TCanvas("c"+filename,"c",0,0,500,500); c->cd(); float y = 0.3; TPad *pad1 = new TPad("pad1", "Control Plots 1", 0.01, y, 0.99, 0.99); TPad *padRatio = new TPad("rp1", "Ratio1", 0.01, 0.01, 0.99, y-0.01); TH1D *ratio = 0; ratio = (TH1D*) sr->Clone(); ratio->Divide(prediction); ratio->GetYaxis()->SetTitle((TString) sr->GetName() + "/" + (TString) prediction->GetName()); ratio->SetTitle(""); ratio->SetLabelSize(0.1,"X"); ratio->SetLabelSize(0.1,"Y"); ratio->SetTitleOffset(0.5,"Y"); ratio->SetTitleSize(0.11,"Y"); ratio->SetLineColor(kBlack); ratio->SetMarkerColor(kBlack); padRatio->cd(); ratio->GetYaxis()->SetRangeUser(0,2); ratio->Draw(); // Draw line at one! float xmin = ratio->GetXaxis()->GetXmin(); float xmax = ratio->GetXaxis()->GetXmax(); TLine *line = new TLine(xmin,1,xmax,1); line->SetLineWidth(2); line->Draw("same"); padRatio->Modified(); TLegend *leg = new TLegend(0.5,0.8,0.85,0.9); leg->AddEntry(sr,sr->GetName(),"l"); leg->AddEntry(prediction,prediction->GetName(),"pel"); pad1->cd(); //pad1->SetLogy(); sr->SetLineColor(kRed); sr->SetMarkerColor(kRed); prediction->SetLineColor(kBlack); prediction->SetMarkerColor(kBlack); sr->SetTitle(""); prediction->SetTitle(""); prediction->GetXaxis()->SetTitle(xTitle); sr->GetXaxis()->SetTitle(xTitle); prediction->SetTitleSize(0.07,"X"); prediction->GetXaxis()->SetTitleOffset(0.7); sr->SetTitleSize(0.07,"X"); sr->GetXaxis()->SetTitleOffset(0.7); prediction->Draw("e"); sr->Draw("e same"); double maximum =prediction->GetMaximum()*1.2; double minimum = 0.00001; if(sr->GetMinimum()!=0) minimum=sr->GetMinimum()*0.9; if(prediction->GetMinimum()!=0) minimum=prediction->GetMinimum()*0.9; if(sr->GetMaximum()>prediction->GetMaximum()){ maximum=sr->GetMaximum()*1.2; } //leg->Draw("same"); //*********************** TLatex* info = new TLatex(); info->SetTextFont(132); info-> SetNDC(); info->SetTextSize(0.06); TString AuxString = Form("Purity of fakes in CR = %4.1f ",purity*100); //info->DrawLatex(0.4,0.7,AuxString); TLatex* info1 = new TLatex(); info1->SetTextFont(132); info1-> SetNDC(); info1->SetTextSize(0.06); if(LowECaloRegion) AuxString = "E_{calo}<10GeV"; else AuxString = "E_{calo}>10GeV"; //info1->DrawLatex(0.2,0.82,AuxString); //*********************** // Draw both pads to canvas c->cd(); pad1->Draw(); padRatio->SetGridy(); c -> SetBottomMargin(0.55); //c->Modified(); padRatio->Draw(); c->SaveAs(filename); return c; }
void compareDressed_darko(std::string mcfilePostfix, std::string var1="h_ystar", float xmin=-9999, float xmax=-9999, float ymin=0.8, float ymax=1.1, bool logScale=false ) { setTDRStyle(); gStyle->SetOptStat(0); TH1D* h_numr; TH1D* h_deno; TH1D* h_both; char tempName[300]; std::string mcfile_numr = "bare_exclusive1Jet_zPt40_" + mcfilePostfix; std::string mcfile_deno = "dressed_exclusive1Jet_zPt40_" + mcfilePostfix; std::string mcfile_both = "both_exclusive1Jet_zPt40_" + mcfilePostfix; std::string mcName_numr="Bare"; std::string mcName_deno="Dressed"; std::string header; std::string output; if(mcfile_numr.find("madgraph")!=std::string::npos) { header="Madgraph"; output="madgraph"; } else if(mcfile_numr.find("sherpa")!=std::string::npos) { header="Sherpa"; output="sherpa"; } if(mcfile_numr.find("electron")!=std::string::npos) { header+= " e"; output+= "E"; } else if(mcfile_numr.find("muon")!=std::string::npos) { header+= " #mu"; output+= "Mu"; } // first get the histogram files TFile *fmc1 = TFile::Open(mcfile_numr.data()); cout << "Reading file 1: " << fmc1->GetName() << endl; TFile *fmc2 = TFile::Open(mcfile_deno.data()); cout << "Reading file 2: " << fmc2->GetName() << endl; TFile *fmc3 = TFile::Open(mcfile_both.data()); cout << "Reading file 3: " << fmc3->GetName() << endl; h_numr = (TH1D*)(fmc1->FindObjectAny(var1.data())); h_deno = (TH1D*)(fmc2->FindObjectAny(var1.data())); h_both = (TH1D*)(fmc3->FindObjectAny(var1.data())); TH1D* hratio =(TH1D*) h_numr->Clone("hratio"); hratio->SetYTitle(Form("%s/%s",mcName_numr.data(),mcName_deno.data())); hratio->SetLineColor(1); hratio->SetMarkerColor(1); h_numr->GetXaxis()->SetNdivisions(5); h_numr->GetYaxis()->SetDecimals(); h_numr->SetTitleOffset(1.2,"Y"); h_deno->GetXaxis()->SetNdivisions(5); h_deno->GetYaxis()->SetDecimals(); h_deno->SetTitleOffset(1.2,"Y"); hratio->GetXaxis()->SetNdivisions(5); hratio->GetYaxis()->SetDecimals(); h_numr->SetLineColor(2); h_numr->SetMarkerColor(2); h_numr->SetMarkerSize(1); h_numr->SetMarkerStyle(24); h_deno->SetLineColor(4); h_deno->SetMarkerColor(4); h_deno->SetMarkerSize(1); h_deno->SetMarkerStyle(21); // if normalizing to the same area, set the scale int binLo = -1; int binHi = -1; int nbins = h_numr->GetNbinsX(); if(xmin>-9999.0 && xmax>-9999.0) { binLo = h_numr->FindBin(xmin); binHi = h_numr->FindBin(xmax)-1; } else { binLo = 1; binHi = nbins; xmin = h_numr->GetBinLowEdge(1); xmax = h_numr->GetBinLowEdge(nbins+1); } cout << "h_numr integral = " << h_numr->Integral() << endl;; cout << "h_deno integral = " << h_deno->Integral() << endl; float area_h_deno = h_deno->Integral(binLo, binHi); h_numr->Sumw2(); h_numr->Scale(1.0/area_h_deno); h_deno->Sumw2(); h_deno->Scale(1.0/area_h_deno); h_both->Sumw2(); h_both->Scale(1.0/area_h_deno); // now use formulas similar to Darko's for error calculation hratio->Reset(); for(int i=1; i<=hratio->GetNbinsX();i++){ double n_n = h_numr->GetBinContent(i); double n_d = h_deno->GetBinContent(i); if(n_d<1e-6)continue; double diff = n_n-n_d; double err_n = h_numr->GetBinError(i); double err_d = h_deno->GetBinError(i); double err_b = h_both->GetBinError(i); double err_y = sqrt(err_n*err_n - err_b*err_b); double err_z = sqrt(err_d*err_d - err_b*err_b); double value = n_n/n_d; double variance = err_b*err_b*diff*diff/n_d/n_d + err_y*err_y + err_z*err_z*value*value; variance /= (n_d*n_d); if(variance < 0){cout << "bin " << i << " has an error in variance" << endl; continue;} variance = sqrt(variance); hratio->SetBinContent(i, value); hratio->SetBinError(i, variance); } for(int i=1;i<=hratio->GetNbinsX();i++) cout << "Bin " << i << " ( " << hratio->GetBinLowEdge(i) << "~" << hratio->GetBinLowEdge(i+1) << " ): " << h_numr->GetBinContent(i) << "/" << h_deno->GetBinContent(i) << " = " << hratio->GetBinContent(i) << " +- " << hratio->GetBinError(i) << endl; h_numr->GetXaxis()->SetRangeUser(xmin,xmax); h_deno->GetXaxis()->SetRangeUser(xmin,xmax); hratio->GetXaxis()->SetRangeUser(xmin,xmax); TCanvas* c1 = new TCanvas("c1","",700,1000); c1->Divide(1,2,0.01,0); c1->cd(1); if(logScale) gPad->SetLogy(1); gPad->SetTopMargin(0.01); gPad->SetBottomMargin(0); gPad->SetRightMargin(0.04); float max_data = h_numr->GetBinError(h_numr->GetMaximumBin()) + h_numr->GetMaximum(); float max_mc = h_deno->GetBinError(h_deno->GetMaximumBin()) + h_deno->GetMaximum(); if(max_data > max_mc) { h_numr->Draw("e"); h_deno->Draw("hesame"); } else { h_deno->Draw("he"); h_numr->Draw("esame"); } float x1NDC = 0.7; float y1NDC = 0.620; float x2NDC = 0.9; float y2NDC = 0.956; TLegend* leg = new TLegend(x1NDC,y1NDC,x2NDC,y2NDC); leg->SetHeader(header.data()); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetTextSize(0.06); leg->SetBorderSize(0); leg->AddEntry(h_numr, mcName_numr.data()); leg->AddEntry(h_deno, mcName_deno.data()); leg->Draw("same"); c1->cd(2); gStyle->SetStatW (0.3); gStyle->SetStatH (0.3); gStyle->SetStatX (0.879447); gStyle->SetStatY (0.939033); gStyle->SetStatFontSize(0.05); gStyle->SetStatBorderSize(0); gPad->SetRightMargin(0.04); gPad->SetTopMargin(0); gPad->SetBottomMargin(0.2); gPad->SetTickx(); gStyle->SetOptFit(1); hratio->SetTitle(""); hratio->SetMaximum(ymax); hratio->SetMinimum(ymin); hratio->SetTitleOffset(1.2,"Y"); hratio->Draw("e1"); TF1* fline = new TF1("fline","pol0"); TLine* l2 = new TLine(xmin,1.,xmax,1.); l2->SetLineColor(4); l2->SetLineStyle(3); fline->SetLineWidth(3); fline->SetLineColor(kMagenta); fline->SetNpx(2500); if(var1.find("ystar")!=std::string::npos) hratio->Fit("fline","","",0,2.0); else if(var1.find("jety")!=std::string::npos) hratio->Fit("fline","","",0,2.4); else if(var1.find("mZ")== std::string::npos && var1.find("zpt")== std::string::npos && var1.find("jetpt")== std::string::npos) hratio->Fit("fline","","",0,2.2); l2->Draw("same"); string dirName = "compareDressed"; gSystem->mkdir(dirName.data()); std::string filename; std::string remword ="h_"; std::string remword2 ="h"; size_t pos = var1.find(remword); if(pos!= std::string::npos) var1.replace(pos,remword2.length(),""); std::string psname = dirName + "/" + var1; if(output !="test") psname = dirName+ "/" + output + var1; else psname = dirName+ "/" + var1; filename = psname + ".eps"; c1->Print(filename.data()); filename = psname + ".gif"; c1->Print(filename.data()); filename = psname + ".pdf"; c1->Print(filename.data()); // c1->Close(); }
void ALICE_Comparison(){ TFile *f = new TFile("~/Summer2016/rootfiles/FinalResult_0104/ALICE_Merged.root"); const int NAchBins = 7; const double correction = 0.731; TH1D* c2_pos[NAchBins][2]; TH1D* c2_neg[NAchBins][2]; TH1D* ach_hist[NAchBins]; double x[NAchBins]; double v2_pos[NAchBins]; double v2_neg[NAchBins]; double v2_diff[NAchBins]; double err_neg[NAchBins]; double err_pos[NAchBins]; double err_diff[NAchBins]; double cmean; double errmean; double sum; double variance_pos; double variance_neg; double variance_diff; double x_alice[10] = {-0.09,-0.07,-0.05,-0.03,-0.01,0.01,0.03,0.05,0.07,0.09}; // double v2_pos_alice[10] = {0.0995,0.0985+0.0005/4,0.098+0.0005/4,0.0975+0.0005*2/3,0.0975+0.0005/6,0.0975,0.097+0.0005/2,0.097+0.0005/2+0.0001}; // double v2_neg_alice[10] = {0.097-0.0005/5,0.097+0.0005/4,0.097+0.0005/2,0.0975,0.0975+0.0005/2,0.098+0.0005/4,0.0985+0.0001,0.0985+0.0005*2/3}; double v2_pos_alice[10] = {0.101486,0.099522,0.0986494,0.0981239,0.0978174,0.0975633,0.0974495,0.0972289,0.0972825,0.0976992}; double v2_neg_alice[10]={0.0991805,0.0968823,0.0971381,0.0972906,0.0974951,0.0977261,0.0981123,0.0986047,0.0988509,0.10041}; double err_pos_alice[10]={0.00199737,0.000688926,0.000277691,0.000144079,0.000101033,8.87595e-05,0.000109954,0.000176882,0.00037035,0.000996611}; double err_neg_alice[10]={0.00196405,0.000663062,0.000268974,0.000141065,0.000100219,8.94285e-05,0.000112572,0.000183565,0.000386812,0.00106967}; double err_diff_alice[10]; double v2_diff_alice[10]; for (int i = 0; i < 10; ++i) { v2_diff_alice[i] = (v2_neg_alice[i]-v2_pos_alice[i])/(v2_neg_alice[i]+v2_pos_alice[i]); sum = v2_pos_alice[i] + v2_neg_alice[i]; variance_pos = err_pos_alice[i]*err_pos_alice[i]; variance_neg = err_neg_alice[i]*err_neg_alice[i]; variance_diff = (4*v2_neg_alice[i]*v2_neg_alice[i]*variance_pos)/(sum*sum*sum*sum)+(4*v2_pos_alice[i]*v2_pos_alice[i]*variance_neg)/(sum*sum*sum*sum); err_diff_alice[i] = sqrt(variance_diff); } double x[NAchBins]; double v2_pos[NAchBins]; double v2_neg[NAchBins]; double err_pos[NAchBins]; double err_neg[NAchBins]; double v2_diff[NAchBins]; double err_diff[NAchBins]; for (Int_t i = 0; i < NAchBins; i++){ ach_hist[i] = (TH1D*)f->Get(Form("demo_n3/ach_%d",i+1)); c2_pos[i][0] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_cos",i)); c2_pos[i][1] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_sin",i)); c2_neg[i][0] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_cos",i)); c2_neg[i][1] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_sin",i)); } for(Int_t i=0; i<NAchBins; i++){ x[i]=ach_hist[i]->GetMean(); x[i] *= correction; //v2 positive cmean = c2_pos[i][0] -> GetMean(); v2_pos[i] = sqrt(cmean); errmean = c2_pos[i][0] -> GetMeanError(); variance_pos = (errmean*errmean)/(4*cmean); //negative cmean = c2_neg[i][0] -> GetMean(); v2_neg[i] = sqrt(cmean); errmean = c2_neg[i][0] -> GetMeanError(); variance_neg = (errmean*errmean)/(4*cmean); //difference v2_diff[i] = (v2_neg[i] - v2_pos[i])/(v2_neg[i] + v2_pos[i]); sum = v2_pos[i] + v2_neg[i]; variance_diff = (4*v2_neg[i]*v2_neg[i]*variance_pos)/(sum*sum*sum*sum)+(4*v2_pos[i]*v2_pos[i]*variance_neg)/(sum*sum*sum*sum); //error bars err_pos[i] = sqrt(variance_pos); err_neg[i] = sqrt(variance_neg); err_diff[i] = sqrt(variance_diff); } gStyle->SetLegendFont(42); TH1D* base = new TH1D("base","base",1,-0.2,0.2); //pPb base->GetYaxis()->SetRangeUser(0.10, 0.11); base->GetXaxis()->SetTitle("Observed A_{ch}"); base->GetYaxis()->SetTitle("v_{2}{SP}"); base->GetXaxis()->CenterTitle(); base->GetYaxis()->CenterTitle(); base->SetTitleSize (0.040,"X"); base->SetTitleOffset(1.4,"X"); base->SetTitleFont (42,"X"); base->SetLabelOffset(0.006,"X"); base->SetLabelSize (0.040,"X"); base->SetLabelFont (42 ,"X"); base->SetTitleSize (0.040,"Y"); base->SetTitleOffset(2.2,"Y"); base->SetTitleFont (42,"Y"); base->SetLabelOffset(0.006,"Y"); base->SetLabelSize (0.040,"Y"); base->SetLabelFont (42 ,"Y"); base->SetLineWidth(0); TH1D* base2 = new TH1D("base2","base2",1,-0.2,0.2); base2->GetYaxis()->SetRangeUser(-0.05, 0.05); base2->GetXaxis()->SetTitle("Observed A_{ch}"); base2->GetYaxis()->SetTitle(" (v^{#minus}_{2} #minus v^{#plus}_{2})/(v^{#minus}_{2} #plus v^{#plus}_{2}) "); base2->GetXaxis()->CenterTitle(); base2->GetYaxis()->CenterTitle(); base2->SetTitleSize (0.040,"X"); base2->SetTitleOffset(1.4,"X"); base2->SetTitleFont (42,"X"); base2->SetLabelOffset(0.006,"X"); base2->SetLabelSize (0.040,"X"); base2->SetLabelFont (42 ,"X"); base2->SetTitleSize (0.040,"Y"); base2->SetTitleOffset(2.0,"Y"); base2->SetTitleFont (42,"Y"); base2->SetLabelOffset(0.006,"Y"); base2->SetLabelSize (0.040,"Y"); base2->SetLabelFont (42 ,"Y"); base2->SetLineWidth(0); cout << v2_pos[0] << endl; TGraphErrors *gr_pos = new TGraphErrors(7,x,v2_pos,NULL,err_pos); TGraphErrors *gr_neg = new TGraphErrors(7,x,v2_neg,NULL,err_neg); TGraphErrors *gr_diff = new TGraphErrors(7,x,v2_diff,NULL,err_diff); TGraphErrors *gr_pos_alice = new TGraphErrors(10,x_alice,v2_pos_alice,NULL,err_pos_alice); TGraphErrors *gr_neg_alice = new TGraphErrors(10,x_alice,v2_neg_alice,NULL,err_neg_alice); TGraphErrors *gr_diff_alice = new TGraphErrors(10,x_alice,v2_diff_alice,NULL,err_diff_alice); TCanvas* c1 = new TCanvas("c1","c1"); TCanvas* c2 = new TCanvas("c2","c2"); gr_neg -> SetMarkerStyle(20); gr_neg -> SetMarkerColor(kBlue); gr_pos -> SetMarkerStyle(34); gr_pos -> SetMarkerColor(kRed); c1->cd(); base->Draw(""); gr_pos->Draw("PSame"); gr_neg->Draw("PSame"); //text_a->Draw("Same"); //text_b->Draw("Same"); //Define a linear function TF1* fit1 = new TF1("f1", "[0]+x*[1]", -0.2, 0.2); TF1* fit2 = new TF1("f2", "[0]+x*[1]", -0.2, 0.2); fit1->SetLineColor(kRed); fit1->SetLineStyle(2); fit2->SetLineColor(kBlue); fit2->SetLineStyle(2); gr_diff->Fit(fit1,"RN0"); gr_diff_alice->Fit(fit2,"RN0"); c2->cd(); base2->Draw(""); TLatex* text2 = makeLatex(Form("CMS Intercept(Red) : %f #pm %f",fit1->GetParameter(0),fit1->GetParError(0)),0.45,0.25) ; TLatex* text1 = makeLatex(Form("CMS slope(Red) : %.4f #pm %.4f",fit1->GetParameter(1),fit1->GetParError(1)),0.45,0.25) ; TLatex* text3 = makeLatex(Form("ALICE Intercept(Blue) : %f #pm %f",fit2->GetParameter(0),fit2->GetParError(0)),0.45,0.35) ; TLatex* text4 = makeLatex(Form("ALICE slope(Blue) : %.4f #pm %.4f",fit2->GetParameter(1),fit2->GetParError(1)),0.45,0.30) ; text1->SetTextFont(42); text2->SetTextFont(42); text3->SetTextFont(42); text4->SetTextFont(42); gr_diff->Draw("PSame"); gr_diff_alice -> SetMarkerStyle(24); gr_diff_alice->Draw("PSame"); text1->DrawClone("Same"); text4->DrawClone("Same"); fit1->DrawClone("Same"); fit2->DrawClone("Same"); TFile *rebinned = new TFile("~/Summer2016/root_forgraphs/figure_alicecomparison.root","RECREATE"); gr_diff->Write(); gr_diff_alice->Write(); fit1->Write(); fit2->Write(); rebinned->Close(); c2->Print("~/Summer2016/comparison_ALICE_ver2.pdf"); c2->Print("~/Summer2016/comparison_ALICE_ver2.gif"); }
void Plot(TString var,TCut cut,TString bins,Double_t xmax,TString cutpoint){ setstyle(); TH1::SetDefaultSumw2(true); TCanvas *c2 = new TCanvas("canvas"+var+cutpoint,"canname"+var+cutpoint,800,800); TPad *mainPad = new TPad("","",0.01,0.25,0.99,0.99); mainPad->SetNumber(1); mainPad->Draw(); TPad *ratioPad = new TPad("","",0.01,0.01,0.99,0.25); ratioPad->SetNumber(2); ratioPad->Draw(); c2->cd(1); // if (cutpoint == "noHT"){ TCut cut = numpj; TCut cutData = numpjData;} // else if (cutpoint == "HT200"){ TCut cut = HT200; TCut cutData = HT200Data; }// // else if (cutpoint == "anoHT"){ TCut cut = anumpj; TCut cutData = anumpjData;} // else if (cutpoint == "aHT200"){ TCut cut = aHT200; TCut cutData = aHT200Data; } // else if (cutpoint == "HT300"){ TCut cut = HT300; TCut cutData = HT300Data;} // else if (cutpoint == "HT350"){ TCut cut = HT350; TCut cutData = HT350Data; } // else if (cutpoint == "aT"){ TCut cut = aT; TCut cutData = aTData;} // else if (cutpoint == "early"){TCut cut = earlyaT; TCut cutData = earlyaTData;} //else{cout << "ERRORRRR: BRaaaaaaaaaaaaaaaaaains" << endl; } TCut cutData = trig && hbhe && cut; TH1D* lm0 = GetHist("LM0",kRed,var,cut,bins,tLM0,cutpoint); /// cout << "lm0" << endl; TH1D* lm1 = GetHist("LM1",kRed,var,cut,bins,tLM1,cutpoint); // cout << "lm1" << endl; TH1D* qcd = GetHist("QCD_AllPtBins_7TeV_Pythia",kOrange+4,var,cut && mu_pt_hi,bins,tQCD,cutpoint); // cout << "qcd" << endl; TH1D* data = GetHist("Data",1,var,cutData,bins,tData,cutpoint); // cout << "data" << endl; TH1D* W = GetHist("Wjets_vols",kBlue,var,cut,bins,tW,cutpoint); //cout << "W" << endl; TH1D* tt = GetHist("ttbarTauola",kGreen,var,cut,bins,tTT,cutpoint); // cout << "tt" << endl; TH1D* Z = GetHist("ZJets_madgraph",kYellow,var,cut,bins,tZ,cutpoint); // cout << "Z" << endl; //TH1D* qcd_lo = GetHist("QCD_AllPtBins_7TeV_Pythia",kOrange+4,var,cut && mu_pt_lo,bins,tQCD,cutpoint); // qcd_lo->Scale(1.94); // qcd->Add(qcd_lo); // TH1D* SM = GetHist("SM",kGray+2,var,cut,binstLM0,cutpoint); lm1->SetLineStyle(2); W->Scale(1.29557302); tt->Scale(1.65789474); Z->Scale(3048./2400.); TH1::SetDefaultSumw2(true); TH1D *SM = (TH1D*)qcd->Clone(); SM->Add(Z); SM->Add(tt); SM->Add(W); //SM->SetLineColor(kGray+2); // SM->SetFillStyle(3001); // SM->SetFillColor(kGray+2); // SM->SetMarkerSize(0.); //for(int bnum = 1; bnum <9; bnum++){ // if(data->GetBinContent(bnum)>0){ // cout << "Bin Number " << bnum << " has qcd " << qcd->GetBinContent(bnum) << " and data " << data->GetBinContent(bnum) << " and SM " << SM->GetBinContent(bnum) << " and scale factor to QCD " << data->GetBinContent(bnum)/qcd->GetBinContent(bnum) << " and scale factor to SM " << data->GetBinContent(bnum)/SM->GetBinContent(bnum) << endl; // } // } c2->cd(1)->SetLogy(); // data->Draw("PE0"); SM->Draw("E"); THStack bkg("bkg","test stacked histograms"); bkg.Add(Z); bkg.Add(tt); bkg.Add(W); bkg.Add(qcd); bkg.Draw("HIST0SAME"); // data->Draw("PE0SAME"); //qcd->Draw("HIST0same"); /* W->Draw("HIST0same"); Z->Draw("HIST0same"); tt->Draw("HIST0same"); */ lm0->Draw("HIST0same"); lm0->SetLineColor(1); lm0->SetFillColor(0); lm1->Draw("HIST0same"); lm1->SetLineColor(1); lm1->SetFillColor(0); lm1->SetLineStyle(2); // data->Draw("EPSAME"); if(xmax == 1337){ double ymax=SM->GetMaximum()*12.6;} else{ double ymax=SM->GetMaximum()*10.6;} SM->GetYaxis()->SetRangeUser(0.05,ymax); if (var=="AlphaT_Lep") { data->GetXaxis()->SetRangeUser(0.,xmax);} SM->GetXaxis()->SetTitle(var); SM->SetTitle(); TLegend *leg = new TLegend(0.73803,0.591026,0.88137,0.880819); // leg->SetShadowColor(0); //leg->SetBorderSize(0); //leg->SetFillStyle(4100); leg->SetTextSize(0.04); leg->SetFillColor(0); leg->SetLineColor(0); // leg->AddEntry(data,"DATA","PL"); leg->AddEntry(qcd,"QCD","FL"); leg->AddEntry(W,"W","FL"); leg->AddEntry(Z,"Z","FL"); leg->AddEntry(tt,"TTbar","FL"); leg->AddEntry(lm0,"LM0","FL"); leg->AddEntry(lm1,"LM1","FL"); //leg->AddEntry(SM,"SM BKGD","FL"); leg->Draw("same"); TLatex *prelim = new TLatex(0.1152,0.81981,"CMS preliminary 2010"); TLatex *lumi = new TLatex(0.1015,.9403,"#scale[0.8]{#int L dt = " +luminum+ "pb^{-1}, #sqrt{s} = 7 TeV}"); prelim->SetNDC(); lumi->SetNDC(); // prelim->Draw("same"); lumi->Draw("same"); TH1D *RatioBottom = (TH1D*)SM->Clone("Ratiob"); TH1D *RatioTop = (TH1D*)data->Clone("Ratiot"); RatioTop->GetYaxis()->SetTitle("data / sim"); RatioTop->GetXaxis()->SetTitle(); RatioTop->Divide(RatioBottom); c2->cd(2); gPad->SetGridx(); gPad->SetGridy(); RatioTop->SetTitleSize(0.1, "XYZ"); RatioTop->SetTitleOffset(0.55, "X"); RatioTop->SetTitleOffset(0.3, "Y"); RatioTop->SetLabelSize(0.06,"XY"); RatioTop->GetYaxis()->SetRangeUser(-2.,4.0); RatioTop->Draw(); RatioTop->GetYaxis()->SetLabelSize(0.05); TBox *unity = new TBox(RatioTop->GetXaxis()->GetBinLowEdge(RatioTop->GetXaxis()->GetFirst()), 0.89,RatioTop->GetXaxis()->GetBinLowEdge(RatioTop->GetXaxis()->GetLast()), 1.11); unity->SetLineWidth(2); unity->SetLineColor(2); unity->SetFillColor(2); unity->SetFillStyle(3002); unity->Draw(); c2->Update(); if(cutpoint == "early"){ c2->SaveAs(plots+erlee+"Muon_ND"+selec+var+"_"+cutpoint+".png"); } else if (xmax == 90003){ c2->SaveAs(plots+"Muon_ND"+selec+"_zooomed_"+var+"_"+cutpoint+".png");} else{ c2->SaveAs(plots+"Muon_ND"+ptsec++selec+var+"_"+cutpoint+".png");} c2->Close(); }
void figure2_0_generator(){ TFile *f; const int NAchBins = 7; const double correction = 0.687; //const double correction = 1.0; TH1D* c2_pos[NAchBins][2]; TH1D* c2_neg[NAchBins][2]; TH1D* ach_hist[NAchBins]; double x[NAchBins]; double v2_pos[NAchBins]; double v2_neg[NAchBins]; double v2_diff[NAchBins]; double err_neg[NAchBins]; double err_pos[NAchBins]; double err_diff[NAchBins]; double cmean; double errmean; double sum; double variance_pos; double variance_neg; double variance_diff; //f = new TFile("../../../rootfiles/systematics/trackselection/loose/Merged.root"); //f = new TFile("../../../rootfiles/systematics/trackselection/tight/Merged.root"); //f = new TFile("../../../rootfiles/systematics/vtz/wide/Merged.root"); //f = new TFile("../../../rootfiles/systematics/vtz/narrow/Merged.root"); //f = new TFile("../../../rootfiles/crosscheck/PbPb/v2/ntrk/185_220/Merged.root"); //f = new TFile("../../../rootfiles/systematics_redo/v2_Cumulant_40.root"); f = new TFile("~/Summer2016/rootfiles/FinalResult_0106/Main_pPb_Merged.root"); // = new TFile("../../../rootfiles/closure/pPb/185_220/Merged.root"); for (Int_t i = 0; i < NAchBins; i++){ ach_hist[i] = (TH1D*)f->Get(Form("demo_n3/ach_%d",i+1)); c2_pos[i][0] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_cos",i)); c2_pos[i][1] = (TH1D*)f->Get(Form("demo_n3/c2pos_%d_sin",i)); c2_neg[i][0] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_cos",i)); c2_neg[i][1] = (TH1D*)f->Get(Form("demo_n3/c2neg_%d_sin",i)); } for(Int_t i=0; i<NAchBins; i++){ x[i]=ach_hist[i]->GetMean(); x[i] *= correction; //v2 positive cmean = c2_pos[i][0] -> GetMean(); v2_pos[i] = sqrt(cmean); errmean = c2_pos[i][0] -> GetMeanError(); variance_pos = (errmean*errmean)/(4*cmean); //negative cmean = c2_neg[i][0] -> GetMean(); v2_neg[i] = sqrt(cmean); errmean = c2_neg[i][0] -> GetMeanError(); variance_neg = (errmean*errmean)/(4*cmean); //difference v2_diff[i] = (v2_neg[i] - v2_pos[i])/(v2_neg[i] + v2_pos[i]); sum = v2_pos[i] + v2_neg[i]; variance_diff = (4*v2_neg[i]*v2_neg[i]*variance_pos)/(sum*sum*sum*sum)+(4*v2_pos[i]*v2_pos[i]*variance_neg)/(sum*sum*sum*sum); //error bars cout << "xcoord " << x[i] << endl; err_pos[i] = sqrt(variance_pos); err_neg[i] = sqrt(variance_neg); err_diff[i] = sqrt(variance_diff); } gStyle->SetLegendFont(42); TH1D* base = new TH1D("base","base",1,-0.15,0.15); //pPb //base->GetYaxis()->SetRangeUser(0.065, 0.075); base->GetYaxis()->SetRangeUser(0.065, 0.075); //PbPb //base->GetYaxis()->SetRangeUser(0.093, 0.103); base->GetXaxis()->SetTitle("Observed A_{ch}"); base->GetYaxis()->SetTitle("v_{2}{2}"); base->GetXaxis()->CenterTitle(); base->GetYaxis()->CenterTitle(); base->SetTitleSize (0.040,"X"); base->SetTitleOffset(1.4,"X"); base->SetTitleFont (42,"X"); base->SetLabelOffset(0.006,"X"); base->SetLabelSize (0.040,"X"); base->SetLabelFont (42 ,"X"); base->SetTitleSize (0.040,"Y"); base->SetTitleOffset(2.2,"Y"); base->SetTitleFont (42,"Y"); base->SetLabelOffset(0.006,"Y"); base->SetLabelSize (0.040,"Y"); base->SetLabelFont (42 ,"Y"); base->SetLineWidth(0); TH1D* base2 = new TH1D("base2","base2",1,-0.15,0.15); base2->GetYaxis()->SetRangeUser(-0.03, 0.03); base2->GetXaxis()->SetTitle("Observed A_{ch}"); base2->GetYaxis()->SetTitle(" (v^{#minus}_{2} #minus v^{#plus}_{2})/(v^{#minus}_{2} #plus v^{#plus}_{2}) "); base2->GetXaxis()->CenterTitle(); base2->GetYaxis()->CenterTitle(); base2->SetTitleSize (0.040,"X"); base2->SetTitleOffset(1.4,"X"); base2->SetTitleFont (42,"X"); base2->SetLabelOffset(0.006,"X"); base2->SetLabelSize (0.040,"X"); base2->SetLabelFont (42 ,"X"); base2->SetTitleSize (0.040,"Y"); base2->SetTitleOffset(2.0,"Y"); base2->SetTitleFont (42,"Y"); base2->SetLabelOffset(0.006,"Y"); base2->SetLabelSize (0.040,"Y"); base2->SetLabelFont (42 ,"Y"); base2->SetLineWidth(0); TFile *rebinned = new TFile("~/Summer2016/root_forgraphs/figure2_0.root","RECREATE"); TGraphErrors *gr_pos = new TGraphErrors(NAchBins,x,v2_pos,NULL,err_pos); TGraphErrors *gr_neg = new TGraphErrors(NAchBins,x,v2_neg,NULL,err_neg); TGraphErrors *gr_diff = new TGraphErrors(NAchBins,x,v2_diff,NULL,err_diff); gr_pos->Write(); gr_neg->Write(); gr_diff->Write(); // TCanvas* c1 = new TCanvas("c1","c1"); // TCanvas* c2 = new TCanvas("c2","c2"); TCanvas* c3 = new TCanvas("c3","c3",1,1,1200,600); c3->Divide(2,1,0.01,0.01); gr_neg -> SetMarkerStyle(20); gr_neg -> SetMarkerColor(kBlue); gr_pos -> SetMarkerStyle(34); gr_pos -> SetMarkerColor(kRed); TLatex* text_a = makeLatex("CMS PbPb #sqrt{s_{NN}}=5.02TeV",0.25,0.85) ; //TLatex* text_b = makeLatex("185 #leq N_{trk}^{offline} < 220",0.25,0.80) ; TLatex* text_b = makeLatex("30-40%",0.25,0.80) ; TLatex* text_c = makeLatex("0.8 < p_{T} < 0.85 GeV/c",0.25,0.75) ; TLatex* text_d = makeLatex("|#Delta#eta| > 2",0.25,0.70) ; text_a->SetTextFont(42); text_b->SetTextFont(42); text_c->SetTextFont(42); text_d->SetTextFont(42); TLegend* leg = new TLegend(0.76,0.80,0.94,.88); leg->SetLineColor(kWhite); leg->SetFillColor(0); leg->SetFillStyle(0); leg->AddEntry(gr_pos, "v_{2}^{#plus}{2}","p"); leg->AddEntry(gr_neg , "v_{2}^{#minus}{2}","p"); c3->cd(1); base->Draw(""); gr_pos->Draw("PSame"); gr_neg->Draw("PSame"); text_a->DrawClone("Same"); text_b->DrawClone("Same"); text_c->DrawClone("Same"); text_d->DrawClone("Same"); leg->DrawClone("Same"); //Define a linear function TF1* fit1 = new TF1("f1", "[0]+x*[1]", -0.13, 0.13); fit1->SetLineColor(kRed); fit1->SetLineStyle(2); gr_diff->Fit(fit1,"RN0"); fit1->Write(); rebinned->Close(); c3->cd(2); TLatex* text2 = makeLatex(Form("Intercept : %f #pm %f",fit1->GetParameter(0),fit1->GetParError(0)),0.45,0.30) ; TLatex* text1 = makeLatex(Form("slope : %.4f #pm %.4f",fit1->GetParameter(1),fit1->GetParError(1)),0.45,0.25) ; text1->SetTextFont(42); text2->SetTextFont(42); base2->Draw(""); fit1->DrawClone("Same"); gr_diff->SetMarkerStyle(20); gr_diff->Draw("PSame"); text_a->DrawClone("Same"); text_b->DrawClone("Same"); text1->DrawClone("Same"); text2->DrawClone("Same"); TF1 *fa1 = new TF1("fa1","0",-10,10); fa1->SetLineColor(kBlack); fa1->SetLineWidth(0); fa1->DrawClone("Same"); TLegend* leg2 = new TLegend(0.25,0.68,0.5,0.78); leg2->SetLineColor(kWhite); leg2->SetFillColor(0); leg2->SetFillStyle(0); leg2->AddEntry(fit1, "Linear fit","l"); leg2->AddEntry(gr_diff , "data","p"); leg2->DrawClone("Same"); //SaveCanvas(c3,"pics",Form("30-40Narrowpt")); }
TCanvas* DrawComparison(TH1D* prediction, TH1D* selection, TString Title, TString LumiTitle, TString xTitle, bool isData) { double MinX = selection->GetXaxis()->GetXmin(); double MaxX = selection->GetXaxis()->GetXmax(); double MaxY = selection->GetMaximum(); double YRangeMax = MaxY; TString titlePrediction; TString titleSelection; TString RatioTitle; if( isData ){ titlePrediction = "Data"; titleSelection = "MC"; RatioTitle = "(Data-MC)/MC"; } else { titlePrediction = "Data-driven Pred. from MC"; titleSelection = "MC Expectation"; RatioTitle = "(Pred-MC)/MC"; } //static Int_t c_LightBrown = TColor::GetColor( "#D9D9CC" ); static Int_t c_LightGray = TColor::GetColor( "#DDDDDD" ); prediction->SetAxisRange(MinX, MaxX, "X"); prediction->GetYaxis()->SetRangeUser(0.005, YRangeMax); prediction->SetMarkerStyle(20); prediction->SetMarkerSize(0.9); prediction->SetMarkerColor(kBlack); prediction->SetXTitle(xTitle); prediction->SetYTitle("Events"); selection->SetAxisRange(MinX, MaxX, "X"); selection->GetYaxis()->SetRangeUser(0.05, YRangeMax); // selection->SetFillColor(c_LightBrown); selection->SetFillColor(c_LightGray); selection->SetTitle(""); selection->SetXTitle(xTitle); selection->SetYTitle("Events"); TCanvas *c = new TCanvas("ca", "Comparison and ratio of two histos", 700, 700); TPad *pad1 = new TPad("pad1a", "pad1a", 0, 0.35, 1, 1); //pad1->SetLogy(); pad1->SetBottomMargin(0); pad1->Draw(); pad1->cd(); selection->DrawCopy("hist"); prediction->Draw("same"); selection->SetFillColor(kAzure-3); selection->SetFillStyle(3354); selection->DrawCopy("e2same"); selection->SetFillStyle(1001); // selection->SetFillColor(c_LightBrown); selection->SetFillColor(c_LightGray); TLegend* leg1 = new TLegend(0.48, 0.63, 0.95, 0.83); leg1->SetFillStyle(0); leg1->SetLineStyle(1); leg1->SetTextFont(42); leg1->SetTextSize(0.04); leg1->AddEntry(selection, titleSelection, "lf"); leg1->AddEntry(prediction, titlePrediction, "lep"); leg1->Draw("same"); TPaveText* pt = new TPaveText(0.11, 0.98, 0.95, 0.86, "NDC"); pt->SetBorderSize(0); pt->SetFillStyle(0); pt->SetTextAlign(12); pt->SetTextSize(0.045); pt->AddText(Title); pt->AddText(LumiTitle); pt->Draw(); c->cd(); TPad *pad2 = new TPad("pad2a", "pad2a", 0, 0, 1, 0.35); pad2->SetTopMargin(0); pad2->Draw(); pad2->cd(); TH1D* r = new TH1D(*selection); r->SetTitle(""); r->SetLabelSize(0.08, "XYZ"); r->SetLabelOffset(0.01, "XYZ"); r->SetTitleSize(0.09, "XYZ"); r->SetTitleOffset(0.65, "Y"); r->SetTickLength(0.05); r->SetYTitle(RatioTitle); r->SetStats(0); r->SetMarkerStyle(20); r->SetMarkerSize(0.9); r->SetMarkerColor(kBlack); r->Reset(); r->Add(prediction, 1); r->Add(selection, -1); r->Divide(selection); r->SetMaximum(1.2); r->SetMinimum(-1.2); r->Draw("ep"); TLine l; l.DrawLine(MinX, 0., MaxX, 0.); c->cd(); return c; }
void compareGen(std::string mcfile1, std::string mcfile2, std::string var1, std::string var2="", std::string xtitle, std::string output="test", std::string header="Z(#rightarrow ee)+#geq 1 jet", std::string mcName1="Data", std::string mcName2="Madgraph", float xmin=-9999.0, float xmax=-9999.0, bool logScale=true ) { setTDRStyle(); gStyle->SetOptStat(0); TH1F* h1; TH1F* h2; char tempName[300]; if(var2 == "" )var2=var1; // first get the histogram files TFile *fmc1 = TFile::Open(mcfile1.data()); TFile *fmc2 = TFile::Open(mcfile2.data()); h1 = (TH1F*)(fmc1->Get(var1.data())); h2 = (TH1F*)(fmc2->Get(var2.data())); TH1D* hscale =(TH1D*) h1->Clone("hscale"); hscale->SetYTitle(Form("%s/%s",mcName1.data(),mcName2.data())); h1->GetXaxis()->SetNdivisions(5); h1->GetYaxis()->SetDecimals(); h2->GetXaxis()->SetNdivisions(5); h2->GetYaxis()->SetDecimals(); hscale->GetXaxis()->SetNdivisions(5); hscale->GetYaxis()->SetDecimals(); h1->SetLineColor(2); h1->SetMarkerColor(2); h1->SetMarkerSize(1); h1->SetMarkerStyle(24); h2->SetLineColor(4); h2->SetMarkerColor(4); h2->SetMarkerSize(1); h2->SetMarkerStyle(21); // if normalizing to the same area, set the scale int binLo = -1; int binHi = -1; int nbins = h1->GetNbinsX(); if(xmin>-9999.0 && xmax>-9999.0) { binLo = h1->FindBin(xmin); binHi = h1->FindBin(xmax)-1; } else { binLo = 1; binHi = nbins; xmin = h1->GetBinLowEdge(1); xmax = h1->GetBinLowEdge(nbins+1); } float scale_mc = (float)h1->Integral(binLo,binHi)/(float)h2->Integral(binLo,binHi); // cout << "binLo = " << binLo << ", binHi = " << binHi << endl; // cout << "xmin = " << xmin << "xmax = " << xmax << endl; // h2->Sumw2(); // // scale_mc = 1000.0*4.890*3048.0/2.29809910000000000e+07; // h2->Scale(scale_mc); cout << "h2 integral = " << h2->Integral() << endl; cout << "h1 integral = " << h1->Integral() << endl;; // get the ratio double chi2 = 0; int realbin = 0; for(int i=1;i<= nbins;i++){ double nmc=h2->GetBinContent(i); double ndata=h1->GetBinContent(i); double nmcerr=h2->GetBinError(i); double ndataerr=h1->GetBinError(i); if(nmc<0 || ndata<0)continue; if(nmcerr==0 && ndataerr==0)continue; if(nmc==0 && ndata==0)continue; double chi2ndef = (nmc-ndata)*(nmc-ndata)/ ( nmcerr*nmcerr+ ndataerr*ndataerr); chi2 += chi2ndef; realbin++; cout << "Bin " << i << " : " << ndata << ", " << nmc; cout << " " << chi2ndef << endl; // now calculate the ratio if(nmc==0 || nmcerr==0 || ndata==0 || ndataerr==0) { hscale->SetBinContent(i,-9999); hscale->SetBinError(i,1e-4); continue; } cout << "Bin " << i << " ratio = " << ndata/nmc << endl; hscale->SetBinContent(i,ndata/nmc); double err = 0; err= (ndata/nmc)*sqrt(pow(nmcerr/nmc,2)+pow(ndataerr/ndata,2)); hscale->SetBinError(i,err); } for(int i=1;i<=hscale->GetNbinsX();i++) cout << i << ": " << hscale->GetBinContent(i) << endl; h1->GetXaxis()->SetRangeUser(xmin,xmax); h2->GetXaxis()->SetRangeUser(xmin,xmax); hscale->GetXaxis()->SetRangeUser(xmin,xmax); TCanvas* c1 = new TCanvas("c1","",700,1000); c1->Divide(1,2,0.01,0); c1->cd(1); if(logScale) gPad->SetLogy(1); gPad->SetTopMargin(0.01); gPad->SetBottomMargin(0); gPad->SetRightMargin(0.04); float max_data = h1->GetBinError(h1->GetMaximumBin()) + h1->GetMaximum(); float max_mc = h2->GetBinError(h2->GetMaximumBin()) + h2->GetMaximum(); if(max_data > max_mc) { h1->Draw("e"); h2->Draw("hesame"); } else { h2->Draw("he"); h1->Draw("esame"); } float x1NDC = 0.725; float y1NDC = 0.615; float x2NDC = 0.928; float y2NDC = 0.951; TLegend* leg = new TLegend(x1NDC,y1NDC,x2NDC,y2NDC); leg->SetHeader(header.data()); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetTextSize(0.04); leg->SetBorderSize(0); leg->AddEntry(h1, mcName1.data()); leg->AddEntry(h2, mcName2.data()); leg->Draw("same"); c1->cd(2); gStyle->SetStatW (0.3); gStyle->SetStatH (0.3); gStyle->SetStatX (0.879447); gStyle->SetStatY (0.939033); gStyle->SetStatFontSize(0.05); gStyle->SetStatBorderSize(0); gPad->SetRightMargin(0.04); gPad->SetTopMargin(0); gPad->SetBottomMargin(0.2); gPad->SetTickx(); gStyle->SetOptFit(1); hscale->SetTitle(""); hscale->GetXaxis()->SetTitle(xtitle.data()); // hscale->SetMaximum(3.0); // hscale->SetMinimum(0.1); hscale->SetMaximum(2.0); hscale->SetMinimum(0.5); hscale->SetTitleOffset(1.2,"Y"); hscale->Draw("e1"); TF1* fline = new TF1("fline","pol1"); TLine* l2 = new TLine(xmin,1.,xmax,1.); l2->SetLineColor(4); l2->SetLineStyle(3); fline->SetLineWidth(3); fline->SetLineColor(6); fline->SetNpx(2500); // hscale->Fit("fline","",""); l2->Draw("same"); string dirName = "compareGen"; gSystem->mkdir(dirName.data()); std::string filename; std::string psname = dirName + "/" + var1; if(output !="test") psname = dirName+ "/" + output; else psname = dirName+ "/" + var1; filename = psname + ".eps"; c1->Print(filename.data()); filename = psname + ".gif"; c1->Print(filename.data()); filename = psname + ".pdf"; c1->Print(filename.data()); // c1->Close(); }
TF1 *fitNP(TTree* nt,double ptmin,double ptmax){ TCanvas *cNP= new TCanvas("cNP","",600,600); TH1D *hNP = new TH1D("hNP","",50,5,6); TString iNP="7.26667*Gaus(x,5.10472e+00,2.63158e-02)/(sqrt(2*3.14159)*2.63158e-02)+4.99089e+01*Gaus(x,4.96473e+00,9.56645e-02)/(sqrt(2*3.14159)*9.56645e-02)+3.94417e-01*(3.74282e+01*Gaus(x,5.34796e+00,3.11510e-02)+1.14713e+01*Gaus(x,5.42190e+00,1.00544e-01))"; TF1 *f = new TF1("fNP","[0]+[1]*x+[2]*("+iNP+")"); nt->Project("hNP","mass",Form("%s&&pt>%f&&pt<%f&&gen!=23333",seldata_2y.Data(),ptmin,ptmax)); //ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); clean0(hNP); hNP->Draw(); f->SetParLimits(1,-1000,0); f->SetParLimits(2,0,1000); hNP->Fit("fNP","q","",5,6); hNP->Fit("fNP","q","",5,6); hNP->SetMarkerSize(0.8); hNP->SetMarkerStyle(20); // function for background shape plotting. take the fit result from f TF1 *background = new TF1("backgroundNP","[0]+[1]*x"); background->SetParameter(0,f->GetParameter(0)); background->SetParameter(1,f->GetParameter(1)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1("massNP","[0]*("+iNP+")"); //cout<<"miaomiaomiao "<<f->GetParameter(2)<<endl; mass->SetParameter(0,f->GetParameter(2)); cout<<"[0]NP: "<<f->GetParameter(2)<<endl; mass->SetLineColor(kGreen+1); mass->SetLineStyle(3); mass->SetFillStyle(3004); mass->SetRange(5,6); hNP->SetMarkerStyle(24); hNP->SetStats(0); hNP->Draw("e"); hNP->SetXTitle("M_{B} (GeV/c^{2})"); hNP->SetYTitle("Entries / (20 MeV/c^{2})"); hNP->GetXaxis()->CenterTitle(); hNP->GetYaxis()->CenterTitle(); hNP->SetTitleOffset(1.,"Y"); hNP->SetAxisRange(0,hNP->GetMaximum()*1.5,"Y"); background->Draw("same"); mass->Draw("same"); f->Draw("same"); double yield = mass->Integral(5,6)/0.02; // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.92); leg->AddEntry(hNP,"CMS Preliminary",""); leg->AddEntry(hNP,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(hNP,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(hNP,"Non-prompt","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Real Non-prompt","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(hNP,"B meson",""); leg2->AddEntry(hNP,Form("N_{B}=%.0f", yield),""); leg2->Draw(); cNP->SaveAs("NonpromptBplus/BMassNP.gif"); return mass; }