CMS 3D CMS Logo

PFTauSelectorDefinition.h
Go to the documentation of this file.
1 #ifndef RecoTauTag_TauTagTools_PFTauSelectorDefinition
2 #define RecoTauTag_TauTagTools_PFTauSelectorDefinition
3 
7 
10 
12 
13 #include <memory>
14 #include <boost/foreach.hpp>
15 
16 #include <iostream>
17 
19 
22  typedef std::vector< const reco::PFTau *> container;
23  typedef container::const_iterator const_iterator;
24 
25  struct DiscCutPair {
28  double cut;
29  };
30  typedef std::vector<DiscCutPair> DiscCutPairVec;
31 
33  std::vector<edm::ParameterSet> discriminators =
34  cfg.getParameter<std::vector<edm::ParameterSet> >("discriminators");
35  // Build each of our cuts
36  BOOST_FOREACH(const edm::ParameterSet &pset, discriminators) {
37  DiscCutPair newCut;
38  newCut.inputToken = iC.consumes<reco::PFTauDiscriminator>(pset.getParameter<edm::InputTag>("discriminator"));
39  newCut.cut = pset.getParameter<double>("selectionCut");
40  discriminators_.push_back(newCut);
41  }
42 
43  // Build a string cut if desired
44  if (cfg.exists("cut")) {
46  cfg.getParameter<std::string>( "cut" )));
47  }
48  }
49 
50  const_iterator begin() const { return selected_.begin(); }
51  const_iterator end() const { return selected_.end(); }
52 
53  void select(const HandleToCollection & hc, const edm::Event & e,
54  const edm::EventSetup& s) {
55  selected_.clear();
56 
57  if (!hc.isValid()) {
58  throw cms::Exception("PFTauSelectorBadHandle")
59  << "an invalid PFTau handle with ProductID"
60  << hc.id() << " passed to PFTauSelector.";
61  }
62 
63  // Load each discriminator
64  BOOST_FOREACH(DiscCutPair &disc, discriminators_) {
65  e.getByToken(disc.inputToken, disc.handle);
66  }
67 
68  const size_t nTaus = hc->size();
69  for (size_t iTau = 0; iTau < nTaus; ++iTau) {
70  bool passed = true;
71  reco::PFTauRef tau(hc, iTau);
72  // Check if it passed all the discrimiantors
73  BOOST_FOREACH(const DiscCutPair &disc, discriminators_) {
74  // Check this discriminator passes
75  if (!((*disc.handle)[tau] > disc.cut)) {
76  passed = false;
77  break;
78  }
79  }
80 
81  if (passed && cut_.get()) {
82  passed = (*cut_)(*tau);
83  }
84 
85  if (passed)
86  selected_.push_back(tau.get());
87  }
88  } // end select()
89 
90  size_t size() const { return selected_.size(); }
91 
92  private:
93  container selected_;
94  DiscCutPairVec discriminators_;
95  std::auto_ptr<StringCutObjectSelector<reco::PFTau> > cut_;
96 
97 };
98 
99 #endif
PFTauSelectorDefinition(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
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 getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
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
const_iterator end() const
edm::Handle< reco::PFTauDiscriminator > handle
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:245
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< reco::PFTauDiscriminator > inputToken
susybsm::HSCParticleCollection hc
Definition: classes.h:25
std::vector< DiscCutPair > DiscCutPairVec
std::auto_ptr< StringCutObjectSelector< reco::PFTau > > cut_