CMS 3D CMS Logo

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 <sstream>
15 
16 namespace reco::tau {
17 
19  public:
21  const edm::ParameterSet& pset);
22  void beginEvent() override;
23  std::vector<double> operator()(const reco::PFTauRef& tau) const override;
24  private:
25  bool takeAbs_;
26  double min_;
27  double max_;
28  typedef std::pair<edm::InputTag, edm::Handle<reco::PFTauDiscriminator> > DiscInfo;
29  std::vector<DiscInfo> discriminators_;
30 };
31 
34 
35  takeAbs_ = pset.getParameter<bool>("takeAbs");
36  min_ = pset.getParameter<double>("minValue");
37  max_ = pset.getParameter<double>("maxValue");
38 
39  std::vector<edm::InputTag> discriminators =
40  pset.getParameter<std::vector<edm::InputTag> >("discSrc");
41  for(auto const& tag : discriminators) {
42  discriminators_.push_back(std::make_pair(tag, edm::Handle<reco::PFTauDiscriminator>()));
43  }
44 }
45 
46 // Called by base class at the beginning of every event
48  for(auto& discInfo : discriminators_) {
49  evt()->getByLabel(discInfo.first, discInfo.second);
50  }
51 }
52 
54  const reco::PFTauRef& tau) const {
55  edm::ProductID tauProdId = tau.id();
56  double result = -999;
57  bool foundGoodDiscriminator = false;
58  for (size_t i = 0; i < discriminators_.size(); ++i) {
59  // Check if the discriminator actually exists
60  if (!discriminators_[i].second.isValid())
61  continue;
62  const reco::PFTauDiscriminator& disc = *(discriminators_[i].second);
63  if (tauProdId == disc.keyProduct().id()) {
64  foundGoodDiscriminator = true;
65  result = (disc)[tau];
66  break;
67  }
68  }
69  // In case no discriminator is found.
70  if (!foundGoodDiscriminator) {
71  std::stringstream error;
72  error << "Couldn't find a PFTauDiscriminator usable with given tau."
73  << std::endl << " Input tau has product id: " << tau.id() << std::endl;
74  for (size_t i = 0; i < discriminators_.size(); ++i ) {
75  error << "disc: " << discriminators_[i].first;
76  error << " isValid: " << discriminators_[i].second.isValid();
77  if (discriminators_[i].second.isValid()) {
78  error << " product: " << discriminators_[i].second->keyProduct().id();
79  }
80  error << std::endl;
81  }
82  edm::LogError("BadDiscriminatorConfiguration") << error.str();
83  }
84  if (result < min_)
85  result = min_;
86  if (result > max_)
87  result = max_;
88  return std::vector<double>(1, result);
89 }
90 
91 } // end namespace reco::tau
92 
96  "RecoTauDiscriminantFromDiscriminator");
T getParameter(std::string const &) const
std::vector< double > operator()(const reco::PFTauRef &tau) const override
ProductID id() const
Accessor for product ID.
Definition: Ref.h:257
U second(std::pair< T, U > const &p)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
KeyRefProd const & keyProduct() const
std::pair< edm::InputTag, edm::Handle< reco::PFTauDiscriminator > > DiscInfo
#define DEFINE_EDM_PLUGIN(factory, type, name)