Go to the documentation of this file.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 ignoreMissingTrackCollection(parset.getUntrackedParameter<bool>("ignoreMissingTrackCollection",false)),
00011 parset_(parset)
00012 {
00013
00014 LogTrace("MuonAssociatorEDProducer") << "constructing MuonAssociatorEDProducer" << parset_.dump();
00015 produces<reco::RecoToSimCollection>();
00016 produces<reco::SimToRecoCollection>();
00017
00019 edm::LogVerbatim("MuonAssociatorByHits") << "constructing MuonAssociatorByHits" << parset_.dump();
00020 edm::LogVerbatim("MuonAssociatorByHits") << "\n MuonAssociatorByHits will associate reco::Tracks with "<<tracksTag
00021 << "\n\t\t and TrackingParticles with "<<tpTag;
00022 const std::string recoTracksLabel = tracksTag.label();
00023 const std::string recoTracksInstance = tracksTag.instance();
00024
00025
00026
00027 if (recoTracksLabel == "standAloneMuons" || recoTracksLabel == "standAloneSETMuons" ||
00028 recoTracksLabel == "cosmicMuons" || recoTracksLabel == "hltL2Muons") {
00029 if (parset_.getParameter<bool>("UseTracker")) {
00030 edm::LogWarning("MuonAssociatorByHits")
00031 <<"\n*** WARNING : inconsistent input tracksTag = "<<tracksTag
00032 <<"\n with UseTracker = true"<<"\n ---> setting UseTracker = false ";
00033 parset_.addParameter<bool>("UseTracker",false);
00034 }
00035 if (!parset_.getParameter<bool>("UseMuon")) {
00036 edm::LogWarning("MuonAssociatorByHits")
00037 <<"\n*** WARNING : inconsistent input tracksTag = "<<tracksTag
00038 <<"\n with UseMuon = false"<<"\n ---> setting UseMuon = true ";
00039 parset_.addParameter<bool>("UseMuon",true);
00040 }
00041 }
00042
00043 if (recoTracksLabel == "generalTracks" || recoTracksLabel == "ctfWithMaterialTracksP5LHCNavigation" ||
00044 recoTracksLabel == "hltL3TkTracksFromL2" ||
00045 (recoTracksLabel == "hltL3Muons" && recoTracksInstance == "L2Seeded")) {
00046 if (parset_.getParameter<bool>("UseMuon")) {
00047 edm::LogWarning("MuonAssociatorByHits")
00048 <<"\n*** WARNING : inconsistent input tracksTag = "<<tracksTag
00049 <<"\n with UseMuon = true"<<"\n ---> setting UseMuon = false ";
00050 parset_.addParameter<bool>("UseMuon",false);
00051 }
00052 if (!parset_.getParameter<bool>("UseTracker")) {
00053 edm::LogWarning("MuonAssociatorByHits")
00054 <<"\n*** WARNING : inconsistent input tracksTag = "<<tracksTag
00055 <<"\n with UseTracker = false"<<"\n ---> setting UseTracker = true ";
00056 parset_.addParameter<bool>("UseTracker",true);
00057 }
00058 }
00059
00060 }
00061
00062 MuonAssociatorEDProducer::~MuonAssociatorEDProducer() {}
00063
00064 void MuonAssociatorEDProducer::beginJob() {
00065 LogTrace("MuonAssociatorEDProducer") << "MuonAssociatorEDProducer::beginJob : constructing MuonAssociatorByHits";
00066 associatorByHits = new MuonAssociatorByHits(parset_);
00067 }
00068
00069 void MuonAssociatorEDProducer::endJob() {}
00070
00071 void MuonAssociatorEDProducer::produce(edm::Event& event, const edm::EventSetup& setup) {
00072 using namespace edm;
00073
00074 Handle<TrackingParticleCollection> TPCollection ;
00075 LogTrace("MuonAssociatorEDProducer") <<"getting TrackingParticle collection - "<<tpTag;
00076 event.getByLabel(tpTag, TPCollection);
00077 LogTrace("MuonAssociatorEDProducer") <<"\t... size = "<<TPCollection->size();
00078
00079 Handle<edm::View<reco::Track> > trackCollection;
00080 LogTrace("MuonAssociatorEDProducer") <<"getting reco::Track collection - "<<tracksTag;
00081 bool trackAvailable = event.getByLabel (tracksTag, trackCollection);
00082 if (trackAvailable) LogTrace("MuonAssociatorEDProducer") <<"\t... size = "<<trackCollection->size();
00083 else LogTrace("MuonAssociatorEDProducer") <<"\t... NOT FOUND.";
00084
00085 std::auto_ptr<reco::RecoToSimCollection> rts;
00086 std::auto_ptr<reco::SimToRecoCollection> str;
00087
00088 if (ignoreMissingTrackCollection && !trackAvailable) {
00089
00090
00091 LogTrace("MuonAssociatorEDProducer") << "\n ignoring missing track collection." << "\n";
00092 }
00093 else {
00094 edm::LogVerbatim("MuonAssociatorEDProducer")
00095 <<"\n >>> RecoToSim association <<< \n"
00096 <<" Track collection : "
00097 <<tracksTag.label()<<":"<<tracksTag.instance()<<" (size = "<<trackCollection->size()<<") \n"
00098 <<" TrackingParticle collection : "
00099 <<tpTag.label()<<":"<<tpTag.instance()<<" (size = "<<TPCollection->size()<<")";
00100
00101 reco::RecoToSimCollection recSimColl = associatorByHits->associateRecoToSim(trackCollection,TPCollection,&event,&setup);
00102
00103 edm::LogVerbatim("MuonAssociatorEDProducer")
00104 <<"\n >>> SimToReco association <<< \n"
00105 <<" TrackingParticle collection : "
00106 <<tpTag.label()<<":"<<tpTag.instance()<<" (size = "<<TPCollection->size()<<") \n"
00107 <<" Track collection : "
00108 <<tracksTag.label()<<":"<<tracksTag.instance()<<" (size = "<<trackCollection->size()<<")";
00109
00110 reco::SimToRecoCollection simRecColl = associatorByHits->associateSimToReco(trackCollection,TPCollection,&event,&setup);
00111
00112 rts.reset(new reco::RecoToSimCollection(recSimColl));
00113 str.reset(new reco::SimToRecoCollection(simRecColl));
00114
00115 event.put(rts);
00116 event.put(str);
00117 }
00118 }