Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:27

0001 #include "L1Trigger/Phase2L1ParticleFlow/interface/HGC3DClusterEgID.h"
0002 #include "CommonTools/MVAUtils/interface/TMVAZipReader.h"
0003 
0004 l1tpf::HGC3DClusterEgID::HGC3DClusterEgID(const edm::ParameterSet &pset)
0005     : isPUFilter_(pset.getParameter<bool>("isPUFilter")),
0006       preselection_(pset.getParameter<std::string>("preselection")),
0007       method_(pset.getParameter<std::string>("method")),
0008       weightsFile_(pset.getParameter<std::string>("weightsFile")),
0009       reader_(new TMVA::Reader()),
0010       wp_(pset.getParameter<std::string>("wp")) {
0011   // first create all the variables
0012   for (const auto &psvar : pset.getParameter<std::vector<edm::ParameterSet>>("variables")) {
0013     variables_.emplace_back(psvar.getParameter<std::string>("name"), psvar.getParameter<std::string>("value"));
0014   }
0015 }
0016 
0017 void l1tpf::HGC3DClusterEgID::prepareTMVA() {
0018   // Declare the variables
0019   for (auto &var : variables_)
0020     var.declare(*reader_);
0021   // then read the weights
0022   if (weightsFile_[0] != '/' && weightsFile_[0] != '.') {
0023     weightsFile_ = edm::FileInPath(weightsFile_).fullPath();
0024   }
0025   reco::details::loadTMVAWeights(&*reader_, method_, weightsFile_);
0026 }
0027 
0028 float l1tpf::HGC3DClusterEgID::passID(l1t::HGCalMulticluster c, l1t::PFCluster &cpf) {
0029   if (preselection_(c)) {
0030     for (auto &var : variables_)
0031       var.fill(c);
0032     float mvaOut = reader_->EvaluateMVA(method_);
0033     if (isPUFilter_)
0034       cpf.setEgVsPUMVAOut(mvaOut);
0035     else
0036       cpf.setEgVsPionMVAOut(mvaOut);
0037     return (mvaOut > wp_(c) ? 1 : 0);
0038   } else {
0039     if (isPUFilter_)
0040       cpf.setEgVsPUMVAOut(-100.0);
0041     else
0042       cpf.setEgVsPionMVAOut(-100.0);
0043     return 0;
0044   }
0045 }