CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
reco::tau::RecoTauMVAHelper Class Reference

#include <RecoTauMVAHelper.h>

Public Member Functions

const
PhysicsTools::Variable::ValueList
discriminants (const PFTauRef &tau) const
 
double operator() (const PFTauRef &tau) const
 
 RecoTauMVAHelper (const std::string &name, const std::string eslabel="")
 
void setEvent (const edm::Event &evt, const edm::EventSetup &es)
 
void train (const PFTauRef &tau, bool target, double weight=1.0) const
 
 ~RecoTauMVAHelper ()
 

Private Types

typedef boost::ptr_map
< PhysicsTools::AtomicId,
RecoTauDiscriminantPlugin
PluginMap
 

Private Member Functions

void fillValues (const reco::PFTauRef &tau) const
 
void loadDiscriminantPlugins (const PhysicsTools::Calibration::MVAComputer &computer)
 

Private Attributes

PhysicsTools::MVAComputerCache computer_
 
std::string eslabel_
 
std::string name_
 
PluginMap plugins_
 
PhysicsTools::Variable::ValueList values_
 

Detailed Description

Definition at line 37 of file RecoTauMVAHelper.h.

Member Typedef Documentation

Definition at line 63 of file RecoTauMVAHelper.h.

Constructor & Destructor Documentation

reco::tau::RecoTauMVAHelper::RecoTauMVAHelper ( const std::string &  name,
const std::string  eslabel = "" 
)
explicit

Definition at line 15 of file RecoTauMVAHelper.cc.

reco::tau::RecoTauMVAHelper::~RecoTauMVAHelper ( )
inline

Definition at line 41 of file RecoTauMVAHelper.h.

41 {}

Member Function Documentation

const PhysicsTools::Variable::ValueList & reco::tau::RecoTauMVAHelper::discriminants ( const PFTauRef tau) const

Definition at line 87 of file RecoTauMVAHelper.cc.

References PhysicsTools::Variable::ValueList::clear(), fillValues(), and values_.

87  {
88  values_.clear();
89  fillValues(tau);
90  return values_;
91 }
void fillValues(const reco::PFTauRef &tau) const
PhysicsTools::Variable::ValueList values_
void reco::tau::RecoTauMVAHelper::fillValues ( const reco::PFTauRef tau) const
private

Definition at line 63 of file RecoTauMVAHelper.cc.

References PhysicsTools::Variable::ValueList::add(), edm::detail::isnan(), python.pfTaus_cff::plugin, plugins_, metsig::tau, and values_.

Referenced by discriminants(), operator()(), and train().

63  {
64  // Loop over the relevant discriminators and the output
65  for (PluginMap::const_iterator plugin = plugins_.begin();
66  plugin != plugins_.end(); ++plugin) {
67  PhysicsTools::AtomicId id = plugin->first;
68  std::vector<double> pluginOutput = (plugin->second)->operator()(tau);
69  // Check for nans
70  for(size_t instance = 0; instance < pluginOutput.size(); ++instance) {
71  if (std::isnan(pluginOutput[instance])) {
72  edm::LogError("CorruptedMVAInput") << "A nan was detected in"
73  << " the tau MVA variable " << id << " returning zero instead!";
74  pluginOutput[instance] = 0.0;
75  }
76  }
77  //std::cout << "id: " << id << " first: " << pluginOutput[0] << std::endl;
78  // Build values and copy into values vector
79  std::for_each(pluginOutput.begin(), pluginOutput.end(),
81  boost::ref(values_), id, _1));
82  }
83 }
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:32
PhysicsTools::Variable::ValueList values_
bool isnan(float x)
Definition: math.h:13
void add(AtomicId id, double value)
Definition: Variable.h:107
void reco::tau::RecoTauMVAHelper::loadDiscriminantPlugins ( const PhysicsTools::Calibration::MVAComputer computer)
private

Definition at line 41 of file RecoTauMVAHelper.cc.

References edm::ParameterSet::addParameter(), SurfaceDeformationFactory::create(), reco::tau::discPluginName(), reco::get(), PhysicsTools::Calibration::MVAComputer::inputSet, and plugins_.

Referenced by setEvent().

42  {
43  typedef std::vector<PhysicsTools::Calibration::Variable> VarList;
44  // List of input variables for this MVA.
45  const VarList &vars = comp.inputSet;
46  // Load the plugin for each of the Var if needed
47  BOOST_FOREACH(const VarList::value_type& var, vars) {
48  // Check to make sure it isn't a magic variable
49  if (std::strncmp(var.name.c_str(), "__", 2) != 0) {
50  // If we haven't added yet, build it.
51  PhysicsTools::AtomicId varId(var.name);
52  if (!plugins_.count(varId)) {
53  edm::ParameterSet fakePSet;
54  fakePSet.addParameter("name", "MVA_" + var.name);
55  plugins_.insert(
57  reco::tau::discPluginName(var.name), fakePSet));
58  }
59  }
60  }
61 }
Container::value_type value_type
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:32
std::string discPluginName(const std::string &mvaName)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:138
SurfaceDeformation * create(int type, const std::vector< double > &params)
T get(const Candidate &c)
Definition: component.h:56
double reco::tau::RecoTauMVAHelper::operator() ( const PFTauRef tau) const

Definition at line 94 of file RecoTauMVAHelper.cc.

References PhysicsTools::Variable::ValueList::clear(), computer_, PhysicsTools::MVAComputer::eval(), fillValues(), and values_.

94  {
95  // Clear output
96  values_.clear();
97  // Build the values
98  fillValues(tau);
99  // Call the MVA
100  return computer_->eval(values_);
101 }
double eval(Iterator_t first, Iterator_t last) const
evaluate variables given by a range of iterators given by first and last
void fillValues(const reco::PFTauRef &tau) const
PhysicsTools::Variable::ValueList values_
PhysicsTools::MVAComputerCache computer_
void reco::tau::RecoTauMVAHelper::setEvent ( const edm::Event evt,
const edm::EventSetup es 
)

Definition at line 19 of file RecoTauMVAHelper.cc.

References computer_, eslabel_, edm::EventSetup::get(), PhysicsTools::MVAComputerCache::get(), patZpeak::handle, loadDiscriminantPlugins(), name_, python.pfTaus_cff::plugin, plugins_, edm::ESHandle< class >::product(), and PhysicsTools::MVAComputerCache::update().

Referenced by RecoTauMVATrainer::analyze().

20  {
21  // Update the event info for all of our discriminators
22  BOOST_FOREACH(PluginMap::value_type plugin, plugins_) {
23  plugin.second->setup(evt, es);
24  }
25  // Update our MVA from the DB
28  if (eslabel_.size()) {
29  es.get<TauTagMVAComputerRcd>().get(eslabel_, handle);
30  } else {
31  es.get<TauTagMVAComputerRcd>().get(handle);
32  }
33  const MVAComputerContainer *container = handle.product();
34  // Load our MVA
35  bool reload = computer_.update(container, name_.c_str());
36  // If the MVA changed, update our list of discriminant plugins
37  if (reload && computer_.get())
38  loadDiscriminantPlugins(container->find(name_));
39 }
Container::value_type value_type
tuple handle
Definition: patZpeak.py:22
bool update(const Calibration::MVAComputer *computer)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
PhysicsTools::MVAComputerCache computer_
void loadDiscriminantPlugins(const PhysicsTools::Calibration::MVAComputer &computer)
void reco::tau::RecoTauMVAHelper::train ( const PFTauRef tau,
bool  target,
double  weight = 1.0 
) const

Definition at line 103 of file RecoTauMVAHelper.cc.

References PhysicsTools::Variable::ValueList::add(), PhysicsTools::Variable::ValueList::clear(), computer_, PhysicsTools::MVAComputer::eval(), fillValues(), and values_.

104  {
105  static const PhysicsTools::AtomicId kTargetId("__TARGET__");
106  static const PhysicsTools::AtomicId kWeightId("__WEIGHT__");
107  if (!computer_)
108  return;
109  values_.clear();
110  values_.add(kTargetId, target);
111  values_.add(kWeightId, weight);
112  // Build the discriminant values
113  fillValues(tau);
115 }
double eval(Iterator_t first, Iterator_t last) const
evaluate variables given by a range of iterators given by first and last
void fillValues(const reco::PFTauRef &tau) const
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:32
PhysicsTools::Variable::ValueList values_
PhysicsTools::MVAComputerCache computer_
void add(AtomicId id, double value)
Definition: Variable.h:107

Member Data Documentation

PhysicsTools::MVAComputerCache reco::tau::RecoTauMVAHelper::computer_
private

Definition at line 60 of file RecoTauMVAHelper.h.

Referenced by operator()(), setEvent(), and train().

std::string reco::tau::RecoTauMVAHelper::eslabel_
private

Definition at line 59 of file RecoTauMVAHelper.h.

Referenced by setEvent().

std::string reco::tau::RecoTauMVAHelper::name_
private

Definition at line 57 of file RecoTauMVAHelper.h.

Referenced by Config.Process::fillProcessDesc(), and setEvent().

PluginMap reco::tau::RecoTauMVAHelper::plugins_
private

Definition at line 64 of file RecoTauMVAHelper.h.

Referenced by fillValues(), loadDiscriminantPlugins(), and setEvent().

PhysicsTools::Variable::ValueList reco::tau::RecoTauMVAHelper::values_
mutableprivate

Definition at line 70 of file RecoTauMVAHelper.h.

Referenced by discriminants(), fillValues(), operator()(), and train().