CMS 3D CMS Logo

RecoTauGenJetMatchSelector.cc
Go to the documentation of this file.
1 /*
2  * AssociationMatchRefSelector
3  *
4  * EDFilter template to select objects from a View<InputType> that have valid
5  * matches in the given Association<MatchedType> matching, and produce a
6  * RefToBaseVector pointing to the matched objects.
7  *
8  * Author: Evan K. Friis (UC Davis)
9  *
10  */
11 
20 
21 namespace reco { namespace tau {
22 
23 namespace {
24 
25 // When the output is a RefToBaseVector<Candidate>, we need to copy the input
26 // RefToBases. (otherwise we get a complaint since Ref<Candidate> is not the
27 // concrete type. When storing RefVectors to PFTaus we need to cast the refs
28 // correctly.
29 
30 class RefCaster {
31  public:
32  template<typename InBaseRef, typename REF>
33  REF convert(const InBaseRef& in) const {
34  return in.template castTo<REF>();
35  }
36 };
37 
38 class RefCopier {
39  public:
40  template<typename InBaseRef, typename REF>
41  REF convert(const InBaseRef& in) const {
42  return REF(in);
43  }
44 };
45 
46 }
47 
48 template<typename InputType, typename MatchedType,
49  typename OutputType=typename edm::RefToBaseVector<InputType>,
50  typename ClonePolicy=RefCopier>
52  public:
53  //typedef typename edm::RefToBaseVector<InputType> OutputType;
57 
59  src_ = pset.getParameter<edm::InputTag>("src");
60  matching_ = pset.getParameter<edm::InputTag>("matching");
61  filter_ = pset.getParameter<bool>("filter");
62  produces<OutputType>();
63  }
64  bool filter(edm::Event& evt, const edm::EventSetup &es) override {
66  evt.getByLabel(src_, input);
68  evt.getByLabel(matching_, match);
69  auto output = std::make_unique<OutputType>();
70  for (size_t i = 0; i < input->size(); ++i) {
71  typename AssocType::reference_type matched = (*match)[input->refAt(i)];
72  // Check if matched
73  if (matched.isNonnull()) {
74  OutputValue toPut =
75  cloner_.template convert<InputRef, OutputValue>(input->refAt(i));
76  output->push_back(toPut);
77  }
78  }
79  bool notEmpty = !output->empty();
80  evt.put(std::move(output));
81  // Filter if no events passed
82  return ( !filter_ || notEmpty );
83  }
84  private:
85  ClonePolicy cloner_;
88  bool filter_;
89 };
90 }} // end reco::tau
91 
97 
100 
103  reco::tau::RefCaster> CandViewPFTauMatchRefSelector;
104 
T getParameter(std::string const &) const
InputType
Definition: InputType.h:5
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
std::vector< PFTau > PFTauCollection
collection of PFTau objects
Definition: PFTauFwd.h:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< GenJet > GenJetCollection
collection of GenJet objects
edm::RefVector< PFTauCollection > PFTauRefVector
vector of references to PFTau objects all in the same collection
Definition: PFTauFwd.h:17
AssociationMatchRefSelector(const edm::ParameterSet &pset)
static std::string const input
Definition: EdmProvDump.cc:44
reco::tau::AssociationMatchRefSelector< reco::Candidate, reco::GenJetCollection > CandViewGenJetMatchRefSelector
def convert(infile, ofile)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
reco::tau::AssociationMatchRefSelector< reco::Candidate, reco::PFTauCollection, reco::PFTauRefVector, reco::tau::RefCaster > CandViewPFTauMatchRefSelector
fixed size matrix
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
bool filter(edm::Event &evt, const edm::EventSetup &es) override
def move(src, dest)
Definition: eostools.py:510