CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/PhysicsTools/HepMCCandAlgos/interface/MCTruthCompositeMatcher.h

Go to the documentation of this file.
00001 #ifndef HepMCCandAlgos_MCTruthCompositeMatcher
00002 #define HepMCCandAlgos_MCTruthCompositeMatcher
00003 /* \class MCTruthCompositeMatcher
00004  *
00005  * \author Luca Lista, INFN
00006  *
00007  */
00008 #include "FWCore/Framework/interface/EDProducer.h"
00009 #include "FWCore/Utilities/interface/InputTag.h"
00010 #include "PhysicsTools/HepMCCandAlgos/interface/MCCandMatcher.h"
00011 
00012 template<typename C1, typename C2 = C1>
00013 class MCTruthCompositeMatcher : public edm::EDProducer {
00014 public:
00015   explicit MCTruthCompositeMatcher( const edm::ParameterSet & );
00016   ~MCTruthCompositeMatcher();
00017 private:
00018   typedef typename CandMatcher<C1, C2>::map_type map_type;
00019   edm::InputTag src_;
00020   std::vector<edm::InputTag> matchMaps_;
00021   void produce( edm::Event & , const edm::EventSetup & );
00022 };
00023 
00024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00025 #include "FWCore/Framework/interface/Event.h"
00026 #include "DataFormats/Common/interface/Handle.h"
00027 
00028 template<typename C1, typename C2>
00029 MCTruthCompositeMatcher<C1, C2>::MCTruthCompositeMatcher( const edm::ParameterSet & cfg ) :
00030   src_( cfg.template getParameter<edm::InputTag>( "src" ) ),
00031   matchMaps_( cfg.template getParameter<std::vector<edm::InputTag> >( "matchMaps" ) ) {
00032   produces<map_type>();
00033 }
00034 
00035 template<typename C1, typename C2>
00036 MCTruthCompositeMatcher<C1, C2>::~MCTruthCompositeMatcher() {
00037 }
00038 
00039 template<typename C1, typename C2>
00040 void MCTruthCompositeMatcher<C1, C2>::produce( edm::Event & evt , const edm::EventSetup & ) {
00041   typedef typename CandMatcher<C1, C2>::reference_type reference_type;
00042   Handle<C1> cands;
00043   evt.getByLabel(src_, cands);
00044   
00045   size_t nMaps = matchMaps_.size();
00046   std::vector<const map_type *> maps;
00047   maps.reserve( nMaps );
00048   for( size_t i = 0; i != nMaps; ++ i ) {
00049     Handle<map_type> matchMap;
00050     evt.getByLabel( matchMaps_[i], matchMap );
00051     maps.push_back( & * matchMap );
00052   } 
00053   MCCandMatcher<C1, C2> match( maps );
00054   auto_ptr<map_type> matchMap( new map_type );
00055   for( size_t i = 0; i != cands->size(); ++ i ) {
00056     const typename C1::value_type & cand = ( * cands )[ i ];
00057     reference_type mc(match( cand ));
00058     if ( mc.isNonnull() ) {
00059       matchMap->insert( reference_type( cands, i ), mc );      
00060     }
00061   }
00062 
00063   evt.put( matchMap );
00064 }
00065 
00066 #endif