CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecoTauMVADiscriminator.cc
Go to the documentation of this file.
1 /*
2  * RecoTauMVADiscriminator
3  *
4  * Apply an MVA discriminator to a collection of PFTaus. Output is a
5  * PFTauDiscriminator. The module takes the following options:
6  * > dbLabel - should match "appendToDataLabel" option of PoolDBSource
7  * if it exists.
8  * > mvas - a vector of PSets, each of which contains nCharged, nPiZeros
9  * and a string giving the name of the correct MVA in the
10  * MVA ComputerContainer provided PoolDBSource. This maps decay
11  * modes to MVA implementations.
12  * > defaultMVA - MVA to use if the decay mode does not match one specified in
13  * mvas.
14  * > remapOutput - TMVA gives its output from (-1, 1). If this enabled remap
15  * it to (0, 1).
16  *
17  * The interface to the MVA framework is handled by the RecoTauMVAHelper class.
18  *
19  * Author: Evan K. Friis (UC Davis)
20  *
21  */
22 
23 #include <boost/foreach.hpp>
24 #include <boost/ptr_container/ptr_map.hpp>
25 
29 
32 
35 
36 
38  public:
39  explicit RecoTauMVADiscriminator(const edm::ParameterSet& pset);
41 
42  void beginEvent(const edm::Event&, const edm::EventSetup&);
43  double discriminate(const reco::PFTauRef&);
44 
45  private:
46  // Map a decay mode to an MVA getter
47  typedef boost::ptr_map<reco::PFTau::hadronicDecayMode,
49 
50  std::auto_ptr<reco::tau::RecoTauMVAHelper> defaultMVA_;
51 
53  std::string dbLabel_;
56 };
57 
60  std::string dbLabel;
61  if (pset.exists("dbLabel"))
62  dbLabel = pset.getParameter<std::string>("dbLabel");
63 
64  unsupportedDMValue_ = (pset.exists("unsupportedDecayModeValue")) ?
65  pset.getParameter<double>("unsupportedDecayModeValue")
67 
68  remapOutput_ = pset.getParameter<bool>("remapOutput");
69 
70  edm::ParameterSet discriminantOptions = pset.getParameter<edm::ParameterSet>(
71  "discriminantOptions");
72 
73  typedef std::vector<edm::ParameterSet> VPSet;
74  const VPSet& mvas = pset.getParameter<VPSet>("mvas");
75 
76  for (VPSet::const_iterator mva = mvas.begin(); mva != mvas.end(); ++mva) {
77  unsigned int nCharged = mva->getParameter<unsigned int>("nCharged");
78  unsigned int nPiZeros = mva->getParameter<unsigned int>("nPiZeros");
80  nCharged, nPiZeros);
81  // Check to ensure this decay mode is not already added
82  if (!mvas_.count(decayMode)) {
83  std::string computerName = mva->getParameter<std::string>("mvaLabel");
84  // Add it
85  mvas_.insert(
86  decayMode, new reco::tau::RecoTauMVAHelper(
87  computerName, dbLabel, discriminantOptions));
88  } else {
89  edm::LogError("DecayModeNotUnique") << "The tau decay mode with "
90  "nCharged/nPiZero = " << nCharged << "/" << nPiZeros << " dm: "
91  << decayMode <<
92  " is associated to multiple MVA implmentations, "
93  "the second instantiation is being ignored!!!";
94  }
95  }
96 
97  // Check if we a catch-all MVA is desired.
98  if (pset.exists("defaultMVA")) {
100  pset.getParameter<std::string>("defaultMVA"),
101  dbLabel, discriminantOptions));
102  }
103 
104 }
105 
107  const edm::EventSetup& es) {
108  // Pass the event setup so the MVAHelpers can get the MVAs from the DB
109  BOOST_FOREACH(MVAMap::value_type mva, mvas_) {
110  mva.second->setEvent(evt, es);
111  }
112  if (defaultMVA_.get())
113  defaultMVA_->setEvent(evt, es);
114 }
115 
116 // Get the MVA output for a given PFTau
118  // Find the right MVA for this tau's decay mode
119  MVAMap::iterator mva = mvas_.find(tau->decayMode());
120  // If this DM has an associated decay mode, get and return the result.
121  double output = unsupportedDMValue_;
122  if (mva != mvas_.end() || defaultMVA_.get()) {
123  if (mva != mvas_.end())
124  output = mva->second->operator()(tau);
125  else
126  output = defaultMVA_->operator()(tau);
127  // TMVA produces output from -1 to 1
128  if (remapOutput_) {
129  output += 1.;
130  output /= 2.;
131  }
132  }
133  return output;
134 }
135 
T getParameter(std::string const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void beginEvent(const edm::Event &, const edm::EventSetup &)
bool exists(std::string const &parameterName) const
checks if a parameter exists
PFTau::hadronicDecayMode translateDecayMode(unsigned int nCharged, unsigned int nPiZero)
RecoTauMVADiscriminator(const edm::ParameterSet &pset)
double discriminate(const reco::PFTauRef &)
Container::value_type value_type
boost::ptr_map< reco::PFTau::hadronicDecayMode, reco::tau::RecoTauMVAHelper > MVAMap
unsigned int nCharged(const GenJet &jet)
std::auto_ptr< reco::tau::RecoTauMVAHelper > defaultMVA_
hadronicDecayMode
Definition: PFTau.h:34