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
31 
32 // products
35 
36 // references
58 
59 //
60 // class decleration
61 //
62 
64 public:
66  ~TrackerToMuonPropagator() override;
67 
68 private:
69  void produce(edm::Event&, const edm::EventSetup&) override;
70 
71  // ----------member data ---------------------------
72 
73  // es tokens
80 
82  const bool m_refitTracker;
83 
86 
88 };
89 
90 //
91 // constants, enums and typedefs
92 //
93 
94 //
95 // static data member definitions
96 //
97 
98 //
99 // constructors and destructor
100 //
102  : m_esTokenProp(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("propagator")))),
103  m_esTokenTk(esConsumes()),
104  m_esTokenDT(esConsumes()),
105  m_esTokenCSC(esConsumes()),
106  m_esTokenMF(esConsumes()),
107  m_esTokenGTGeo(esConsumes()),
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 }
122 
124  // do anything here that needs to be done at desctruction time
125  // (e.g. close files, deallocate resources etc.)
126 }
127 
128 //
129 // member functions
130 //
131 
132 // ------------ method called to produce the data ------------
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 }
271 
272 //define this as a plug-in
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
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)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
const edm::InputTag m_globalMuons
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > m_esTokenDT
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
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
void produce(edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< reco::MuonCollection > muonToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TrackerToMuonPropagator(const edm::ParameterSet &)
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
const edm::InputTag m_globalMuonTracks
fixed size matrix
HLT enums.
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.
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:50
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