CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  std::vector< edm::InputTag > matches_;
47  std::vector< edm::EDGetTokenT< TriggerObjectStandAloneMatch > > matchesTokens_;
48 
49  public:
50 
51  explicit PATTriggerMatchEmbedder( const edm::ParameterSet & iConfig );
53 
54  private:
55 
56  virtual void produce( edm::Event & iEvent, const edm::EventSetup& iSetup) 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  std::auto_ptr< std::vector< PATObjectType > > output( new 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( output );
117 }
118 
119 
121 
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
PATTriggerMatchEmbedder(const edm::ParameterSet &iConfig)
std::vector< edm::EDGetTokenT< TriggerObjectStandAloneMatch > > matchesTokens_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
PATTriggerMatchEmbedder< Electron > PATTriggerMatchElectronEmbedder
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< edm::InputTag > matches_
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
int iEvent
Definition: GenABIO.cc:243
edm::EDGetTokenT< edm::View< PATObjectType > > srcToken_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
PATTriggerMatchEmbedder< Muon > PATTriggerMatchMuonEmbedder
bool isValid() const
Definition: HandleBase.h:76
PATTriggerMatchEmbedder< Tau > PATTriggerMatchTauEmbedder
string const
Definition: compareJSON.py:14
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
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:6
PATTriggerMatchEmbedder< MET > PATTriggerMatchMETEmbedder