CMS 3D CMS Logo

PATTriggerMatchEmbedder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PatAlgos
4 // Class: pat::PATTriggerMatchEmbedder
5 //
15 //
16 //
17 
18 #include <vector>
19 
21 
30 
37 
38 namespace pat {
39 
40  template <class PATObjectType>
44  const std::vector<edm::InputTag> matches_;
45  const std::vector<edm::EDGetTokenT<TriggerObjectStandAloneMatch>> matchesTokens_;
46 
47  public:
48  explicit PATTriggerMatchEmbedder(const edm::ParameterSet& iConfig);
50 
51  private:
52  void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
53  };
54 
61 
62 } // namespace pat
63 
64 using namespace pat;
65 
66 template <class PATObjectType>
68  : src_(iConfig.getParameter<edm::InputTag>("src")),
69  srcToken_(consumes<edm::View<PATObjectType>>(src_)),
70  matches_(iConfig.getParameter<std::vector<edm::InputTag>>("matches")),
71  matchesTokens_(edm::vector_transform(
72  matches_, [this](edm::InputTag const& tag) { return consumes<TriggerObjectStandAloneMatch>(tag); })) {
73  produces<std::vector<PATObjectType>>();
74 }
75 
76 template <class PATObjectType>
79  const edm::EventSetup& iSetup) const {
80  auto output = std::make_unique<std::vector<PATObjectType>>();
81 
83  iEvent.getByToken(srcToken_, candidates);
84  if (!candidates.isValid()) {
85  edm::LogError("missingInputSource") << "Input source with InputTag " << src_.encode() << " not in event.";
86  return;
87  }
88 
89  for (typename edm::View<PATObjectType>::const_iterator iCand = candidates->begin(); iCand != candidates->end();
90  ++iCand) {
91  const unsigned index(iCand - candidates->begin());
92  PATObjectType cand(candidates->at(index));
93  std::set<TriggerObjectStandAloneRef> cachedRefs;
94  for (size_t iMatch = 0; iMatch < matchesTokens_.size(); ++iMatch) {
96  iEvent.getByToken(matchesTokens_.at(iMatch), match);
97  if (!match.isValid()) {
98  edm::LogError("missingInputMatch")
99  << "Input match with InputTag " << matches_.at(iMatch).encode() << " not in event.";
100  continue;
101  }
102  const TriggerObjectStandAloneRef trigRef((*match)[candidates->refAt(index)]);
103  if (trigRef.isNonnull() && trigRef.isAvailable()) {
104  if (cachedRefs.insert(trigRef).second) { // protection from multiple entries of the same trigger objects
105  cand.addTriggerObjectMatch(*trigRef);
106  }
107  }
108  }
109  output->push_back(cand);
110  }
111 
112  iEvent.put(std::move(output));
113 }
114 
116 
PATTriggerMatchEmbedder(const edm::ParameterSet &iConfig)
PATTriggerMatchEmbedder< Jet > PATTriggerMatchJetEmbedder
PATTriggerMatchEmbedder< Tau > PATTriggerMatchTauEmbedder
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
Log< level::Error, false > LogError
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
PATTriggerMatchEmbedder< Electron > PATTriggerMatchElectronEmbedder
PATTriggerMatchEmbedder< Muon > PATTriggerMatchMuonEmbedder
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< edm::View< PATObjectType > > srcToken_
PATTriggerMatchEmbedder< Photon > PATTriggerMatchPhotonEmbedder
const std::vector< edm::InputTag > matches_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const std::vector< edm::EDGetTokenT< TriggerObjectStandAloneMatch > > matchesTokens_
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
PATTriggerMatchEmbedder< MET > PATTriggerMatchMETEmbedder
def move(src, dest)
Definition: eostools.py:511