CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: MVAModuleHelper.h,v 1.2 2010/10/20 20:39:10 wmtan Exp $
13 //
14 
15 #include <functional>
16 #include <algorithm>
17 #include <numeric>
18 #include <cstring>
19 #include <string>
20 #include <vector>
21 #include <cmath>
22 
23 #include <boost/bind.hpp>
24 
26 
31 
32 namespace PhysicsTools {
33 
42 template<typename Object>
45 
46  double operator()(const Object &object,
48  { return object.compute(name); }
49 };
50 
61 template<class Record, typename Object,
62  class Filler = MVAModuleHelperDefaultFiller<Object> >
64  public:
65  MVAModuleHelper(const std::string &label) : label(label) {}
66  MVAModuleHelper(const MVAModuleHelper &orig) : label(orig.label) {}
68 
69  void setEventSetup(const edm::EventSetup &setup);
70  void setEventSetup(const edm::EventSetup &setup, const char *esLabel);
71 
72  double operator()(const Object &object) const;
73 
74  void train(const Object &object, bool target, double weight = 1.0) const;
75 
76  private:
78 
79  const std::string label;
81 
82  class Value {
83  public:
84  Value(const std::string &name) :
85  name(name), filler(name) {}
86  Value(const std::string &name, double value) :
87  name(name), filler(name), value(value) {}
88 
89  inline bool update(const Object &object) const
90  {
91  value = filler(object, name);
92  return !std::isfinite(value);
93  }
94 
95  PhysicsTools::AtomicId getName() const { return name; }
96  double getValue() const { return value; }
97 
98  private:
100  Filler filler;
101 
102  mutable double value;
103  };
104 
105  std::vector<Value> values;
106 };
107 
108 template<class Record, typename Object, class Filler>
110  const edm::EventSetup &setup)
111 {
113  setup.get<Record>().get(handle);
114  const PhysicsTools::Calibration::MVAComputerContainer *container = handle.product();
115  if (cache.update(container, label.c_str()) && cache)
116  init(container);
117 }
118 
119 template<class Record, typename Object, class Filler>
121  const edm::EventSetup &setup, const char *esLabel)
122 {
124  setup.get<Record>().get(esLabel, handle);
125  const PhysicsTools::Calibration::MVAComputerContainer *container = handle.product();
126  if (cache.update(container, label.c_str()) && cache)
127  init(container);
128 }
129 
130 template<class Record, typename Object, class Filler>
133 {
134  const std::vector<PhysicsTools::Calibration::Variable> &vars =
135  container->find(label).inputSet;
136  values.clear();
137  for(std::vector<PhysicsTools::Calibration::Variable>::const_iterator
138  iter = vars.begin(); iter != vars.end(); ++iter)
139  if (std::strncmp(iter->name.c_str(), "__", 2) != 0)
140  values.push_back(Value(iter->name));
141 }
142 
143 template<class Record, typename Object, class Filler>
145  const Object &object) const
146 {
147  std::for_each(values.begin(), values.end(),
148  boost::bind(&Value::update, _1, object));
149  return cache->eval(values);
150 }
151 
152 template<class Record, typename Object, class Filler>
154  const Object &object, bool target, double weight) const
155 {
156  static const PhysicsTools::AtomicId kTargetId("__TARGET__");
157  static const PhysicsTools::AtomicId kWeightId("__WEIGHT__");
158 
159  if (!cache)
160  return;
161 
162  using boost::bind;
163  if (std::accumulate(values.begin(), values.end(), 0,
164  bind(std::plus<int>(), _1,
165  bind(&Value::update, _2, object))))
166  return;
167 
169  list.add(kTargetId, target);
170  list.add(kWeightId, weight);
171  for(typename std::vector<Value>::const_iterator iter = values.begin();
172  iter != values.end(); ++iter)
173  list.add(iter->getName(), iter->getValue());
174 
175  cache->eval(list);
176 }
177 
178 } // namespace PhysicsTools
179 
180 #endif // PhysicsTools_MVAComputer_MVAModuleHelper_h
MVAModuleHelper(const std::string &label)
virtual const MVAComputer & find(const std::string &label) const
Definition: MVAComputer.cc:190
PhysicsTools::AtomicId getName() const
PhysicsTools::MVAComputerCache cache
MVAModuleHelper(const MVAModuleHelper &orig)
void train(const Object &object, bool target, double weight=1.0) const
const std::string & label
Definition: MVAComputer.cc:186
int init
Definition: HydjetWrapper.h:63
double operator()(const Object &object, const PhysicsTools::AtomicId &name)
MVAModuleHelperDefaultFiller(const PhysicsTools::AtomicId &name)
Value(const std::string &name)
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:32
Template for automated variable collection and MVA computation in EDM modules.
void setEventSetup(const edm::EventSetup &setup)
tuple handle
Definition: patZpeak.py:22
reco::JetExtendedAssociation::JetExtendedData Value
std::vector< Value > values
bool update(const Object &object) const
Helper class that can contain an list of identifier-value pairs.
Definition: Variable.h:82
const T & get() const
Definition: EventSetup.h:55
void init(const PhysicsTools::Calibration::MVAComputerContainer *container)
T const * product() const
Definition: ESHandle.h:62
#define update(a, b)
Value(const std::string &name, double value)
Creates and and MVAComputer from calibrations via EventSetup.
double operator()(const Object &object) const
Default template for MVAModuleHelper &quot;Filler&quot; template argument.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
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:107