#include #include #include #include "TChain.h" #include "TH1.h" #include "TTree.h" #include "TKey.h" #include "Riostream.h" #include "TCanvas.h" #include "TFile.h" #include "TH2.h" #include "TLegend.h" #include "TROOT.h" #include "TStyle.h" #include #include #include #include "TList.h" #include #include "TObject.h" #include "TBranch.h" #include #include "TAxis.h" using namespace std; void Impose( TDirectory *ttarget, TList *ssourcelist, string &np_legend , vector titles_ ); void ModifyHist (TH1F * &h, int cl,vector title); void Overlap() { vector titles; TList *FileList; TFile *Target; titles.clear(); titles.push_back("PseudoData"); titles.push_back("TtZJets"); titles.push_back("TtWJets"); titles.push_back("TtGJets"); titles.push_back("TtWWJets"); titles.push_back("WZJetsTo3LNu"); titles.push_back("WZJetsTo2L2Q"); titles.push_back("WZJetsTo2Q2Nu"); titles.push_back("ZZTo2L2Nu"); titles.push_back("ZZTo2L2Q"); titles.push_back("WWGJets"); titles.push_back("WWJetsTo2L2Nu"); titles.push_back("WWDS"); titles.push_back("WmWmqq"); titles.push_back("WWZJets"); titles.push_back("Z3Jets"); titles.push_back("Z4Jets"); titles.push_back("ST_t_t"); titles.push_back("ST_t_tbar"); titles.push_back("ST_tW_t"); titles.push_back("ST_tW_tbar"); titles.push_back("ST_s_t"); titles.push_back("ST_s_tbar"); titles.push_back("W3Jets"); titles.push_back("W4Jets"); titles.push_back("TTnlo"); string fout = "mergedData.root"; FileList = new TList (); for (int i=0; iAdd (TFile::Open (file.c_str())); } Target = TFile::Open (fout.c_str (), "RECREATE"); string np_title = titles[0]; Impose (Target, FileList, np_title,titles); delete FileList; delete Target; } void Impose (TDirectory * target, TList * sourcelist, string & np_title_, vector titles) { TString path ((char *) strstr (target->GetPath (), ":")); path.Remove (0, 2); float Lumi=19125.189; vector lumiweights; lumiweights.clear(); lumiweights.push_back(float(Lumi)); lumiweights.push_back(float(1221848.84));//TTZ lumiweights.push_back(float(912266.17));//TTW lumiweights.push_back(float(33147.22));//TTG lumiweights.push_back(float(106931762));//TTWW lumiweights.push_back(float(2313379.06));//WZJets3LNu lumiweights.push_back(float(1832468.94));//WZJets2L2Q lumiweights.push_back(float(537062.6780));//WZJets2Q2Nu lumiweights.push_back(float(3356246.428));//ZZJets2L2Nu lumiweights.push_back(float(2095585.71));//ZZJets2LQ lumiweights.push_back(float(407426.1363));//WWG lumiweights.push_back(float(411325.96));//WWJets2L2Nu lumiweights.push_back(float(1418669.84));//WWDS lumiweights.push_back(float(1085495.495));//WmWmqq lumiweights.push_back(float(3510805.69));//WWZ lumiweights.push_back(float(21093.104));//Z3Jets lumiweights.push_back(float(29353.1));//Z4Jets lumiweights.push_back(float(66468.6525));//ST_t_t lumiweights.push_back(float(58866.3518));//ST_t_tb lumiweights.push_back(float(44833.8640));//ST_tW_t lumiweights.push_back(float(43339.7297));//ST_tW_tb lumiweights.push_back(float(68591.029));//ST_s_t lumiweights.push_back(float(79530.68));//ST_s_tb lumiweights.push_back(float(23122.4822));//W3Jets lumiweights.push_back(float(52433.8092));//W4Jets lumiweights.push_back(float(154395.43));//TTnlo NNLO thoeretical TH1F* allbkg; TFile *first_source = (TFile *) sourcelist->First (); first_source->cd (); TDirectory *current_sourcedir = gDirectory; Bool_t status = TH1::AddDirectoryStatus (); TH1::AddDirectory (kFALSE); TChain *globChain = 0; TIter nextkey (current_sourcedir->GetListOfKeys ()); TKey *key, *oldkey = 0; int count=0; while ((key = (TKey *) nextkey ())) { count++; if (count>1) break; if (oldkey && !strcmp (oldkey->GetName (), key->GetName ())) continue; first_source->cd (path); TObject *obj = key->ReadObj (); //TCanvas *c2 = new TCanvas ("c2",obj->GetName () ,0,22,1350,750); TH1F* hh[100]; if (obj->IsA ()->InheritsFrom ("TH1F") ) { TH1F *h1 = (TH1F *) obj; h1->SetMinimum(0); ModifyHist (h1,1,Lumi,lumiweights[0],titles[0]); TFile *nextsource = (TFile *) sourcelist->After (first_source); int cl; h1->SetStats(0); h1->SetLineWidth(2); cl=1; h1->SetLineStyle(1); h1->Draw("ep1"); hh[cl]=h1; THStack *hs = new THStack(h1->GetName(),h1->GetTitle()); allbkg = (TH1F*) hh[1]->Clone(); allbkg->Add(hh[1],-1); while (nextsource) { nextsource->cd (path); TKey *key2 = (TKey *) gDirectory->GetListOfKeys ()->FindObject (h1->GetName ()); if (key2) { cl++; TH1F *h2; h2 = (TH1F*) key2->ReadObj (); h2->SetMinimum(0); ModifyHist (h2, cl,Lumi,lumiweights[cl-1],titles[cl-1]); h2->SetStats(0); h2->SetLineWidth(1.5); hh[cl] = h2; hs->Add(h2); if (cl>1) allbkg->Add(h2); h2->Draw("sames"); } nextsource = (TFile *) sourcelist->After (nextsource); } } if (obj) { target->cd (); TH1 *hsum = ((TH1 *)(hs->GetStack()->Last())); // the "SUM" for (int y=0;y<=hsum->GetNbinsX();y++) float dbn=hh[1]->GetBinContent(y); Int_t firstbin = hsum->FindFirstBinAbove(0); Int_t lastbin = hsum->FindLastBinAbove(0); hsum->GetXaxis()->SetRange(hsum->FindFirstBinAbove(0),hsum->FindLastBinAbove(0)); hsum->SetFillColor(0); hsum->Draw(); hs->Draw("same"); } } } void ModifyHist (TH1F * &h, int cl_ ,float & lumi,float & weight,string & title_) { double temp_integral; int nbins=h->GetNbinsX(); int nn=1; if ( nbins>149) {nn=5; h->Rebin(nn); } h->GetXaxis()->SetNdivisions(512); string titlee=h->GetName(); int col=kOrange; string title1,title2; if(title_.find("Pseudo") == 0) col= kBlack;//TT else if(title_.find("TT") == 0) col= kPink;//TT else if (std::string::npos != title_.find("W1Jets")) col= kBlue; else if (std::string::npos != title_.find("W2Jets")) col= kBlue; else if (std::string::npos != title_.find("W3Jets")) col= kBlue; else if (std::string::npos != title_.find("W4Jets")) col= kBlue; else if (std::string::npos != title_.find("WJets_HT")) col= kBlue; else if (std::string::npos != title_.find("Z1Jets")) col= kViolet; else if (std::string::npos != title_.find("Z2Jets")) col= kViolet; else if (std::string::npos != title_.find("Z3Jets")) col= kViolet; else if (std::string::npos != title_.find("Z4Jets")) col= kViolet; else if (std::string::npos != title_.find("ST")) col= kCyan; else col= kOrange;//other bkg h->SetLineColor (col); h->SetFillColor (col); double dic=double(lumi)/double(weight); string namet=h->GetName(); if (lumi>0 ) h->Scale (double(dic)); }