CMS 3D CMS Logo

HGC3DClusterTMVASelector.cc
Go to the documentation of this file.
6 
11 
12 #include "TMVA/Factory.h"
13 #include "TMVA/Reader.h"
14 
15 namespace l1t {
17  public:
20 
21  private:
22  class Var {
23  public:
25  void declare(TMVA::Reader &r) { r.AddVariable(name_, &val_); }
26  void fill(const l1t::HGCalMulticluster &c) { val_ = expr_(c); }
27 
28  private:
31  float val_;
32  };
33 
36  std::vector<Var> variables_;
38  std::unique_ptr<TMVA::Reader> reader_;
40 
41  void produce(edm::Event &, const edm::EventSetup &) override;
42 
43  }; // class
44 } // namespace l1t
45 
47  : src_(consumes<l1t::HGCalMulticlusterBxCollection>(iConfig.getParameter<edm::InputTag>("src"))),
48  preselection_(iConfig.getParameter<std::string>("preselection")),
49  method_(iConfig.getParameter<std::string>("method")),
50  weightsFile_(iConfig.getParameter<std::string>("weightsFile")),
51  reader_(new TMVA::Reader()),
52  wp_(iConfig.getParameter<std::string>("wp")) {
53  // first create all the variables
54  for (const auto &psvar : iConfig.getParameter<std::vector<edm::ParameterSet>>("variables")) {
55  variables_.emplace_back(psvar.getParameter<std::string>("name"), psvar.getParameter<std::string>("value"));
56  }
57  // then declare them
58  for (auto &var : variables_)
59  var.declare(*reader_);
60  // then read the weights
61  if (weightsFile_[0] != '/' && weightsFile_[0] != '.') {
63  }
65  // finally, declare outputs
66  produces<l1t::HGCalMulticlusterBxCollection>();
67  produces<l1t::HGCalMulticlusterBxCollection>("fail");
68 }
69 
71  std::unique_ptr<l1t::HGCalMulticlusterBxCollection> out = std::make_unique<l1t::HGCalMulticlusterBxCollection>();
72  std::unique_ptr<l1t::HGCalMulticlusterBxCollection> fail = std::make_unique<l1t::HGCalMulticlusterBxCollection>();
73 
75  iEvent.getByToken(src_, multiclusters);
76 
77  for (int bx = multiclusters->getFirstBX(); bx <= multiclusters->getLastBX(); ++bx) {
78  for (auto it = multiclusters->begin(bx), ed = multiclusters->end(bx); it != ed; ++it) {
79  const auto &c = *it;
80  if (preselection_(c)) {
81  for (auto &var : variables_)
82  var.fill(c);
83  float mvaOut = reader_->EvaluateMVA(method_);
84  if (mvaOut > wp_(c)) {
85  out->push_back(bx, c);
86  } else {
87  fail->push_back(bx, c);
88  }
89  }
90  }
91  }
92 
93  iEvent.put(std::move(out));
94  iEvent.put(std::move(fail), "fail");
95 }
l1t::HGC3DClusterTMVASelector::HGC3DClusterTMVASelector
HGC3DClusterTMVASelector(const edm::ParameterSet &)
Definition: HGC3DClusterTMVASelector.cc:46
l1t::HGC3DClusterTMVASelector::Var::val_
float val_
Definition: HGC3DClusterTMVASelector.cc:31
StringObjectFunction< l1t::HGCalMulticluster >
l1t::HGC3DClusterTMVASelector::Var::name_
std::string name_
Definition: HGC3DClusterTMVASelector.cc:29
l1t::HGC3DClusterTMVASelector::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: HGC3DClusterTMVASelector.cc:70
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
l1t::HGC3DClusterTMVASelector::variables_
std::vector< Var > variables_
Definition: HGC3DClusterTMVASelector.cc:36
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
EDProducer.h
l1t::HGC3DClusterTMVASelector::src_
edm::EDGetTokenT< l1t::HGCalMulticlusterBxCollection > src_
Definition: HGC3DClusterTMVASelector.cc:34
edm::Handle
Definition: AssociativeIterator.h:50
trigObjTnPSource_cfi.var
var
Definition: trigObjTnPSource_cfi.py:21
BXVector
Definition: BXVector.h:15
BXVector::getFirstBX
int getFirstBX() const
edm::FileInPath
Definition: FileInPath.h:64
l1t::HGCalMulticluster
Definition: HGCalMulticluster.h:13
MakerMacros.h
l1t::HGC3DClusterTMVASelector::reader_
std::unique_ptr< TMVA::Reader > reader_
Definition: HGC3DClusterTMVASelector.cc:38
l1t::HGC3DClusterTMVASelector::Var::Var
Var(const std::string &name, const std::string &expr)
Definition: HGC3DClusterTMVASelector.cc:24
HGCalMulticluster.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
l1t::HGC3DClusterTMVASelector::Var::fill
void fill(const l1t::HGCalMulticluster &c)
Definition: HGC3DClusterTMVASelector.cc:26
l1t::HGC3DClusterTMVASelector::preselection_
StringCutObjectSelector< l1t::HGCalMulticluster > preselection_
Definition: HGC3DClusterTMVASelector.cc:35
l1t::HGC3DClusterTMVASelector::Var::expr_
StringObjectFunction< l1t::HGCalMulticluster > expr_
Definition: HGC3DClusterTMVASelector.cc:30
l1t::HGC3DClusterTMVASelector::Var
Definition: HGC3DClusterTMVASelector.cc:22
BXVector::begin
const_iterator begin(int bx) const
l1t::HGC3DClusterTMVASelector
Definition: HGC3DClusterTMVASelector.cc:16
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
l1t::HGC3DClusterTMVASelector::Var::declare
void declare(TMVA::Reader &r)
Definition: HGC3DClusterTMVASelector.cc:25
BXVector::end
const_iterator end(int bx) const
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
l1t
delete x;
Definition: CaloConfig.h:22
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
alignCSCRings.r
r
Definition: alignCSCRings.py:93
l1t::HGC3DClusterTMVASelector::wp_
StringObjectFunction< l1t::HGCalMulticluster > wp_
Definition: HGC3DClusterTMVASelector.cc:39
l1t::HGC3DClusterTMVASelector::weightsFile_
std::string weightsFile_
Definition: HGC3DClusterTMVASelector.cc:37
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
StringCutObjectSelector.h
jets_cff.expr
expr
Definition: jets_cff.py:489
Frameworkfwd.h
StringCutObjectSelector< l1t::HGCalMulticluster >
l1t::HGC3DClusterTMVASelector::method_
std::string method_
Definition: HGC3DClusterTMVASelector.cc:37
reco::details::loadTMVAWeights
TMVA::IMethod * loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)
Definition: TMVAZipReader.cc:52
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TMVAZipReader.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::Event
Definition: Event.h:73
StringObjectFunction.h
BXVector::getLastBX
int getLastBX() const
l1t::HGC3DClusterTMVASelector::~HGC3DClusterTMVASelector
~HGC3DClusterTMVASelector() override
Definition: HGC3DClusterTMVASelector.cc:19
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:161