test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecoTauDiscriminantFromDiscriminator.cc
Go to the documentation of this file.
1 /*
2  * RecoTauDiscriminantFromDiscriminator
3  *
4  * Makes a discriminator function from a PFRecoTauDiscriminator stored in the
5  * event.
6  *
7  * Author: Evan K. Friis (UC Davis)
8  *
9  */
10 
11 #include <boost/foreach.hpp>
12 #include <sstream>
16 
17 namespace reco { namespace tau {
18 
20  public:
22  const edm::ParameterSet& pset);
23  void beginEvent() override;
24  std::vector<double> operator()(const reco::PFTauRef& tau) const override;
25  private:
26  bool takeAbs_;
27  double min_;
28  double max_;
29  typedef std::pair<edm::InputTag, edm::Handle<reco::PFTauDiscriminator> > DiscInfo;
30  std::vector<DiscInfo> discriminators_;
31 };
32 
35  takeAbs_ = pset.existsAs<bool>("takeAbs") ?
36  pset.getParameter<bool>("takeAbs") : false;
37  min_ = pset.existsAs<double>("minValue") ?
38  pset.getParameter<double>("minValue") : -1*std::numeric_limits<double>::max();
39  max_ = pset.existsAs<double>("maxValue") ?
40  pset.getParameter<double>("maxValue") : std::numeric_limits<double>::max();
41 
42  if (pset.existsAs<edm::InputTag>("discSrc")) {
43  discriminators_.push_back(std::make_pair(
44  pset.getParameter<edm::InputTag>("discSrc"),
46  } else {
47  // Get multiple discriminators. This supports the case when the MVAHelper
48  // class might be dealing with multiple tau collections (training)
49  std::vector<edm::InputTag> discriminators =
50  pset.getParameter<std::vector<edm::InputTag> >("discSrc");
51  BOOST_FOREACH(const edm::InputTag& tag, discriminators) {
52  discriminators_.push_back(std::make_pair(
54  }
55  }
56 }
57 
58 // Called by base class at the beginning of every event
60  BOOST_FOREACH(DiscInfo& discInfo, discriminators_) {
61  evt()->getByLabel(discInfo.first, discInfo.second);
62  }
63 }
64 
66  const reco::PFTauRef& tau) const {
67  edm::ProductID tauProdId = tau.id();
68  double result = -999;
69  bool foundGoodDiscriminator = false;
70  for (size_t i = 0; i < discriminators_.size(); ++i) {
71  // Check if the discriminator actually exists
72  if (!discriminators_[i].second.isValid())
73  continue;
74  const reco::PFTauDiscriminator& disc = *(discriminators_[i].second);
75  if (tauProdId == disc.keyProduct().id()) {
76  foundGoodDiscriminator = true;
77  result = (disc)[tau];
78  break;
79  }
80  }
81  // In case no discriminator is found.
82  if (!foundGoodDiscriminator) {
83  std::stringstream error;
84  error << "Couldn't find a PFTauDiscriminator usable with given tau."
85  << std::endl << " Input tau has product id: " << tau.id() << std::endl;
86  for (size_t i = 0; i < discriminators_.size(); ++i ) {
87  error << "disc: " << discriminators_[i].first;
88  error << " isValid: " << discriminators_[i].second.isValid();
89  if (discriminators_[i].second.isValid()) {
90  error << " product: " << discriminators_[i].second->keyProduct().id();
91  }
92  error << std::endl;
93  }
94  edm::LogError("BadDiscriminatorConfiguration") << error.str();
95  }
96  if (result < min_)
97  result = min_;
98  if (result > max_)
99  result = max_;
100  return std::vector<double>(1, result);
101 }
102 
103 }} // end namespace reco::tau
104 
108  "RecoTauDiscriminantFromDiscriminator");
T getParameter(std::string const &) const
std::vector< double > operator()(const reco::PFTauRef &tau) const override
int i
Definition: DBlmapReader.cc:9
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
tuple result
Definition: mps_fire.py:83
U second(std::pair< T, U > const &p)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
KeyRefProd const & keyProduct() const
std::pair< edm::InputTag, edm::Handle< reco::PFTauDiscriminator > > DiscInfo
#define DEFINE_EDM_PLUGIN(factory, type, name)