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 
85 };
86 
87 //
88 // constants, enums and typedefs
89 //
90 
91 //
92 // static data member definitions
93 //
94 
95 //
96 // constructors and destructor
97 //
99  : m_esTokenProp(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("propagator")))),
100  m_esTokenTk(esConsumes()),
101  m_esTokenDT(esConsumes()),
102  m_esTokenCSC(esConsumes()),
103  m_esTokenMF(esConsumes()),
104  m_esTokenGTGeo(esConsumes()) {
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 }
117 
119  // do anything here that needs to be done at desctruction time
120  // (e.g. close files, deallocate resources etc.)
121 }
122 
123 //
124 // member functions
125 //
126 
127 // ------------ method called to produce the data ------------
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 }
269 
270 //define this as a plug-in
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
void produce(edm::Event &, const edm::EventSetup &) override
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
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