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 
21 // system include files
22 #include <memory>
23 
24 // user include files
31 
32 // products
35 
36 // references
58 
59 //
60 // class decleration
61 //
62 
64  public:
66  ~TrackerToMuonPropagator() override;
67 
68  private:
69  void beginJob() override ;
70  void produce(edm::Event&, const edm::EventSetup&) override;
71  void endJob() override ;
72 
73  // ----------member data ---------------------------
74 
77 
80 };
81 
82 //
83 // constants, enums and typedefs
84 //
85 
86 //
87 // static data member definitions
88 //
89 
90 //
91 // constructors and destructor
92 //
94 {
95  m_globalMuons = iConfig.getParameter<edm::InputTag>("globalMuons");
96  m_globalMuonTracks = iConfig.getParameter<edm::InputTag>("globalMuonTracks");
97  m_propagator = iConfig.getParameter<std::string>("propagator");
98  m_refitTracker = iConfig.getParameter<bool>("refitTrackerTrack");
99  if (m_refitTracker) {
100  m_trackTransformer = new TrackTransformer(iConfig.getParameter<edm::ParameterSet>("trackerTrackTransformer"));
101  }
102  else m_trackTransformer = nullptr;
103 
104  produces<std::vector<Trajectory> >();
105  produces<TrajTrackAssociationCollection>();
106 }
107 
108 
110 {
111 
112  // do anything here that needs to be done at desctruction time
113  // (e.g. close files, deallocate resources etc.)
114 
115 }
116 
117 
118 //
119 // member functions
120 //
121 
122 // ------------ method called to produce the data ------------
123 void
125 {
127 
129  iEvent.getByLabel(m_globalMuons, globalMuons);
130 
131  edm::Handle<reco::TrackCollection> globalMuonTracks;
132  iEvent.getByLabel(m_globalMuonTracks, globalMuonTracks);
133 
135  iSetup.get<TrackingComponentsRecord>().get(m_propagator, propagator);
136 
137  edm::ESHandle<TrackerGeometry> trackerGeometry;
138  iSetup.get<TrackerDigiGeometryRecord>().get(trackerGeometry);
139 
140  edm::ESHandle<DTGeometry> dtGeometry;
141  iSetup.get<MuonGeometryRecord>().get(dtGeometry);
142 
143  edm::ESHandle<CSCGeometry> cscGeometry;
144  iSetup.get<MuonGeometryRecord>().get(cscGeometry);
145 
147  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
148 
150  iSetup.get<GlobalTrackingGeometryRecord>().get(globalGeometry);
151 
152  // Create these factories once per event
153 
154  MuonTransientTrackingRecHitBuilder muonTransBuilder;
155 
156  // Create a collection of Trajectories, to put in the Event
157  auto trajectoryCollection = std::make_unique<std::vector<Trajectory>>();
158 
159  // Remember which trajectory is associated with which track
160  std::map<edm::Ref<std::vector<Trajectory> >::key_type, edm::Ref<reco::TrackCollection>::key_type> reference_map;
161  edm::Ref<std::vector<Trajectory> >::key_type trajCounter = 0;
162 
163  for (reco::MuonCollection::const_iterator globalMuon = globalMuons->begin(); globalMuon != globalMuons->end(); ++globalMuon) {
164 
165  // get the counter for this global muon (that's why we needed to extract the collection explicitly
167  reco::TrackCollection::const_iterator globalMuonTrack = globalMuonTracks->begin();
168  for (; globalMuonTrack != globalMuonTracks->end(); ++globalMuonTrack) {
169  trackCounter++;
170  if (fabs(globalMuon->combinedMuon()->phi() - globalMuonTrack->phi()) < 1e-10 &&
171  fabs(globalMuon->combinedMuon()->eta() - globalMuonTrack->eta()) < 1e-10) break;
172  }
173  if (globalMuonTrack == globalMuonTracks->end()) {
174  throw cms::Exception("BadConfig") << "The tracks label doesn't correspond to the same objects as the muons label" << std::endl;
175  }
176 
177  TrajectoryStateOnSurface tracker_tsos;
178  DetId outerDetId;
179  if (m_refitTracker) {
180  std::vector<Trajectory> trackerTrajectories = m_trackTransformer->transform(*globalMuon->track());
181  if (trackerTrajectories.size() == 1) {
182  const Trajectory trackerTrajectory = *(trackerTrajectories.begin());
183 
184  // surprisingly, firstMeasurement() corresponds to the outermost state of the tracker
185  tracker_tsos = trackerTrajectory.firstMeasurement().forwardPredictedState();
186  outerDetId = trackerTrajectory.firstMeasurement().recHit()->geographicalId();
187  }
188  else continue;
189  }
190  else {
191  // get information about the outermost tracker hit
192  GlobalPoint outerPosition(globalMuon->track()->outerPosition().x(), globalMuon->track()->outerPosition().y(), globalMuon->track()->outerPosition().z());
193  GlobalVector outerMomentum(globalMuon->track()->outerMomentum().x(), globalMuon->track()->outerMomentum().y(), 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 = TrajectoryStateOnSurface(globalTrajParams, curviError, trackerGeometry->idToDet(outerDetId)->surface());
205  }
206 
207  TrajectoryStateOnSurface last_tsos = tracker_tsos;
208 
209  // loop over the muon hits, keeping track of the successful extrapolations
211  std::vector<TrajectoryStateOnSurface> TSOSes;
212  for (trackingRecHit_iterator hit = globalMuon->combinedMuon()->recHitsBegin(); hit != globalMuon->combinedMuon()->recHitsEnd(); ++hit) {
213  DetId id = (*hit)->geographicalId();
214 
215  TrajectoryStateOnSurface extrapolation;
216  bool extrapolated = false;
217  if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::DT) {
218  extrapolation = propagator->propagate(last_tsos, dtGeometry->idToDet(id)->surface());
219  extrapolated = true;
220  }
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), edm::Ref<reco::TrackCollection>(globalMuonTracks, trackCounter));
266  }
267  // and put it in the Event, also
268  iEvent.put(std::move(trajTrackMap));
269 }
270 
271 // ------------ method called once each job just before starting event loop ------------
272 void
274 {
275 }
276 
277 // ------------ method called once each job just after ending the event loop ------------
278 void
280 }
281 
282 //define this as a plug-in
T getParameter(std::string const &) const
RecHitPointer build(const TrackingRecHit *p, edm::ESHandle< GlobalTrackingGeometry > trackingGeometry) const
Call the MuonTransientTrackingRecHit::specificBuild.
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:167
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
void setServices(const edm::EventSetup &) override
set the services needed by the TrackTransformer
ConstRecHitPointer const & recHit() const
const GeomDet * idToDet(DetId) const override
Definition: CSCGeometry.cc:114
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
size_type size() const
Definition: OwnVector.h:264
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
TrackTransformer * m_trackTransformer
void push_back(D *&d)
Definition: OwnVector.h:290
int iEvent
Definition: GenABIO.cc:230
static const int CSC
Definition: MuonSubdetId.h:13
bool empty() const
Definition: OwnVector.h:269
void produce(edm::Event &, const edm::EventSetup &) override
TrackerToMuonPropagator(const edm::ParameterSet &)
std::vector< Trajectory > transform(const reco::Track &) const override
Convert a reco::Track into Trajectory.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
Definition: DetId.h:18
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:187
TrackingRecHit::ConstRecHitPointer ConstRecHitPointer
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
T get() const
Definition: EventSetup.h:68
const GeomDet * idToDet(DetId) const override
Definition: DTGeometry.cc:93
const TrackerGeomDet * idToDet(DetId) const override
static const int DT
Definition: MuonSubdetId.h:12
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:50
def move(src, dest)
Definition: eostools.py:511
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:77