void drawTogetherS(TH1F* th1,TH1F* th2){ TPad *pad1 = new TPad("pad1","This is pad1",0.05,0.3,0.95,0.97); TPad *pad2 = new TPad("pad2","This is pad2",0.05,0.02,0.95,0.35); pad1->Draw(); pad2->Draw(); pad1->cd(); drawTwoSameS(th1,th2); pad2->cd(); drawRatio(th1,th2); }
TCanvas* getExtrapolFak(TString plotName, TString label, int verbose, TString outputFileFull, TString outputFileParton, TString outputFileHadron){ // ============================ // Set Root Style // ============================ TStyle myStyle("HHStyle","HHStyle"); setHHStyle(myStyle); TGaxis::SetMaxDigits(2); myStyle.cd(); gROOT->SetStyle("HHStyle"); // open files TFile* fileFull = TFile::Open(outputFileFull , "READ"); TFile* fileParton = TFile::Open(outputFileParton, "READ"); TFile* fileHadron = TFile::Open(outputFileHadron, "READ"); // dont associate new objects with file to be able to close it in the end gROOT->cd(); // get canvas^3 for chosen cross section TCanvas* canvasFull = (TCanvas*)(fileFull ->Get("xSec/sysNo/"+plotName+"Norm")->Clone()); TCanvas* canvasParton = (TCanvas*)(fileParton->Get("xSec/sysNo/"+plotName+"Norm")->Clone()); TCanvas* canvasHadron = (TCanvas*)(fileHadron->Get("xSec/sysNo/"+plotName+"Norm")->Clone()); // get data histos TH1F* dataFull = killEmptyBins((TH1F*)((canvasFull ->GetPrimitive(plotName+"kData"))->Clone())); TH1F* dataRawParton = killEmptyBins((TH1F*)((canvasParton->GetPrimitive(plotName+"kData"))->Clone())); TH1F* dataRawHadron = killEmptyBins((TH1F*)((canvasHadron->GetPrimitive(plotName+"kData"))->Clone())); // use always the correct PS definition: // hadron level for b-quarks and lepton // parton level for all others TH1F* dataPS = ( (plotName.Contains("bq")||plotName.Contains("lep")) ? (TH1F*)dataRawHadron->Clone() : (TH1F*)dataRawParton->Clone() ); // adjust style and labels TString PSlabel = ( (plotName.Contains("bq")||plotName.Contains("lep")) ? "hadron" : "parton" ); int color = kBlue; if(PSlabel=="hadron") color-=4; dataPS->SetLineColor(color); dataPS->SetMarkerColor(color); histogramStyle(*dataFull, kData); dataFull->SetLineWidth(3); dataPS->SetLineWidth(3); if (plotName=="lepPt") dataFull->GetXaxis()->SetRangeUser(0.,199.); else if(plotName=="bqPt" ) dataFull->GetXaxis()->SetRangeUser(0.,399.); else setXAxisRange(dataFull, plotName); double max=dataFull->GetMaximum(); if(max<dataPS->GetMaximum()) max=dataPS->GetMaximum(); dataFull->SetMaximum(1.3*max); dataFull->GetXaxis()->SetTitle(xSecLabelName(plotName)); TString label2=label; TString label3=""; if(label.Contains("/[GeV]")){ label2.ReplaceAll("/[GeV]",""); label3=" / [GeV]"; } label2.ReplaceAll("/ ",""); dataFull->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{d"+label2+"}"+label3); dataFull->GetYaxis()->SetNoExponent(false); dataFull->GetXaxis()->SetNoExponent(true); dataFull->SetTitle(""); // create legend TLegend *leg0 = new TLegend(0.65, 0.762, 0.95, 0.89); leg0->SetFillStyle(0); leg0->SetBorderSize(0); leg0->SetHeader("phase spaces"); leg0->AddEntry(dataFull, "extrapol. parton lv","L"); leg0->AddEntry(dataPS , "restricted "+PSlabel+" lv","L"); // create label TPaveText *headerlabel = new TPaveText(); headerlabel -> SetX1NDC(gStyle->GetPadLeftMargin()); headerlabel -> SetY1NDC(1.0-gStyle->GetPadTopMargin()); headerlabel -> SetX2NDC(1.0-gStyle->GetPadRightMargin()); headerlabel -> SetY2NDC(1.0); headerlabel -> SetTextFont(42); headerlabel -> AddText("comparing 2011 data results"); headerlabel->SetFillStyle(0); headerlabel->SetBorderSize(0); headerlabel->SetTextSize(0.04); headerlabel->SetTextAlign(32); // create extrapolation factor / ratio canvas std::vector<TCanvas*> plotCanvas_; addCanvas(plotCanvas_); plotCanvas_[0]->cd(); plotCanvas_[0]->Draw(); dataFull->Draw("hist"); dataPS->Draw("hist same"); leg0->Draw("same"); headerlabel->Draw("same"); DrawDecayChLabel("e/#mu + Jets Combined"); drawRatio(dataPS, dataFull, 0., 2.4, myStyle, verbose, std::vector<double>(0), PSlabel+" PS", "extrapolated", "hist", kBlack); // close files fileFull ->Close(); fileParton->Close(); fileHadron->Close(); // return return plotCanvas_[0]; }
void ATLASCMSCOMPARISON(TString quantity="ttbarMass"){ bool cmssim=true; // --- // canvas style // --- TStyle myStyle("HHStyle","HHStyle"); setHHStyle(myStyle); myStyle.SetErrorX(0.5); myStyle.cd(); gROOT->SetStyle("HHStyle"); gStyle->SetEndErrorSize(10); gStyle->SetOptFit(0); // --- // top Pt 7 TeV // --- int Nbins7=7; if( quantity=="topPt" ) Nbins7=7; else if(quantity=="ttbarMass") Nbins7=5; else if(quantity=="ttbarY" ) Nbins7=6; // CMS data TGraphAsymmErrors* CMSdata7 = new TGraphAsymmErrors(Nbins7); if(quantity=="topPt"){ CMSdata7->SetPoint( 0, 25.0 , 0.004032 ); CMSdata7->SetPoint( 1, 75.0 , 0.006746 ); CMSdata7->SetPoint( 2, 125.0, 0.004737 ); CMSdata7->SetPoint( 3, 175.0, 0.002506 ); CMSdata7->SetPoint( 4, 225.0, 0.001140 ); CMSdata7->SetPoint( 5, 300.0, 0.000334 ); CMSdata7->SetPoint( 6, 575.0, 0.000019 ); CMSdata7->SetPointError( 0, 25., 25., ( 5.5/100)*0.004032, ( 5.5/100)*0.004032 ); CMSdata7->SetPointError( 1, 25., 25., ( 4.1/100)*0.006746, ( 4.1/100)*0.006746 ); CMSdata7->SetPointError( 2, 25., 25., ( 4.0/100)*0.004737, ( 4.0/100)*0.004737 ); CMSdata7->SetPointError( 3, 25., 25., ( 5.4/100)*0.002506, ( 5.4/100)*0.002506 ); CMSdata7->SetPointError( 4, 25., 25., ( 5.6/100)*0.001140, ( 5.6/100)*0.001140 ); CMSdata7->SetPointError( 5, 50., 50., ( 8.4/100)*0.000334, ( 8.4/100)*0.000334 ); CMSdata7->SetPointError( 6, 225.,225., (14.1/100)*0.000019, (14.1/100)*0.000019 ); } else if(quantity=="ttbarMass"){ CMSdata7->SetPoint( 0, 350.0 , 0.002588 ); CMSdata7->SetPoint( 1, 500.0 , 0.002685 ); CMSdata7->SetPoint( 2, 625.0 , 0.000953 ); CMSdata7->SetPoint( 3, 825.0 , 0.000232 ); CMSdata7->SetPoint( 4, 1725.0, 0.000008 ); CMSdata7->SetPointError( 0, 100., 100., ( 4.9 /100)*0.002588, (4.9 /100)*0.002588 ); CMSdata7->SetPointError( 1, 50. , 50. , ( 6.9 /100)*0.002685, (6.9 /100)*0.002685 ); CMSdata7->SetPointError( 2, 75. , 75. , ( 7.7 /100)*0.000953, (7.7 /100)*0.000953 ); CMSdata7->SetPointError( 3, 125., 125., ( 14.4/100)*0.000232, (14.4/100)*0.000232 ); CMSdata7->SetPointError( 4, 775., 775., ( 27.6/100)*0.000008, (27.6/100)*0.000008 ); } else if(quantity=="ttbarY"){ CMSdata7->SetPoint( 0, -1.75, 0.082140 ); CMSdata7->SetPoint( 1, -0.75, 0.318979 ); CMSdata7->SetPoint( 2, -0.25, 0.427823 ); CMSdata7->SetPoint( 3, 0.25, 0.44591 ); CMSdata7->SetPoint( 4, 0.75, 0.318820 ); CMSdata7->SetPoint( 5, 1.75, 0.080457 ); CMSdata7->SetPointError( 0, 0.75, 0.75, (8.1/100)*0.082140, (8.1/100)*0.082140 ); CMSdata7->SetPointError( 1, 0.25, 0.25, (3.3/100)*0.318979, (3.3/100)*0.318979 ); CMSdata7->SetPointError( 2, 0.25, 0.25, (3.0/100)*0.427823, (3.0/100)*0.427823 ); CMSdata7->SetPointError( 3, 0.25, 0.25, (3.5/100)*0.44591 , (3.5/100)*0.44591 ); CMSdata7->SetPointError( 4, 0.25, 0.25, (3.5/100)*0.318820, (3.5/100)*0.318820 ); CMSdata7->SetPointError( 5, 0.75, 0.75, (5.9/100)*0.080457, (5.9/100)*0.080457 ); } CMSdata7->SetLineWidth(3.); CMSdata7->SetMarkerSize(1.2); CMSdata7->SetMarkerStyle(24); CMSdata7->SetLineStyle(1); CMSdata7->SetMarkerColor(kBlue); CMSdata7->SetLineColor(kBlue); CMSdata7->SetFillStyle(3004); CMSdata7->SetFillColor(kBlue); // CMS MadGraph+Pythia(Z2*) TGraphAsymmErrors* CMSMadGraph7 = new TGraphAsymmErrors(Nbins7); if(quantity=="topPt"){ CMSMadGraph7->SetPoint( 0, 25.0 , 0.003331 ); CMSMadGraph7->SetPoint( 1, 75.0 , 0.006495 ); CMSMadGraph7->SetPoint( 2, 125.0, 0.005077 ); CMSMadGraph7->SetPoint( 3, 175.0, 0.002748 ); CMSMadGraph7->SetPoint( 4, 225.0, 0.001282 ); CMSMadGraph7->SetPoint( 5, 300.0, 0.000413 ); CMSMadGraph7->SetPoint( 6, 575.0, 0.000027 ); CMSMadGraph7->SetPointError( 0, 25., 25., 0., 0. ); CMSMadGraph7->SetPointError( 1, 25., 25., 0., 0. ); CMSMadGraph7->SetPointError( 2, 25., 25., 0., 0. ); CMSMadGraph7->SetPointError( 3, 25., 25., 0., 0. ); CMSMadGraph7->SetPointError( 4, 25., 25., 0., 0. ); CMSMadGraph7->SetPointError( 5, 50., 50., 0., 0. ); CMSMadGraph7->SetPointError( 6, 225., 225., 0., 0. ); } else if(quantity=="ttbarMass"){ CMSMadGraph7->SetPoint( 0, 350.0 , 0.002541 ); CMSMadGraph7->SetPoint( 1, 500.0 , 0.002759 ); CMSMadGraph7->SetPoint( 2, 625.0 , 0.000988 ); CMSMadGraph7->SetPoint( 3, 825.0 , 0.000222 ); CMSMadGraph7->SetPoint( 4, 1725.0, 0.000008 ); CMSMadGraph7->SetPointError( 0, 100., 100., 0., 0. ); CMSMadGraph7->SetPointError( 1, 50. , 50. , 0., 0. ); CMSMadGraph7->SetPointError( 2, 75. , 75. , 0., 0. ); CMSMadGraph7->SetPointError( 3, 125., 125., 0., 0. ); CMSMadGraph7->SetPointError( 4, 775., 775., 0., 0. ); } else if(quantity=="ttbarY"){ CMSMadGraph7->SetPoint( 0, -1.75, 0.088374 ); CMSMadGraph7->SetPoint( 1, -0.75, 0.319964 ); CMSMadGraph7->SetPoint( 2, -0.25, 0.414022 ); CMSMadGraph7->SetPoint( 3, 0.25, 0.415108 ); CMSMadGraph7->SetPoint( 4, 0.75, 0.320370 ); CMSMadGraph7->SetPoint( 5, 1.75, 0.088218 ); CMSMadGraph7->SetPointError( 0, 0.75, 0.75, 0., 0. ); CMSMadGraph7->SetPointError( 1, 0.25, 0.25, 0., 0. ); CMSMadGraph7->SetPointError( 2, 0.25, 0.25, 0., 0. ); CMSMadGraph7->SetPointError( 3, 0.25, 0.25, 0., 0. ); CMSMadGraph7->SetPointError( 4, 0.25, 0.25, 0., 0. ); CMSMadGraph7->SetPointError( 5, 0.75, 0.75, 0., 0. ); } CMSMadGraph7->SetLineWidth(3.); CMSMadGraph7->SetMarkerSize(1.2); CMSMadGraph7->SetLineStyle(1); CMSMadGraph7->SetMarkerStyle(20); CMSMadGraph7->SetMarkerColor(kAzure+6); CMSMadGraph7->SetLineColor(kAzure+6); // ATLAS data TGraphAsymmErrors* ATLASdata7 = new TGraphAsymmErrors(Nbins7); if(quantity=="topPt"){ ATLASdata7->SetPoint( 0, 25.0 , 0.0034 ); ATLASdata7->SetPoint( 1, 75.0 , 0.0067 ); ATLASdata7->SetPoint( 2, 125.0, 0.0052 ); ATLASdata7->SetPoint( 3, 175.0, 0.00266 ); ATLASdata7->SetPoint( 4, 225.0, 0.00114 ); ATLASdata7->SetPoint( 5, 300.0, 0.00033 ); ATLASdata7->SetPoint( 6, 575.0, 0.000018); ATLASdata7->SetPointError( 0, 25., 25., (4.47 /100)*0.0034 , (4.47 /100)*0.0034 ); ATLASdata7->SetPointError( 1, 25., 25., (1.41 /100)*0.0067 , (1.41 /100)*0.0067 ); ATLASdata7->SetPointError( 2, 25., 25., (2.83 /100)*0.0052 , (2.83 /100)*0.0052 ); ATLASdata7->SetPointError( 3, 25., 25., (3.61 /100)*0.00266 , (3.61 /100)*0.00266 ); ATLASdata7->SetPointError( 4, 25., 25., (3.61 /100)*0.00114 , (3.61 /100)*0.00114 ); ATLASdata7->SetPointError( 5, 50., 50., (5.83 /100)*0.00033 , (5.83 /100)*0.00033 ); ATLASdata7->SetPointError( 6, 225., 225., (11.66/100)*0.000018, (11.66/100)*0.000018 ); } else if(quantity=="ttbarMass"){ ATLASdata7->SetPoint( 0, 350.0 , 0.00250 ); ATLASdata7->SetPoint( 1, 500.0 , 0.00273 ); ATLASdata7->SetPoint( 2, 625.0 , 0.00102 ); ATLASdata7->SetPoint( 3, 825.0 , 0.00023 ); ATLASdata7->SetPoint( 4, 1725.0, 0.0000076 ); ATLASdata7->SetPointError( 0, 100., 100., 0.00008 , 0.00008 ); ATLASdata7->SetPointError( 1, 50. , 50. , 0.00007 , 0.00007 ); ATLASdata7->SetPointError( 2, 75. , 75. , 0.00004 , 0.00004 ); ATLASdata7->SetPointError( 3, 125., 125., 0.00001 , 0.00001 ); ATLASdata7->SetPointError( 4, 775., 775., 0.0000005, 0.0000005 ); } else if(quantity=="ttbarY"){ ATLASdata7->SetPoint( 0, -1.75, 0.081 ); ATLASdata7->SetPoint( 1, -0.75, 0.321 ); ATLASdata7->SetPoint( 2, -0.25, 0.436 ); ATLASdata7->SetPoint( 3, 0.25, 0.423 ); ATLASdata7->SetPoint( 4, 0.75, 0.321 ); ATLASdata7->SetPoint( 5, 1.75, 0.087 ); ATLASdata7->SetPointError( 0, 0.75, 0.75, 0.003, 0.003); ATLASdata7->SetPointError( 1, 0.25, 0.25, 0.009, 0.009); ATLASdata7->SetPointError( 2, 0.25, 0.25, 0.009, 0.009); ATLASdata7->SetPointError( 3, 0.25, 0.25, 0.007, 0.007); ATLASdata7->SetPointError( 4, 0.25, 0.25, 0.005, 0.005); ATLASdata7->SetPointError( 5, 0.75, 0.75, 0.005, 0.005); } ATLASdata7->SetLineWidth(3.); ATLASdata7->SetMarkerSize(1.2); ATLASdata7->SetMarkerStyle(22); ATLASdata7->SetLineStyle(2); ATLASdata7->SetMarkerColor(kRed); ATLASdata7->SetLineColor(kRed); ATLASdata7->SetFillStyle(3005); ATLASdata7->SetFillColor(kRed); // --- // dummy plots for axis // --- // create variable bin edges std::map<TString, std::vector<double> > binning_ = makeVariableBinning(false); std::vector<double> newTopBins_; if(quantity=="topPt"){ newTopBins_.push_back(0.); newTopBins_.push_back(50.); newTopBins_.push_back(100.); newTopBins_.push_back(150.); newTopBins_.push_back(200.); newTopBins_.push_back(250.); newTopBins_.push_back(350.); newTopBins_.push_back(800.); } else if(quantity=="ttbarMass"){ newTopBins_.push_back(250.); newTopBins_.push_back(450.); newTopBins_.push_back(550.); newTopBins_.push_back(700.); newTopBins_.push_back(950.); newTopBins_.push_back(2500.); } else if(quantity=="ttbarY" ){ newTopBins_.push_back(-2.5); newTopBins_.push_back(-1.0); newTopBins_.push_back(-0.5); newTopBins_.push_back(0. ); newTopBins_.push_back(0.5 ); newTopBins_.push_back(1.0 ); newTopBins_.push_back(2.5 ); } binning_[quantity]=newTopBins_; double start=0.; double range=800.; int Nfinebins=800; if(quantity=="topPt"){ Nfinebins=800; start=0.; range=800.;} else if(quantity=="ttbarMass"){ Nfinebins=2250; start=250.; range=2500.; } else if(quantity=="ttbarY" ){ Nfinebins=500 ; start=-2.5; range=2.5;} TH1F* dummy= new TH1F("","",Nfinebins,start,range); reBinTH1F(*dummy, binning_[quantity], 0); histogramStyle(*dummy, kSig); TString label="p_{T}^{t} [GeV]"; TString label2="p_{T}^{t}"; if(quantity=="topPt"){label="p_{T}^{t} [GeV]"; label2="p_{T}^{t}";} else if(quantity=="ttbarMass"){ label="m^{t#bar{t}} [GeV]"; label2="m^{t#bar{t}}"; } else if(quantity=="ttbarY" ){ label="y^{t#bar{t}}"; label2=label; } dummy->GetXaxis()->SetTitle(label); dummy->GetYaxis()->SetTitle(TString("#frac{1}{#sigma} #frac{d#sigma}{")+label2+"}"); double max=0.01; double min=0.; if(quantity=="topPt" ){max=0.01 ; min=0.;} if(quantity=="ttbarMass"){max=0.004; min=0.;} if(quantity=="ttbarY" ){max=1.0 ; min=0.;} dummy->SetMaximum(max); dummy->SetMinimum(min); TH1F* A=convertToHist(ATLASdata7, dummy, Nbins7); TH1F* C=convertToHist(CMSdata7 , dummy, Nbins7); histogramStyle(*A, kSig, true, 1.2, kRed); A->SetLineWidth(3.); A->SetMarkerSize(1.2); A->SetMarkerStyle(22); A->SetLineStyle(1); A->SetMarkerColor(kRed); A->SetLineColor(kRed); A->SetFillStyle(3005); histogramStyle(*C, kSig, true, 1.2, kBlue); C->SetLineWidth(3.); C->SetMarkerSize(1.2); C->SetMarkerStyle(24); C->SetLineStyle(1); C->SetMarkerColor(kBlue); C->SetLineColor(kBlue); C->SetFillStyle(3004); TH1F* M=convertToHist(CMSMadGraph7 , dummy, Nbins7); histogramStyle(*M, kSig, false, 1.2, kAzure+6); M->SetLineWidth(3.); M->SetMarkerSize(1.2); M->SetMarkerStyle(22); M->SetLineStyle(1); M->SetMarkerColor(kAzure+6); M->SetLineColor(kAzure+6); // --- // legend // --- TLegend *leg0 = new TLegend(0.45, 0.65, 0.95, 0.85); leg0->SetFillStyle(0); leg0->SetBorderSize(0); leg0->SetHeader("#sqrt{s}=7TeV data (e/#mu channel)"); TLegend *leg1=(TLegend*)leg0->Clone(); if(cmssim) leg0->AddEntry( CMSMadGraph7, "CMS MadGraph+Pythia(Z2*)", "LP"); leg0->AddEntry( CMSdata7 , "CMS data in ATLAS binning" , "LP"); leg0->AddEntry( ATLASdata7 , "ATLAS data" , "LP"); leg1->AddEntry( ATLASdata7 , "ATLAS (ATLAS-CONF-2013-099)" , "FP"); leg1->AddEntry( CMSdata7 , "CMS (TOP-11-013 in ATLAS binning)" , "FP"); if(cmssim) leg1->AddEntry( CMSMadGraph7, "CMS MadGraph+Pythia(Z2*)", "LP"); // --- // privatworklabel // --- TPaveText *privatworklabel = new TPaveText(); privatworklabel -> SetX1NDC(gStyle->GetPadLeftMargin()); privatworklabel -> SetY1NDC(1.0-gStyle->GetPadTopMargin()); privatworklabel -> SetX2NDC(1.0-gStyle->GetPadRightMargin()); privatworklabel -> SetY2NDC(1.0); privatworklabel -> SetTextFont(42); privatworklabel -> AddText("private work"); privatworklabel->SetFillStyle(0); privatworklabel->SetBorderSize(0); privatworklabel->SetTextSize(0.04); privatworklabel->SetTextAlign(32); // canvas std::vector<TCanvas*> plotCanvas_; // a) linear addCanvas(plotCanvas_); plotCanvas_[plotCanvas_.size()-1]->cd(0); plotCanvas_[plotCanvas_.size()-1]->SetTitle(quantity+" measurement comparison"); // drawing dummy->Draw("axis"); if(cmssim) CMSMadGraph7->Draw("p e1 same"); ATLASdata7 ->Draw("p e2 same"); CMSdata7 ->Draw("p e2 same"); leg0 ->Draw("same"); privatworklabel->Draw("same"); // b) log scale TH1F* dummy2=(TH1F*)dummy->Clone(); dummy2->SetMinimum(0.00001); dummy2->SetMaximum(max*10); addCanvas(plotCanvas_); plotCanvas_[plotCanvas_.size()-1]->cd(0); plotCanvas_[plotCanvas_.size()-1]->SetTitle(quantity+" measurement comparison"); plotCanvas_[plotCanvas_.size()-1]->SetLogy(); // drawing dummy2->Draw("axis"); if(cmssim) CMSMadGraph7->Draw("p e1 same"); CMSdata7 ->Draw("p e2 same"); ATLASdata7 ->Draw("p e2 same"); leg0 ->Draw("same"); privatworklabel->Draw("same"); // c) both data with bands addCanvas(plotCanvas_); plotCanvas_[plotCanvas_.size()-1]->cd(0); plotCanvas_[plotCanvas_.size()-1]->SetTitle(quantity+" measurement comparison"); // drawing dummy->Draw("axis"); //DrawSteps(C, "e2 same"); //C->Draw("e2 same"); //DrawSteps(A, "e2 same"); //A->Draw("e2 same"); if(cmssim) CMSMadGraph7->Draw("p e1 same"); CMSdata7 ->Draw("p e2 same"); ATLASdata7 ->Draw("p e2 same"); // new pad for log plot TPad *rPad = new TPad("rPad","",0.4,0.15,0.95,0.85); rPad->SetFillStyle(0); rPad->SetFillColor(0); rPad->SetBorderSize(0); rPad->SetBorderMode(0); rPad->SetLogy(0); rPad->SetLogx(0); rPad->SetTicky(1); rPad->Draw(""); rPad->cd(); // log plot curves rPad->SetLogy(); dummy2->Draw("axis"); if(cmssim) CMSMadGraph7->Draw("p e1 same"); CMSdata7 ->Draw("p e2 same"); ATLASdata7 ->Draw("p e2 same"); leg1->Draw("same"); privatworklabel->Draw("same"); // d) both data with ratio addCanvas(plotCanvas_); plotCanvas_[plotCanvas_.size()-1]->cd(0); plotCanvas_[plotCanvas_.size()-1]->SetTitle(quantity+" measurement comparison"); // drawing dummy->Draw("axis"); if(cmssim) CMSMadGraph7->Draw("p e1 same"); //DrawSteps(C, "e2 same"); //C->Draw("e2 same"); //DrawSteps(A, "e2 same"); //A->Draw("e2 same"); CMSdata7 ->Draw("p e2 same"); ATLASdata7 ->Draw("p e2 same"); leg1 ->Draw("same"); privatworklabel->Draw("same"); std::vector<double> errA_; for(int bin=1; bin<=Nbins7; ++bin){ errA_.push_back((ATLASdata7->GetY()[bin-1]/CMSdata7->GetY()[bin-1])*((ATLASdata7->GetErrorYhigh(bin-1)/ATLASdata7->GetY()[bin-1]))); } std::vector<double> errC_; for(int bin=1; bin<=Nbins7; ++bin){ errC_.push_back((CMSdata7->GetErrorYhigh(bin-1)/CMSdata7->GetY()[bin-1])); } if(cmssim){ std::vector<double> errM_; for(int bin=1; bin<=Nbins7; ++bin){ errM_.push_back(0.); //errM_.push_back((CMSMadGraph7->GetY()[bin-1]/CMSdata7->GetY()[bin-1])*((CMSMadGraph7->GetErrorYhigh(bin-1)/CMSMadGraph7->GetY()[bin-1]))); } drawRatio(M, C, 0.5, 1.5, myStyle, 0, errM_, "x", "CMS data", "hist ", kAzure+6, false, 0.7); drawRatio(C, C, 0.5, 1.5, myStyle, 0, errC_, "x", "CMS data", "p e2 same" , kBlue, true, 0.7); } else drawRatio(C, C, 0.5, 1.5, myStyle, 0, errC_, "x", "CMS data", "p e2" , kBlue, true, 0.7); drawRatio(A, C, 0.5, 1.5, myStyle, 0, errA_, "x", "CMS data", "p e2 same", kRed , true, 0.7); //saving TString path="./diffXSecFromSignal/plots/combined/2012/comparisonATLAS/"; plotCanvas_[0]->Print(path+quantity+"ATLASvsCMS7TeV.eps"); plotCanvas_[0]->Print(path+quantity+"ATLASvsCMS7TeV.png"); plotCanvas_[1]->Print(path+quantity+"ATLASvsCMS7TeVLog.eps"); plotCanvas_[1]->Print(path+quantity+"ATLASvsCMS7TeVLog.png"); plotCanvas_[2]->Print(path+quantity+"ATLASvsCMS7TeVNoratio.eps"); plotCanvas_[2]->Print(path+quantity+"ATLASvsCMS7TeVNoratio.png"); plotCanvas_[plotCanvas_.size()-1]->Print(path+quantity+"ATLASvsCMS7TeVratio.eps"); plotCanvas_[plotCanvas_.size()-1]->Print(path+quantity+"ATLASvsCMS7TeVratio.png"); plotCanvas_[plotCanvas_.size()-1]->SetTitle(quantity); saveToRootFile("ATLASvsCMSDataComparisonPlots.root", plotCanvas_[plotCanvas_.size()-1], true, 0,""); }
void ATLASCompTreeSGsamples(bool save = true, int verbose=1, int binning=0, TString outputfolder="./diffXSecFromSignal/plots/combined/2012/ttgencomparison/") { //void ATLASCompTreeSGsamples(bool save = true, int verbose=1, int binning=0, TString outputfolder="./ttgencomparison/"){ // binning= 0:fine binning, 1:ATLAS, 2:CMS bool debug = verbose>0 ? true : false; bool debug2 = verbose>1 ? true : false; bool excludeATLAS=true; // ============================ // documentation on how to run // ---------------------------- // run via root -q -b -l ATLASCompTreeSGsamples.C++g // a) parameters // - choose binning via "binning"= 0:fine binning, 1:ATLAS, 2:CMS // - choose output level via "verbose"= 0: minimal, 1: detailed, 2: debug // - choose via "save" whether you want to save single plots as eps and in rootfile and all plots in one pdf // - choose destination where plots are save via "outputfolder" // - change the binning in "makeVariableBinningA" // have fun, Martin // ============================ // ============================ // Set Root Style // ============================ TStyle myStyle("HHStyle","HHStyle"); setHHStyle(myStyle); myStyle.SetStripDecimals(true); myStyle.cd(); gROOT->SetStyle("HHStyle"); gROOT->ForceStyle(); TGaxis::SetMaxDigits(2); // ============================ // load rootfiles // ============================ std::vector<TFile* > file_; //file_.push_back(TFile::Open("/afs/naf.desy.de/group/cms/scratch/tophh/RecentAnalysisRun/combinedDiffXSecSigFall11PFLarge.root" , "Open")); file_.push_back(TFile::Open("/afs/cern.ch/work/i/iasincru/public/TopLHCWG_DiffXSex_CMS/MC_theory_samples/CMSttbarMadGraphZ2Pythia6CTEQ6L1Fall11MCProductionCycle.root", "Open")); file_.push_back(TFile::Open("/afs/cern.ch/work/i/iasincru/public/TopLHCWG_DiffXSex_CMS/MC_theory_samples/CMSttbarPowhegZ2Pythia6CTEQ6MFall11MCProductionCycle.root" , "Open")); file_.push_back(TFile::Open("/afs/cern.ch/work/i/iasincru/public/TopLHCWG_DiffXSex_CMS/MC_theory_samples/CMSttbarPowhegAUET2Herwig6CTEQ6MFall11MCProductionCycle.root", "Open")); file_.push_back(TFile::Open("/afs/cern.ch/work/i/iasincru/public/TopLHCWG_DiffXSex_CMS/MC_theory_samples/[email protected]" , "Open")); file_.push_back(TFile::Open("/afs/cern.ch/user/d/disipio/public/toplhcwg/ntuples_atlas/AlpgenJimmyttbarlnqq.root" , "Open")); //file_.push_back(TFile::Open("/afs/cern.ch/user/d/disipio/public/toplhcwg/ntuples_atlas/AlpGenPythia_P2011_CTEQ5L_ttbarlnqq.root" , "Open")); file_.push_back(TFile::Open("/afs/cern.ch/user/d/disipio/public/toplhcwg/ntuples_atlas/TTbar_PowHeg_Pythia_P2011C.root" , "Open")); file_.push_back(TFile::Open("/afs/cern.ch/user/d/disipio/public/toplhcwg/ntuples_atlas/TTbar_PowHeg_Pythia_AUET2.root" , "Open")); file_.push_back(TFile::Open("/afs/cern.ch/user/d/disipio/public/toplhcwg/ntuples_atlas/TTbar_PowHeg_Jimmy.root" , "Open")); file_.push_back(TFile::Open("/afs/cern.ch/user/d/disipio/public/toplhcwg/ntuples_atlas/T1_McAtNlo_Jimmy.root" , "Open")); // list plots of relevance std::vector<TString> plotList_, axisLabel_; TString plots1D[ ] = { // KinFit plots before prob cut "topPt", "topY", "ttbarPt", "ttbarY", "ttbarMass", //"decayChannel", }; TString axisLabel1D[ ] = { // KinFit plots before prob cut "p_{T}^{t} #left[GeV#right];#Top quarks (norm.);0;20", "y^{t};#Top quarks (norm.);0;1", "p_{T}^{t#bar{t}} #left[GeV#right];t#bar{t} pairs (norm.);0;20", "y^{t#bar{t}};t#bar{t} pairs (norm.);0;1", "m^{t#bar{t}} #left[GeV#right];t#bar{t} pairs (norm.);0;50", //"t#bar{t} decay Channel;relative #Top-quark pairs;0;1", }; plotList_ .insert(plotList_ .begin(), plots1D , plots1D + sizeof(plots1D )/sizeof(TString)); axisLabel_.insert(axisLabel_.begin(), axisLabel1D, axisLabel1D+ sizeof(axisLabel1D)/sizeof(TString)); if(plotList_.size() != axisLabel_.size()) { std::cout << "ERROR - 1D plots: Number of plots and axis label do not correspond .... Exiting macro!" << std::endl; exit(1); } // run automatically in batch mode if there are many canvas if(plotList_.size()>15) gROOT->SetBatch(); // create canvas container std::vector<TCanvas*> plotCanvas_, plotCanvas2_; // create legend TLegend* leg = new TLegend(0.4, 0.5, 0.85, 0.88); legendStyle(*leg ,"#bf{t#bar{t} simulation, #sqrt{s}=7 TeV}" ); TLegend* leg2= new TLegend(0.4, 0.6, 0.85, 0.88); legendStyle(*leg2,"#bf{t#bar{t} PYTHIA simulation, #sqrt{s}=7 TeV}"); TLegend* leg3= new TLegend(0.4, 0.6, 0.85, 0.88); legendStyle(*leg3,"#bf{t#bar{t} HERWIG simulation, #sqrt{s}=7 TeV}"); TLegend* leg4= new TLegend(0.4, 0.7, 0.85, 0.88); legendStyle(*leg4,"#bf{t#bar{t} default simulation, #sqrt{s}=7 TeV}"); TLegend* leg5= new TLegend(0.4, 0.7, 0.85, 0.88); legendStyle(*leg5,"#bf{t#bar{t} Powheg simulation, #sqrt{s}=7 TeV}"); // ============================ // get histos from tree // ============================ unsigned int kfirst =kMad; unsigned int klast =kMcaA; unsigned int krelative1 =kPow; TString krelative1lab=excludeATLAS ? "#scale[0.85]{Powheg+Pythia}" : "#scale[0.85]{#splitline{Powheg+Pythia}{(CMS)}}"; unsigned int krelative2 =kPow; TString krelative2lab=krelative1lab; unsigned int krelative3 =kPowHer; TString krelative3lab=excludeATLAS ? "#scale[0.85]{Powheg+Herwig}" : "#scale[0.85]{#splitline{Powheg+Herwig}{(CMS)}}"; unsigned int krelative4 =kMad; TString krelative4lab="#scale[0.55]{MadGraph+Pythia (CMS)}"; unsigned int krelative5 =kPowHer; TString krelative5lab=krelative3lab; TString treePath ="genTree/tree"; TString treePathA="tree"; std::map< TString, std::map <unsigned int, TH1F*> > histo_; std::map<TString, std::vector<double> > binning_=makeVariableBinningA(binning); std::map< unsigned int, double> Ntotev_; // get template histos std::vector<TH1F*> template_, template2_, template3_, template4_, template5_; if(debug) std::cout << "get template histos" << std::endl; // loop all plots for(int plot=0; plot<(int)plotList_.size(); ++plot) { TString thname="analyzeTopPartonLevelKinematics/"+plotList_[plot]; if(debug) std::cout << thname << std::endl; //TH1F* temp=new TH1F(plotList_[plot], plotList_[plot], 100000, -5000., 5000.); TH1F* temp=new TH1F(plotList_[plot], plotList_[plot], binning_[plotList_[plot]].size()-1, &(binning_[plotList_[plot]][0])); //double rebinFactor =atof(((string)getStringEntry(axisLabel_[plot],4,";")).c_str()); //temp->Rebin(rebinFactor); //reBinTH1F(*temp, binning_[plotList_[plot]], 2); temp->Reset("icms"); temp->SetTitle(""); temp->GetXaxis()->SetTitle(getStringEntry(axisLabel_[plot],1,";")); temp->GetYaxis()->SetTitle(getStringEntry(axisLabel_[plot],2,";")); temp->GetXaxis()->SetNoExponent(true); temp->SetStats(kFALSE); temp->SetLineWidth(3); temp->SetMarkerSize(1.25); //int binMax=temp->GetNbinsX()+1; template_ .push_back(temp); template2_.push_back(temp); template3_.push_back(temp); template4_.push_back(temp); template5_.push_back(temp); } if(debug) std::cout << "process trees" << std::endl; // loop all samples for(unsigned int sample=kfirst; sample<=klast; ++sample) { bool CMS = TString(file_.at(sample)->GetName()).Contains("CMS"); if(debug) { std::cout << "sample " << sample; if(CMS) std::cout << " (CMS)"; else std::cout << " (ATLAS)"; std::cout << std::endl; } // get tree TString treePath2=treePath; if(!CMS)treePath2=treePathA; TTree* tree = (TTree*)(file_[sample]->Get(treePath2)); if(!tree) { std::cout << "WARNING: tree " << treePath << " not found in sample " << sample << ", will continue and neglect this one " << std::endl; // exit(0); } // container for values read from tree std::map< TString, float > value_; std::map< TString, float > valueA_; // initialize map entries with 0 value_["weight" ]=1; value_["topPt" ]=0; value_["topbarPt" ]=0; value_["topY" ]=0; value_["topbarY" ]=0; value_["ttbarPt" ]=0; value_["ttbarY" ]=0; value_["ttbarMass"]=0; //value_["decayChannel"]=0; valueA_["weight" ]=1; valueA_["topPt" ]=0; valueA_["topbarPt" ]=0; valueA_["topY" ]=0; valueA_["topbarY" ]=0; valueA_["ttbarPt" ]=0; valueA_["ttbarY" ]=0; valueA_["ttbarMass"]=0; //valueA_["decayChannel"]=0; // initialize branches if(tree) { tree->SetBranchStatus("*", 0); tree->SetBranchStatus("weight" ,1); tree->SetBranchStatus("topPt" ,1); tree->SetBranchStatus("topbarPt" ,1); tree->SetBranchStatus("topY" ,1); tree->SetBranchStatus("topbarY" ,1); tree->SetBranchStatus("ttbarPt" ,1); tree->SetBranchStatus("ttbarY" ,1); tree->SetBranchStatus("ttbarMass" ,1); //tree->SetBranchStatus("decayChannel",1); if(CMS) { tree->SetBranchAddress("weight" , (&value_["weight" ] )); tree->SetBranchAddress("topPt" , (&value_["topPt" ] )); tree->SetBranchAddress("topbarPt" , (&value_["topbarPt" ] )); tree->SetBranchAddress("topY" , (&value_["topY" ] )); tree->SetBranchAddress("topbarY" , (&value_["topbarY" ] )); tree->SetBranchAddress("ttbarPt" , (&value_["ttbarPt" ] )); tree->SetBranchAddress("ttbarY" , (&value_["ttbarY" ] )); tree->SetBranchAddress("ttbarMass" , (&value_["ttbarMass"] )); //tree->SetBranchAddress("decayChannel", (&value_["decayChannel"])); } else { tree->SetBranchAddress("weight" , (&valueA_["weight" ] )); tree->SetBranchAddress("topPt" , (&valueA_["topPt" ] )); tree->SetBranchAddress("topbarPt" , (&valueA_["topbarPt" ] )); tree->SetBranchAddress("topY" , (&valueA_["topY" ] )); tree->SetBranchAddress("topbarY" , (&valueA_["topbarY" ] )); tree->SetBranchAddress("ttbarPt" , (&valueA_["ttbarPt" ] )); tree->SetBranchAddress("ttbarY" , (&valueA_["ttbarY" ] )); tree->SetBranchAddress("ttbarMass" , (&valueA_["ttbarMass"] )); //tree->SetBranchAddress("decayChannel", (&valueA_["decayChannel"])); } } // initialize histo if(debug) std::cout << "initialize histos from template" << std::endl; int color =kRed+7; TString sampleName="MadGraph+Pythia old"; //if( sample==kMadOld){ color =kRed+7 ; sampleName="MadGraph+Pythia old" ;} if(sample==kMad||sample==kAlp) { color =kRed ; sample==kMad ? sampleName="MadGraph+Pythia" : sampleName="Alpgen+Herwig" ; sample==kMad ? sampleName+="(Z2)" : sampleName+="(AUET2)" ; } else if(sample==kPow||sample==kPowA||sample==kPowA2) { color =kGreen ; sampleName="Powheg+Pythia"; if( sample==kPow ) sampleName+="(Z2)"; else if(sample==kPowA ) sampleName+="(P11)"; else if(sample==kPowA2) { sampleName+="(AUET2)"; color=kGreen+3; } } else if(sample==kPowHer||sample==kPowHerA) { color =kMagenta; sampleName="Powheg+Herwig(AUET2)"; } else if(sample==kMca ||sample==kMcaA ) { color =kBlue ; sampleName="MC@NLO+Herwig"; if(sample==kMcaA) sampleName+="(AUET2)"; } if(CMS&&!excludeATLAS) sampleName+="(CMS)" ; else if(!CMS) { sampleName+="(ATLAS)"; //color+=1; } for(int plot=0; plot<(int)plotList_.size(); ++plot) { // initialize result plots from template histo_[plotList_[plot]][sample]=(TH1F*)template_[plot]->Clone(plotList_[plot]+getTStringFromInt(sample)); histo_[plotList_[plot]][sample]->SetLineColor(color); histo_[plotList_[plot]][sample]->SetMarkerColor(color); if(!CMS) { histo_[plotList_[plot]][sample]->SetLineStyle(2); if(sample==kPowA2) histo_[plotList_[plot]][sample]->SetLineStyle(3); histo_[plotList_[plot]][sample]->SetLineWidth(4.5); } } // Add legend entry if(CMS||!excludeATLAS) { std::cout << "sample: " << sample << std::endl; std::cout << "CMS? " << CMS << std::endl; std::cout << "excludeATLAS? " << excludeATLAS << std::endl; leg->AddEntry(histo_[plotList_[0]][sample], sampleName, "L"); if( PythiaSample(sample)) leg2->AddEntry(histo_[plotList_[0]][sample], sampleName, "L"); if(!PythiaSample(sample)) leg3->AddEntry(histo_[plotList_[0]][sample], sampleName, "L"); if(sample==kMad||sample==kAlp) leg4->AddEntry(histo_[plotList_[0]][sample], sampleName, "L"); if(sample==kPow||sample==kPowA||sample==kPowA2||sample==kPowHer||sample==kPowHerA) leg5->AddEntry(histo_[plotList_[0]][sample], sampleName, "L"); } // loop tree if(tree&&(CMS||!excludeATLAS)) { if(debug) std::cout << "fill plots from tree" << std::endl; for(unsigned int event=0; event<tree->GetEntries(); ++event) { // get event tree->GetEntry(event); // get relevant quantities float weight = CMS ? value_["weight" ] : valueA_["weight" ]; //float decayChannel = CMS ? value_["decayChannel"] : valueA_["decayChannel"]; float topPtLep = CMS ? value_["topPt" ] : valueA_["topPt" ]; float topPtHad = CMS ? value_["topbarPt" ] : valueA_["topbarPt" ]; float topYLep = CMS ? value_["topY" ] : valueA_["topY" ]; float topYHad = CMS ? value_["topbarY" ] : valueA_["topbarY" ]; float ttbarPt = CMS ? value_["ttbarPt" ] : valueA_["ttbarPt" ]; float ttbarY = CMS ? value_["ttbarY" ] : valueA_["ttbarY" ]; float ttbarMass = CMS ? value_["ttbarMass" ] : valueA_["ttbarMass" ]; // debugging output if(debug2) { std::cout << "event " << event+1 << "/" << tree->GetEntries() << std::endl; std::cout << "weight: " << weight << std::endl; //std::cout << "decayChannel: " << decayChannel << std::endl; std::cout << "topPtLep: " << topPtLep << std::endl; std::cout << "topPtHad: " << topPtHad << std::endl; std::cout << "topYLep: " << topYLep << std::endl; std::cout << "topYHad: " << topYHad << std::endl; std::cout << "ttbarPt: " << ttbarPt << std::endl; std::cout << "ttbarMass: " << ttbarMass << std::endl; std::cout << "ttbarY: " << ttbarY << std::endl; } // fill histo for all histo_["topPt" ][sample]->Fill(topPtLep , weight); histo_["topPt" ][sample]->Fill(topPtHad , weight); histo_["topY" ][sample]->Fill(topYLep , weight); histo_["topY" ][sample]->Fill(topYHad , weight); histo_["ttbarPt" ][sample]->Fill(ttbarPt , weight); histo_["ttbarY" ][sample]->Fill(ttbarY , weight); histo_["ttbarMass" ][sample]->Fill(ttbarMass, weight); } // end loop event } // end if tree // save N(events) if(sample==krelative1||sample==krelative2||sample==krelative3||sample==krelative4||sample==krelative5) Ntotev_[sample]=histo_[plotList_[0]][sample]->Integral(0.,histo_[plotList_[0]][sample]->GetNbinsX()+1); for(int plot=0; plot<(int)plotList_.size(); ++plot) { // normalize to unity histo_[plotList_[plot]][sample]->Scale(1./histo_[plotList_[plot]][sample]->Integral(0.,histo_[plotList_[plot]][sample]->GetNbinsX()+1)); } } // end loop samples // create label TPaveText *label = new TPaveText(); label -> SetX1NDC(gStyle->GetPadLeftMargin()); label -> SetY1NDC(1.0-gStyle->GetPadTopMargin()); label -> SetX2NDC(1.0-gStyle->GetPadRightMargin()); label -> SetY2NDC(1.0); label -> SetTextFont(42); label -> AddText(excludeATLAS ? "CMS simulation, #sqrt{s} = 7 TeV" : "TOPLHCWG Preliminary, #sqrt{s} = 7 TeV"); label -> SetFillStyle(0); label -> SetBorderSize(0); label -> SetTextSize(0.04); label -> SetTextAlign(32); // ============================ // create canvas // ============================ if(debug) std::cout << "create canvas" << std::endl; for(int set=1; set<=5; ++set) { // loop plots for(int plot=0; plot<(int)plotList_.size(); ++plot) { TString name=plotList_[plot]; TH1F* temptemplate=0; if(set==1) temptemplate=(TH1F*)template_ [plot]->Clone(TString(template_ [plot]->GetName())+"1"); if(set==2) temptemplate=(TH1F*)template2_[plot]->Clone(TString(template2_[plot]->GetName())+"2"); if(set==3) temptemplate=(TH1F*)template3_[plot]->Clone(TString(template3_[plot]->GetName())+"3"); if(set==4) temptemplate=(TH1F*)template4_[plot]->Clone(TString(template4_[plot]->GetName())+"4"); if(set==5) temptemplate=(TH1F*)template5_[plot]->Clone(TString(template4_[plot]->GetName())+"5"); TString nameExt= set==2 ? "PYTHIA" : (set==3 ? "HERWIG" : (set==4 ? "MadgraphAlpgen" : ( set==5 ? "Powheg" : ""))); if(debug) std::cout << "plot " << name << std::endl; addCanvas(plotCanvas_); //###################################### if(plotList_[plot].Contains("topPt")||plotList_[plot].Contains("ttbarPt")) { plotCanvas_[plotCanvas_.size()-1]->SetLogy(1); temptemplate->GetYaxis()->SetRangeUser(0.0001, 1000); } //###################################### plotCanvas_[plotCanvas_.size()-1]->cd(0); plotCanvas_[plotCanvas_.size()-1]->SetName(name+nameExt); plotCanvas_[plotCanvas_.size()-1]->SetTitle(name+nameExt); temptemplate->SetMaximum(1.5*histo_[name][kPow]->GetMaximum()); if(plotCanvas_[plotCanvas_.size()-1]->GetLogy()) temptemplate->SetMaximum(10*temptemplate->GetMaximum()); if(plotList_[plot].Contains("Y")) temptemplate->SetMaximum(1.2*temptemplate->GetMaximum()); if(plotList_[plot].Contains("ttbarMass")) temptemplate->SetLabelSize(0.03); //temptemplate->GetXaxis()->SetLabelSize(0); //temptemplate->GetXaxis()->SetTitleSize(0); temptemplate->Draw("AXIS"); // draw all samples for(unsigned int sample=kfirst; sample<=klast; ++sample) { if(histo_[name].count(sample)>0&&(set==1||(set==2&&PythiaSample(sample))||(set==3&&!PythiaSample(sample))||(set==4&&(sample==kMad||sample==kAlp))||(set==5&&(sample==kPow||sample==kPowA||sample==kPowA2||sample==kPowHer||sample==kPowHerA)))&&(!excludeATLAS||!ATLASSample(sample))) { if(debug) std::cout << " - draw sample " << sample << std::endl; histo_[name][sample]->Draw("hist same"); } } // legend TLegend* templeg=0; // - clone correct legend if (set==1) templeg=(TLegend*)(leg ->Clone(TString("templeg")+plotList_[plot]+getTStringFromInt(set))); else if(set==2) templeg=(TLegend*)(leg2->Clone(TString("templeg")+plotList_[plot]+getTStringFromInt(set))); else if(set==3) templeg=(TLegend*)(leg3->Clone(TString("templeg")+plotList_[plot]+getTStringFromInt(set))); else if(set==4) templeg=(TLegend*)(leg4->Clone(TString("templeg")+plotList_[plot]+getTStringFromInt(set))); else if(set==5) templeg=(TLegend*)(leg5->Clone(TString("templeg")+plotList_[plot]+getTStringFromInt(set))); // - adjust legend position for different quantities if(plotList_[plot].Contains("topPt")) { templeg->SetX1(0.22); templeg->SetY1(0.4); templeg->SetX2(0.67); templeg->SetY2(0.61); } else if(plotList_[plot].Contains("topY")) { templeg->SetX1(0.4); templeg->SetY1(0.37); templeg->SetX2(0.85); templeg->SetY2(0.55); } else if(plotList_[plot].Contains("ttbarPt")) { templeg->SetX1(0.46); templeg->SetY1(0.63); templeg->SetX2(0.91); templeg->SetY2(0.87); } else if(plotList_[plot].Contains("ttbarY")) { templeg->SetX1(0.45); templeg->SetY1(0.68); templeg->SetX2(0.90); templeg->SetY2(0.88); } else if(plotList_[plot].Contains("ttbarMass")) { templeg->SetX1(0.44); templeg->SetY1(0.60); templeg->SetX2(0.89); templeg->SetY2(0.86); } // - draw it if(debug) std::cout << " - draw legend" << std::endl; templeg->Draw("same"); label->Draw("same"); if(debug) std::cout << " - draw label" << std::endl; // zero error std::vector<double> zeroerr_; for(int bin=0; bin<temptemplate->GetNbinsX(); ++bin) zeroerr_.push_back(0); // draw ratios if(debug) std::cout << " - draw ratios:" << std::endl; //bool first=true; unsigned int krelative=krelative1; TString krelativelab=krelative1lab; TString nominatorLabel= "simulation"; if(set==2 ) { krelative=krelative2; krelativelab=krelative2lab; } if(set==3 ) { krelative=krelative3; krelativelab=krelative3lab; } if(set==4 ) { krelative=krelative4; krelativelab=krelative4lab; nominatorLabel= "#scale[0.55]{ATLAS Alpgen+Herwig}"; } if(set==5 ) { krelative=krelative5; krelativelab=krelative5lab; } // ratio y axis min/max valuse double min=0.3; double max=1.7; if(binning>0) { min=0.7 ; max=1.3 ; } if(set==4) { min=0.85; max=1.15; } if(binning==0&&(name.Contains("topPt")||name.Contains("ttbarY"))) { min=0.85; max=1.15; } // axis and labels for ratio plot drawRatio(temptemplate, temptemplate, min, max, myStyle, verbose, zeroerr_, nominatorLabel, krelativelab, "AXIS", kWhite); // draw errorband for relative MC if(histo_[name].count(krelative)>0) { std::vector<double> err_; for(int bin=0; bin<histo_[name][krelative]->GetNbinsX(); ++bin) { err_.push_back(sqrt(histo_[name][krelative]->GetBinContent(bin)*1000000)); // NOTE: 1M events are assumed for the statistical error at the moment } TH1F* ratiotemp =(TH1F*)(histo_[name][krelative]->Clone(TString(histo_[name][krelative]->GetName())+"errup")); TH1F* ratiotemp2=(TH1F*)(histo_[name][krelative]->Clone(TString(histo_[name][krelative]->GetName())+"errdn")); TH1F* ratiotemp3=(TH1F*)(histo_[name][krelative]->Clone(TString(histo_[name][krelative]->GetName())+"errc" )); if(debug) std::cout << "draw uncertainty bands" << std::endl; for(int bin=0; bin<=histo_[name][krelative]->GetNbinsX()+1; ++bin) { if(debug2) std::cout << "bin: #" << bin << " - "; double Ntotev=Ntotev_[krelative]; double relUnc=1. / ( sqrt(histo_[name][krelative]->GetBinContent(bin)*Ntotev) ); // take care of empty bins if(histo_[name][krelative]->GetBinContent(bin)==0.) { relUnc=max-1.0; ratiotemp ->SetBinContent(bin, 0.000001); ratiotemp2->SetBinContent(bin, 0.000001); ratiotemp3->SetBinContent(bin, 0.000001); } ratiotemp ->SetBinContent(bin, (1.+relUnc)*ratiotemp ->GetBinContent(bin)); ratiotemp2->SetBinContent(bin, (1.-relUnc)*ratiotemp2->GetBinContent(bin)); if(debug2) std::cout << "content: " << histo_[name][krelative]->GetBinContent(bin) << ", unc: " << relUnc << std::endl; } int ratioColor =kGray; int whiteColor=10; ratiotemp ->SetFillStyle(1001); ratiotemp2->SetFillStyle(1001); ratiotemp ->SetLineWidth(1); ratiotemp2->SetLineWidth(1); ratiotemp ->SetFillColor(ratioColor); ratiotemp2->SetFillColor(whiteColor); ratiotemp ->SetLineColor(ratioColor); ratiotemp2->SetLineColor(whiteColor); // central value+1sigma statistics filled in gray drawRatio(ratiotemp , ratiotemp3, min, max, myStyle, verbose-1, zeroerr_, nominatorLabel, krelativelab, "hist same", ratioColor, false, 0.1); // central value+1sigma statistics filled in white drawRatio(ratiotemp2 , ratiotemp3, min, max, myStyle, verbose-1, zeroerr_, nominatorLabel, krelativelab, "hist same", whiteColor, false, 0.1); // redraw axis drawRatio(temptemplate, temptemplate, min, max, myStyle, verbose-1, zeroerr_, nominatorLabel, krelativelab, "AXIS same", kWhite); } for(unsigned int sample=kfirst; sample<=klast; ++sample) { if((histo_[name].count(sample)>0&&histo_[name].count(krelative)>0)&&((set==1)||(set==2&&PythiaSample(sample))||(set==3&&!PythiaSample(sample))||(set==4&&(sample==kAlp||sample==kMad))||(set==5&&(sample==kPow||sample==kPowA||sample==kPowA2||sample==kPowHer||sample==kPowHerA)))&&(!excludeATLAS||!ATLASSample(sample))) { if(debug) std::cout << " sample " << sample << " / sample " << krelative << std::endl; //TString opt = first ? "hist" : "hist same"; TString opt = "hist same"; //if(first) first=false; drawRatio(histo_[name][sample], histo_[name][krelative], min, max, myStyle, verbose, zeroerr_, nominatorLabel, krelativelab, opt, histo_[name][sample]->GetLineColor()); } } //if(set>1) DrawLabel(TString(template_[plot]->GetXaxis()->GetTitle()), 0.2, 0.07, 0.95, 0.3, 32, 0.15); temptemplate->Draw("AXIS same"); } // end for loop plot } // end for loop sep if(save) { TString name=outputfolder+"treeATLASCMScomparison"; if(excludeATLAS) name+="CMSonly"; TString name2=binning==1 ? "ATLASbinning" : (binning==2 ? "CMSbinning" : "FineBinning"); if(debug) std::cout << "save plots as pictures" << std::endl; saveCanvas(plotCanvas_, name+name2, "", true, true, true); if(debug) std::cout << "save plots in rootfile" << std::endl; for(unsigned int i=0; i<plotCanvas_.size(); ++i) { if(debug) { std::cout << i+1 << "/" << plotCanvas_.size(); std::cout << ": "<< plotCanvas_[i]->GetTitle(); std::cout << "->" << name+".root" << " (subfolder " << name2 << ")" << std::endl; } saveToRootFile(name+".root", plotCanvas_[i], true, 0, name2); } } }
void treeComparison(double luminosity = 19712, bool save = true, int verbose=1, TString inputFolderName= "RecentAnalysisRun8TeV_doubleKinFit", TString dataFile= "/afs/naf.desy.de/group/cms/scratch/tophh/RecentAnalysisRun8TeV_doubleKinFit/elecDiffXSecData2012ABCDAll.root:/afs/naf.desy.de/group/cms/scratch/tophh/RecentAnalysisRun8TeV_doubleKinFit/muonDiffXSecData2012ABCDAll.root", const std::string decayChannel = "combined", bool withRatioPlot=true, TString test="prob") { // test= "prob" or "PV" // data/MC -> MC/data bool invert=true; // linear fit in ratio? bool linFit=true; // =================================== // Define plotting order // =================================== std::vector<int> samples_; samples_.push_back(kSig); samples_.push_back(kBkg); samples_.push_back(kSTop); samples_.push_back(kWjets); samples_.push_back(kZjets); samples_.push_back(kDiBos); samples_.push_back(kQCD); samples_.push_back(kData); // ============================ // Set Root Style // ============================ TStyle myStyle("HHStyle","HHStyle"); setHHStyle(myStyle); myStyle.SetStripDecimals(true); myStyle.cd(); gROOT->SetStyle("HHStyle"); gROOT->ForceStyle(); TGaxis::SetMaxDigits(2); // user specific configuration TString testQuantity=""; // name of separator in tree TString treePath=""; // path of tree // values for splitting topPt (Val0<=plot1<Val1<=plot2<Val2) std::vector< double > Val_; TString treeExt=""; if(test=="PV"){ testQuantity="nPV"; treePath="compositedKinematicsKinFit/tree"; Val_.push_back(0. ); Val_.push_back(8. ); Val_.push_back(13.); Val_.push_back(17.); Val_.push_back(22.); Val_.push_back(50.); treeExt="Fit"; } if(test=="prob"){ testQuantity="chi2"; treePath="analyzeTopRecoKinematicsKinFit/tree"; Val_.push_back(0. ); Val_.push_back(1.386); // chi2<1.386 ~prob>0.50 Val_.push_back(2.1); // chi2<2.1 ~prob>0.35 Val_.push_back(3.219); // chi2<3.219 ~prob>0.20 Val_.push_back(7.824); // chi2<7.824 ~prob>0.02 Val_.push_back(99999.); treeExt=""; } // default configurations unsigned int systematicVariation=sysNo; TString ttbarMC="Madgraph"; bool scaleTtbarToMeasured=true; // adjust luminosity and data files for combined control plots double luminosityEl=constLumiElec; double luminosityMu=constLumiMuon; if(!dataFile.Contains(":")){ std::cout << "wrong input filenames, should be dataFileEl:dataFileMu, but is "; std::cout << dataFile << std::endl; exit(0); } TString dataFileEl=getStringEntry(dataFile,1 , ":"); TString dataFileMu=getStringEntry(dataFile,42, ":"); // file container std::map<unsigned int, TFile*> files_, filesMu_, filesEl_; // file vector storage std::vector< std::map<unsigned int, TFile*> > fileList_; // get analysis files TString inputFolder="/afs/naf.desy.de/group/cms/scratch/tophh/"+inputFolderName; if(verbose>0) std::cout << "loading files from " << inputFolder << std::endl; if(decayChannel!="combined"){ TString dataFiletemp= decayChannel=="muon" ? dataFileMu : dataFileEl; files_ = getStdTopAnalysisFiles(inputFolder, systematicVariation, dataFiletemp, decayChannel, ttbarMC); fileList_.push_back(files_); } else{ filesMu_ = getStdTopAnalysisFiles(inputFolder, systematicVariation, dataFileMu, "muon" , ttbarMC); filesEl_ = getStdTopAnalysisFiles(inputFolder, systematicVariation, dataFileEl, "electron", ttbarMC); fileList_.push_back(filesMu_); fileList_.push_back(filesEl_); } // topPt histogram template if(verbose>0) std::cout << "creating temp histo" << std::endl; TH1F* temp= (TH1F*)(((TH1F*)(fileList_.at(0)[kSig]->Get("analyzeTopRecoKinematicsKinFit/topPt"))->Clone())); temp->Rebin(20); temp->Reset("icms"); temp->SetTitle(""); temp->GetXaxis()->SetTitle("p_{T}^{t} #left[GeV#right]"); temp->GetYaxis()->SetTitle("Top quarks"); //axesStyle(*temp, "p_{T}^{t} #left[GeV#right]", "norm. Top quarks", 0., 0.15); temp->GetXaxis()->SetRangeUser(0.,500.); //temp->GetYaxis()->SetRangeUser(0.,0.2 ); temp->SetStats(kFALSE); temp->SetLineWidth(3); temp->SetMarkerSize(1.25); int binMax=temp->GetNbinsX()+1; // container for all histos std::map< TString, std::map <unsigned int, TH1F*> > histo_; // determine number of channels unsigned int nchannels = decayChannel=="combined" ? 2 : 1; // loop decay channels if(verbose>0) std::cout << "looping channels" << std::endl; for(unsigned int channel=0; channel<nchannels; ++channel){ std::map<unsigned int, TFile*> tempfiles_=fileList_.at(channel); std::string tempChannel= decayChannel!="combined" ? decayChannel : (channel==0 ? "muon" : "electron"); if(verbose>1) std::cout << " - " << tempChannel << std::endl; TString channelExt=getTStringFromInt(channel); // loop samples for(unsigned int sample=kSig; sample<=kSAToptW; ++sample){ bool note=false; // check if sample is relevant if(isValidsample(sample, systematicVariation)){ if(verbose>1){ std::cout << " -> processing " << sampleLabel(sample, tempChannel); std::cout << " (file " << tempfiles_[sample]->GetName() << ")" << std::endl; } // calculate luminosity event weight double lumi=decayChannel!="combined" ? luminosity : (channel==0 ? luminosityMu : luminosityEl); double lumiwgt=lumiweight(sample, lumi, systematicVariation, tempChannel); if(verbose>1) std::cout << " (lumiweight=" << lumiwgt << ")" << std::endl; // get trees TTree* tree = (TTree*)(tempfiles_[sample]->Get(treePath)); if(!tree){ std::cout << " !ERROR: tree not found!" << std::endl; exit(0); } else if(verbose>1) std::cout << " (tree found, contains " << tree->GetEntries() << " entries)" << std::endl; // container for values read from tree std::map< TString, float > value_; // initialize map entries with 0 value_["weight" ]=1.; value_["testQuantity" ]=0.; value_["topPtLep"]=0.; value_["topPtHad"]=0.; // initialize branches tree->SetBranchStatus ("*", 0); tree->SetBranchStatus ("weight" , 1); tree->SetBranchStatus ("topPtLep"+treeExt, 1); tree->SetBranchStatus ("topPtHad"+treeExt, 1); tree->SetBranchStatus (testQuantity , 1); tree->SetBranchAddress(testQuantity ,(&value_["testQuantity" ])); tree->SetBranchAddress("weight" ,(&value_["weight" ])); tree->SetBranchAddress("topPtLep"+treeExt,(&value_["topPtLep"])); tree->SetBranchAddress("topPtHad"+treeExt,(&value_["topPtHad"])); // initialize result plots histo_["topPt"+channelExt ][sample]=(TH1F*)(temp->Clone()); for(int plot=1; plot<(int)Val_.size(); ++plot){ histo_["topPtProb"+getTStringFromInt(plot)+channelExt][sample]=(TH1F*)(temp->Clone()); } if(verbose>1) std::cout << " -> looping tree" << std::endl; // loop all events to fill plots for(unsigned int event=0; event<tree->GetEntries(); ++event){ // get event tree->GetEntry(event); // check if values are reasonable if(!((value_["weight"]>0&&value_["weight"]<10)||(test!="PV"&&value_["weight"]==0.))){ if(!note){ std::cout << "!!! WARNING - some weights are strange (e.g." << value_["weight"] << ") !!!"<< std::endl; note=true; } value_["weight"]=1.0; } // get relevant quantities double weight=value_["weight"]*lumiwgt; double filterQuantity =value_["testQuantity" ]; double topPtLep=value_["topPtLep"]; double topPtHad=value_["topPtHad"]; if(verbose>2){ std::cout << " event #" << event+1 << "/" << tree->GetEntries() << ":" << std::endl; std::cout << " weight=" << weight << ", " << "testQuantity" << "=" << filterQuantity << ", topPtLep=" << topPtLep << ", topPtHad=" << topPtHad << std::endl; } // fill histo for all histo_["topPt"+channelExt][sample]->Fill(topPtLep, weight); histo_["topPt"+channelExt][sample]->Fill(topPtHad, weight); // fill histo for different ranges of the filterQuantity for(int plot=1; plot<(int)Val_.size(); ++plot){ TString nameNr=getTStringFromInt(plot); if(filterQuantity>=Val_[plot-1]&&filterQuantity<Val_[plot]){ histo_["topPtProb"+nameNr+channelExt][sample]->Fill(topPtLep, weight); histo_["topPtProb"+nameNr+channelExt][sample]->Fill(topPtHad, weight); } } // end for loop separation values } // end for loop tree events } // end if is valid sample } // end for loop samples } // end for loop decay channels // create final plots // -> combine decay channels and MC samples unsigned int kAllMC=42; // loop samples if(verbose>0) std::cout << "combining decay channels and MC samples" << std::endl; for(unsigned int sample=kSig; sample<=kSAToptW; ++sample){ // check if sample is relevant if(isValidsample(sample, systematicVariation)){ // loop decay channels for(unsigned int channel=0; channel<nchannels; ++channel){ std::string tempChannel= decayChannel!="combined" ? decayChannel : (channel==0 ? "muon" : "electron"); if(verbose>1) std::cout << " -> processing " << sampleLabel(sample, tempChannel) << "(" << tempChannel << ")" << std::endl; TString channelExt=getTStringFromInt(channel); // get plots for current channels std::vector <TH1F*> tempHist_; tempHist_.push_back((TH1F*)histo_["topPt"+channelExt ][sample]->Clone()); for(int plot=1; plot<(int)Val_.size(); ++plot){ TString nameNr=getTStringFromInt(plot); tempHist_.push_back((TH1F*)histo_["topPtProb"+nameNr+channelExt][sample]->Clone()); } std::vector <int> nevents_; for(int plot=0; plot<(int)Val_.size(); ++plot){ nevents_.push_back(tempHist_[plot]->Integral(0,binMax)); } // add all channels for final histogram if(channel==0){ for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histo_["topPt"+nameNr][sample]=(TH1F*)tempHist_[plot]->Clone(); } } else{ for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histo_["topPt"+nameNr][sample]->Add((TH1F*)tempHist_[plot]->Clone()); } } if(verbose>2){ std::cout << " (#events(" << tempChannel << ")="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << nevents_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << ")" << std::endl; } } // end channel for loop std::vector <double> neventsComb_; for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); neventsComb_.push_back(histo_["topPt"+nameNr][sample]->Integral(0,binMax)); } if(verbose>1){ std::cout << " (#events="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsComb_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << ")" << std::endl; } // combine all MC samples if(sample!=kData){ if(sample==kSig){ for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histo_["topPt"+nameNr][kAllMC]=(TH1F*)histo_["topPt"+nameNr][sample]->Clone(); } } else{ for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histo_["topPt"+nameNr][kAllMC]->Add((TH1F*)histo_["topPt"+nameNr][sample]->Clone()); } } // MC histogram style for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histogramStyle(*histo_["topPt"+nameNr][sample], sample, true); //histo_["topPt"+nameNr][sample]->SetLineColor(histo_["topPt"+nameNr][sample]->GetFillColor()); histo_["topPt"+nameNr][sample]->SetLineWidth(1); } } else{ // data histogram style for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histogramStyle(*histo_["topPt"+nameNr][sample], kData, false); } } } // end if sample is valid } // end sample for loop // print some interesting numbers // chosen slices std::vector< double >neventsMC_; if(verbose>0){ std::cout << "slices in " << testQuantity << ": all / "; for(int plot=1; plot<(int)Val_.size(); ++plot){ std::cout << "[" << Val_[plot-1] << ".." << Val_[plot] << "]"; if(plot<(int)Val_.size()-1) std::cout << "/ "; } std::cout << std::endl; } // total number of MC events for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); neventsMC_.push_back(histo_["topPt"+nameNr][kAllMC]->Integral(0,binMax)); } if(verbose>0){ std::cout << "#events( MC )="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsMC_[plot]; if(plot<(int)Val_.size()-1) std::cout << ", "; } std::cout << std::endl; } // total number of data events std::vector< double >neventsData_; for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); neventsData_.push_back(histo_["topPt"+nameNr][kData]->Integral(0,binMax)); } if(verbose>0){ std::cout << "#events(Data)="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsData_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << std::endl; } // data over MC ratio if(verbose>0){ std::cout << "(data/MC ratio="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsData_[plot]/neventsMC_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << ")" << std::endl; } // scale ttbar to match total number of events if(scaleTtbarToMeasured){ if(verbose>0) std::cout << "scale ttbar component to match #data events " << std::endl; std::vector<double>neventsTop_, SFTop_; for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); neventsTop_.push_back(histo_["topPt"+nameNr][kSig]->Integral(0,binMax)+histo_["topPt"+nameNr][kBkg]->Integral(0,binMax)); SFTop_.push_back((neventsTop_[plot]+(neventsData_[plot]-neventsMC_[plot]))/neventsTop_[plot]); } // scale combined and top MC plots for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); // subtract ttbar from all MC histo_["topPt"+nameNr][kAllMC]->Add((TH1F*)(histo_["topPt"+nameNr][kSig]->Clone()) , -1.); histo_["topPt"+nameNr][kAllMC]->Add((TH1F*)(histo_["topPt"+nameNr][kBkg]->Clone()) , -1.); // scale ttbar histo_["topPt"+nameNr][kSig]->Scale(SFTop_[plot]); histo_["topPt"+nameNr][kBkg]->Scale(SFTop_[plot]); // re-add ttbar MC histo_["topPt"+nameNr][kAllMC]->Add((TH1F*)(histo_["topPt"+nameNr][kSig]->Clone()) ); histo_["topPt"+nameNr][kAllMC]->Add((TH1F*)(histo_["topPt"+nameNr][kBkg]->Clone()) ); } // printout std::vector<double>neventsMCscaled_; for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); neventsMCscaled_.push_back(histo_["topPt"+nameNr][kAllMC]->Integral(0,binMax)); } if(verbose>1){ std::cout << "#events(scaledMC)="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsMCscaled_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << std::endl; std::cout << "(data/scaledMC ratio="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsData_[plot]/neventsMCscaled_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << ")" << std::endl; } }; // combine single top subsamples for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histo_["topPt"+nameNr][kSTop]=(TH1F*)histo_["topPt"+nameNr][kSAToptW]->Clone(); for(int sample=(int)kSTops; sample<(int)kSAToptW; ++sample){ // add to combined STop histo_["topPt"+nameNr][kSTop]->Add((TH1F*)histo_["topPt"+nameNr][sample]->Clone()); } // end for loop single top subsamples } // end for loop plots // create MC histo stack plots int lastSample=-1; // loop samples if(verbose>0) std::cout << "creating MC stack histos" << std::endl; for(int sampleOri=(int)kDiBos; sampleOri>=(int)kSig; --sampleOri){ // use previous defined order int sampleMod=samples_[sampleOri]; if(verbose>1) std::cout << "processing " << sampleLabel(sampleMod, decayChannel) << "(= " << sampleMod <<", last sample=" << lastSample << ")" << std::endl; // exclude QCD and Diboson if(sampleMod!=kQCD&&sampleMod!=kDiBos){ if(lastSample>-1){ if(verbose>1) std::cout << "adding " << sampleLabel(lastSample, decayChannel) << " to " << sampleLabel(sampleMod, decayChannel) << std::endl; // loop plots for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); if(verbose>1) std::cout << "processing " << "topPt"+nameNr << std::endl; // add to stack if(!histo_.count("topPt"+nameNr)>0) std::cout << "WARNING: topPt"+nameNr+" does not exist in histo_!" << std::endl; else if(!histo_["topPt"+nameNr].count(sampleMod )>0) std::cout << "WARNING: sample " << sampleMod << " does not exist in histo_[topPt"+nameNr+"]!" << std::endl; else if(!histo_["topPt"+nameNr].count(lastSample)>0) std::cout << "WARNING: sample " << lastSample << " does not exist in histo_[topPt"+nameNr+"]!" << std::endl; histo_["topPt"+nameNr][sampleMod]->Add((TH1F*)histo_["topPt"+nameNr][lastSample]->Clone()); } // end for loop plots if(verbose>1) std::cout << "done" << std::endl; } // if not last sample if(verbose>1) std::cout << "lastSample set to " << sampleMod << std::endl; lastSample=sampleMod; } // end else if !QCD } // end for loop original sample ordering // printout std::vector<double>neventsMCstack_; for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); neventsMCstack_.push_back(histo_["topPt"+nameNr][kAllMC]->Integral(0,binMax)); } if(verbose>1){ std::cout << "#events(stack MC) ="; for(int plot=0; plot<(int)Val_.size(); ++plot){ std::cout << neventsMCstack_[plot]; if(plot<(int)Val_.size()-1) std::cout << " / "; } std::cout << std::endl; } // all MC histogram style for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); histo_["topPt"+nameNr][kAllMC]->SetLineColor(kBlue); histo_["topPt"+nameNr][kAllMC]->SetMarkerColor(kBlue); histo_["topPt"+nameNr][kAllMC]->SetLineStyle(1); } std::vector<double> zeroerr_; for(int bin=0; bin<histo_["topPt"][kAllMC]->GetNbinsX(); ++bin) zeroerr_.push_back(0); // normalization // -> not done at the moment, scaled wrt Ndata for each plot separately // Create canvas if(verbose>0) std::cout << "creating canvas" << std::endl; std::vector<TCanvas*> plotCanvas_; for(unsigned int sample=0; sample<Val_.size(); sample++){ addCanvas(plotCanvas_); } // create legends if(verbose>0) std::cout << "creating legend" << std::endl; std::vector< TLegend* > leg_; TLegend *leg= new TLegend(0.73, 0.5, 0.91, 0.88); legendStyle(*leg,""); for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr = plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); TString sVallow = plot==0 ? "" : getTStringFromDouble(Val_[plot-1], getRelevantDigits(Val_[plot-1])); TString sValhigh = plot==0 ? "" : getTStringFromDouble(Val_[plot ], getRelevantDigits(Val_[plot ])); TString legHeader= plot==0 ? "KinFit, all" : sVallow+"#leq"+testQuantity+"<"+sValhigh; TLegend *templeg=(TLegend*)leg->Clone(); templeg ->SetHeader(legHeader); templeg ->AddEntry(histo_["topPt"+nameNr][kData ], "data" , "P"); //templeg ->AddEntry(histo_["topPt"+nameNr][kAllMC], "all MC" , "L" ); for(unsigned int sample=kSig; sample<kData; sample++){ unsigned int sampleMod=samples_[sample]; if(sampleMod!=kQCD&&sampleMod!=kDiBos) templeg ->AddEntry(histo_["topPt"+nameNr][sampleMod], sampleLabel(sampleMod, decayChannel), "F" ); } leg_.push_back((TLegend*)(templeg->Clone())); } int canvasNumber=0; // do the plotting if(verbose>0) std::cout << "plotting " << std::endl; for(int plot=0; plot<(int)Val_.size(); ++plot){ TString nameNr= plot==0 ? "" : "TestSlice"+getTStringFromInt(plot); TString title = plot==0 ? "topPtKinFit"+TString(decayChannel) : "topPt"+testQuantity+getTStringFromInt(plot)+TString(decayChannel); plotCanvas_[canvasNumber]->cd(0); plotCanvas_[canvasNumber]->SetTitle(title); // drawing // plots histo_["topPt"+nameNr][kSig]->SetMaximum(1.3*histo_["topPt"+nameNr][kData]->GetMaximum()); histo_["topPt"+nameNr][kSig]->GetXaxis()->SetNoExponent(true); histo_["topPt"+nameNr][kSig]->GetYaxis()->SetNoExponent(true); histo_["topPt"+nameNr][kSig]->Draw("axis"); // loop samples for(int sampleOri=(int)kSig; sampleOri<=(int)kDiBos; ++sampleOri){ // use previous defined order int sampleMod=samples_[sampleOri]; if(verbose>2) std::cout << "processing sample " << sampleMod << " ("+sampleLabel(sampleMod, decayChannel)+")" << std::endl; // draw other MC samples, excluding QCD if(sampleMod!=kQCD&&sampleMod!=kDiBos){ if(verbose>2) std::cout << "-> drawing!" << sampleMod << std::endl; histo_["topPt"+nameNr][sampleMod]->Draw("hist same"); } } // end for loop ori samples //histo_["topPt"+nameNr][kAllMC]->Draw("hist same"); histo_["topPt"+nameNr][kData ]->Draw("ep same"); // legend leg_[plot]->Draw("same"); // add labels for decay channel, luminosity, energy and CMS preliminary (if applicable) if (decayChannel=="muon" ) DrawDecayChLabel("#mu + Jets"); else if (decayChannel=="electron") DrawDecayChLabel("e + Jets"); else DrawDecayChLabel("e/#mu + Jets Combined"); DrawCMSLabels(true,luminosity); // draw ratio if(withRatioPlot){ // labels of ratio TString ratioLabelNominator ="N_{MC}"; TString ratioLabelDenominator="N_{Data}"; double ratMin= invert ? 0.75 : 0.30; double ratMax= invert ? 1.75 : 1.29; std::vector<double> err_; for(int bin=1; bin<histo_["topPt"+nameNr][kSig]->GetNbinsX(); ++bin){ double ratio = histo_["topPt"+nameNr][kData]->GetBinContent(bin)/histo_["topPt"+nameNr][kSig]->GetBinContent(bin); if(invert) ratio=1./ratio; double val=ratio*(histo_["topPt"+nameNr][kData]->GetBinError(bin)/histo_["topPt"+nameNr][kData]->GetBinContent(bin)); if(val<0||val>histo_["topPt"+nameNr][kData]->GetBinContent(bin)) val=1.; err_.push_back(val); } int rval1 = drawRatio(histo_["topPt"+nameNr][kData], histo_["topPt"+nameNr][kSig], ratMin, ratMax, myStyle, verbose, err_, ratioLabelNominator, ratioLabelDenominator, "p e", kBlack, true, 0.5, 505, invert, true, linFit); if (rval1!=0) std::cout << " Problem occured when creating ratio plot for " << nameNr << std::endl; } canvasNumber++; } // saving if(verbose>0) std::cout << "saving" << std::endl; if(save){ TString outfolder="./diffXSecFromSignal/plots/combined/2012/topPtTest/"; // eps and png if(verbose==0) gErrorIgnoreLevel=kWarning; saveCanvas(plotCanvas_, outfolder, "topPtTest"+testQuantity+TString(decayChannel), true, true, true); } }