diff --git a/bin/AnalyserSimpleExample.cc b/bin/AnalyserSimpleExample.cc new file mode 100644 index 00000000..edd52044 --- /dev/null +++ b/bin/AnalyserSimpleExample.cc @@ -0,0 +1,98 @@ +#include "Analysis/Tools/interface/Analyser.h" + +// this example is a dijet analysis in which the leading jet +// is required to have a muon, and both of the leading +// jets are btagged + +using namespace std; +using namespace analysis; +using namespace analysis::tools; + +int main(int argc, char ** argv) +{ + TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms + + Analyser analyser(argc,argv); + + // you can always get the ususal analysis class + auto analysis = analyser.analysis(); + +// HISTOGRAMS + // create some predefined jet histograms + analyser.jetHistograms(2,"dijet"); + // create some predefined muon histograms + // muon histograms still not available + + // get a map with all TH1F histograms pointers + std::map > histos = analyser.histograms(); + + for ( int i = 0 ; i < analyser.nEvents() ; ++i ) + { + if ( ! analyser.event(i) ) continue; + +// TRIGGER selection + if ( ! analyser.selectionHLT() ) continue; + if ( ! analyser.selectionL1 () ) continue; // to be used mainly in case of "OR" of seeds + +// MUONS pre-selection + // muon identification selection + if ( ! analyser.selectionMuonId() ) continue; + if ( ! analyser.selectionNMuons() ) continue; + // if you need the selected muons explicitly - be careful where you use it + std::vector< std::shared_ptr > selmuon = analyser.selectedMuons(); + +// JETS pre-selection + // jet identification selection + if ( ! analyser.selectionJetId() ) continue; + if ( ! analyser.selectionJetPileupId() ) continue; + if ( ! analyser.selectionNJets() ) continue; + // if you need the selected jets explicitly - be careful where you use it + std::vector< std::shared_ptr > seljets = analyser.selectedJets(); + +// CORRECTIONS to pre-selected jets + // b energy regression + if ( analyser.config()->bRegression() ) + analyser.actionApplyBjetRegression(); + + // MC-only jet corrections + if ( analyser.config()->isMC() ) + { + // apply btag SF + analyser.actionApplyBtagSF(1); + analyser.actionApplyBtagSF(2); + + // jet energy resolution to all selected jets + analyser.actionApplyJER(); + } + +// MAIN SELECTION + // JETS + // 1st and 2nd jet kinematic selection, pt and eta + if ( ! analyser.selectionJet(1) ) continue; + if ( ! analyser.selectionJet(2) ) continue; + // delta R jet selection + if ( ! analyser.selectionJetDr(1,2) ) continue; + // btag of two leading jets + if ( ! analyser.selectionBJet(1) ) continue; + if ( ! analyser.selectionBJet(2) ) continue; + // jets 1 and 2 matching to online jets + if ( ! analyser.onlineJetMatching(1) ) continue; + if ( ! analyser.onlineJetMatching(2) ) continue; + // dije mass selection + if ( ! analyser.selectionDiJetMass(1,2) ) continue; + + // MUON + // muon kinematic selection + if ( ! analyser.selectionMuons() ) continue; + // muon trigger matching - at least nmin offline muons matched to online objects + if ( ! analyser.onlineMuonMatching() ) continue; + + // MUONJET + if ( ! analyser.muonJet(1) ) continue; + +// HISTOGRAMS + analyser.fillJetHistograms("dijet"); + + } //end event loop +} // end main + diff --git a/bin/AnalyserTriggerExample.cc b/bin/AnalyserTriggerExample.cc new file mode 100644 index 00000000..972a82dd --- /dev/null +++ b/bin/AnalyserTriggerExample.cc @@ -0,0 +1,42 @@ +#include "Analysis/Tools/interface/Analyser.h" + +using namespace std; +using namespace analysis; +using namespace analysis::tools; + +int main(int argc, char ** argv) +{ + TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms + + Analyser trigger(argc,argv); + + auto analysis = trigger.analysis(); // that's the usual Analysis class + + for ( int i = 0 ; i < trigger.nEvents() ; ++i ) + { + if ( ! trigger.event(i) ) continue; + // trigger selection + if ( ! trigger.selectionHLT() ) continue; + if ( ! trigger.selectionL1 () ) continue; // to be used in case of "OR" of seeds + + // One can always use the usual Analysis to retrieve some information + auto l1jets_ana = analysis->collection(trigger.config()->triggerObjectsL1Jets()); + for ( int j = 0 ; j < l1jets_ana->size() ; ++j ) + { + TriggerObject l1jet = l1jets_ana->at(j); + std::cout << "L1 Jet (Analysis): pT = " << l1jet.pt() << ", " << l1jet.eta() << ", " << l1jet.phi() << std::endl; + } + std::cout << "----" << std::endl; + + // But sometimes there is a method in the analyser one can use directly + // L1 jets trigger objects + auto l1jets = trigger.triggerObjectsL1Jets(); + for ( auto jet : l1jets ) + { + std::cout << "L1 Jet (Analyser): pT = " << jet->pt() << ", " << jet->eta() << ", " << jet->phi() << std::endl; + } + std::cout << "====" << std::endl; + } + + return 0; +} diff --git a/bin/AnalysisBJets.cc b/bin/AnalysisBJets.cc deleted file mode 100644 index 451e58d0..00000000 --- a/bin/AnalysisBJets.cc +++ /dev/null @@ -1,94 +0,0 @@ -#include "boost/program_options.hpp" -#include "boost/algorithm/string.hpp" -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" -#include "Analysis/Tools/interface/BTagCalibrationStandalone.h" - -#include "Analysis/Tools/bin/macro_config.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - if ( macro_config(argc, argv) != 0 ) return -1; - std::transform(btagalgo_.begin(), btagalgo_.end(), btagalgo_.begin(), ::tolower); - - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - Analysis analysis(inputlist_); - - // b-tag scale factors - BTagCalibration calib(btagalgo_, btagsf_ ); - BTagCalibrationReader reader(BTagEntry::OP_TIGHT, // operating point - "central", // central sys type - {"up", "down"}); // other sys types - reader.load(calib, // calibration instance - BTagEntry::FLAV_B, // btag flavour - B - "comb"); // measurement type - reader.load(calib, // calibration instance - BTagEntry::FLAV_C, // btag flavour - C - "comb"); // measurement type - reader.load(calib, // calibration instance - BTagEntry::FLAV_UDSG, // btag flavour - UDSG - "incl"); // measurement type - - // Physics Objects Collections - analysis.addTree ("Jets",jetsCol_); - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - for ( int i = 0 ; i < analysis.size() ; ++i ) - { - analysis.event(i); - - std::cout << "++++++ ENTRY " << i; - std::cout << std::endl; - - // Jets - auto jets = analysis.collection("Jets"); - int nbjets = 0; - for ( int j = 0 ; j < jets->size() ; ++j ) - { - Jet jet = jets->at(j); - if ( btagalgo_ != "deepcsv" ) continue; - if ( (jet.btag("btag_deepb") + jet.btag("btag_deepbb")) < jetsbtagmin_[0] ) continue; // probing btag DeepCSV jets - - ++nbjets; - - // b-tag scale factors - double jet_bscalefactor; - if ( jet.flavour("Hadron") == 5 ) jet_bscalefactor = reader.eval_auto_bounds("central", BTagEntry::FLAV_B, fabs(jet.eta()), jet.pt() ); - if ( jet.flavour("Hadron") == 4 ) jet_bscalefactor = reader.eval_auto_bounds("central", BTagEntry::FLAV_C, fabs(jet.eta()), jet.pt() ); - if ( jet.flavour("Hadron") == 0 ) jet_bscalefactor = reader.eval_auto_bounds("central", BTagEntry::FLAV_UDSG, fabs(jet.eta()), jet.pt() ); - - std::cout << " Jet #" << j << ": "; - std::cout << "pT = " << jet.pt() << ", "; - std::cout << "eta = " << jet.eta() << ", "; - std::cout << "flavour = " << jet.flavour() << ", "; - std::cout << "btag = " << jet.btag("btag_deepb") + jet.btag("btag_deepbb"); - std::cout << " with scale factor = " << jet_bscalefactor << std::endl; - } - - std::cout << "===================" << std::endl; - - if ( nbjets < nbjetsmin_ ) continue; - - } - - -// -} - diff --git a/bin/AnalysisBJetsv2.cc b/bin/AnalysisBJetsv2.cc deleted file mode 100644 index 31f11fdc..00000000 --- a/bin/AnalysisBJetsv2.cc +++ /dev/null @@ -1,97 +0,0 @@ -#include "boost/program_options.hpp" -#include "boost/algorithm/string.hpp" -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" -#include "Analysis/Tools/bin/macro_config.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -float btagMin(const std::string & btagwp); - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - if ( macro_config(argc, argv) != 0 ) return -1; - - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - Analysis analysis(inputlist_); - - // btag - float btagmin = btagMin(btagwp_); - - // b-tag scale factors - // inputs from the config file test/analysis_bjetsv2.cfg - // btagalgo_ = "deepcsv"; - // btagsf_ = "../data/DeepCSV_94XSF_V3_B_F.csv"; - // btagwp_ = "tight"; - auto bsf_reader = analysis.btagCalibration(btagalgo_, btagsf_, btagwp_); - - // Physics Objects Collections - analysis.addTree ("Jets",jetsCol_); - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - for ( int i = 0 ; i < analysis.size() ; ++i ) - { - analysis.event(i); - - std::cout << "++++++ ENTRY " << i; - std::cout << std::endl; - - // Jets - auto jets = analysis.collection("Jets"); - int nbjets = 0; - for ( int j = 0 ; j < jets->size() ; ++j ) - { - Jet jet = jets->at(j); - if ( btagalgo_ != "deepcsv" ) continue; - if ( (jet.btag("btag_deepb") + jet.btag("btag_deepbb")) < btagmin ) continue; // probing btag DeepCSV jets - - ++nbjets; - - // b-tag scale factors central, up and down - double jet_bscalefactor = jet.btagSF(bsf_reader); // OR jet.btagSF(analysis.btagCalibration()); - double jet_bscalefactorup = jet.btagSFup(bsf_reader,2); - double jet_bscalefactordown = jet.btagSFdown(bsf_reader,2); - - std::cout << " Jet #" << j << ": "; - std::cout << "pT = " << jet.pt() << ", "; - std::cout << "eta = " << jet.eta() << ", "; - std::cout << "flavour = " << jet.flavour() << ", "; - std::cout << "btag = " << jet.btag("btag_deepb") + jet.btag("btag_deepbb") << " with scale factor = " << jet_bscalefactor; - std::cout << " up = " << jet_bscalefactorup << " down = " << jet_bscalefactordown << std::endl; - } - - std::cout << "===================" << std::endl; - - if ( nbjets < nbjetsmin_ ) continue; - - } - - std::cout << "Btag WP = " << btagwp_ << std::endl; -// -} - -float btagMin(const string & wp) -{ - float min = -1000; - if ( wp == "loose" ) min = btagwploose_; - if ( wp == "medium" ) min = btagwpmedium_; - if ( wp == "tight" ) min = btagwptight_; - - return min; - -} diff --git a/bin/AnalysisDeepFlavourBjets.cc b/bin/AnalysisDeepFlavourBjets.cc deleted file mode 100644 index b35b7f2b..00000000 --- a/bin/AnalysisDeepFlavourBjets.cc +++ /dev/null @@ -1,97 +0,0 @@ -#include "boost/program_options.hpp" -#include "boost/algorithm/string.hpp" -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" -#include "Analysis/Tools/bin/macro_config.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -float btagMin(const std::string & btagwp); - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - if ( macro_config(argc, argv) != 0 ) return -1; - - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - Analysis analysis(inputlist_); - - // btag - float btagmin = btagMin(btagwp_); - - // b-tag scale factors - // inputs from the config file test/analysis_bjetsv2.cfg - // btagalgo_ = "deepcsv"; - // btagsf_ = "../data/DeepCSV_94XSF_V3_B_F.csv"; - // btagwp_ = "tight"; - auto bsf_reader = analysis.btagCalibration(btagalgo_, btagsf_, btagwp_); - - // Physics Objects Collections - analysis.addTree ("Jets",jetsCol_); - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - for ( int i = 0 ; i < analysis.size() ; ++i ) - { - analysis.event(i); - - std::cout << "++++++ ENTRY " << i; - std::cout << std::endl; - - // Jets - auto jets = analysis.collection("Jets"); - int nbjets = 0; - for ( int j = 0 ; j < jets->size() ; ++j ) - { - Jet jet = jets->at(j); - if ( btagalgo_ != "deepflavour" ) continue; - if ( (jet.btag("btag_dfb") + jet.btag("btag_dfbb") + jet.btag("btag_dflepb")) < btagmin ) continue; // probing btag DeepCSV jets - - ++nbjets; - - // b-tag scale factors central, up and down - double jet_bscalefactor = jet.btagSF(bsf_reader); // OR jet.btagSF(analysis.btagCalibration()); - double jet_bscalefactorup = jet.btagSFup(bsf_reader,2); - double jet_bscalefactordown = jet.btagSFdown(bsf_reader,2); - - std::cout << " Jet #" << j << ": "; - std::cout << "pT = " << jet.pt() << ", "; - std::cout << "eta = " << jet.eta() << ", "; - std::cout << "flavour = " << jet.flavour() << ", "; - std::cout << "btag = " << jet.btag("btag_dfb") + jet.btag("btag_dfbb") + jet.btag("btag_dflepb") << " with scale factor = " << jet_bscalefactor; - std::cout << " up = " << jet_bscalefactorup << " down = " << jet_bscalefactordown << std::endl; - } - - std::cout << "===================" << std::endl; - - if ( nbjets < nbjetsmin_ ) continue; - - } - - std::cout << "Btag WP = " << btagwp_ << std::endl; -// -} - -float btagMin(const string & wp) -{ - float min = -1000; - if ( wp == "loose" ) min = btagwploose_; - if ( wp == "medium" ) min = btagwpmedium_; - if ( wp == "tight" ) min = btagwptight_; - - return min; - -} diff --git a/bin/AnalysisEventInfo.cc b/bin/AnalysisEventInfo.cc deleted file mode 100644 index 3410a440..00000000 --- a/bin/AnalysisEventInfo.cc +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - std::string inputList = "rootFileList.txt"; - Analysis analysis(inputList); - - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - std::cout << "Printing information from first 5 entries... \n\n"; - - for ( int i = 0 ; i < analysis.size() ; ++i ) - { - analysis.event(i); - - if ( i < 5 ) - { - std::cout << "++++++ ENTRY " << i; - std::cout << ", Run = " << analysis.run(); - std::cout << ", Event = " << analysis.event(); - std::cout << ", LumiSection = " << analysis.lumiSection(); - std::cout << ", nPileup = " << analysis.nPileup(); - std::cout << ", nTruePileup = " << analysis.nTruePileup(); - std::cout << std::endl; - std::cout << " "; - std::cout << " Gen Weight = " << analysis.genWeight(); - std::cout << ", Gen Scale = " << analysis.genScale(); - std::cout << ", PDF id 1 = " << analysis.pdf().id.first; - std::cout << ", PDF id 2 = " << analysis.pdf().id.second; - std::cout << ", PDF x 1 = " << analysis.pdf().x.first; - std::cout << ", PDF x 2 = " << analysis.pdf().x.second; - std::cout << "\n" << std::endl; - - } - - } - -// -} - diff --git a/bin/AnalysisGenParticle.cc b/bin/AnalysisGenParticle.cc deleted file mode 100644 index 490028c9..00000000 --- a/bin/AnalysisGenParticle.cc +++ /dev/null @@ -1,70 +0,0 @@ -#include "boost/program_options.hpp" -#include "boost/algorithm/string.hpp" -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" -#include "Analysis/Tools/bin/macro_config.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - if ( macro_config(argc, argv) != 0 ) return -1; - - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - Analysis analysis(inputlist_); - - // btag - // Physics Objects Collections - analysis.addTree ("GenParticles",genParticleCol_); - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - - int nevts = analysis.size(); - if ( nevtmax_ > 0 ) nevts = nevtmax_; - - for ( int i = 0 ; i < nevts ; ++i ) - { - analysis.event(i); - - std::cout << "++++++ ENTRY " << i; - std::cout << std::endl; - - // Jets - auto genps = analysis.collection("GenParticles"); - - printf("| %10s | %10s | %10s | %10s | %10s | %10s | %10s |\n","index","pdg","status","mo1","mo2","da1","da2"); - for ( int j = 0 ; j < genps->size() ; ++j ) - { - GenParticle genp = genps -> at(j); - - int indx = genp.index(); - int mo1 = genp.mother(1); - int mo2 = genp.mother(2); - int da1 = genp.daughter(1); - int da2 = genp.daughter(2); - int status = genp.status(); - int pdg = genp.pdgId(); - printf("| %10d | %10d | %10d | %10d | %10d | %10d | %10d |\n",indx,pdg,status,mo1,mo2,da1,da2); - } - - std::cout << "===================" << std::endl; - - } - -// -} diff --git a/bin/AnalysisGenerator.cc b/bin/AnalysisGenerator.cc deleted file mode 100644 index da1c3fd2..00000000 --- a/bin/AnalysisGenerator.cc +++ /dev/null @@ -1,255 +0,0 @@ -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - -void createHistograms(); -void writeHistograms(); - -bool genPartPTordering(GenParticle p1, GenParticle p2) {return (p1.pt()>p2.pt());} -bool genJetPTordering(GenJet p1, GenJet p2) {return (p1.pt()>p2.pt());} - -bool isSignal_; -std::map h1_; - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - isSignal_ = true; - - createHistograms(); - - // Input files list - std::string inputList = "rootFileList.txt"; - Analysis analysis(inputList); - - // Physics Objects Collections - analysis.addTree ("GenParticles","MssmHbb/Events/prunedGenParticles"); - analysis.addTree ("GenJets","MssmHbb/Events/slimmedGenJets"); - analysis.addTree ("Jets","MssmHbb/Events/slimmedJetsReapplyJEC"); - - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - int nevents = analysis.size(); - if ( nevents > 20000 ) nevents = 20000; - for ( int i = 0 ; i < nevents ; ++i ) - { - - if ( i > 0 && i%10000 == 0 ) std::cout << i << " events processed..." << std::endl; - - analysis.event(i); - - // Generated Particles - // The higgs (pdgId == 36) is also in such collection. - // If higgs status=22, then hard-process intermediate (mass preserved) - // If higgs status=62, then particle with primordial kT included - // The higgs daughters have initially status = 23, but they will undergo several steps - // until status=71, i.e. before hadronisation, which would be the best to use. - // Thereofre, one can then try to follow the cascade down to the last b quarks - // using delta_R matching. Maybe maybe some delta_pt/pt... but that's not done here. - - - auto genParticles = analysis.collection("GenParticles"); - GenParticle bquark; - GenParticle bbarquark; - std::vector muons; - - for ( int j = 0 ; j < genParticles->size() ; ++j ) - { - GenParticle gp = genParticles->at(j); - if ( abs(gp.pdgId()) == 13 && gp.status() == 1 ) - { - muons.push_back(gp); - } - - if ( isSignal_ ) - { - if ( gp.pdgId() == 36 && gp.status() > 60 ) - { - h1_["h_hig_pt"] -> Fill(gp.pt() ); - h1_["h_hig_eta"] -> Fill(gp.eta()); - h1_["h_hig_phi"] -> Fill(gp.phi()); - } - if ( fabs(gp.pdgId()) == 5 && gp.higgsDaughter() ) - { - if ( gp.pdgId() > 0 ) bquark = gp; - if ( gp.pdgId() < 0 ) bbarquark = gp; - } - } - } - - if ( isSignal_ ) - { - - h1_["h_hig_d1_pt"] -> Fill(bquark.pt() ); - h1_["h_hig_d1_eta"] -> Fill(bquark.eta()); - h1_["h_hig_d1_phi"] -> Fill(bquark.phi()); - - h1_["h_hig_d2_pt"] -> Fill(bbarquark.pt() ); - h1_["h_hig_d2_eta"] -> Fill(bbarquark.eta()); - h1_["h_hig_d2_phi"] -> Fill(bbarquark.phi()); - - h1_["h_hig_dEta12"] -> Fill(fabs(bquark.eta()-bbarquark.eta())); - h1_["h_hig_dR12"] -> Fill(bquark.p4().DeltaR(bbarquark.p4())); - - } - - - // muons - std::sort(muons.begin(),muons.end(),genPartPTordering); - - if ( muons.size() > 0 ) - { - h1_["h_muon1_pt"] -> Fill(muons[0].pt() ); - h1_["h_muon1_eta"] -> Fill(muons[0].eta()); - h1_["h_muon1_phi"] -> Fill(muons[0].phi()); - } - - - -// ==================================================================== - - // Generated jets - // Let's match with the Higgs daughters - auto genJets = analysis.collection("GenJets"); - if ( genJets->size() > 1 ) - { - GenJet j1 = genJets->at(0); - GenJet j2 = genJets->at(1); - - TLorentzVector j12 = j1.p4() + j2.p4(); - double m12 = j12.M(); - - h1_["h_jettrue_eta1"] -> Fill(j1.eta()); - h1_["h_jettrue_eta2"] -> Fill(j2.eta()); - h1_["h_jettrue_pt1"] -> Fill(j1.pt()); - h1_["h_jettrue_pt2"] -> Fill(j2.pt()); - h1_["h_jettrue_m12"] -> Fill(m12); - h1_["h_jettrue_dEta12"]-> Fill(fabs(j1.eta()-j2.eta())); - - } - - -// -// ==================================================================== - - -// nb = 0; -// nbbar = 0; -// // reconstructed jets -// // will now try to match the gen jets that are daughter of the higgs to the reconstructed jets -// auto jets = analysis.collection("Jets"); -// Jet bjet; -// Jet bbarjet; -// for ( int j = 0 ; j < jets->size() ; ++j ) -// { -// Jet jet = jets->at(j); -// if ( bgenjet.deltaR(jet) < 0.3 && nb == 0 ) -// { -// bjet = jet ; -// ++nb; -// } -// if ( bbargenjet.deltaR(jet) < 0.3 && nbbar == 0 ) -// { -// bbarjet = jet ; -// ++nbbar; -// } -// if ( nb > 0 && nbbar > 0 ) break; -// -// } -// std::cout << " I am a reco jet matched to a higgs daughter b quark! " << " : "; -// std::cout << "pT = " << bjet.pt() << ", "; -// std::cout << "eta = " << bjet.eta() << ", "; -// std::cout << "phi = " << bjet.phi() << ", " << std::endl; -// -// std::cout << " I am a reco jet matched to a higgs daughter bbar quark! " << " : "; -// std::cout << "pT = " << bbarjet.pt() << ", "; -// std::cout << "eta = " << bbarjet.eta() << ", "; -// std::cout << "phi = " << bbarjet.phi() << ", " << std::endl; - - -// std::cout << "=====" << std::endl; - - - } - - writeHistograms(); - -// -} - -void createHistograms() -{ - // Higgs - if ( isSignal_ ) - { - h1_["h_hig_pt"] = new TH1F("h_hig_pt","",100,0,200); - h1_["h_hig_eta"] = new TH1F("h_hig_eta","",100,-10,10); - h1_["h_hig_phi"] = new TH1F("h_hig_phi","",100,-3.15,3.15); - - h1_["h_hig_d1_pt"] = new TH1F("h_hig_d1_pt","",100,0,200); - h1_["h_hig_d1_eta"] = new TH1F("h_hig_d1_eta","",100,-10,10); - h1_["h_hig_d1_phi"] = new TH1F("h_hig_d1_phi","",100,-3.15,3.15); - - h1_["h_hig_d2_pt"] = new TH1F("h_hig_d2_pt","",100,0,200); - h1_["h_hig_d2_eta"] = new TH1F("h_hig_d2_eta","",100,-10,10); - h1_["h_hig_d2_phi"] = new TH1F("h_hig_d2_phi","",100,-3.15,3.15); - - h1_["h_hig_dEta12"] = new TH1F("h_hig_dEta12","",100,0,10); - h1_["h_hig_dR12"] = new TH1F("h_hig_dR12","",100,0,5); - - - } - - // Generated muon - h1_["h_muon1_pt"] = new TH1F("h_muon1_pt","",100,0,200); - h1_["h_muon1_eta"] = new TH1F("h_muon1_eta","",100,-10,10); - h1_["h_muon1_phi"] = new TH1F("h_muon1_phi","",100,-3.15,3.15); - - // gen jets - h1_["h_jettrue_pt1"] = new TH1F("h_jettrue_pt1","",200,0,200); - h1_["h_jettrue_pt2"] = new TH1F("h_jettrue_pt2","",200,0,200); - - h1_["h_jettrue_eta1"] = new TH1F("h_jettrue_eta1","",100,-10,10); - h1_["h_jettrue_eta2"] = new TH1F("h_jettrue_eta2","",100,-10,10); - h1_["h_jettrue_m12"] = new TH1F("h_jettrue_m12","",200,0,2000); - h1_["h_jettrue_dEta12"] = new TH1F("h_jettrue_dEta12","",100,0,10); -} - -void writeHistograms() -{ - TFile * f_out = new TFile("analysis_generator.root","recreate"); - - if ( isSignal_ ) - { - f_out -> mkdir("higgs","higgs true info"); - } - f_out -> mkdir("muons","muons true info"); - - for (auto & ih1 : h1_) - { - f_out -> cd(); - if ( isSignal_ && TString(ih1.first).BeginsWith("h_hig") ) f_out -> cd("higgs"); - if ( TString(ih1.first).BeginsWith("h_muon") ) f_out -> cd("muons"); - - ih1.second -> Write(); - } - - f_out -> Close(); -} - - - diff --git a/bin/AnalysisJets.cc b/bin/AnalysisJets.cc deleted file mode 100644 index dcc88a7e..00000000 --- a/bin/AnalysisJets.cc +++ /dev/null @@ -1,64 +0,0 @@ -#include "boost/program_options.hpp" -#include "boost/algorithm/string.hpp" -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" -#include "Analysis/Tools/bin/macro_config.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - if ( macro_config(argc, argv) != 0 ) return -1; - - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - Analysis analysis(inputlist_); - - // Physics Objects Collections - analysis.addTree ("Jets",jetsCol_); - - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - for ( int i = 0 ; i < analysis.size() ; ++i ) - { - analysis.event(i); - - std::cout << "++++++ ENTRY " << i; - std::cout << std::endl; - - // Jets - auto jets = analysis.collection("Jets"); - for ( int j = 0 ; j < jets->size() ; ++j ) - { - Jet jet = jets->at(j); - std::cout << " Jet #" << j << ": "; - std::cout << "pT = " << jet.pt() << ", "; - std::cout << "eta = " << jet.eta() << ", "; - std::cout << "phi = " << jet.phi() << ", "; - std::cout << "flavour = " << jet.flavour() << ", "; - std::cout << "btag = " << jet.btag("btag_csvivf") << std::endl; - std::cout << " quark-gluon likelihood = " << jet.qgLikelihood() << std::endl; - std::cout << " pileup jet id full discriminant = " << jet.pileupJetIdFullDiscriminant() << std::endl; - std::cout << " pileup jet id full id = " << jet.pileupJetIdFullId() << std::endl; - - } - std::cout << "===================" << std::endl; - } - -// -} - diff --git a/bin/AnalysisJetsExample.cc b/bin/AnalysisJetsExample.cc new file mode 100644 index 00000000..9a92794d --- /dev/null +++ b/bin/AnalysisJetsExample.cc @@ -0,0 +1,177 @@ +#include "boost/program_options.hpp" +#include "boost/algorithm/string.hpp" +#include +#include +#include + +#include "TFile.h" +#include "TFileCollection.h" +#include "TChain.h" +#include "TH1.h" + +#include "Analysis/Tools/interface/Analysis.h" +#include "Analysis/Tools/bin/macro_config.h" + +using namespace std; +using namespace analysis; +using namespace analysis::tools; + +float btagMin(const std::string & btagwp); + +// ============================================================================================= +int main(int argc, char * argv[]) +{ + if ( macro_config(argc, argv) != 0 ) return -1; + + TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms + + // Input files list + Analysis analysis(inputlist_); + + // btag + float btagmin = btagMin(btagwp_); + // b-tag scale factors + // inputs from the config file test/analysis_bjetsv2.cfg + // btagalgo_ = "deepcsv"; + // btagsf_ = "../data/DeepCSV_94XSF_V3_B_F.csv"; + // btagwp_ = "tight"; + auto bsf_reader = analysis.btagCalibration(btagalgo_, btagsf_, btagwp_); + + // jer + // Jet energy resolution scale factors and pt resolution + auto jerinfo = analysis.jetResolutionInfo(jerpt_,jersf_); + + // Physics Objects Collections + analysis.addTree ("Jets",jetsCol_); + analysis.addTree ("GenParticles",genParticleCol_); + analysis.addTree ("GenJets",genjetsCol_); + + // Analysis of events + std::cout << "This analysis has " << analysis.size() << " events" << std::endl; + int nevts = analysis.size(); + if ( nevts > 0 ) nevts = nevtmax_; + for ( int i = 0 ; i < nevts ; ++i ) + { + analysis.event(i); + + std::cout << "++++++ ENTRY " << i; + + // EventInfo + std::cout << ", Run = " << analysis.run(); + std::cout << ", Event = " << analysis.event(); + std::cout << ", LumiSection = " << analysis.lumiSection(); + std::cout << "\n" << std::endl; + + // GenParticles + auto particles = analysis.collection("GenParticles"); // of course one can also loop over the particles + // GenJets + auto genjets = analysis.collection("GenJets"); // of course one can also loop over the genjets + // Jets + auto jets = analysis.collection("Jets"); + + // associate partons to jets + jets->associatePartons(particles,0.4,1); + // associate genjets to jets + jets->addGenJets(genjets); // if not defined -> jerMatch = false, smearing will be done using the stochastic method only + + for ( int j = 0 ; j < jets->size() ; ++j ) + { + Jet jet = jets->at(j); + + // BTAGGING + float btag = -10000.; + if ( btagalgo_ == "deepcsv" ) + btag = jet.btag("btag_deepb") + jet.btag("btag_deepbb"); + if ( btagalgo_ == "deepflavour" ) + btag = jet.btag("btag_dfb") + jet.btag("btag_dfbb") + jet.btag("btag_dflepb"); + + // b-tag scale factors central, up and down + double jet_bscalefactor = jet.btagSF(bsf_reader); // OR jet.btagSF(analysis.btagCalibration()); + double jet_bscalefactorup = jet.btagSFup(bsf_reader,2); + double jet_bscalefactordown = jet.btagSFdown(bsf_reader,2); + + // JER + jet.jerInfo(*jerinfo,0.2); // this also performs matching to the added gen jets above, with delta R < 0.2 which is default and can be omitted + + + // PRINTOUT + + std::cout << "Jet #" << j << ": "; + std::cout << "pT = " << jet.pt() << ", "; + std::cout << "eta = " << jet.eta() << ", "; + std::cout << "phi = " << jet.phi() << ", "; + std::cout << "flavour = " << jet.flavour() << " (extended = " << jet.extendedFlavour() << "), "; + std::cout << "btag = " << btag << " with scale factor = " << jet_bscalefactor; + std::cout << " up = " << jet_bscalefactorup << " down = " << jet_bscalefactordown << std::endl; + std::cout << " JER SF = " << jet.jerSF() << ", match = " << jet.jerMatch() << " jer corr = " << jet.jerCorrection() << " + "; + std::cout << jet.jerCorrection("up") << " - " << jet.jerCorrection("down") << std::endl; + std::cout << " quark-gluon likelihood = " << jet.qgLikelihood() << std::endl; + std::cout << " pileup jet id full discriminant = " << jet.pileupJetIdFullDiscriminant() << std::endl; + std::cout << " pileup jet id full id = " << jet.pileupJetIdFullId() << std::endl; + + } + std::cout << "===================" << std::endl; + } + std::cout << "Btag WP = " << btagwp_ << std::endl; + +// +} + +float btagMin(const string & wp) +{ + float min = -1000; + if ( wp == "loose" ) min = btagwploose_; + if ( wp == "medium" ) min = btagwpmedium_; + if ( wp == "tight" ) min = btagwptight_; + + return min; + +} + +// ==================================================================== +// // Below is a snippet of how to use the BTV standalone classes +// +// // before the event loop +// // b-tag scale factors +// BTagCalibration calib(btagalgo_, btagsf_ ); +// BTagCalibrationReader reader(BTagEntry::OP_TIGHT, // operating point - example for TIGHT +// "central", // central sys type +// {"up", "down"}); // other sys types +// reader.load(calib, // calibration instance +// BTagEntry::FLAV_B, // btag flavour - B +// "comb"); // measurement type +// reader.load(calib, // calibration instance +// BTagEntry::FLAV_C, // btag flavour - C +// "comb"); // measurement type +// reader.load(calib, // calibration instance +// BTagEntry::FLAV_UDSG, // btag flavour - UDSG +// "incl"); // measurement type +// +// // inside the jet loop +// +// // b-tag scale factors +// double jet_bscalefactor; +// if ( jet.flavour("Hadron") == 5 ) jet_bscalefactor = reader.eval_auto_bounds("central", BTagEntry::FLAV_B, fabs(jet.eta()), jet.pt() ); +// if ( jet.flavour("Hadron") == 4 ) jet_bscalefactor = reader.eval_auto_bounds("central", BTagEntry::FLAV_C, fabs(jet.eta()), jet.pt() ); +// if ( jet.flavour("Hadron") == 0 ) jet_bscalefactor = reader.eval_auto_bounds("central", BTagEntry::FLAV_UDSG, fabs(jet.eta()), jet.pt() ); +// + +// ==================================================================== + + +// // Below is a snippet of how to use the JME standalone classes +// +// // before the event loop +// // Jet energy resolution scale factors and pt resolution +// JME::JetResolution resolution = JME::JetResolution(jerpt_); +// JME::JetResolutionScaleFactor resolution_sf = JME::JetResolutionScaleFactor(jersf_); +// +// // inside the event loop +// analysis.match("Jets","GenJets",0.2); +// // inside the jet loop +// JME::JetParameters jetResPars = {{JME::Binning::JetPt, jet.pt()}, {JME::Binning::JetEta, jet.eta()}, {JME::Binning::Rho, jet.rho()}}; +// JME::JetParameters jetResSFPars = {{JME::Binning::JetEta, jet.eta()}, {JME::Binning::Rho, jet.rho()}};; +// +// std::cout << "resolution = " << resolution.getResolution(jetResPars) << ", "; +// std::cout << "JER SF = " << resolution_sf.getScaleFactor(jetResSFPars) << ", " << genjet << std::endl; +// diff --git a/bin/AnalysisJetsFlavour.cc b/bin/AnalysisJetsFlavour.cc deleted file mode 100644 index a084595c..00000000 --- a/bin/AnalysisJetsFlavour.cc +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - std::string inputList = "rootFileList.txt"; - Analysis analysis(inputList); - - // Physics Objects Collections - analysis.addTree ("Jets","MssmHbb/Events/selectedUpdatedPatJets"); - analysis.addTree ("GenParticles","MssmHbb/Events/prunedGenParticles"); - - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - for ( int i = 0 ; i < analysis.size() ; ++i ) - { -// std::cout << "++++++ ENTRY " << i; -// std::cout << std::endl; - - analysis.event(i); - - // GenParticles - auto particles = analysis.collection("GenParticles"); - - // Jets - auto jets = analysis.collection("Jets"); - jets->associatePartons(particles,0.4,1); - jets->btagAlgo("btag_csvmva"); - - for ( int j = 0 ; j < jets->size() ; ++j ) - { - Jet jet = jets->at(j); - if ( jet.pt() < 30 ) continue; -// std::cout << jet.btag("btag_csvivf") << " " << jet.btag("btag_csvivf") << " pt = " << jet.pt() << std::endl; -// if ( ( jet.extendedFlavour() == "cc" || jet.extendedFlavour() == "bb" ) && jets->size() > 4 ) - { -// std::cout << analysis.event() << " " << analysis.lumiSection() << std::endl; - std::cout << "Jet # " << j << " with flavour = " << jet.flavour() << " and extended flavour = " << jet.extendedFlavour() << " btag = " << jet.btag("btag_csvivf") << ", " << jet.btag("btag_csvmva") << std::endl; - } - } - - } - -// -} - diff --git a/bin/AnalysisJetsJER.cc b/bin/AnalysisJetsJER.cc deleted file mode 100644 index ad3a330f..00000000 --- a/bin/AnalysisJetsJER.cc +++ /dev/null @@ -1,81 +0,0 @@ -#include "boost/program_options.hpp" -#include "boost/algorithm/string.hpp" -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" -#include "Analysis/Tools/interface/JetResolution.h" - -#include "Analysis/Tools/bin/macro_config.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - if ( macro_config(argc, argv) != 0 ) return -1; - - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - Analysis analysis(inputlist_); - - // Physics Objects Collections - analysis.addTree ("Jets",jetsCol_); - analysis.addTree ("GenJets",genjetsCol_); - - // Jet energy resolution scale factors and pt resolution - JME::JetResolution resolution = JME::JetResolution(jerpt_); - JME::JetResolutionScaleFactor resolution_sf = JME::JetResolutionScaleFactor(jersf_); - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; -// for ( int i = 0 ; i < analysis.size() ; ++i ) - for ( int i = 0 ; i < 10 ; ++i ) - { - analysis.event(i); - - std::cout << "++++++ ENTRY " << i; - std::cout << std::endl; - - analysis.match("Jets","GenJets",0.2); - - // Jets - auto jets = analysis.collection("Jets"); - auto genjets = analysis.collection("GenJets"); - - for ( int j = 0 ; j < jets->size() ; ++j ) - { - Jet jet = jets->at(j); - auto * genjet = jet.matched("GenJets"); - - JME::JetParameters jetResPars = {{JME::Binning::JetPt, jet.pt()}, {JME::Binning::JetEta, jet.eta()}, {JME::Binning::Rho, jet.rho()}}; - JME::JetParameters jetResSFPars = {{JME::Binning::JetEta, jet.eta()}, {JME::Binning::Rho, jet.rho()}};; - - std::cout << " Jet #" << j << ": "; - std::cout << "pT = " << jet.pt() << ", "; - std::cout << "eta = " << jet.eta() << ", "; - std::cout << "resolution = " << resolution.getResolution(jetResPars) << ", "; - std::cout << "JER SF = " << resolution_sf.getScaleFactor(jetResSFPars) << ", " << genjet << std::endl; - - - - } - - std::cout << "===================" << std::endl; - - } - - -// -} - diff --git a/bin/AnalysisJetsJERv2.cc b/bin/AnalysisJetsJERv2.cc deleted file mode 100644 index f78afebb..00000000 --- a/bin/AnalysisJetsJERv2.cc +++ /dev/null @@ -1,78 +0,0 @@ -#include "boost/program_options.hpp" -#include "boost/algorithm/string.hpp" -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" - -#include "Analysis/Tools/bin/macro_config.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - if ( macro_config(argc, argv) != 0 ) return -1; - - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - Analysis analysis(inputlist_); - - // Physics Objects Collections - analysis.addTree ("Jets",jetsCol_); - analysis.addTree ("GenJets",genjetsCol_); - - // Jet energy resolution scale factors and pt resolution - auto jerinfo = analysis.jetResolutionInfo(jerpt_,jersf_); - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; -// for ( int i = 0 ; i < analysis.size() ; ++i ) - for ( int i = 0 ; i < 10 ; ++i ) - { - analysis.event(i); - - std::cout << "++++++ ENTRY " << i; - std::cout << std::endl; - - // Jets - auto jets = analysis.collection("Jets"); - auto genjets = analysis.collection("GenJets"); - - jets->addGenJets(genjets); // if not defined -> jerMatch = false, smearing will be done using the stochastic method only - - for ( int j = 0 ; j < jets->size() ; ++j ) - { - Jet jet = jets->at(j); - jet.jerInfo(*jerinfo,0.2); // this also performs matching to the added gen jets above, with delta R < 0.2 which is default and can be omitted - - - std::cout << " Jet #" << j << ": "; - std::cout << "pT = " << jet.pt() << ", "; - std::cout << "eta = " << jet.eta() << ", "; - std::cout << "resolution = " << jet.jerPtResolution() << ", "; - std::cout << "JER SF = " << jet.jerSF() << ", match = " << jet.jerMatch() << " jer corr = " << jet.jerCorrection() << " + "; - std::cout << jet.jerCorrection("up") << " - " << jet.jerCorrection("down") << std::endl; - - - - } - - std::cout << "===================" << std::endl; - - } - - -// -} - diff --git a/bin/AnalysisJetsSimple.cc b/bin/AnalysisJetsSimple.cc deleted file mode 100644 index 9972cf76..00000000 --- a/bin/AnalysisJetsSimple.cc +++ /dev/null @@ -1,139 +0,0 @@ -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - double ptmin = 20.; - - bool isMC = false; - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - std::string inputList = "rootFileList.txt"; - Analysis analysis(inputList); - - // Physics Objects Collections - analysis.addTree ("Jets","MssmHbb/Events/slimmedJetsReapplyJEC"); - // Trigger results - analysis.triggerResults("MssmHbb/Events/TriggerResults"); - std::string hltPath = "HLT_DoubleJetsC100_DoubleBTagCSV_p014_DoublePFJetsC100MaxDeta1p6_v"; - - // Trigger objects - std::vector triggerObjects; - triggerObjects.push_back("hltL1sDoubleJetC100"); - triggerObjects.push_back("hltDoubleJetsC100"); - triggerObjects.push_back("hltBTagCaloCSVp014DoubleWithMatching"); - triggerObjects.push_back("hltDoublePFJetsC100"); - triggerObjects.push_back("hltDoublePFJetsC100MaxDeta1p6"); - - std::string trgobj_path = "MssmHbb/Events/selectedPatTrigger/"; - for ( auto & obj : triggerObjects ) - analysis.addTree(obj,trgobj_path+obj); - - // Certified lumis - if ( ! isMC ) analysis.processJsonFile("json.txt"); - - - TFile hout("histograms_rereco_ptmin20.root","recreate"); - - std::map h1; - h1["n"] = new TH1F("n" , "" , 30, 0, 30); - h1["pt"] = new TH1F("pt" , "" , 500, 0, 100); - h1["eta"] = new TH1F("eta" , "" , 100, -5, 5); - h1["phi"] = new TH1F("phi" , "" , 100, -4, 4); - - h1["nHadFrac"] = new TH1F("nHadFrac" , "" , 100, 0, 1); - h1["nEmFrac"] = new TH1F("nEmFrac" , "" , 100, 0, 1); - h1["nMult"] = new TH1F("nMult" , "" , 40, 0, 40); - h1["cHadFrac"] = new TH1F("cHadFrac" , "" , 100, 0, 1); - h1["cEmFrac"] = new TH1F("cEmFrac" , "" , 100, 0, 1); - h1["cMult"] = new TH1F("cMult" , "" , 40, 0, 40); - h1["muFrac"] = new TH1F("muFrac" , "" , 100, 0, 1); - h1["nConst"] = new TH1F("nConst" , "" , 40, 0, 40); - - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - int nevents = analysis.size(); -// nevents = 10000; -// std::string prevFile = ""; - - int nFired = 0; - for ( int i = 0 ; i < nevents ; ++i ) - { - if ( i > 0 && i%100000 == 0 ) std::cout << i << " events processed..." << std::endl; - - analysis.event(i); - - if ( !isMC ) - { -// if ( analysis.run() == 275782) -// { -// if ( prevFile == "" || prevFile != analysis.fileName() ) -// { -// prevFile = analysis.fileName(); -// std::cout << prevFile << std::endl; -// } -// } - if ( !analysis.selectJson() ) continue; - } - - // Trigger results - // hltPath - int trgFired = analysis.triggerResult(hltPath); - if ( ! trgFired ) continue; - ++nFired; - -// std::cout << "++++++ ENTRY " << i; -// std::cout << std::endl; - - // Jets - auto jets = analysis.collection("Jets"); - int njets = 0; - for ( int j = 0 ; j < jets->size() ; ++j ) - { - Jet jet = jets->at(j); - if ( ! jet.idLoose() ) continue; - if ( jet.pt() < ptmin ) continue; - ++njets; - h1["pt"] -> Fill(jet.pt()); - h1["eta"] -> Fill(jet.eta()); - h1["phi"] -> Fill(jet.phi()); - h1["nHadFrac"] -> Fill(jet.neutralHadronFraction()); - h1["nEmFrac"] -> Fill(jet.neutralEmFraction() ); - h1["nMult"] -> Fill(jet.neutralMultiplicity() ); - h1["cHadFrac"] -> Fill(jet.chargedHadronFraction()); - h1["cEmFrac"] -> Fill(jet.chargedEmFraction() ); - h1["cMult"] -> Fill(jet.chargedMultiplicity() ); - h1["muFrac"] -> Fill(jet.muonFraction() ); - h1["nConst"] -> Fill(jet.constituents() ); - - } - h1["n"] -> Fill(njets); - - } - - for (auto & ih1 : h1) - { - ih1.second -> Write(); - } - - std::cout << "Number of triggered events = " << nFired << std::endl; - -// -} - diff --git a/bin/AnalysisJetsTags.cc b/bin/AnalysisJetsTags.cc deleted file mode 100644 index 5192987f..00000000 --- a/bin/AnalysisJetsTags.cc +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - std::string inputList = "rootFileList.txt"; - Analysis analysis(inputList,"MssmHbbTrigger/Events/EventInfo"); - - // Physics Objects Collections - analysis.addTree ("Jets","MssmHbbTrigger/Events/hltCombinedSecondaryVertexBJetTagsCalo"); - - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - for ( int i = 0 ; i < analysis.size() ; ++i ) - { - analysis.event(i); - - std::cout << "++++++ ENTRY " << i; - std::cout << std::endl; - - // Jets - auto jets = analysis.collection("Jets"); - for ( int j = 0 ; j < jets->size() ; ++j ) - { - JetTag jet = jets->at(j); - std::cout << " Jet #" << j << ": "; - std::cout << "pT = " << jet.pt() << ", "; - std::cout << "eta = " << jet.eta() << ", "; - std::cout << "phi = " << jet.phi() << ", "; - std::cout << "btag = " << jet.btag() << std::endl; - - } - - } - -// -} - diff --git a/bin/AnalysisMCTrue.cc b/bin/AnalysisMCTrue.cc deleted file mode 100644 index 4521a6b6..00000000 --- a/bin/AnalysisMCTrue.cc +++ /dev/null @@ -1,165 +0,0 @@ -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - std::string inputList = "rootFileList.txt"; - Analysis analysis(inputList); - - // Physics Objects Collections - analysis.addTree ("GenParticles","MssmHbb/Events/prunedGenParticles"); - analysis.addTree ("GenJets","MssmHbb/Events/slimmedGenJets"); - analysis.addTree ("Jets","MssmHbb/Events/slimmedJetsReapplyJEC"); - - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - int nevents = analysis.size(); - nevents = 5; - for ( int i = 0 ; i < nevents ; ++i ) - { - analysis.event(i); - - std::cout << "++++++ ENTRY " << i; - std::cout << std::endl; - - // Generated Particles - // The higgs (pdgId == 36) is also in such collection. - // If higgs status=22, then hard-process intermediate (mass preserved) - // If higgs status=62, then particle with primordial kT included - // The higgs daughters have initially status = 23, but they will undergo several steps - // until status=71, i.e. before hadronisation, which would be the best to use. - // Thereofre, one can then try to follow the cascade down to the last b quarks - // using delta_R matching. Maybe maybe some delta_pt/pt... but that's not done here. - auto genParticles = analysis.collection("GenParticles"); - GenParticle bquark; - GenParticle bbarquark; - for ( int j = 0 ; j < genParticles->size() ; ++j ) - { - GenParticle gp = genParticles->at(j); - if ( gp.pdgId() == 36 && gp.status() > 60 ) - { - std::cout << "I am the higgs! " << " : "; - std::cout << "pT = " << gp.pt() << ", "; - std::cout << "eta = " << gp.eta() << ", "; - std::cout << "phi = " << gp.phi() << ", "; - std::cout << "pdgId = " << gp.pdgId() << ", "; - std::cout << "status = " << gp.status() << std::endl; - } - if ( fabs(gp.pdgId()) == 5 && gp.higgsDaughter() ) - { - if ( gp.pdgId() > 0 ) bquark = gp; - if ( gp.pdgId() < 0 ) bbarquark = gp; - } - } - - std::cout << " I am a higgs b quark daughter! " << " : "; - std::cout << "pT = " << bquark.pt() << ", "; - std::cout << "eta = " << bquark.eta() << ", "; - std::cout << "phi = " << bquark.phi() << ", "; - std::cout << "pdgId = " << bquark.pdgId() << ", "; - std::cout << "status = " << bquark.status() << std::endl; - - std::cout << " I am a higgs bbar quark daughter! " << " : "; - std::cout << "pT = " << bbarquark.pt() << ", "; - std::cout << "eta = " << bbarquark.eta() << ", "; - std::cout << "phi = " << bbarquark.phi() << ", "; - std::cout << "pdgId = " << bbarquark.pdgId() << ", "; - std::cout << "status = " << bbarquark.status() << std::endl; - -// ==================================================================== - - // Generated jets - // Let's match with the Higgs daughters - auto genJets = analysis.collection("GenJets"); - GenJet bgenjet; - GenJet bbargenjet; - int nb = 0; - int nbbar = 0; - for ( int j = 0 ; j < genJets->size() ; ++j ) - { - GenJet gjet = genJets->at(j); - if ( gjet.deltaR(bquark) < 0.3 && nb == 0) - { - bgenjet = gjet ; - ++nb; - } - if ( gjet.deltaR(bbarquark) < 0.3 && nbbar == 0 ) - { - bbargenjet = gjet ; - std::cout << " I am a gen jet matched to a higgs daughter bbar! " << " : "; - std::cout << "pT = " << gjet.pt() << ", "; - std::cout << "eta = " << gjet.eta() << ", "; - std::cout << "phi = " << gjet.phi() << ", " << std::endl; - ++nbbar; - } - if ( nb > 0 && nbbar > 0 ) break; - } - - std::cout << " I am a gen jet matched to a higgs daughter b quark! " << " : "; - std::cout << "pT = " << bgenjet.pt() << ", "; - std::cout << "eta = " << bgenjet.eta() << ", "; - std::cout << "phi = " << bgenjet.phi() << ", " << std::endl; - - std::cout << " I am a gen jet matched to a higgs daughter bbar quark! " << " : "; - std::cout << "pT = " << bbargenjet.pt() << ", "; - std::cout << "eta = " << bbargenjet.eta() << ", "; - std::cout << "phi = " << bbargenjet.phi() << ", " << std::endl; - -// ==================================================================== - - - nb = 0; - nbbar = 0; - // reconstructed jets - // will now try to match the gen jets that are daughter of the higgs to the reconstructed jets - auto jets = analysis.collection("Jets"); - Jet bjet; - Jet bbarjet; - for ( int j = 0 ; j < jets->size() ; ++j ) - { - Jet jet = jets->at(j); - if ( bgenjet.deltaR(jet) < 0.3 && nb == 0 ) - { - bjet = jet ; - ++nb; - } - if ( bbargenjet.deltaR(jet) < 0.3 && nbbar == 0 ) - { - bbarjet = jet ; - ++nbbar; - } - if ( nb > 0 && nbbar > 0 ) break; - - } - std::cout << " I am a reco jet matched to a higgs daughter b quark! " << " : "; - std::cout << "pT = " << bjet.pt() << ", "; - std::cout << "eta = " << bjet.eta() << ", "; - std::cout << "phi = " << bjet.phi() << ", " << std::endl; - - std::cout << " I am a reco jet matched to a higgs daughter bbar quark! " << " : "; - std::cout << "pT = " << bbarjet.pt() << ", "; - std::cout << "eta = " << bbarjet.eta() << ", "; - std::cout << "phi = " << bbarjet.phi() << ", " << std::endl; - } - -// -} - diff --git a/bin/AnalysisMetadata.cc b/bin/AnalysisMetadataExample.cc similarity index 100% rename from bin/AnalysisMetadata.cc rename to bin/AnalysisMetadataExample.cc diff --git a/bin/AnalysisMuonJet.cc b/bin/AnalysisMuonJet.cc deleted file mode 100644 index 09e59fdf..00000000 --- a/bin/AnalysisMuonJet.cc +++ /dev/null @@ -1,71 +0,0 @@ -#include "boost/program_options.hpp" -#include "boost/algorithm/string.hpp" -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" -#include "Analysis/Tools/bin/macro_config.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - if ( macro_config(argc, argv) != 0 ) return -1; - - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - Analysis analysis(inputlist_); - - // Physics Objects Collections - analysis.addTree ("Jets" ,jetsCol_ ); - analysis.addTree ("Muons",muonsCol_); - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - for ( int i = 0 ; i < analysis.size() ; ++i ) - { - analysis.event(i); - - std::cout << "++++++ ENTRY " << i; - std::cout << std::endl; - - // Jets - auto jets = analysis.collection("Jets"); - auto muons = analysis.collection("Muons"); - - if ( muons->size() < 1 ) continue; - if ( jets ->size() < 1 ) continue; - - std::shared_ptr muon = std::make_shared(muons->at(0)); - - for ( int j = 0 ; j < jets->size() ; ++j ) - { - std::shared_ptr jet = std::make_shared(jets->at(j)); - float deltaR = jet->deltaR(*muon); - - if ( !jet->muon() && deltaR < 0.4 ) jet->addMuon(muon); - - if ( jet->muon() ) - { - std::cout << "jet eta,phi = " << jet->eta() << ", " << jet->phi() << " muon eta,phi = " << jet->muon()->eta() << ", " << jet->muon()->phi() << std::endl; - } - } - - std::cout << "===================" << std::endl; - - - } - -// -} diff --git a/bin/AnalysisMuons.cc b/bin/AnalysisMuonsExample.cc similarity index 67% rename from bin/AnalysisMuons.cc rename to bin/AnalysisMuonsExample.cc index 439333d7..567108ce 100644 --- a/bin/AnalysisMuons.cc +++ b/bin/AnalysisMuonsExample.cc @@ -26,26 +26,6 @@ int main(int argc, char * argv[]) // Physics Objects Collections analysis.addTree ("Muons","MssmHbb/Events/slimmedMuons"); - -// // Trigger results -// analysis.triggerResults("MssmHbb/Events/TriggerResults"); -// std::string hltPath = "HLT_DoubleJetsC100_DoubleBTagCSV_p014_DoublePFJetsC100MaxDeta1p6_v"; -// -// // Trigger objects -// std::vector triggerObjects; -// triggerObjects.push_back("hltL1sDoubleJetC100"); -// triggerObjects.push_back("hltDoubleJetsC100"); -// triggerObjects.push_back("hltBTagCaloCSVp014DoubleWithMatching"); -// triggerObjects.push_back("hltDoublePFJetsC100"); -// triggerObjects.push_back("hltDoublePFJetsC100MaxDeta1p6"); -// -// std::string trgobj_path = "MssmHbb/Events/selectedPatTrigger/"; -// for ( auto & obj : triggerObjects ) -// analysis.addTree(obj,trgobj_path+obj); -// -// // Certified lumis -// if ( ! isMC ) analysis.processJsonFile("json.txt"); - TFile hout("histograms_muons.root","recreate"); @@ -73,20 +53,6 @@ int main(int argc, char * argv[]) analysis.event(i); -// if ( !isMC ) -// { -// if ( !analysis.selectJson() ) continue; -// } - -// // Trigger results -// // hltPath -// int trgFired = analysis.triggerResult(hltPath); -// if ( ! trgFired ) continue; -// ++nFired; - -// std::cout << "++++++ ENTRY " << i; -// std::cout << std::endl; - // Muons auto muons = analysis.collection("Muons"); int nmuons = 0; diff --git a/bin/AnalysisRecoMuons.cc b/bin/AnalysisRecoMuonsExample.cc similarity index 100% rename from bin/AnalysisRecoMuons.cc rename to bin/AnalysisRecoMuonsExample.cc diff --git a/bin/AnalysisRecoTracks.cc b/bin/AnalysisRecoTracksExample.cc similarity index 100% rename from bin/AnalysisRecoTracks.cc rename to bin/AnalysisRecoTracksExample.cc diff --git a/bin/AnalysisTrigger.cc b/bin/AnalysisTrigger.cc deleted file mode 100644 index 6e2ddb1f..00000000 --- a/bin/AnalysisTrigger.cc +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - std::string inputList = "rootfile.txt"; - Analysis analysis(inputList); - - // Physics Objects Collections - analysis.triggerResults("MssmHbb/Events/TriggerResults"); - std::string hltPath = "HLT_Mu8_v"; - std::vector l1seeds; - l1seeds.push_back("L1_SingleMu3"); - l1seeds.push_back("L1_SingleMu5"); - l1seeds.push_back("L1_SingleMu7"); - -// // Trigger objects -// std::vector jetTriggerObjects; -// jetTriggerObjects.push_back("hltL1sDoubleJetC100"); -// jetTriggerObjects.push_back("hltDoubleJetsC100"); -// jetTriggerObjects.push_back("hltSingleBTagCSV0p84"); -// jetTriggerObjects.push_back("hltJetC350"); -// -// std::string trgobj_path = "MssmHbb/Events/selectedPatTrigger/"; -// for ( auto & obj : jetTriggerObjects ) -// analysis.addTree(obj,trgobj_path+obj); - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - int nevts = analysis.size(); - nevts = 1; - for ( int i = 0 ; i < nevts ; ++i ) - { - analysis.event(i); - - std::cout << "++++++ ENTRY " << i; - std::cout << std::endl; - - // Trigger results: fired and prescales - // hltPath1 - int trg_fired = analysis.triggerResult(hltPath); - std::map l1ps = analysis.triggerPrescale(l1seeds); - int hltps = analysis.triggerPrescale(hltPath); - std::string s_accept = " fired "; - if ( ! trg_fired ) s_accept = " did not fire "; - std::cout << "The path " << hltPath << s_accept << "and has HLT PS = " << hltps << std::endl; - std::cout << "and its L1 seeds have the following prescales: " << endl; - for ( auto & l1 : l1seeds ) - std::cout << " " << l1 << ": " << l1ps[l1] << std::endl; - - } - -// -} - diff --git a/bin/AnalysisTriggerExample.cc b/bin/AnalysisTriggerExample.cc new file mode 100644 index 00000000..d2c2bb92 --- /dev/null +++ b/bin/AnalysisTriggerExample.cc @@ -0,0 +1,76 @@ +#include +#include +#include + +#include "TFile.h" +#include "TFileCollection.h" +#include "TChain.h" +#include "TH1.h" + +#include "Analysis/Tools/interface/Analysis.h" +#include "Analysis/Tools/bin/macro_config.h" + +using namespace std; +using namespace analysis; +using namespace analysis::tools; + + +// ============================================================================================= +int main(int argc, char * argv[]) +{ + TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms + + if ( macro_config(argc, argv) != 0 ) return -1; + + // Input files list + Analysis analysis(inputlist_); + + // Trigger + analysis.triggerResults(triggerCol_); + + // Trigger objects + for ( auto & obj : triggerObjectsJets_ ) + analysis.addTree(obj,triggerObjDir_+"/"+obj); + + // Analysis of events + std::cout << "This analysis has " << analysis.size() << " events" << std::endl; + int nevts = analysis.size(); + if ( nevts > 0 ) nevts = nevtmax_; + for ( int i = 0 ; i < nevts ; ++i ) + { + analysis.event(i); + + std::cout << "++++++ ENTRY " << i << std::endl; + + // Trigger results: fired and prescales + // hltPath + int trg_fired = analysis.triggerResult(hltPath_); + // prescales + int l1ps = analysis.triggerPrescale(l1Seed_); + int hltps = analysis.triggerPrescale(hltPath_); + std::string s_accept = " fired "; + + // printing info + if ( ! trg_fired ) + { + std::cout << "The path " << hltPath_ << " did not fire " << std::endl; + continue; + } + + std::cout << "The path " << hltPath_ << " fired and has HLT PS = " << hltps << std::endl; + std::cout << "and its L1 seed " << l1Seed_ << " has the following prescale: " << l1ps << endl; + + // dealing with trigger objects + // *** WARNING! *** the order you enter the trigger object in the config file matter! + auto l1jets = analysis.collection(triggerObjectsJets_[0]); + for ( int j = 0 ; j < l1jets->size() ; ++j ) + { + TriggerObject l1jet = l1jets->at(j); + std::cout << "L1 Jet: pT = " << l1jet.pt() << ", " << l1jet.eta() << ", " << l1jet.phi() << std::endl; + } + + } + + +} + diff --git a/bin/AnalysisTriggerObjects.cc b/bin/AnalysisTriggerObjects.cc deleted file mode 100644 index d2f0e6e0..00000000 --- a/bin/AnalysisTriggerObjects.cc +++ /dev/null @@ -1,108 +0,0 @@ -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - std::string inputList = "rootFileList.txt"; - Analysis analysis(inputList,"MssmHbbTrigger/Events/EventInfo"); - - // Physics Objects Collections - analysis.triggerResults("MssmHbbTrigger/Events/TriggerResults"); - std::string hltPath[20]; - hltPath[0] = "HLT_L1SingleMu3_v1"; - hltPath[1] = "HLT_L1SingleJet20_v1"; - - // Trigger objects - std::vector jetTriggerObjects; - jetTriggerObjects.push_back("hltL1sSingleMu3"); - jetTriggerObjects.push_back("hltL1sSingleJet20"); - - std::string trgobj_path = "MssmHbbTrigger/Events/hltTriggerSummaryAOD/"; - for ( auto & obj : jetTriggerObjects ) - analysis.addTree(obj,trgobj_path+obj); - - // Get generator filter information - FilterResults genFilter = analysis.generatorFilter("MssmHbbTrigger/Metadata/GeneratorFilter"); - - // Get cross section - analysis.crossSections("MssmHbbTrigger/Metadata/CrossSections"); - - double crossSection = analysis.crossSection(); - - // Analysis of events - std::cout << "This analysis has " << analysis.size() << " events" << std::endl; - - int nSelected = 0; - int nTotal = genFilter.filtered; - float genFilterEfficiency = genFilter.efficiency; - for ( int i = 0 ; i < analysis.size() ; ++i ) - { - analysis.event(i); - - if ( analysis.nPileup() != 45 ) continue; - - // Trigger results: fired and prescales - // hltPath1 - int trg_fired = analysis.triggerResult(hltPath[0]) && analysis.triggerResult(hltPath[1]); - - if ( ! trg_fired ) continue; - - // muon selection at L1 - auto l1Mu3s = analysis.collection("hltL1sSingleMu3"); - - std::vector selL1Mu10s; - for ( int m = 0 ; m < l1Mu3s->size() ; ++m ) - { - TriggerObject l1Mu3 = l1Mu3s->at(m); - if ( l1Mu3.pt() >= 10 && fabs(l1Mu3.eta()) <= 2.2 ) - { - selL1Mu10s.push_back(l1Mu3); -// std::cout << l1Mu3.pt() << std::endl; - } - - } - if ( selL1Mu10s.size() < 1 ) continue; - - // jet selection at L1 - auto l1Jet20s = analysis.collection("hltL1sSingleJet20"); - std::vector selL1Jet30s; - for ( int j = 0 ; j < l1Jet20s->size() ; ++j ) - { - TriggerObject l1Jet20 = l1Jet20s->at(j); - if ( l1Jet20.pt() >= 30 && fabs(l1Jet20.eta()) <= 2.2 ) - { - selL1Jet30s.push_back(l1Jet20); - } - } - std::cout << selL1Jet30s.size() < - + - + - - - - - + @@ -28,15 +24,7 @@ - - - - - - - - - + @@ -44,23 +32,11 @@ - - - - - - - - - - - + @@ -68,23 +44,11 @@ - + - - - - - - - - - - - - - + @@ -92,23 +56,20 @@ - - + + - - + + - - + + - - - - + diff --git a/bin/NtupleDiagnostics.cc b/bin/NtupleDiagnostics.cc deleted file mode 100644 index d452e07a..00000000 --- a/bin/NtupleDiagnostics.cc +++ /dev/null @@ -1,35 +0,0 @@ -#include "boost/program_options.hpp" -#include "boost/algorithm/string.hpp" -#include -#include -#include -#include - -#include "TFile.h" -#include "TFileCollection.h" -#include "TChain.h" -#include "TH1.h" - -#include "Analysis/Tools/interface/Analysis.h" -#include "Analysis/Tools/bin/macro_config.h" - -using namespace std; -using namespace analysis; -using namespace analysis::tools; - -// ============================================================================================= -int main(int argc, char * argv[]) -{ - - if ( macro_config(argc, argv) != 0 ) return -1; - - TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms - - // Input files list - Analysis analysis(inputlist_); - - // Ntuples # events - std::cout << "These ntuples have " << analysis.size() << " events" << std::endl; - -} //end main - diff --git a/bin/PlotsCompare.cc b/bin/PlotsCompare.cc new file mode 100644 index 00000000..18fb1cee --- /dev/null +++ b/bin/PlotsCompare.cc @@ -0,0 +1,219 @@ +#include +#include +#include + +#include "TFile.h" +#include "TCanvas.h" +#include "TApplication.h" +#include "TH1.h" +#include "TRatioPlot.h" +#include "TLegend.h" +#include "Analysis/Tools/interface/plotscomp_config.h" +#include "Analysis/Tools/interface/tdrstyle.C" +#include "Analysis/Tools/interface/CMS_lumi.h" + +int W; +int H; +// for the margins +float T; +float B; +float L; +float R; + +TCanvas * c1; +TFile * f[10]; +TH1F * h[10]; +TRatioPlot * rp; +TLegend * legend; +std::string hn[10]; +std::string leg[10]; +std::string fn[10]; + +int plot_ratio(); +int draw_legend(); + +int main(int argc, char * argv[]) +{ + if ( plotscomp_config(argc, argv) != 0 ) return -1; + + W = 800; + H = 600; + // for the margins + T = 0.1*H; + B = 0.48*H; + L = 0.12*W; + R = 0.04*W; + + setTDRStyle(); + gStyle->SetOptStat(0); + TApplication theApp("App", 0, 0); + + hn[0] = hist1_; + hn[1] = hist2_; + + fn[0] = file1_; + fn[1] = file2_; + + leg[0] = legend1_; + leg[1] = legend2_; + + int color[10] = {kBlack,kRed}; + + TString out = TString(outplot_); + +// if ( outplot_ == "" ) outplot_ = "comparison_plot.png"; + + // read 2 histograms from the same file + if ( file_ != "" ) + { + f[0] = new TFile(file_.c_str(),"old"); + for ( int i = 0; i < 2 ; ++i ) + { + if ( hn[i] == "" ) return -1; + h[i] = (TH1F*) f[0] -> Get(hn[i].c_str()); + h[i] -> SetNameTitle(Form("%s_%d",hn[i].c_str(),i), Form("%s (%s)",leg[i].c_str(),h[i]->GetXaxis()->GetTitle())); + h[i] -> GetYaxis() -> SetTitle("entries"); + } + } + // read same histogram from 2 different files + else + { + if ( hist_ == "" ) return -1; + for ( int i = 0; i < 2 ; ++i ) + { + if ( fn[i] == "" ) return -1; + f[i] = new TFile(fn[i].c_str(),"old"); + h[i] = (TH1F*) f[i] -> Get(hist_.c_str()); + h[i] -> SetNameTitle(Form("%s_%d",hist_.c_str(),i), Form("%s (%s)",title_.c_str(),h[i]->GetXaxis()->GetTitle())); + } + } + if ( outplot_ == "" ) + { + out = TString(std::string(h[0]->GetName()) + "_versus_" + std::string(h[1]->GetName()) + ".png"); + out.ReplaceAll("/","_"); + } + + for ( int i = 0; i < 2 ; ++i ) + { + h[i] -> SetMarkerStyle(20); + h[i] -> SetMarkerSize(1.2); + h[i] -> SetMarkerColor(color[i]); + h[i] -> SetLineColor(color[i]); + h[i] -> SetLineWidth(2); + h[i] -> GetYaxis() -> SetTitle("entries"); + if ( max_ > min_ ) + { + h[i] -> GetXaxis()->SetRangeUser(min_,max_); + } + h[i] -> SetMinimum(0); + if ( logy_ ) h[i] -> SetMinimum(0.8); + } + h[1] -> Scale(scale_); + + // Ratio plot + plot_ratio(); + draw_legend(); + +// + if ( logx_ ) c1 -> SetLogx(); + if ( logy_ ) c1 -> SetLogy(); + + CMS_lumi(rp->GetUpperPad(),"private"); + + legend -> SetShadowColor(0); + +// if ( outplot_ == "" ) outplot_ = "comparison_plot.png"; + c1 -> SaveAs(out); + + if ( app_ ) theApp.Run(); // will not return + + delete rp; + delete c1; + delete f[0]; + delete f[1]; + + return 0; +} + +int plot_ratio() +{ + // Prepare a Canvas + c1 = new TCanvas("c1","test", W, H); + c1 -> SetFillColor(0); + c1 -> SetBorderMode(0); + c1 -> SetFrameFillStyle(0); + c1 -> SetFrameBorderMode(0); + c1 -> SetTickx(0); + c1 -> SetTicky(0); + + // The ratio plot + rp = new TRatioPlot(h[0], h[1]); + + rp -> SetH1DrawOpt("E"); + rp -> SetH2DrawOpt("E"); + rp -> SetGraphDrawOpt("P"); + rp -> SetSeparationMargin(0.03); + + rp -> SetLeftMargin( L/W ); + rp -> SetRightMargin( R/W ); + rp -> SetUpTopMargin( T/H ); + rp -> SetLowBottomMargin( B/H ); + + rp->Draw(); + + rp -> GetLowYaxis() -> SetNdivisions(503); + rp -> GetLowerRefGraph() -> GetXaxis() -> SetTitleOffset(1.1); + rp -> GetLowerRefGraph() -> GetYaxis() -> SetTitle("ratio"); + rp -> GetLowerRefYaxis() -> SetTitleOffset(1.2); + rp -> GetLowerRefYaxis() -> SetLabelSize(0.05); + rp -> GetLowerRefYaxis() -> SetTitleSize(0.05); + rp->GetLowerRefGraph()->SetMarkerStyle(20); + rp->GetLowerRefGraph()->SetMarkerColor(kGray+2); + rp->GetLowerRefGraph()->SetMarkerSize(1.2); + rp->GetLowerRefGraph()->SetLineWidth(2); + rp->GetLowerRefGraph()->SetLineColor(kGray+2); + rp->GetLowerRefGraph()->SetMinimum(0.); + rp->GetLowerRefGraph()->SetMaximum(2.4); + + rp -> GetUpperRefXaxis() -> SetLabelSize(0.05); + rp -> GetUpperRefXaxis() -> SetTitleSize(0.05); + + rp -> GetUpperRefYaxis() -> SetLabelSize(0.05); + rp -> GetUpperRefYaxis() -> SetTitleSize(0.05); + rp -> GetUpperRefYaxis() -> SetTitleOffset(1.2); + + if ( logx_ ) rp -> GetUpperPad() -> SetLogx(); + if ( logy_ ) rp -> GetUpperPad() -> SetLogy(); + + c1->Update(); + + return 0; +} + +int draw_legend() +{ + std::string var = h[0]->GetName(); + + if ( TString(var).Contains("m_jet") || TString(var).Contains("pt_jet") ) + legend = rp -> GetUpperPad() -> BuildLegend(0.65,0.65,0.90,0.85); + else if ( !TString(var).Contains("deta_jet") && ( TString(var).Contains("eta_jet") || TString(var).Contains("phi_jet") )) + legend = rp -> GetUpperPad() -> BuildLegend(0.40,0.05,0.65,0.25); +// legend = rp -> GetUpperPad() -> BuildLegend(0.65,0.65,0.90,0.85); + else if ( TString(var).Contains("btag_jet") ) + { + if ( logy_ ) + legend = rp -> GetUpperPad() -> BuildLegend(0.35,0.05,0.60,0.25); + else + legend = rp -> GetUpperPad() -> BuildLegend(0.35,0.65,0.60,0.85); + } + else + legend = rp -> GetUpperPad() -> BuildLegend(0.15,0.65,0.40,0.85); + legend -> Clear(); + + legend ->AddEntry(h[0], leg[0].c_str(), "P"); + legend ->AddEntry(h[1], leg[1].c_str(), "P"); + + c1->Update(); + + return 0; +} diff --git a/bin/ExampleToolsForNtuple.cc b/bin/ToolsForNtupleExample.cc similarity index 100% rename from bin/ExampleToolsForNtuple.cc rename to bin/ToolsForNtupleExample.cc diff --git a/bin/TruePileup.cc b/bin/TruePileup.cc new file mode 100644 index 00000000..7ab9c7bb --- /dev/null +++ b/bin/TruePileup.cc @@ -0,0 +1,34 @@ +#include "TRandom3.h" +#include "Analysis/Tools/interface/Analyser.h" + +// this produces histogram with the true pileup + +using namespace std; +using namespace analysis; +using namespace analysis::tools; + +int main(int argc, char ** argv) +{ + TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms + + Analyser analyser(argc,argv); + + analyser.pileupHistogram(); + + TRandom3 * rnd = new TRandom3(); + + float ps = 1./analyser.config()->prescale(); + + // events loop + for ( int i = 0 ; i < analyser.nEvents() ; ++i ) + { + // avoiding bias for some samples + auto x = rnd->Rndm(); + if ( x > ps ) continue; + analyser.event(i); + analyser.fillPileupHistogram(); + + } //end events loop + +} // end main + diff --git a/bin/Cutflow.cc b/bin/Workflow.cc similarity index 51% rename from bin/Cutflow.cc rename to bin/Workflow.cc index e4f8474c..ab5f36cb 100644 --- a/bin/Cutflow.cc +++ b/bin/Workflow.cc @@ -15,33 +15,37 @@ int main(int argc, char * argv[]) TFile f(rootfile,"old"); - TH1F * h = (TH1F*) f.Get("cutflow"); + TH1F * h = (TH1F*) f.Get("workflow"); - printf("+%s+\n", std::string(110,'-').c_str()); - printf("| %-48s | %10s | %16s | %16s |\n","cut","n events","ratio wrt first","ratio wrt previous"); - printf("+%s+\n", std::string(110,'-').c_str()); - int firstbin = -1; + printf("+%s+\n", std::string(150,'-').c_str()); + printf("| %-88s | %10s | %16s | %16s |\n",h->GetTitle(),"n events","ratio wrt first","ratio wrt previous"); + printf("+%s+\n", std::string(150,'-').c_str()); + int firstbin = 2; for ( int i = 1; i <= h ->GetNbinsX(); ++i ) { std::string label = std::string(h->GetXaxis()->GetBinLabel(i)); if ( label == "" ) continue; - if ( firstbin < 0 ) firstbin = i; +// if ( firstbin < 0 ) firstbin = i; float n = h->GetBinContent(i); float rn1 = h->GetBinContent(i)/h->GetBinContent(firstbin); float rni = 0; - if ( i == firstbin ) + if ( i == 1 ) { - printf("| %-48s | %10.0f | %16.4f | %19s |\n",label.c_str(),n,rn1,"-"); + printf("| %-88s | %10.1f | %16s | %19s |\n",label.c_str(),n,"-","-"); + } + else if ( i == 2 ) + { + printf("| %2d - %-83s | %10.1f | %16.6f | %19s |\n",i-1,label.c_str(),n,rn1,"-"); } else { rni = h-> GetBinContent(i)/h->GetBinContent(i-1); - printf("| %-48s | %10.0f | %16.4f | %16.4f |\n",label.c_str(),n,rn1,rni); + printf("| %2d - %-83s | %10.1f | %16.6f | %16.6f |\n",i-1,label.c_str(),n,rn1,rni); } } - printf("+%s+\n", std::string(110,'-').c_str()); + printf("+%s+\n", std::string(150,'-').c_str()); return 0; diff --git a/bin/analysis_jets.cfg b/bin/analysis_jets.cfg deleted file mode 100644 index 0ceb0f7e..00000000 --- a/bin/analysis_jets.cfg +++ /dev/null @@ -1,5 +0,0 @@ -nEventsMax = -1 -ntuplesList = testfile.txt -isMC = false -# Jets -jetsCollection = MssmHbb/Events/slimmedJets diff --git a/bin/example.cfg b/bin/example.cfg deleted file mode 100644 index e7c29b12..00000000 --- a/bin/example.cfg +++ /dev/null @@ -1,42 +0,0 @@ -nEventsMax = -1 -ntuplesList = rootFileList.txt -isMC = false -json = json.txt -output = histograms.root -# Trigger -hltPath = HLT_DoublePFJets100MaxDeta1p6_DoubleCaloBTagCSV_p33_v -triggerObjects = hltL1DoubleJet100er2p3dEtaMax1p6 -triggerObjects = hltDoubleCaloBJets100eta2p3 -triggerObjects = hltBTagCalo80x6CSVp0p92DoubleWithMatching -triggerObjects = hltDoublePFJets100Eta2p3 -triggerObjects = hltDoublePFJets100Eta2p3MaxDeta1p6 -# -# Jets -nJetsMin = 3 -dRMin = 1.0 -dEtaMax = 1.5 - -# jet pt -# ranked jets in pt, the order below matters -jetsPtMin = 100.0 -jetsPtMin = 100.0 -jetsPtMin = 40.0 - -# jet eta -# ranked jets in pt, the order below matters -jetsEtaMax = 2.2 -jetsEtaMax = 2.2 -jetsEtaMax = 2.2 - -# Btagging -## just define working points and type of region... -btagWP = 0.8484 -nonbtagWP = 0.46 -signalRegion = false - -## or set for each jet, but which method has to be defined in the macro -# ranked jets in pt, the order below matters -#nBJetsMin = 3 -#jetsBtagMin = 0.8484 -#jetsBtagMin = 0.8484 -#jetsBtagMin = -0.46 diff --git a/bin/rootFileList.txt b/bin/rootFileList.txt deleted file mode 100644 index 06cb8e3b..00000000 --- a/bin/rootFileList.txt +++ /dev/null @@ -1,2 +0,0 @@ -/nfs/dust/cms/user/walsh/tmp/test_mc_hbbM300_1.root -/nfs/dust/cms/user/walsh/tmp/test_mc_hbbM300_2.root diff --git a/data/PileUpWeight_2017.root b/data/PileUpWeight_2017.root new file mode 100644 index 00000000..462652ae Binary files /dev/null and b/data/PileUpWeight_2017.root differ diff --git a/data/PileupWeight_Run2017CDEF_Mix_2017.root b/data/PileupWeight_Run2017CDEF_Mix_2017.root new file mode 100644 index 00000000..ad95e9a6 Binary files /dev/null and b/data/PileupWeight_Run2017CDEF_Mix_2017.root differ diff --git a/data/PileupWeight_Run2017_Mix_2017.root b/data/PileupWeight_Run2017_Mix_2017.root new file mode 100644 index 00000000..f63dc509 Binary files /dev/null and b/data/PileupWeight_Run2017_Mix_2017.root differ diff --git a/doc/AnalyserStructure.001.png b/doc/AnalyserStructure.001.png new file mode 100644 index 00000000..e15eb979 Binary files /dev/null and b/doc/AnalyserStructure.001.png differ diff --git a/interface/Analyser.h b/interface/Analyser.h index 6641cbd1..0e10ddf5 100644 --- a/interface/Analyser.h +++ b/interface/Analyser.h @@ -25,18 +25,10 @@ #include // // user include files -#include "boost/program_options.hpp" +#include "Analysis/Tools/interface/TriggerAnalyser.h" +#include "Analysis/Tools/interface/JetAnalyser.h" +#include "Analysis/Tools/interface/MuonAnalyser.h" -#include "Analysis/Tools/interface/Analysis.h" -#include "Analysis/Tools/interface/Config.h" -#include "TFile.h" -#include "TH1.h" -#include "TH2.h" - - -namespace po = boost::program_options; -using TH1s = std::map; -using TH2s = std::map; // // class declaration @@ -45,12 +37,15 @@ using TH2s = std::map; namespace analysis { namespace tools { - class Analyser { + class Analyser : + public analysis::tools::TriggerAnalyser, + public analysis::tools::JetAnalyser, + public analysis::tools::MuonAnalyser + + { public: /// constructors -// Analyser(const std::string & inputFilelist, const std::string & evtinfo = "MssmHbb/Events/EventInfo"); -// Analyser(Analysis *); Analyser(); Analyser(int argc, char * argv[]); /// desctructor @@ -59,73 +54,16 @@ namespace analysis { // ----------member data --------------------------- protected: - std::shared_ptr analysis_; - std::shared_ptr config_; - - std::vector jets_; - std::vector selectedJets_; - std::vector selectedMuons_; - - bool jetsanalysis_; - bool muonsanalysis_; - - int cutflow_; - - TH1s h1_; - TH2s h2_; private: - - std::shared_ptr hout_; public: - // Gets - std::shared_ptr analysis(); - std::shared_ptr config(); - std::vector selectedJets(); - std::vector jets(); - std::vector selectedMuons(); - - float btag(const Jet & , const std::string & ); - - // Sets - void jets(const std::string &); - void triggerResults(const std::string &); - void triggerObjects(const std::string &,const std::string &); - - // Gets - TH1s H1Fs(); - TH1F * H1F(const std::string &); - - // Actions - virtual void analyse(); - virtual void end(); virtual bool event(const int &); - virtual bool analysisWithJets(); - virtual bool selectionTrigger(); - virtual bool selectionJet(); - virtual bool selectionJet(const int &); - virtual bool selectionJetDeta(const int &, const int &, const float &); - virtual bool selectionJetDeta(const int &, const int &); - virtual bool selectionJetDr(const int &, const int &, const float &); - virtual bool selectionJetDr(const int &, const int &); - virtual bool selectionJetId(); - virtual bool selectionJetPileupId(); - virtual bool selectionNJets(); - virtual bool selectionBJet(); - virtual bool selectionBJet(const int &); - virtual bool selectionNonBJet(const int &); - virtual bool selectionMuon(); - virtual bool onlineJetMatching(); - virtual bool onlineJetMatching(const int &); - virtual bool onlineBJetMatching(); - virtual bool onlineBJetMatching(const int &); - virtual void histograms(const std::string &, const int & n = 1); - virtual void fillJetHistograms(); - virtual void fillMuonHistograms(); - int nEvents(); + + void generatorWeight(); + virtual bool muonJet(const int & ); }; } diff --git a/interface/Analysis.h b/interface/Analysis.h index 9edd45ad..befe95e1 100644 --- a/interface/Analysis.h +++ b/interface/Analysis.h @@ -41,6 +41,8 @@ #include "Analysis/Tools/interface/PhysicsObjectTree.h" #include "Analysis/Tools/interface/Collection.h" #include "Analysis/Tools/interface/BTagCalibrationStandalone.h" +#include "Analysis/Tools/interface/PileupWeight.h" + // // class declaration @@ -122,7 +124,7 @@ namespace analysis { double luminosity(const std::string & title); // Trigger results - void triggerResults(const std::string & path); + bool triggerResults(const std::string & path); bool triggerResult(const std::string & trig); int triggerPrescale(const std::string & trig); std::map triggerPrescale(const std::vector & trigs); @@ -163,6 +165,7 @@ namespace analysis { float scaleLuminosity(const float & lumi); // in pb-1 + std::shared_ptr pileupWeights(const std::string & ); // ----------member data --------------------------- protected: @@ -184,6 +187,9 @@ namespace analysis { std::shared_ptr btagcalibread_; std::shared_ptr jerinfo_; + + // pileup weight + std::shared_ptr puweights_; std::map xsections_; diff --git a/interface/BaseAnalyser.h b/interface/BaseAnalyser.h new file mode 100644 index 00000000..c948e050 --- /dev/null +++ b/interface/BaseAnalyser.h @@ -0,0 +1,147 @@ +#ifndef Analysis_Tools_BaseAnalyser_h +#define Analysis_Tools_BaseAnalyser_h 1 + +// -*- C++ -*- +// +// Package: Analysis/Tools +// Class: Analysis +// +/**\class BaseAnalyser BaseAnalyser.cc Analysis/Tools/src/BaseAnalyser.cc + + Description: A base class for analyser + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Roberval Walsh +// Created: 6 Sep 2018 +// +// + +// system include files +#include +#include +#include +// +// user include files +#include "boost/program_options.hpp" + +#include "Analysis/Tools/interface/Analysis.h" +#include "Analysis/Tools/interface/Config.h" +#include "TFile.h" +#include "TH1.h" +#include "TH2.h" + + +namespace po = boost::program_options; + + +// +// class declaration +// + +namespace analysis { + namespace tools { + + class BaseAnalyser { + + public: + /// constructors + BaseAnalyser(); + BaseAnalyser(int argc, char * argv[]); + /// desctructor + ~BaseAnalyser(); + + + // ----------member data --------------------------- + protected: + // main objects + std::shared_ptr analysis_; + std::shared_ptr config_; + + // selection + int cutflow_; + + // seed value + int seed_; + + // event weight + float weight_; + + // cross section + float xsection_; + + // output root file + std::shared_ptr hout_; + std::map > h1_; + std::map > h2_; + + bool genpartsanalysis_; + + // pileup weight + std::shared_ptr puweights_; + bool istruepu_; + + private: + + // name of the executable + std::string exe_; + + public: + // Gets + /// returns pointer to Analysis object + std::shared_ptr analysis(); + /// returns pointer to Config object + std::shared_ptr config(); + + /// number of events to be processed + int nEvents(); + + + /// returns 1D histograms + std::map > histograms(); + /// returns a given histogram + std::shared_ptr histogram(const std::string &); + + /// print out the cut flow + void cutflow(); + + // Actions + /// event entry to be readout and processed + virtual bool event(const int &); + /// create n histograms of a given type + virtual void histograms(const std::string &, const int &); + + /// others + int seed(); + int seed(const std::string &); + void seed(const int &); + + /// event weight + float weight(); + void weight(const float &); + + // cross section + float crossSection() const; + + // output root file + std::shared_ptr output(); + + // genparticle collection + bool genParticlesAnalysis() const; + + // pileup + std::shared_ptr pileupWeights() const; + float pileupWeight(const float & truepu, const int & var) const; + void actionApplyPileupWeight(const int & var = 0); + + void pileupHistogram(); + void fillPileupHistogram(); + + + }; + } +} + +#endif // Analysis_Tools_BaseAnalyser_h diff --git a/interface/CMS_lumi.h b/interface/CMS_lumi.h index 5c59d116..ccfb2ec3 100644 --- a/interface/CMS_lumi.h +++ b/interface/CMS_lumi.h @@ -17,7 +17,7 @@ TString cmsText = "CMS"; float cmsTextFont = 61; // default is helvetic-bold -bool writeExtraText = false; +bool writeExtraText = true; TString extraText = "Preliminary"; float extraTextFont = 52; // default is helvetica-italics @@ -41,7 +41,7 @@ TString lumi_7TeV = "5.1 fb^{-1}"; bool drawLogo = false; -void CMS_lumi( TPad* pad, int iPeriod=3, int iPosX=10 ); +void CMS_lumi( TPad* pad, TString mytxt = "", int iPeriod=20, int iPosX=0 ); #endif diff --git a/interface/Config.h b/interface/Config.h index 0a6de1c2..1911ca5a 100644 --- a/interface/Config.h +++ b/interface/Config.h @@ -71,10 +71,36 @@ namespace analysis { // analysis control std::string inputlist_; + std::string eventinfo_; + std::string xsectiontree_; + std::string xsectiontype_; + float lumi_; int nevtmax_; bool isMC_; bool signalregion_; + bool blind_; bool override_; + bool nlo_; + bool fullweight_; + int workflow_; + + int seed_; + std::string seedfile_; + + bool pythia8_; + + float scale_; + + std::vector era_; + std::vector eralumi_; + + std::string puweight_; + + // generic options + int prescale_; + int n_; + float min_; + float max_; // jets @@ -86,7 +112,32 @@ namespace analysis { std::vector jetsetamax_; std::string jetsid_; std::string jetspuid_; + // JER resolution and scale factors from txt file + std::string jerptres_; + std::string jersf_; + // std::string l1tjetsCol_; + // + std::vector jetsbtagwp_; + std::string nonbtagwp_; + int nonbtagjet_; + // cuts on the probabilities + std::vector jetsbtagprobb_; + std::vector jetsbtagprobbb_; + std::vector jetsbtagproblepb_; + std::vector jetsbtagprobc_; + std::vector jetsbtagprobg_; + std::vector jetsbtagproblight_; + + // + std::vector triggerObjectsJets_; + bool usejetsflv_; + bool usejetsextflv_; + bool dodijet_; + bool dodijet_flavour_; + + bool bregression_; + // muons std::string muonsCol_; @@ -100,8 +151,42 @@ namespace analysis { // trigger std::string triggerCol_; + std::string triggerObjDir_; + std::string triggerObjectsL1Muons_; + std::string triggerObjectsL3Muons_; + std::string triggerObjectsBJets_; + std::string triggerObjectsL1Jets_; + std::string triggerObjectsCaloJets_; + std::string triggerObjectsPFJets_; + + // generator level collections + std::string genjetsCol_; + std::string genpartsCol_; + + // btag + float btagwploose_; + float btagwpmedium_; + float btagwptight_; + float btagwpxxx_; + + // general + float massmin_; + float massmax_; + + // AI + std::vector varsf_ai_; + std::vector varsi_ai_; + std::string dir_ai_; + std::string method_ai_; + float disc_max_ai_; + float disc_min_ai_; + float eff_min_ai_; + // output tree + + bool do_tree_; + private: @@ -112,10 +197,30 @@ namespace analysis { // gets (to replace the public variables) // analysis control std::string ntuplesList() const; + std::string eventInfo() const; + std::string crossSectionTree() const; + std::string crossSectionType() const; + float luminosity() const; int nEventsMax() const; bool isMC() const; bool signalRegion() const; + bool blind() const; bool override() const; + bool nlo() const; + bool fullWeight() const; + int workflow() const; + + std::string seedFile() const; + int seed() const; + + bool pythia8() const; + + float scale() const; + + std::vector eraLumi() const; + std::vector era() const; + + std::string pileupWeights() const; // jets std::string jetsCollection() const; @@ -126,7 +231,25 @@ namespace analysis { std::vector jetsEtaMax() const; std::string jetsId() const; std::string jetsPuId() const; + std::string jerPtRes() const; + std::string jerSF() const; std::string l1tJetsCollection() const; + std::vector jetsBtagWP() const; + std::vector jetsBtagProbB() const; + std::vector jetsBtagProbBB() const; + std::vector jetsBtagProbLepB() const; + std::vector jetsBtagProbC() const; + std::vector jetsBtagProbG() const; + std::vector jetsBtagProbLight() const; + bool bRegression() const; + std::string nonBtagWP() const; + int nonBtagJet() const; + std::vector triggerObjectsJets() const; + void triggerObjectsJets(const std::string & label, const int & index); + bool useJetsFlavour() const; + bool useJetsExtendedFlavour() const; + bool doDijet() const; + bool doDijetFlavour() const; // muons std::string muonsCollection() const; @@ -139,7 +262,41 @@ namespace analysis { std::string l1tMuonsCollection() const; // trigger - std::string triggerResults() const; + std::string triggerResults() const; + std::string triggerObjectsDir() const; + std::string triggerObjectsL1Muons() const; + std::string triggerObjectsL3Muons() const; + std::string triggerObjectsBJets() const; + std::string triggerObjectsL1Jets() const; + std::string triggerObjectsCaloJets() const; + std::string triggerObjectsPFJets() const; + // generator level + std::string genJetsCollection() const; + std::string genParticlesCollection() const; + + // btag + float btagWP(const std::string &) const; + + // general + float massMin() const; + float massMax() const; + + // AI + std::vector variablesAI(const std::string & t = "F") const; + std::string directoryAI() const; + std::string methodAI() const; + float discriminatorMaxAI() const; + float discriminatorMinAI() const; + float efficiencyMinAI() const; + + // output tree + bool doTree() const; + + // generic options + int prescale() const; + int n() const; + float min() const; + float max() const; // ======================== @@ -177,17 +334,17 @@ namespace analysis { float detamax_; float detamin_; float dphimin_; + float dphimax_; float ptimbalmax_; + float ptimbalmin_; + + std::vector qgmin_; + std::vector qgmax_; std::string btagalgo_; std::string btagwp_; - float btagwploose_; - float btagwpmedium_; - float btagwptight_; //float btagwp_; - float nonbtagwp_; - int nonbtagjet_; std::string hltPath_; @@ -195,21 +352,17 @@ namespace analysis { std::vector triggerObjects_; std::vector triggerObjectsMatches_; std::vector triggerObjectsMatchesRank_; - std::vector triggerObjectsJets_; - std::vector triggerObjectsBJets_; - std::vector triggerObjectsL1Jets_; + + + + int triggerObjectsJetsMatches_; int triggerObjectsBJetsMatches_; int triggerObjectsL1JetsMatches_; std::vector triggerObjectsMuons_; - std::vector triggerObjectsL1Muons_; int triggerObjectsMuonsMatches_; int triggerObjectsL1MuonsMatches_; - - // ntuples collections - std::string genParticleCol_; - std::string genjetsCol_; - std::string triggerObjDir_; + int triggerObjectsL3MuonsMatches_; protected: int argc_; diff --git a/interface/Jet.h b/interface/Jet.h index efd97654..551cf255 100644 --- a/interface/Jet.h +++ b/interface/Jet.h @@ -184,6 +184,7 @@ namespace analysis { void jerInfo(const JetResolutionInfo &, const std::string &); void jerInfo(const JetResolutionInfo &, const float & drmin=0.2); + void applyJER(const JetResolutionInfo &, const float & drmin=0.2); /// add parton that gave rise to jet void addParton(const std::shared_ptr &); @@ -227,6 +228,8 @@ namespace analysis { void bRegCorr(const float &); void bRegRes(const float &); + void applyBjetRegression(); + /// Rho void rho(const double &); @@ -245,6 +248,8 @@ namespace analysis { /// associate a muon to the jet void addMuon(std::shared_ptr); + /// associate a muon to the jet from a collection of muons + void addMuon(std::vector< std::shared_ptr > muons, const float & dr = 0.4); /// remove muon association to the jet void rmMuon(); diff --git a/interface/JetAnalyser.h b/interface/JetAnalyser.h new file mode 100644 index 00000000..09589368 --- /dev/null +++ b/interface/JetAnalyser.h @@ -0,0 +1,111 @@ +#ifndef Analysis_Tools_JetAnalyser_h +#define Analysis_Tools_JetAnalyser_h 1 + +// -*- C++ -*- +// +// Package: Analysis/Tools +// Class: Analysis +// +/**\class Analysis JetAnalyser.cc Analysis/Tools/src/JetAnalyser.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Roberval Walsh Bastos Rangel +// Created: Mon, 20 Oct 2014 14:24:08 GMT +// +// + +// system include files +#include +#include +#include +// +#include "Analysis/Tools/interface/BaseAnalyser.h" +// +// class declaration +// + +namespace analysis { + namespace tools { + + class JetAnalyser : virtual public analysis::tools::BaseAnalyser { + + public: + /// constructors + JetAnalyser(); + JetAnalyser(int argc, char * argv[]); + /// desctructor + ~JetAnalyser(); + + // ----------member data --------------------------- + protected: + std::vector< std::shared_ptr > jets_; + std::vector< std::shared_ptr > selectedJets_; + + // number of histogrammed jets + int n_hjets_; + + bool jetsanalysis_; + bool genjetsanalysis_; + bool applyjer_; + + std::map >bsf_reader_; + + std::shared_ptr jerinfo_; + + std::vector flavours_; + + private: + + public: + std::vector< std::shared_ptr > selectedJets(); + std::vector< std::shared_ptr > jets(); + float btag(const Jet & , const std::string & ); + + // Sets + void jets(const std::string &); + + // Actions + virtual bool analysisWithJets(); + virtual bool selectionJet(const int &); + virtual bool selectionJetDeta(const int &, const int &, const float &); + virtual bool selectionJetDeta(const int &, const int &); + virtual bool selectionJetDphi(const int &, const int &, const float &); + virtual bool selectionJetDphi(const int &, const int &); + virtual bool selectionJetDr(const int &, const int &, const float &); + virtual bool selectionJetDr(const int &, const int &); + virtual bool selectionJetPtImbalance(const int &, const int &, const float &); + virtual bool selectionJetPtImbalance(const int &, const int &); + virtual bool selectionJetId(); + virtual bool selectionJetPileupId(); + virtual bool selectionNJets(); + virtual bool selectionDiJetMass(const int &, const int &); + virtual bool selectionBJet(const int &); + virtual bool selectionBJetProbB(const int &); + virtual bool selectionBJetProbBB(const int &); + virtual bool selectionBJetProbLepB(const int &); + virtual bool selectionBJetProbC(const int &); + virtual bool selectionBJetProbG(const int &); + virtual bool selectionBJetProbLight(const int &); + virtual ScaleFactors btagSF(const int &, const std::string &); + virtual bool selectionNonBJet(const int &); + virtual bool onlineJetMatching(const int &); + virtual bool onlineBJetMatching(const int &); + virtual void jetHistograms(const int & n = 1, const std::string & label = "x"); + virtual void fillJetHistograms(const std::string & label = "x"); + virtual void actionApplyJER(); + virtual void actionApplyBtagSF(const int &); + virtual void actionApplyBjetRegression(); + virtual void jetSwap(const int &, const int &); + virtual bool selectionJetQGlikelihood(const int &, const float &); + virtual bool selectionJetQGlikelihood(const int &); + + }; + } +} + +#endif // Analysis_Tools_JetAnalyser_h diff --git a/interface/MuonAnalyser.h b/interface/MuonAnalyser.h new file mode 100644 index 00000000..c7caeb3c --- /dev/null +++ b/interface/MuonAnalyser.h @@ -0,0 +1,81 @@ +#ifndef Analysis_Tools_MuonAnalyser_h +#define Analysis_Tools_MuonAnalyser_h 1 + +// -*- C++ -*- +// +// Package: Analysis/Tools +// Class: Analysis +// +/**\class Analysis MuonAnalyser.cc Analysis/Tools/src/MuonAnalyser.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Roberval Walsh Bastos Rangel +// Created: Mon, 20 Oct 2014 14:24:08 GMT +// +// + +// system include files +#include +#include +#include +// +#include "Analysis/Tools/interface/BaseAnalyser.h" +// +// class declaration +// + +namespace analysis { + namespace tools { + + class MuonAnalyser : virtual public analysis::tools::BaseAnalyser { + + public: + /// constructors + MuonAnalyser(); + MuonAnalyser(int argc, char * argv[]); + /// desctructor + ~MuonAnalyser(); + + // ----------member data --------------------------- + protected: + std::vector< std::shared_ptr > muons_; + std::vector< std::shared_ptr > selectedMuons_; + std::vector< std::shared_ptr > onlineMatchedMuons_; + + bool muonsanalysis_; + + std::map >bsf_reader_; + + private: + + public: + std::vector< std::shared_ptr > selectedMuons(); + std::vector< std::shared_ptr > onlineMatchedMuons(); + std::vector< std::shared_ptr > muons(); + float btag(const Muon & , const std::string & ); + + // Sets + + // Actions + virtual bool analysisWithMuons(); + virtual bool selectionMuon(const int &); + virtual bool selectionMuons(); +// virtual bool selectionMuon(); + virtual bool selectionMuonId(); + virtual bool selectionNMuons(); + virtual bool onlineMuonMatching(); + virtual bool onlineL1MuonMatching(const int &); + virtual bool onlineL3MuonMatching(const int &); + virtual void muonHistograms(const std::string &, const int & n = 1); + virtual void fillMuonHistograms(); + + }; + } +} + +#endif // Analysis_Tools_MuonAnalyser_h diff --git a/interface/PileupWeight.h b/interface/PileupWeight.h new file mode 100644 index 00000000..d238a906 --- /dev/null +++ b/interface/PileupWeight.h @@ -0,0 +1,62 @@ +#ifndef Analysis_Tools_PileupWeight_h +#define Analysis_Tools_PileupWeight_h 1 + +// -*- C++ -*- +// +// Package: Analysis/Tools +// Class: Analysis +// +/**\class Analysis PileupWeight.cc Analysis/Tools/src/PileupWeight.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Roberval Walsh Bastos Rangel +// Created: Mon, 20 Oct 2014 14:24:08 GMT +// +// + +// system include files +#include +#include +#include +#include +#include +// +// user include files + +#include "TH1.h" + + +// +// class declaration +// + +namespace analysis { + namespace tools { + + class PileupWeight { + public: + /// constructors + PileupWeight(); + PileupWeight(const std::string &); + /// desctructor + ~PileupWeight(); + + // ----------member data --------------------------- + protected: + std::map > histos_; + + private: + + public: + float weight(const float & truepu, const int & var = 0); + std::shared_ptr histogram(const int & var = 0); + }; + } +} + +#endif // Analysis_Tools_PileupWeight_h diff --git a/interface/TriggerAnalyser.h b/interface/TriggerAnalyser.h new file mode 100644 index 00000000..69c39a84 --- /dev/null +++ b/interface/TriggerAnalyser.h @@ -0,0 +1,69 @@ +#ifndef Analysis_Tools_TriggerAnalyser_h +#define Analysis_Tools_TriggerAnalyser_h 1 + +// -*- C++ -*- +// +// Package: Analysis/Tools +// Class: Analysis +// +/**\class Analysis TriggerAnalyser.cc Analysis/Tools/src/TriggerAnalyser.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Roberval Walsh Bastos Rangel +// Created: Mon, 20 Oct 2014 14:24:08 GMT +// +// + +// system include files +#include +#include +#include +// +#include "Analysis/Tools/interface/BaseAnalyser.h" +// +// class declaration +// + +namespace analysis { + namespace tools { + + class TriggerAnalyser : virtual public analysis::tools::BaseAnalyser { + + public: + /// constructors + TriggerAnalyser(); + TriggerAnalyser(int argc, char * argv[]); + /// desctructor + ~TriggerAnalyser(); + + + // ----------member data --------------------------- + protected: + bool triggeranalysis_; + + private: + + public: + + // Actions + virtual bool analysisWithTrigger(); + virtual bool selectionTrigger(); + virtual bool selectionHLT(); + virtual bool selectionL1(); + + std::vector< std::shared_ptr > triggerObjectsL1Jets(); + std::vector< std::shared_ptr > triggerObjectsCaloJets(); + std::vector< std::shared_ptr > triggerObjectsPFJets(); + std::vector< std::shared_ptr > triggerObjectsL1Muons(); + std::vector< std::shared_ptr > triggerObjectsL3Muons(); + + }; + } +} + +#endif // Analysis_Tools_TriggerAnalyser_h diff --git a/interface/Utils.h b/interface/Utils.h index 6920ddbd..0f03c2bd 100644 --- a/interface/Utils.h +++ b/interface/Utils.h @@ -60,6 +60,12 @@ namespace analysis { JME::JetResolutionScaleFactor scalefactor; }; + struct ScaleFactors + { + float nominal; + float up; + float down; + }; } } diff --git a/interface/plotscomp_config.h b/interface/plotscomp_config.h new file mode 100644 index 00000000..fa19356d --- /dev/null +++ b/interface/plotscomp_config.h @@ -0,0 +1,127 @@ +#ifndef Analysis_Tools_plotscomp_config_h_ +#define Analysis_Tools_plotscomp_config_h_ + +#include "boost/program_options.hpp" +#include "boost/algorithm/string.hpp" +#include +#include +#include +#include + +int plotscomp_config(int argc, char * argv[]); + +//std::string cfg_; + +// if file, give up to 4 histograms +std::vector files_; +std::vector histos_; +std::vector titles_; + +std::string file_; +std::string hist1_; +std::string hist2_; + +std::string hist_; +std::string file1_; +std::string file2_; + +std::string title_; +std::string legend1_; +std::string legend2_; + +std::string outplot_; + +float min_,max_; + +float scale_; + +bool logx_; +bool logy_; +bool app_; + + + +int plotscomp_config(int argc, char * argv[]) +{ + app_ = true; + logx_ = false; + logy_ = false; + try + { + namespace po = boost::program_options; + po::options_description desc("Options"); + desc.add_options() + ("help,h" , "Show help messages") + ("bkg,b" , "Run in the background") + ("logx" , "x-axis in log scale") + ("logy" , "y-axis in log scale") + ("files" , po::value >(&files_)->multitoken(),"list of files") + ("histos" , po::value >(&histos_)->multitoken(),"list of histograms") + ("titles" , po::value >(&titles_)->multitoken(),"titles of histograms") + ("title,t" , po::value (&title_) -> default_value("") , "Title of the histogram") + ("legend1" , po::value (&legend1_)-> default_value("histo 1") , "Legend of the histogram 1") + ("legend2" , po::value (&legend2_)-> default_value("histo 2") , "Legend of the histogram 2") + ("scale,s" , po::value (&scale_) -> default_value(1) , "Scale factor for the 2nd histogram") + ("min" , po::value (&min_) -> default_value(-1) , "Min value histogram range") + ("max" , po::value (&max_) -> default_value(-2) , "Max value histogram range") + ("file,f" , po::value (&file_) -> default_value("") , "File with up to 2 histograms to compare") + ("hist1" , po::value (&hist1_ ) -> default_value("") , "1st histogram name in file") + ("hist2" , po::value (&hist2_ ) -> default_value("") , "2nd histogram name in file") + ("hist,h" , po::value (&hist_) -> default_value("") , "Histogram name common to the different files") + ("file1" , po::value (&file1_) -> default_value("") , "1st file with 1 histogram to compare") + ("file2" , po::value (&file2_) -> default_value("") , "2nd file with 1 histogram to compare") + ("output" , po::value (&outplot_)-> default_value("") , "name of the output plot"); + +// ("config,c",po::value(&cfg_),"Configuration file name"); + +// po::options_description config("Configuration"); +// config.add_options() +// ("file",po::value (&file_) ->default_value(""),"File with up to 2 histograms to compare") +// ("hist",po::value (&hist_) ->default_value(""),"Histogram name common to the different files"); + + po::variables_map vm; + try + { + po::store(po::parse_command_line(argc, argv, desc), vm); // can throw + // --help option + + if ( vm.count("help") ) + { + std::cout << "PlotsCompare macro" << std::endl + << desc << std::endl; +// << config << std::endl; + return 1; + } + if ( vm.count("logx") ) logx_ = true; + if ( vm.count("logy") ) logy_ = true; + if ( vm.count("bkg") ) app_ = false; + + po::notify(vm); + +// std::ifstream cfg_s(cfg_.c_str()); +// po::store(po::parse_config_file(cfg_s, config), vm); // can throw +// if ( vm.count("config") ) +// { +// +// } + po::notify(vm); + } + catch(po::error& e) + { + std::cerr << "ERROR: " << e.what() << std::endl << std::endl; + std::cerr << desc << std::endl; + return -1; + } + + } + catch(std::exception& e) + { + std::cerr << "ERROR: " << e.what() << std::endl << std::endl; + return -1; + } + + return 0; +} + + +#endif diff --git a/interface/tdrstyle.C b/interface/tdrstyle.C new file mode 100644 index 00000000..184f53ca --- /dev/null +++ b/interface/tdrstyle.C @@ -0,0 +1,162 @@ +#include "TStyle.h" + +TStyle *tdrStyle; + +// tdrGrid: Turns the grid lines on (true) or off (false) + +void tdrGrid(bool gridOn) { + tdrStyle->SetPadGridX(gridOn); + tdrStyle->SetPadGridY(gridOn); +} + +// fixOverlay: Redraws the axis + +void fixOverlay() { + gPad->RedrawAxis(); +} + +void setTDRStyle() { + tdrStyle = new TStyle("tdrStyle","Style for P-TDR"); + +// For the canvas: + tdrStyle->SetCanvasBorderMode(0); + tdrStyle->SetCanvasColor(kWhite); + tdrStyle->SetCanvasDefH(600); //Height of canvas + tdrStyle->SetCanvasDefW(600); //Width of canvas + tdrStyle->SetCanvasDefX(0); //POsition on screen + tdrStyle->SetCanvasDefY(0); + +// For the Pad: + tdrStyle->SetPadBorderMode(0); + // tdrStyle->SetPadBorderSize(Width_t size = 1); + tdrStyle->SetPadColor(kWhite); + tdrStyle->SetPadGridX(false); + tdrStyle->SetPadGridY(false); + tdrStyle->SetGridColor(0); + tdrStyle->SetGridStyle(3); + tdrStyle->SetGridWidth(1); + +// For the frame: + tdrStyle->SetFrameBorderMode(0); + tdrStyle->SetFrameBorderSize(1); + tdrStyle->SetFrameFillColor(0); + tdrStyle->SetFrameFillStyle(0); + tdrStyle->SetFrameLineColor(1); + tdrStyle->SetFrameLineStyle(1); + tdrStyle->SetFrameLineWidth(1); + +// For the histo: + // tdrStyle->SetHistFillColor(1); + // tdrStyle->SetHistFillStyle(0); + tdrStyle->SetHistLineColor(1); + tdrStyle->SetHistLineStyle(0); + tdrStyle->SetHistLineWidth(1); + // tdrStyle->SetLegoInnerR(Float_t rad = 0.5); + // tdrStyle->SetNumberContours(Int_t number = 20); + + tdrStyle->SetEndErrorSize(2); + // tdrStyle->SetErrorMarker(20); + //tdrStyle->SetErrorX(0.); + + tdrStyle->SetMarkerStyle(20); + +//For the fit/function: + tdrStyle->SetOptFit(1); + tdrStyle->SetFitFormat("5.4g"); + tdrStyle->SetFuncColor(2); + tdrStyle->SetFuncStyle(1); + tdrStyle->SetFuncWidth(1); + +//For the date: + tdrStyle->SetOptDate(0); + // tdrStyle->SetDateX(Float_t x = 0.01); + // tdrStyle->SetDateY(Float_t y = 0.01); + +// For the statistics box: + tdrStyle->SetOptFile(0); + tdrStyle->SetOptStat(0); // To display the mean and RMS: SetOptStat("mr"); + tdrStyle->SetStatColor(kWhite); + tdrStyle->SetStatFont(42); + tdrStyle->SetStatFontSize(0.025); + tdrStyle->SetStatTextColor(1); + tdrStyle->SetStatFormat("6.4g"); + tdrStyle->SetStatBorderSize(1); + tdrStyle->SetStatH(0.1); + tdrStyle->SetStatW(0.15); + // tdrStyle->SetStatStyle(Style_t style = 1001); + // tdrStyle->SetStatX(Float_t x = 0); + // tdrStyle->SetStatY(Float_t y = 0); + +// Margins: + tdrStyle->SetPadTopMargin(0.05); + tdrStyle->SetPadBottomMargin(0.13); + tdrStyle->SetPadLeftMargin(0.16); + tdrStyle->SetPadRightMargin(0.02); + +// For the Global title: + + tdrStyle->SetOptTitle(0); + tdrStyle->SetTitleFont(42); + tdrStyle->SetTitleColor(1); + tdrStyle->SetTitleTextColor(1); + tdrStyle->SetTitleFillColor(10); + tdrStyle->SetTitleFontSize(0.05); + // tdrStyle->SetTitleH(0); // Set the height of the title box + // tdrStyle->SetTitleW(0); // Set the width of the title box + // tdrStyle->SetTitleX(0); // Set the position of the title box + // tdrStyle->SetTitleY(0.985); // Set the position of the title box + // tdrStyle->SetTitleStyle(Style_t style = 1001); + // tdrStyle->SetTitleBorderSize(2); + +// For the axis titles: + + tdrStyle->SetTitleColor(1, "XYZ"); + tdrStyle->SetTitleFont(42, "XYZ"); + tdrStyle->SetTitleSize(0.06, "XYZ"); + // tdrStyle->SetTitleXSize(Float_t size = 0.02); // Another way to set the size? + // tdrStyle->SetTitleYSize(Float_t size = 0.02); + tdrStyle->SetTitleXOffset(0.9); + tdrStyle->SetTitleYOffset(1.25); + // tdrStyle->SetTitleOffset(1.1, "Y"); // Another way to set the Offset + +// For the axis labels: + + tdrStyle->SetLabelColor(1, "XYZ"); + tdrStyle->SetLabelFont(42, "XYZ"); + tdrStyle->SetLabelOffset(0.007, "XYZ"); + tdrStyle->SetLabelSize(0.05, "XYZ"); + +// For the axis: + + tdrStyle->SetAxisColor(1, "XYZ"); + tdrStyle->SetStripDecimals(kTRUE); + tdrStyle->SetTickLength(0.03, "XYZ"); + tdrStyle->SetNdivisions(510, "XYZ"); + tdrStyle->SetPadTickX(1); // To get tick marks on the opposite side of the frame + tdrStyle->SetPadTickY(1); + +// Change for log plots: + tdrStyle->SetOptLogx(0); + tdrStyle->SetOptLogy(0); + tdrStyle->SetOptLogz(0); + +// Postscript options: + tdrStyle->SetPaperSize(20.,20.); + // tdrStyle->SetLineScalePS(Float_t scale = 3); + // tdrStyle->SetLineStyleString(Int_t i, const char* text); + // tdrStyle->SetHeaderPS(const char* header); + // tdrStyle->SetTitlePS(const char* pstitle); + + // tdrStyle->SetBarOffset(Float_t baroff = 0.5); + // tdrStyle->SetBarWidth(Float_t barwidth = 0.5); + // tdrStyle->SetPaintTextFormat(const char* format = "g"); + // tdrStyle->SetPalette(Int_t ncolors = 0, Int_t* colors = 0); + // tdrStyle->SetTimeOffset(Double_t toffset); + // tdrStyle->SetHistMinimumZero(kTRUE); + + tdrStyle->SetHatchesLineWidth(5); + tdrStyle->SetHatchesSpacing(0.05); + + tdrStyle->cd(); + +} diff --git a/scripts/pileupCalcMC.py b/scripts/pileupCalcMC.py new file mode 100755 index 00000000..b6e2160c --- /dev/null +++ b/scripts/pileupCalcMC.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +# pileupCalcMC.py + +from argparse import ArgumentParser +from importlib import import_module +from ROOT import TH1D +from ROOT import TFile + +# parsing arguments +parser = ArgumentParser() +parser.add_argument("--pu" , dest="pileup" , help="Pileup from mixing module") +parser.add_argument("--n" , dest="nbins" , type=int, default=100 , help="number of bins") +parser.add_argument("--min" , dest="min" , type=int, default=0 , help="Min pileup") +parser.add_argument("--max" , dest="max" , type=int, default=100 , help="Max pileup") +parser.add_argument("--out" , dest="out" , default="MyMCPileupHistogram.root", help="output") +args = parser.parse_args() +if not args.pileup: + print "nothing to be done" + quit() + +puconfig = import_module(args.pileup) + +bins = puconfig.mix.input.nbPileupEvents.probFunctionVariable +values = puconfig.mix.input.nbPileupEvents.probValue + + +hPU = TH1D("pileup", "true pileup", args.nbins, args.min, args.max) + +for i in range(1, args.nbins+1): + try: + hPU.SetBinContent(i,values[bins.index(hPU.GetBinLowEdge(i))]) + except ValueError as error: + hPU.SetBinContent(i,0) + +fout = TFile(args.out,"recreate") +hPU.Write() +fout.Close() + diff --git a/scripts/pileupWeights.py b/scripts/pileupWeights.py new file mode 100755 index 00000000..a83d4e30 --- /dev/null +++ b/scripts/pileupWeights.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python + +# pileupCalcMC.py + +from argparse import ArgumentParser +from ROOT import TH1D +from ROOT import TH1F +from ROOT import TFile + +# parsing arguments +parser = ArgumentParser() +parser.add_argument("--data" , dest="data" , help="file containing data pileup") +parser.add_argument("--mc" , dest="mc" , help="file containing mc pileup") +parser.add_argument("--up1" , dest="up1" , help="file containing data pileup 1sigma up var") +parser.add_argument("--down1" , dest="down1" , help="file containing data pileup 1sigma down var") +parser.add_argument("--up2" , dest="up2" , help="file containing data pileup 2sigma up var") +parser.add_argument("--down2" , dest="down2" , help="file containing data pileup 2sigma down var") +parser.add_argument("--output" , dest="out" , help="name ouf output file", default = "PileupWeight.root") + +args = parser.parse_args() +if not ( args.data and args.mc ): + print "nothing to be done" + quit() + +f_data = TFile(args.data,"old") +h_data = TH1D(f_data.Get("pileup")) +h_data.Scale(1./h_data.Integral()) + +f_mc = TFile(args.mc,"old") +try: + h_mc = TH1D(f_mc.Get("pileup")) +except TypeError as error: + h_mc = TH1F(f_mc.Get("pileup")) + +h_mc.Scale(1./h_mc.Integral()) + +h_weight = TH1D(h_data.Clone("weight")); +h_weight.Divide(h_mc); + +if args.up1: + f_up1 = TFile(args.up1,"old") + h_up1 = TH1D(f_up1.Get("pileup")) + h_up1.SetName("weight_1up") + h_up1.Scale(1./h_up1.Integral()) + h_up1.Divide(h_mc) + +if args.down1: + f_down1 = TFile(args.down1,"old") + h_down1 = TH1D(f_down1.Get("pileup")) + h_down1.SetName("weight_1down") + h_down1.Scale(1./h_down1.Integral()) + h_down1.Divide(h_mc) + +if args.up2: + f_up2 = TFile(args.up2,"old") + h_up2 = TH1D(f_up2.Get("pileup")) + h_up2.SetName("weight_2up") + h_up2.Scale(1./h_up2.Integral()) + h_up2.Divide(h_mc) + +if args.down2: + f_down2 = TFile(args.down2,"old") + h_down2 = TH1D(f_down2.Get("pileup")) + h_down2.SetName("weight_2down") + h_down2.Scale(1./h_down2.Integral()) + h_down2.Divide(h_mc) + + +fout = TFile(args.out,"recreate") +h_weight.Write() +if args.up1: + h_up1.Write() +if args.down1: + h_down1.Write() +if args.up2: + h_up2.Write() +if args.down2: + h_down2.Write() + + +fout.Close() + diff --git a/src/Analyser.cc b/src/Analyser.cc index 2ab4f550..ec3de9f4 100644 --- a/src/Analyser.cc +++ b/src/Analyser.cc @@ -20,7 +20,6 @@ #include // // user include files -#include "TString.h" #include "Analysis/Tools/interface/Analyser.h" // @@ -30,70 +29,21 @@ using namespace analysis; using namespace analysis::tools; -// -// constructors and destructor -// -// Analyser::Analyser(const std::string & inputFilelist, const std::string & evtinfo) -// { -// analysis_ = new Analysis(inputFilelist,evtinfo); -// } -// -// Analyser::Analyser(Analysis * a) -// { -// analysis_ = a; -// } -// Analyser::Analyser() { } -Analyser::Analyser(int argc, char * argv[]) -{ - config_ = std::make_shared(argc,argv); - analysis_ = std::make_shared(config_->ntuplesList()); - - cutflow_ = 0; +Analyser::Analyser(int argc, char * argv[]) : BaseAnalyser(argc,argv), // not sure the BaseAnalyser should be called here + TriggerAnalyser(argc,argv), + JetAnalyser(argc,argv), + MuonAnalyser(argc,argv) - // Physics objects - // Jets - jetsanalysis_ = ( analysis_->addTree ("Jets",config_->jetsCollection()) != nullptr ); - - // Muons - muonsanalysis_ = ( analysis_->addTree("Muons",config_->muonsCollection()) != nullptr ); - - // Trigger - // Trigger Results - analysis_->triggerResults(config_->triggerResults()); - // Trigger objects - if ( config_->triggerObjDir_ != "" ) - { - for ( auto & obj : config_->triggerObjects_ ) analysis_->addTree (obj,Form("%s/%s",config_->triggerObjDir_.c_str(),obj.c_str())); - for ( auto & obj : config_->triggerObjectsJets_ ) analysis_->addTree (obj,Form("%s/%s",config_->triggerObjDir_.c_str(),obj.c_str())); - for ( auto & obj : config_->triggerObjectsBJets_ ) analysis_->addTree (obj,Form("%s/%s",config_->triggerObjDir_.c_str(),obj.c_str())); - } - // JSON for data - if( !config_->isMC() && config_->json_ != "" ) analysis_->processJsonFile(config_->json_); - - // output file - if ( config_->outputRoot_ != "" ) - { - hout_= std::shared_ptr(new TFile(config_->outputRoot_.c_str(),"recreate")); - } - - h1_["cutflow"] = new TH1F("cutflow","", 30,0,30); - if ( config_->isMC() ) - { - if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(1)) == "" ) - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,"Generated events"); - } - +{ } Analyser::~Analyser() { - // do anything here that needs to be done at desctruction time - // (e.g. close files, deallocate resources etc.) } @@ -102,40 +52,21 @@ Analyser::~Analyser() // // ------------ method called for each event ------------ -void Analyser::jets(const std::string & col) -{ - analysis_->addTree ("Jets",col); -} -void Analyser::triggerResults(const std::string & col) -{ - analysis_->triggerResults(col); -} - -void Analyser::analyse() -{ -} - -void Analyser::end() -{ - if ( hout_ ) - { - hout_->Write(); - hout_->Close(); - } -} - bool Analyser::event(const int & i) { bool ok = true; analysis_->event(i); cutflow_ = 0; + weight_ = 1.; // reset weight at the beginning of the event analysis + h1_["cutflow"] -> Fill(cutflow_,weight_); if ( config_->isMC() ) { - h1_["cutflow"] -> Fill(cutflow_); + this -> generatorWeight(); + ++cutflow_; + h1_["cutflow"] -> Fill(cutflow_,weight_); } - if ( config_->runmin_ > 0 && analysis_->run() < config_->runmin_ ) return false; if ( config_->runmax_ > 0 && analysis_->run() > config_->runmax_ ) return false; @@ -144,558 +75,45 @@ bool Analyser::event(const int & i) if ( ! ok ) return false; analysisWithJets(); + analysisWithMuons(); return ok; } -void Analyser::histograms(const std::string & obj, const int & n) +void Analyser::generatorWeight() { - if ( obj == "jet" ) - { - for ( int j = 0; j < n; ++j ) - { - h1_[Form("pt_%s%d" , obj.c_str(),j+1)] = new TH1F(Form("pt_%s%d" , obj.c_str(),j+1) , "" ,100 , 0 , 1000 ); - h1_[Form("eta_%s%d" , obj.c_str(),j+1)] = new TH1F(Form("eta_%s%d" , obj.c_str(),j+1) , "" , 60 , -3, 3 ); - h1_[Form("btag_%s%d", obj.c_str(),j+1)] = new TH1F(Form("btag_%s%d", obj.c_str(),j+1) , "" , 100 , 0, 1 ); - for ( int k = j+1; k < n && j < n; ++k ) - { - h1_[Form("dr_%s%d%d" , obj.c_str(),j+1,k+1)] = new TH1F(Form("dr_%s%d%d" , obj.c_str(),j+1,k+1) , "" , 50 , 0, 5 ); - h1_[Form("deta_%s%d%d", obj.c_str(),j+1,k+1)] = new TH1F(Form("deta_%s%d%d", obj.c_str(),j+1,k+1) , "" ,100 , 0,10 ); - h1_[Form("m_%s%d%d" , obj.c_str(),j+1,k+1)] = new TH1F(Form("m_%s%d%d ", obj.c_str(),j+1,k+1) , "" ,300 , 0,3000 ); - } - } - - } - if ( obj == "muon" ) - { - for ( int j = 0; j < n; ++j ) - { - h1_[Form("pt_%s%d" , obj.c_str(),j+1)] = new TH1F(Form("pt_%s%d" , obj.c_str(),j+1) , "" ,100 , 0 , 1000 ); - h1_[Form("eta_%s%d" , obj.c_str(),j+1)] = new TH1F(Form("eta_%s%d" , obj.c_str(),j+1) , "" , 60 , -3, 3 ); - } - - } + if ( ! config_->isMC() ) return; -} - - -std::shared_ptr Analyser::analysis() -{ - return analysis_; -} - -std::shared_ptr Analyser::config() -{ - return config_; -} - - -float Analyser::btag(const Jet & jet, const std::string & algo) -{ - float btag; - if ( config_->btagalgo_ == "csvivf" || config_->btagalgo_ == "csv" ) { btag = jet.btag("btag_csvivf"); } - else if ( config_->btagalgo_ == "deepcsv" ) { btag = jet.btag("btag_deepb") + jet.btag("btag_deepbb"); } - else if ( config_->btagalgo_ == "deepbvsall" ) { btag = jet.btag("btag_deepbvsall"); } - else { btag = -9999; } - - return btag; -} - -bool Analyser::selectionJet() -{ - bool isgood = true; - - // jet kinematics - std::map isOk; - for ( int j = 0; j < config_->nJetsMin() ; ++j ) - { - if ( ! selectionJet(j+1) ) return false; - } - return isgood; -} - -bool Analyser::selectionJet(const int & r) -{ - ++cutflow_; - - bool isgood = true; - int j = r-1; - - if ( selectedJets_.size() == 0 ) isgood = (isgood && selectionJetId()); - if ( !isgood || (int)selectedJets_.size() < r ) return false; - - // kinematic selection - if ( selectedJets_[j] -> pt() < config_->jetsPtMin()[j] && !(config_->jetsPtMin()[j] < 0) ) return false; - if ( fabs(selectedJets_[j] -> eta()) > config_->jetsEtaMax()[j] && !(config_->jetsEtaMax()[j] < 0) ) return false; - - if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: pt > %5.1f and |eta| < %3.1f",r,config_->jetsPtMin()[j], config_->jetsEtaMax()[j] )); - - h1_["cutflow"] -> Fill(cutflow_); - - return isgood; -} - - -bool Analyser::selectionJetDeta(const int & j1, const int & j2, const float & delta) -{ - ++cutflow_; - - if ( (int)selectedJets_.size() < j1 || (int)selectedJets_.size() < j2 ) + float weight = analysis_->genWeight(); + if ( ! config_->fullWeight() ) { - std::cout << "-errr- Analyser::selectionJetDeta(): you dont have enough selected jets. Will return false" << std::endl; - return false; - } - if ( delta > 0 ) - { - if ( fabs(selectedJets_[j1-1]->eta() - selectedJets_[j2-1]->eta()) > fabs(delta) ) return false; + float sign = (weight > 0) ? 1 : ((weight < 0) ? -1 : 0); + weight_ *= sign; } else { - if ( fabs(selectedJets_[j1-1]->eta() - selectedJets_[j2-1]->eta()) < fabs(delta) ) return false; - } - - if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) - { - if ( delta > 0 ) - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Deta(jet %d, jet %d) < %4.2f",j1,j2,fabs(delta))); - else - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Deta(jet %d, jet %d) > %4.2f",j1,j2,fabs(delta))); - } - - - h1_["cutflow"] -> Fill(cutflow_); - - return true; - -} -bool Analyser::selectionJetDeta(const int & j1, const int & j2) -{ - bool ok = true; - if (config_->detamax_ < 0 ) - { - ok = ok && true; - } - else - { - ok = ok && selectionJetDeta(j1,j2,config_->detamax_); - } - - if (config_->detamin_ < 0 ) - { - ok = ok && true; - } - else - { - ok = ok && selectionJetDeta(j1,j2,-1*config_->detamin_); - } - return ok; - -} - - -bool Analyser::selectionJetDr(const int & j1, const int & j2, const float & delta) -{ - ++cutflow_; - - if ( (int)selectedJets_.size() < j1 || (int)selectedJets_.size() < j2 ) - { - std::cout << "-e- Analyser::selectionJetDr(): at least one of the jets does not exist" << std::endl; - return false; - } - - if ( delta > 0 ) - { - if ( selectedJets_[j1-1]->deltaR(*selectedJets_[j2-1]) > fabs(delta) ) return false; - } - else - { - if ( selectedJets_[j1-1]->deltaR(*selectedJets_[j2-1]) < fabs(delta) ) return false; - } - - - if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) - { - if ( delta > 0 ) - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("DR(jet %d, jet %d) < %4.2f",j1,j2,fabs(delta))); - else - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("DR(jet %d, jet %d) > %4.2f",j1,j2,fabs(delta))); - } - - h1_["cutflow"] -> Fill(cutflow_); - - return true; - -} - -bool Analyser::selectionJetDr(const int & j1, const int & j2) -{ - bool ok = true; - if (config_->drmax_ < 0 ) - { - ok = ok && true; - } - else - { - ok = ok && selectionJetDr(j1,j2,config_->drmax_); - } - - if (config_->drmin_ < 0 ) - { - ok = ok && true; - } - else - { - ok = ok && selectionJetDr(j1,j2,-1*config_->drmin_); - } - return ok; -} - -bool Analyser::analysisWithJets() -{ - jets_.clear(); - selectedJets_.clear(); - if ( ! jetsanalysis_ ) return false; - - analysis_->match("Jets",config_->triggerObjectsJets_,0.3); - analysis_->match("Jets",config_->triggerObjectsBJets_,0.3); - - auto jets = analysis_->collection("Jets"); - for ( int j = 0 ; j < jets->size() ; ++j ) jets_.push_back(&jets->at(j)); - - selectedJets_ = jets_; - - return true; -} - -std::vector Analyser::jets() -{ - return jets_; -} - -bool Analyser::selectionJetId() -{ - ++cutflow_; - - if ( ! jetsanalysis_ ) return false; - - auto jet = std::begin(selectedJets_); - while ( jet != std::end(selectedJets_) ) - { - if ( ! (*jet)->id(config_->jetsId() ) ) - jet = selectedJets_.erase(jet); - else - ++jet; - } - if ( selectedJets_.size() == 0 ) return false; - - if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("JetId: %s",config_->jetsId().c_str())); - - h1_["cutflow"] -> Fill(cutflow_); - - return true; -} - -bool Analyser::selectionJetPileupId() -{ - ++cutflow_; - - if ( ! jetsanalysis_ ) return false; - - auto jet = std::begin(selectedJets_); - - while ( jet != std::end(selectedJets_) ) - { - if ( ! (*jet)->pileupJetIdFullId(config_->jetsPuId()) ) - jet = selectedJets_.erase(jet); - else - ++jet; + weight_ *= weight; } - if ( selectedJets_.size() == 0 ) return false; - - if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("JetPileupId: %s",config_->jetsPuId().c_str())); - - h1_["cutflow"] -> Fill(cutflow_); - - return true; - -} - -bool Analyser::selectionNJets() -{ - ++cutflow_; - - if ((int)selectedJets_.size() < config_->nJetsMin()) return false; - - if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("NJets >= %d",config_->nJetsMin())); - - h1_["cutflow"] -> Fill(cutflow_); - - return true; - -} - - - - -// bool Analyser::selectionJetId() -// { -// if ( ! jetsanalysis_ ) return false; -// -// for ( auto jet : selectedJets_ ) -// { -// if ( jet->id(config_->jetsId()) && jet->pileupJetIdFullId(config_->jetsPuId()) ) selectedJets_.push_back(jet); -// } -// if ( (int)selectedJets_.size() < config_->nJetsMin() ) return false; -// -// return true; -// } -// -std::vector Analyser::selectedMuons() -{ - return selectedMuons_; -} - - -bool Analyser::selectionBJet() -{ - bool isgood = true; - // jet btag - for ( int j = 0; j < config_->nbjetsmin_ ; ++j ) - { - if ( ! selectionBJet(j+1) ) return false; - } - return isgood; } -bool Analyser::selectionBJet(const int & r ) +bool Analyser::muonJet(const int & r) { int j = r-1; - if ( config_->jetsbtagmin_[j] < 0 ) return true; // there is not selection here, so will not update the cutflow - ++ cutflow_; - - if ( r > config_->nbjetsmin_ ) - { - std::cout << "* warning * - Analyser::selectionBJet(): given jet rank > nbjetsmin. Returning false! " << std::endl; - return false; - } - - // jet btag - if ( btag(*selectedJets_[j],config_->btagalgo_) < config_->jetsbtagmin_[j] ) return false; - if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: btag > %6.4f",r,config_->jetsbtagmin_[j])); - - h1_["cutflow"] -> Fill(cutflow_); - - return true; -} - -bool Analyser::selectionNonBJet(const int & r ) -{ - int j = r-1; - if ( config_->nonbtagwp_ < 0 || config_->jetsbtagmin_[j] < 0 ) return true; // there is not selection here, so will not update the cutflow - - ++ cutflow_; - - if ( r > config_->nbjetsmin_ ) { - std::cout << "* warning * - Analyser::selectionBJet(): given jet rank > nbjetsmin. Returning false! " << std::endl; - return false; + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: Jet-muon association",r)); } - // jet non btag - if ( btag(*selectedJets_[j],config_->btagalgo_) > config_->nonbtagwp_ ) return false; - - if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: btag < %6.4f",r,config_->nonbtagwp_)); + auto jet = selectedJets_[j]; + jet -> addMuon(selectedMuons_); - h1_["cutflow"] -> Fill(cutflow_); + if ( ! jet -> muon() ) return false; + h1_["cutflow"] -> Fill(cutflow_,weight_); return true; -} - -bool Analyser::selectionMuon() -{ - bool isgood = true; - - if ( config_->muonsCollection() != "" ) - { - } - return isgood; } -bool Analyser::onlineJetMatching() -{ - if ( config_->triggerObjectsJetsMatches_ < 0 ) return true; - - for ( int j = 0; j < config_->triggerObjectsJetsMatches_; ++j ) - { - if ( ! onlineJetMatching(j+1) ) return false; - } - - return true; -} - -bool Analyser::onlineBJetMatching() -{ - if ( config_->triggerObjectsBJetsMatches_ < 0 ) return true; - - for ( int j = 0; j < config_->triggerObjectsBJetsMatches_; ++j ) - { - if ( ! onlineBJetMatching(j+1) ) return false; - } - - return true; -} - - - -bool Analyser::onlineJetMatching(const int & r) -{ - int j = r-1; - if ( config_->triggerObjectsJets_.size() == 0 ) return true; - - ++cutflow_; - - if ( r > config_->nJetsMin() ) - { - std::cout << "*Warning* Analyser::onlineJetMatching(): asking for matching of unselected jet. Returning false!" << std::endl; - return false; // asking for a match beyond the selection, that's wrong, therefore false - } - if ( selectedJets_.size() == 0 ) - { - std::cout << "*Warning* Analyser::onlineJetMatching(): selectedJets is empty. Returning false!" << std::endl; - return false; // asking for a match beyond the selection, that's wrong, therefore false - } - - Jet * jet = selectedJets_[j]; - for ( size_t io = 0; io < config_->triggerObjectsJets_.size() ; ++io ) - { - if ( ! jet->matched(config_->triggerObjectsJets_[io]) ) return false; - } - - if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("JetTriggerMatch_%d",r)); - - h1_["cutflow"] -> Fill(cutflow_); - - return true; -} - - -bool Analyser::onlineBJetMatching(const int & r) -{ - int j = r-1; - if ( config_->triggerObjectsBJets_.size() == 0 ) return true; - - ++cutflow_; - - if ( r > config_->nJetsMin() ) - { - std::cout << "*Warning* Analyser::onlineBJetMatching(): asking for matching of unselected jet. Returning false!" << std::endl; - return false; // asking for a match beyond the selection, that's wrong, therefore false - } - if ( selectedJets_.size() == 0 ) - { - std::cout << "*Warning* Analyser::onlineBJetMatching(): selectedJets is empty. You must run selectionJetId() before. Returning false!" << std::endl; - return false; // asking for a match beyond the selection, that's wrong, therefore false - } - - Jet * jet = selectedJets_[j]; - for ( size_t io = 0; io < config_->triggerObjectsBJets_.size() ; ++io ) - { - if ( ! jet->matched(config_->triggerObjectsBJets_[io]) ) return false; - } - - if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("BTagTriggerMatch_%d",r)); - - - h1_["cutflow"] -> Fill(cutflow_); - - return true; -} - - - -bool Analyser::selectionTrigger() -{ - ++cutflow_; - if ( ! analysis_->triggerResult(config_->hltPath_) ) return false; - if ( ! analysis_->triggerResult(config_->l1Seed_) ) return false; - - if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,"Trigger"); - - h1_["cutflow"] -> Fill(cutflow_); - - return true; -} - -void Analyser::fillJetHistograms() -{ - int n = config_->nJetsMin(); - - for ( int j = 0; j < n; ++j ) - { - h1_[Form("pt_jet%d",j+1)] -> Fill(selectedJets_[j]->pt()); - h1_[Form("eta_jet%d",j+1)] -> Fill(selectedJets_[j]->eta()); - h1_[Form("btag_jet%d",j+1)] -> Fill(btag(*selectedJets_[j],config_->btagalgo_)); - for ( int k = j+1; k < n && j < n; ++k ) - { - float deltaR = selectedJets_[j]->deltaR(*selectedJets_[k]); - h1_[Form("dr_jet%d%d",j+1,k+1)] -> Fill(deltaR); - float deltaEta = fabs(selectedJets_[j]->eta() - selectedJets_[k]->eta()); - h1_[Form("deta_jet%d%d",j+1,k+1)] -> Fill(deltaEta); - float m = (selectedJets_[j]->p4()+selectedJets_[k]->p4()).M(); - if ( !config_->signalRegion() ) - { - h1_[Form("m_jet%d%d",j+1,k+1)] -> Fill(m); - } - } - } - - -} - -void Analyser::fillMuonHistograms() -{ - int n = config_->nMuonsMin(); - - for ( int j = 0; j < n; ++j ) - { - h1_[Form("pt_muon%d",j+1)] -> Fill(selectedMuons_[j]->pt()); - h1_[Form("eta_muon%d",j+1)] -> Fill(selectedMuons_[j]->eta()); - } - -} - - -TH1s Analyser::H1Fs() { return h1_; } - -TH1F * Analyser::H1F(const std::string & hname) -{ - if ( h1_.find(hname) == h1_.end() ) - { - std::cout << "-e- Analyser::H1F(const std::string & hname) -> no histogram with hname = " << hname << std::endl; - return nullptr; - } - - return h1_[hname]; -} - - -int Analyser::nEvents() -{ - int maxevt = config_->nEventsMax(); - if ( maxevt < 0 ) maxevt = analysis_->size(); - return maxevt; -} diff --git a/src/Analysis.cc b/src/Analysis.cc index cc171a2a..8c299741 100644 --- a/src/Analysis.cc +++ b/src/Analysis.cc @@ -172,7 +172,7 @@ void Analysis::treeInit_(const std::string & unique_name, const std::string & pa // =============== Method for Trigger Results================= // =========================================================== -void Analysis::triggerResults(const std::string & path) +bool Analysis::triggerResults(const std::string & path) { t_triggerResults_ = new TChain(path.c_str()); int ok = t_triggerResults_ -> AddFileInfoList(fileList_); @@ -180,7 +180,7 @@ void Analysis::triggerResults(const std::string & path) if ( ok == 0 ) { std::cout << "tree does not exist" << std::endl; - return; + return false; } TObjArray * triggerBranches = t_triggerResults_ -> GetListOfBranches(); for ( int i = 0 ; i < triggerBranches->GetEntries() ; ++i ) @@ -197,6 +197,7 @@ void Analysis::triggerResults(const std::string & path) t_triggerResults_ -> SetBranchAddress(branch.c_str(), &triggerResults_[branch]); } } + return true; } bool Analysis::triggerResult(const std::string & trig) @@ -504,6 +505,12 @@ std::shared_ptr Analysis::jetResolutionInfo(const std::string return jerinfo_; } +std::shared_ptr Analysis::pileupWeights(const std::string & f_pu) +{ + puweights_ = std::make_shared(PileupWeight(f_pu)); + return puweights_; +} + std::shared_ptr Analysis::btagCalibration(const std::string & tagger, const std::string & filename, const std::string & wp, diff --git a/src/BaseAnalyser.cc b/src/BaseAnalyser.cc new file mode 100644 index 00000000..03292ea9 --- /dev/null +++ b/src/BaseAnalyser.cc @@ -0,0 +1,313 @@ +/**\class BaseAnalyser BaseAnalyser.cc Analysis/Tools/src/BaseAnalyser.cc + + Description: A base class for analyser + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Roberval Walsh +// Created: 6 Sep 2018 +// +// + +// system include files +#include "boost/program_options.hpp" +#include "boost/algorithm/string.hpp" +#include +#include +#include +#include +// +// user include files +#include "Analysis/Tools/interface/BaseAnalyser.h" + +// +// class declaration +// + +using namespace analysis; +using namespace analysis::tools; + +// +// constructors and destructor +// +BaseAnalyser::BaseAnalyser() +{ +} + + +BaseAnalyser::BaseAnalyser(int argc, char * argv[]) +{ + exe_ = std::string(argv[0]); + + config_ = std::make_shared(argc,argv); + analysis_ = std::make_shared(config_->ntuplesList(),config_->eventInfo()); + + seed_ = analysis_ ->seed(config_->seedFile()); + + if ( config_->isMC() ) + { + analysis_ -> crossSections(config_->crossSectionTree()); + xsection_ = analysis_->crossSection(config_->crossSectionType()); + } + + weight_ = 1.; + + // Pileup weights + if ( config_->isMC() && config_->pileupWeights() != "" ) + { + puweights_ = analysis_->pileupWeights(config_->pileupWeights()); + } + + // JSON for data + if( !config_->isMC() && config_->json_ != "" ) analysis_->processJsonFile(config_->json_); + + // output file + if ( config_->outputRoot_ != "" ) + { + hout_= std::make_shared(config_->outputRoot_.c_str(),"recreate"); + hout_ -> cd(); + } + + genpartsanalysis_ = false; + if ( config_->isMC() ) genpartsanalysis_ = ( analysis_->addTree ("GenParticles",config_->genParticlesCollection()) != nullptr ); + + h1_["cutflow"] = std::make_shared("workflow",Form("Workflow #%d",config_->workflow()), 100,0,100); + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(1,"Total events read"); + if ( config_->isMC() ) + { + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(2)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(2,"Generated weighted events"); + } + +} + +BaseAnalyser::~BaseAnalyser() +{ + std::cout << std::endl; + // get last bin + int lastbin = 0; + for ( int i = 1; i <= h1_["cutflow"] ->GetNbinsX(); ++i ) + { + std::string label = std::string(h1_["cutflow"]->GetXaxis()->GetBinLabel(i)); + if ( label == "" ) + { + lastbin = i-1; + break; + } + } + float fevts = h1_["cutflow"] -> GetBinContent(lastbin); + // overall scale + float scale = 1.; + // scale to luminosity + if ( config_->isMC() && config_ -> luminosity() > 0. && config_ -> scale() < 0. ) + { + float nwevts = h1_["cutflow"] -> GetBinContent(2); + float genlumi = nwevts/xsection_; + scale = config_->luminosity()/genlumi; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(lastbin+1)) == "" ) + { + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(lastbin+1,Form("Number of events after scaling to luminosity = %8.3f/pb",config_->luminosity())); + } + h1_["cutflow"] -> Fill(lastbin,fevts*scale); + } + // scale from config + if ( config_ -> scale() > 0. ) + { + scale = config_ -> scale(); + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(lastbin+1)) == "" ) + { + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(lastbin+1,Form("Number of events after scaling to = %10.5f/pb",scale)); + } + h1_["cutflow"] -> Fill(lastbin,fevts*scale); + } + + for ( auto h : h1_ ) + { + if ( h.first == "cutflow" ) continue; + if ( h.first == "pileup" ) + { + h.second -> Scale(1./h.second->Integral()); + continue; + } + h.second -> Scale(scale); + } + cutflow(); + if ( hout_ ) + { + std::cout << std::endl; + std::cout << "output root file: " << config_->outputRoot_ << std::endl; + hout_ -> cd(); + hout_->Write(); +// hout_->Close(); + } + +// std::string cutflow = "Cutflow " + config_->outputRoot_; +// std::system(cutflow.c_str()); + + std::cout << exe_ << " finished!" << std::endl; + printf("%s\n", std::string(100,'_').c_str()); + std::cout << std::endl; +} + + +// +// member functions +// +// ------------ method called for each event ------------ + +bool BaseAnalyser::event(const int & i) { return true; } +void BaseAnalyser::histograms(const std::string & s, const int & i) { } + +std::shared_ptr BaseAnalyser::analysis() +{ + return analysis_; +} + +std::shared_ptr BaseAnalyser::config() +{ + return config_; +} + +int BaseAnalyser::nEvents() +{ + int maxevt = config_->nEventsMax(); + if ( maxevt < 0 ) maxevt = analysis_->size(); + return maxevt; +} + +std::shared_ptr BaseAnalyser::histogram(const std::string & hname) +{ + if ( h1_.find(hname) == h1_.end() ) + { + std::cout << "-e- BaseAnalyser::H1F(const string & hname) -> no histogram with hname = " << hname << std::endl; + return nullptr; + } + + return h1_[hname]; +} + +std::map > BaseAnalyser::histograms() +{ + return h1_; +} + + +void BaseAnalyser::cutflow() +{ + printf("+%s+\n", std::string(150,'-').c_str()); + printf("| %-88s | %10s | %16s | %16s |\n",h1_["cutflow"] -> GetTitle(),"n events","ratio wrt first","ratio wrt previous"); + printf("+%s+\n", std::string(150,'-').c_str()); + int firstbin = 2; + for ( int i = 1; i <= h1_["cutflow"] ->GetNbinsX(); ++i ) + { + std::string label = std::string(h1_["cutflow"]->GetXaxis()->GetBinLabel(i)); + if ( label == "" ) continue; +// if ( firstbin < 0 ) firstbin = i; + float n = h1_["cutflow"]->GetBinContent(i); + float rn1 = h1_["cutflow"]->GetBinContent(i)/h1_["cutflow"]->GetBinContent(firstbin); + float rni = 0; + if ( i == 1 ) + { + printf("| %-88s | %10.1f | %16s | %19s |\n",label.c_str(),n,"-","-"); + } + else if ( i == 2 ) + { + printf("| %2d - %-83s | %10.1f | %16.4f | %19s |\n",i-1,label.c_str(),n,rn1,"-"); + } + else + { + rni = h1_["cutflow"]-> GetBinContent(i)/h1_["cutflow"]->GetBinContent(i-1); + printf("| %2d - %-83s | %10.1f | %16.4f | %16.4f |\n",i-1,label.c_str(),n,rn1,rni); + } + + } + printf("+%s+\n", std::string(150,'-').c_str()); + +} + +int BaseAnalyser::seed() +{ + return seed_; +} + +int BaseAnalyser::seed(const std::string & f) +{ + seed_ = analysis_ ->seed(f); + return seed_; +} + +void BaseAnalyser::seed(const int & seed) +{ + seed_ = seed; +} + +void BaseAnalyser::weight(const float & w) +{ + weight_ = w; +} + +float BaseAnalyser::weight() +{ + return weight_; +} + +std::shared_ptr BaseAnalyser::output() +{ + return hout_; +} + +bool BaseAnalyser::genParticlesAnalysis() const +{ + return genpartsanalysis_; +} + +float BaseAnalyser::crossSection() const +{ + return xsection_; +} + +std::shared_ptr BaseAnalyser::pileupWeights() const +{ + return puweights_; +} + +float BaseAnalyser::pileupWeight(const float & truepu, const int & var) const +{ + if ( ! puweights_ ) return 1.; + return puweights_->weight(truepu,var); +} + +void BaseAnalyser::actionApplyPileupWeight(const int & var) +{ + if ( ! puweights_ ) return; + if ( ! config_->isMC() ) return; + + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,"*** Apply pileup weight"); + + weight_ *= this->pileupWeight(analysis_->nTruePileup(),var); + + h1_["cutflow"] -> Fill(cutflow_,weight_); +} + +void BaseAnalyser::pileupHistogram() +{ + this->output()->cd(); + h1_["pileup"] = std::make_shared("pileup" , "pileup" , config_->n() , config_->min() , config_->max() ); + +} +void BaseAnalyser::fillPileupHistogram() +{ + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,"*** Fill true pileup histrogram"); + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + h1_["pileup"] -> Fill(analysis_->nTruePileup()); +} + diff --git a/src/CMS_lumi.cc b/src/CMS_lumi.cc index 5705390f..9a69de3c 100644 --- a/src/CMS_lumi.cc +++ b/src/CMS_lumi.cc @@ -2,8 +2,10 @@ //#include "TASImage.h" void -CMS_lumi( TPad* pad, int iPeriod, int iPosX ) +CMS_lumi( TPad* pad, TString mytxt , int iPeriod, int iPosX ) { + writeExtraText = true; + extraText = mytxt; bool outOfFrame = false; if( iPosX/10==0 ) { @@ -153,7 +155,8 @@ CMS_lumi( TPad* pad, int iPeriod, int iPosX ) latex.SetTextFont(extraTextFont); latex.SetTextSize(extraTextSize*t); latex.SetTextAlign(align_); - latex.DrawLatex(posX_, posY_+0.7, extraText); +// latex.DrawLatex(posX_, posY_+0.7, extraText); + latex.DrawLatex(posX_, posY_, extraText); } return; } diff --git a/src/Config.cc b/src/Config.cc index f6f6b7ff..edf34e5a 100644 --- a/src/Config.cc +++ b/src/Config.cc @@ -39,6 +39,7 @@ Config::Config() // Main constructor Config::Config(int argc, char ** argv) : opt_cmd_("Options"), opt_cfg_("Configuration") { + std::string datapath = Form("%s/src/Analysis/Tools/data",getenv("CMSSW_BASE")); argc_ = argc; argv_ = argv; // read configuration options @@ -52,7 +53,12 @@ Config::Config(int argc, char ** argv) : opt_cmd_("Options"), opt_cfg_("Configur // analysis info opt_cfg_.add_options() ("ntuplesList",po::value (&inputlist_)->default_value("rootFileList.txt"),"File with list of ntuples") - ("collectionsTreePath",po::value (&treePath_)->default_value("Events"),"Name of the tree path for the event collections.") + ("eventInfo",po::value (&eventinfo_)->default_value("MssmHbb/Events/EventInfo"),"EventInfo directory in the tree") + ("crossSectionTree",po::value (&xsectiontree_)->default_value("MssmHbb/Metadata/CrossSections"),"Tree containing cross sections") + ("crossSectionType",po::value (&xsectiontype_)->default_value("crossSection"),"Type of cross section") + ("scale",po::value (&scale_)->default_value(-1.), "Overall scale for histograms") + ("luminosity",po::value (&lumi_)->default_value(-1.), "Luminosity in pb-1 to scale histograms") + ("collectionsTreePath",po::value (&treePath_)->default_value("Events"),"Name of the tree path for the event collections") ("nEventsMax",po::value (&nevtmax_)->default_value(-1), "Maximum number of events") ("nLumiSections",po::value (&nlumis_)->default_value(-1), "Number of lumi sections processed") ("runMin",po::value (&runmin_)->default_value(-1), "Minimum run number") @@ -60,10 +66,28 @@ Config::Config(int argc, char ** argv) : opt_cmd_("Options"), opt_cfg_("Configur ("output",po::value (&outputRoot_)->default_value("histograms.root"),"Output root file") ("json",po::value (&json_)->default_value("no_json.txt"),"JSON file for data") ("isMC",po::value (&isMC_)->default_value(true),"Flag for MC dataset") - ("signalRegion",po::value (&signalregion_)->default_value(true),"Flag for signal region"); + ("pythia8",po::value (&pythia8_)->default_value(true),"Flag for Pythia8 or other recent generators MC") + ("nlo",po::value (&nlo_)->default_value(false),"Flag for NLO samples") + ("fullWeight",po::value (&fullweight_)->default_value(false),"Flag for full weight of MC samples") + ("workflow",po::value (&workflow_)->default_value(1),"Workflow index defined by user") + ("blind",po::value (&blind_)->default_value(true),"Flag for blind analysis") + ("signalRegion",po::value (&signalregion_)->default_value(true),"Flag for signal region") + ("eraLumi", po::value >(&eralumi_)->multitoken(),"Lumi of an era") + ("era", po::value >(&era_)->multitoken(),"Era of data taking") + ("pileupWeights",po::value (&puweight_)->default_value(""),"Root file containing pileup weights") + ("seed",po::value (&seed_)->default_value(-1), "Seed value for random numbers") + ("seedFile",po::value (&seedfile_)->default_value("no_seed.txt"),"File with seed value for random numbers"); + // generic options + opt_cfg_.add_options() + ("prescale",po::value (&prescale_)->default_value(1), "Prescale factor") + ("n",po::value (&n_)->default_value(-1), "Some integer") + ("min",po::value (&min_)->default_value(-1.), "some minimum value") + ("max",po::value (&max_)->default_value(-1.), "some maximum value"); + // analysis control opt_cfg_.add_options() + ("doTree",po::value (&do_tree_)->default_value(false),"Flag for output") ("override",po::value (&override_)->default_value(true),"Flag to be used to override procedure, e.g. a selection"); // jets @@ -73,23 +97,40 @@ Config::Config(int argc, char ** argv) : opt_cmd_("Options"), opt_cfg_("Configur ("nJetsMax",po::value (&njetsmax_)->default_value(-1),"Maximum number of jets") ("jetsPtMin", po::value >(&jetsptmin_)->multitoken(),"Mimium pt of the jets") ("jetsPtMax", po::value >(&jetsptmax_)->multitoken(),"Maximum pt of the jets") + ("qgMin", po::value >(&qgmin_)->multitoken(),"Minimum value for q-g likelihood") + ("qgMax", po::value >(&qgmax_)->multitoken(),"Maximum value for q-g likelihood") ("jetsEtaMax", po::value >(&jetsetamax_)->multitoken(),"Maximum |eta| of the jets") ("jetsBtagMin", po::value >(&jetsbtagmin_)->multitoken(),"Minimum btag of the jets; if < 0 -> reverse btag") + ("jetsBtagProbB", po::value >(&jetsbtagprobb_)->multitoken(),"Maximum (minimum) btag prob b of the jets if >0 (<0)") + ("jetsBtagProbBB", po::value >(&jetsbtagprobbb_)->multitoken(),"Maximum (minimum) btag prob bb of the jets if >0 (<0)") + ("jetsBtagProbLepB", po::value >(&jetsbtagproblepb_)->multitoken(),"Maximum (minimum) btag prob lepb of the jets if >0 (<0)") + ("jetsBtagProbC", po::value >(&jetsbtagprobc_)->multitoken(),"Maximum (minimum) btag prob c of the jets if >0 (<0)") + ("jetsBtagProbG", po::value >(&jetsbtagprobg_)->multitoken(),"Maximum (minimum) btag prob g of the jets if >0 (<0)") + ("jetsBtagProbLight", po::value >(&jetsbtagproblight_)->multitoken(),"Maximum (minimum) btag prob light of the jets if >0 (<0)") + ("jetsBtagWP", po::value >(&jetsbtagwp_)->multitoken(),"Jets btag working point") ("jetsId",po::value (&jetsid_)->default_value("tight"),"Jets id criteria for all jets") ("jetsPuId",po::value (&jetspuid_)->default_value("loose"),"Jets pileup id criteria for all jets") + ("jerPtRes",po::value (&jerptres_)->default_value(""),"JER pT resolution file") + ("jerSF",po::value (&jersf_)->default_value(""),"JER SF file") + ("bRegression",po::value (&bregression_)->default_value(false),"Apply b jet energy regression") + ("doDijet",po::value (&dodijet_)->default_value(false),"Combine jets in dijet objects") + ("doDijetFlavour",po::value (&dodijet_flavour_)->default_value(false),"Combine jets in dijet objects split by flavour combination") + ("useJetsFlavour",po::value (&usejetsflv_)->default_value(false),"For splitting results accoding to jet flavour") + ("useJetsExtendedFlavour",po::value (&usejetsextflv_)->default_value(false),"For splitting results accoding to jet extended flavour") ("l1tJetsCollection",po::value (&l1tjetsCol_)->default_value("l1tJets"),"Name of the L1T jets collection"); // btagging opt_cfg_.add_options() ("nBJetsMin",po::value (&nbjetsmin_)->default_value(0),"Minimum number of btgaged jets") - ("btagSF",po::value (&btagsf_)->default_value("DeepCSV.csv"),"b-tagging scale factor in CSV format") + ("btagSF",po::value (&btagsf_)->default_value(""),"b-tagging scale factor in CSV format") ("btagAlgorithm",po::value (&btagalgo_)->default_value("csvivf"),"BTag algorithm") ("btagWorkingPoint",po::value (&btagwp_)->default_value("tight"),"BTag working point") - ("btagWPLoose",po::value (&btagwploose_)->default_value(0.46),"BTag working point LOOSE") - ("btagWPMedium",po::value (&btagwpmedium_)->default_value(0.84),"BTag working point MEDIUM") - ("btagWPTight",po::value (&btagwptight_)->default_value(0.92),"BTag working point TIGHT") - ("nonbtagWP",po::value (&nonbtagwp_)->default_value(0.46),"non-Btag working point") - ("nonbtagJet",po::value (&nonbtagjet_)->default_value(-1),"non-Btag Jet"); + ("btagLoose",po::value (&btagwploose_)->default_value(0.46),"BTag working point LOOSE") + ("btagMedium",po::value (&btagwpmedium_)->default_value(0.84),"BTag working point MEDIUM") + ("btagTight",po::value (&btagwptight_)->default_value(0.92),"BTag working point TIGHT") + ("btagXXX",po::value (&btagwpxxx_)->default_value(0.92),"BTag undefined working point XXX") + ("nonBtagWP",po::value (&nonbtagwp_)->default_value(""),"non-Btag working point") + ("nonBtagJet",po::value (&nonbtagjet_)->default_value(-1),"non-Btag Jet"); // muons opt_cfg_.add_options() @@ -111,22 +152,26 @@ Config::Config(int argc, char ** argv) : opt_cmd_("Options"), opt_cfg_("Configur ("triggerObjectsMatches", po::value >(&triggerObjectsMatches_)->multitoken(),"Number of trigger objects matches") ("triggerObjectsMatchesRank", po::value >(&triggerObjectsMatchesRank_)->multitoken(),"Rank of offline object the trigger objects matches") ("triggerObjectsJets", po::value >(&triggerObjectsJets_)->multitoken(),"Trigger objects for b jets") - ("triggerObjectsBJets", po::value >(&triggerObjectsBJets_)->multitoken(),"Trigger objects for btag jets") - ("triggerObjectsL1Jets", po::value >(&triggerObjectsL1Jets_)->multitoken(),"Trigger objects for L1 jets") + ("triggerObjectsBJets" , po::value (&triggerObjectsBJets_) ->default_value(""),"Trigger objects for btag jets") + ("triggerObjectsL1Jets" , po::value (&triggerObjectsL1Jets_) ->default_value(""),"Trigger objects for L1 jets") + ("triggerObjectsCaloJets" , po::value (&triggerObjectsCaloJets_)->default_value(""),"Trigger objects for Calo jets") + ("triggerObjectsPFJets" , po::value (&triggerObjectsPFJets_) ->default_value(""),"Trigger objects for PF jets") ("triggerObjectsJetsMatches", po::value (&triggerObjectsJetsMatches_)->default_value(-1),"Number of matches with trigger objects for jets") ("triggerObjectsBJetsMatches", po::value (&triggerObjectsBJetsMatches_)->default_value(-1),"Number of matches with trigger objects for b jets") ("triggerObjectsL1JetsMatches", po::value (&triggerObjectsL1JetsMatches_)->default_value(-1),"Number of matches with L1 trigger objects jets") ("triggerObjectsMuons", po::value >(&triggerObjectsMuons_)->multitoken(),"Trigger objects for muons") - ("triggerObjectsL1Muons", po::value >(&triggerObjectsL1Muons_)->multitoken(),"Trigger objects for L1 muons") + ("triggerObjectsL1Muons", po::value (&triggerObjectsL1Muons_)->default_value(""),"Trigger objects for L1 muons") + ("triggerObjectsL3Muons", po::value (&triggerObjectsL3Muons_)->default_value(""),"Trigger objects for L3 muons") ("triggerObjectsMuonsMatches", po::value (&triggerObjectsMuonsMatches_)->default_value(-1),"Number of matches with trigger objects for muons") ("triggerObjectsL1MuonsMatches", po::value (&triggerObjectsL1MuonsMatches_)->default_value(-1),"Number of matches with L1 trigger objects for muons") + ("triggerObjectsL3MuonsMatches", po::value (&triggerObjectsL3MuonsMatches_)->default_value(-1),"Number of matches with L3 trigger objects for muons") ("triggerMatchDeltaRMax",po::value (&trgmatchdrmax_)->default_value(0.3),"DeltaR max for matching online-offline") ("triggerResultsCollection",po::value (&triggerCol_)->default_value(""),"Name of the trigger results collection") ("triggerObjectsDirectory",po::value (&triggerObjDir_)->default_value("slimmedPatTrigger"),"Name of the trigger objects directory"); // generator level opt_cfg_.add_options() - ("genParticleCollection",po::value (&genParticleCol_)->default_value(""),"Name of the gen particle collection") + ("genparticlesCollection",po::value (&genpartsCol_)->default_value(""),"Name of the gen particle collection") ("genjetsCollection",po::value (&genjetsCol_)->default_value(""),"Name of the gen jets collection"); @@ -142,8 +187,26 @@ Config::Config(int argc, char ** argv) : opt_cmd_("Options"), opt_cfg_("Configur ("dEtaMax",po::value (&detamax_)->default_value(-1.),"Maximum delta eta between candidates") ("dEtaMin",po::value (&detamin_)->default_value(-1.),"Minimum delta eta between candidates") ("dPhiMin",po::value (&dphimin_)->default_value(-1.),"Minimum delta phi between candidates") - ("ptImbalanceMax",po::value (&ptimbalmax_)->default_value(1000.),"Maximum relative imbalance between two candidates"); + ("dPhiMax",po::value (&dphimax_)->default_value(-1.),"Maximum delta phi between candidates") + ("ptImbalanceMin",po::value (&ptimbalmin_)->default_value(-1),"Minimum relative imbalance between two candidates") + ("ptImbalanceMax",po::value (&ptimbalmax_)->default_value(-1),"Maximum relative imbalance between two candidates"); + + // general + opt_cfg_.add_options() + ("massMin",po::value (&massmin_)->default_value(-1.),"Cut on a mass, min value") + ("massMax",po::value (&massmax_)->default_value(-1.),"Cut on a mass, max value"); + + // AI + opt_cfg_.add_options() + ("variablesFloatAI", po::value >(&varsf_ai_)->multitoken(),"Float variables names for AI(TMVA)") + ("variablesIntAI", po::value >(&varsi_ai_)->multitoken(),"Integer variables names for AI(TMVA)") + ("directoryAI",po::value (&dir_ai_)->default_value(""),"Directory with weights for AI(TMVA)") + ("methodAI",po::value (&method_ai_)->default_value(""),"Method AI(TMVA)") + ("efficiencyMinAI",po::value (&eff_min_ai_)->default_value(-1.),"Min value for AI Cuts efficiency") + ("discriminatorMaxAI",po::value (&disc_max_ai_)->default_value(-1001.),"Max value for AI discriminator") + ("discriminatorMinAI",po::value (&disc_min_ai_)->default_value(-1001.),"Min value for AI discriminator"); + po::variables_map vm; try { @@ -168,7 +231,10 @@ Config::Config(int argc, char ** argv) : opt_cmd_("Options"), opt_cfg_("Configur boost::algorithm::to_lower(jetsid_); std::transform(btagalgo_.begin(), btagalgo_.end(), btagalgo_.begin(), ::tolower); std::transform(btagwp_.begin(), btagwp_.end(), btagwp_.begin(), ::tolower); - + if ( jerptres_ != "" ) jerptres_ = Form("%s/%s", datapath.c_str(), jerptres_.c_str()); + if ( jersf_ != "" ) jersf_ = Form("%s/%s", datapath.c_str(), jersf_.c_str() ); + if ( btagsf_ != "" ) btagsf_ = Form("%s/%s", datapath.c_str(), btagsf_.c_str() ); + if ( puweight_ != "" ) puweight_ = Form("%s/%s", datapath.c_str(), puweight_.c_str()); } catch(po::error& e) @@ -223,24 +289,52 @@ void Config::loadOptions() } // analysis info -std::string Config::ntuplesList() const { return inputlist_; } -int Config::nEventsMax() const { return nevtmax_; } -bool Config::isMC() const { return isMC_; } -bool Config::signalRegion() const { return signalregion_; } +std::string Config::ntuplesList() const { return inputlist_; } +std::string Config::eventInfo() const { return eventinfo_; } +std::string Config::crossSectionTree() const { return xsectiontree_; } +std::string Config::crossSectionType() const { return xsectiontype_; } +float Config::luminosity() const { return lumi_; } +int Config::nEventsMax() const { return nevtmax_; } +bool Config::isMC() const { return isMC_; } +bool Config::signalRegion() const { return signalregion_; } +bool Config::blind() const { return blind_; } +bool Config::nlo() const { return nlo_; } +bool Config::fullWeight() const { return fullweight_; } +int Config::workflow() const { return workflow_; } +float Config::scale() const { return scale_; } +std::vector Config::eraLumi() const { return eralumi_; } +std::vector Config::era() const { return era_; } +std::string Config::pileupWeights() const { return puweight_; } // analysis control -bool Config::override() const { return override_; } +bool Config::override() const { return override_; } // jets -std::string Config::jetsCollection() const { return jetsCol_; } -int Config::nJetsMin() const { return njetsmin_; } -int Config::nJetsMax() const { return njetsmax_; } -std::vector Config::jetsPtMin() const { return jetsptmin_; } -std::vector Config::jetsPtMax() const { return jetsptmax_; } -std::vector Config::jetsEtaMax() const { return jetsetamax_; } -std::string Config::jetsId() const { return jetsid_; } -std::string Config::jetsPuId() const { return jetspuid_; } -std::string Config::l1tJetsCollection() const { return l1tjetsCol_; } +std::string Config::jetsCollection() const { return jetsCol_; } +int Config::nJetsMin() const { return njetsmin_; } +int Config::nJetsMax() const { return njetsmax_; } +std::vector Config::jetsPtMin() const { return jetsptmin_; } +std::vector Config::jetsPtMax() const { return jetsptmax_; } +std::vector Config::jetsEtaMax() const { return jetsetamax_; } +std::string Config::jetsId() const { return jetsid_; } +std::string Config::jetsPuId() const { return jetspuid_; } +std::string Config::jerPtRes() const { return jerptres_; } +std::string Config::jerSF() const { return jersf_; } +std::string Config::l1tJetsCollection() const { return l1tjetsCol_; } +std::vector Config::jetsBtagWP() const { return jetsbtagwp_; } +std::vector Config::jetsBtagProbB() const { return jetsbtagprobb_; } +std::vector Config::jetsBtagProbBB() const { return jetsbtagprobbb_; } +std::vector Config::jetsBtagProbLepB() const { return jetsbtagproblepb_; } +std::vector Config::jetsBtagProbC() const { return jetsbtagprobc_; } +std::vector Config::jetsBtagProbG() const { return jetsbtagprobg_; } +std::vector Config::jetsBtagProbLight() const { return jetsbtagproblight_; } +bool Config::bRegression() const { return bregression_; } +std::string Config::nonBtagWP() const { return nonbtagwp_; } +int Config::nonBtagJet() const { return nonbtagjet_; } +bool Config::useJetsFlavour() const { return usejetsflv_; } +bool Config::useJetsExtendedFlavour() const { return usejetsextflv_; } +bool Config::doDijet() const { return dodijet_; } +bool Config::doDijetFlavour() const { return dodijet_flavour_; } // muons std::string Config::muonsCollection() const { return muonsCol_; } @@ -253,5 +347,67 @@ std::string Config::muonsId() const { return muonsid_; } std::string Config::l1tMuonsCollection() const { return l1tmuonsCol_; } // trigger -std::string Config::triggerResults() const { return triggerCol_; } +std::string Config::triggerResults() const { return triggerCol_; } +std::string Config::triggerObjectsDir() const { return triggerObjDir_; } +std::string Config::triggerObjectsL1Muons() const { return triggerObjectsL1Muons_; } +std::string Config::triggerObjectsL3Muons() const { return triggerObjectsL3Muons_; } +std::string Config::triggerObjectsBJets() const { return triggerObjectsBJets_; } +std::string Config::triggerObjectsL1Jets() const { return triggerObjectsL1Jets_; } +std::string Config::triggerObjectsCaloJets() const { return triggerObjectsCaloJets_; } +std::string Config::triggerObjectsPFJets() const { return triggerObjectsPFJets_; } +// generator level +std::string Config::genJetsCollection() const { return genjetsCol_; } +std::string Config::genParticlesCollection() const { return genpartsCol_; } + +// seed +std::string Config::seedFile() const { return seedfile_; } +int Config::seed() const { return seed_; } + +bool Config::pythia8() const { return pythia8_; } + +// btag +float Config::btagWP(const std::string & wp) const +{ + if ( wp == "loose" ) return btagwploose_ ; + if ( wp == "medium" ) return btagwpmedium_; + if ( wp == "tight" ) return btagwptight_ ; + if ( wp == "xxx" ) return btagwpxxx_; + + return -100.; +} + +std::vector Config::triggerObjectsJets() const +{ + return triggerObjectsJets_; +} +void Config::triggerObjectsJets(const std::string & label, const int & index) +{ + triggerObjectsJets_.at(index) = label; +} +// General stuff +float Config::massMin() const { return massmin_; } +float Config::massMax() const { return massmax_; } + + +// AI +std::vector Config::variablesAI(const std::string & t) const +{ + if ( t == "I" ) return varsi_ai_; + return varsf_ai_; +} +std::string Config::directoryAI() const { return dir_ai_ ; } +std::string Config::methodAI() const { return method_ai_ ; } +float Config::discriminatorMaxAI() const { return disc_max_ai_; } +float Config::discriminatorMinAI() const { return disc_min_ai_; } +float Config::efficiencyMinAI() const { return eff_min_ai_ ; } + +// output tree +bool Config::doTree() const { return do_tree_; +} + +// generic options +int Config::prescale() const { return prescale_; } +int Config::n() const { return n_; } +float Config::min() const { return min_; } +float Config::max() const { return max_; } diff --git a/src/Jet.cc b/src/Jet.cc index 5a663dc0..5e473672 100644 --- a/src/Jet.cc +++ b/src/Jet.cc @@ -166,9 +166,13 @@ void Jet::jerCorrections() if ( jermatch_ ) { - c += (sf-1)*((this->pt() - genjet_->pt())/this->pt()); - cup += (sfup-1)*((this->pt() - genjet_->pt())/this->pt()); - cdown += (sfdown-1)*((this->pt() - genjet_->pt())/this->pt()); +// c += (sf-1)*((this->pt() - genjet_->pt())/this->pt()); +// cup += (sfup-1)*((this->pt() - genjet_->pt())/this->pt()); +// cdown += (sfdown-1)*((this->pt() - genjet_->pt())/this->pt()); + // to avoid problems with regression corrections, use "uncorrected" + c += (sf-1)*((this->pt() - genjet_->pt())/uncorrJetp4_.Pt()); + cup += (sfup-1)*((this->pt() - genjet_->pt())/uncorrJetp4_.Pt()); + cdown += (sfdown-1)*((this->pt() - genjet_->pt())/uncorrJetp4_.Pt()); } else { @@ -219,6 +223,16 @@ void Jet::jerInfo(const JetResolutionInfo & jerinfo, const float & drmin) jerCorrections(); } +void Jet::applyJER(const JetResolutionInfo & jerinfo, const float & drmin) +{ + this -> jerInfo(jerinfo,drmin); + float pt = p4_.Pt()*this->jerCorrection(); + float eta = p4_.Eta(); + float phi = p4_.Phi(); + float e = p4_.E(); + p4_.SetPtEtaPhiE(pt,eta,phi,e); +} + // @@ -238,6 +252,18 @@ int Jet::pileupJetIdFullId() const { return puJetIdFullId_ float Jet::bRegCorr() const { return bRegCorr_; } float Jet::bRegRes() const { return bRegRes_; } +void Jet::applyBjetRegression() +{ + float pt = p4_.Pt()*this->bRegCorr(); + float eta = p4_.Eta(); + float phi = p4_.Phi(); + float e = p4_.E(); + p4_.SetPtEtaPhiE(pt,eta,phi,e); +} + + + + double Jet::rho() const { return rho_; } @@ -283,9 +309,14 @@ double Jet::btagSFsys(std::shared_ptr reader, const std:: if ( reader == nullptr ) return sf; - if ( this->flavour(flavalgo) == 5 ) sf = reader->eval_auto_bounds(systype, BTagEntry::FLAV_B, fabs(this->eta()), this->pt() ); - if ( this->flavour(flavalgo) == 4 ) sf = reader->eval_auto_bounds(systype, BTagEntry::FLAV_C, fabs(this->eta()), this->pt() ); - if ( this->flavour(flavalgo) == 0 ) sf = reader->eval_auto_bounds(systype, BTagEntry::FLAV_UDSG, fabs(this->eta()), this->pt() ); +// if ( this->flavour(flavalgo) == 5 ) sf = reader->eval_auto_bounds(systype, BTagEntry::FLAV_B, fabs(this->eta()), this->pt() ); +// if ( this->flavour(flavalgo) == 4 ) sf = reader->eval_auto_bounds(systype, BTagEntry::FLAV_C, fabs(this->eta()), this->pt() ); +// if ( this->flavour(flavalgo) == 0 ) sf = reader->eval_auto_bounds(systype, BTagEntry::FLAV_UDSG, fabs(this->eta()), this->pt() ); + +// to avoid problems with other corrections + if ( this->flavour(flavalgo) == 5 ) sf = reader->eval_auto_bounds(systype, BTagEntry::FLAV_B, fabs(uncorrJetp4_.Eta()), uncorrJetp4_.Pt() ); + if ( this->flavour(flavalgo) == 4 ) sf = reader->eval_auto_bounds(systype, BTagEntry::FLAV_C, fabs(uncorrJetp4_.Eta()), uncorrJetp4_.Pt() ); + if ( this->flavour(flavalgo) == 0 ) sf = reader->eval_auto_bounds(systype, BTagEntry::FLAV_UDSG, fabs(uncorrJetp4_.Eta()), uncorrJetp4_.Pt() ); return sf; } @@ -431,6 +462,20 @@ void Jet::addMuon(const std::shared_ptr m) muon_ = m; } +void Jet::addMuon(std::vector< std::shared_ptr > muons, const float & dr) +{ + if ( muons.size() == 0 ) return; + + for ( auto m : muons ) + { + if ( this->deltaR((*m)) < dr ) + { + addMuon(m); + return; + } + } +} + void Jet::rmMuon() { muon_ = nullptr; diff --git a/src/JetAnalyser.cc b/src/JetAnalyser.cc new file mode 100644 index 00000000..a1bb5660 --- /dev/null +++ b/src/JetAnalyser.cc @@ -0,0 +1,1388 @@ +/**\class JetAnalyser JetAnalyser.cc Analysis/Tools/src/JetAnalyser.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Roberval Walsh Bastos Rangel +// Created: Mon, 20 Oct 2014 14:24:08 GMT +// +// + +// system include files +#include "boost/program_options.hpp" +#include "boost/algorithm/string.hpp" +#include +#include +#include +#include +// +// user include files +#include "Analysis/Tools/interface/Composite.h" +#include "Analysis/Tools/interface/JetAnalyser.h" + +// +// class declaration +// + +using namespace analysis; +using namespace analysis::tools; + +JetAnalyser::JetAnalyser() +{ +} + + +JetAnalyser::JetAnalyser(int argc, char * argv[]) : BaseAnalyser(argc,argv) +{ + // Physics objects + // Jets + jetsanalysis_ = ( analysis_->addTree ("Jets",config_->jetsCollection()) != nullptr ); + + genjetsanalysis_ = false; // should I move to BaseAnalyser??? + if ( config_->isMC() ) genjetsanalysis_ = ( analysis_->addTree ("GenJets",config_->genJetsCollection()) != nullptr ); + + applyjer_ = false; + + if ( config_->btagsf_ != "" ) + { + bsf_reader_["loose"] = analysis_->btagCalibration(config_->btagalgo_, config_->btagsf_, "loose"); + bsf_reader_["medium"] = analysis_->btagCalibration(config_->btagalgo_, config_->btagsf_, "medium"); + bsf_reader_["tight"] = analysis_->btagCalibration(config_->btagalgo_, config_->btagsf_, "tight"); + } + + if ( config_->jerPtRes() != "" && config_->jerSF() != "" && genjetsanalysis_ ) // FIXME: check if files exist + { + jerinfo_ = analysis_->jetResolutionInfo(config_->jerPtRes(),config_->jerSF()); + applyjer_ = ( jerinfo_ != nullptr ); + } + + if ( config_->isMC() ) + { + flavours_ = {"udsg","c","b"}; + if ( config_->useJetsExtendedFlavour() ) + { + flavours_.push_back("cc"); + flavours_.push_back("bb"); + } + } +// histograms("jet",config_->nJetsMin()); + +} + +JetAnalyser::~JetAnalyser() +{ + // do anything here that needs to be done at desctruction time + // (e.g. close files, deallocate resources etc.) +} + + +// +// member functions +// +// ------------ method called for each event ------------ + +bool JetAnalyser::analysisWithJets() +{ + jets_.clear(); + selectedJets_.clear(); + if ( ! jetsanalysis_ ) return false; + + analysis_->match("Jets",config_->triggerObjectsL1Jets(),0.3); + analysis_->match("Jets",config_->triggerObjectsCaloJets(),0.3); + analysis_->match("Jets",config_->triggerObjectsPFJets(),0.3); + analysis_->match("Jets",config_->triggerObjectsBJets(),0.3); + + // std::shared_ptr< Collection > + auto jets = analysis_->collection("Jets"); + + if ( this->genParticlesAnalysis() && config_ -> useJetsExtendedFlavour() ) + { + auto particles = analysis_->collection("GenParticles"); + jets->associatePartons(particles,0.4,1.,config_->pythia8()); + } + + if ( genjetsanalysis_ ) + { + auto genjets = analysis_->collection("GenJets"); + jets->addGenJets(genjets); + } + + for ( int j = 0 ; j < jets->size() ; ++j ) jets_.push_back(std::make_shared(jets->at(j))); + + selectedJets_ = jets_; + + return true; +} + + +void JetAnalyser::jets(const std::string & col) +{ + analysis_->addTree ("Jets",col); +} + +void JetAnalyser::jetHistograms( const int & n, const std::string & label ) +{ + this->output()->cd(); + this->output()->mkdir(label.c_str()); + this->output()->cd(label.c_str()); + + n_hjets_ = n; + + h1_[Form("jet_hist_weight_%s",label.c_str())] = std::make_shared(Form("jet_hist_weight_%s",label.c_str()) , Form("jet_hist_weight_%s",label.c_str()) ,1 , 0. , 1. ); + + // btag variable binning + float min1 = 0.0; + float max1 = 0.1; + float size1 = 0.0001; + int nbins1 = int((max1-min1)/size1); + float min2 = 0.1; + float max2 = 0.9; + float size2 = 0.001; + int nbins2 = int((max2-min2)/size2); + float min3 = 0.9; + float max3 = 1.0; + float size3 = 0.0001; + int nbins3 = int((max3-min3)/size3); + int nbins_btag = nbins1+nbins2+nbins3; + + std::vector bins_btag; + bins_btag.clear(); + int counter = 0; + for ( int i = 0; i(Form("pt_jet%d" , j+1) , Form("pt_jet%d_%s" , j+1,label.c_str()) ,1500 , 0 , 1500 ); + h1_[Form("eta_jet%d_%s" , j+1,label.c_str())] = std::make_shared(Form("eta_jet%d" , j+1) , Form("eta_jet%d_%s" , j+1,label.c_str()) , 600 , -3, 3 ); + h1_[Form("phi_jet%d_%s" , j+1,label.c_str())] = std::make_shared(Form("phi_jet%d" , j+1) , Form("phi_jet%d_%s" , j+1,label.c_str()) , 360 , -180, 180 ); + h1_[Form("btag_jet%d_%s", j+1,label.c_str())] = std::make_shared(Form("btag_jet%d", j+1) , Form("btag_jet%d_%s", j+1,label.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btaglog_jet%d_%s", j+1,label.c_str())] = std::make_shared(Form("btaglog_jet%d", j+1) , Form("btaglog_jet%d_%s", j+1,label.c_str()) , 200 , 1.e-6, 10 ); + h1_[Form("qglikelihood_jet%d_%s", j+1,label.c_str())] = std::make_shared(Form("qglikelihood_jet%d", j+1) , Form("qglikelihood_jet%d_%s", j+1,label.c_str()) , 200 , 0, 1 ); + h1_[Form("nconstituents_jet%d_%s", j+1,label.c_str())] = std::make_shared(Form("nconstituents_jet%d", j+1) , Form("nconstituents_jet%d_%s", j+1,label.c_str()) , 200 , 0, 200 ); + + h1_[Form("pt_jet%d_%s" , j+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d p_{T} [GeV]",j+1)); + h1_[Form("eta_jet%d_%s" , j+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d #eta",j+1)); + h1_[Form("phi_jet%d_%s" , j+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d #phi",j+1)); + h1_[Form("btag_jet%d_%s", j+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d btag discriminator",j+1)); + h1_[Form("btaglog_jet%d_%s", j+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d -ln(1-btag discriminator)",j+1)); + h1_[Form("qglikelihood_jet%d_%s", j+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d q-g likelihood",j+1)); + h1_[Form("nconstituents_jet%d_%s", j+1,label.c_str())]-> GetXaxis() -> SetTitle(Form("Jet %d n constituents",j+1)); + + if ( config_->btagalgo_ == "deepcsv") + { + h1_[Form("btag_light_jet%d_%s", j+1,label.c_str())] = std::make_shared(Form("btag_light_jet%d", j+1) , Form("btag_light_jet%d_%s", j+1,label.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_c_jet%d_%s" , j+1,label.c_str())] = std::make_shared(Form("btag_c_jet%d" , j+1) , Form("btag_c_jet%d_%s" , j+1,label.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_b_jet%d_%s" , j+1,label.c_str())] = std::make_shared(Form("btag_b_jet%d" , j+1) , Form("btag_b_jet%d_%s" , j+1,label.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_bb_jet%d_%s" , j+1,label.c_str())] = std::make_shared(Form("btag_bb_jet%d" , j+1) , Form("btag_bb_jet%d_%s" , j+1,label.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_cc_jet%d_%s" , j+1,label.c_str())] = std::make_shared(Form("btag_cc_jet%d" , j+1) , Form("btag_cc_jet%d_%s" , j+1,label.c_str()) , nbins_btag, &bins_btag[0] ); + } + if ( config_->btagalgo_ == "deepflavour") + { + h1_[Form("btag_light_jet%d_%s", j+1,label.c_str())] = std::make_shared(Form("btag_light_jet%d", j+1) , Form("btag_light_jet%d_%s", j+1,label.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_g_jet%d_%s" , j+1,label.c_str())] = std::make_shared(Form("btag_g_jet%d" , j+1) , Form("btag_g_jet%d_%s" , j+1,label.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_c_jet%d_%s" , j+1,label.c_str())] = std::make_shared(Form("btag_c_jet%d" , j+1) , Form("btag_c_jet%d_%s" , j+1,label.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_b_jet%d_%s" , j+1,label.c_str())] = std::make_shared(Form("btag_b_jet%d" , j+1) , Form("btag_b_jet%d_%s" , j+1,label.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_bb_jet%d_%s" , j+1,label.c_str())] = std::make_shared(Form("btag_bb_jet%d" , j+1) , Form("btag_bb_jet%d_%s" , j+1,label.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_lepb_jet%d_%s" , j+1,label.c_str())] = std::make_shared(Form("btag_lepb_jet%d" , j+1) , Form("btag_lepb_jet%d_%s" , j+1,label.c_str()) , nbins_btag, &bins_btag[0] ); + } + + // 2D histograms + h2_[Form("pt_eta_jet%d_%s" , j+1,label.c_str())] = std::make_shared(Form("pt_eta_jet%d" , j+1) , Form("pt_eta_jet%d_%s" , j+1,label.c_str()) ,1500 , 0 , 1500, 600, -3, 3 ); + h2_[Form("pt_eta_jet%d_%s" , j+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d p_{T} [GeV]",j+1)); + h2_[Form("pt_eta_jet%d_%s" , j+1,label.c_str())] -> GetYaxis() -> SetTitle(Form("Jet %d #eta",j+1)); + + if ( config_->isMC() && ( config_->useJetsFlavour() || config_->useJetsExtendedFlavour() ) ) + { + for ( auto & flv : flavours_ ) // flavour dependent histograms + { + // 1D histograms + h1_[Form("pt_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("pt_jet%d_%s" , j+1, flv.c_str()) , Form("pt_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) ,1500 , 0 , 1500 ); + h1_[Form("eta_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("eta_jet%d_%s" , j+1, flv.c_str()) , Form("eta_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) , 600 , -3, 3 ); + h1_[Form("phi_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("phi_jet%d_%s" , j+1, flv.c_str()) , Form("phi_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) , 360 , -180, 180 ); + h1_[Form("btag_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("btag_jet%d_%s" , j+1, flv.c_str()) , Form("btag_jet%d_%s_%s", j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("qglikelihood_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("qglikelihood_jet%d_%s" , j+1, flv.c_str()) , Form("qglikelihood_jet%d_%s_%s", j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("nconstituents_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("nconstituents_jet%d_%s" , j+1, flv.c_str()) , Form("nconstituents_jet%d_%s_%s", j+1,label.c_str(),flv.c_str()) , 200 , 0, 200 ); + + h1_[Form("pt_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d (%s) p_{T} [GeV]" , j+1, flv.c_str())); + h1_[Form("eta_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d (%s) #eta" , j+1, flv.c_str())); + h1_[Form("phi_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d (%s) #phi" , j+1, flv.c_str())); + h1_[Form("btag_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d (%s) btag discriminator" , j+1, flv.c_str())); + h1_[Form("qglikelihood_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d (%s) q-g likelihood" , j+1, flv.c_str())); + h1_[Form("nconstituents_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d (%s) n constituents" , j+1, flv.c_str())); + + if ( config_->btagalgo_ == "deepcsv") + { + h1_[Form("btag_light_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("btag_light_jet%d_%s", j+1,flv.c_str()) , Form("btag_light_jet%d_%s_%s", j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_c_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("btag_c_jet%d_%s" , j+1,flv.c_str()) , Form("btag_c_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_b_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("btag_b_jet%d_%s" , j+1,flv.c_str()) , Form("btag_b_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_bb_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("btag_bb_jet%d_%s" , j+1,flv.c_str()) , Form("btag_bb_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_cc_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("btag_cc_jet%d_%s" , j+1,flv.c_str()) , Form("btag_cc_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + } + if ( config_->btagalgo_ == "deepflavour") + { + h1_[Form("btag_light_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("btag_light_jet%d_%s", j+1,flv.c_str()) , Form("btag_light_jet%d_%s_%s", j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_g_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("btag_g_jet%d_%s" , j+1,flv.c_str()) , Form("btag_g_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_c_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("btag_c_jet%d_%s" , j+1,flv.c_str()) , Form("btag_c_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_b_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("btag_b_jet%d_%s" , j+1,flv.c_str()) , Form("btag_b_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_bb_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("btag_bb_jet%d_%s" , j+1,flv.c_str()) , Form("btag_bb_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + h1_[Form("btag_lepb_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("btag_lepb_jet%d_%s" , j+1,flv.c_str()) , Form("btag_lepb_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) , nbins_btag, &bins_btag[0] ); + } + // 2D histograms + h2_[Form("pt_eta_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] = std::make_shared(Form("pt_eta_jet%d_%s" , j+1,flv.c_str()) , Form("pt_eta_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str()) ,1500 , 0 , 1500, 600, -3, 3 ); + h2_[Form("pt_eta_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d (%s) p_{T} [GeV]" , j+1,flv.c_str())); + h2_[Form("pt_eta_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> GetYaxis() -> SetTitle(Form("Jet %d (%s) #eta" ,j+1,flv.c_str())); + + } + } + if ( config_->doDijet() || config_->doDijetFlavour() ) // dijet histograms + { + for ( int k = j+1; k < n && j < n; ++k ) + { + h1_[Form("dptrel_jet%d%d_%s" , j+1,k+1,label.c_str())] = std::make_shared(Form("dptrel_jet%d%d" , j+1,k+1) , Form("dptrel_jet%d%d_%s" , j+1,k+1,label.c_str()) ,1000 , 0,1 ); + h1_[Form("dpt_jet%d%d_%s" , j+1,k+1,label.c_str())] = std::make_shared(Form("dpt_jet%d%d" , j+1,k+1) , Form("dpt_jet%d%d_%s" , j+1,k+1,label.c_str()) ,1000 , 0,1000 ); + h1_[Form("dr_jet%d%d_%s" , j+1,k+1,label.c_str())] = std::make_shared(Form("dr_jet%d%d" , j+1,k+1) , Form("dr_jet%d%d_%s" , j+1,k+1,label.c_str()) , 100 , 0, 5 ); + h1_[Form("deta_jet%d%d_%s" , j+1,k+1,label.c_str())] = std::make_shared(Form("deta_jet%d%d", j+1,k+1) , Form("deta_jet%d%d_%s" , j+1,k+1,label.c_str()) , 100 , 0,10 ); + h1_[Form("dphi_jet%d%d_%s" , j+1,k+1,label.c_str())] = std::make_shared(Form("dphi_jet%d%d", j+1,k+1) , Form("dphi_jet%d%d_%s" , j+1,k+1,label.c_str()) , 315 , 0, 3.15 ); + h1_[Form("pt_jet%d%d_%s" , j+1,k+1,label.c_str())] = std::make_shared(Form("pt_jet%d%d" , j+1,k+1) , Form("pt_jet%d%d_%s" , j+1,k+1,label.c_str()) , 300 , 0,3000 ); + h1_[Form("eta_jet%d%d_%s" , j+1,k+1,label.c_str())] = std::make_shared(Form("eta_jet%d%d" , j+1,k+1) , Form("eta_jet%d%d_%s" , j+1,k+1,label.c_str()) , 200 , -10,10 ); + h1_[Form("phi_jet%d%d_%s" , j+1,k+1,label.c_str())] = std::make_shared(Form("phi_jet%d%d" , j+1,k+1) , Form("phi_jet%d%d_%s" , j+1,k+1,label.c_str()) , 360 , -180,180 ); + h1_[Form("m_jet%d%d_%s" , j+1,k+1,label.c_str())] = std::make_shared(Form("m_jet%d%d" , j+1,k+1) , Form("m_jet%d%d_%s" , j+1,k+1,label.c_str()) ,3000 , 0,3000 ); + + h1_[Form("dptrel_jet%d%d_%s" , j+1,k+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("#DeltaP_{T}(Jet %d, Jet %d)/Jet %d p_{T}",j+1,k+1,j+1)); + h1_[Form("dpt_jet%d%d_%s" , j+1,k+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("#Delta p_{T}(Jet %d, Jet %d) [GeV]",j+1,k+1)); + h1_[Form("dr_jet%d%d_%s" , j+1,k+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("#DeltaR(Jet %d, Jet %d)",j+1,k+1)); + h1_[Form("deta_jet%d%d_%s" , j+1,k+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("#Delta#eta(Jet %d, Jet %d)",j+1,k+1)); + h1_[Form("dphi_jet%d%d_%s" , j+1,k+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("#Delta#phi(Jet %d, Jet %d)",j+1,k+1)); + h1_[Form("pt_jet%d%d_%s" , j+1,k+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d + Jet %d p_{T} [GeV]",j+1,k+1)); + h1_[Form("eta_jet%d%d_%s" , j+1,k+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d + Jet %d #eta",j+1,k+1)); + h1_[Form("phi_jet%d%d_%s" , j+1,k+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d + Jet %d #phi",j+1,k+1)); + h1_[Form("m_jet%d%d_%s" , j+1,k+1,label.c_str())] -> GetXaxis() -> SetTitle(Form("M_{%d%d} [GeV]",j+1,k+1)); + + if ( config_->isMC() && config_->doDijetFlavour() ) + { + for ( auto & flv1 : flavours_ ) + { + for ( auto & flv2 : flavours_ ) + { + h1_[Form("dptrel_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] = std::make_shared(Form("dptrel_jet%d%d_%s_%s" , j+1,k+1,flv1.c_str(),flv2.c_str()) , Form("dptrel_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str()) , 100 , 0,1 ); + h1_[Form("dpt_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] = std::make_shared(Form("dpt_jet%d%d_%s_%s" , j+1,k+1,flv1.c_str(),flv2.c_str()) , Form("dpt_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str()) , 100 , 0,1000 ); + h1_[Form("dr_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] = std::make_shared(Form("dr_jet%d%d_%s_%s" , j+1,k+1,flv1.c_str(),flv2.c_str()) , Form("dr_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str()) , 100 , 0, 5 ); + h1_[Form("deta_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] = std::make_shared(Form("deta_jet%d%d_%s_%s" , j+1,k+1,flv1.c_str(),flv2.c_str()) , Form("deta_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str()) , 100 , 0,10 ); + h1_[Form("dphi_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] = std::make_shared(Form("dphi_jet%d%d_%s_%s" , j+1,k+1,flv1.c_str(),flv2.c_str()) , Form("dphi_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str()) , 315 , 0, 3.15 ); + h1_[Form("pt_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] = std::make_shared(Form("pt_jet%d%d_%s_%s" , j+1,k+1,flv1.c_str(),flv2.c_str()) , Form("pt_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str()) , 300 , 0,300 ); + h1_[Form("eta_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] = std::make_shared(Form("eta_jet%d%d_%s_%s" , j+1,k+1,flv1.c_str(),flv2.c_str()) , Form("eta_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str()) , 200 , -10,10 ); + h1_[Form("phi_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] = std::make_shared(Form("phi_jet%d%d_%s_%s" , j+1,k+1,flv1.c_str(),flv2.c_str()) , Form("phi_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str()) , 360 , -180,180 ); + h1_[Form("m_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] = std::make_shared(Form("m_jet%d%d_%s_%s" , j+1,k+1,flv1.c_str(),flv2.c_str()) , Form("m_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str()) ,3000 , 0,300 ); + + h1_[Form("dptrel_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> GetXaxis() -> SetTitle(Form("#DeltaP_{T}(Jet %d (%s), Jet %d (%s))/Jet %d p_{T}",j+1,flv1.c_str(),k+1,flv2.c_str(),j+1)); + h1_[Form("dpt_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> GetXaxis() -> SetTitle(Form("#Delta p_{T}(Jet %d (%s), Jet %d (%s)) [GeV]",j+1,flv1.c_str(),k+1,flv2.c_str())); + h1_[Form("dr_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> GetXaxis() -> SetTitle(Form("#DeltaR(Jet %d (%s), Jet %d (%s))",j+1,flv1.c_str(),k+1,flv2.c_str())); + h1_[Form("deta_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> GetXaxis() -> SetTitle(Form("#Delta#eta(Jet %d (%s), Jet %d (%s))",j+1,flv1.c_str(),k+1,flv2.c_str())); + h1_[Form("dphi_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> GetXaxis() -> SetTitle(Form("#Delta#phi(Jet %d (%s), Jet %d (%s))",j+1,flv1.c_str(),k+1,flv2.c_str())); + h1_[Form("pt_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d (%s) + Jet %d (%s) p_{T} [GeV]",j+1,flv1.c_str(),k+1,flv2.c_str())); + h1_[Form("eta_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d (%s) + Jet %d (%s) #eta",j+1,flv1.c_str(),k+1,flv2.c_str())); + h1_[Form("phi_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> GetXaxis() -> SetTitle(Form("Jet %d (%s) + Jet %d (%s) #phi",j+1,flv1.c_str(),k+1,flv2.c_str())); + h1_[Form("m_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> GetXaxis() -> SetTitle(Form("M_{%d%d} (%s)(%s) [GeV]",j+1,k+1,flv1.c_str(),flv2.c_str())); + } + } + } + } + } + } + + this->output()->cd(); +} + + +float JetAnalyser::btag(const Jet & jet, const std::string & algo) +{ + float btag; + if ( config_->btagalgo_ == "csvivf" || config_->btagalgo_ == "csv" ) { btag = jet.btag("btag_csvivf"); } + else if ( config_->btagalgo_ == "deepcsv" ) { btag = jet.btag("btag_deepb") + jet.btag("btag_deepbb"); } + else if ( config_->btagalgo_ == "deepbvsall" ) { btag = jet.btag("btag_deepbvsall"); } + else if ( config_->btagalgo_ == "deepflavour" ) { btag = jet.btag("btag_dfb") + jet.btag("btag_dfbb") + jet.btag("btag_dflepb"); } + else { btag = -9999; } + + return btag; +} + +bool JetAnalyser::selectionJet(const int & r) +{ + ++cutflow_; + bool isgood = true; + int j = r-1; + + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( config_->jetsPtMax().size() > 0 && config_->jetsPtMax()[j] > config_->jetsPtMin()[j] ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: pt > %5.1f GeV and pt < %5.1f GeV and |eta| < %3.1f",r,config_->jetsPtMin()[j], config_->jetsPtMax()[j],config_->jetsEtaMax()[j] )); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: pt > %5.1f GeV and |eta| < %3.1f",r,config_->jetsPtMin()[j], config_->jetsEtaMax()[j] )); + } + +// if ( selectedJets_.size() == 0 ) isgood = (isgood && selectionJetId()); +// if ( !isgood || (int)selectedJets_.size() < r ) return false; + if ( (int)selectedJets_.size() < r ) return false; + + // kinematic selection + if ( selectedJets_[j] -> pt() < config_->jetsPtMin()[j] && !(config_->jetsPtMin()[j] < 0) ) return false; + if ( fabs(selectedJets_[j] -> eta()) > config_->jetsEtaMax()[j] && !(config_->jetsEtaMax()[j] < 0) ) return false; + if ( config_->jetsPtMax().size() > 0 ) + { + if ( selectedJets_[j] -> pt() > config_->jetsPtMax()[j] && !(config_->jetsPtMax()[j] < config_->jetsPtMin()[j]) ) return false; + } + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return isgood; +} + + +bool JetAnalyser::selectionJetDeta(const int & j1, const int & j2, const float & delta) +{ + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( delta > 0 ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Deta(jet %d, jet %d) < %4.2f",j1,j2,fabs(delta))); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Deta(jet %d, jet %d) > %4.2f",j1,j2,fabs(delta))); + } + + + if ( (int)selectedJets_.size() < j1 || (int)selectedJets_.size() < j2 ) + { + std::cout << "-errr- JetAnalyser::selectionJetDeta(): you dont have enough selected jets. Will return false" << std::endl; + return false; + } + if ( delta > 0 ) + { + if ( fabs(selectedJets_[j1-1]->eta() - selectedJets_[j2-1]->eta()) > fabs(delta) ) return false; + } + else + { + if ( fabs(selectedJets_[j1-1]->eta() - selectedJets_[j2-1]->eta()) < fabs(delta) ) return false; + } + + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; + +} +bool JetAnalyser::selectionJetDeta(const int & j1, const int & j2) +{ + bool ok = true; + if (config_->detamax_ < 0 ) + { + ok = ok && true; + } + else + { + ok = ok && selectionJetDeta(j1,j2,config_->detamax_); + } + + if (config_->detamin_ < 0 ) + { + ok = ok && true; + } + else + { + ok = ok && selectionJetDeta(j1,j2,-1*config_->detamin_); + } + return ok; + +} + +bool JetAnalyser::selectionJetDphi(const int & j1, const int & j2, const float & delta) +{ + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( delta > 0 ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Dphi(jet %d, jet %d) < %4.2f",j1,j2,fabs(delta))); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Dphi(jet %d, jet %d) > %4.2f",j1,j2,fabs(delta))); + } + + if ( (int)selectedJets_.size() < j1 || (int)selectedJets_.size() < j2 ) + { + std::cout << "-errr- JetAnalyser::selectionJetDeta(): you dont have enough selected jets. Will return false" << std::endl; + return false; + } + if ( delta > 0 ) + { + if ( fabs(selectedJets_[j1-1]->deltaPhi(*selectedJets_[j2-1])) > fabs(delta) ) return false; + } + else + { + if ( fabs(selectedJets_[j1-1]->deltaPhi(*selectedJets_[j2-1])) < fabs(delta) ) return false; + } + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; + +} +bool JetAnalyser::selectionJetDphi(const int & j1, const int & j2) +{ + bool ok = true; + if (config_->dphimax_ < 0 ) + { + ok = ok && true; + } + else + { + ok = ok && selectionJetDphi(j1,j2,config_->dphimax_); + } + + if (config_->dphimin_ < 0 ) + { + ok = ok && true; + } + else + { + ok = ok && selectionJetDphi(j1,j2,-1*config_->dphimin_); + } + return ok; + +} + + +bool JetAnalyser::selectionJetDr(const int & j1, const int & j2, const float & delta) +{ + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( delta > 0 ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("DR(jet %d, jet %d) < %4.2f",j1,j2,fabs(delta))); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("DR(jet %d, jet %d) > %4.2f",j1,j2,fabs(delta))); + } + + + if ( (int)selectedJets_.size() < j1 || (int)selectedJets_.size() < j2 ) + { + std::cout << "-e- JetAnalyser::selectionJetDr(): at least one of the jets does not exist" << std::endl; + return false; + } + + if ( delta > 0 ) + { + if ( selectedJets_[j1-1]->deltaR(*selectedJets_[j2-1]) > fabs(delta) ) return false; + } + else + { + if ( selectedJets_[j1-1]->deltaR(*selectedJets_[j2-1]) < fabs(delta) ) return false; + } + + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; + +} + +bool JetAnalyser::selectionJetDr(const int & j1, const int & j2) +{ + bool ok = true; + if (config_->drmax_ < 0 ) + { + ok = ok && true; + } + else + { + ok = ok && selectionJetDr(j1,j2,config_->drmax_); + } + + if (config_->drmin_ < 0 ) + { + ok = ok && true; + } + else + { + ok = ok && selectionJetDr(j1,j2,-1*config_->drmin_); + } + return ok; +} + + +std::vector< std::shared_ptr > JetAnalyser::jets() +{ + return jets_; +} + +std::vector< std::shared_ptr > JetAnalyser::selectedJets() +{ + return selectedJets_; +} + + +bool JetAnalyser::selectionJetId() +{ + if ( ! jetsanalysis_ ) return false; + + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("JetId: %s",config_->jetsId().c_str())); + + auto jet = std::begin(selectedJets_); + while ( jet != std::end(selectedJets_) ) + { + if ( ! (*jet)->id(config_->jetsId() ) ) + jet = selectedJets_.erase(jet); + else + ++jet; + } + if ( selectedJets_.size() == 0 ) return false; + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + +bool JetAnalyser::selectionJetPileupId() +{ + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("JetPileupId: %s",config_->jetsPuId().c_str())); + + + if ( ! jetsanalysis_ ) return false; + + auto jet = std::begin(selectedJets_); + + while ( jet != std::end(selectedJets_) ) + { + if ( ! (*jet)->pileupJetIdFullId(config_->jetsPuId()) ) + jet = selectedJets_.erase(jet); + else + ++jet; + } + + if ( selectedJets_.size() == 0 ) return false; + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; + +} + +bool JetAnalyser::selectionNJets() +{ + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("NJets >= %d",config_->nJetsMin())); + + + if ((int)selectedJets_.size() < config_->nJetsMin()) return false; + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; + +} + + +bool JetAnalyser::selectionBJet(const int & r ) +{ + if ( ! config_->signalRegion() && r == config_->nonBtagJet() ) return this->selectionNonBJet(r); + + int j = r-1; + if ( config_->btagWP(config_->jetsBtagWP()[j]) < 0 ) return true; // there is no selection here, so will not update the cutflow + + ++ cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag > %6.4f (%s)",r,config_->btagalgo_.c_str(),config_->btagWP(config_->jetsBtagWP()[j]),config_->jetsBtagWP()[j].c_str())); + + if ( r > config_->nbjetsmin_ ) + { + std::cout << "* warning * - JetAnalyser::selectionBJet(): given jet rank > nbjetsmin. Returning false! " << std::endl; + return false; + } + + // jet btag +// if ( btag(*selectedJets_[j],config_->btagalgo_) < config_->jetsbtagmin_[j] ) return false; + + if ( btag(*selectedJets_[j],config_->btagalgo_) < config_->btagWP(config_->jetsBtagWP()[j]) ) return false; + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + + +bool JetAnalyser::selectionNonBJet(const int & r ) +{ + int j = r-1; + + if ( config_->btagWP(config_->nonBtagWP()) < 0 ) return true; // there is no selection here, so will not update the cutflow + + ++ cutflow_; + + if ( r > config_->nbjetsmin_ ) + { + std::cout << "* warning * - JetAnalyser::selectionBJet(): given jet rank > nbjetsmin. Returning false! " << std::endl; + return false; + } + + // jet non btag + if ( btag(*selectedJets_[j],config_->btagalgo_) > config_->btagWP(config_->nonBtagWP()) ) return false; + + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag < %6.4f (%s) [reverse btag]",r,config_->btagalgo_.c_str(),config_->btagWP(config_->nonBtagWP()),config_->nonBtagWP().c_str())); + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + + +bool JetAnalyser::onlineJetMatching(const int & r) +{ + int j = r-1; + if ( config_->triggerObjectsL1Jets() == "" && config_->triggerObjectsCaloJets() == "" && config_->triggerObjectsPFJets() == "") return true; + + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: online jet match",r)); + + + if ( r > config_->nJetsMin() ) + { + std::cout << "*Warning* JetAnalyser::onlineJetMatching(): asking for matching of unselected jet. Returning false!" << std::endl; + return false; // asking for a match beyond the selection, that's wrong, therefore false + } + if ( selectedJets_.size() == 0 ) + { + std::cout << "*Warning* JetAnalyser::onlineJetMatching(): selectedJets is empty. Returning false!" << std::endl; + return false; // asking for a match beyond the selection, that's wrong, therefore false + } + + std::shared_ptr jet = selectedJets_[j]; + if ( ! jet->matched(config_->triggerObjectsL1Jets() ) ) return false; + if ( ! jet->matched(config_->triggerObjectsCaloJets() ) ) return false; + if ( ! jet->matched(config_->triggerObjectsPFJets() ) ) return false; + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + + +bool JetAnalyser::onlineBJetMatching(const int & r) +{ + int j = r-1; + if ( config_->triggerObjectsBJets() == "" ) return true; + + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: online b jet match",r)); + + + if ( r > config_->nJetsMin() ) + { + std::cout << "*Warning* JetAnalyser::onlineBJetMatching(): asking for matching of unselected jet. Returning false!" << std::endl; + return false; // asking for a match beyond the selection, that's wrong, therefore false + } + if ( selectedJets_.size() == 0 ) + { + std::cout << "*Warning* JetAnalyser::onlineBJetMatching(): selectedJets is empty. You must run selectionJetId() before. Returning false!" << std::endl; + return false; // asking for a match beyond the selection, that's wrong, therefore false + } + + std::shared_ptr jet = selectedJets_[j]; + if ( ! jet->matched(config_->triggerObjectsBJets()) ) return false; + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + +void JetAnalyser::fillJetHistograms(const std::string & label) +{ + this->output()->cd(); + ++ cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("*** Filling jets histograms - %s",label.c_str())); + + this->output()->cd(label.c_str()); + + int n = n_hjets_; + + if ( n > config_->nJetsMin() ) n = config_->nJetsMin(); + + h1_[Form("jet_hist_weight_%s",label.c_str())] -> Fill(0.,weight_); + + for ( int j = 0; j < n; ++j ) + { + // 1D histograms + h1_[Form("pt_jet%d_%s",j+1,label.c_str())] -> Fill(selectedJets_[j]->pt(),weight_); + h1_[Form("eta_jet%d_%s",j+1,label.c_str())] -> Fill(selectedJets_[j]->eta(),weight_); + h1_[Form("phi_jet%d_%s",j+1,label.c_str())] -> Fill(selectedJets_[j]->phi()*180./acos(-1.),weight_); + float mybtag = btag(*selectedJets_[j],config_->btagalgo_); + float mybtaglog = 1.e-7; + if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); + h1_[Form("btag_jet%d_%s",j+1,label.c_str())] -> Fill(mybtag,weight_); + h1_[Form("btaglog_jet%d_%s",j+1,label.c_str())] -> Fill(mybtaglog,weight_); + h1_[Form("qglikelihood_jet%d_%s", j+1,label.c_str())] -> Fill(selectedJets_[j]->qgLikelihood(),weight_); + h1_[Form("nconstituents_jet%d_%s", j+1,label.c_str())] -> Fill(selectedJets_[j]->constituents(),weight_); + + if ( config_->btagalgo_ == "deepcsv") + { + h1_[Form("btag_light_jet%d_%s", j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_deeplight"),weight_); + h1_[Form("btag_c_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepc"),weight_); + h1_[Form("btag_b_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepb"),weight_); + h1_[Form("btag_bb_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepbb"),weight_); + h1_[Form("btag_cc_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepcc"),weight_); + } + if ( config_->btagalgo_ == "deepflavour") + { + h1_[Form("btag_light_jet%d_%s", j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_dflight"),weight_); + h1_[Form("btag_g_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_dfg") ,weight_); + h1_[Form("btag_c_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_dfc") ,weight_); + h1_[Form("btag_b_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_dfb") ,weight_); + h1_[Form("btag_bb_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_dfbb") ,weight_); + h1_[Form("btag_lepb_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_dflepb") ,weight_); + +// mybtag = selectedJets_[j]->btag("btag_dflight"); +// mybtaglog = 1.e-7; +// if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); +// h1_[Form("btaglog_light_jet%d_%s", j+1,label.c_str())] -> Fill(mybtaglog ,weight_); +// mybtag = selectedJets_[j]->btag("btag_dfg"); +// mybtaglog = 1.e-7; +// if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); +// h1_[Form("btaglog_g_jet%d_%s" , j+1,label.c_str())] -> Fill(mybtaglog ,weight_); +// mybtag = selectedJets_[j]->btag("btag_dfc"); +// mybtaglog = 1.e-7; +// if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); +// h1_[Form("btaglog_c_jet%d_%s" , j+1,label.c_str())] -> Fill(mybtaglog ,weight_); +// mybtag = selectedJets_[j]->btag("btag_dfb"); +// mybtaglog = 1.e-7; +// if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); +// h1_[Form("btaglog_b_jet%d_%s" , j+1,label.c_str())] -> Fill(mybtaglog ,weight_); +// mybtag = selectedJets_[j]->btag("btag_dfbb"); +// mybtaglog = 1.e-7; +// if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); +// h1_[Form("btaglog_bb_jet%d_%s" , j+1,label.c_str())] -> Fill(mybtaglog ,weight_); +// mybtag = selectedJets_[j]->btag("btag_dflepb"); +// mybtaglog = 1.e-7; +// if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); +// h1_[Form("btaglog_lepb_jet%d_%s" , j+1,label.c_str())] -> Fill(mybtaglog ,weight_); + + } + // 2D histograms + h2_[Form("pt_eta_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->pt(), selectedJets_[j]->eta(), weight_); + + if ( config_->isMC() && ( config_ -> useJetsFlavour() || config_ -> useJetsExtendedFlavour() )) + { + std::string flv = "udsg"; + if ( config_ -> useJetsFlavour() ) + { + if ( abs(selectedJets_[j]->flavour()) == 4 ) flv = "c"; + if ( abs(selectedJets_[j]->flavour()) == 5 ) flv = "b"; + } + if ( config_ -> useJetsExtendedFlavour() ) flv = selectedJets_[j]->extendedFlavour(); + // 1D histograms + h1_[Form("pt_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->pt(),weight_); + h1_[Form("eta_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->eta(),weight_); + h1_[Form("phi_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->phi()*180./acos(-1.),weight_); + h1_[Form("btag_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> Fill(btag(*selectedJets_[j],config_->btagalgo_),weight_); + h1_[Form("qglikelihood_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->qgLikelihood(),weight_); + h1_[Form("nconstituents_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->constituents(),weight_); + if ( config_->btagalgo_ == "deepcsv") + { + h1_[Form("btag_light_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_deeplight"),weight_); + h1_[Form("btag_c_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepc"),weight_); + h1_[Form("btag_b_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepb"),weight_); + h1_[Form("btag_bb_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepbb"),weight_); + h1_[Form("btag_cc_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepcc"),weight_); + } + if ( config_->btagalgo_ == "deepflavour") + { + h1_[Form("btag_light_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_dflight"),weight_); + h1_[Form("btag_g_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_dfg") ,weight_); + h1_[Form("btag_c_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_dfc") ,weight_); + h1_[Form("btag_b_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_dfb") ,weight_); + h1_[Form("btag_bb_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_dfbb") ,weight_); + h1_[Form("btag_lepb_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_dflepb") ,weight_); + +// mybtag = selectedJets_[j]->btag("btag_dflight"); +// mybtaglog = 1.e-7; +// if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); +// h1_[Form("btag_light_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> Fill(mybtaglog ,weight_); +// mybtag = selectedJets_[j]->btag("btag_dfg"); +// mybtaglog = 1.e-7; +// if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); +// h1_[Form("btag_g_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(mybtaglog ,weight_); +// mybtag = selectedJets_[j]->btag("btag_dfc"); +// mybtaglog = 1.e-7; +// if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); +// h1_[Form("btag_c_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(mybtaglog ,weight_); +// mybtag = selectedJets_[j]->btag("btag_dfb"); +// mybtaglog = 1.e-7; +// if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); +// h1_[Form("btag_b_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(mybtaglog ,weight_); +// mybtag = selectedJets_[j]->btag("btag_dfbb"); +// mybtaglog = 1.e-7; +// if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); +// h1_[Form("btag_bb_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(mybtaglog ,weight_); +// mybtag = selectedJets_[j]->btag("btag_dflepb"); +// mybtaglog = 1.e-7; +// if ( mybtag > 0 ) mybtaglog = -log(1.-mybtag); +// h1_[Form("btag_lepb_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(mybtaglog ,weight_); + + } + // 2D histograms + h2_[Form("pt_eta_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->pt(), selectedJets_[j]->eta(), weight_); + } + + if ( config_ -> doDijet() || config_->doDijetFlavour() ) + { + for ( int k = j+1; k < n && j < n; ++k ) + { + Composite c_ij(*(selectedJets_[j]),*(selectedJets_[k])); + + h1_[Form("dptrel_jet%d%d_%s" , j+1,k+1,label.c_str())] -> Fill(fabs(selectedJets_[j]->pt()-selectedJets_[k]->pt())/selectedJets_[j]->pt(),weight_); + h1_[Form("dpt_jet%d%d_%s" , j+1,k+1,label.c_str())] -> Fill(fabs(selectedJets_[j]->pt()-selectedJets_[k]->pt()),weight_); + h1_[Form("dr_jet%d%d_%s",j+1,k+1,label.c_str())] -> Fill(c_ij.deltaR(),weight_); + h1_[Form("deta_jet%d%d_%s",j+1,k+1,label.c_str())] -> Fill(c_ij.deltaEta(),weight_); + h1_[Form("dphi_jet%d%d_%s",j+1,k+1,label.c_str())] -> Fill(fabs(selectedJets_[j]->deltaPhi(*selectedJets_[k]))); + h1_[Form("pt_jet%d%d_%s",j+1,k+1,label.c_str())] -> Fill(c_ij.pt(),weight_); + h1_[Form("eta_jet%d%d_%s",j+1,k+1,label.c_str())] -> Fill(c_ij.eta(),weight_); + h1_[Form("phi_jet%d%d_%s",j+1,k+1,label.c_str())] -> Fill(c_ij.phi()*180./acos(-1.),weight_); + if ( config_->isMC() || !config_->signalRegion() ) + { + h1_[Form("m_jet%d%d_%s",j+1,k+1,label.c_str())] -> Fill(c_ij.m(),weight_); + } + else // blind + { + h1_[Form("m_jet%d%d_%s",j+1,k+1,label.c_str())] -> Fill(0.,weight_); + } + if ( config_->isMC() && config_->doDijetFlavour() ) + { + std::string flv1 = "udsg"; + std::string flv2 = "udsg"; + if ( config_ -> useJetsFlavour() ) + { + if ( abs(selectedJets_[j]->flavour()) == 4 ) flv1 = "c"; + if ( abs(selectedJets_[j]->flavour()) == 5 ) flv1 = "b"; + if ( abs(selectedJets_[k]->flavour()) == 4 ) flv2 = "c"; + if ( abs(selectedJets_[k]->flavour()) == 5 ) flv2 = "b"; + } + if ( config_ -> useJetsExtendedFlavour() ) + { + flv1 = selectedJets_[j]->extendedFlavour(); + flv2 = selectedJets_[k]->extendedFlavour(); + } + h1_[Form("dptrel_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> Fill(fabs(selectedJets_[j]->pt()-selectedJets_[k]->pt())/selectedJets_[j]->pt(),weight_); + h1_[Form("dpt_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> Fill(fabs(selectedJets_[j]->pt()-selectedJets_[k]->pt()),weight_); + h1_[Form("dr_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> Fill(c_ij.deltaR(),weight_); + h1_[Form("deta_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> Fill(c_ij.deltaEta(),weight_); + h1_[Form("dphi_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> Fill(fabs(selectedJets_[j]->deltaPhi(*selectedJets_[k]))); + h1_[Form("pt_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> Fill(c_ij.pt(),weight_); + h1_[Form("eta_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> Fill(c_ij.eta(),weight_); + h1_[Form("phi_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> Fill(c_ij.phi()*180./acos(-1.),weight_); + h1_[Form("m_jet%d%d_%s_%s_%s" , j+1,k+1,label.c_str(),flv1.c_str(),flv2.c_str())] -> Fill(c_ij.m(),weight_); + + } + } + } + } + this->output()->cd(); + + h1_["cutflow"] -> Fill(cutflow_,weight_); + +} + +ScaleFactors JetAnalyser::btagSF(const int & r, const std::string & wp) +{ + ScaleFactors sf; + int j = r-1; + sf.nominal = selectedJets_[j]->btagSF(bsf_reader_[wp]); + sf.up = selectedJets_[j]->btagSFup(bsf_reader_[wp]); + sf.down = selectedJets_[j]->btagSFdown(bsf_reader_[wp]); + + return sf; +} + + +void JetAnalyser::actionApplyJER() +{ + if ( ! applyjer_ ) return; // will not apply btag SF + + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,"*** Apply JER smearing"); + + + for ( auto & j : selectedJets_ ) + { + j -> applyJER(*jerinfo_,0.2); + } + + h1_["cutflow"] -> Fill(cutflow_,weight_); +} + +void JetAnalyser::actionApplyBtagSF(const int & r) +{ + if ( ! config_-> isMC() || config_->btagsf_ == "" ) return; // will not apply btag SF + if ( ! config_->signalRegion() && r == config_->nonBtagJet() ) return; + + int j = r-1; + ++ cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( config_->jetsBtagWP()[j] == "xxx" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: btag SF = 1 applied (%s %s WP)",r,config_->btagalgo_.c_str(),config_->jetsBtagWP()[j].c_str())); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: btag SF applied (%s %s WP)",r,config_->btagalgo_.c_str(),config_->jetsBtagWP()[j].c_str())); + } + + float sf = 1.; + if ( config_->jetsBtagWP()[j] != "xxx" ) sf = this->btagSF(r,config_->jetsBtagWP()[j]).nominal; + + weight_ *= sf; + h1_["cutflow"] -> Fill(cutflow_,weight_); + +} + +void JetAnalyser::actionApplyBjetRegression() +{ + if ( ! config_->bRegression() ) return; + + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,"*** Apply b jet energy regression"); + + for ( auto & j : selectedJets_ ) + { + j -> applyBjetRegression(); + } + h1_["cutflow"] -> Fill(cutflow_,weight_); +} + +bool JetAnalyser::selectionDiJetMass(const int & r1, const int & r2) +{ + float min = config_->massMin(); + float max = config_->massMax(); + if ( min < 0. && max < 0. ) return true; + + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + std::string label = Form("M(Jet %d + Jet %d)",r1,r2); + if ( min > 0. ) + { + if ( max > 0. && max > min ) label = Form("%5.1f GeV < %s < %5.1f GeV",min,label.c_str(),max); + else label = Form("%s > %5.1f GeV",label.c_str(),min); + } + else + { + label = Form("%s < %5.1f GeV",label.c_str(),max); + } + + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,label.c_str()); + } + + int j1 = r1-1; + int j2 = r2-1; + Composite c_j1j2(*(selectedJets_[j1]),*(selectedJets_[j2])); + float mass = c_j1j2.m(); + + if ( min > 0. && mass < min ) return false; + if ( max > 0. && mass > max ) return false; + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + + + +void JetAnalyser::jetSwap(const int & r1, const int & r2) +{ + if ( r1 == r2 ) return; + int j1 = r1-1; + int j2 = r2-1; +// ++ cutflow_; +// if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) +// h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d <--> Jet %d: jets ranking was swapped ",r1,r2)); + + auto jet1 = selectedJets_[j1]; + auto jet2 = selectedJets_[j2]; + + selectedJets_[j1] = jet2; + selectedJets_[j2] = jet1; + +// h1_["cutflow"] -> Fill(cutflow_,weight_); + +} + + + +bool JetAnalyser::selectionJetPtImbalance(const int & j1, const int & j2, const float & delta) +{ + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( delta > 0 ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("DpT(jet %d, jet %d)/jet %d pT < %4.2f",j1,j2,j1,fabs(delta))); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("DpT(jet %d, jet %d)/jet %d pT > %4.2f",j1,j2,j1,fabs(delta))); + } + + + if ( (int)selectedJets_.size() < j1 || (int)selectedJets_.size() < j2 ) + { + std::cout << "-errr- JetAnalyser::selectionJetDptrel(): you dont have enough selected jets. Will return false" << std::endl; + return false; + } + if ( delta > 0 ) + { + if ( fabs(selectedJets_[j1-1]->pt() - selectedJets_[j2-1]->pt())/selectedJets_[j1-1]->pt() > fabs(delta) ) return false; + } + else + { + if ( fabs(selectedJets_[j1-1]->pt() - selectedJets_[j2-1]->pt())/selectedJets_[j1-1]->pt() < fabs(delta) ) return false; + } + + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; + +} +bool JetAnalyser::selectionJetPtImbalance(const int & j1, const int & j2) +{ + bool ok = true; + if (config_->ptimbalmax_ < 0 ) + { + ok = ok && true; + } + else + { + ok = ok && selectionJetPtImbalance(j1,j2,config_->ptimbalmax_); + } + + if (config_->ptimbalmin_ < 0 ) + { + ok = ok && true; + } + else + { + ok = ok && selectionJetPtImbalance(j1,j2,-1*config_->ptimbalmin_); + } + return ok; + +} + +bool JetAnalyser::selectionJetQGlikelihood(const int & r, const float & cut) +{ + int j = r-1; + + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( cut > 0 ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d Q-G likelihood < %4.2f",r,fabs(cut))); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d Q-G likelihood > %4.2f",r,fabs(cut))); + } + + if ( cut > 0 ) + { + if ( selectedJets_[j]->qgLikelihood() > fabs(cut) ) return false; + } + else + { + if ( selectedJets_[j]->qgLikelihood() < fabs(cut) ) return false; + } + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; + +} + +bool JetAnalyser::selectionJetQGlikelihood(const int & r) +{ + int j = r-1; + bool ok = true; + if ( config_->qgmax_.size() == 0 || config_->qgmax_[j] < 0 || (int)config_->qgmax_.size() < r ) + { + ok = ok && true; + } + else + { + ok = ok && selectionJetQGlikelihood(r,config_->qgmax_[j]); + } + + if (config_->qgmin_.size() == 0 || config_->qgmin_[j] < 0 || (int)config_->qgmin_.size() < r ) + { + ok = ok && true; + } + else + { + ok = ok && selectionJetQGlikelihood(r,-1*config_->qgmin_[j] ); + } + return ok; + +} + + +bool JetAnalyser::selectionBJetProbB(const int & r ) +{ + if ( config_->jetsBtagProbB().size() == 0 ) return true; + int j = r-1; + float wp = config_->jetsBtagProbB()[j]; + std::string algo = config_->btagalgo_; + if ( fabs(wp) > 1 ) return true; // there is no selection here, so will not update the cutflow + + ++ cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( wp > 0 ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag prob b < %6.4f",r,algo.c_str(),fabs(wp))); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag prob b > %6.4f",r,algo.c_str(),fabs(wp))); + } + + + if ( r > config_->nbjetsmin_ ) + { + std::cout << "* warning * - JetAnalyser::selectionBJetProbB(): given jet rank > nbjetsmin. Returning false! " << std::endl; + return false; + } + + // jet btag + if ( algo == "deepcsv" ) + { + if ( wp > 0 && selectedJets_[j]->btag("btag_deepb") > fabs(wp) ) return false; + if ( wp < 0 && selectedJets_[j]->btag("btag_deepb") < fabs(wp) ) return false; + } + if ( algo == "deepflavour" ) + { + if ( wp > 0 && selectedJets_[j]->btag("btag_dfb") > fabs(wp) ) return false; + if ( wp < 0 && selectedJets_[j]->btag("btag_dfb") < fabs(wp) ) return false; + } + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + + + + +bool JetAnalyser::selectionBJetProbBB(const int & r ) +{ + if ( config_->jetsBtagProbBB().size() == 0 ) return true; + int j = r-1; + float wp = config_->jetsBtagProbBB()[j]; + std::string algo = config_->btagalgo_; + if ( fabs(wp) > 1 ) return true; // there is no selection here, so will not update the cutflow + + ++ cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( wp > 0 ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag prob bb < %6.4f",r,algo.c_str(),fabs(wp))); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag prob bb > %6.4f",r,algo.c_str(),fabs(wp))); + } + + + if ( r > config_->nbjetsmin_ ) + { + std::cout << "* warning * - JetAnalyser::selectionBJetProbBB(): given jet rank > nbjetsmin. Returning false! " << std::endl; + return false; + } + + // jet btag + if ( algo == "deepcsv" ) + { + if ( wp > 0 && selectedJets_[j]->btag("btag_deepbb") > fabs(wp) ) return false; + if ( wp < 0 && selectedJets_[j]->btag("btag_deepbb") < fabs(wp) ) return false; + } + if ( algo == "deepflavour" ) + { + if ( wp > 0 && selectedJets_[j]->btag("btag_dfbb") > fabs(wp) ) return false; + if ( wp < 0 && selectedJets_[j]->btag("btag_dfbb") < fabs(wp) ) return false; + } + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + +bool JetAnalyser::selectionBJetProbLepB(const int & r ) +{ + if ( config_->jetsBtagProbLepB().size() == 0 ) return true; + int j = r-1; + float wp = config_->jetsBtagProbLepB()[j]; + std::string algo = config_->btagalgo_; + if ( fabs(wp) > 1 || algo == "deepcsv" ) return true; // there is no selection here, so will not update the cutflow + + ++ cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( wp > 0 ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag prob lepb < %6.4f",r,algo.c_str(),fabs(wp))); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag prob lepb > %6.4f",r,algo.c_str(),fabs(wp))); + } + + + if ( r > config_->nbjetsmin_ ) + { + std::cout << "* warning * - JetAnalyser::selectionBJetProbLepB(): given jet rank > nbjetsmin. Returning false! " << std::endl; + return false; + } + + // jet btag + if ( algo == "deepflavour" ) + { + if ( wp > 0 && selectedJets_[j]->btag("btag_dflepb") > fabs(wp) ) return false; + if ( wp < 0 && selectedJets_[j]->btag("btag_dflepb") < fabs(wp) ) return false; + } + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + + + +bool JetAnalyser::selectionBJetProbC(const int & r ) +{ + if ( config_->jetsBtagProbC().size() == 0 ) return true; + int j = r-1; + float wp = config_->jetsBtagProbC()[j]; + std::string algo = config_->btagalgo_; + if ( fabs(wp) > 1 ) return true; // there is no selection here, so will not update the cutflow + + ++ cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( wp > 0 ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag prob c < %6.4f",r,algo.c_str(),fabs(wp))); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag prob c > %6.4f",r,algo.c_str(),fabs(wp))); + } + + + if ( r > config_->nbjetsmin_ ) + { + std::cout << "* warning * - JetAnalyser::selectionBJetProbC(): given jet rank > nbjetsmin. Returning false! " << std::endl; + return false; + } + + // jet btag + if ( algo == "deepcsv" ) + { + if ( wp > 0 && selectedJets_[j]->btag("btag_deepc") > fabs(wp) ) return false; + if ( wp < 0 && selectedJets_[j]->btag("btag_deepc") < fabs(wp) ) return false; + } + if ( algo == "deepflavour" ) + { + if ( wp > 0 && selectedJets_[j]->btag("btag_dfc") > fabs(wp) ) return false; + if ( wp < 0 && selectedJets_[j]->btag("btag_dfc") < fabs(wp) ) return false; + } + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + +bool JetAnalyser::selectionBJetProbG(const int & r ) +{ + if ( config_->jetsBtagProbG().size() == 0 ) return true; + int j = r-1; + float wp = config_->jetsBtagProbG()[j]; + std::string algo = config_->btagalgo_; + if ( fabs(wp) > 1 || algo == "deepcsv" ) return true; // there is no selection here, so will not update the cutflow + + ++ cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( wp > 0 ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag prob g < %6.4f",r,algo.c_str(),fabs(wp))); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag prob g > %6.4f",r,algo.c_str(),fabs(wp))); + } + + + if ( r > config_->nbjetsmin_ ) + { + std::cout << "* warning * - JetAnalyser::selectionBJetProbG(): given jet rank > nbjetsmin. Returning false! " << std::endl; + return false; + } + + // jet btag + if ( algo == "deepflavour" ) + { + if ( wp > 0 && selectedJets_[j]->btag("btag_dfg") > fabs(wp) ) return false; + if ( wp < 0 && selectedJets_[j]->btag("btag_dfg") < fabs(wp) ) return false; + } + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + +bool JetAnalyser::selectionBJetProbLight(const int & r ) +{ + if ( config_->jetsBtagProbLight().size() == 0 ) return true; + int j = r-1; + float wp = config_->jetsBtagProbLight()[j]; + std::string algo = config_->btagalgo_; + if ( fabs(wp) > 1 ) return true; // there is no selection here, so will not update the cutflow + + ++ cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( wp > 0 ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag prob light < %6.4f",r,algo.c_str(),fabs(wp))); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag prob light > %6.4f",r,algo.c_str(),fabs(wp))); + } + + + if ( r > config_->nbjetsmin_ ) + { + std::cout << "* warning * - JetAnalyser::selectionBJetProbLight(): given jet rank > nbjetsmin. Returning false! " << std::endl; + return false; + } + + // jet btag + if ( algo == "deepcsv" ) + { + if ( wp > 0 && selectedJets_[j]->btag("btag_deeplight") > fabs(wp) ) return false; + if ( wp < 0 && selectedJets_[j]->btag("btag_deeplight") < fabs(wp) ) return false; + } + if ( algo == "deepflavour" ) + { + if ( wp > 0 && selectedJets_[j]->btag("btag_dflight") > fabs(wp) ) return false; + if ( wp < 0 && selectedJets_[j]->btag("btag_dflight") < fabs(wp) ) return false; + } + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + + diff --git a/src/MuonAnalyser.cc b/src/MuonAnalyser.cc new file mode 100644 index 00000000..a9f5d9c4 --- /dev/null +++ b/src/MuonAnalyser.cc @@ -0,0 +1,312 @@ +/**\class MuonAnalyser MuonAnalyser.cc Analysis/Tools/src/MuonAnalyser.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Roberval Walsh Bastos Rangel +// Created: Mon, 20 Oct 2014 14:24:08 GMT +// +// + +// system include files +#include "boost/program_options.hpp" +#include "boost/algorithm/string.hpp" +#include +#include +#include +#include +// +// user include files +#include "Analysis/Tools/interface/MuonAnalyser.h" + +// +// class declaration +// + +using namespace analysis; +using namespace analysis::tools; + +MuonAnalyser::MuonAnalyser() +{ +} + + +MuonAnalyser::MuonAnalyser(int argc, char * argv[]) : BaseAnalyser(argc,argv) +{ + // Physics objects + // Muons + muonsanalysis_ = ( analysis_->addTree ("Muons",config_->muonsCollection()) != nullptr ); + +} + +MuonAnalyser::~MuonAnalyser() +{ + // do anything here that needs to be done at desctruction time + // (e.g. close files, deallocate resources etc.) +} + + +// +// member functions +// +// ------------ method called for each event ------------ + +bool MuonAnalyser::analysisWithMuons() +{ + muons_.clear(); + selectedMuons_.clear(); + onlineMatchedMuons_.clear(); + if ( ! muonsanalysis_ ) return false; + + if ( config_->triggerObjectsL1Muons() != "" ) + analysis_->match("Muons",config_->triggerObjectsL1Muons(),0.3); + if ( config_->triggerObjectsL3Muons() != "" ) + analysis_->match("Muons",config_->triggerObjectsL3Muons(),0.3); + + auto muons = analysis_->collection("Muons"); + for ( int j = 0 ; j < muons->size() ; ++j ) muons_.push_back(std::make_shared(muons->at(j))); + + selectedMuons_ = muons_; + + return true; +} + + +std::vector< std::shared_ptr > MuonAnalyser::muons() +{ + return muons_; +} + +std::vector< std::shared_ptr > MuonAnalyser::selectedMuons() +{ + return selectedMuons_; +} + +std::vector< std::shared_ptr > MuonAnalyser::onlineMatchedMuons() +{ + return onlineMatchedMuons_; +} + + + + +// FIXME: need to pass label to the histograms +void MuonAnalyser::muonHistograms(const std::string & obj, const int & n) +{ + if ( obj == "muon" ) + { + for ( int j = 0; j < n; ++j ) + { + h1_[Form("pt_%s%d" , obj.c_str(),j+1)] = std::make_shared(Form("pt_%s%d" , obj.c_str(),j+1) , "" ,100 , 0 , 1000 ); + h1_[Form("eta_%s%d" , obj.c_str(),j+1)] = std::make_shared(Form("eta_%s%d" , obj.c_str(),j+1) , "" , 60 , -3, 3 ); + h1_[Form("phi_%s%d" , obj.c_str(),j+1)] = std::make_shared(Form("phi_%s%d" , obj.c_str(),j+1) , "" , 64 , -3.2, 3.2 ); + } + + } +} + + +bool MuonAnalyser::selectionMuon(const int & r) +{ + bool isgood = true; + ++cutflow_; + int m = r-1; + + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( config_->muonsPtMax().size() > 0 && config_->muonsPtMax()[m] > config_->muonsPtMin()[m] ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Muon %d: pt > %5.1f GeV and pt < %5.1f GeV and |eta| < %3.1f",r,config_->muonsPtMin()[m], config_->muonsPtMax()[m],config_->muonsEtaMax()[m] )); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Muon %d: pt > %5.1f GeV and |eta| < %3.1f",r,config_->muonsPtMin()[m], config_->muonsEtaMax()[m] )); + } + + // kinematic selection + if ( selectedMuons_[m] -> pt() < config_->muonsPtMin()[m] && !(config_->muonsPtMin()[m] < 0) ) return false; + if ( fabs(selectedMuons_[m] -> eta()) > config_->muonsEtaMax()[m] && !(config_->muonsEtaMax()[m] < 0) ) return false; + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return isgood; +} + +bool MuonAnalyser::selectionMuons() +{ + // selectedMuons will be composed of muons with the lowest pt threshold + + bool isgood = true; + ++cutflow_; +// + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + { + if ( config_->muonsPtMax().size() > 0 && config_->muonsPtMax().back() > config_->muonsPtMin().back() ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Muons selected: pt > %5.1f GeV and pt < %5.1f GeV and |eta| < %3.1f", config_->muonsPtMin().back(), config_->muonsPtMax().back(), config_->muonsEtaMax().back() )); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Muons selected: pt > %5.1f GeV and |eta| < %3.1f", config_->muonsPtMin().back(), config_->muonsEtaMax().back() )); + } + + // kinematic selection + auto muon = std::begin(selectedMuons_); + while ( muon != std::end(selectedMuons_) ) + { + if ( config_->muonsPtMax().size() > 0 && config_->muonsPtMax().back() > config_->muonsPtMin().back() ) + { + if ( (*muon)->pt() < config_->muonsPtMin().back() || (*muon)->pt() > config_->muonsPtMax().back() || fabs((*muon)->eta()) > config_->muonsEtaMax().back() ) + muon = selectedMuons_.erase(muon); + else + ++muon; + } + else + { + if ( (*muon)->pt() < config_->muonsPtMin().back() || fabs((*muon)->eta()) > config_->muonsEtaMax().back() ) + muon = selectedMuons_.erase(muon); + else + ++muon; + } + } + if ( (int)selectedMuons_.size() < config_->nMuonsMin() ) return false; + + h1_["cutflow"] -> Fill(cutflow_,weight_); +// + return isgood; +} + + + +bool MuonAnalyser::selectionMuonId() +{ + ++cutflow_; + + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("MuonId: %s",config_->muonsId().c_str())); + + if ( ! muonsanalysis_ ) return false; + + auto muon = std::begin(selectedMuons_); + while ( muon != std::end(selectedMuons_) ) + { + if ( ! (*muon)->id(config_->muonsId() ) ) + muon = selectedMuons_.erase(muon); + else + ++muon; + } + if ( selectedMuons_.size() == 0 ) return false; + + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + +bool MuonAnalyser::selectionNMuons() +{ + ++cutflow_; + + if ((int)selectedMuons_.size() < config_->nMuonsMin()) return false; + + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("NMuons >= %d",config_->nMuonsMin())); + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; + +} + + +bool MuonAnalyser::onlineMuonMatching() +{ + if ( config_->triggerObjectsL1Muons() == "" && config_->triggerObjectsL3Muons() == "" ) return true; + + ++cutflow_; + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,"Muons selected: Online muon matching (L1 and L3)"); + + auto muon = std::begin(selectedMuons_); + while ( muon != std::end(selectedMuons_) ) + { + if ( !((*muon)->matched(config_->triggerObjectsL3Muons()) && (*muon)->matched(config_->triggerObjectsL3Muons()) )) + muon = selectedMuons_.erase(muon); + else + ++muon; + } + + if ( (int)selectedMuons_.size() < config_->nMuonsMin() ) return false; + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + +bool MuonAnalyser::onlineL1MuonMatching(const int & r) +{ + int j = r-1; + if ( config_->triggerObjectsL1Muons() == "" ) return true; + + ++cutflow_; + + if ( r > config_->nMuonsMin() ) + { + std::cout << "*Warning* MuonAnalyser::onlineL1MuonMatching(): asking for matching of unselected muon. Returning false!" << std::endl; + return false; // asking for a match beyond the selection, that's wrong, therefore false + } + if ( selectedMuons_.size() == 0 ) + { + std::cout << "*Warning* MuonAnalyser::onlineL1MuonMatching(): selectedMuons is empty. Returning false!" << std::endl; + return false; // asking for a match beyond the selection, that's wrong, therefore false + } + + if ( ! selectedMuons_[j]->matched(config_->triggerObjectsL1Muons()) ) return false; + + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("L1MuonTriggerMatch_%d",r)); + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + +bool MuonAnalyser::onlineL3MuonMatching(const int & r) +{ + int j = r-1; + if ( config_->triggerObjectsL3Muons() == "" ) return true; + + ++cutflow_; + + if ( r > config_->nMuonsMin() ) + { + std::cout << "*Warning* MuonAnalyser::onlineL3MuonMatching(): asking for matching of unselected muon. Returning false!" << std::endl; + return false; // asking for a match beyond the selection, that's wrong, therefore false + } + if ( selectedMuons_.size() == 0 ) + { + std::cout << "*Warning* MuonAnalyser::onlineL3MuonMatching(): selectedMuons is empty. Returning false!" << std::endl; + return false; // asking for a match beyond the selection, that's wrong, therefore false + } + + if ( ! selectedMuons_[j]->matched(config_->triggerObjectsL3Muons()) ) return false; + + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("L3MuonTriggerMatch_%d",r)); + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + + +// FIXME: need to pass label to the histograms +void MuonAnalyser::fillMuonHistograms() +{ + int n = config_->nMuonsMin(); + + for ( int j = 0; j < n; ++j ) + { + h1_[Form("pt_muon%d",j+1)] -> Fill(selectedMuons_[j]->pt()); + h1_[Form("eta_muon%d",j+1)] -> Fill(selectedMuons_[j]->eta()); + h1_[Form("phi_muon%d",j+1)] -> Fill(selectedMuons_[j]->phi()); + } + +} diff --git a/src/PileupWeight.cc b/src/PileupWeight.cc new file mode 100644 index 00000000..deb8dce8 --- /dev/null +++ b/src/PileupWeight.cc @@ -0,0 +1,86 @@ +/**\class PileupWeight PileupWeight.cc Analysis/Tools/src/PileupWeight.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Roberval Walsh Bastos Rangel +// Created: Mon, 20 Oct 2014 14:24:08 GMT +// +// + +// system include files +// user include files +#include "Analysis/Tools/interface/PileupWeight.h" +#include "TFile.h" + +// +// class declaration +// + +using namespace analysis; +using namespace analysis::tools; + +// +// constructors and destructor +PileupWeight::PileupWeight() +{ +} + +// Main constructor +PileupWeight::PileupWeight(const std::string & fname ) +{ + TH1D * tmp; + std::shared_ptr f = std::make_shared(fname.c_str(),"old"); + tmp = (TH1D*) f->Get("weight_2down"); + if ( tmp ) histos_[-2] = std::make_shared(*tmp); + + tmp = (TH1D*) f->Get("weight_1down"); + if ( tmp ) histos_[-1] = std::make_shared(*tmp); + + tmp = (TH1D*) f->Get("weight"); + if ( tmp ) histos_[0] = std::make_shared(*tmp); + + tmp = (TH1D*) f->Get("weight_1up"); + if ( tmp ) histos_[1] = std::make_shared(*tmp); + + tmp = (TH1D*) f->Get("weight_2up"); + if ( tmp ) histos_[2] = std::make_shared(*tmp); + + if ( ! histos_[-2] ) + std::cout << "WARNING - PileupWeight::PileupWeight | Histogram weight_2down not found. Weight = 1" << std::endl; + if ( ! histos_[-1] ) + std::cout << "WARNING - PileupWeight::PileupWeight | Histogram weight_1down not found. Weight = 1" << std::endl; + if ( ! histos_[0] ) + std::cout << "WARNING - PileupWeight::PileupWeight | Histogram weight not found. Weight = 1" << std::endl; + if ( ! histos_[1] ) + std::cout << "WARNING - PileupWeight::PileupWeight | Histogram weight_1up not found. Weight = 1" << std::endl; + if ( ! histos_[2] ) + std::cout << "WARNING - PileupWeight::PileupWeight | Histogram weight_2up not found. Weight = 1" << std::endl; +} + +PileupWeight::~PileupWeight() +{ + // do anything here that needs to be done at desctruction time + // (e.g. close files, deallocate resources etc.) +} + + +// +// member functions +// +// ------------ method called for each event ------------ + +// output tree +float PileupWeight::weight(const float & truepu, const int & var) +{ + float weight = 1.; + if ( ! histos_[0] ) return weight; + if ( ! histos_[var] ) return weight; + int bin = histos_[var] -> GetBin(truepu); + weight = histos_[var] -> GetBinContent(bin); + return weight; +} + diff --git a/src/TriggerAnalyser.cc b/src/TriggerAnalyser.cc new file mode 100644 index 00000000..bf50e10e --- /dev/null +++ b/src/TriggerAnalyser.cc @@ -0,0 +1,162 @@ +/**\class TriggerAnalyser TriggerAnalyser.cc Analysis/Tools/src/TriggerAnalyser.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Roberval Walsh Bastos Rangel +// Created: Mon, 20 Oct 2014 14:24:08 GMT +// +// + +// system include files +#include "boost/program_options.hpp" +#include "boost/algorithm/string.hpp" +#include +#include +#include +#include +// +// user include files +#include "TString.h" +#include "Analysis/Tools/interface/TriggerAnalyser.h" + +// +// class declaration +// + +using namespace analysis; +using namespace analysis::tools; + +TriggerAnalyser::TriggerAnalyser() +{ +} + + +TriggerAnalyser::TriggerAnalyser(int argc, char * argv[]) : BaseAnalyser(argc,argv) +{ + triggeranalysis_ = false; + if ( config_->triggerResults() != "" ) + triggeranalysis_ = analysis_->triggerResults(config_->triggerResults()); + + if ( config_->triggerObjectsDir() != "" ) + { + // online jets + analysis_->addTree (config_->triggerObjectsL1Jets() ,Form("%s/%s", config_->triggerObjectsDir().c_str(),config_->triggerObjectsL1Jets().c_str())); + analysis_->addTree (config_->triggerObjectsCaloJets(),Form("%s/%s", config_->triggerObjectsDir().c_str(),config_->triggerObjectsCaloJets().c_str())); + analysis_->addTree (config_->triggerObjectsPFJets() ,Form("%s/%s", config_->triggerObjectsDir().c_str(),config_->triggerObjectsPFJets().c_str())); + // online b jets + analysis_->addTree (config_->triggerObjectsBJets(),Form("%s/%s", config_->triggerObjectsDir().c_str(),config_->triggerObjectsBJets().c_str())); + // online muons + analysis_->addTree (config_->triggerObjectsL1Muons(),Form("%s/%s",config_->triggerObjectsDir().c_str(),config_->triggerObjectsL1Muons().c_str())); + analysis_->addTree (config_->triggerObjectsL3Muons(),Form("%s/%s",config_->triggerObjectsDir().c_str(),config_->triggerObjectsL3Muons().c_str())); + } + +} + +TriggerAnalyser::~TriggerAnalyser() +{ + // do anything here that needs to be done at desctruction time + // (e.g. close files, deallocate resources etc.) +} + + +// +// member functions +// +// ------------ method called for each event ------------ + + +bool TriggerAnalyser::selectionTrigger() // Maybe not use this, use selectionHLT and selectionL1 +{ + bool hlt = selectionHLT(); + bool l1 = selectionL1(); + + return (hlt && l1); + +} + +bool TriggerAnalyser::selectionHLT() +{ + if ( config_->hltPath_ == "" ) return true; + + ++cutflow_; + if ( ! analysis_->triggerResult(config_->hltPath_) ) return false; + + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,(config_->hltPath_).c_str()); + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + +bool TriggerAnalyser::selectionL1() +{ + if ( config_->l1Seed_ == "" ) return true; + + ++cutflow_; + if ( ! analysis_->triggerResult(config_->l1Seed_) ) return false; + + if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,(config_->l1Seed_).c_str()); + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; +} + + +bool TriggerAnalyser::analysisWithTrigger() +{ + return triggeranalysis_; +} + + +std::vector< std::shared_ptr > TriggerAnalyser::triggerObjectsL1Jets() +{ + auto collection = analysis_->collection(config_->triggerObjectsL1Jets()); + std::vector< std::shared_ptr > objects; + for ( int j = 0 ; j < collection->size() ; ++j ) + objects.push_back(std::make_shared(collection->at(j))); + return objects; +} + +std::vector< std::shared_ptr > TriggerAnalyser::triggerObjectsCaloJets() +{ + auto collection = analysis_->collection(config_->triggerObjectsCaloJets()); + std::vector< std::shared_ptr > objects; + for ( int j = 0 ; j < collection->size() ; ++j ) + objects.push_back(std::make_shared(collection->at(j))); + return objects; +} + +std::vector< std::shared_ptr > TriggerAnalyser::triggerObjectsPFJets() +{ + auto collection = analysis_->collection(config_->triggerObjectsPFJets()); + std::vector< std::shared_ptr > objects; + for ( int j = 0 ; j < collection->size() ; ++j ) + objects.push_back(std::make_shared(collection->at(j))); + return objects; +} + +std::vector< std::shared_ptr > TriggerAnalyser::triggerObjectsL1Muons() +{ + auto collection = analysis_->collection(config_->triggerObjectsL1Muons()); + std::vector< std::shared_ptr > objects; + for ( int j = 0 ; j < collection->size() ; ++j ) + objects.push_back(std::make_shared(collection->at(j))); + return objects; +} + +std::vector< std::shared_ptr > TriggerAnalyser::triggerObjectsL3Muons() +{ + auto collection = analysis_->collection(config_->triggerObjectsL3Muons()); + std::vector< std::shared_ptr > objects; + for ( int j = 0 ; j < collection->size() ; ++j ) + objects.push_back(std::make_shared(collection->at(j))); + return objects; +} + diff --git a/test/analyser_simple_example.cfg b/test/analyser_simple_example.cfg new file mode 100644 index 00000000..b1ac56e9 --- /dev/null +++ b/test/analyser_simple_example.cfg @@ -0,0 +1,73 @@ +nEventsMax = -1 +ntuplesList = rootFileList.txt +isMC = true +nlo = true +signalRegion = true +output = histograms.root + +# Trigger +triggerResultsCollection = MssmHbb/Events/TriggerResults +triggerObjectsDirectory = MssmHbb/Events/slimmedPatTrigger + +hltPath = HLT_Mu12_DoublePFJets40MaxDeta1p6_DoubleCaloBTagCSV_p33_v +l1Seed = L1_Mu12er2p3_Jet40er2p3_dR_Max0p4_DoubleJet40er2p3_dEta_Max1p6 +triggerObjectsL1Jets = hltL1Mu12er2p3Jet40er2p3dRMax0p4DoubleJet40er2p3dEtaMax1p6_l1jet +triggerObjectsCaloJets = hltDoubleCaloBJets30eta2p3 +triggerObjectsPFJets = hltDoublePFBJets40Eta2p3 +triggerObjectsBJets = hltBTagCalo30x8CSVp0p92DoubleWithMatching +triggerObjectsL1Muons = hltL1Mu12er2p3Jet40er2p3dRMax0p4DoubleJet40er2p3dEtaMax1p6_l1muon +triggerObjectsL3Muons = hltL3fL1sMu12Dijet40L1f0L2f8L3Filtered12 + +# Muons +muonsCollection = MssmHbb/Events/slimmedMuons +nMuonsMin = 1 +muonsId = tight +muonsPtMin = 13. +muonsEtaMax = 2.2 + +# Jets +jetsCollection = MssmHbb/Events/updatedPatJets +# all dijet combinations split by flavour +doDijetFlavour = true +# the collection below is needed for extended jet flavour +genparticlesCollection = MssmHbb/Events/prunedGenParticles +useJetsExtendedFlavour = true + +# to apply JER smearing +genjetsCollection = MssmHbb/Events/slimmedGenJets +jerPtRes = Fall17_V3_MC_PtResolution_AK4PFchs.txt +jerSF = Fall17_V3_MC_SF_AK4PFchs.txt + +# apply regression +bRegression = true + +# jet selection +nJetsMin = 2 +jetsId = tight +jetsPuId = loose +dRMin = 1.0 +dEtaMax = 1.5 + +# jet pt +# ranked jets in pt, the order below matters +jetsPtMin = 57 +jetsPtMin = 47 + +# jet eta +# ranked jets in pt, the order below matters +jetsEtaMax = 2.2 +jetsEtaMax = 2.2 + +# mass +massMin = 100. +massMax = 1000. + +# Btag +nBJetsMin = 2 +btagAlgorithm = deepflavour +btagLoose = 0.0521 +btagMedium = 0.3033 +btagTight = 0.7489 +btagSF = DeepFlavour_94XSF_V1_B_F.csv +jetsBtagWP = medium +jetsBtagWP = medium diff --git a/test/analyser_trigger_example.cfg b/test/analyser_trigger_example.cfg new file mode 100644 index 00000000..fc2234a6 --- /dev/null +++ b/test/analyser_trigger_example.cfg @@ -0,0 +1,23 @@ +#### General stuff +nEventsMax = -1 +ntuplesList = rootFileList.txt +isMC = true +output = histograms.root + +#### Trigger +triggerResultsCollection = MssmHbb/Events/TriggerResults +hltPath = HLT_Mu12_DoublePFJets40MaxDeta1p6_DoubleCaloBTagCSV_p33_v +l1Seed = L1_Mu12er2p3_Jet40er2p3_dR_Max0p4_DoubleJet40er2p3_dEta_Max1p6 + +#### Trigger objects +triggerObjectsDirectory = MssmHbb/Events/slimmedPatTrigger +# online jets +triggerObjectsL1Jets = hltL1Mu12er2p3Jet40er2p3dRMax0p4DoubleJet40er2p3dEtaMax1p6_l1jet +triggerObjectsCaloJets = hltDoubleCaloBJets30eta2p3 +triggerObjectsPFJets = hltDoublePFBJets40Eta2p3 +# online btag +triggerObjectsBJets = hltBTagCalo30x8CSVp0p92DoubleWithMatching +# online muons +triggerObjectsL1Muons = hltL1Mu12er2p3Jet40er2p3dRMax0p4DoubleJet40er2p3dEtaMax1p6_l1muon +triggerObjectsL3Muons = hltL3fL1sMu12Dijet40L1f0L2f8L3Filtered12 + diff --git a/test/analysis_bjets.cfg b/test/analysis_bjets.cfg deleted file mode 100644 index 1fa43881..00000000 --- a/test/analysis_bjets.cfg +++ /dev/null @@ -1,12 +0,0 @@ -nEventsMax = -1 -ntuplesList = analysis_bjets.ntuples -isMC = true -# Jets -jetsCollection = MssmHbb/Events/updatedPatJets - -# Btag -nBJetsMin = 1 -btagAlgorithm = DeepCSV -jetsBtagMin = 0.8001 -# scale factors -btagSF = ../data/DeepCSV_94XSF_V3_B_F.csv diff --git a/test/analysis_bjets.ntuples b/test/analysis_bjets.ntuples deleted file mode 100644 index 3218c708..00000000 --- a/test/analysis_bjets.ntuples +++ /dev/null @@ -1 +0,0 @@ -/pnfs/desy.de/cms/tier2/store/user/rwalsh/Analysis/Ntuples/MC/Fall17/ntuplizer_94X_mc_2017_fall17-v3/SUSYGluGluToBBHToBB_NarrowWidth_M-350_TuneCP5_13TeV-pythia8/RunIIFall17MiniAODv2-PU2017_12Apr2018_94X_mc2017_realistic_v14-v1/180730_160336/0000/ntuple_1-1.root diff --git a/test/analysis_bjets_94Xv4.ntuples b/test/analysis_bjets_94Xv4.ntuples deleted file mode 100644 index 4f54d31f..00000000 --- a/test/analysis_bjets_94Xv4.ntuples +++ /dev/null @@ -1 +0,0 @@ -/pnfs/desy.de/cms/tier2/store/user/rwalsh/Analysis/Ntuples/MC/Fall17/ntuplizer_94X_mc_2017_fall17-v4/SUSYGluGluToBBHToBB_M-500_TuneCP5_13TeV-amcatnlo-pythia8/RunIIFall17MiniAODv2-PU2017_12Apr2018_94X_mc2017_realistic_v14-v1/190114_170442/0000/ntuple_1-1.root diff --git a/test/analysis_bjetsv2.cfg b/test/analysis_bjetsv2.cfg deleted file mode 100644 index 8fd3bab7..00000000 --- a/test/analysis_bjetsv2.cfg +++ /dev/null @@ -1,16 +0,0 @@ -nEventsMax = -1 -ntuplesList = analysis_bjets.ntuples -isMC = true -# Jets -jetsCollection = MssmHbb/Events/updatedPatJets - -# Btag -nBJetsMin = 1 -btagAlgorithm = DeepCSV -btagWorkingPoint = LOOSE -# btag working points definitions for 2017 DeepCSV -btagWPLoose = 0.1522 -btagWPMedium = 0.4941 -btagWPTight = 0.8001 -# scale factors -btagSF = /afs/desy.de/user/w/walsh/cms/analysis/cmssw/mssmhbb/2017/CMSSW_9_4_9/src/Analysis/Tools/data/DeepCSV_94XSF_V3_B_F.csv diff --git a/test/analysis_deepflavour.cfg b/test/analysis_deepflavour.cfg deleted file mode 100644 index 5e31468b..00000000 --- a/test/analysis_deepflavour.cfg +++ /dev/null @@ -1,16 +0,0 @@ -nEventsMax = -1 -ntuplesList = analysis_bjets_94Xv4.ntuples -isMC = true -# Jets -jetsCollection = MssmHbb/Events/updatedPatJets - -# Btag -nBJetsMin = 1 -btagAlgorithm = DeepFlavour -btagWorkingPoint = LOOSE -# btag working points definitions for 2017 DeepFlavour -btagWPLoose = 0.0521 -btagWPMedium = 0.3033 -btagWPTight = 0.7489 -# scale factors -btagSF = /afs/desy.de/user/w/walsh/cms/analysis/cmssw/mssmhbb/2017/CMSSW_9_4_12/src/Analysis/Tools/data/DeepFlavour_94XSF_V1_B_F.csv diff --git a/test/analysis_genparticles.cfg b/test/analysis_genparticles.cfg deleted file mode 100644 index dc4ce75f..00000000 --- a/test/analysis_genparticles.cfg +++ /dev/null @@ -1,5 +0,0 @@ -nEventsMax = 1 -ntuplesList = analysis_genpart.ntuples -isMC = true -# GenParticle -genParticleCollection = MssmHbb/Events/prunedGenParticles diff --git a/test/analysis_genparticles.ntuples b/test/analysis_genparticles.ntuples deleted file mode 100644 index 5994df4f..00000000 --- a/test/analysis_genparticles.ntuples +++ /dev/null @@ -1 +0,0 @@ -/pnfs/desy.de/cms/tier2/store/user/rwalsh/Analysis/Ntuples/MC/Fall17/ntuplizer_94X_mc_2017_fall17-v3/QCD_Pt_1000to1400_TuneCP5_13TeV_pythia8/RunIIFall17MiniAODv2-PU2017_12Apr2018_94X_mc2017_realistic_v14-v1/180926_162754/0000/ntuple_1-2.root diff --git a/test/analysis_jets_example.cfg b/test/analysis_jets_example.cfg new file mode 100644 index 00000000..518233e2 --- /dev/null +++ b/test/analysis_jets_example.cfg @@ -0,0 +1,37 @@ +nEventsMax = 100 +ntuplesList = rootFileList.txt +isMC = true +# Jets +jetsCollection = MssmHbb/Events/updatedPatJets +# GenParticle +genParticleCollection = MssmHbb/Events/prunedGenParticles +# GenJets +genjetsCollection = MssmHbb/Events/slimmedGenJets + +# Jets +jerPT = /afs/desy.de/user/w/walsh/cms/analysis/cmssw/dev/CMSSW_9_4_13_patch3/src/Analysis/Tools/data/Fall17_V3_MC_PtResolution_AK4PFchs.txt +jerSF = /afs/desy.de/user/w/walsh/cms/analysis/cmssw/dev/CMSSW_9_4_13_patch3/src/Analysis/Tools/data/Fall17_V3_MC_SF_AK4PFchs.txt + +# Btag +nBJetsMin = 1 +btagWorkingPoint = MEDIUM + +# #### DeepCSV +# btagAlgorithm = DeepCSV +# # btag working points definitions for 2017 DeepCSV +# btagWPLoose = 0.1522 +# btagWPMedium = 0.4941 +# btagWPTight = 0.8001 +# # scale factors +# btagSF = /afs/desy.de/user/w/walsh/cms/analysis/cmssw/dev/CMSSW_9_4_13_patch3/src/Analysis/Tools/data/DeepCSV_94XSF_V3_B_F.csv + +#### DeepFlavour +btagAlgorithm = DeepFlavour +# btag working points definitions for 2017 DeepFlavour +btagWPLoose = 0.0521 +btagWPMedium = 0.3033 +btagWPTight = 0.7489 +# scale factors +btagSF = /afs/desy.de/user/w/walsh/cms/analysis/cmssw/dev/CMSSW_9_4_13_patch3/src/Analysis/Tools/data/DeepFlavour_94XSF_V1_B_F.csv + + diff --git a/test/analysis_jets_jer.cfg b/test/analysis_jets_jer.cfg deleted file mode 100644 index ffb1dac8..00000000 --- a/test/analysis_jets_jer.cfg +++ /dev/null @@ -1,13 +0,0 @@ -nEventsMax = -1 -#ntuplesList = analysis_bjets.ntuples -ntuplesList = analysis_bjets_94Xv4.ntuples -isMC = true -# Jets -jetsCollection = MssmHbb/Events/updatedPatJets -genjetsCollection = MssmHbb/Events/slimmedGenJets - -# JER -#jerPT = /afs/desy.de/user/w/walsh/cms/analysis/cmssw/mssmhbb/2017/CMSSW_9_4_12/src/Analysis/Tools/data/Summer16_25nsV1_MC_PtResolution_AK4PFchs.txt -#jerSF = /afs/desy.de/user/w/walsh/cms/analysis/cmssw/mssmhbb/2017/CMSSW_9_4_12/src/Analysis/Tools/data/Summer16_25nsV1_MC_SF_AK4PFchs.txt -jerPT = /afs/desy.de/user/w/walsh/cms/analysis/cmssw/mssmhbb/2017/CMSSW_9_4_12/src/Analysis/Tools/data/Fall17_V3_MC_PtResolution_AK4PFchs.txt -jerSF = /afs/desy.de/user/w/walsh/cms/analysis/cmssw/mssmhbb/2017/CMSSW_9_4_12/src/Analysis/Tools/data/Fall17_V3_MC_SF_AK4PFchs.txt diff --git a/test/analysis_muonjet.cfg b/test/analysis_muonjet.cfg deleted file mode 100644 index 98bec52a..00000000 --- a/test/analysis_muonjet.cfg +++ /dev/null @@ -1,7 +0,0 @@ -nEventsMax = -1 -ntuplesList = analysis_bjets.ntuples -isMC = true -# Jets -jetsCollection = MssmHbb/Events/updatedPatJets -# Muons -muonsCollection = MssmHbb/Events/slimmedMuons diff --git a/test/analysis_trigger_example.cfg b/test/analysis_trigger_example.cfg new file mode 100644 index 00000000..4d9b7cde --- /dev/null +++ b/test/analysis_trigger_example.cfg @@ -0,0 +1,19 @@ +#### General stuff +nEventsMax = 100 +ntuplesList = rootFileList.txt +isMC = true + +#### Trigger +triggerResultsCollection = MssmHbb/Events/TriggerResults +hltPath = HLT_DoublePFJets100MaxDeta1p6_DoubleCaloBTagCSV_p33_v +l1Seed = L1_DoubleJet100er2p3_dEta_Max1p6 + +#### Trigger objects +triggerObjectsDirectory = MssmHbb/Events/slimmedPatTrigger +# online jets +triggerObjectsJets = hltL1DoubleJet100er2p3dEtaMax1p6Ior112er2p3dEtaMax1p6 +triggerObjectsJets = hltDoubleCaloBJets100eta2p3 +triggerObjectsJets = hltBTagCalo80x6CSVp0p92DoubleWithMatching +triggerObjectsJets = hltDoublePFJets100Eta2p3 + + diff --git a/test/naf_submit.csh b/test/naf_submit.csh deleted file mode 100755 index 3fa8e8ea..00000000 --- a/test/naf_submit.csh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/csh -f - -if ( $#argv < 3 ) then - echo Need to give sample name, the macro name and the number of splits - exit -endif - -set rootfilelist = $1 -set macro = $2 -set nsplit = $3 - - -./split.csh $nsplit $rootfilelist - -set files = `/bin/ls *_x???.txt` - -foreach file ( $files ) - - set counter = `basename $file .txt | awk -F "x" '{print $2}'` - set exedir = "NAF_"$macro"_"$counter - if ( -d $exedir ) then - echo "Similar jobs were already submitted. Move ot remove directories NAF_"$macro"_* and resubmit" - exit - endif - mkdir -p $exedir - cd $exedir - mv ../$file ./rootFileList.txt - if ( -e ../json.txt ) then - cp -p ../json.txt . - endif - ../qsub.sh $macro - sleep 5 - cd - -end - - -exit - - - - -#./qsub.sh $exeName $sampleName diff --git a/test/ntuple_diagnostics.cfg b/test/ntuple_diagnostics.cfg deleted file mode 100644 index 30f42811..00000000 --- a/test/ntuple_diagnostics.cfg +++ /dev/null @@ -1,3 +0,0 @@ -## Example configuration for the NtupleDiagnostics macro - -ntuplesList = ntuples_2017C_v1.txt diff --git a/test/ntuplizer_data.py b/test/ntuplizer_data.py deleted file mode 100644 index 03e149e1..00000000 --- a/test/ntuplizer_data.py +++ /dev/null @@ -1,144 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -process = cms.Process("MssmHbb") - -process.load("FWCore.MessageService.MessageLogger_cfi") -process.MessageLogger.cerr.FwkReport.reportEvery = cms.untracked.int32(1000) - -## Using MINIAOD. GlobalTag just in case jet re-clustering, L1 trigger filter etc is needed to be done -process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") -from Configuration.AlCa.GlobalTag_condDBv2 import GlobalTag as customiseGlobalTag -process.GlobalTag = customiseGlobalTag(process.GlobalTag, globaltag = '74X_dataRun2_v5') -process.GlobalTag.connect = 'frontier://FrontierProd/CMS_CONDITIONS' -process.GlobalTag.pfnPrefix = cms.untracked.string('frontier://FrontierProd/') -for pset in process.GlobalTag.toGet.value(): - pset.connect = pset.connect.value().replace('frontier://FrontierProd/', 'frontier://FrontierProd/') -## fix for multi-run processing -process.GlobalTag.RefreshEachRun = cms.untracked.bool( False ) -process.GlobalTag.ReconnectEachRun = cms.untracked.bool( False ) - -process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) ) - -output_file = 'ntuple.root' -## TFileService -process.TFileService = cms.Service("TFileService", - fileName = cms.string(output_file) -) - -## ============ TRIGGER FILTER =============== -## Enable below at cms.Path if needed -process.triggerSelection = cms.EDFilter( "TriggerResultsFilter", - triggerConditions = cms.vstring( - "HLT_ZeroBias_v*", - ), - hltResults = cms.InputTag( "TriggerResults", "", "HLT" ), - l1tResults = cms.InputTag( "" ), - l1tIgnoreMask = cms.bool( False ), - l1techIgnorePrescales = cms.bool( False ), - daqPartitions = cms.uint32( 1 ), - throw = cms.bool( True ) -) - - -## ============ EVENT FILTER COUNTER =============== -## Filter counter (maybe more useful for MC) -process.TotalEvents = cms.EDProducer("EventCountProducer") -process.FilteredEvents = cms.EDProducer("EventCountProducer") - -## ============ PRIMARY VERTEX FILTER =============== -process.primaryVertexFilter = cms.EDFilter("VertexSelector", - src = cms.InputTag("offlineSlimmedPrimaryVertices"), # primary vertex collection name - cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"), # ndof>thr=4 corresponds to sum(track_weigths) > (thr+3)/2 = 3.5 so typically 4 good tracks - filter = cms.bool(True), # otherwise it won't filter the events, just produce an empty vertex collection. -) - -## ============ THE NTUPLIZER!!! =============== -process.MssmHbb = cms.EDAnalyzer("Ntuplizer", - MonteCarlo = cms.bool(False), - UseFullName = cms.bool(False), - ################### - TotalEvents = cms.InputTag("TotalEvents"), - FilteredEvents = cms.InputTag("FilteredEvents"), - PatJets = cms.VInputTag( - cms.InputTag("slimmedJetsPuppi"), - cms.InputTag("slimmedJets"), -# cms.InputTag("slimmedJetsAK8PFCHSSoftDropPacked","SubJets","PAT") - ), -# PatMETs = cms.VInputTag( -# cms.InputTag("slimmedMETs"), -# cms.InputTag("slimmedMETsPuppi") -# ), - PatMuons = cms.VInputTag( - cms.InputTag("slimmedMuons") - ), - PrimaryVertices = cms.VInputTag( - cms.InputTag("offlineSlimmedPrimaryVertices") - ), - BTagAlgorithms = cms.vstring ( - "pfCombinedInclusiveSecondaryVertexV2BJetTags", -# "combinedSecondaryVertexBJetTags", -# "pfJetBProbabilityBJetTags", -# "pfJetProbabilityBJetTags", -# "pfTrackCountingHighPurBJetTags", -# "pfTrackCountingHighEffBJetTags", -# "pfSimpleSecondaryVertexHighEffBJetTags", -# "pfSimpleSecondaryVertexHighPurBJetTags", -# "pfCombinedSecondaryVertexV2BJetTags", -# "pfCombinedSecondaryVertexSoftLeptonBJetTags", -# "pfCombinedMVABJetTags", - ), - BTagAlgorithmsAlias = cms.vstring ( - "btag_csvivf", -# "btag_csv", -# "btag_jetbprob", -# "btag_jetprob", -# "btag_tchp", -# "btag_tche", -# "btag_svhe", -# "btag_svhp", -# "btag_csvv2", -# "btag_csvlep", -# "btag_csvmva", - ), - TriggerResults = cms.VInputTag(cms.InputTag("TriggerResults","","HLT")), - TriggerPaths = cms.vstring ( - ## I recommend using the version number explicitly to be able to compare - ## however for production one has to be careful that all versions are included. - ## Thinking of a better solution... - "HLT_ZeroBias_v", - ), -# TriggerObjectStandAlone = cms.VInputTag( -# cms.InputTag("selectedPatTrigger"), -# ), -# TriggerObjectLabels = cms.vstring ( -# "hltL1sL1DoubleJetC100", -# ), - L1ExtraJets = cms.VInputTag( - cms.InputTag("l1extraParticles","Central","RECO"), -# cms.InputTag("l1extraParticles","Forward","RECO"), -# cms.InputTag("l1extraParticles","Tau","RECO") - ), - L1ExtraMuons = cms.VInputTag( - cms.InputTag("l1extraParticles","","RECO") - ), -) - -process.p = cms.Path( - process.TotalEvents * - process.triggerSelection * - process.primaryVertexFilter * - process.FilteredEvents * - process.MssmHbb - ) - - -readFiles = cms.untracked.vstring() -secFiles = cms.untracked.vstring() -process.source = cms.Source ("PoolSource",fileNames = readFiles, secondaryFileNames = secFiles) -readFiles.extend( [ - '/store/data/Run2015D/ZeroBias/MINIAOD/05Oct2015-v1/30000/CE916313-4B6F-E511-BD1E-00261894393D.root', -] ); - - -secFiles.extend( [ - ] ) diff --git a/test/ntuplizer_mc.py b/test/ntuplizer_mc.py deleted file mode 100644 index 0b225f7d..00000000 --- a/test/ntuplizer_mc.py +++ /dev/null @@ -1,171 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -process = cms.Process("MssmHbb") - -process.load("FWCore.MessageService.MessageLogger_cfi") -process.MessageLogger.cerr.FwkReport.reportEvery = cms.untracked.int32(1000) - -## Using MINIAOD. GlobalTag just in case jet re-clustering, L1 trigger filter etc is needed to be done -process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") -from Configuration.AlCa.GlobalTag_condDBv2 import GlobalTag as customiseGlobalTag -process.GlobalTag = customiseGlobalTag(process.GlobalTag, globaltag = '74X_mcRun2_asymptotic_v2') -process.GlobalTag.connect = 'frontier://FrontierProd/CMS_CONDITIONS' -process.GlobalTag.pfnPrefix = cms.untracked.string('frontier://FrontierProd/') -for pset in process.GlobalTag.toGet.value(): - pset.connect = pset.connect.value().replace('frontier://FrontierProd/', 'frontier://FrontierProd/') -## fix for multi-run processing -process.GlobalTag.RefreshEachRun = cms.untracked.bool( False ) -process.GlobalTag.ReconnectEachRun = cms.untracked.bool( False ) - -process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(100) ) - -output_file = 'ntuple.root' -## TFileService -process.TFileService = cms.Service("TFileService", - fileName = cms.string(output_file) -) - -## ============ TRIGGER FILTER =============== -## Enable below at cms.Path if needed -process.triggerSelection = cms.EDFilter( "TriggerResultsFilter", - triggerConditions = cms.vstring( - "HLT_ZeroBias_v*", - ), - hltResults = cms.InputTag( "TriggerResults", "", "HLT" ), - l1tResults = cms.InputTag( "" ), - l1tIgnoreMask = cms.bool( False ), - l1techIgnorePrescales = cms.bool( False ), - daqPartitions = cms.uint32( 1 ), - throw = cms.bool( True ) -) - - -## ============ EVENT FILTER COUNTER =============== -## Filter counter (maybe more useful for MC) -process.TotalEvents = cms.EDProducer("EventCountProducer") -process.FilteredEvents = cms.EDProducer("EventCountProducer") - -## ============ PRIMARY VERTEX FILTER =============== -process.primaryVertexFilter = cms.EDFilter("VertexSelector", - src = cms.InputTag("offlineSlimmedPrimaryVertices"), # primary vertex collection name - cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"), # ndof>thr=4 corresponds to sum(track_weigths) > (thr+3)/2 = 3.5 so typically 4 good tracks - filter = cms.bool(True), # otherwise it won't filter the events, just produce an empty vertex collection. -) - -## ============ THE NTUPLIZER!!! =============== -process.MssmHbb = cms.EDAnalyzer("Ntuplizer", - MonteCarlo = cms.bool(True), - CrossSection = cms.double(1), # in pb - UseFullName = cms.bool(False), - ## Monte Carlo only - GenFilterInfo = cms.InputTag("genFilterEfficiencyProducer"), - GenRunInfo = cms.InputTag("generator"), - GenJets = cms.VInputTag(cms.InputTag("slimmedGenJets")), - GenParticles = cms.VInputTag(cms.InputTag("prunedGenParticles")), - ################### - TotalEvents = cms.InputTag("TotalEvents"), - FilteredEvents = cms.InputTag("FilteredEvents"), - PatJets = cms.VInputTag( - cms.InputTag("slimmedJetsPuppi"), -# cms.InputTag("slimmedJetsAK8PFCHSSoftDropPacked","SubJets","PAT") - ), - PatMETs = cms.VInputTag( - cms.InputTag("slimmedMETs"), - cms.InputTag("slimmedMETsPuppi") - ), - PatMuons = cms.VInputTag( - cms.InputTag("slimmedMuons") - ), - PrimaryVertices = cms.VInputTag( - cms.InputTag("offlineSlimmedPrimaryVertices") - ), - BTagAlgorithms = cms.vstring ( - "pfCombinedInclusiveSecondaryVertexV2BJetTags", - "combinedSecondaryVertexBJetTags", - "pfJetBProbabilityBJetTags", - "pfJetProbabilityBJetTags", - "pfTrackCountingHighPurBJetTags", - "pfTrackCountingHighEffBJetTags", - "pfSimpleSecondaryVertexHighEffBJetTags", - "pfSimpleSecondaryVertexHighPurBJetTags", - "pfCombinedSecondaryVertexV2BJetTags", - "pfCombinedSecondaryVertexSoftLeptonBJetTags", - "pfCombinedMVABJetTags", - ), - BTagAlgorithmsAlias = cms.vstring ( - "btag_csvivf", - "btag_csv", - "btag_jetbprob", - "btag_jetprob", - "btag_tchp", - "btag_tche", - "btag_svhe", - "btag_svhp", - "btag_csvv2", - "btag_csvlep", - "btag_csvmva", - ), - TriggerResults = cms.VInputTag(cms.InputTag("TriggerResults","","HLT")), - TriggerPaths = cms.vstring ( - ## I recommend using the version number explicitly to be able to compare - ## however for production one has to be careful that all versions are included. - ## Thinking of a better solution... - "HLT_DoubleJetsC100_DoubleBTagCSV0p9_DoublePFJetsC100MaxDeta1p6_v1", - "HLT_DoubleJetsC100_DoubleBTagCSV0p85_DoublePFJetsC160_v1", - "HLT_DoubleJetsC112_DoubleBTagCSV0p9_DoublePFJetsC112MaxDeta1p6_v1", - "HLT_DoubleJetsC112_DoubleBTagCSV0p85_DoublePFJetsC172_v1", - "HLT_DoubleJet90_Double30_TripleBTagCSV0p67_v2", - "HLT_QuadJet45_DoubleBTagCSV0p67_v2", - "HLT_QuadJet45_TripleBTagCSV0p67_v2", - "HLT_QuadPFJet_DoubleBTagCSV_VBF_Mqq200_v2", - "HLT_QuadPFJet_DoubleBTagCSV_VBF_Mqq240_v2", - "HLT_QuadPFJet_SingleBTagCSV_VBF_Mqq460_v2", - "HLT_QuadPFJet_SingleBTagCSV_VBF_Mqq500_v2", - ), - TriggerObjectStandAlone = cms.VInputTag( - cms.InputTag("selectedPatTrigger"), - ), - TriggerObjectLabels = cms.vstring ( - "hltL1sL1DoubleJetC100", - "hltDoubleJetsC100", - "hltDoublePFJetsC100", - "hltDoublePFJetsC100MaxDeta1p6", - "hltDoublePFJetsC160", - "hltDoubleBTagCSV0p85", - "hltDoubleBTagCSV0p9", - "hltL1sL1DoubleJetC112", - "hltDoubleJetsC112", - "hltDoublePFJetsC112", - "hltDoublePFJetsC112MaxDeta1p6", - "hltDoublePFJetsC172", - ), -# L1ExtraJets = cms.VInputTag( -# cms.InputTag("l1extraParticles","Central","RECO"), -# cms.InputTag("l1extraParticles","Forward","RECO"), -# cms.InputTag("l1extraParticles","Tau","RECO") -# ), -# L1ExtraMuons = cms.VInputTag( -# cms.InputTag("l1extraParticles","","RECO") -# ), -) - -process.p = cms.Path( - process.TotalEvents * - process.primaryVertexFilter * - process.FilteredEvents * - process.MssmHbb - ) - - -readFiles = cms.untracked.vstring() -secFiles = cms.untracked.vstring() -process.source = cms.Source ("PoolSource",fileNames = readFiles, secondaryFileNames = secFiles) -readFiles.extend( [ -# '/store/mc/RunIISpring15DR74/SUSYGluGluToBBHToBB_M-300_TuneCUETP8M1_13TeV-pythia8/MINIAODSIM/Asympt25ns_MCRUN2_74_V9-v2/50000/38C86330-3F13-E511-86E6-002590A37106.root', - '/store/mc/RunIISpring15MiniAODv2/QCD_Pt_120to170_TuneCUETP8M1_13TeV_pythia8/MINIAODSIM/74X_mcRun2_asymptotic_v2-v1/40000/000CFC54-C771-E511-9586-002354EF3BE2.root', -] ); - - -secFiles.extend( [ - ] ) - diff --git a/test/qsub.sh b/test/qsub.sh deleted file mode 100755 index 9e4a7509..00000000 --- a/test/qsub.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh -# $1 - code name -cat > $1.zsh <