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 
19 #include <vector>
20 
22 
30 
37 
38 
39 namespace pat {
40 
41  template< class PATObjectType >
43 
46  const std::vector< edm::InputTag > matches_;
47  const std::vector< edm::EDGetTokenT< TriggerObjectStandAloneMatch > > matchesTokens_;
48 
49  public:
50 
51  explicit PATTriggerMatchEmbedder( const edm::ParameterSet & iConfig );
52  ~PATTriggerMatchEmbedder() override {};
53 
54  private:
55 
56  void produce( edm::StreamID, edm::Event & iEvent, const edm::EventSetup& iSetup) const override;
57 
58  };
59 
66 
67 }
68 
69 
70 using namespace pat;
71 
72 
73 template< class PATObjectType >
75  src_( iConfig.getParameter< edm::InputTag >( "src" ) ),
76  srcToken_( consumes< edm::View< PATObjectType > >( src_ ) ),
77  matches_( iConfig.getParameter< std::vector< edm::InputTag > >( "matches" ) ),
78  matchesTokens_( edm::vector_transform( matches_, [this](edm::InputTag const & tag) { return consumes< TriggerObjectStandAloneMatch >( tag ); } ) )
79 {
80  produces< std::vector< PATObjectType > >();
81 }
82 
83 template< class PATObjectType >
85 {
86  auto output = std::make_unique<std::vector<PATObjectType>>();
87 
89  iEvent.getByToken( srcToken_, candidates );
90  if ( ! candidates.isValid() ) {
91  edm::LogError( "missingInputSource" ) << "Input source with InputTag " << src_.encode() << " not in event.";
92  return;
93  }
94 
95  for ( typename edm::View< PATObjectType >::const_iterator iCand = candidates->begin(); iCand != candidates->end(); ++iCand ) {
96  const unsigned index( iCand - candidates->begin() );
97  PATObjectType cand( candidates->at( index ) );
98  std::set< TriggerObjectStandAloneRef > cachedRefs;
99  for ( size_t iMatch = 0; iMatch < matchesTokens_.size(); ++iMatch ) {
101  iEvent.getByToken( matchesTokens_.at( iMatch ), match );
102  if ( ! match.isValid() ) {
103  edm::LogError( "missingInputMatch" ) << "Input match with InputTag " << matches_.at( iMatch ).encode() << " not in event.";
104  continue;
105  }
106  const TriggerObjectStandAloneRef trigRef( ( *match )[ candidates->refAt( index ) ] );
107  if ( trigRef.isNonnull() && trigRef.isAvailable() ) {
108  if ( cachedRefs.insert( trigRef ).second ) { // protection from multiple entries of the same trigger objects
109  cand.addTriggerObjectMatch( *trigRef );
110  }
111  }
112  }
113  output->push_back( cand );
114  }
115 
116  iEvent.put(std::move(output) );
117 }
118 
119 
121 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
const std::vector< edm::InputTag > matches_
PATTriggerMatchEmbedder(const edm::ParameterSet &iConfig)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
PATTriggerMatchEmbedder< Electron > PATTriggerMatchElectronEmbedder
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
PATTriggerMatchEmbedder< Photon > PATTriggerMatchPhotonEmbedder
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
std::string encode() const
Definition: InputTag.cc:166
const std::vector< edm::EDGetTokenT< TriggerObjectStandAloneMatch > > matchesTokens_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:230
PATTriggerMatchEmbedder< Muon > PATTriggerMatchMuonEmbedder
bool isValid() const
Definition: HandleBase.h:74
PATTriggerMatchEmbedder< Tau > PATTriggerMatchTauEmbedder
const edm::EDGetTokenT< edm::View< PATObjectType > > srcToken_
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
PATTriggerMatchEmbedder< Jet > PATTriggerMatchJetEmbedder
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:510