#include "TFile.h" #include "TTree.h" #include "TString.h" #include "TH2.h" #include "TROOT.h" #include "TCanvas.h" void fakeratio_tqz1() { TFile *f = TFile::Open("May26_2.root"); if (!f || f->IsZombie()) { delete f; return; } // just a precaution TTree *t2; f->GetObject("demo/AnaTree", t2); if (!t2) { delete f; return; } // just a precaution TString SelMu_cut, VetoMu_cut; SelMu_cut = "selNonIsoMu_pt > 20 && selNonIsoMu_eta < 2.5 && selNonIsoMu_idTight == 1 && selNonIsoMu_ismuon == 1 && selNonIsoMu_iso < 0.12"; VetoMu_cut = SelMu_cut; // use the same cut double bins_x[] = {10, 20, 40, 70, 100}; double bins_y[] = {0, 1, 1.5, 2.5}; TH2F *h1 = new TH2F("h_SelMu", "Sel Muons;Pt_{T}^{} [GeV/c];#eta", (sizeof(bins_x) / sizeof(double) - 1), bins_x, (sizeof(bins_y) / sizeof(double) - 1), bins_y); t2->Project("h_SelMu", "SelMu_eta:SelMu_pt", SelMu_cut); TH2F *h2 = new TH2F("h_VetoMu", "Veto Muons;Pt_{T}^{} [GeV/c];#eta", (sizeof(bins_x) / sizeof(double) - 1), bins_x, (sizeof(bins_y) / sizeof(double) - 1), bins_y); t2->Project("h_VetoMu", "VetoMu_eta:VetoMu_pt", VetoMu_cut); TH2F *h3 = new TH2F(*h1); h3->SetNameTitle("h_ratio", "Sel Muons / Veto Muons;Pt_{T}^{} [GeV/c];#eta"); h3->Divide(h2); h1->SetDirectory(gROOT); // (gROOT) ... or ... (0) h2->SetDirectory(gROOT); // (gROOT) ... or ... (0) h3->SetDirectory(gROOT); // (gROOT) ... or ... (0) #if 1 /* 0 or 1 */ h1->SetName("tight muons"); h2->SetName("loose muons"); h3->SetName("ratio"); #endif /* 0 or 1 */ TCanvas *c1 = new TCanvas("c1", "c1", 800, 800); c1->Divide(2, 2); c1->cd(1); h1->Draw("colz text e"); c1->cd(2); h2->Draw("colz text e"); c1->cd(3); h3->Draw("colz text e"); c1->cd(0); delete f; // automatically deletes "t2", too }