CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFTauSelectorDefinition.h
Go to the documentation of this file.
1 #ifndef RecoTauTag_TauTagTools_PFTauSelectorDefinition
2 #define RecoTauTag_TauTagTools_PFTauSelectorDefinition
3 
6 
8 
9 #include <memory>
10 #include <boost/foreach.hpp>
11 
12 #include <iostream>
13 
15 
18  typedef std::vector< const reco::PFTau *> container;
19  typedef container::const_iterator const_iterator;
20 
21  struct DiscCutPair {
24  double cut;
25  };
26  typedef std::vector<DiscCutPair> DiscCutPairVec;
27 
29  std::vector<edm::ParameterSet> discriminators =
30  cfg.getParameter<std::vector<edm::ParameterSet> >("discriminators");
31  // Build each of our cuts
32  BOOST_FOREACH(const edm::ParameterSet &pset, discriminators) {
33  DiscCutPair newCut;
34  newCut.inputTag = pset.getParameter<edm::InputTag>("discriminator");
35  newCut.cut = pset.getParameter<double>("selectionCut");
36  discriminators_.push_back(newCut);
37  }
38 
39  // Build a string cut if desired
40  if (cfg.exists("cut")) {
42  cfg.getParameter<std::string>( "cut" )));
43  }
44  }
45 
46  const_iterator begin() const { return selected_.begin(); }
47  const_iterator end() const { return selected_.end(); }
48 
49  void select(const HandleToCollection & hc, const edm::Event & e,
50  const edm::EventSetup& s) {
51  selected_.clear();
52 
53  if (!hc.isValid()) {
54  throw cms::Exception("PFTauSelectorBadHandle")
55  << "an invalid PFTau handle with ProductID"
56  << hc.id() << " passed to PFTauSelector.";
57  }
58 
59  // Load each discriminator
60  BOOST_FOREACH(DiscCutPair &disc, discriminators_) {
61  e.getByLabel(disc.inputTag, disc.handle);
62  }
63 
64  const size_t nTaus = hc->size();
65  for (size_t iTau = 0; iTau < nTaus; ++iTau) {
66  bool passed = true;
67  reco::PFTauRef tau(hc, iTau);
68  // Check if it passed all the discrimiantors
69  BOOST_FOREACH(const DiscCutPair &disc, discriminators_) {
70  // Check this discriminator passes
71  if (!(*disc.handle)[tau] > disc.cut) {
72  passed = false;
73  break;
74  }
75  }
76 
77  if (passed && cut_.get()) {
78  passed = (*cut_)(*tau);
79  }
80 
81  if (passed)
82  selected_.push_back(tau.get());
83  }
84  } // end select()
85 
86  size_t size() const { return selected_.size(); }
87 
88  private:
91  std::auto_ptr<StringCutObjectSelector<reco::PFTau> > cut_;
92 
93 };
94 
95 #endif
T getParameter(std::string const &) const
reco::PFTauCollection collection
std::vector< const reco::PFTau * > container
const_iterator begin() const
std::vector< PFTau > PFTauCollection
collection of PFTau objects
Definition: PFTauFwd.h:9
ProductID id() const
Definition: HandleBase.cc:15
bool exists(std::string const &parameterName) const
checks if a parameter exists
void select(const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s)
edm::Handle< collection > HandleToCollection
container::const_iterator const_iterator
PFTauSelectorDefinition(const edm::ParameterSet &cfg)
const_iterator end() const
edm::Handle< reco::PFTauDiscriminator > handle
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
std::vector< DiscCutPair > DiscCutPairVec
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
std::auto_ptr< StringCutObjectSelector< reco::PFTau > > cut_