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 
29 
36 
37 namespace pat {
38 
39  template <class PATObjectType>
43  const std::vector<edm::InputTag> matches_;
44  const std::vector<edm::EDGetTokenT<TriggerObjectStandAloneMatch>> matchesTokens_;
45 
46  public:
47  explicit PATTriggerMatchEmbedder(const edm::ParameterSet& iConfig);
49 
50  private:
51  void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
52  };
53 
60 
61 } // namespace pat
62 
63 using namespace pat;
64 
65 template <class PATObjectType>
67  : src_(iConfig.getParameter<edm::InputTag>("src")),
68  srcToken_(consumes<edm::View<PATObjectType>>(src_)),
69  matches_(iConfig.getParameter<std::vector<edm::InputTag>>("matches")),
71  matches_, [this](edm::InputTag const& tag) { return consumes<TriggerObjectStandAloneMatch>(tag); })) {
72  produces<std::vector<PATObjectType>>();
73 }
74 
75 template <class PATObjectType>
78  const edm::EventSetup& iSetup) const {
79  auto output = std::make_unique<std::vector<PATObjectType>>();
80 
82  iEvent.getByToken(srcToken_, candidates);
83  if (!candidates.isValid()) {
84  edm::LogError("missingInputSource") << "Input source with InputTag " << src_.encode() << " not in event.";
85  return;
86  }
87 
88  for (typename edm::View<PATObjectType>::const_iterator iCand = candidates->begin(); iCand != candidates->end();
89  ++iCand) {
90  const unsigned index(iCand - candidates->begin());
91  PATObjectType cand(candidates->at(index));
92  std::set<TriggerObjectStandAloneRef> cachedRefs;
93  for (size_t iMatch = 0; iMatch < matchesTokens_.size(); ++iMatch) {
95  iEvent.getByToken(matchesTokens_.at(iMatch), match);
96  if (!match.isValid()) {
97  edm::LogError("missingInputMatch")
98  << "Input match with InputTag " << matches_.at(iMatch).encode() << " not in event.";
99  continue;
100  }
101  const TriggerObjectStandAloneRef trigRef((*match)[candidates->refAt(index)]);
102  if (trigRef.isNonnull() && trigRef.isAvailable()) {
103  if (cachedRefs.insert(trigRef).second) { // protection from multiple entries of the same trigger objects
104  cand.addTriggerObjectMatch(*trigRef);
105  }
106  }
107  }
108  output->push_back(cand);
109  }
110 
111  iEvent.put(std::move(output));
112 }
113 
115 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
PATTriggerMatchEmbedder(const edm::ParameterSet &iConfig)
PATTriggerMatchEmbedder< Jet > PATTriggerMatchJetEmbedder
PATTriggerMatchEmbedder< Tau > PATTriggerMatchTauEmbedder
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
PATTriggerMatchEmbedder< Electron > PATTriggerMatchElectronEmbedder
std::string encode() const
Definition: InputTag.cc:159
PATTriggerMatchEmbedder< Muon > PATTriggerMatchMuonEmbedder
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< edm::View< PATObjectType > > srcToken_
PATTriggerMatchEmbedder< Photon > PATTriggerMatchPhotonEmbedder
const std::vector< edm::InputTag > matches_
bool isValid() const
Definition: HandleBase.h:70
const std::vector< edm::EDGetTokenT< TriggerObjectStandAloneMatch > > matchesTokens_
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
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