Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:54

0001 /** \class GlobalMuonToMuonProducer
0002  *  No description available.
0003  *
0004  *  \author R. Bellan - INFN Torino <riccardo.bellan@cern.ch>
0005  */
0006 
0007 #include "RecoMuon/MuonIdentification/plugins/GlobalMuonToMuonProducer.h"
0008 
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 // tmp
0015 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0016 #include "DataFormats/TrackReco/interface/Track.h"
0017 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0018 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
0019 
0020 /// Constructor
0021 GlobalMuonToMuonProducer::GlobalMuonToMuonProducer(const edm::ParameterSet& pSet) {
0022   theLinksCollectionLabel = pSet.getParameter<edm::InputTag>("InputObjects");
0023 
0024   setAlias(pSet.getParameter<std::string>("@module_label"));
0025   produces<reco::MuonCollection>().setBranchAlias(theAlias + "s");
0026   trackLinkToken_ = consumes<reco::MuonTrackLinksCollection>(theLinksCollectionLabel);
0027   trackingGeomToken_ = esConsumes<GlobalTrackingGeometry, GlobalTrackingGeometryRecord>();
0028 }
0029 
0030 /// Destructor
0031 GlobalMuonToMuonProducer::~GlobalMuonToMuonProducer() {}
0032 
0033 void GlobalMuonToMuonProducer::printTrackRecHits(const reco::Track& track,
0034                                                  edm::ESHandle<GlobalTrackingGeometry> trackingGeometry) const {
0035   const std::string metname = "Muon|RecoMuon|MuonIdentification|GlobalMuonToMuonProducer";
0036 
0037   LogTrace(metname) << "Valid RecHits: " << track.found() << " invalid RecHits: " << track.lost();
0038 
0039   int i = 0;
0040   for (trackingRecHit_iterator recHit = track.recHitsBegin(); recHit != track.recHitsEnd(); ++recHit)
0041     if ((*recHit)->isValid()) {
0042       const GeomDet* geomDet = trackingGeometry->idToDet((*recHit)->geographicalId());
0043       double r = geomDet->surface().position().perp();
0044       double z = geomDet->toGlobal((*recHit)->localPosition()).z();
0045       LogTrace(metname) << i++ << " r: " << r << " z: " << z << " " << geomDet->toGlobal((*recHit)->localPosition())
0046                         << std::endl;
0047     }
0048 }
0049 
0050 /// reconstruct muons
0051 void GlobalMuonToMuonProducer::produce(edm::StreamID, edm::Event& event, const edm::EventSetup& eventSetup) const {
0052   const std::string metname = "Muon|RecoMuon|MuonIdentification|GlobalMuonToMuonProducer";
0053 
0054   // the muon collection, it will be loaded in the event
0055   auto muonCollection = std::make_unique<reco::MuonCollection>();
0056 
0057   edm::Handle<reco::MuonTrackLinksCollection> linksCollection;
0058   event.getByToken(trackLinkToken_, linksCollection);
0059 
0060   if (linksCollection->empty()) {
0061     event.put(std::move(muonCollection));
0062     return;
0063   }
0064 
0065   // Global Tracking Geometry
0066   edm::ESHandle<GlobalTrackingGeometry> trackingGeometry = eventSetup.getHandle(trackingGeomToken_);
0067 
0068   for (reco::MuonTrackLinksCollection::const_iterator links = linksCollection->begin(); links != linksCollection->end();
0069        ++links) {
0070     // some temporary print-out
0071     LogTrace(metname) << "trackerTrack";
0072     printTrackRecHits(*(links->trackerTrack()), trackingGeometry);
0073     LogTrace(metname) << "standAloneTrack";
0074     printTrackRecHits(*(links->standAloneTrack()), trackingGeometry);
0075     LogTrace(metname) << "globalTrack";
0076     printTrackRecHits(*(links->globalTrack()), trackingGeometry);
0077 
0078     // Fill the muon
0079     reco::Muon muon;
0080     muon.setStandAlone(links->standAloneTrack());
0081     muon.setTrack(links->trackerTrack());
0082     muon.setCombined(links->globalTrack());
0083 
0084     // FIXME: can this break in case combined info cannot be added to some tracks?
0085     muon.setCharge(links->globalTrack()->charge());
0086 
0087     //FIXME: E = sqrt(p^2 + m^2), where m == 0.105658369(9)GeV
0088     double energy = sqrt(links->globalTrack()->p() * links->globalTrack()->p() + 0.011163691);
0089     math::XYZTLorentzVector p4(
0090         links->globalTrack()->px(), links->globalTrack()->py(), links->globalTrack()->pz(), energy);
0091 
0092     muon.setP4(p4);
0093     muon.setVertex(links->globalTrack()->vertex());
0094 
0095     muonCollection->push_back(muon);
0096   }
0097 
0098   event.put(std::move(muonCollection));
0099 }