CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
TrackerToMuonPropagator Class Reference

#include <Alignment/TrackerToMuonPropagator/src/TrackerToMuonPropagator.cc>

Inheritance diagram for TrackerToMuonPropagator:
edm::stream::EDProducer<>

Public Member Functions

 TrackerToMuonPropagator (const edm::ParameterSet &)
 
 ~TrackerToMuonPropagator () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Member Functions

void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

const edm::ESGetToken< CSCGeometry, MuonGeometryRecordm_esTokenCSC
 
const edm::ESGetToken< DTGeometry, MuonGeometryRecordm_esTokenDT
 
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecordm_esTokenGTGeo
 
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecordm_esTokenMF
 
const edm::ESGetToken< Propagator, TrackingComponentsRecordm_esTokenProp
 
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecordm_esTokenTk
 
const edm::InputTag m_globalMuons
 
const edm::InputTag m_globalMuonTracks
 
const bool m_refitTracker
 
TrackTransformerm_trackTransformer
 
const edm::EDGetTokenT< reco::MuonCollectionmuonToken_
 
const edm::EDGetTokenT< reco::TrackCollectiontrackToken_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 63 of file TrackerToMuonPropagator.cc.

Constructor & Destructor Documentation

◆ TrackerToMuonPropagator()

TrackerToMuonPropagator::TrackerToMuonPropagator ( const edm::ParameterSet iConfig)
explicit

Definition at line 101 of file TrackerToMuonPropagator.cc.

References edm::ParameterSet::getParameter(), m_refitTracker, m_trackTransformer, and HLT_2023v12_cff::TrackTransformer.

102  : m_esTokenProp(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("propagator")))),
108  m_globalMuons(iConfig.getParameter<edm::InputTag>("globalMuons")),
109  m_globalMuonTracks(iConfig.getParameter<edm::InputTag>("globalMuonTracks")),
110  m_refitTracker(iConfig.getParameter<bool>("refitTrackerTrack")),
111  muonToken_(consumes<reco::MuonCollection>(m_globalMuons)),
112  trackToken_(consumes<reco::TrackCollection>(m_globalMuonTracks)) {
113  if (m_refitTracker)
115  new TrackTransformer(iConfig.getParameter<edm::ParameterSet>("trackerTrackTransformer"), consumesCollector());
116  else
117  m_trackTransformer = nullptr;
118 
119  produces<std::vector<Trajectory>>();
120  produces<TrajTrackAssociationCollection>();
121 }
const edm::EDGetTokenT< reco::TrackCollection > trackToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const edm::InputTag m_globalMuons
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > m_esTokenDT
const edm::ESGetToken< Propagator, TrackingComponentsRecord > m_esTokenProp
const edm::ESGetToken< CSCGeometry, MuonGeometryRecord > m_esTokenCSC
TrackTransformer * m_trackTransformer
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > m_esTokenTk
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > m_esTokenGTGeo
const edm::EDGetTokenT< reco::MuonCollection > muonToken_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > m_esTokenMF
const edm::InputTag m_globalMuonTracks

◆ ~TrackerToMuonPropagator()

TrackerToMuonPropagator::~TrackerToMuonPropagator ( )
override

Definition at line 123 of file TrackerToMuonPropagator.cc.

123  {
124  // do anything here that needs to be done at desctruction time
125  // (e.g. close files, deallocate resources etc.)
126 }

Member Function Documentation

◆ produce()

void TrackerToMuonPropagator::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 133 of file TrackerToMuonPropagator.cc.

References alongMomentum, MuonTransientTrackingRecHitBuilder::build(), ALCARECOTkAlJpsiMuMu_cff::charge, MuonSubdetId::CSC, MuonSubdetId::DT, MillePedeFileConverter_cfg::e, edm::OwnVector< T, P >::empty(), Exception, Trajectory::firstMeasurement(), TrajectoryMeasurement::forwardPredictedState(), edm::EventSetup::getData(), susybsm::HSCParticleType::globalMuon, globalMuons_cfi::globalMuons, mps_fire::i, DTGeometry::idToDet(), TrackerGeometry::idToDet(), CSCGeometry::idToDet(), iEvent, TrajectoryStateOnSurface::isValid(), m_esTokenCSC, m_esTokenDT, m_esTokenGTGeo, m_esTokenMF, m_esTokenProp, m_esTokenTk, m_refitTracker, m_trackTransformer, HLT_2023v12_cff::magneticField, eostools::move(), DetId::Muon, muonToken_, trajectoryStateTransform::persistentState(), TrackCandidateProducer_cfi::propagator, Trajectory::push(), edm::OwnVector< T, P >::push_back(), DetId::rawId(), TrajectoryMeasurement::recHit(), TrackTransformer::setServices(), edm::OwnVector< T, P >::size(), GeomDet::surface(), trackToken_, and TrackTransformer::transform().

133  {
134  if (m_trackTransformer)
136 
138  const edm::Handle<reco::TrackCollection>& globalMuonTracks = iEvent.getHandle(trackToken_);
139 
140  const Propagator* propagator = &iSetup.getData(m_esTokenProp);
141  const TrackerGeometry* trackerGeometry = &iSetup.getData(m_esTokenTk);
142  const DTGeometry* dtGeometry = &iSetup.getData(m_esTokenDT);
143  const CSCGeometry* cscGeometry = &iSetup.getData(m_esTokenCSC);
145  const GlobalTrackingGeometry* globalGeometry = &iSetup.getData(m_esTokenGTGeo);
146 
147  // Create these factories once per event
148 
149  MuonTransientTrackingRecHitBuilder muonTransBuilder;
150 
151  // Create a collection of Trajectories, to put in the Event
152  auto trajectoryCollection = std::make_unique<std::vector<Trajectory>>();
153 
154  // Remember which trajectory is associated with which track
155  std::map<edm::Ref<std::vector<Trajectory>>::key_type, edm::Ref<reco::TrackCollection>::key_type> reference_map;
156  edm::Ref<std::vector<Trajectory>>::key_type trajCounter = 0;
157 
158  for (reco::MuonCollection::const_iterator globalMuon = globalMuons->begin(); globalMuon != globalMuons->end();
159  ++globalMuon) {
160  // get the counter for this global muon (that's why we needed to extract the collection explicitly
162  reco::TrackCollection::const_iterator globalMuonTrack = globalMuonTracks->begin();
163  for (; globalMuonTrack != globalMuonTracks->end(); ++globalMuonTrack) {
164  trackCounter++;
165  if (fabs(globalMuon->combinedMuon()->phi() - globalMuonTrack->phi()) < 1e-10 &&
166  fabs(globalMuon->combinedMuon()->eta() - globalMuonTrack->eta()) < 1e-10)
167  break;
168  }
169  if (globalMuonTrack == globalMuonTracks->end()) {
170  throw cms::Exception("BadConfig") << "The tracks label doesn't correspond to the same objects as the muons label"
171  << std::endl;
172  }
173 
174  TrajectoryStateOnSurface tracker_tsos;
175  DetId outerDetId;
176  if (m_refitTracker) {
177  std::vector<Trajectory> trackerTrajectories = m_trackTransformer->transform(*globalMuon->track());
178  if (trackerTrajectories.size() == 1) {
179  const Trajectory trackerTrajectory = *(trackerTrajectories.begin());
180 
181  // surprisingly, firstMeasurement() corresponds to the outermost state of the tracker
182  tracker_tsos = trackerTrajectory.firstMeasurement().forwardPredictedState();
183  outerDetId = trackerTrajectory.firstMeasurement().recHit()->geographicalId();
184  } else
185  continue;
186  } else {
187  // get information about the outermost tracker hit
188  GlobalPoint outerPosition(globalMuon->track()->outerPosition().x(),
189  globalMuon->track()->outerPosition().y(),
190  globalMuon->track()->outerPosition().z());
191  GlobalVector outerMomentum(globalMuon->track()->outerMomentum().x(),
192  globalMuon->track()->outerMomentum().y(),
193  globalMuon->track()->outerMomentum().z());
194  int charge = globalMuon->track()->charge();
195  const reco::Track::CovarianceMatrix outerStateCovariance = globalMuon->track()->outerStateCovariance();
196  outerDetId = DetId(globalMuon->track()->outerDetId());
197 
198  // construct the information necessary to make a TrajectoryStateOnSurface
199  GlobalTrajectoryParameters globalTrajParams(outerPosition, outerMomentum, charge, magneticField);
200  CurvilinearTrajectoryError curviError(outerStateCovariance);
201  FreeTrajectoryState tracker_state(globalTrajParams, curviError);
202 
203  // starting point for propagation into the muon system
204  tracker_tsos =
205  TrajectoryStateOnSurface(globalTrajParams, curviError, trackerGeometry->idToDet(outerDetId)->surface());
206  }
207 
208  TrajectoryStateOnSurface last_tsos = tracker_tsos;
209 
210  // loop over the muon hits, keeping track of the successful extrapolations
212  std::vector<TrajectoryStateOnSurface> TSOSes;
213  for (auto const& hit : globalMuon->combinedMuon()->recHits()) {
214  DetId id = hit->geographicalId();
215 
216  TrajectoryStateOnSurface extrapolation;
217  bool extrapolated = false;
218  if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::DT) {
219  extrapolation = propagator->propagate(last_tsos, dtGeometry->idToDet(id)->surface());
220  extrapolated = true;
221  } else if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC) {
222  extrapolation = propagator->propagate(last_tsos, cscGeometry->idToDet(id)->surface());
223  extrapolated = true;
224  }
225 
226  if (extrapolated && extrapolation.isValid()) {
227  muonHits.push_back(hit->clone());
228  TSOSes.push_back(extrapolation);
229  }
230  } // end loop over standAloneMuon hits
231 
232  // if it has any successful extrapolations, make them into a Trajectory
233  if (!muonHits.empty()) {
234  PTrajectoryStateOnDet const& PTraj = trajectoryStateTransform::persistentState(tracker_tsos, outerDetId.rawId());
235  TrajectorySeed trajectorySeed(PTraj, muonHits, alongMomentum);
236  Trajectory trajectory(trajectorySeed, alongMomentum);
237 
238  for (unsigned int i = 0; i < muonHits.size(); i++) {
239  TrajectoryMeasurement::ConstRecHitPointer hitPtr(muonTransBuilder.build(&(muonHits[i]), globalGeometry));
240  TrajectoryStateOnSurface TSOS = TSOSes[i];
241  trajectory.push(TrajectoryMeasurement(TSOS, TSOS, TSOS, hitPtr));
242  } // end filling Trajectory
243 
244  trajectoryCollection->push_back(trajectory);
245 
246  // Remember which Trajectory is associated with which Track
247  trajCounter++;
248  reference_map[trajCounter] = trackCounter;
249 
250  } // end if we have some good extrapolations
251 
252  } // end loop over globalMuons
253 
254  unsigned int numTrajectories = trajectoryCollection->size();
255 
256  // insert the trajectories into the Event
257  edm::OrphanHandle<std::vector<Trajectory>> ohTrajs = iEvent.put(std::move(trajectoryCollection));
258 
259  // create the trajectory <-> track association map
260  auto trajTrackMap = std::make_unique<TrajTrackAssociationCollection>();
261 
262  for (trajCounter = 0; trajCounter < numTrajectories; trajCounter++) {
263  edm::Ref<reco::TrackCollection>::key_type trackCounter = reference_map[trajCounter];
264 
265  trajTrackMap->insert(edm::Ref<std::vector<Trajectory>>(ohTrajs, trajCounter),
266  edm::Ref<reco::TrackCollection>(globalMuonTracks, trackCounter));
267  }
268  // and put it in the Event, also
269  iEvent.put(std::move(trajTrackMap));
270 }
const edm::EDGetTokenT< reco::TrackCollection > trackToken_
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
void setServices(const edm::EventSetup &) override
set the services needed by the TrackTransformer
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > m_esTokenDT
const edm::ESGetToken< Propagator, TrackingComponentsRecord > m_esTokenProp
const edm::ESGetToken< CSCGeometry, MuonGeometryRecord > m_esTokenCSC
TrackTransformer * m_trackTransformer
RecHitPointer build(const TrackingRecHit *p, edm::ESHandle< GlobalTrackingGeometry > trackingGeometry) const
Call the MuonTransientTrackingRecHit::specificBuild.
void push_back(D *&d)
Definition: OwnVector.h:326
int iEvent
Definition: GenABIO.cc:224
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > m_esTokenTk
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > m_esTokenGTGeo
const GeomDet * idToDet(DetId) const override
Definition: DTGeometry.cc:77
size_type size() const
Definition: OwnVector.h:300
const edm::EDGetTokenT< reco::MuonCollection > muonToken_
const TrackerGeomDet * idToDet(DetId) const override
Definition: DetId.h:17
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > m_esTokenMF
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
TrackingRecHit::ConstRecHitPointer ConstRecHitPointer
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:166
bool empty() const
Definition: OwnVector.h:305
static constexpr int DT
Definition: MuonSubdetId.h:11
static constexpr int CSC
Definition: MuonSubdetId.h:12
std::vector< Trajectory > transform(const reco::Track &) const override
Convert a reco::Track into Trajectory.
def move(src, dest)
Definition: eostools.py:511
ConstRecHitPointer const & recHit() const
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74
const GeomDet * idToDet(DetId) const override
Definition: CSCGeometry.cc:91

Member Data Documentation

◆ m_esTokenCSC

const edm::ESGetToken<CSCGeometry, MuonGeometryRecord> TrackerToMuonPropagator::m_esTokenCSC
private

Definition at line 77 of file TrackerToMuonPropagator.cc.

Referenced by produce().

◆ m_esTokenDT

const edm::ESGetToken<DTGeometry, MuonGeometryRecord> TrackerToMuonPropagator::m_esTokenDT
private

Definition at line 76 of file TrackerToMuonPropagator.cc.

Referenced by produce().

◆ m_esTokenGTGeo

const edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> TrackerToMuonPropagator::m_esTokenGTGeo
private

Definition at line 79 of file TrackerToMuonPropagator.cc.

Referenced by produce().

◆ m_esTokenMF

const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> TrackerToMuonPropagator::m_esTokenMF
private

Definition at line 78 of file TrackerToMuonPropagator.cc.

Referenced by produce().

◆ m_esTokenProp

const edm::ESGetToken<Propagator, TrackingComponentsRecord> TrackerToMuonPropagator::m_esTokenProp
private

Definition at line 74 of file TrackerToMuonPropagator.cc.

Referenced by produce().

◆ m_esTokenTk

const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> TrackerToMuonPropagator::m_esTokenTk
private

Definition at line 75 of file TrackerToMuonPropagator.cc.

Referenced by produce().

◆ m_globalMuons

const edm::InputTag TrackerToMuonPropagator::m_globalMuons
private

Definition at line 81 of file TrackerToMuonPropagator.cc.

◆ m_globalMuonTracks

const edm::InputTag TrackerToMuonPropagator::m_globalMuonTracks
private

Definition at line 81 of file TrackerToMuonPropagator.cc.

◆ m_refitTracker

const bool TrackerToMuonPropagator::m_refitTracker
private

Definition at line 82 of file TrackerToMuonPropagator.cc.

Referenced by produce(), and TrackerToMuonPropagator().

◆ m_trackTransformer

TrackTransformer* TrackerToMuonPropagator::m_trackTransformer
private

Definition at line 87 of file TrackerToMuonPropagator.cc.

Referenced by produce(), and TrackerToMuonPropagator().

◆ muonToken_

const edm::EDGetTokenT<reco::MuonCollection> TrackerToMuonPropagator::muonToken_
private

Definition at line 84 of file TrackerToMuonPropagator.cc.

Referenced by produce().

◆ trackToken_

const edm::EDGetTokenT<reco::TrackCollection> TrackerToMuonPropagator::trackToken_
private

Definition at line 85 of file TrackerToMuonPropagator.cc.

Referenced by produce().