/* This tool allows to retrieve and write in a root file all the templates variations in all regions needed for template fit with systematic, with regular bin size Run with: >root root [0] .L TemplatesMaker.C root [1] TemplatesMaker("...") Region="SR", "CR", "btagR", "BDT" SampleType = "data", "VBS", "VBS_S2", "QCD_aMCAtNLO", "QCD_S222", "QCD_S224", "ttbar", "Zpjets", "ZpjetsDD", "WZqcd", "WZewkSFP", "WZewkSFM", "WZewkOFP", "WZewkOFM","SingleT" LeptonType = "elec", "muon" SliceType = "1", "2", "3", "4", "5" RegionABCD= "A", "B", "C", "D" */ using namespace std; #include #include "TNtupleD.h" #include "TProfile.h" #include #include #include #include #include #include #include "TMath.h" #include "TLorentzVector.h" #include "TTree.h" #include "TTreeReader.h" #include "TLeaf.h" #include #include #include #include #include #include #include void TemplatesMaker(TString Region, TString SampleType, TString LeptonType="elec", TString SliceType="1", TString RegionABCD= "A", bool debug=false){ cout<<"Run with region: "<Sumw2(); //histograms with regular bins from the initial histograms (for the template fit) TH1F *h_mjj_BS=new TH1F(nameTemp_BS, "", bins,0, bins); //signal h_mjj_BS->Sumw2(); TFile *f0; TString dir=""; if(SampleType == "data") dir="/nfs/dust/atlas/user/ychinn/llgammaMxAOD/h024VBStestPflow/"; else //dir="/nfs/dust/atlas/user/ychinn/llgammaMxAOD/h024VBStest/mc16a/"; dir="/nfs/dust/atlas/user/ychinn/llgammaMxAOD/h024VBStestPflow/mc16a/"; TString fileToGet=""; TString nameHistoCF=""; if(LeptonType == "elec"){ if(SampleType == "VBS"){ fileToGet="user.yyap.user.yyap.20191206.mc16a.363267.h024VBStestPflow_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_EWKZeegamma_weighted"; } if(SampleType == "ttbar"){ fileToGet="user.yyap.mc16a.410389.MadGraphPythia8EvtGen_A14NNPDF23_ttgamma_nonallhadronic.p3703.h024VBStestPflow_MxAOD.root/merge.root"; nameHistoCF="CutFlow_MGPy8_ttgamma_nonallhadronic_weighted"; } if(SampleType == "WZqcd"){ fileToGet="user.yyap.mc16a.364253.Sherpa_222_NNPDF30NNLO_lllv.p3793.h024VBStestPflow_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa_364253_lllv_weighted"; } if(SampleType == "singleT"){ fileToGet="user.yyap.mc16a.412120.MadGraphPythia8EvtGen_A14NNPDF23_tWgamma.a875_p3793.h024VBStestPflow3_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_tWgamma_weighted"; } if(SampleType == "WZewkSFP"){ fileToGet="user.yyap.mc16a.364742.MGPy8EG_NNPDF30NLO_lvlljjEW6_SFPlus.p3793.h024VBStestPflow1_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_lvlljjEW6_SFPlus_weighted"; } if(SampleType == "WZewkSFM"){ fileToGet="user.yyap.mc16a.364741.MGPy8EG_NNPDF30NLO_lvlljjEW6_SFMinus.p3793.h024VBStestPflow1_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_lvlljjEW6_SFMinus_weighted"; } if(SampleType == "WZewkOFP"){ fileToGet="user.yyap.mc16a.364740.MGPy8EG_NNPDF30NLO_lvlljjEW6_OFPlus.p3793.h024VBStestPflow1_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_lvlljjEW6_OFPlus_weighted"; } if(SampleType == "WZewkOFM"){ fileToGet="user.yyap.mc16a.364739.MGPy8EG_NNPDF30NLO_lvlljjEW6_OFMinus.p3793.h024VBStestPflow_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_lvlljjEW6_OFMinus_weighted"; } if(SampleType == "QCD_aMCAtNLO"){ if(SliceType == "1"){ fileToGet="user.yyap.mc16a.345775.aMcAtNloPythia8_NNPDF30NLO_FxFx_eegamma_HT0_125.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_345775_weighted"; } if(SliceType == "2"){ fileToGet="user.yyap.mc16a.345776.aMcAtNloPythia8_NNPDF30NLO_FxFx_eegamma_HTGT125_MjjLT150.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_345776_weighted"; } if(SliceType == "3"){ fileToGet="user.yyap.mc16a.345777.aMcAtNloPythia8_NNPDF30NLO_FxFx_eegamma_HTGT125_MjjLT500.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_345777_weighted"; } if(SliceType == "4"){ fileToGet="user.yyap.mc16a.345778.aMcAtNloPythia8_NNPDF30NLO_FxFx_eegamma_HTGT125_MjjGT500.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_345778_weighted"; } } if(SampleType == "QCD_S222"){ if(SliceType == "1"){ fileToGet="user.yyap.mc16a.364500.Sherpa_222_NNPDF30NNLO_eegamma_pty_7_15.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa2_eegamma_pty_7_15_weighted"; } if(SliceType == "2"){ fileToGet="user.yyap.mc16a.364501.Sherpa_222_NNPDF30NNLO_eegamma_pty_15_35.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa2_eegamma_pty_15_35_weighted"; } if(SliceType == "3"){ fileToGet="user.yyap.mc16a.364502.Sherpa_222_NNPDF30NNLO_eegamma_pty_35_70.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa2_eegamma_pty_35_70_weighted"; } if(SliceType == "4"){ fileToGet="user.yyap.mc16a.364503.Sherpa_222_NNPDF30NNLO_eegamma_pty_70_140.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa2_eegamma_pty_70_140_weighted"; } if(SliceType == "5"){ fileToGet="user.yyap.mc16a.364504.Sherpa_222_NNPDF30NNLO_eegamma_pty_140_E_CMS.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa2_eegamma_pty_140_weighted"; } } if(SampleType == "QCD_S224"){ if(SliceType == "1"){ fileToGet="user.yyap.mc16a.366140.Sh_224_NN30NNLO_eegamma_LO_pty_7_15.p3705.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa_366140_weighted"; } if(SliceType == "2"){ fileToGet="user.yyap.mc16a.366141.Sh_224_NN30NNLO_eegamma_LO_pty_15_35.p3705.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa_366141_weighted"; } if(SliceType == "3"){ fileToGet="user.yyap.mc16a.366142.Sh_224_NN30NNLO_eegamma_LO_pty_35_70.p3705.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa_366142_weighted"; } if(SliceType == "4"){ fileToGet="user.yyap.mc16a.366143.Sh_224_NN30NNLO_eegamma_LO_pty_70_140.p3705.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa_366143_weighted"; } if(SliceType == "5"){ fileToGet="user.yyap.mc16a.366144.Sh_224_NN30NNLO_eegamma_LO_pty_140_E_CMS.p3705.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa_366144_weighted"; } } } if(LeptonType == "muon"){ if(SampleType == "VBS"){ fileToGet="user.yyap.user.yyap.20191206.mc16a.363268.h024VBStestPflow_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_EWKZmumugamma_weighted"; } if(SampleType == "QCD_aMCAtNLO"){ if(SliceType == "1"){ //fileToGet="user.yyap.mc16a.345779.aMcAtNloPythia8_NNPDF30NLO_FxFx_mumugamma_HT0_125.p3565.h024VBStest2_MxAOD.root/merge.root"; fileToGet="user.yyap.mc16a.345779.aMcAtNloPythia8_NNPDF30NLO_FxFx_mumugamma_HT0_125.p3795.h024VBStestPflow_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_345779_weighted"; //nameHistoCF="CutFlow_Madgraph_345779"; } if(SliceType == "2"){ //fileToGet="user.yyap.mc16a.345780.aMcAtNloPythia8_NNPDF30NLO_FxFx_mumugamma_HTGT125_MjjLT150.p3565.h024VBStest2_MxAOD.root/merge.root"; fileToGet="user.yyap.mc16a.345780.aMcAtNloPythia8_NNPDF30NLO_FxFx_mumugamma_HTGT125_MjjLT150.p3795.h024VBStestPflow_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_345780_weighted"; //nameHistoCF="CutFlow_Madgraph_345780"; } if(SliceType == "3"){ //fileToGet="user.yyap.mc16a.345781.aMcAtNloPythia8_NNPDF30NLO_FxFx_mumugamma_HTGT125_MjjLT500.p3565.h024VBStest2_MxAOD.root/merge.root"; fileToGet="user.yyap.mc16a.345781.aMcAtNloPythia8_NNPDF30NLO_FxFx_mumugamma_HTGT125_MjjLT500.p3795.h024VBStestPflow_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_345781_weighted"; //nameHistoCF="CutFlow_Madgraph_345781"; } if(SliceType == "4"){ //fileToGet="user.yyap.mc16a.345782.aMcAtNloPythia8_NNPDF30NLO_FxFx_mumugamma_HTGT125_MjjGT500.p3565.h024VBStest2_MxAOD.root/merge.root"; fileToGet="user.yyap.mc16a.345782.aMcAtNloPythia8_NNPDF30NLO_FxFx_mumugamma_HTGT125_MjjGT500.p3795.h024VBStestPflow_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Madgraph_345782_weighted"; //nameHistoCF="CutFlow_Madgraph_345782"; } } if(SampleType == "QCD_S222"){ if(SliceType == "1"){ fileToGet="user.yyap.mc16a.364505.Sherpa_222_NNPDF30NNLO_mumugamma_pty_7_15.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa2_mumugamma_pty_7_15_weighted"; //nameHistoCF="CutFlow_Sherpa2_mumugamma_pty_7_15"; } if(SliceType == "2"){ fileToGet="user.yyap.mc16a.364506.Sherpa_222_NNPDF30NNLO_mumugamma_pty_15_35.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa2_mumugamma_pty_15_35_weighted"; //nameHistoCF="CutFlow_Sherpa2_mumugamma_pty_15_35"; } if(SliceType == "3"){ fileToGet="user.yyap.mc16a.364507.Sherpa_222_NNPDF30NNLO_mumugamma_pty_35_70.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa2_mumugamma_pty_35_70_weighted"; //nameHistoCF="CutFlow_Sherpa2_mumugamma_pty_35_70"; } if(SliceType == "4"){ fileToGet="user.yyap.mc16a.364508.Sherpa_222_NNPDF30NNLO_mumugamma_pty_70_140.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa2_mumugamma_pty_70_140_weighted"; //nameHistoCF="CutFlow_Sherpa2_mumugamma_pty_70_140"; } if(SliceType == "5"){ fileToGet="user.yyap.mc16a.364509.Sherpa_222_NNPDF30NNLO_mumugamma_pty_140_E_CMS.p3565.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa2_mumugamma_pty_140_weighted"; //nameHistoCF="CutFlow_Sherpa2_mumugamma_pty_140"; } } if(SampleType == "QCD_S224"){ if(SliceType == "1"){ fileToGet="user.yyap.mc16a.366145.Sh_224_NN30NNLO_mumugamma_LO_pty_7_15.p3705.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa_366145_weighted"; //nameHistoCF="CutFlow_Sherpa_366145"; } if(SliceType == "2"){ fileToGet="user.yyap.mc16a.366146.Sh_224_NN30NNLO_mumugamma_LO_pty_15_35.p3705.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa_366146_weighted"; //nameHistoCF="CutFlow_Sherpa_366146"; } if(SliceType == "3"){ fileToGet="user.yyap.mc16a.366147.Sh_224_NN30NNLO_mumugamma_LO_pty_35_70.p3705.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa_366147_weighted"; //nameHistoCF="CutFlow_Sherpa_366147"; } if(SliceType == "4"){ fileToGet="user.yyap.mc16a.366148.Sh_224_NN30NNLO_mumugamma_LO_pty_70_140.p3705.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa_366148_weighted"; //nameHistoCF="CutFlow_Sherpa_366148"; } if(SliceType == "5"){ fileToGet="user.yyap.mc16a.366149.Sh_224_NN30NNLO_mumugamma_LO_pty_140_E_CMS.p3705.h024VBStest2_MxAOD.root/merge.root"; nameHistoCF="CutFlow_Sherpa_366149_weighted"; //nameHistoCF="CutFlow_Sherpa_366149"; } } } if(SampleType == "data") //fileToGet="data1516.root"; //fileToGet="user.yyap.data15_13TeV.p3876.root"; //fileToGet="user.yyap.data16_13TeV.p3876.root"; //fileToGet="user.yyap.data17_13TeV.p3876.root"; fileToGet="user.yyap.data18_13TeV.p3876.root"; TString all=""; all=dir+fileToGet; f0=TFile::Open(all); cout<Get("CollectionTree"); TH1F*hCF=(TH1F*)f0->Get(nameHistoCF); hCF->Sumw2(); cout<<"1st bin content "<GetBinContent(1)<Get(nameHistoCF); }*/ int nev0 = t0->GetEntries(); cout<<"nev0 "< v_jetpt; std::vector v_jeteta; std::vector v_jetphi; std::vector v_photonpt; std::vector v_photonptcone20; std::vector v_photoneta; std::vector v_photonphi; std::vector v_tight; std::vector v_iso; TTreeReader reader("CollectionTree", f0); //TTree *t = (TTree*)f0->Get("CollectionTree"); //TTreeReader reader(t); //TTreeReaderValue> jetpt(reader, "HGamAntiKt4EMPFlowJetsAuxDyn.pt"); //TTreeReaderValue> jeteta(reader, "HGamAntiKt4EMPFlowJetsAuxDyn.eta"); //TTreeReaderValue> jetphi(reader, "HGamAntiKt4EMPFlowJetsAuxDyn.phi"); TTreeReaderValue< vector > jetpt(reader, "HGamAntiKt4EMTopoJetsAuxDyn.pt"); TTreeReaderValue< vector > jeteta(reader, "HGamAntiKt4EMTopoJetsAuxDyn.eta"); TTreeReaderValue< vector > jetphi(reader, "HGamAntiKt4EMTopoJetsAuxDyn.phi"); TTreeReaderValue m_jj(reader, "HGamEventInfoAuxDyn.m_jj"); TTreeReaderValue weight(reader, "HGamEventInfoAuxDyn.weight"); TString XSreader=""; if(SampleType!="data") XSreader="HGamEventInfoAuxDyn.crossSectionBRfilterEff"; else XSreader="HGamEventInfoAuxDyn.weight"; TTreeReaderValue weightCrossSection(reader, XSreader); TTreeReaderValue centrality(reader, "HGamEventInfoAuxDyn.Zy_centrality"); TTreeReaderValue N_j_btag(reader, "HGamEventInfoAuxDyn.N_j_btag30"); TTreeReaderValue N_j(reader, "HGamEventInfoAuxDyn.N_j"); TTreeReaderValue> photonpt(reader, "HGamPhotonsAuxDyn.pt"); TTreeReaderValue> photoneta(reader, "HGamPhotonsAuxDyn.eta"); TTreeReaderValue> photonphi(reader, "HGamPhotonsAuxDyn.phi"); TTreeReaderValue> photonptcone20(reader, "HGamPhotonsAuxDyn.ptcone20"); TTreeReaderValue pass(reader, "HGamEventInfoAuxDyn.isPassedZyVBSPreSel"); //TTreeReaderValue pass(reader, "HGamEventInfoAuxDyn.isPassedZy"); //TTreeReaderValue pass(reader, "HGamEventInfoAuxDyn.isPassedZyPreSel"); TTreeReaderValue> tight(reader, "HGamPhotonsAuxDyn.isTight"); TTreeReaderValue> iso(reader, "HGamPhotonsAuxDyn.isIsoFixedCutLoose"); TTreeReaderValue N_e(reader, "HGamEventInfoAuxDyn.N_e"); TTreeReaderValue N_mu(reader, "HGamEventInfoAuxDyn.N_mu"); TTreeReaderValue m_ll(reader, "HGamEventInfoAuxDyn.m_ll"); TTreeReaderValue m_lly(reader, "HGamEventInfoAuxDyn.m_lly"); cout<<"after variables "<Sumw2(); h_mj->Sumw2(); h_ptj1->Sumw2(); h_ptj2->Sumw2(); h_ptg->Sumw2(); h_etag->Sumw2(); h_phig->Sumw2(); h_etaj1->Sumw2(); h_etaj2->Sumw2(); h_Zgcentr->Sumw2(); h_weight->Sumw2(); h_weight1->Sumw2(); h_weight2->Sumw2(); cout<<"after histo "<at(0); ptj1 = v_jetpt[0]*1e-3; //cout<<"ptj1 "<Fill(weight2*weightXS); h_weight1->Fill(weight2); h_weight2->Fill(weightXS); //=========== SELECTION ===============// //if(isPass && isTight && isIso && (Ne+Nmu)==2 && (mll+mlly)>182){ //if(isPass && (Ne+Nmu)==2 && (mll+mlly)>182){ //if(isPass && (Ne+Nmu)==2 && (mll+mlly)>182 && (ptcone20g<(0.05*ptg))){ if(isPass && (Ne+Nmu)==2 && (mll+mlly)>182 && (ptcone20g<(0.05*ptg)) && isTight && isIso){ //if(isPass){ if(Region=="SR"){ if(ngj>=2 && mjj>500 && ptj1>JETcut && ptj2>JETcut && nBJets==0 && fabs(Zgcentr)<=5 && fabs(etaJet1-etaJet2)>dYcut){ h_mjj->Fill(fabs(Zgcentr), weight2*weightXS); m_count++; } }if(Region=="CR"){ if(ngj>=2 && mjj>150 && mjj<=500 && ptj1>JETcut && ptj2>JETcut && nBJets==0 && fabs(Zgcentr)<=5 && fabs(etaJet1-etaJet2)>dYcut){ h_mjj->Fill(fabs(Zgcentr), weight2*weightXS); m_count++; } }if(Region=="btagR"){ if(ngj>=2 && mjj>150 && ptj1>JETcut && ptj2>JETcut && nBJets>0 && fabs(Zgcentr)<=5 && fabs(etaJet1-etaJet2)>dYcut){ if(nBJets>3) nBJets=3; //put all outliers in the last bin h_mjj->Fill(nBJets, weight2*weightXS); m_count++; } } if(Region=="BDT"){ //if(ngj>=2 && mjj>150 && ptj1>JETcut && ptj2>JETcut && nBJets==0 && fabs(Zgcentr)<=5){ //if(ngj>=2 && mjj>150 && ptj1>JETcut && ptj2>JETcut && nBJets==0 && fabs(Zgcentr)<=5 && fabs(etaJet1-etaJet2)>dYcut){ //if(ngj>=0){ //if(ngj>=2 && mjj>150){ //if(ngj>=2 && mjj>150 && ptj1>JETcut ){ //if(ngj>=2 && mjj>150 && ptj1>JETcut && ptj2>JETcut ){ //if(ngj>=2 && mjj>150 && ptj1>JETcut && ptj2>JETcut && nBJets==0 ){ //if(ngj>=2 && mjj>150 && ptj1>JETcut && ptj2>JETcut && nBJets==0 && fabs(Zgcentr)<=5 ){ //with isPassZgVBSPreSel flag if(ngj>=2 && nBJets==0 && fabs(Zgcentr)<=5){ m_count++; m_countw1 +=weight2; m_countw2 +=weightXS; m_countw +=(weight2*weightXS); h_mjj->Fill(fabs(Zgcentr), weight2*weightXS); h_ngj->Fill(ngj, weight2*weightXS); h_mj->Fill(mjj, weight2*weightXS); h_ptj1->Fill(ptj1, weight2*weightXS); h_ptj2->Fill(ptj2, weight2*weightXS); h_etaj1->Fill(etaJet1, weight2*weightXS); h_etaj2->Fill(etaJet2, weight2*weightXS); h_Zgcentr->Fill(Zgcentr, weight2*weightXS); h_ptg->Fill(ptg, weight2*weightXS); h_etag->Fill(etag, weight2*weightXS); h_phig->Fill(phig, weight2*weightXS); //h_mjj->Fill(BDTout, weight2*weightXS); //cout<<"pass full selection "<GetBinContent(1)); cout<<"m_countw "<Scale(36000/hCF->GetBinContent(1)); h_ngj->Scale(36000/hCF->GetBinContent(1)); h_mj->Scale(36000/hCF->GetBinContent(1)); h_ptj1->Scale(36000/hCF->GetBinContent(1)); h_ptj2->Scale(36000/hCF->GetBinContent(1)); h_etaj1->Scale(36000/hCF->GetBinContent(1)); h_etaj2->Scale(36000/hCF->GetBinContent(1)); h_Zgcentr->Scale(36000/hCF->GetBinContent(1)); h_ptg->Scale(36000/hCF->GetBinContent(1)); h_etag->Scale(36000/hCF->GetBinContent(1)); h_phig->Scale(36000/hCF->GetBinContent(1)); } for (int b =0; b< bins+1; b++) { h_mjj_BS->SetBinContent(b+1, h_mjj->GetBinContent(b+1)); h_mjj_BS->SetBinError(b+1, h_mjj->GetBinError(b+1)); } h_mjj_BS->Write(); cout<<"Write mjj"<Write(); h_mj->Write(); h_ptj1->Write(); h_ptj2->Write(); h_etaj1->Write(); h_etaj2->Write(); h_Zgcentr->Write(); h_weight->Write(); h_weight1->Write(); h_weight2->Write(); h_ptg->Write(); h_etag->Write(); h_phig->Write(); if(SampleType!="data") hCF->Write("hCF"); result->Close(); f0->Close(); delete h_mjj;h_mjj=0; delete h_mjj_BS; h_mjj_BS=0; }