#include #include #include "TCanvas.h" #include "TH1.h" #include "TH1F.h" #include "TLegend.h" #include "TStyle.h" #include "TVirtualPad.h" void plotFromTreeTest() { bool log = true; TH1::SetDefaultSumw2(true); TCanvas* c1 = new TCanvas("c1", "c1", 700, 700); TPad *pad1 = new TPad("pad1","pad1",0,0.3,1,1); pad1->Draw(); pad1->cd(); std::string varexp("HT>>ht"); TH1F* ht = new TH1F("ht", "test", 10, 0, 10); log = true; ht->Fill(1); ht->Fill(2); ht->Fill(2); cout << "entries: " << ht->GetEntries() << endl; TH1F* hData = (TH1F*)ht->Clone("h_data"); TH1F* h = (TH1F*)ht->Clone("hs_data"); TLegend* legend = new TLegend(0.7,0.3,0.88,0.75); std::string name = "bkg"; ht->Fill(2); ht->Fill(3); ht->SetTitle(name.c_str()); TString hname = TString("hs_") + name; h = (TH1F*)ht->Clone(hname.Data()); legend->AddEntry(h); TH1F* hRatio = (TH1F*)hData->Clone("hRatio"); hData->Draw(); h->Draw("HIST SAME"); h->SetFillColor(kBlack); h->SetFillStyle(3001); h->Draw("E2 SAME"); hData->Draw("SAME"); hData->Draw("AXIS SAME"); legend->Draw(); gStyle->SetOptStat(1111); gPad->SetLogy(log); c1->cd(); TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3); pad2->Draw(); pad2->cd(); hRatio->SetTitle(""); hRatio->Divide(h); hRatio->SetFillColor(kBlack); hRatio->SetFillStyle(3001); hRatio->Draw("AXIS"); hRatio->Draw("E2 SAME"); gStyle->SetOptStat(0); gStyle->SetOptFit(1111); hRatio->Fit("pol0", "", "SAME"); //gStyle->SetOptStat(1111); }