TCanvas* createCanvas(TString name,int xlen,int ylen, int xDiv, bool ratio) { TCanvas* aCanvas = new TCanvas(name,name,xlen*xDiv,ylen); float xstep = 1./xDiv; for (int i1=0; i1<xDiv; i1++) { TPad *mainPad = new TPad();//,0.01+((i1)*xstep),0.25,((i1+1)*xstep)-0.01,0.99); mainPad->SetNumber(1+i1); if(ratio){ mainPad = new TPad();//,0.01+((i1)*xstep),0.25,((i1+1)*xstep)-0.01,0.99); mainPad->SetNumber(i1); } mainPad->Draw(); if(ratio){ TPad *ratioPad = new TPad("","",0.01+((i1)*xstep),0.01,((i1+1)*xstep)-0.01,0.25); ratioPad->SetNumber(i1*2+2); ratioPad->Draw(); } } aCanvas->SetFillColor(0); aCanvas->SetBottomMargin(0.125); aCanvas->SetLeftMargin(0.125); aCanvas->SetFrameFillColor(0); aCanvas->SetFrameBorderMode(0); aCanvas->SetFrameLineWidth(2); return aCanvas; }
TCanvas* createCanvas(TString name,int xlen,int ylen,int xDiv,bool logOn) { TCanvas* aCanvas = new TCanvas(name,name,xlen,ylen); float xstep = 1./xDiv; for (int i1=1; i1<=xDiv; i1++) { TPad *mainPad = new TPad("","",0.01+((i1-1)*xstep),0.25,(i1*xstep)-0.01,0.99); mainPad->SetNumber(i1); mainPad->Draw(); TPad *ratioPad = new TPad("","",0.01+((i1-1)*xstep),0.01,(i1*xstep)-0.01,0.25); ratioPad->SetNumber(i1+xDiv); ratioPad->Draw(); } if (logOn==true) { gPad->SetLogy(); } aCanvas->SetFillColor(0); aCanvas->SetBottomMargin(0.125); aCanvas->SetLeftMargin(0.125); aCanvas->SetFrameFillColor(0); aCanvas->SetFrameBorderMode(0); aCanvas->SetFrameLineWidth(2); return aCanvas; }
void DisplayTracker(TStrawTracker *trX_1, TStrawTracker *trX_2, TStrawTracker *trX_3, TStrawTracker *trY_1, TStrawTracker *trY_2, TStrawTracker *trY_3) { // all trackers if (gStrela->GetDisplay()) return; TStrelaDisplay *display = new TStrelaDisplay(); Double_t xl[3] = {0.00, 0.20, 0.475}; // 0.00, 0.25, 0.75 Double_t xu[3] = {0.20, 0.475, 1.00}; // 0.25, 0.75, 1.00 Double_t yl[3] = {0.1072, 0.192, 0.000}; Double_t yu[3] = {0.3929, 0.308, 0.500}; TPad *pad; Int_t npad = 1; // must start from 1 TPad *pad0 = display->GetPad(); for (Int_t iy = 0; iy < 2; iy++) { for (Int_t ix = 0; ix < 3; ix++) { yl[ix] = iy*0.5 + yl[ix]; yu[ix] = iy*0.5 + yu[ix]; pad = new TPad(Form("%s_%d", pad0->GetName(), npad), "", xl[ix], yl[ix], xu[ix], yu[ix]); pad->SetNumber(npad++); pad->Draw(); } } // special pad_7 pad = new TPad(Form("%s_%d", pad0->GetName(), npad), "", 0.30, yl[0], 0.50, yu[0]); pad->SetNumber(npad++); pad->Draw(); if (trY_1) { pad0->cd(1); display->DrawTracker(trY_1); } if (trY_2) { pad0->cd(2); display->DrawTracker(trY_2); } if (trY_3) { pad0->cd(3); display->DrawTracker(trY_3); } if (trX_1) { pad0->cd(4); display->DrawTracker(trX_1); } if (trX_2) { pad0->cd(7); display->DrawTracker(trX_2); // display->FindRange(0.006); } if (trX_3) { pad0->cd(6); display->DrawTracker(trX_3); } pad0->cd(0); }
void compareplots_noRatio(){ vector<TFile*> files; files.push_back(new TFile("/storage/9/schweiger/analyseFxFx/pythia8/100kEvents/ttbarMergedFxFx8TeVCTEQ6M-extracted.root")); files.push_back(new TFile("/storage/9/schweiger/analyseFxFx/pythia8/100kEvents/mergingscale_30/ttbarMergedFxFxMS30GeVMECut10GeV8TeVCTEQ6M-extracted.root")); files.push_back(new TFile("/storage/9/schweiger/analyseFxFx/pythia8/100kEvents/mergingscale_100/ttbarMergedMS100GeV8TeVCTEQ6M-extracted.root")); files.push_back(new TFile("/storage/9/schweiger/analyseFxFx/pythia8/100kEvents/mergingscale_100/ttbarMergedMS100GeVMCCut50GeV8TeVCTEQ6M-extracted.root")); vector<TString> names; names.push_back("ttbar +0/1 Jet, #mu_{Q}=10 GeV #mu_{ME} = 10 GeV"); names.push_back("ttbar +0/1 Jet, #mu_{Q}=30 GeV #mu_{ME} = 10 GeV"); names.push_back("ttbar +0/1 Jet, #mu_{Q}=100 GeV #mu_{ME} = 10 GeV"); names.push_back("ttbar +0/1 Jet, #mu_{Q}=100 GeV #mu_{ME} = 50 GeV"); vector<TString> titles; titles.push_back("Gen-Jet p_{T} with pos weights (GeV)"); titles.push_back("Gen-Jet p_{T} with neg weights (GeV)"); titles.push_back("Gen-Jet p_{T} (GeV)"); titles.push_back("Gen_Jet #phi with pos. weights"); titles.push_back("Gen_Jet #phi with neg. weights"); titles.push_back("Gen_Jet #phi"); titles.push_back("Gen Jet #theta with pos weights"); titles.push_back("Gen Jet #theta with neg weights"); titles.push_back("Gen Jet #theta"); titles.push_back("Gen Jet Energy with pos weights (GeV) "); titles.push_back("Gen Jet Energy with neg weights (GeV)"); titles.push_back("Gen Jet Energy (GeV)"); titles.push_back("p_{T} of hardest Gen-Jet with pos weights (GeV)"); titles.push_back("p_{T} of hardest Gen-Jet with neg weights (GeV)"); titles.push_back("p_{T} of hardest Gen-Jet (GeV)"); titles.push_back("p_{T} of 2nd hardest Gen-Jet with pos weights (GeV)"); titles.push_back("p_{T} of 2nd hardest Gen-Jet with neg weights (GeV)"); titles.push_back("p_{T} of 2nd hardest Gen-Jet (GeV)"); titles.push_back("#eta of hardest Gen-Jets with pos weights"); titles.push_back("#eta of hardest Gen-Jets with neg weights"); titles.push_back("#eta of hardest Gen-Jets"); titles.push_back("Number of Gen-Jets with pos. weights"); titles.push_back("Number of Gen-Jets with neg. weights"); titles.push_back("Number of Gen-Jets"); TFile *vergleich = new TFile("vergleich_ttbar_0Jet.root","RECREATE"); // Show no statistics box gStyle->SetOptStat(0); TH1::SetDefaultSumw2(); // Main program part TIter nextkey(files.at(0)->GetListOfKeys()); TKey *key; bool first=true; TCanvas* c = new TCanvas(); c->Print("plots.pdf["); // Save also as pictures int pictureNumber = 0; int run = 0; while (key = (TKey*)nextkey()) { pictureNumber++; TString pictureName = TString::Format("%d.png",pictureNumber); vector<TH1F*> histos; histos.push_back((TH1F*)key->ReadObj()); for(size_t i=1;i<files.size();i++){ histos.push_back((TH1F*)files.at(i)->Get(histos.at(0)->GetName())); } for(size_t i=0;i<histos.size();i++){ if(i == 0){ histos.at(i)->SetLineColor(kBlack); } if(i == 1){ histos.at(i)->SetLineColor(kRed); } if(i == 2){ histos.at(i)->SetLineColor(kBlue); } if(i == 3){ histos.at(i)->SetLineColor(kGreen+2); } if(i == 4){ histos.at(i)->SetLineColor(kMagenta-7); } if(i == 5){ histos.at(i)->SetLineColor(kOrange+7); } } for(size_t i=0;i<histos.size();i++){ histos.at(i)->Sumw2(); histos.at(i)->Scale(1./histos.at(i)->Integral(),"width"); } // Set axis title histos.at(0)->GetYaxis()->SetTitle("Normalized units"); std::string const histogramName = histos.at(1)->GetName(); histos.at(0)->GetXaxis()->SetLabelSize(0.05); histos.at(0)->GetXaxis()->SetLabelOffset(0.006); histos.at(0)->GetYaxis()->SetLabelSize(0.05); histos.at(0)->GetYaxis()->SetLabelOffset(0.006); histos.at(0)->GetXaxis()->SetTitleSize(0.06); histos.at(0)->GetXaxis()->SetTitleOffset(1.1); histos.at(0)->GetYaxis()->SetTitleSize(0.06); histos.at(0)->GetYaxis()->SetTitleOffset(1.15); histos.at(0)->GetXaxis()->SetTitle(titles.at(run)); run = run+1; if(run == (3*8)){ run = 0; } // If only two histograms per plot make a ratio plot if(histos.size() == 2) { //create main pad TPad *mainPad = new TPad("","",0.0,0.0,1.0,1.0); mainPad->SetNumber(1); mainPad->SetBottomMargin(0.15); mainPad->SetRightMargin(0.04); mainPad->SetLeftMargin(0.13); mainPad->Draw(); gStyle->SetOptTitle(0); //create ratio pad /*TPad *ratioPad = new TPad("","",0.0,0.0,1.0,0.3); ratioPad->SetTopMargin(0.0); ratioPad->SetBottomMargin(0.4); ratioPad->SetLeftMargin(0.13); ratioPad->SetRightMargin(0.04); gStyle->SetOptTitle(0); ratioPad->SetFillColor(0); ratioPad->SetNumber(2); ratioPad->SetGridy(); ratioPad->Draw();*/ // Draw both histograms first c->cd(1); histos.at(0)->Draw("histo E"); histos.at(1)->Draw("histo same E"); // Show legend and statistical tests in first pad for(size_t i=0;i<histos.size()-1;i=i+2){ double ksresult = histos.at(i)->KolmogorovTest(histos.at(i+1)); ksresult=floor(ksresult*1000+0.5)/1000; double chi2result =histos.at(i)->Chi2Test(histos.at(i+1),"WW"); chi2result=floor(chi2result*1000+0.5)/1000; stringstream ss; //ss << " KS: " <<std::setprecision(3) << ksresult << " chi2: " <<std::setprecision(3) << chi2result << " Private Work"; ss << " Private Work"; const char * ch = & ss.str().c_str();; TLatex * ks = new TLatex(0.1, 0.9-0.03*i, ch ); ks->SetTextColor(histos.at(i)->GetLineColor()); ks->SetNDC(); ks->Draw(""); } TLegend* l = new TLegend(0.40,0.9,0.69,0.99); // Options for legend l->SetBorderSize(0); l->SetLineStyle(0); l->SetTextSize(0.049); l->SetFillStyle(0); for(size_t i=0;i<names.size();i++){ l->AddEntry(histos.at(i),names.at(i),"L"); } l->Draw("same"); /* // Clone histograms and draw ratio plot c->cd(2); TH1F* ratioHisto = (TH1F*)histos.at(0)->Clone(); ratioHisto->Divide(histos.at(1)); ratioHisto->SetLineColor(kBlue); ratioHisto->SetStats(false); ratioHisto->GetYaxis()->SetTitle("Ratio #frac{noFxFx}{FxFx}"); // Same Size like in histogram ratioHisto->SetLabelSize(histos.at(0)->GetLabelSize() * 0.7 / 0.3); ratioHisto->SetTitleOffset((histos.at(0)->GetTitleOffset("Y") * 0.3 / 0.7), "Y"); ratioHisto->SetTitleSize((histos.at(0)->GetTitleSize("Y") * 0.7 / 0.3), "Y"); ratioHisto->SetTitleOffset((histos.at(0)->GetTitleOffset("X")), "X"); ratioHisto->SetTitleSize((histos.at(0)->GetTitleSize("X") * 0.7 / 0.3), "X"); // Use nicer range ratioHisto->GetYaxis()->SetRangeUser(0, 2.2); ratioHisto->GetYaxis()->SetNdivisions(503); ratioHisto->GetYaxis()->SetLabelSize(0.06 * 0.7 / 0.3); ratioHisto->Draw();*/ } else { TPad *mainPad = new TPad("","",0.0,0.0,1.0,1.0); mainPad->SetNumber(1); mainPad->SetBottomMargin(0.15); mainPad->SetRightMargin(0.04); mainPad->SetLeftMargin(0.13); mainPad->Draw(); gStyle->SetOptTitle(0); //mainPad->SetLogx(1); c->cd(1); histos.at(0)->Draw("histo E"); for(size_t i=0;i<histos.size();i++){ histos.at(i)->Draw("histo same E"); } for(size_t i=0;i<histos.size()-1;i=i+2){ /* double ksresult = histos.at(i)->KolmogorovTest(histos.at(i+1)); ksresult=floor(ksresult*1000+0.5)/1000; double chi2result =histos.at(i)->Chi2Test(histos.at(i+1),"WW"); chi2result=floor(chi2result*1000+0.5)/1000; stringstream ss; ss << "KS: " <<std::setprecision(3) << ksresult << " chi2: " <<std::setprecision(3) << chi2result; const char * ch = & ss.str().c_str();; TText * ks = new TText(0.1, 0.9-0.03*i, ch ); ks->SetTextColor(histos.at(i)->GetLineColor()); ks->SetNDC(); ks->Draw(""); */ } TLegend* l = new TLegend(0.65,0.5,0.9,0.7); l->SetBorderSize(0); l->SetLineStyle(0); // l->SetTextSize(0.039); l->SetFillStyle(0); for(size_t i=0;i<names.size();i++){ l->AddEntry(histos.at(i),names.at(i),"L"); } l->Draw("same"); } c->Print("plots.pdf"); c->SaveAs(pictureName); vergleich->WriteTObject(c); } c->Print("plots.pdf]"); }
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 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(); }
// Make main selection plots // n-1, control type plots and plots after all cuts void makePlot(const TString & histoName, TFile * outputFile, TString anaType, const TString & xTitle, const double & xMin, const double & xMax, const double & yMin = 0., const double & yMax = 0., bool logY=false, const float lumi = 0, const bool plotData=false, bool drawRatioPlot=false ) { std::cout << "----> Making plots for : " << histoName.Data() << std::endl; std::cout << "Plotting data ? " << plotData << std::endl; TH1::SetDefaultSumw2(); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); // Keep track of integrals of background & data double totalBkgMCIntegral = 0; // double totalDataIntegral = 0; // // DATA // TH1F * histoData=0; if (plotData) { TFile * inputFile= new TFile ("CombinedFiles/Data_combined_"+anaType+".root", "READ"); histoData = (TH1F*)inputFile->Get(histoName); // totalDataIntegral = histoData->Integral(); histoData->SetStats(0); histoData->SetMarkerStyle(21); histoData->SetMarkerSize(1); } // // SIGNAL MC // // Not good at the moment - just taking one or two examples to plot and hard coded the names of the files here TFile * signalInputFile1= new TFile (signal1+anaType+".root", "READ"); TH1F * histoSignal1 = (TH1F*)signalInputFile1->Get(histoName); histoSignal1->SetStats(0); histoSignal1->Scale(lumi); TFile * signalInputFile2= new TFile (signal2+anaType+".root", "READ"); TH1F * histoSignal2 = (TH1F*)signalInputFile2->Get(histoName); histoSignal2->SetStats(0); histoSignal2->Scale(lumi); int minIntegral=0; int maxIntegral=histoSignal1->GetNbinsX(); // if ( histoName=="nMinus1_isolationLeptonH_removedLifetimeCuts" || histoName=="nMinus1_relIsolationLeptonH_removedLifetimeCuts" ) { // // std::cout << find90Cut( histoSignal1 ) << std::endl; // // std::cout << find90Cut( histoSignal2 ) << std::endl; // // minIntegral=histoSignal1->FindBin( find90Cut(histoSignal1) ); // // // Check integral below specific cut // if ( histoName=="nMinus1_relIsolationLeptonH_removedLifetimeCuts" ) { // std::cout << "Signal 1" << std::endl; // std::cout << "Efficiency with rel iso cut at 0.1 : " << histoSignal1->Integral( 1, histoSignal1->FindBin(0.1) ) / histoSignal1->Integral() << std::endl; // std::cout << "Efficiency with rel iso cut at 0.05 : " << histoSignal1->Integral( 1, histoSignal1->FindBin(0.05) ) / histoSignal1->Integral() << std::endl; // std::cout << "Signal 2" << std::endl; // std::cout << "Efficiency with rel iso cut at 0.1 : " << histoSignal2->Integral( 1, histoSignal2->FindBin(0.1) ) / histoSignal2->Integral() << std::endl; // std::cout << "Efficiency with rel iso cut at 0.05 : " << histoSignal2->Integral( 1, histoSignal2->FindBin(0.05) ) / histoSignal2->Integral() << std::endl; // } // } TFile * signalInputFile3= new TFile (signal3+anaType+".root", "READ"); TH1F * histoSignal3 = (TH1F*)signalInputFile3->Get(histoName); histoSignal3->SetStats(0); histoSignal3->Scale(lumi); // // BACKGROUND MC // THStack stack("Background MC",""); setPlotTitle(stack, lumi); // Add all different background MC to this stack TLegend *legend= new TLegend(0.5,0.6,0.85,0.85); totalBkgMCIntegral = addBackgroundHistos(anaType, histoName, stack, legend, lumi, minIntegral, maxIntegral); // if ( histoName=="nMinus1_isolationLeptonH_removedLifetimeCuts" || histoName=="nMinus1_relIsolationLeptonH_removedLifetimeCuts" ) { // std::cout << "Integral of background between " << minIntegral << " and " << maxIntegral << " : " << totalBkgMCIntegral << std::endl; // } // Output histograms to file outputFile->cd(); // Setup canvas TCanvas canvas(histoName); canvas.cd(); // Draw one or two pads TPad * up = new TPad("u","u",0.01,0.25,0.99,0.99); up->SetNumber(1); up->Draw(); TPad * dp = new TPad("d","d",0.01,0.01,0.99,0.25); if ( drawRatioPlot ) { dp->SetNumber(2); dp->UseCurrentStyle(); dp->Draw(); } else { up->SetPad(0.01,0.01,0.99,0.99); up->Draw(); } if ( logY ) up->SetLogy(); canvas.Draw(); canvas.cd(1); up->cd(); canvas.SetFillColor(kWhite); canvas.SetBorderMode(0); // Draw background MC // There may be zero entries, which will mess up drawing options // Not a good fix at the moment bool axesExist=false; if (totalBkgMCIntegral>0) { axesExist=true; stack.Draw("HISTE"); stack.GetXaxis()->SetRangeUser(xMin, xMax); stack.SetMaximum(yMax); stack.SetMinimum(yMin); stack.GetXaxis()->SetTitle(xTitle); stack.GetYaxis()->SetTitle("Entries"); } std::cout << "Drawing signal histos" << std::endl; // Draw signal MC histoSignal1->SetLineStyle(2); histoSignal1->SetLineColor(kMagenta+2); histoSignal1->SetLineWidth(2); if(axesExist) histoSignal1->Draw("same,HIST"); else histoSignal1->Draw("HIST"); histoSignal2->SetLineStyle(2); histoSignal2->SetLineColor(kGreen+2); histoSignal2->SetLineWidth(2); if(axesExist) histoSignal2->Draw("same,HIST"); else histoSignal2->Draw("HIST"); // histoSignal3->SetLineStyle(2); // histoSignal3->SetLineColor(4); // histoSignal3->SetLineWidth(2); // histoSignal3->Draw("same,HIST"); // Draw data if ( plotData ) { if (axesExist) histoData->Draw("same,P,E,X0"); else histoData->Draw("P,E,X0"); } // Draw legend legend->SetBorderSize(0); legend->SetFillStyle(0); if ( plotData ) legend->AddEntry(histoData,"data","p"); legend->AddEntry(histoSignal1,"m_{H}=1000 GeV/c^{2} m_{X}=350 GeV/c^{2}","l"); legend->AddEntry(histoSignal2,"m_{H}=400 GeV/c^{2} m_{X}=50 GeV/c^{2}","l"); // legend->AddEntry(histoSignal3,"m_{squark}=350 GeV/c^{2} m_{#Chi}=148 GeV/c^{2}","l"); legend->Draw(); canvas.Update(); // Draw mc/data ratio if ( drawRatioPlot ) { dp->cd(); TH1F ratioHist( drawMCDataRatio( ((TH1*)stack.GetStack()->Last()), histoData ) ); // Check content of ratioHist ratioHist.GetXaxis()->SetRangeUser(xMin, xMax); ratioHist.SetMarkerStyle(20); ratioHist.GetYaxis()->SetNdivisions(5,0,0); ratioHist.GetYaxis()->SetTickLength(0.01); dp->SetGridy(); ratioHist.Draw("P"); canvas.Update(); canvas.Write(); } else canvas.Write(); // Draw systematic errors for reco PV plot // FIXME For some reason, old canvas can't handle this! if ( histoName=="nRecoPV" ) { TGraphAsymmErrors gr( makePUPlot( stack, anaType, lumi ) ); // Move back to output file (as other files have been opened and closed in makePUPlot outputFile->cd(); gr.SetFillColor(1); gr.SetFillStyle(3001); gr.Draw("2P0"); canvas.Update(); // Test TCanvas can("puSystematic"); can.cd(); // can.SetLogy(); can.Draw(); gr.SetTitle("TGraphAsymmErrors Example"); stack.Draw("HISTE"); gr.Draw("2P0"); histoData->Draw("P,E,X0SAME"); legend->Draw(); can.Update(); can.Write(); } }