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

64 : 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 65 of file MVAModuleHelper.h.

65 : label(orig.label) {}

◆ ~MVAModuleHelper()

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

Definition at line 66 of file MVAModuleHelper.h.

66 {}

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

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 }

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

145 {
146  std::for_each(values.begin(), values.end(),
147  boost::bind(&Value::update, _1, object));
148  return cache->eval(values);
149 }

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

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 }

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

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 }

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

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 }

References utilities::cache(), list(), 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 79 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:78
patZpeak.handle
handle
Definition: patZpeak.py:23
PhysicsTools::MVAModuleHelper::Value::update
bool update(const Object &object) const
Definition: MVAModuleHelper.h:88
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::MVAModuleHelper::init
void init(const PhysicsTools::Calibration::MVAComputerContainer *container)
Definition: MVAModuleHelper.h:130
PhysicsTools::MVAModuleHelper::cache
PhysicsTools::MVAComputerCache cache
Definition: MVAModuleHelper.h:79
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:104
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
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
weight
Definition: weight.py:1