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