CMS 3D CMS Logo

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 MVAModuleHelper &orig)
 
 MVAModuleHelper (const std::string &label)
 
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 57 of file MVAModuleHelper.h.

Constructor & Destructor Documentation

◆ MVAModuleHelper() [1/2]

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

Definition at line 59 of file MVAModuleHelper.h.

59 : label(label) {}

◆ MVAModuleHelper() [2/2]

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 60 of file MVAModuleHelper.h.

60 : label(orig.label) {}

◆ ~MVAModuleHelper()

template<class Record , typename Object , class Filler = MVAModuleHelperDefaultFiller<Object>>
PhysicsTools::MVAModuleHelper< Record, Object, Filler >::~MVAModuleHelper ( )
inline

Definition at line 61 of file MVAModuleHelper.h.

61 {}

Member Function Documentation

◆ init()

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

Definition at line 118 of file MVAModuleHelper.h.

118  {
119  const std::vector<PhysicsTools::Calibration::Variable> &vars = container->find(label).inputSet;
120  values.clear();
121  for (std::vector<PhysicsTools::Calibration::Variable>::const_iterator iter = vars.begin(); iter != vars.end();
122  ++iter)
123  if (std::strncmp(iter->name.c_str(), "__", 2) != 0)
124  values.push_back(Value(iter->name));
125  }

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

◆ operator()()

template<class Record , typename Object , class Filler >
double PhysicsTools::MVAModuleHelper< Record, Object, Filler >::operator() ( const Object &  object) const

Definition at line 128 of file MVAModuleHelper.h.

128  {
129  std::for_each(values.begin(), values.end(), std::bind(&Value::update, std::placeholders::_1, object));
130  return cache->eval(values);
131  }

References utilities::cache(), update, and contentValuesCheck::values.

◆ setEventSetup() [1/2]

template<class Record , typename Object , class Filler >
void PhysicsTools::MVAModuleHelper< Record, Object, Filler >::setEventSetup ( const edm::EventSetup setup)

Definition at line 100 of file MVAModuleHelper.h.

100  {
102  setup.get<Record>().get(handle);
103  const PhysicsTools::Calibration::MVAComputerContainer *container = handle.product();
104  if (cache.update(container, label.c_str()) && cache)
105  init(container);
106  }

References utilities::cache(), get, patZpeak::handle, init, label, and singleTopDQM_cfi::setup.

◆ setEventSetup() [2/2]

template<class Record , typename Object , class Filler >
void PhysicsTools::MVAModuleHelper< Record, Object, Filler >::setEventSetup ( const edm::EventSetup setup,
const char *  esLabel 
)

Definition at line 109 of file MVAModuleHelper.h.

109  {
111  setup.get<Record>().get(esLabel, handle);
112  const PhysicsTools::Calibration::MVAComputerContainer *container = handle.product();
113  if (cache.update(container, label.c_str()) && cache)
114  init(container);
115  }

References utilities::cache(), get, patZpeak::handle, init, label, and singleTopDQM_cfi::setup.

◆ train()

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 134 of file MVAModuleHelper.h.

134  {
135  static const PhysicsTools::AtomicId kTargetId("__TARGET__");
136  static const PhysicsTools::AtomicId kWeightId("__WEIGHT__");
137 
138  if (!cache)
139  return;
140 
141  if (std::accumulate(
142  values.begin(),
143  values.end(),
144  0,
145  std::bind(
146  std::plus<int>(), std::placeholders::_1, std::bind(&Value::update, std::placeholders::_2, object))))
147  return;
148 
150  list.add(kTargetId, target);
151  list.add(kWeightId, weight);
152  for (typename std::vector<Value>::const_iterator iter = values.begin(); iter != values.end(); ++iter)
153  list.add(iter->getName(), iter->getValue());
154 
155  cache->eval(list);
156  }

References PhysicsTools::Variable::ValueList::add(), utilities::cache(), filterCSVwithJSON::target, update, and contentValuesCheck::values.

Member Data Documentation

◆ cache

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

Definition at line 74 of file MVAModuleHelper.h.

◆ label

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

◆ values

template<class Record , typename Object , class Filler = MVAModuleHelperDefaultFiller<Object>>
std::vector<Value> PhysicsTools::MVAModuleHelper< Record, Object, Filler >::values
private
PhysicsTools::AtomicId
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
PhysicsTools::MVAComputer::eval
double eval(Iterator_t first, Iterator_t last) const
evaluate variables given by a range of iterators given by first and last
PhysicsTools::MVAModuleHelper::label
const std::string label
Definition: MVAModuleHelper.h:73
patZpeak.handle
handle
Definition: patZpeak.py:23
PhysicsTools::MVAModuleHelper::Value::update
bool update(const Object &object) const
Definition: MVAModuleHelper.h:81
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
vars
vars
Definition: DeepTauId.cc:163
edm::ESHandle
Definition: DTSurvey.h:22
PhysicsTools::Variable::ValueList::add
void add(AtomicId id, double value)
Definition: Variable.h:103
PhysicsTools::MVAModuleHelper::init
void init(const PhysicsTools::Calibration::MVAComputerContainer *container)
Definition: MVAModuleHelper.h:118
PhysicsTools::MVAModuleHelper::cache
PhysicsTools::MVAComputerCache cache
Definition: MVAModuleHelper.h:74
PhysicsTools::Calibration::MVAComputer::inputSet
std::vector< Variable > inputSet
Definition: MVAComputer.h:237
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:96
get
#define get
PhysicsTools::MVAComputerCache::update
bool update(const Calibration::MVAComputer *computer)
Definition: MVAComputerCache.cc:15
Record
PhysicsTools::Calibration::MVAComputerContainer
Definition: MVAComputer.h:250
filterCSVwithJSON.target
target
Definition: filterCSVwithJSON.py:32
reco::JetExtendedAssociation::Value
reco::JetExtendedAssociation::JetExtendedData Value
Definition: JetExtendedAssociation.h:27
weight
Definition: weight.py:1