CMS 3D CMS Logo

MCTruthCompositeMatcher.h
Go to the documentation of this file.
1 #ifndef HepMCCandAlgos_MCTruthCompositeMatcher
2 #define HepMCCandAlgos_MCTruthCompositeMatcher
3 /* \class MCTruthCompositeMatcher
4  *
5  * \author Luca Lista, INFN
6  *
7  */
10 #include "PhysicsTools/HepMCCandAlgos/interface/MCCandMatcher.h"
11 
12 template<typename C1, typename C2 = C1>
14 public:
15  explicit MCTruthCompositeMatcher( const edm::ParameterSet & );
17 private:
20  std::vector<edm::EDGetTokenT<map_type> > matchMapTokens_;
21  void produce( edm::Event & , const edm::EventSetup&) override;
22 };
23 
28 
29 template<typename C1, typename C2>
31  srcToken_( consumes<C1>(cfg.template getParameter<edm::InputTag>( "src" ) ) ),
32  matchMapTokens_( edm::vector_transform(cfg.template getParameter<std::vector<edm::InputTag> >( "matchMaps" ), [this](edm::InputTag const & tag){return consumes<map_type>(tag);} ) ) {
33  produces<map_type>();
34 }
35 
36 template<typename C1, typename C2>
38 }
39 
40 template<typename C1, typename C2>
42  typedef typename CandMatcher<C1, C2>::reference_type reference_type;
43  Handle<C1> cands;
44  evt.getByToken(srcToken_, cands);
45 
46  size_t nMaps = matchMaps_.size();
47  std::vector<const map_type *> maps;
48  maps.reserve( nMaps );
49  for( size_t i = 0; i != nMaps; ++ i ) {
50  Handle<map_type> matchMap;
51  evt.getByToken( matchMapTokens_[i], matchMap );
52  maps.push_back( & * matchMap );
53  }
54  MCCandMatcher<C1, C2> match( maps );
55  auto matchMap = std::make_unique<map_type>();
56  for( size_t i = 0; i != cands->size(); ++ i ) {
57  const typename C1::value_type & cand = ( * cands )[ i ];
58  reference_type mc(match( cand ));
59  if ( mc.isNonnull() ) {
60  matchMap->insert( reference_type( cands, i ), mc );
61  }
62  }
63 
64  evt.put(std::move(matchMap) );
65 }
66 
67 #endif
68 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
std::vector< edm::EDGetTokenT< map_type > > matchMapTokens_
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
MCTruthCompositeMatcher(const edm::ParameterSet &)
CandMatcher< C1, C2 >::map_type map_type
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< C1 > srcToken_
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
HLT enums.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
map_type::key_type reference_type
concrete candidate reference type
Definition: CandMatcher.h:27
def move(src, dest)
Definition: eostools.py:510