CMS 3D CMS Logo

TrackerToMuonPropagator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TrackerToMuonPropagator
4 // Class: TrackerToMuonPropagator
5 //
13 //
14 // Original Author: Jim Pivarski
15 // Created: Wed Dec 12 13:31:55 CST 2007
16 // $Id: TrackerToMuonPropagator.cc,v 1.4 2010/01/04 15:36:54 mussgill Exp $
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
30 
31 // products
34 
35 // references
57 
58 //
59 // class decleration
60 //
61 
63 public:
65  ~TrackerToMuonPropagator() override;
66 
67 private:
68  void beginJob() override;
69  void produce(edm::Event&, const edm::EventSetup&) override;
70  void endJob() override;
71 
72  // ----------member data ---------------------------
73 
76 
79 };
80 
81 //
82 // constants, enums and typedefs
83 //
84 
85 //
86 // static data member definitions
87 //
88 
89 //
90 // constructors and destructor
91 //
93  m_globalMuons = iConfig.getParameter<edm::InputTag>("globalMuons");
94  m_globalMuonTracks = iConfig.getParameter<edm::InputTag>("globalMuonTracks");
95  m_propagator = iConfig.getParameter<std::string>("propagator");
96  m_refitTracker = iConfig.getParameter<bool>("refitTrackerTrack");
97  if (m_refitTracker) {
98  m_trackTransformer = new TrackTransformer(iConfig.getParameter<edm::ParameterSet>("trackerTrackTransformer"));
99  } else
100  m_trackTransformer = nullptr;
101 
102  produces<std::vector<Trajectory>>();
103  produces<TrajTrackAssociationCollection>();
104 }
105 
107  // do anything here that needs to be done at desctruction time
108  // (e.g. close files, deallocate resources etc.)
109 }
110 
111 //
112 // member functions
113 //
114 
115 // ------------ method called to produce the data ------------
117  if (m_trackTransformer)
119 
121  iEvent.getByLabel(m_globalMuons, globalMuons);
122 
123  edm::Handle<reco::TrackCollection> globalMuonTracks;
124  iEvent.getByLabel(m_globalMuonTracks, globalMuonTracks);
125 
128 
129  edm::ESHandle<TrackerGeometry> trackerGeometry;
130  iSetup.get<TrackerDigiGeometryRecord>().get(trackerGeometry);
131 
132  edm::ESHandle<DTGeometry> dtGeometry;
133  iSetup.get<MuonGeometryRecord>().get(dtGeometry);
134 
135  edm::ESHandle<CSCGeometry> cscGeometry;
136  iSetup.get<MuonGeometryRecord>().get(cscGeometry);
137 
140 
142  iSetup.get<GlobalTrackingGeometryRecord>().get(globalGeometry);
143 
144  // Create these factories once per event
145 
146  MuonTransientTrackingRecHitBuilder muonTransBuilder;
147 
148  // Create a collection of Trajectories, to put in the Event
149  auto trajectoryCollection = std::make_unique<std::vector<Trajectory>>();
150 
151  // Remember which trajectory is associated with which track
152  std::map<edm::Ref<std::vector<Trajectory>>::key_type, edm::Ref<reco::TrackCollection>::key_type> reference_map;
153  edm::Ref<std::vector<Trajectory>>::key_type trajCounter = 0;
154 
155  for (reco::MuonCollection::const_iterator globalMuon = globalMuons->begin(); globalMuon != globalMuons->end();
156  ++globalMuon) {
157  // get the counter for this global muon (that's why we needed to extract the collection explicitly
159  reco::TrackCollection::const_iterator globalMuonTrack = globalMuonTracks->begin();
160  for (; globalMuonTrack != globalMuonTracks->end(); ++globalMuonTrack) {
161  trackCounter++;
162  if (fabs(globalMuon->combinedMuon()->phi() - globalMuonTrack->phi()) < 1e-10 &&
163  fabs(globalMuon->combinedMuon()->eta() - globalMuonTrack->eta()) < 1e-10)
164  break;
165  }
166  if (globalMuonTrack == globalMuonTracks->end()) {
167  throw cms::Exception("BadConfig") << "The tracks label doesn't correspond to the same objects as the muons label"
168  << std::endl;
169  }
170 
171  TrajectoryStateOnSurface tracker_tsos;
172  DetId outerDetId;
173  if (m_refitTracker) {
174  std::vector<Trajectory> trackerTrajectories = m_trackTransformer->transform(*globalMuon->track());
175  if (trackerTrajectories.size() == 1) {
176  const Trajectory trackerTrajectory = *(trackerTrajectories.begin());
177 
178  // surprisingly, firstMeasurement() corresponds to the outermost state of the tracker
179  tracker_tsos = trackerTrajectory.firstMeasurement().forwardPredictedState();
180  outerDetId = trackerTrajectory.firstMeasurement().recHit()->geographicalId();
181  } else
182  continue;
183  } else {
184  // get information about the outermost tracker hit
185  GlobalPoint outerPosition(globalMuon->track()->outerPosition().x(),
186  globalMuon->track()->outerPosition().y(),
187  globalMuon->track()->outerPosition().z());
188  GlobalVector outerMomentum(globalMuon->track()->outerMomentum().x(),
189  globalMuon->track()->outerMomentum().y(),
190  globalMuon->track()->outerMomentum().z());
191  int charge = globalMuon->track()->charge();
192  const reco::Track::CovarianceMatrix outerStateCovariance = globalMuon->track()->outerStateCovariance();
193  outerDetId = DetId(globalMuon->track()->outerDetId());
194 
195  // construct the information necessary to make a TrajectoryStateOnSurface
196  GlobalTrajectoryParameters globalTrajParams(outerPosition, outerMomentum, charge, &(*magneticField));
197  CurvilinearTrajectoryError curviError(outerStateCovariance);
198  FreeTrajectoryState tracker_state(globalTrajParams, curviError);
199 
200  // starting point for propagation into the muon system
201  tracker_tsos =
202  TrajectoryStateOnSurface(globalTrajParams, curviError, trackerGeometry->idToDet(outerDetId)->surface());
203  }
204 
205  TrajectoryStateOnSurface last_tsos = tracker_tsos;
206 
207  // loop over the muon hits, keeping track of the successful extrapolations
209  std::vector<TrajectoryStateOnSurface> TSOSes;
210  for (auto const& hit : globalMuon->combinedMuon()->recHits()) {
211  DetId id = hit->geographicalId();
212 
213  TrajectoryStateOnSurface extrapolation;
214  bool extrapolated = false;
215  if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::DT) {
216  extrapolation = propagator->propagate(last_tsos, dtGeometry->idToDet(id)->surface());
217  extrapolated = true;
218  } else if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC) {
219  extrapolation = propagator->propagate(last_tsos, cscGeometry->idToDet(id)->surface());
220  extrapolated = true;
221  }
222 
223  if (extrapolated && extrapolation.isValid()) {
224  muonHits.push_back(hit->clone());
225  TSOSes.push_back(extrapolation);
226  }
227  } // end loop over standAloneMuon hits
228 
229  // if it has any successful extrapolations, make them into a Trajectory
230  if (!muonHits.empty()) {
231  PTrajectoryStateOnDet const& PTraj = trajectoryStateTransform::persistentState(tracker_tsos, outerDetId.rawId());
232  TrajectorySeed trajectorySeed(PTraj, muonHits, alongMomentum);
233  Trajectory trajectory(trajectorySeed, alongMomentum);
234 
235  for (unsigned int i = 0; i < muonHits.size(); i++) {
236  TrajectoryMeasurement::ConstRecHitPointer hitPtr(muonTransBuilder.build(&(muonHits[i]), globalGeometry));
237  TrajectoryStateOnSurface TSOS = TSOSes[i];
238  trajectory.push(TrajectoryMeasurement(TSOS, TSOS, TSOS, hitPtr));
239  } // end filling Trajectory
240 
241  trajectoryCollection->push_back(trajectory);
242 
243  // Remember which Trajectory is associated with which Track
244  trajCounter++;
245  reference_map[trajCounter] = trackCounter;
246 
247  } // end if we have some good extrapolations
248 
249  } // end loop over globalMuons
250 
251  unsigned int numTrajectories = trajectoryCollection->size();
252 
253  // insert the trajectories into the Event
254  edm::OrphanHandle<std::vector<Trajectory>> ohTrajs = iEvent.put(std::move(trajectoryCollection));
255 
256  // create the trajectory <-> track association map
257  auto trajTrackMap = std::make_unique<TrajTrackAssociationCollection>();
258 
259  for (trajCounter = 0; trajCounter < numTrajectories; trajCounter++) {
260  edm::Ref<reco::TrackCollection>::key_type trackCounter = reference_map[trajCounter];
261 
262  trajTrackMap->insert(edm::Ref<std::vector<Trajectory>>(ohTrajs, trajCounter),
263  edm::Ref<reco::TrackCollection>(globalMuonTracks, trackCounter));
264  }
265  // and put it in the Event, also
266  iEvent.put(std::move(trajTrackMap));
267 }
268 
269 // ------------ method called once each job just before starting event loop ------------
271 
272 // ------------ method called once each job just after ending the event loop ------------
274 
275 //define this as a plug-in
Vector3DBase
Definition: Vector3DBase.h:8
TrackerGeometry::idToDet
const TrackerGeomDet * idToDet(DetId) const override
Definition: TrackerGeometry.cc:193
Propagator.h
TrackerToMuonPropagator::~TrackerToMuonPropagator
~TrackerToMuonPropagator() override
Definition: TrackerToMuonPropagator.cc:106
TrackerToMuonPropagator
Definition: TrackerToMuonPropagator.cc:62
MuonSubdetId::CSC
static constexpr int CSC
Definition: MuonSubdetId.h:12
mps_fire.i
i
Definition: mps_fire.py:355
Muon.h
TrackerGeometry.h
EDProducer.h
TrackerToMuonPropagator::m_trackTransformer
TrackTransformer * m_trackTransformer
Definition: TrackerToMuonPropagator.cc:78
TrackTransformer::setServices
void setServices(const edm::EventSetup &) override
set the services needed by the TrackTransformer
Definition: TrackTransformer.cc:66
HLT_2018_cff.magneticField
magneticField
Definition: HLT_2018_cff.py:348
trajectoryStateTransform::persistentState
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
Definition: TrajectoryStateTransform.cc:14
CSCGeometry::idToDet
const GeomDet * idToDet(DetId) const override
Definition: CSCGeometry.cc:91
HLT_2018_cff.TrackTransformer
TrackTransformer
Definition: HLT_2018_cff.py:8374
TrackTransformer::transform
std::vector< Trajectory > transform(const reco::Track &) const override
Convert a reco::Track into Trajectory.
Definition: TrackTransformer.cc:164
GlobalTrackingGeometryRecord
Definition: GlobalTrackingGeometryRecord.h:17
TrackingRecHitFwd.h
edm::Handle< reco::MuonCollection >
edm::Ref
Definition: AssociativeIterator.h:58
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
TrackerToMuonPropagator::m_globalMuonTracks
edm::InputTag m_globalMuonTracks
Definition: TrackerToMuonPropagator.cc:74
DetId
Definition: DetId.h:17
edm::OwnVector::empty
bool empty() const
Definition: OwnVector.h:305
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrackerToMuonPropagator::m_refitTracker
bool m_refitTracker
Definition: TrackerToMuonPropagator.cc:77
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MakerMacros.h
TrackingRecHit.h
Track.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
TrackFwd.h
CurvilinearTrajectoryError
Definition: CurvilinearTrajectoryError.h:27
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TrackCandidateProducer_cfi.propagator
propagator
Definition: TrackCandidateProducer_cfi.py:17
TrajectoryMeasurement::forwardPredictedState
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
Definition: TrajectoryMeasurement.h:177
MuonFwd.h
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
TrackerToMuonPropagator::m_propagator
std::string m_propagator
Definition: TrackerToMuonPropagator.cc:75
TrackerToMuonPropagator::m_globalMuons
edm::InputTag m_globalMuons
Definition: TrackerToMuonPropagator.cc:74
IdealMagneticFieldRecord.h
edm::ESHandle< Propagator >
TrackerToMuonPropagator::beginJob
void beginJob() override
Definition: TrackerToMuonPropagator.cc:270
GlobalTrajectoryParameters
Definition: GlobalTrajectoryParameters.h:15
MuonSubdetId::DT
static constexpr int DT
Definition: MuonSubdetId.h:11
Point3DBase< float, GlobalTag >
TrajTrackAssociation.h
GlobalTrackingGeometryRecord.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DTGeometry.h
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
TrackerDigiGeometryRecord.h
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
MuonTransientTrackingRecHitBuilder::build
RecHitPointer build(const TrackingRecHit *p, edm::ESHandle< GlobalTrackingGeometry > trackingGeometry) const
Call the MuonTransientTrackingRecHit::specificBuild.
Definition: MuonTransientTrackingRecHitBuilder.cc:20
MagneticField.h
TrackTransformer.h
TrackerToMuonPropagator::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: TrackerToMuonPropagator.cc:116
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
Trajectory::push
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:50
MuonSubdetId.h
edm::Ref::key_type
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
TrackerToMuonPropagator::TrackerToMuonPropagator
TrackerToMuonPropagator(const edm::ParameterSet &)
Definition: TrackerToMuonPropagator.cc:92
TrajectoryMeasurement::recHit
ConstRecHitPointer const & recHit() const
Definition: TrajectoryMeasurement.h:190
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
TrackerToMuonPropagator::endJob
void endJob() override
Definition: TrackerToMuonPropagator.cc:273
Trajectory.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
edm::OrphanHandle
Definition: EDProductfwd.h:39
Trajectory::firstMeasurement
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:166
FreeTrajectoryState
Definition: FreeTrajectoryState.h:27
TrajectoryMeasurement::ConstRecHitPointer
TrackingRecHit::ConstRecHitPointer ConstRecHitPointer
Definition: TrajectoryMeasurement.h:28
Trajectory
Definition: Trajectory.h:38
Frameworkfwd.h
MuonTransientTrackingRecHitBuilder.h
TrackingComponentsRecord.h
Exception
Definition: hltDiff.cc:246
TrajectorySeed
Definition: TrajectorySeed.h:17
EventSetup.h
edm::EDProducer
Definition: EDProducer.h:36
TrajectoryStateTransform.h
edm::OwnVector::push_back
void push_back(D *&d)
Definition: OwnVector.h:326
DetId::Muon
Definition: DetId.h:26
PTrajectoryStateOnDet
Definition: PTrajectoryStateOnDet.h:10
ParameterSet.h
MuonGeometryRecord.h
GlobalTrackingGeometry.h
reco::TrackBase::CovarianceMatrix
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74
edm::Event
Definition: Event.h:73
globalMuons_cfi.globalMuons
globalMuons
Definition: globalMuons_cfi.py:6
MuonTransientTrackingRecHitBuilder
Definition: MuonTransientTrackingRecHitBuilder.h:12
TrajectoryMeasurement
Definition: TrajectoryMeasurement.h:25
DTGeometry::idToDet
const GeomDet * idToDet(DetId) const override
Definition: DTGeometry.cc:77
edm::OwnVector::size
size_type size() const
Definition: OwnVector.h:300
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
edm::InputTag
Definition: InputTag.h:15
alongMomentum
Definition: PropagationDirection.h:4
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
hit
Definition: SiStripHitEffFromCalibTree.cc:88
edm::OwnVector< TrackingRecHit >
CSCGeometry.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
susybsm::HSCParticleType::globalMuon
Definition: HSCParticle.h:20
TrackingComponentsRecord
Definition: TrackingComponentsRecord.h:12
TrackTransformer
Definition: TrackTransformer.h:44