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
 
edm::InputTag m_globalMuons
 
edm::InputTag m_globalMuonTracks
 
bool m_refitTracker
 
TrackTransformerm_trackTransformer
 

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 98 of file TrackerToMuonPropagator.cc.

References edm::ParameterSet::getParameter(), m_globalMuons, m_globalMuonTracks, m_refitTracker, m_trackTransformer, and HLT_2022v14_cff::TrackTransformer.

99  : m_esTokenProp(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("propagator")))),
105  m_globalMuons = iConfig.getParameter<edm::InputTag>("globalMuons");
106  m_globalMuonTracks = iConfig.getParameter<edm::InputTag>("globalMuonTracks");
107  m_refitTracker = iConfig.getParameter<bool>("refitTrackerTrack");
108  if (m_refitTracker) {
110  new TrackTransformer(iConfig.getParameter<edm::ParameterSet>("trackerTrackTransformer"), consumesCollector());
111  } else
112  m_trackTransformer = nullptr;
113 
114  produces<std::vector<Trajectory>>();
115  produces<TrajTrackAssociationCollection>();
116 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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::ESGetToken< MagneticField, IdealMagneticFieldRecord > m_esTokenMF

◆ ~TrackerToMuonPropagator()

TrackerToMuonPropagator::~TrackerToMuonPropagator ( )
override

Definition at line 118 of file TrackerToMuonPropagator.cc.

118  {
119  // do anything here that needs to be done at desctruction time
120  // (e.g. close files, deallocate resources etc.)
121 }

Member Function Documentation

◆ produce()

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

Definition at line 128 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_globalMuons, m_globalMuonTracks, m_refitTracker, m_trackTransformer, HLT_2022v14_cff::magneticField, eostools::move(), DetId::Muon, 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(), and TrackTransformer::transform().

128  {
129  if (m_trackTransformer)
131 
133  iEvent.getByLabel(m_globalMuons, globalMuons);
134 
135  edm::Handle<reco::TrackCollection> globalMuonTracks;
136  iEvent.getByLabel(m_globalMuonTracks, globalMuonTracks);
137 
138  const Propagator* propagator = &iSetup.getData(m_esTokenProp);
139  const TrackerGeometry* trackerGeometry = &iSetup.getData(m_esTokenTk);
140  const DTGeometry* dtGeometry = &iSetup.getData(m_esTokenDT);
141  const CSCGeometry* cscGeometry = &iSetup.getData(m_esTokenCSC);
143  const GlobalTrackingGeometry* globalGeometry = &iSetup.getData(m_esTokenGTGeo);
144 
145  // Create these factories once per event
146 
147  MuonTransientTrackingRecHitBuilder muonTransBuilder;
148 
149  // Create a collection of Trajectories, to put in the Event
150  auto trajectoryCollection = std::make_unique<std::vector<Trajectory>>();
151 
152  // Remember which trajectory is associated with which track
153  std::map<edm::Ref<std::vector<Trajectory>>::key_type, edm::Ref<reco::TrackCollection>::key_type> reference_map;
154  edm::Ref<std::vector<Trajectory>>::key_type trajCounter = 0;
155 
156  for (reco::MuonCollection::const_iterator globalMuon = globalMuons->begin(); globalMuon != globalMuons->end();
157  ++globalMuon) {
158  // get the counter for this global muon (that's why we needed to extract the collection explicitly
160  reco::TrackCollection::const_iterator globalMuonTrack = globalMuonTracks->begin();
161  for (; globalMuonTrack != globalMuonTracks->end(); ++globalMuonTrack) {
162  trackCounter++;
163  if (fabs(globalMuon->combinedMuon()->phi() - globalMuonTrack->phi()) < 1e-10 &&
164  fabs(globalMuon->combinedMuon()->eta() - globalMuonTrack->eta()) < 1e-10)
165  break;
166  }
167  if (globalMuonTrack == globalMuonTracks->end()) {
168  throw cms::Exception("BadConfig") << "The tracks label doesn't correspond to the same objects as the muons label"
169  << std::endl;
170  }
171 
172  TrajectoryStateOnSurface tracker_tsos;
173  DetId outerDetId;
174  if (m_refitTracker) {
175  std::vector<Trajectory> trackerTrajectories = m_trackTransformer->transform(*globalMuon->track());
176  if (trackerTrajectories.size() == 1) {
177  const Trajectory trackerTrajectory = *(trackerTrajectories.begin());
178 
179  // surprisingly, firstMeasurement() corresponds to the outermost state of the tracker
180  tracker_tsos = trackerTrajectory.firstMeasurement().forwardPredictedState();
181  outerDetId = trackerTrajectory.firstMeasurement().recHit()->geographicalId();
182  } else
183  continue;
184  } else {
185  // get information about the outermost tracker hit
186  GlobalPoint outerPosition(globalMuon->track()->outerPosition().x(),
187  globalMuon->track()->outerPosition().y(),
188  globalMuon->track()->outerPosition().z());
189  GlobalVector outerMomentum(globalMuon->track()->outerMomentum().x(),
190  globalMuon->track()->outerMomentum().y(),
191  globalMuon->track()->outerMomentum().z());
192  int charge = globalMuon->track()->charge();
193  const reco::Track::CovarianceMatrix outerStateCovariance = globalMuon->track()->outerStateCovariance();
194  outerDetId = DetId(globalMuon->track()->outerDetId());
195 
196  // construct the information necessary to make a TrajectoryStateOnSurface
197  GlobalTrajectoryParameters globalTrajParams(outerPosition, outerMomentum, charge, magneticField);
198  CurvilinearTrajectoryError curviError(outerStateCovariance);
199  FreeTrajectoryState tracker_state(globalTrajParams, curviError);
200 
201  // starting point for propagation into the muon system
202  tracker_tsos =
203  TrajectoryStateOnSurface(globalTrajParams, curviError, trackerGeometry->idToDet(outerDetId)->surface());
204  }
205 
206  TrajectoryStateOnSurface last_tsos = tracker_tsos;
207 
208  // loop over the muon hits, keeping track of the successful extrapolations
210  std::vector<TrajectoryStateOnSurface> TSOSes;
211  for (auto const& hit : globalMuon->combinedMuon()->recHits()) {
212  DetId id = hit->geographicalId();
213 
214  TrajectoryStateOnSurface extrapolation;
215  bool extrapolated = false;
216  if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::DT) {
217  extrapolation = propagator->propagate(last_tsos, dtGeometry->idToDet(id)->surface());
218  extrapolated = true;
219  } else if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC) {
220  extrapolation = propagator->propagate(last_tsos, cscGeometry->idToDet(id)->surface());
221  extrapolated = true;
222  }
223 
224  if (extrapolated && extrapolation.isValid()) {
225  muonHits.push_back(hit->clone());
226  TSOSes.push_back(extrapolation);
227  }
228  } // end loop over standAloneMuon hits
229 
230  // if it has any successful extrapolations, make them into a Trajectory
231  if (!muonHits.empty()) {
232  PTrajectoryStateOnDet const& PTraj = trajectoryStateTransform::persistentState(tracker_tsos, outerDetId.rawId());
233  TrajectorySeed trajectorySeed(PTraj, muonHits, alongMomentum);
234  Trajectory trajectory(trajectorySeed, alongMomentum);
235 
236  for (unsigned int i = 0; i < muonHits.size(); i++) {
237  TrajectoryMeasurement::ConstRecHitPointer hitPtr(muonTransBuilder.build(&(muonHits[i]), globalGeometry));
238  TrajectoryStateOnSurface TSOS = TSOSes[i];
239  trajectory.push(TrajectoryMeasurement(TSOS, TSOS, TSOS, hitPtr));
240  } // end filling Trajectory
241 
242  trajectoryCollection->push_back(trajectory);
243 
244  // Remember which Trajectory is associated with which Track
245  trajCounter++;
246  reference_map[trajCounter] = trackCounter;
247 
248  } // end if we have some good extrapolations
249 
250  } // end loop over globalMuons
251 
252  unsigned int numTrajectories = trajectoryCollection->size();
253 
254  // insert the trajectories into the Event
255  edm::OrphanHandle<std::vector<Trajectory>> ohTrajs = iEvent.put(std::move(trajectoryCollection));
256 
257  // create the trajectory <-> track association map
258  auto trajTrackMap = std::make_unique<TrajTrackAssociationCollection>();
259 
260  for (trajCounter = 0; trajCounter < numTrajectories; trajCounter++) {
261  edm::Ref<reco::TrackCollection>::key_type trackCounter = reference_map[trajCounter];
262 
263  trajTrackMap->insert(edm::Ref<std::vector<Trajectory>>(ohTrajs, trajCounter),
264  edm::Ref<reco::TrackCollection>(globalMuonTracks, trackCounter));
265  }
266  // and put it in the Event, also
267  iEvent.put(std::move(trajTrackMap));
268 }
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
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
bool getData(T &iHolder) const
Definition: EventSetup.h:122
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

edm::InputTag TrackerToMuonPropagator::m_globalMuons
private

Definition at line 81 of file TrackerToMuonPropagator.cc.

Referenced by produce(), and TrackerToMuonPropagator().

◆ m_globalMuonTracks

edm::InputTag TrackerToMuonPropagator::m_globalMuonTracks
private

Definition at line 81 of file TrackerToMuonPropagator.cc.

Referenced by produce(), and TrackerToMuonPropagator().

◆ m_refitTracker

bool TrackerToMuonPropagator::m_refitTracker
private

Definition at line 83 of file TrackerToMuonPropagator.cc.

Referenced by produce(), and TrackerToMuonPropagator().

◆ m_trackTransformer

TrackTransformer* TrackerToMuonPropagator::m_trackTransformer
private

Definition at line 84 of file TrackerToMuonPropagator.cc.

Referenced by produce(), and TrackerToMuonPropagator().