CMS 3D CMS Logo

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>

List of all members.

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, const char *esLabel)
void setEventSetup (const edm::EventSetup &setup)
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.

: 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.

: 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.

{}

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(), label, and makeHLTPrescaleTable::values.

{
        const std::vector<PhysicsTools::Calibration::Variable> &vars =
                                        container->find(label).inputSet;
        values.clear();
        for(std::vector<PhysicsTools::Calibration::Variable>::const_iterator
                        iter = vars.begin(); iter != vars.end(); ++iter)
                if (std::strncmp(iter->name.c_str(), "__", 2) != 0)
                        values.push_back(Value(iter->name));
}
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.

{
        std::for_each(values.begin(), values.end(),
                      boost::bind(&Value::update, _1, object));
        return cache->eval(values);
}
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, label, and edm::ESHandle< T >::product().

{
        edm::ESHandle<PhysicsTools::Calibration::MVAComputerContainer> handle;
        setup.get<Record>().get(esLabel, handle);
        const PhysicsTools::Calibration::MVAComputerContainer *container = handle.product();
        if (cache.update(container, label.c_str()) && cache)
                init(container);
}
template<class Record , typename Object , class Filler >
void PhysicsTools::MVAModuleHelper< Record, Object, Filler >::setEventSetup ( const edm::EventSetup setup)
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.

{
        static const PhysicsTools::AtomicId kTargetId("__TARGET__");
        static const PhysicsTools::AtomicId kWeightId("__WEIGHT__");

        if (!cache)
                return;

        using boost::bind;
        if (std::accumulate(values.begin(), values.end(), 0,
                            bind(std::plus<int>(), _1,
                                 bind(&Value::update, _2, object))))
                return;

        PhysicsTools::Variable::ValueList list;
        list.add(kTargetId, target);
        list.add(kWeightId, weight);
        for(typename std::vector<Value>::const_iterator iter = values.begin();
            iter != values.end(); ++iter)
                list.add(iter->getName(), iter->getValue());

        cache->eval(list);
}

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]

Definition at line 79 of file MVAModuleHelper.h.

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.