Go to the documentation of this file.00001
00009 #include "RecoMuon/MuonIdentification/plugins/MuonProducer.h"
00010
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015
00016 #include "DataFormats/MuonReco/interface/Muon.h"
00017 #include "DataFormats/MuonReco/interface/MuonTrackLinks.h"
00018 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00019
00020
00021 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00022 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00023 #include "DataFormats/TrackReco/interface/Track.h"
00024 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00025 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00026
00027
00029 MuonProducer::MuonProducer(const edm::ParameterSet& pSet){
00030
00031 theLinksCollectionLabel = pSet.getParameter<edm::InputTag>("InputObjects");
00032
00033 setAlias(pSet.getParameter<std::string>("@module_label"));
00034 produces<reco::MuonCollection>().setBranchAlias(theAlias + "s");
00035 }
00036
00038 MuonProducer::~MuonProducer(){
00039
00040 }
00041
00042 void MuonProducer::printTrackRecHits(const reco::Track &track,
00043 edm::ESHandle<GlobalTrackingGeometry> trackingGeometry) const{
00044
00045 const std::string metname = "Muon|RecoMuon|MuonIdentification|MuonProducer";
00046
00047 LogTrace(metname) << "Valid RecHits: "<<track.found() << " invalid RecHits: " << track.lost();
00048
00049 int i = 0;
00050 for(trackingRecHit_iterator recHit = track.recHitsBegin(); recHit != track.recHitsEnd(); ++recHit)
00051 if((*recHit)->isValid()){
00052 const GeomDet* geomDet = trackingGeometry->idToDet((*recHit)->geographicalId());
00053 double r = geomDet->surface().position().perp();
00054 double z = geomDet->toGlobal((*recHit)->localPosition()).z();
00055 LogTrace(metname) << i++ <<" r: "<< r <<" z: "<<z <<" "<<geomDet->toGlobal((*recHit)->localPosition())
00056 <<std::endl;
00057 }
00058 }
00059
00060
00061
00063 void MuonProducer::produce(edm::Event& event, const edm::EventSetup& eventSetup){
00064
00065 const std::string metname = "Muon|RecoMuon|MuonIdentification|MuonProducer";
00066
00067
00068 std::auto_ptr<reco::MuonCollection> muonCollection(new reco::MuonCollection());
00069
00070
00071 edm::Handle<reco::MuonTrackLinksCollection> linksCollection;
00072 event.getByLabel(theLinksCollectionLabel,linksCollection);
00073
00074 if(linksCollection->empty()) {
00075 event.put(muonCollection);
00076 return;
00077 }
00078
00079
00080
00081 edm::ESHandle<GlobalTrackingGeometry> trackingGeometry;
00082 eventSetup.get<GlobalTrackingGeometryRecord>().get(trackingGeometry);
00083
00084 for(reco::MuonTrackLinksCollection::const_iterator links = linksCollection->begin();
00085 links != linksCollection->end(); ++links){
00086
00087
00088 LogTrace(metname) << "trackerTrack";
00089 printTrackRecHits(*(links->trackerTrack()),trackingGeometry);
00090 LogTrace(metname) << "standAloneTrack";
00091 printTrackRecHits(*(links->standAloneTrack()),trackingGeometry);
00092 LogTrace(metname) << "globalTrack";
00093 printTrackRecHits(*(links->globalTrack()),trackingGeometry);
00094
00095
00096 reco::Muon muon;
00097 muon.setStandAlone(links->standAloneTrack());
00098 muon.setTrack(links->trackerTrack());
00099 muon.setCombined(links->globalTrack());
00100
00101
00102 muon.setCharge(links->globalTrack()->charge());
00103
00104
00105 double energy = sqrt(links->globalTrack()->p() * links->globalTrack()->p() + 0.011163691);
00106 math::XYZTLorentzVector p4(links->globalTrack()->px(),
00107 links->globalTrack()->py(),
00108 links->globalTrack()->pz(),
00109 energy);
00110
00111 muon.setP4(p4);
00112 muon.setVertex(links->globalTrack()->vertex());
00113
00114 muonCollection->push_back(muon);
00115
00116 }
00117
00118 event.put(muonCollection);
00119 }