CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
PhysicsTools::MVAModuleHelper< Record, Object, Filler > Class Template Reference

Template for automated variable collection and MVA computation in EDM modules. More...

#include <MVAModuleHelper.h>

Classes

class  Value
 

Public Member Functions

 MVAModuleHelper (const std::string &label)
 
 MVAModuleHelper (const MVAModuleHelper &orig)
 
double operator() (const Object &object) const
 
void setEventSetup (const edm::EventSetup &setup)
 
void setEventSetup (const edm::EventSetup &setup, const char *esLabel)
 
void train (const Object &object, bool target, double weight=1.0) const
 
 ~MVAModuleHelper ()
 

Private Member Functions

void init (const PhysicsTools::Calibration::MVAComputerContainer *container)
 

Private Attributes

PhysicsTools::MVAComputerCache cache
 
const std::string label
 
std::vector< Valuevalues
 

Detailed Description

template<class Record, typename Object, class Filler = MVAModuleHelperDefaultFiller<Object>>
class PhysicsTools::MVAModuleHelper< Record, Object, Filler >

Template for automated variable collection and MVA computation in EDM modules.

The class MVAModuleHelper can be embedded in EDM modules. It automatically collects the variables listed in the MVA training description using type traits and passes them on to the computer. The calibration and or trainer is automatically collected from the EventSetup.

Definition at line 63 of file MVAModuleHelper.h.

Constructor & Destructor Documentation

template<class Record , typename Object , class Filler = MVAModuleHelperDefaultFiller<Object>>
PhysicsTools::MVAModuleHelper< Record, Object, Filler >::MVAModuleHelper ( const std::string &  label)
inline

Definition at line 65 of file MVAModuleHelper.h.

65 : label(label) {}
template<class Record , typename Object , class Filler = MVAModuleHelperDefaultFiller<Object>>
PhysicsTools::MVAModuleHelper< Record, Object, Filler >::MVAModuleHelper ( const MVAModuleHelper< Record, Object, Filler > &  orig)
inline

Definition at line 66 of file MVAModuleHelper.h.

66 : label(orig.label) {}
template<class Record , typename Object , class Filler = MVAModuleHelperDefaultFiller<Object>>
PhysicsTools::MVAModuleHelper< Record, Object, Filler >::~MVAModuleHelper ( )
inline

Definition at line 67 of file MVAModuleHelper.h.

67 {}

Member Function Documentation

template<class Record , typename Object , class Filler >
void PhysicsTools::MVAModuleHelper< Record, Object, Filler >::init ( const PhysicsTools::Calibration::MVAComputerContainer container)
private

Definition at line 131 of file MVAModuleHelper.h.

References PhysicsTools::Calibration::MVAComputerContainer::find(), diffTwoXMLs::label, and makeHLTPrescaleTable::values.

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 }
virtual const MVAComputer & find(const std::string &label) const
Definition: MVAComputer.cc:190
reco::JetExtendedAssociation::JetExtendedData Value
std::vector< Value > values
std::vector< Variable > inputSet
Definition: MVAComputer.h:177
template<class Record , typename Object , class Filler >
double PhysicsTools::MVAModuleHelper< Record, Object, Filler >::operator() ( const Object &  object) const

Definition at line 144 of file MVAModuleHelper.h.

References update, and makeHLTPrescaleTable::values.

146 {
147  std::for_each(values.begin(), values.end(),
148  boost::bind(&Value::update, _1, object));
149  return cache->eval(values);
150 }
PhysicsTools::MVAComputerCache cache
double eval(Iterator_t first, Iterator_t last) const
evaluate variables given by a range of iterators given by first and last
std::vector< Value > values
bool update(const Object &object) const
template<class Record , typename Object , class Filler >
void PhysicsTools::MVAModuleHelper< Record, Object, Filler >::setEventSetup ( const edm::EventSetup setup)

Definition at line 109 of file MVAModuleHelper.h.

References edm::EventSetup::get(), patZpeak::handle, init, diffTwoXMLs::label, and edm::ESHandle< class >::product().

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 }
PhysicsTools::MVAComputerCache cache
tuple handle
Definition: patZpeak.py:22
bool update(const Calibration::MVAComputer *computer)
const T & get() const
Definition: EventSetup.h:55
void init(const PhysicsTools::Calibration::MVAComputerContainer *container)
T const * product() const
Definition: ESHandle.h:62
template<class Record , typename Object , class Filler >
void PhysicsTools::MVAModuleHelper< Record, Object, Filler >::setEventSetup ( const edm::EventSetup setup,
const char *  esLabel 
)

Definition at line 120 of file MVAModuleHelper.h.

References edm::EventSetup::get(), patZpeak::handle, init, diffTwoXMLs::label, and edm::ESHandle< class >::product().

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 }
PhysicsTools::MVAComputerCache cache
tuple handle
Definition: patZpeak.py:22
bool update(const Calibration::MVAComputer *computer)
const T & get() const
Definition: EventSetup.h:55
void init(const PhysicsTools::Calibration::MVAComputerContainer *container)
T const * product() const
Definition: ESHandle.h:62
template<class Record , typename Object , class Filler >
void PhysicsTools::MVAModuleHelper< Record, Object, Filler >::train ( const Object &  object,
bool  target,
double  weight = 1.0 
) const

Definition at line 153 of file MVAModuleHelper.h.

References PhysicsTools::Variable::ValueList::add(), list(), update, and makeHLTPrescaleTable::values.

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 }
PhysicsTools::MVAComputerCache cache
double eval(Iterator_t first, Iterator_t last) const
evaluate variables given by a range of iterators given by first and last
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:32
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
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

Member Data Documentation

template<class Record , typename Object , class Filler = MVAModuleHelperDefaultFiller<Object>>
PhysicsTools::MVAComputerCache PhysicsTools::MVAModuleHelper< Record, Object, Filler >::cache
private

Definition at line 80 of file MVAModuleHelper.h.

template<class Record , typename Object , class Filler = MVAModuleHelperDefaultFiller<Object>>
const std::string PhysicsTools::MVAModuleHelper< Record, Object, Filler >::label
private
template<class Record , typename Object , class Filler = MVAModuleHelperDefaultFiller<Object>>
std::vector<Value> PhysicsTools::MVAModuleHelper< Record, Object, Filler >::values
private

Definition at line 105 of file MVAModuleHelper.h.

Referenced by python.seqvaluedict.seqdict::items().