CMS 3D CMS Logo

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/ParameterSet/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   using namespace edm;
00042   using namespace reco;
00043   using namespace std;
00044   typedef typename CandMatcher<C1, C2>::reference_type reference_type;
00045   Handle<C1> cands;
00046   evt.getByLabel(src_, cands);
00047   
00048   size_t nMaps = matchMaps_.size();
00049   std::vector<const map_type *> maps;
00050   maps.reserve( nMaps );
00051   for( size_t i = 0; i != nMaps; ++ i ) {
00052     Handle<map_type> matchMap;
00053     evt.getByLabel( matchMaps_[i], matchMap );
00054     maps.push_back( & * matchMap );
00055   } 
00056   MCCandMatcher<C1, C2> match( maps );
00057   auto_ptr<map_type> matchMap( new map_type );
00058   for( size_t i = 0; i != cands->size(); ++ i ) {
00059     const typename C1::value_type & cand = ( * cands )[ i ];
00060     reference_type mc(match( cand ));
00061     if ( mc.isNonnull() ) {
00062       matchMap->insert( reference_type( cands, i ), mc );      
00063     }
00064   }
00065 
00066   evt.put( matchMap );
00067 }
00068 
00069 #endif

Generated on Tue Jun 9 17:41:05 2009 for CMSSW by  doxygen 1.5.4