Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Authors: Y.Gao (FNAL)
0004 //
0005 // system include files
0006 #include <memory>
0007 
0008 // user include files
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/stream/EDProducer.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/Framework/interface/MakerMacros.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/Utilities/interface/ESGetToken.h"
0017 
0018 // related to reco::Track
0019 #include "DataFormats/TrackReco/interface/Track.h"
0020 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0021 
0022 // related to reco::Muon
0023 #include "DataFormats/MuonReco/interface/Muon.h"
0024 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0025 
0026 // TrajectorSeed Related
0027 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
0028 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0029 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
0030 
0031 // TrajectorSeed Related
0032 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
0033 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0034 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
0035 #include "MagneticField/Engine/interface/MagneticField.h"
0036 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0037 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0038 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
0039 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0040 
0041 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0042 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0043 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
0044 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
0045 
0046 #include "RecoMuon/MuonIdentification/interface/MuonCosmicsId.h"
0047 
0048 class TrajectorySeedFromMuonProducer : public edm::stream::EDProducer<> {
0049 public:
0050   explicit TrajectorySeedFromMuonProducer(const edm::ParameterSet&);
0051   void produce(edm::Event&, const edm::EventSetup&) override;
0052 
0053 private:
0054   edm::InputTag muonCollectionTag_;
0055   edm::InputTag trackCollectionTag_;
0056   edm::EDGetTokenT<edm::View<reco::Muon> > muonCollectionToken_;
0057   edm::EDGetTokenT<reco::TrackCollection> trackCollectionToken_;
0058   edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
0059   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeometryToken_;
0060   bool skipMatchedMuons_;
0061 };
0062 
0063 TrajectorySeedFromMuonProducer::TrajectorySeedFromMuonProducer(const edm::ParameterSet& iConfig) {
0064   muonCollectionTag_ = iConfig.getParameter<edm::InputTag>("muonCollectionTag");
0065   trackCollectionTag_ = iConfig.getParameter<edm::InputTag>("trackCollectionTag");
0066   skipMatchedMuons_ = iConfig.getParameter<bool>("skipMatchedMuons");
0067 
0068   muonCollectionToken_ = consumes<edm::View<reco::Muon> >(muonCollectionTag_);
0069   trackCollectionToken_ = consumes<reco::TrackCollection>(trackCollectionTag_);
0070   magneticFieldToken_ = esConsumes<MagneticField, IdealMagneticFieldRecord>();
0071   trackerGeometryToken_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>();
0072 
0073   produces<TrajectorySeedCollection>();
0074 }
0075 
0076 void TrajectorySeedFromMuonProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0077   using namespace edm;
0078   using namespace reco;
0079   using namespace std;
0080 
0081   // Product
0082   auto result = std::make_unique<TrajectorySeedCollection>();
0083 
0084   edm::ESHandle<MagneticField> magneticField = iSetup.getHandle(magneticFieldToken_);
0085 
0086   edm::ESHandle<TrackerGeometry> trackerGeometry = iSetup.getHandle(trackerGeometryToken_);
0087 
0088   edm::Handle<edm::View<Muon> > muonCollectionHandle;
0089   iEvent.getByToken(muonCollectionToken_, muonCollectionHandle);
0090 
0091   edm::Handle<reco::TrackCollection> trackCollectionHandle;
0092   iEvent.getByToken(trackCollectionToken_, trackCollectionHandle);
0093 
0094   // Loop over the muon track
0095   for (edm::View<Muon>::const_iterator muon = muonCollectionHandle->begin(); muon != muonCollectionHandle->end();
0096        ++muon) {
0097     // muon must have a tracker track
0098     if (muon->innerTrack().isNull())
0099       continue;
0100     edm::RefToBase<reco::Track> track(muon->innerTrack());
0101     // check if there is a back-to-back track
0102     if (skipMatchedMuons_ && muonid::findOppositeTrack(trackCollectionHandle, *track).isNonnull())
0103       continue;
0104     if ((!track->innerOk()) || (!track->recHit(0)->isValid()))
0105       continue;
0106     GlobalPoint innerPosition(track->innerPosition().x(), track->innerPosition().y(), track->innerPosition().z());
0107     GlobalVector innerMomentum(track->innerMomentum().x(), track->innerMomentum().y(), track->innerMomentum().z());
0108     int charge = track->charge();
0109     const reco::Track::CovarianceMatrix innerStateCovariance = track->innerStateCovariance();
0110     DetId innerDetId = DetId(track->innerDetId());
0111     // Construct the information necessary to make a TrajectoryStateOnSurface
0112     GlobalTrajectoryParameters globalTrajParams(innerPosition, innerMomentum, charge, &(*magneticField));
0113     CurvilinearTrajectoryError curviError(innerStateCovariance);
0114     FreeTrajectoryState tracker_state(globalTrajParams, curviError);
0115     LogTrace("MuonIdentification") << "Track Inner FTS: " << tracker_state;
0116 
0117     TrajectoryStateOnSurface tracker_tsos =
0118         TrajectoryStateOnSurface(globalTrajParams, curviError, trackerGeometry->idToDet(innerDetId)->surface());
0119 
0120     // Make Hits, push back the innermost Hit
0121     edm::OwnVector<TrackingRecHit> trackHits;
0122     trackHits.push_back(track->recHit(0)->clone());
0123 
0124     // Make TrajectorySeed
0125     PTrajectoryStateOnDet const& PTraj = trajectoryStateTransform::persistentState(tracker_tsos, innerDetId.rawId());
0126     TrajectorySeed trajectorySeed(PTraj, trackHits, oppositeToMomentum);
0127     LogTrace("MuonIdentification") << "Trajectory Seed Direction: " << trajectorySeed.direction() << endl;
0128     result->push_back(trajectorySeed);
0129   }
0130 
0131   iEvent.put(std::move(result));
0132 }
0133 
0134 DEFINE_FWK_MODULE(TrajectorySeedFromMuonProducer);