00001 #include <memory> 00002 #include "SimMuon/MCTruth/plugins/MuonAssociatorEDProducer.h" 00003 #include "DataFormats/Common/interface/Handle.h" 00004 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00005 #include "DataFormats/RecoCandidate/interface/TrackAssociation.h" 00006 00007 MuonAssociatorEDProducer::MuonAssociatorEDProducer(const edm::ParameterSet& parset): 00008 tracksTag(parset.getParameter< edm::InputTag >("tracksTag")), 00009 tpTag(parset.getParameter< edm::InputTag >("tpTag")), 00010 parset_(parset) 00011 { 00012 LogTrace("MuonAssociatorEDProducer") << "constructing MuonAssociatorEDProducer" << parset_.dump(); 00013 produces<reco::RecoToSimCollection>(); 00014 produces<reco::SimToRecoCollection>(); 00015 } 00016 00017 MuonAssociatorEDProducer::~MuonAssociatorEDProducer() {} 00018 00019 void MuonAssociatorEDProducer::beginJob(const edm::EventSetup& setup) { 00020 LogTrace("MuonAssociatorEDProducer") << "MuonAssociatorEDProducer::beginJob : constructing MuonAssociatorByHits"; 00021 associatorByHits = new MuonAssociatorByHits::MuonAssociatorByHits(parset_); 00022 } 00023 00024 void MuonAssociatorEDProducer::endJob() {} 00025 00026 void MuonAssociatorEDProducer::produce(edm::Event& event, const edm::EventSetup& setup) { 00027 using namespace edm; 00028 00029 Handle<edm::View<reco::Track> > trackCollection; 00030 LogTrace("MuonAssociatorEDProducer") <<"getting reco::Track collection - "<<tracksTag; 00031 event.getByLabel (tracksTag, trackCollection ); 00032 LogTrace("MuonAssociatorEDProducer") <<"... size = "<<trackCollection->size(); 00033 00034 Handle<TrackingParticleCollection> TPCollection ; 00035 LogTrace("MuonAssociatorEDProducer") <<"getting TrackingParticle collection - "<<tpTag; 00036 event.getByLabel(tpTag, TPCollection); 00037 LogTrace("MuonAssociatorEDProducer") <<"... size = "<<TPCollection->size(); 00038 00039 LogTrace("MuonAssociatorEDProducer") << "\n >>> Calling associateRecoToSim method <<<" << "\n"; 00040 reco::RecoToSimCollection recSimColl = 00041 associatorByHits->associateRecoToSim(trackCollection,TPCollection,&event,&setup); 00042 00043 LogTrace("MuonAssociatorEDProducer") << "\n >>> Calling associateSimToReco method <<<" << "\n"; 00044 reco::SimToRecoCollection simRecColl = 00045 associatorByHits->associateSimToReco(trackCollection,TPCollection,&event,&setup); 00046 00047 std::auto_ptr<reco::RecoToSimCollection> rts(new reco::RecoToSimCollection(recSimColl)); 00048 std::auto_ptr<reco::SimToRecoCollection> str(new reco::SimToRecoCollection(simRecColl)); 00049 00050 event.put(rts); 00051 event.put(str); 00052 }