CMS 3D CMS Logo

PFTauViewRefSelector.cc
Go to the documentation of this file.
1 /* \class CandViewRefSelector
2  *
3  * PFTau Selector based on a configurable cut.
4  * Reads a edm::View<PFTau> as input
5  * and saves a vector of references
6  * Usage:
7  *
8  * module selectedCands = PFTauViewRefSelector {
9  * InputTag src = myCollection
10  * string cut = "pt > 15.0"
11  * };
12  *
13  * \author: Luca Lista, INFN
14  * \modifications: Evan Friis, UC Davis
15  *
16  */
17 
18 #include <boost/foreach.hpp>
19 
22 
25 
31 
33  public:
36  bool filter(edm::Event& evt, const edm::EventSetup& es) override;
37  private:
40  std::unique_ptr<StringCutObjectSelector<reco::PFTau> > outputSelector_;
41  bool filter_;
42 };
43 
45  src_ = pset.getParameter<edm::InputTag>("src");
46  std::string cut = pset.getParameter<std::string>("cut");
47  filter_ = pset.exists("filter") ? pset.getParameter<bool>("filter") : false;
48  outputSelector_ = std::make_unique<StringCutObjectSelector<reco::PFTau>>(cut);
49  produces<reco::PFTauRefVector>();
50 }
51 
52 bool
54  auto output = std::make_unique<reco::PFTauRefVector>();
55  // Get the input collection to clean
57  evt.getByLabel(src_, input);
58  // Cast the input candidates to Refs to real taus
59  reco::PFTauRefVector inputRefs =
60  reco::tau::castView<reco::PFTauRefVector>(input);
61 
62  BOOST_FOREACH(const reco::PFTauRef &tau, inputRefs) {
63  if (outputSelector_.get() && (*outputSelector_)(*tau)) {
64  output->push_back(tau);
65  }
66  }
67  size_t outputSize = output->size();
68  evt.put(std::move(output));
69  // Filter if desired and no objects passed our cut
70  return !(filter_ && outputSize == 0);
71 }
72 
74 
77 typedef SingleObjectSelector<
81 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
SingleObjectSelector< edm::View< reco::Jet >, StringCutObjectSelector< reco::Jet, true > > JetViewRefSelector
static std::string const input
Definition: EdmProvDump.cc:44
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > outputSelector_
bool filter(edm::Event &evt, const edm::EventSetup &es) override
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
PFTauViewRefSelector(const edm::ParameterSet &pset)
def move(src, dest)
Definition: eostools.py:510