#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "TROOT.h" #include "TH1F.h" #include "TFile.h" #include "TCanvas.h" #include "TLegend.h" using namespace std; void overlay_hist(){ //TChain for ttH std::ifstream file ("list_ttH.txt"); std::string str; std::string file_contents; std::string treename; TChain *ch = new TChain ("nominal"); while (std::getline(file,str)) { file_contents = str; const char* filename = file_contents.c_str(); std::cout << "name: " << filename << "\n"; treename = file_contents + "/nominal"; const char* name = treename.c_str(); ch->AddFile(name); } //TChain for ttbar std::ifstream file1 ("list_ttbar.txt"); std::string str1; std::string file_contents1; std::string treename1; TChain *ch2 = new TChain ("nominal"); while (std::getline(file1,str1)) { file_contents1 = str1; const char* filename1 = file_contents1.c_str(); std::cout << "name: " << filename1 << "\n"; treename1 = file_contents1 + "/nominal"; const char* name1 = treename1.c_str(); ch2->AddFile(name1); } TTree *ttHTree = new TTree("tth_final", "ttH_weighted_cs"); TTree *ttbarTree = new TTree("ttbar_final", "ttbar_weighted_cs"); ttHTree = (TTree*)ch->CloneTree(0); ttbarTree = (TTree*)ch2->CloneTree(0); Double_t cross_section1; Double_t cross_section2; UInt_t mcChannelNumber; Int_t ejets_2015_ttH; Int_t ejets_2016_ttH; Int_t mujets_2015_ttH; Int_t mujets_2016_ttH; Int_t ejets_2015_ttbar; Int_t ejets_2016_ttbar; Int_t mujets_2015_ttbar; Int_t mujets_2016_ttbar; vector * jet_e_ttH; vector * jet_e_ttbar; mcChannelNumber = 0; cross_section1 = 0; cross_section2 = 0; ejets_2015_ttH = 0; ejets_2016_ttH = 0; mujets_2015_ttH = 0; mujets_2016_ttH = 0; ejets_2015_ttbar = 0; ejets_2016_ttbar = 0; mujets_2015_ttbar = 0; mujets_2016_ttbar = 0; //ttH ch->SetBranchAddress("mcChannelNumber", &mcChannelNumber); ch->SetBranchAddress("ejets_2015", &ejets_2015_ttH); ch->SetBranchAddress("ejets_2016", &ejets_2016_ttH); ch->SetBranchAddress("mujets_2015", &mujets_2015_ttH); ch->SetBranchAddress("mujets_2016", &mujets_2016_ttH); ch->SetBranchAddress("jet_e", &jet_e_ttH); //ttbar ch2->SetBranchAddress("ejets_2015", &ejets_2015_ttbar); ch2->SetBranchAddress("ejets_2016", &ejets_2016_ttbar); ch2->SetBranchAddress("mujets_2015", &mujets_2015_ttbar); ch2->SetBranchAddress("mujets_2016", &mujets_2016_ttbar); ch2->SetBranchAddress("jet_e", &jet_e_ttbar); ttHTree->Branch("cross_section", &cross_section1); ttbarTree->Branch("cross_section", &cross_section2); //tth loop for 4 jets for(Int_t ievt =0; ievt < ch->GetEntries(); ievt++){ if(jet_e_ttH->size() == 4){ ch->GetEntry(ievt); if(mcChannelNumber == 343365) cross_section1 = 0.05343; if(mcChannelNumber == 343366) cross_section1 = 0.22276; if(mcChannelNumber == 343367) cross_section1 = 0.23082; ttHTree->Fill(); } } //ttbar loop for 4 jets for(Int_t ievt =0; ievt < ch2->GetEntries(); ievt++){ if(jet_e_ttbar->size() == 4){ ch2->GetEntry(ievt); cross_section2 = 377.9932 * 1.1949; ttbarTree->Fill(); } } //ttH for electrons for(Int_t ievt =0; ievt < ch->GetEntries(); ievt++){ ch->GetEntry(ievt); if(ejets_2015_ttH == 1 && ejets_2016_ttH == 1){ if(mcChannelNumber == 343365) cross_section1 = 0.05343; if(mcChannelNumber == 343366) cross_section1 = 0.22276; if(mcChannelNumber == 343367) cross_section1 = 0.23082; ttHTree->Fill(); } } // TTree *t1 = (TTree *)->Get("ttbarTree"); TH1F *h1 = new TH1F ("ttbar","Log_likelihood_minR_allhad", 100, -110, -25); ttbarTree->Project("ttbar","klfitter_logLikelihood","weight_mc * cross_section"); h1->Scale(1/h1->Integral()); // TTree *t2 = (TTree *)->Get("ttHtree"); //loads the Tree named "nominal" TH1F *h2 = new TH1F ("ttH","Log_likelihood_minR_allhad", 100, -110, -25); ttHTree->Project("ttH","klfitter_logLikelihood","weight_mc * cross_section"); h2->Scale(1/h2->Integral());//normalizes the histogram. }