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,
61  class Filler = MVAModuleHelperDefaultFiller<Object> >
63  public:
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
PhysicsTools::AtomicId
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
PhysicsTools::MVAModuleHelper::train
void train(const Object &object, bool target, double weight=1.0) const
Definition: MVAModuleHelper.h:152
init
int init
Definition: HydjetWrapper.h:64
PhysicsTools::MVAModuleHelper::setEventSetup
void setEventSetup(const edm::EventSetup &setup)
Definition: MVAModuleHelper.h:108
PhysicsTools::MVAModuleHelper::label
const std::string label
Definition: MVAModuleHelper.h:78
patZpeak.handle
handle
Definition: patZpeak.py:23
PhysicsTools::MVAModuleHelper::Value::Value
Value(const std::string &name)
Definition: MVAModuleHelper.h:83
PhysicsTools::MVAModuleHelper::Value::filler
Filler filler
Definition: MVAModuleHelper.h:99
PhysicsTools::MVAModuleHelper::Value::update
bool update(const Object &object) const
Definition: MVAModuleHelper.h:88
PhysicsTools::MVAModuleHelper
Template for automated variable collection and MVA computation in EDM modules.
Definition: MVAModuleHelper.h:62
PhysicsTools::Variable::ValueList
Helper class that can contain an list of identifier-value pairs.
Definition: Variable.h:77
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
PhysicsTools::MVAComputerCache
Creates and and MVAComputer from calibrations via EventSetup.
Definition: MVAComputerCache.h:28
PhysicsTools::MVAModuleHelperDefaultFiller::MVAModuleHelperDefaultFiller
MVAModuleHelperDefaultFiller(const PhysicsTools::AtomicId &name)
Definition: MVAModuleHelper.h:43
PhysicsTools::MVAModuleHelper::MVAModuleHelper
MVAModuleHelper(const MVAModuleHelper &orig)
Definition: MVAModuleHelper.h:65
PhysicsTools::MVAModuleHelper::MVAModuleHelper
MVAModuleHelper(const std::string &label)
Definition: MVAModuleHelper.h:64
vars
vars
Definition: DeepTauId.cc:163
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
PhysicsTools::MVAModuleHelper::Value::Value
Value(const std::string &name, double value)
Definition: MVAModuleHelper.h:85
PhysicsTools::MVAModuleHelper::Value::value
double value
Definition: MVAModuleHelper.h:101
PhysicsTools::MVAModuleHelper::Value::name
PhysicsTools::AtomicId name
Definition: MVAModuleHelper.h:98
edm::ESHandle
Definition: DTSurvey.h:22
AtomicId.h
PhysicsTools::MVAModuleHelper::Value::getValue
double getValue() const
Definition: MVAModuleHelper.h:95
PhysicsTools::MVAModuleHelperDefaultFiller
Default template for MVAModuleHelper "Filler" template argument.
Definition: MVAModuleHelper.h:42
MVAComputer.h
PhysicsTools::MVAModuleHelper::init
void init(const PhysicsTools::Calibration::MVAComputerContainer *container)
Definition: MVAModuleHelper.h:130
PhysicsTools::MVAModuleHelper::cache
PhysicsTools::MVAComputerCache cache
Definition: MVAModuleHelper.h:79
utilities.cache
def cache(function)
Definition: utilities.py:3
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PhysicsTools
Definition: Histogram.h:13
PhysicsTools::Calibration::MVAComputerContainer::find
virtual const MVAComputer & find(const std::string &label) const
Definition: MVAComputer.cc:162
PhysicsTools::MVAModuleHelper::values
std::vector< Value > values
Definition: MVAModuleHelper.h:104
value
Definition: value.py:1
edm::EventSetup
Definition: EventSetup.h:57
PhysicsTools::MVAModuleHelper::Value::getName
PhysicsTools::AtomicId getName() const
Definition: MVAModuleHelper.h:94
get
#define get
MVAComputerCache.h
PhysicsTools::MVAModuleHelper::~MVAModuleHelper
~MVAModuleHelper()
Definition: MVAModuleHelper.h:66
Record
Calibration.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
PhysicsTools::Calibration::MVAComputerContainer
Definition: MVAComputer.h:250
PhysicsTools::MVAModuleHelperDefaultFiller::operator()
double operator()(const Object &object, const PhysicsTools::AtomicId &name)
Definition: MVAModuleHelper.h:45
filterCSVwithJSON.target
target
Definition: filterCSVwithJSON.py:32
reco::JetExtendedAssociation::Value
reco::JetExtendedAssociation::JetExtendedData Value
Definition: JetExtendedAssociation.h:27
list
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
PhysicsTools::MVAModuleHelper::Value
Definition: MVAModuleHelper.h:81
PhysicsTools::MVAModuleHelper::operator()
double operator()(const Object &object) const
Definition: MVAModuleHelper.h:143
label
const char * label
Definition: PFTauDecayModeTools.cc:11
weight
Definition: weight.py:1
update
#define update(a, b)
Definition: TrackClassifier.cc:10