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, const edm::ParameterSet &pluginOptions)
 
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_
 
edm::ParameterSet pluginOptions_
 
PluginMap plugins_
 
PhysicsTools::Variable::ValueList values_
 

Detailed Description

Definition at line 40 of file RecoTauMVAHelper.h.

Member Typedef Documentation

Definition at line 70 of file RecoTauMVAHelper.h.

Constructor & Destructor Documentation

reco::tau::RecoTauMVAHelper::RecoTauMVAHelper ( const std::string &  name,
const std::string &  eslabel,
const edm::ParameterSet pluginOptions 
)
explicit

Definition at line 17 of file RecoTauMVAHelper.cc.

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

Definition at line 45 of file RecoTauMVAHelper.h.

45 {}

Member Function Documentation

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

Definition at line 109 of file RecoTauMVAHelper.cc.

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

109  {
110  values_.clear();
111  fillValues(tau);
112  return values_;
113 }
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 81 of file RecoTauMVAHelper.cc.

References PhysicsTools::Variable::ValueList::add(), error, instance, edm::isNotFinite(), fwrapper::plugin, plugins_, metsig::tau, and values_.

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

81  {
82  // Loop over the relevant discriminators and the output
83  for (PluginMap::const_iterator plugin = plugins_.begin();
84  plugin != plugins_.end(); ++plugin) {
85  PhysicsTools::AtomicId id = plugin->first;
86  std::vector<double> pluginOutput = (plugin->second)->operator()(tau);
87  // Check for nans
88  for(size_t instance = 0; instance < pluginOutput.size(); ++instance) {
89  if (edm::isNotFinite(pluginOutput[instance])) {
90  std::ostringstream error;
91  error << "A nan was detected in"
92  << " the tau MVA variable " << id << " returning zero instead!"
93  << " The PFTau: " << *tau << std::endl;
94  tau->dump(error);
95  edm::LogError("CorruptedMVAInput") << error.str();
96  pluginOutput[instance] = 0.0;
97  }
98  }
99  //std::cout << "id: " << id << " first: " << pluginOutput[0] << std::endl;
100  // Build values and copy into values vector
101  std::for_each(pluginOutput.begin(), pluginOutput.end(),
103  boost::ref(values_), id, _1));
104  }
105 }
auto_ptr< JetDefinition::Plugin > plugin
static PFTauRenderPlugin instance
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:32
bool isNotFinite(T x)
Definition: isFinite.h:10
PhysicsTools::Variable::ValueList values_
void add(AtomicId id, double value)
Definition: Variable.h:107
void reco::tau::RecoTauMVAHelper::loadDiscriminantPlugins ( const PhysicsTools::Calibration::MVAComputer computer)
private

Definition at line 44 of file RecoTauMVAHelper.cc.

References edm::ParameterSet::addParameter(), SurfaceDeformationFactory::create(), reco::tau::discPluginName(), edm::ParameterSet::exists(), reco::get(), edm::ParameterSet::getParameter(), PhysicsTools::Calibration::MVAComputer::inputSet, AlCaHLTBitMon_ParallelJobs::options, pluginOptions_, plugins_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by setEvent().

45  {
46  typedef std::vector<PhysicsTools::Calibration::Variable> VarList;
47  // List of input variables for this MVA.
48  const VarList &vars = comp.inputSet;
49  // Load the plugin for each of the Var if needed
50  BOOST_FOREACH(const VarList::value_type& var, vars) {
51  // Check to make sure it isn't a magic variable
52  if (std::strncmp(var.name.c_str(), "__", 2) != 0) {
53  // If we haven't added yet, build it.
54  PhysicsTools::AtomicId varId(var.name);
55  if (!plugins_.count(varId)) {
57  if (pluginOptions_.exists(var.name)) {
58  options = pluginOptions_.getParameter<edm::ParameterSet>(var.name);
59  };
60  // Make sure it has a name (required by base class)
61  if (!options.exists("name"))
62  options.addParameter("name", "MVA_" + var.name);
63  // Check if we want to specify the plugin name manually. This is
64  // required for things like the discriminant from discriminators, which
65  // take an InputTag. If we want to have more than one, we have to be
66  // able take the MVA name (like FlightPathSig) and map it to
67  // RecoTauDiscriminantFromDiscriminator[disc input tag = flight path sig]
68  // Otherwise we just keep our regular plugin mapping.
69  std::string pluginName = reco::tau::discPluginName(var.name);
70  if (options.exists("plugin")) {
71  pluginName = options.getParameter<std::string>("plugin");
72  }
73  plugins_.insert(
75  pluginName, options));
76  }
77  }
78  }
79 }
T getParameter(std::string const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
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:145
edm::ParameterSet pluginOptions_
Container::value_type value_type
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 116 of file RecoTauMVAHelper.cc.

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

116  {
117  // Clear output
118  values_.clear();
119  // Build the values
120  fillValues(tau);
121  // Call the MVA
122  return computer_->eval(values_);
123 }
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 22 of file RecoTauMVAHelper.cc.

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

Referenced by RecoTauMVATrainer::analyze().

23  {
24  // Update our MVA from the DB
27  if (eslabel_.size()) {
28  es.get<TauTagMVAComputerRcd>().get(eslabel_, handle);
29  } else {
30  es.get<TauTagMVAComputerRcd>().get(handle);
31  }
32  const MVAComputerContainer *container = handle.product();
33  // Load our MVA
34  bool reload = computer_.update(container, name_.c_str());
35  // If the MVA changed, update our list of discriminant plugins
36  if (reload && computer_.get())
37  loadDiscriminantPlugins(container->find(name_));
38  // Update the event info for all of our discriminators
39  BOOST_FOREACH(PluginMap::value_type plugin, plugins_) {
40  plugin.second->setup(evt, es);
41  }
42 }
auto_ptr< JetDefinition::Plugin > plugin
tuple handle
Definition: patZpeak.py:22
Container::value_type value_type
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 125 of file RecoTauMVAHelper.cc.

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

126  {
127  static const PhysicsTools::AtomicId kTargetId("__TARGET__");
128  static const PhysicsTools::AtomicId kWeightId("__WEIGHT__");
129  if (!computer_)
130  return;
131  values_.clear();
132  values_.add(kTargetId, target);
133  values_.add(kWeightId, weight);
134  // Build the discriminant values
135  fillValues(tau);
137 }
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_
int weight
Definition: histoStyle.py:50
void add(AtomicId id, double value)
Definition: Variable.h:107

Member Data Documentation

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

Definition at line 67 of file RecoTauMVAHelper.h.

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

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

Definition at line 63 of file RecoTauMVAHelper.h.

Referenced by setEvent().

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

Definition at line 61 of file RecoTauMVAHelper.h.

Referenced by setEvent().

edm::ParameterSet reco::tau::RecoTauMVAHelper::pluginOptions_
private

Definition at line 65 of file RecoTauMVAHelper.h.

Referenced by loadDiscriminantPlugins().

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

Definition at line 71 of file RecoTauMVAHelper.h.

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

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

Definition at line 77 of file RecoTauMVAHelper.h.

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