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 // $Id: PATTriggerMatchEmbedder.cc,v 1.6 2010/09/02 17:52:47 vadler Exp $
17 //
18 
19 
20 #include <vector>
21 
29 
36 
37 
38 namespace pat {
39 
40  template< class PATObjectType >
42 
44  std::vector< edm::InputTag > matches_;
45 
46  public:
47 
48  explicit PATTriggerMatchEmbedder( const edm::ParameterSet & iConfig );
50 
51  private:
52 
53  virtual void produce( edm::Event & iEvent, const edm::EventSetup & iSetup );
54 
55  };
56 
63 
64 }
65 
66 
67 using namespace pat;
68 
69 
70 template< class PATObjectType >
72  src_( iConfig.getParameter< edm::InputTag >( "src" ) ),
73  matches_( iConfig.getParameter< std::vector< edm::InputTag > >( "matches" ) )
74 {
75  produces< std::vector< PATObjectType > >();
76 }
77 
78 template< class PATObjectType >
80 {
81  std::auto_ptr< std::vector< PATObjectType > > output( new std::vector< PATObjectType >() );
82 
84  iEvent.getByLabel( src_, candidates );
85  if ( ! candidates.isValid() ) {
86  edm::LogError( "missingInputSource" ) << "Input source with InputTag " << src_.encode() << " not in event.";
87  return;
88  }
89 
90  for ( typename edm::View< PATObjectType >::const_iterator iCand = candidates->begin(); iCand != candidates->end(); ++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 < matches_.size(); ++iMatch ) {
96  iEvent.getByLabel( matches_.at( iMatch ), match );
97  if ( ! match.isValid() ) {
98  edm::LogError( "missingInputMatch" ) << "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( output );
112 }
113 
114 
116 
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
PATTriggerMatchEmbedder(const edm::ParameterSet &iConfig)
PATTriggerMatchEmbedder< Electron > PATTriggerMatchElectronEmbedder
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< edm::InputTag > matches_
PATTriggerMatchEmbedder< Photon > PATTriggerMatchPhotonEmbedder
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
PATTriggerMatchEmbedder< Muon > PATTriggerMatchMuonEmbedder
bool isValid() const
Definition: HandleBase.h:76
PATTriggerMatchEmbedder< Tau > PATTriggerMatchTauEmbedder
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
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