diff --git a/interface/Config.h b/interface/Config.h index b52112cd..f59ec321 100644 --- a/interface/Config.h +++ b/interface/Config.h @@ -109,6 +109,9 @@ namespace analysis { std::string jerPtRes() const; std::string jerSF() const; std::string l1tJetsCollection() const; + + std::string btagAlgorithm() const; + std::string btagScaleFactors() const; std::vector jetsBtagWP() const; std::vector jetsBtagProbB() const; std::vector jetsBtagProbBB() const; @@ -123,8 +126,22 @@ namespace analysis { bool doDijet() const; bool doDijetFlavour() const; int nBJetsMin() const; + + std::vector jetsQGmin() const; + std::vector jetsQGmax() const; + + // jet-jet + float jetsDetaMax() const; + float jetsDetaMin() const; + float jetsDphiMax() const; + float jetsDphiMin() const; + float jetsDrMax() const; + float jetsDrMin() const; + float jetsPtImbalanceMax() const; + float jetsPtImbalanceMin() const; + // muons std::string muonsCollection() const; int nMuonsMin() const; @@ -195,7 +212,6 @@ namespace analysis { // btag SF csv file - std::string btagsf_; std::vector jetsbtagmin_; // additional cuts of unidentified objects or for extra selections @@ -205,12 +221,6 @@ namespace analysis { std::vector ptmax_; std::vector etamax_; - float jetsdrmin_; - float jetsdrmax_; - float jetsdetamax_; - float jetsdetamin_; - float jetsdphimin_; - float jetsdphimax_; float drmin_; @@ -220,15 +230,6 @@ namespace analysis { float dphimin_; float dphimax_; - float ptimbalmax_; - float ptimbalmin_; - - std::vector qgmin_; - std::vector qgmax_; - - std::string btagalgo_; - - std::string hltPath_; std::string l1Seed_; @@ -293,12 +294,29 @@ namespace analysis { std::string jetsid_; std::string jetspuid_; + std::vector qgmin_; + std::vector qgmax_; + + float jetsdetamax_; + float jetsdetamin_; + float jetsdphimin_; + float jetsdphimax_; + float jetsdrmin_; + float jetsdrmax_; + float jetsptimbalmax_; + float jetsptimbalmin_; + // JER resolution and scale factors from txt file std::string jerptres_; std::string jersf_; // std::string l1tjetsCol_; // + // + std::string btagalgo_; + std::string btagsf_; + + std::vector jetsbtagwp_; std::string nonbtagwp_; int nonbtagjet_; diff --git a/interface/JetAnalyser.h b/interface/JetAnalyser.h index 938778aa..621a1a13 100644 --- a/interface/JetAnalyser.h +++ b/interface/JetAnalyser.h @@ -61,24 +61,41 @@ namespace analysis { private: public: + /// vector of pointers of the selectedJets std::vector< std::shared_ptr > selectedJets(); + /// vector of pointers of all jets from the "Jets" collection std::vector< std::shared_ptr > jets(); - float btag(const Jet & , const std::string & ); + + /// Returns the btag value of the jet for a given btag algorithm + float btag(const Jet & jet, const std::string & algo); - // Sets - void jets(const std::string &); + /// Creates the "Jets" collection + void jets(const std::string & col); // 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 &); + /// Given the ranking 'r' of a jet, it returns whether the jet passes the pt_min and |eta_max|, optionally pt_max, where the values of the thresholds pt_min and |eta_max|, pt_max are passed by configuration file + virtual bool selectionJet(const int & r); + /// Given the ranking 'r' of a jet, it returns whether the jet passes the pt_min and |eta_max|, optionally pt_max, where the values of the thresholds pt_min and |eta_max|, pt_max (opt) are passed as arguments + virtual bool selectionJet(const int & r, const float & pt_min, const float &eta_max, const float &pt_max=-1. ); + /// Given the rankings r1 and r2 of two jets, it returns whether the jets passes the delta_eta selection; the threshold delta is passed by the configuration file + virtual bool selectionJetDeta(const int & r1, const int &r2); + /// Given the rankings r1 and r2 of two jets, it returns whether the jets passes the delta_eta selection; the threshold delta is passed as an argument (if delta <= 0, |delta| = delta_min; else |delta| = delta_max ) + virtual bool selectionJetDeta(const int & r1, const int & r2, const float & delta); + /// Given the rankings r1 and r2 of two jets, it returns whether the jets passes the delta_phi selection; the threshold delta is passed by the configuration file + virtual bool selectionJetDphi(const int & r1, const int & r2); + /// Given the rankings r1 and r2 of two jets, it returns whether the jets passes the delta_phi selection; the threshold delta is passed as an argument (if delta <= 0, |delta| = delta_min; else |delta| = delta_max ) + virtual bool selectionJetDphi(const int & r1, const int & r2, const float & delta); + /// Given the rankings r1 and r2 of two jets, it returns whether the jets passes the delta_R selection; the threshold delta is passed by the configuration file + virtual bool selectionJetDr(const int & r1, const int & r2); + /// Given the rankings r1 and r2 of two jets, it returns whether the jets passes the delta_R selection; the threshold delta is passed as an argument (if delta <= 0, |delta| = delta_min; else |delta| = delta_max ) + virtual bool selectionJetDr(const int & r1, const int & r2, const float & delta); + /// Given the rankings r1 and r2 of two jets, it returns whether the jets passes the pt imbalance selection; the threshold delta is passed by the configuration file + virtual bool selectionJetPtImbalance(const int & r1, const int & r2); + /// Given the rankings r1 and r2 of two jets, it returns whether the jets passes the pt imbalance selection; the threshold delta is passed as an argument (if delta <= 0, |delta| = delta_min; else |delta| = delta_max ) + virtual bool selectionJetPtImbalance(const int & r1, const int & r2, const float & delta); + + virtual bool selectionJetId(); virtual bool selectionJetPileupId(); virtual bool selectionNJets(); diff --git a/src/Config.cc b/src/Config.cc index 15fa8f4f..0831dc29 100644 --- a/src/Config.cc +++ b/src/Config.cc @@ -168,8 +168,8 @@ Config::Config(int argc, char ** argv) : opt_cmd_("Options"), opt_cfg_("Configur ("ptMin", po::value >(&ptmin_)->multitoken(),"Mimium pt of an object") ("ptMax", po::value >(&ptmax_)->multitoken(),"Maximum pt of an object") ("etaMax", po::value >(&etamax_)->multitoken(),"Maximum |eta| of an object") - ("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"); + ("ptImbalanceMin",po::value (&jetsptimbalmin_)->default_value(-1),"Minimum relative imbalance between two candidates") + ("ptImbalanceMax",po::value (&jetsptimbalmax_)->default_value(-1),"Maximum relative imbalance between two candidates"); opt_cfg_.add_options() @@ -357,6 +357,8 @@ 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::string Config::btagAlgorithm() const { return btagalgo_; } +std::string Config::btagScaleFactors() const { return btagsf_; } std::vector Config::jetsBtagWP() const { return jetsbtagwp_; } std::vector Config::jetsBtagProbB() const { return jetsbtagprobb_; } std::vector Config::jetsBtagProbBB() const { return jetsbtagprobbb_; } @@ -371,6 +373,19 @@ bool Config::useJetsExtendedFlavour() const { return usejetsextflv bool Config::doDijet() const { return dodijet_ ; } int Config::nBJetsMin() const { return nbjetsmin_; } +std::vector Config::jetsQGmin() const { return qgmin_; } +std::vector Config::jetsQGmax() const { return qgmax_; } + +// jet-jet +float Config::jetsDetaMax() const { return jetsdetamax_; } +float Config::jetsDetaMin() const { return jetsdetamin_; } +float Config::jetsDphiMax() const { return jetsdphimax_; } +float Config::jetsDphiMin() const { return jetsdphimin_; } +float Config::jetsDrMax() const { return jetsdrmax_; } +float Config::jetsDrMin() const { return jetsdrmin_; } +float Config::jetsPtImbalanceMax() const { return jetsptimbalmax_; } +float Config::jetsPtImbalanceMin() const { return jetsptimbalmin_; } + // muons std::string Config::muonsCollection() const { return muonsCol_; } int Config::nMuonsMin() const { return nmuonsmin_; } diff --git a/src/JetAnalyser.cc b/src/JetAnalyser.cc index 78d5ddbf..b41bebf7 100644 --- a/src/JetAnalyser.cc +++ b/src/JetAnalyser.cc @@ -31,11 +31,11 @@ JetAnalyser::JetAnalyser(int argc, char * argv[]) : BaseAnalyser(argc,argv) applyjer_ = false; - if ( config_->btagsf_ != "" ) + if ( config_->btagScaleFactors() != "" ) { - 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"); + bsf_reader_["loose"] = analysis_->btagCalibration(config_->btagAlgorithm(), config_->btagScaleFactors(), "loose"); + bsf_reader_["medium"] = analysis_->btagCalibration(config_->btagAlgorithm(), config_->btagScaleFactors(), "medium"); + bsf_reader_["tight"] = analysis_->btagCalibration(config_->btagAlgorithm(), config_->btagScaleFactors(), "tight"); } if ( config_->jerPtRes() != "" && config_->jerSF() != "" && this->genJetsAnalysis() ) // FIXME: check if files exist @@ -189,7 +189,7 @@ void JetAnalyser::jetHistograms( const int & n, const std::string & label ) 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") + if ( config_->btagAlgorithm() == "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] ); @@ -197,7 +197,7 @@ void JetAnalyser::jetHistograms( const int & n, const std::string & label ) 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" || config_->btagalgo_ == "deepjet" ) + if ( config_->btagAlgorithm() == "deepflavour" || config_->btagAlgorithm() == "deepjet" ) { 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] ); @@ -231,7 +231,7 @@ void JetAnalyser::jetHistograms( const int & n, const std::string & label ) 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") + if ( config_->btagAlgorithm() == "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] ); @@ -239,7 +239,7 @@ void JetAnalyser::jetHistograms( const int & n, const std::string & label ) 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" || config_->btagalgo_ == "deepjet" ) + if ( config_->btagAlgorithm() == "deepflavour" || config_->btagAlgorithm() == "deepjet" ) { 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] ); @@ -318,16 +318,32 @@ void JetAnalyser::jetHistograms( const int & n, const std::string & label ) 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" || config_->btagalgo_ == "deepjet" ) { btag = jet.btag("btag_dfb") + jet.btag("btag_dfbb") + jet.btag("btag_dflepb"); } + if ( config_->btagAlgorithm() == "csvivf" || config_->btagAlgorithm() == "csv" ) { btag = jet.btag("btag_csvivf"); } + else if ( config_->btagAlgorithm() == "deepcsv" ) { btag = jet.btag("btag_deepb") + jet.btag("btag_deepbb"); } + else if ( config_->btagAlgorithm() == "deepbvsall" ) { btag = jet.btag("btag_deepbvsall"); } + else if ( config_->btagAlgorithm() == "deepflavour" || config_->btagAlgorithm() == "deepjet" ) { btag = jet.btag("btag_dfb") + jet.btag("btag_dfbb") + jet.btag("btag_dflepb"); } else { btag = -9999; } return btag; } bool JetAnalyser::selectionJet(const int & r) +{ + if ( r > config_->nJetsMin() ) return true; + int j = r-1; + + float pt_min = config_->jetsPtMin()[j]; + float pt_max = -1.; + float eta_max = config_->jetsEtaMax()[j]; + + if ( config_->jetsPtMax().size() > 0 && config_->jetsPtMax()[j] > config_->jetsPtMin()[j] ) pt_max = config_->jetsPtMax()[j]; + + bool isgood = this -> selectionJet(r,pt_min,eta_max,pt_max); + + return isgood; +} + +bool JetAnalyser::selectionJet(const int & r, const float & pt_min, const float &eta_max, const float &pt_max) { if ( r > config_->nJetsMin() ) return true; ++cutflow_; @@ -336,22 +352,20 @@ bool JetAnalyser::selectionJet(const int & r) 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] )); + if ( pt_max > pt_min ) + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: pt > %5.1f GeV and pt < %5.1f GeV and |eta| < %3.1f",r,pt_min, pt_max, eta_max )); 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] )); + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: pt > %5.1f GeV and |eta| < %3.1f",r,pt_min, eta_max )); } -// 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 ( selectedJets_[j] -> pt() < pt_min && !(pt_min < 0) ) return false; + if ( fabs(selectedJets_[j] -> eta()) > eta_max && !(eta_max < 0) ) return false; if ( config_->jetsPtMax().size() > 0 ) { - if ( selectedJets_[j] -> pt() > config_->jetsPtMax()[j] && !(config_->jetsPtMax()[j] < config_->jetsPtMin()[j]) ) return false; + if ( selectedJets_[j] -> pt() > pt_max && !(pt_max < pt_min ) ) return false; } h1_["cutflow"] -> Fill(cutflow_,weight_); @@ -360,27 +374,30 @@ bool JetAnalyser::selectionJet(const int & r) } -bool JetAnalyser::selectionJetDeta(const int & j1, const int & j2, const float & delta) +bool JetAnalyser::selectionJetDeta(const int & r1, const int & r2, const float & delta) { - if ( j1 > config_->nJetsMin() || j2 > config_->nJetsMin() ) return true; + if ( r1 > config_->nJetsMin() || r2 > config_->nJetsMin() ) return true; ++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))); + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Deta(jet %d, jet %d) < %4.2f",r1,r2,fabs(delta))); else - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Deta(jet %d, jet %d) > %4.2f",j1,j2,fabs(delta))); + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Deta(jet %d, jet %d) > %4.2f",r1,r2,fabs(delta))); } + int j1 = r1-1; + int j2 = r2-1; + if ( delta > 0 ) { - if ( fabs(selectedJets_[j1-1]->eta() - selectedJets_[j2-1]->eta()) > fabs(delta) ) return false; + if ( fabs(selectedJets_[j1]->eta() - selectedJets_[j2]->eta()) > fabs(delta) ) return false; } else { - if ( fabs(selectedJets_[j1-1]->eta() - selectedJets_[j2-1]->eta()) < fabs(delta) ) return false; + if ( fabs(selectedJets_[j1]->eta() - selectedJets_[j2]->eta()) < fabs(delta) ) return false; } @@ -389,50 +406,53 @@ bool JetAnalyser::selectionJetDeta(const int & j1, const int & j2, const float & return true; } -bool JetAnalyser::selectionJetDeta(const int & j1, const int & j2) +bool JetAnalyser::selectionJetDeta(const int & r1, const int & r2) { bool ok = true; - if (config_->jetsdetamax_ < 0 ) + if (config_->jetsDetaMax() < 0 ) { ok = ok && true; } else { - ok = ok && selectionJetDeta(j1,j2,config_->jetsdetamax_); + ok = ok && selectionJetDeta(r1,r2,config_->jetsDetaMax()); } - if (config_->jetsdetamin_ < 0 ) + if (config_->jetsDetaMin() < 0 ) { ok = ok && true; } else { - ok = ok && selectionJetDeta(j1,j2,-1*config_->jetsdetamin_); + ok = ok && selectionJetDeta(r1,r2,-1*config_->jetsDetaMin()); } return ok; } -bool JetAnalyser::selectionJetDphi(const int & j1, const int & j2, const float & delta) +bool JetAnalyser::selectionJetDphi(const int & r1, const int & r2, const float & delta) { - if ( j1 > config_->nJetsMin() || j2 > config_->nJetsMin() ) return true; + if ( r1 > config_->nJetsMin() || r2 > config_->nJetsMin() ) return true; ++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))); + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Dphi(jet %d, jet %d) < %4.2f",r1,r2,fabs(delta))); else - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Dphi(jet %d, jet %d) > %4.2f",j1,j2,fabs(delta))); + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Dphi(jet %d, jet %d) > %4.2f",r1,r2,fabs(delta))); } + int j1 = r1-1; + int j2 = r2-1; + if ( delta > 0 ) { - if ( fabs(selectedJets_[j1-1]->deltaPhi(*selectedJets_[j2-1])) > fabs(delta) ) return false; + if ( fabs(selectedJets_[j1]->deltaPhi(*selectedJets_[j2])) > fabs(delta) ) return false; } else { - if ( fabs(selectedJets_[j1-1]->deltaPhi(*selectedJets_[j2-1])) < fabs(delta) ) return false; + if ( fabs(selectedJets_[j1]->deltaPhi(*selectedJets_[j2])) < fabs(delta) ) return false; } h1_["cutflow"] -> Fill(cutflow_,weight_); @@ -440,53 +460,54 @@ bool JetAnalyser::selectionJetDphi(const int & j1, const int & j2, const float & return true; } -bool JetAnalyser::selectionJetDphi(const int & j1, const int & j2) +bool JetAnalyser::selectionJetDphi(const int & r1, const int & r2) { bool ok = true; - if (config_->jetsdphimax_ < 0 ) + if (config_->jetsDphiMax() < 0 ) { ok = ok && true; } else { - ok = ok && selectionJetDphi(j1,j2,config_->jetsdphimax_); + ok = ok && selectionJetDphi(r1,r2,config_->jetsDphiMax()); } - if (config_->jetsdphimin_ < 0 ) + if (config_->jetsDphiMin() < 0 ) { ok = ok && true; } else { - ok = ok && selectionJetDphi(j1,j2,-1*config_->jetsdphimin_); + ok = ok && selectionJetDphi(r1,r2,-1*config_->jetsDphiMin()); } return ok; } -bool JetAnalyser::selectionJetDr(const int & j1, const int & j2, const float & delta) +bool JetAnalyser::selectionJetDr(const int & r1, const int & r2, const float & delta) { - if ( j1 > config_->nJetsMin() || j2 > config_->nJetsMin() ) return true; + if ( r1 > config_->nJetsMin() || r2 > config_->nJetsMin() ) return true; ++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))); + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("DR(jet %d, jet %d) < %4.2f",r1,r2,fabs(delta))); else - h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("DR(jet %d, jet %d) > %4.2f",j1,j2,fabs(delta))); + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("DR(jet %d, jet %d) > %4.2f",r1,r2,fabs(delta))); } - + int j1 = r1-1; + int j2 = r2-1; if ( delta > 0 ) { - if ( selectedJets_[j1-1]->deltaR(*selectedJets_[j2-1]) > fabs(delta) ) return false; + if ( selectedJets_[j1]->deltaR(*selectedJets_[j2]) > fabs(delta) ) return false; } else { - if ( selectedJets_[j1-1]->deltaR(*selectedJets_[j2-1]) < fabs(delta) ) return false; + if ( selectedJets_[j1]->deltaR(*selectedJets_[j2]) < fabs(delta) ) return false; } @@ -496,29 +517,84 @@ bool JetAnalyser::selectionJetDr(const int & j1, const int & j2, const float & d } -bool JetAnalyser::selectionJetDr(const int & j1, const int & j2) +bool JetAnalyser::selectionJetDr(const int & r1, const int & r2) { bool ok = true; - if (config_->jetsdrmax_ < 0 ) + if (config_->jetsDrMax() < 0 ) { ok = ok && true; } else { - ok = ok && selectionJetDr(j1,j2,config_->jetsdrmax_); + ok = ok && selectionJetDr(r1,r2,config_->jetsDrMax()); } - if (config_->jetsdrmin_ < 0 ) + if (config_->jetsDrMin() < 0 ) { ok = ok && true; } else { - ok = ok && selectionJetDr(j1,j2,-1*config_->jetsdrmin_); + ok = ok && selectionJetDr(r1,r2,-1*config_->jetsDrMin()); } return ok; } +bool JetAnalyser::selectionJetPtImbalance(const int & r1, const int & r2, const float & delta) +{ + if ( r1 > config_->nJetsMin() || r2 > config_->nJetsMin() ) return true; + + ++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",r1,r2,r1,fabs(delta))); + else + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("DpT(jet %d, jet %d)/jet %d pT > %4.2f",r1,r2,r1,fabs(delta))); + } + + int j1 = r1-1; + int j2 = r2-1; + + if ( delta > 0 ) + { + if ( fabs(selectedJets_[j1]->pt() - selectedJets_[j2]->pt())/selectedJets_[j1]->pt() > fabs(delta) ) return false; + } + else + { + if ( fabs(selectedJets_[j1]->pt() - selectedJets_[j2]->pt())/selectedJets_[j1]->pt() < fabs(delta) ) return false; + } + + + h1_["cutflow"] -> Fill(cutflow_,weight_); + + return true; + +} +bool JetAnalyser::selectionJetPtImbalance(const int & r1, const int & r2) +{ + bool ok = true; + if (config_->jetsPtImbalanceMax() < 0 ) + { + ok = ok && true; + } + else + { + ok = ok && selectionJetPtImbalance(r1,r2,config_->jetsPtImbalanceMax()); + } + + if (config_->jetsPtImbalanceMin() < 0 ) + { + ok = ok && true; + } + else + { + ok = ok && selectionJetPtImbalance(r1,r2,-1*config_->jetsPtImbalanceMin()); + } + return ok; + +} + std::vector< std::shared_ptr > JetAnalyser::jets() { @@ -632,9 +708,9 @@ bool JetAnalyser::selectionBJet(const int & r ) ++ 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())); + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag > %6.4f (%s)",r,config_->btagAlgorithm().c_str(),config_->btagWP(config_->jetsBtagWP()[j]),config_->jetsBtagWP()[j].c_str())); - if ( btag(*selectedJets_[j],config_->btagalgo_) < config_->btagWP(config_->jetsBtagWP()[j]) ) return false; + if ( btag(*selectedJets_[j],config_->btagAlgorithm()) < config_->btagWP(config_->jetsBtagWP()[j]) ) return false; h1_["cutflow"] -> Fill(cutflow_,weight_); @@ -657,10 +733,10 @@ bool JetAnalyser::selectionNonBJet(const int & r ) } // jet non btag - if ( btag(*selectedJets_[j],config_->btagalgo_) > config_->btagWP(config_->nonBtagWP()) ) return false; + if ( btag(*selectedJets_[j],config_->btagAlgorithm()) > 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"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: %s btag < %6.4f (%s) [reverse btag]",r,config_->btagAlgorithm().c_str(),config_->btagWP(config_->nonBtagWP()),config_->nonBtagWP().c_str())); h1_["cutflow"] -> Fill(cutflow_,weight_); @@ -840,7 +916,7 @@ void JetAnalyser::fillJetHistograms(const int & r, const std::string & label, co // h1_[Form("eta_jet%d_%s",j+1,label.c_str())] -> Fill(selectedJets_[j]->eta(),weight_*sf); h1_[Form("phi_jet%d_%s",j+1,label.c_str())] -> Fill(selectedJets_[j]->phi()*180./acos(-1.),weight_*sf); - float mybtag = btag(*selectedJets_[j],config_->btagalgo_); + float mybtag = btag(*selectedJets_[j],config_->btagAlgorithm()); 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_*sf); @@ -848,7 +924,7 @@ void JetAnalyser::fillJetHistograms(const int & r, const std::string & label, co h1_[Form("qglikelihood_jet%d_%s", j+1,label.c_str())] -> Fill(selectedJets_[j]->qgLikelihood(),weight_*sf); h1_[Form("nconstituents_jet%d_%s", j+1,label.c_str())] -> Fill(selectedJets_[j]->constituents(),weight_*sf); - if ( config_->btagalgo_ == "deepcsv") + if ( config_->btagAlgorithm() == "deepcsv") { h1_[Form("btag_light_jet%d_%s", j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_deeplight"),weight_*sf); h1_[Form("btag_c_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepc"),weight_*sf); @@ -856,7 +932,7 @@ void JetAnalyser::fillJetHistograms(const int & r, const std::string & label, co h1_[Form("btag_bb_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepbb"),weight_*sf); h1_[Form("btag_cc_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepcc"),weight_*sf); } - if ( config_->btagalgo_ == "deepflavour" || config_->btagalgo_ == "deepjet" ) + if ( config_->btagAlgorithm() == "deepflavour" || config_->btagAlgorithm() == "deepjet" ) { h1_[Form("btag_light_jet%d_%s", j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_dflight"),weight_*sf); h1_[Form("btag_g_jet%d_%s" , j+1,label.c_str())] -> Fill(selectedJets_[j]->btag("btag_dfg") ,weight_*sf); @@ -885,10 +961,10 @@ void JetAnalyser::fillJetHistograms(const int & r, const std::string & label, co h1_[Form("pt_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->pt(),weight_*sf); h1_[Form("eta_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->eta(),weight_*sf); h1_[Form("phi_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->phi()*180./acos(-1.),weight_*sf); - h1_[Form("btag_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> Fill(btag(*selectedJets_[j],config_->btagalgo_),weight_*sf); + h1_[Form("btag_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> Fill(btag(*selectedJets_[j],config_->btagAlgorithm()),weight_*sf); h1_[Form("qglikelihood_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->qgLikelihood(),weight_*sf); h1_[Form("nconstituents_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->constituents(),weight_*sf); - if ( config_->btagalgo_ == "deepcsv") + if ( config_->btagAlgorithm() == "deepcsv") { h1_[Form("btag_light_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_deeplight"),weight_*sf); h1_[Form("btag_c_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepc"),weight_*sf); @@ -896,7 +972,7 @@ void JetAnalyser::fillJetHistograms(const int & r, const std::string & label, co h1_[Form("btag_bb_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepbb"),weight_*sf); h1_[Form("btag_cc_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_deepcc"),weight_*sf); } - if ( config_->btagalgo_ == "deepflavour" || config_->btagalgo_ == "deepjet") + if ( config_->btagAlgorithm() == "deepflavour" || config_->btagAlgorithm() == "deepjet") { h1_[Form("btag_light_jet%d_%s_%s", j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_dflight"),weight_*sf); h1_[Form("btag_g_jet%d_%s_%s" , j+1,label.c_str(),flv.c_str())] -> Fill(selectedJets_[j]->btag("btag_dfg") ,weight_*sf); @@ -961,7 +1037,7 @@ void JetAnalyser::actionApplyJER() float JetAnalyser::actionApplyBtagSF(const int & r, const bool & global_weight) { float sf = 1.; - if ( ! config_-> isMC() || config_->btagsf_ == "" ) return sf; // will not apply btag SF + if ( ! config_-> isMC() || config_->btagScaleFactors() == "" ) return sf; // will not apply btag SF if ( ! config_->signalRegion() && r == config_->nonBtagJet() ) return sf; int j = r-1; @@ -969,9 +1045,9 @@ float JetAnalyser::actionApplyBtagSF(const int & r, const bool & global_weight) 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())); + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: btag SF = 1 applied (%s %s WP)",r,config_->btagAlgorithm().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())); + h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Jet %d: btag SF applied (%s %s WP)",r,config_->btagAlgorithm().c_str(),config_->jetsBtagWP()[j].c_str())); } if ( global_weight || config_->jetsBtagWP()[j] != "xxx" ) sf = this->btagSF(r,config_->jetsBtagWP()[j]).nominal; @@ -987,7 +1063,7 @@ float JetAnalyser::getBtagSF(const int & r) { float sf = 1.; int j = r-1; - if ( ! config_-> isMC() || config_->btagsf_ == "" ) return sf; // will not apply btag SF + if ( ! config_-> isMC() || config_->btagScaleFactors() == "" ) return sf; // will not apply btag SF if ( ! config_->signalRegion() && r == config_->nonBtagJet() ) return sf; if ( config_->jetsBtagWP()[j] != "xxx" ) sf = this->btagSF(r,config_->jetsBtagWP()[j]).nominal; @@ -1069,59 +1145,6 @@ void JetAnalyser::jetSwap(const int & r1, const int & r2) -bool JetAnalyser::selectionJetPtImbalance(const int & j1, const int & j2, const float & delta) -{ - if ( j1 > config_->nJetsMin() || j2 > config_->nJetsMin() ) return true; - - ++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 ( 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; @@ -1154,22 +1177,22 @@ 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 ) + if ( config_->jetsQGmax().size() == 0 || config_->jetsQGmax()[j] < 0 || (int)config_->jetsQGmax().size() < r ) { ok = ok && true; } else { - ok = ok && selectionJetQGlikelihood(r,config_->qgmax_[j]); + ok = ok && selectionJetQGlikelihood(r,config_->jetsQGmax()[j]); } - if (config_->qgmin_.size() == 0 || config_->qgmin_[j] < 0 || (int)config_->qgmin_.size() < r ) + if (config_->jetsQGmin().size() == 0 || config_->jetsQGmin()[j] < 0 || (int)config_->jetsQGmin().size() < r ) { ok = ok && true; } else { - ok = ok && selectionJetQGlikelihood(r,-1*config_->qgmin_[j] ); + ok = ok && selectionJetQGlikelihood(r,-1*config_->jetsQGmin()[j] ); } return ok; @@ -1181,7 +1204,7 @@ 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_; + std::string algo = config_->btagAlgorithm(); if ( fabs(wp) > 1 ) return true; // there is no selection here, so will not update the cutflow ++ cutflow_; @@ -1225,7 +1248,7 @@ 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_; + std::string algo = config_->btagAlgorithm(); if ( fabs(wp) > 1 ) return true; // there is no selection here, so will not update the cutflow ++ cutflow_; @@ -1266,7 +1289,7 @@ 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_; + std::string algo = config_->btagAlgorithm(); if ( fabs(wp) > 1 || algo == "deepcsv" ) return true; // there is no selection here, so will not update the cutflow ++ cutflow_; @@ -1304,7 +1327,7 @@ 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_; + std::string algo = config_->btagAlgorithm(); if ( fabs(wp) > 1 ) return true; // there is no selection here, so will not update the cutflow ++ cutflow_; @@ -1345,7 +1368,7 @@ 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_; + std::string algo = config_->btagAlgorithm(); if ( fabs(wp) > 1 || algo == "deepcsv" ) return true; // there is no selection here, so will not update the cutflow ++ cutflow_; @@ -1381,7 +1404,7 @@ 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_; + std::string algo = config_->btagAlgorithm(); if ( fabs(wp) > 1 ) return true; // there is no selection here, so will not update the cutflow ++ cutflow_;