CMS 3D CMS Logo

MVAModuleHelper.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_MVAComputer_MVAModuleHelper_h
2 #define PhysicsTools_MVAComputer_MVAModuleHelper_h
3 // -*- C++ -*-
4 //
5 // Package: MVAComputer
6 // Class : MVAModuleHelper
7 //
8 
9 //
10 // Author: Christophe Saout <christophe.saout@cern.ch>
11 // Created: Sat Apr 24 15:18 CEST 2007
12 //
13 
14 #include <functional>
15 #include <algorithm>
16 #include <numeric>
17 #include <cstring>
18 #include <string>
19 #include <vector>
20 #include <cmath>
21 
22 #include <boost/bind.hpp>
23 
25 
30 
31 namespace PhysicsTools {
32 
41 template<typename Object>
44 
45  double operator()(const Object &object,
47  { return object.compute(name); }
48 };
49 
60 template<class Record, typename Object,
63  public:
64  MVAModuleHelper(const std::string &label) : label(label) {}
65  MVAModuleHelper(const MVAModuleHelper &orig) : label(orig.label) {}
67 
68  void setEventSetup(const edm::EventSetup &setup);
69  void setEventSetup(const edm::EventSetup &setup, const char *esLabel);
70 
71  double operator()(const Object &object) const;
72 
73  void train(const Object &object, bool target, double weight = 1.0) const;
74 
75  private:
77 
80 
81  class Value {
82  public:
84  name(name), filler(name) {}
85  Value(const std::string &name, double value) :
86  name(name), filler(name), value(value) {}
87 
88  inline bool update(const Object &object) const
89  {
90  value = filler(object, name);
91  return !std::isfinite(value);
92  }
93 
94  PhysicsTools::AtomicId getName() const { return name; }
95  double getValue() const { return value; }
96 
97  private:
99  Filler filler;
100 
101  mutable double value;
102  };
103 
104  std::vector<Value> values;
105 };
106 
107 template<class Record, typename Object, class Filler>
109  const edm::EventSetup &setup)
110 {
112  setup.get<Record>().get(handle);
113  const PhysicsTools::Calibration::MVAComputerContainer *container = handle.product();
114  if (cache.update(container, label.c_str()) && cache)
115  init(container);
116 }
117 
118 template<class Record, typename Object, class Filler>
120  const edm::EventSetup &setup, const char *esLabel)
121 {
123  setup.get<Record>().get(esLabel, handle);
124  const PhysicsTools::Calibration::MVAComputerContainer *container = handle.product();
125  if (cache.update(container, label.c_str()) && cache)
126  init(container);
127 }
128 
129 template<class Record, typename Object, class Filler>
132 {
133  const std::vector<PhysicsTools::Calibration::Variable> &vars =
134  container->find(label).inputSet;
135  values.clear();
136  for(std::vector<PhysicsTools::Calibration::Variable>::const_iterator
137  iter = vars.begin(); iter != vars.end(); ++iter)
138  if (std::strncmp(iter->name.c_str(), "__", 2) != 0)
139  values.push_back(Value(iter->name));
140 }
141 
142 template<class Record, typename Object, class Filler>
144  const Object &object) const
145 {
146  std::for_each(values.begin(), values.end(),
147  boost::bind(&Value::update, _1, object));
148  return cache->eval(values);
149 }
150 
151 template<class Record, typename Object, class Filler>
153  const Object &object, bool target, double weight) const
154 {
155  static const PhysicsTools::AtomicId kTargetId("__TARGET__");
156  static const PhysicsTools::AtomicId kWeightId("__WEIGHT__");
157 
158  if (!cache)
159  return;
160 
161  using boost::bind;
162  if (std::accumulate(values.begin(), values.end(), 0,
163  bind(std::plus<int>(), _1,
164  bind(&Value::update, _2, object))))
165  return;
166 
168  list.add(kTargetId, target);
169  list.add(kWeightId, weight);
170  for(typename std::vector<Value>::const_iterator iter = values.begin();
171  iter != values.end(); ++iter)
172  list.add(iter->getName(), iter->getValue());
173 
174  cache->eval(list);
175 }
176 
177 } // namespace PhysicsTools
178 
179 #endif // PhysicsTools_MVAComputer_MVAModuleHelper_h
MVAModuleHelper(const std::string &label)
virtual const MVAComputer & find(const std::string &label) const
Definition: MVAComputer.cc:222
PhysicsTools::AtomicId getName() const
PhysicsTools::MVAComputerCache cache
MVAModuleHelper(const MVAModuleHelper &orig)
void train(const Object &object, bool target, double weight=1.0) const
int init
Definition: HydjetWrapper.h:67
double operator()(const Object &object, const PhysicsTools::AtomicId &name)
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
Definition: weight.py:1
MVAModuleHelperDefaultFiller(const PhysicsTools::AtomicId &name)
Value(const std::string &name)
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
Template for automated variable collection and MVA computation in EDM modules.
void setEventSetup(const edm::EventSetup &setup)
reco::JetExtendedAssociation::JetExtendedData Value
Definition: value.py:1
std::vector< Value > values
bool update(const Object &object) const
Helper class that can contain an list of identifier-value pairs.
Definition: Variable.h:81
def cache(function)
void init(const PhysicsTools::Calibration::MVAComputerContainer *container)
std::vector< Variable > inputSet
Definition: MVAComputer.h:234
#define update(a, b)
T get() const
Definition: EventSetup.h:63
Value(const std::string &name, double value)
Creates and and MVAComputer from calibrations via EventSetup.
double operator()(const Object &object) const
vars
Definition: DeepTauId.cc:77
Default template for MVAModuleHelper "Filler" template argument.
T const * product() const
Definition: ESHandle.h:86
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
void add(AtomicId id, double value)
Definition: Variable.h:106