CMS 3D CMS Logo

TrackExtenderWithMTD.cc
Go to the documentation of this file.
7 
10 
13 
15 
17 
22 
27 
29 
33 
35 
38 
41 
43 
46 
47 #include <sstream>
48 
50 
53 #include "CLHEP/Units/GlobalPhysicalConstants.h"
54 #include "CLHEP/Units/GlobalSystemOfUnits.h"
55 
56 using namespace std;
57 using namespace edm;
58 
59 
60 
61 
62 template<class TrackCollection>
64  public:
67 
69 
70  template <class H, class T>
71  void fillValueMap(edm::Event& iEvent, const H& handle, const std::vector<T>& vec, const std::string& name) const;
72 
73  void produce(edm::Event& ev, const edm::EventSetup& es) final;
74 
75  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
76 
77  TransientTrackingRecHit::ConstRecHitContainer tryBTLLayers(const TrackType&,
79  const MTDDetLayerGeometry*,
80  const MagneticField* field,
81  const Propagator* prop) const;
82 
83  TransientTrackingRecHit::ConstRecHitContainer tryETLLayers(const TrackType&,
85  const MTDDetLayerGeometry*,
86  const MagneticField* field,
87  const Propagator* prop) const;
88 
91 
92  if (!recHits.empty()){
93  GlobalPoint first = gtg->idToDet(recHits.front()->geographicalId())->position();
94  GlobalPoint last = gtg->idToDet(recHits.back()->geographicalId())->position();
95 
96  // maybe perp2?
97  auto rFirst = first.mag2();
98  auto rLast = last.mag2();
99  if(rFirst < rLast) return RefitDirection::insideOut;
100  if(rFirst > rLast) return RefitDirection::outsideIn;
101  }
102  LogDebug("TrackExtenderWithMTD") << "Impossible to determine the rechits order" <<endl;
104  }
105 
106  reco::Track buildTrack(const reco::Track&, const Trajectory&, const Trajectory &, const reco::BeamSpot&, const MagneticField* field,const Propagator* prop, bool hasMTD, float& pathLength, float& tmtdOut, float& sigmatmtdOut) const;
107  reco::TrackExtra buildTrackExtra(const Trajectory& trajectory) const;
108 
109  string dumpLayer(const DetLayer* layer) const;
110 
111  private:
112  static constexpr char pathLengthName[] = "pathLength";
113  static constexpr char tmtdName[] = "tmtd";
114  static constexpr char sigmatmtdName[] = "sigmatmtd";
115  static constexpr char pOrigTrkName[] = "generalTrackp";
116  static constexpr char betaOrigTrkName[] = "generalTrackBeta";
117  static constexpr char t0OrigTrkName[] = "generalTrackt0";
118  static constexpr char sigmat0OrigTrkName[] = "generalTracksigmat0";
119  static constexpr char pathLengthOrigTrkName[] = "generalTrackPathLength";
120  static constexpr char tmtdOrigTrkName[] = "generalTracktmtd";
121  static constexpr char sigmatmtdOrigTrkName[] = "generalTracksigmatmtd";
122 
126  const bool updateTraj_, updateExtra_, updatePattern_;
127  const std::string mtdRecHitBuilder_,propagator_, transientTrackBuilder_;
128  std::unique_ptr<MeasurementEstimator> theEstimator;
129  std::unique_ptr<TrackTransformer> theTransformer;
134 };
135 
136 
137 template<class TrackCollection>
139  tracksToken_(consumes<InputCollection>(iConfig.getParameter<edm::InputTag>("tracksSrc"))),
140  hitsToken_(consumes<MTDTrackingDetSetVector>(iConfig.getParameter<edm::InputTag>("hitsSrc"))),
141  bsToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotSrc"))),
142  updateTraj_(iConfig.getParameter<bool>("updateTrackTrajectory")),
143  updateExtra_(iConfig.getParameter<bool>("updateTrackExtra")),
144  updatePattern_(iConfig.getParameter<bool>("updateTrackHitPattern")),
145  mtdRecHitBuilder_(iConfig.getParameter<std::string>("MTDRecHitBuilder")),
146  propagator_(iConfig.getParameter<std::string>("Propagator")),
147  transientTrackBuilder_(iConfig.getParameter<std::string>("TransientTrackBuilder")) {
148  constexpr float maxChi2=500.;
149  constexpr float nSigma=10.;
150  theEstimator = std::make_unique<Chi2MeasurementEstimator>(maxChi2,nSigma);
151 
152  theTransformer = std::make_unique<TrackTransformer>(iConfig.getParameterSet("TrackTransformer"));
153 
154  produces<edm::ValueMap<float> >(pathLengthName);
155  produces<edm::ValueMap<float> >(tmtdName);
156  produces<edm::ValueMap<float> >(sigmatmtdName);
157  produces<edm::ValueMap<float> >(pOrigTrkName);
158  produces<edm::ValueMap<float> >(betaOrigTrkName);
159  produces<edm::ValueMap<float> >(t0OrigTrkName);
160  produces<edm::ValueMap<float> >(sigmat0OrigTrkName);
161  produces<edm::ValueMap<float> >(pathLengthOrigTrkName);
162  produces<edm::ValueMap<float> >(tmtdOrigTrkName);
163  produces<edm::ValueMap<float> >(sigmatmtdOrigTrkName);
164 
165  produces<edm::OwnVector<TrackingRecHit>>();
166  produces<reco::TrackExtraCollection>();
167  produces<TrackCollection>();
168 }
169 
170 template<class TrackCollection>
172  edm::ParameterSetDescription desc,transDesc;
173  desc.add<edm::InputTag>("tracksSrc",edm::InputTag("generalTracks"));
174  desc.add<edm::InputTag>("hitsSrc",edm::InputTag("mtdTrackingRecHits"));
175  desc.add<edm::InputTag>("beamSpotSrc",edm::InputTag("offlineBeamSpot"));
176  desc.add<bool>("updateTrackTrajectory",true);
177  desc.add<bool>("updateTrackExtra",true);
178  desc.add<bool>("updateTrackHitPattern",true);
179  desc.add<std::string>("TransientTrackBuilder","TransientTrackBuilder");
180  desc.add<std::string>("MTDRecHitBuilder","MTDRecHitBuilder");
181  desc.add<std::string>("Propagator","PropagatorWithMaterialForMTD");
183  false,
184  "KFFitterForRefitInsideOut",
185  "KFSmootherForRefitInsideOut",
186  "PropagatorWithMaterialForMTD",
187  "alongMomentum",
188  true,
189  "WithTrackAngle",
190  "MuonRecHitBuilder",
191  "MTDRecHitBuilder"
192  );
193  desc.add<edm::ParameterSetDescription>("TrackTransformer",transDesc);
194  descriptions.add("trackExtenderWithMTDBase", desc);
195 }
196 
197 template<class TrackCollection>
198 template <class H, class T>
199 void TrackExtenderWithMTDT<TrackCollection>::fillValueMap(edm::Event& iEvent, const H& handle, const std::vector<T>& vec, const std::string& name) const {
200  auto out = std::make_unique<edm::ValueMap<T>>();
202  filler.insert(handle, vec.begin(), vec.end());
203  filler.fill();
204  iEvent.put(std::move(out),name);
205 }
206 
207 template<class TrackCollection>
209  const edm::EventSetup& es ) {
210  //this produces pieces of the track extra
211  Traj2TrackHits t2t;
212 
213  theTransformer->setServices(es);
214 
217 
219 
221  es.get<MTDRecoGeometryRecord>().get(geo);
222 
224  es.get<IdealMagneticFieldRecord>().get(magfield);
225 
228 
230  es.get<TrackingComponentsRecord>().get(propagator_,prop);
231 
233  es.get<TrackerTopologyRcd>().get(httopo);
234  const TrackerTopology& ttopo = *httopo;
235 
236  auto output = std::make_unique<TrackCollection>();
237  auto extras = std::make_unique<reco::TrackExtraCollection>();
238  auto outhits = std::make_unique<edm::OwnVector<TrackingRecHit>>();
239 
240  std::vector<float> pathLengthsRaw;
241  std::vector<float> tmtdRaw;
242  std::vector<float> sigmatmtdRaw;
243  std::vector<float> pOrigTrkRaw;
244  std::vector<float> betaOrigTrkRaw;
245  std::vector<float> t0OrigTrkRaw;
246  std::vector<float> sigmat0OrigTrkRaw;
247  std::vector<float> pathLengthsOrigTrkRaw;
248  std::vector<float> tmtdOrigTrkRaw;
249  std::vector<float> sigmatmtdOrigTrkRaw;
250 
252  ev.getByToken(tracksToken_,tracksH);
253  const auto& tracks = *tracksH;
254 
256  ev.getByToken(hitsToken_,hitsH);
257  const auto& hits = *hitsH;
258 
260  ev.getByToken(bsToken_,bsH);
261  const auto& bs = *bsH;
262 
263  std::vector<unsigned> track_indices;
264  unsigned itrack = 0;
265  for( const auto& track : tracks ) {
266 
267  reco::TransientTrack ttrack(track,magfield.product(),gtg);
268  const auto& trajs = theTransformer->transform(track);
269  auto thits = theTransformer->getTransientRecHits(ttrack);
270 
272  const auto& btlhits = tryBTLLayers(track,hits,geo.product(),magfield.product(),prop.product());
273  mtdthits.insert(mtdthits.end(),btlhits.begin(),btlhits.end());
274 
275  // in the future this should include an intermediate refit before propagating to the ETL
276  // for now it is ok
277  const auto& etlhits = tryETLLayers(track,hits,geo.product(),magfield.product(),prop.product());
278  mtdthits.insert(mtdthits.end(),etlhits.begin(),etlhits.end());
279 
280  auto ordering = checkRecHitsOrdering(thits);
282  thits.insert(thits.end(),mtdthits.begin(),mtdthits.end());
283  } else {
284  std::reverse(mtdthits.begin(),mtdthits.end());
285  mtdthits.insert(mtdthits.end(),thits.begin(),thits.end());
286  thits.swap(mtdthits);
287  }
288  const auto& trajwithmtd = theTransformer->transform(ttrack,thits);
289  float pMap = 0.f, betaMap = 0.f, t0Map = 0.f, sigmat0Map = -1.f, pathLengthMap = -1.f, tmtdMap = 0.f, sigmatmtdMap = -1.f;
290 
291  for( const auto& trj : trajwithmtd ) {
292  const auto& thetrj = (updateTraj_ ? trj : trajs.front());
293  float pathLength = 0.f, tmtd = 0.f, sigmatmtd = -1.f;
294  reco::Track result = buildTrack(track, thetrj, trj, bs, magfield.product(),
295  prop.product(), !mtdthits.empty(),pathLength,tmtd,sigmatmtd);
296  if( result.ndof() >= 0 ) {
298  reco::TrackExtra::TrajParams trajParams;
300  size_t hitsstart = outhits->size();
301  if( updatePattern_ ) {
302  t2t(trj,*outhits,trajParams,chi2s); // this fills the output hit collection
303  } else {
304  t2t(thetrj,*outhits,trajParams,chi2s);
305  }
306  size_t hitsend = outhits->size();
307  extras->push_back(buildTrackExtra(trj)); // always push back the fully built extra, update by setting in track
308  extras->back().setHits(hitsRefProd,hitsstart,hitsend-hitsstart);
309  extras->back().setTrajParams(trajParams,chi2s);
310  //create the track
311  output->push_back(result);
312  pathLengthsRaw.push_back(pathLength);
313  tmtdRaw.push_back(tmtd);
314  sigmatmtdRaw.push_back(sigmatmtd);
315  pathLengthMap = pathLength;
316  tmtdMap = tmtd;
317  sigmatmtdMap = sigmatmtd;
318  auto& backtrack = output->back();
319  pMap = backtrack.p();
320  betaMap = backtrack.beta();
321  t0Map = backtrack.t0();
322  sigmat0Map = std::copysign(std::sqrt(std::abs(backtrack.covt0t0())),backtrack.covt0t0());
323  reco::TrackExtraRef extraRef(extrasRefProd,extras->size()-1);
324  backtrack.setExtra( (updateExtra_ ? extraRef : track.extra()) );
325  for(unsigned ihit = hitsstart; ihit < hitsend; ++ihit) {
326  backtrack.appendHitPattern((*outhits)[ihit],ttopo);
327  }
328  }
329  }
330  pOrigTrkRaw.push_back(pMap);
331  betaOrigTrkRaw.push_back(betaMap);
332  t0OrigTrkRaw.push_back(t0Map);
333  sigmat0OrigTrkRaw.push_back(sigmat0Map);
334  pathLengthsOrigTrkRaw.push_back(pathLengthMap);
335  tmtdOrigTrkRaw.push_back(tmtdMap);
336  sigmatmtdOrigTrkRaw.push_back(sigmatmtdMap);
337  ++itrack;
338  }
339 
340  auto outTrksHandle = ev.put(std::move(output));
341  ev.put(std::move(extras));
342  ev.put(std::move(outhits));
343 
344  fillValueMap(ev, outTrksHandle, pathLengthsRaw, pathLengthName);
345  fillValueMap(ev, outTrksHandle, tmtdRaw, tmtdName);
346  fillValueMap(ev, outTrksHandle, sigmatmtdRaw, sigmatmtdName);
347  fillValueMap(ev, tracksH, pOrigTrkRaw, pOrigTrkName);
348  fillValueMap(ev, tracksH, betaOrigTrkRaw, betaOrigTrkName);
349  fillValueMap(ev, tracksH, t0OrigTrkRaw, t0OrigTrkName);
350  fillValueMap(ev, tracksH, sigmat0OrigTrkRaw, sigmat0OrigTrkName);
351  fillValueMap(ev, tracksH, pathLengthsOrigTrkRaw, pathLengthOrigTrkName);
352  fillValueMap(ev, tracksH, tmtdOrigTrkRaw, tmtdOrigTrkName);
353  fillValueMap(ev, tracksH, sigmatmtdOrigTrkRaw, sigmatmtdOrigTrkName);
354 }
355 
356 namespace {
357  bool cmp_for_detset(const unsigned one, const unsigned two) { return one < two; };
358 
359  void find_hits_in_dets(const MTDTrackingDetSetVector& hits, const DetLayer* layer,
360  const TrajectoryStateOnSurface& tsos, const Propagator* prop,
364  pair<bool, TrajectoryStateOnSurface> comp = layer->compatible(tsos,*prop,theEstimator);
365  if( comp.first ) {
366  vector<DetLayer::DetWithState> compDets = layer->compatibleDets(tsos,*prop,theEstimator);
367  if (!compDets.empty()) {
368  MTDTrackingRecHit* best = nullptr;
369  double best_chi2 = std::numeric_limits<double>::max();
370  for( const auto& detWithState : compDets ) {
371  auto range = hits.equal_range(detWithState.first->geographicalId(),cmp_for_detset);
372  for( auto detitr = range.first; detitr != range.second; ++detitr ) {
373  for( auto itr = detitr->begin(); itr != detitr->end(); ++itr ) {
374  auto est = theEstimator.estimate(detWithState.second,*itr);
375  if( est.first && est.second < best_chi2 ) { // just take the best chi2
376  best = &(*itr);
377  best_chi2 = est.second;
378  }
379 
380  }
381  }
382  }
383  if( best )
384  output.push_back(hitbuilder.build(best));
385  }
386  }
387  }
388 }
389 
390 template<class TrackCollection>
394  const MTDDetLayerGeometry* geo,
395  const MagneticField* field,
396  const Propagator* prop) const {
397 
399  const vector<const DetLayer*>& layers = geo->allBTLLayers();
400  auto tTrack = builder->build(track);
401 
402  for (const DetLayer* ilay : layers) {
403  // get the outermost trajectory point on the track
404  TrajectoryStateOnSurface tsos = tTrack.outermostMeasurementState();
405  find_hits_in_dets(hits,ilay,tsos,prop,*theEstimator,*hitbuilder,output);
406  }
407  return output;
408 }
409 
410 template<class TrackCollection>
414  const MTDDetLayerGeometry* geo,
415  const MagneticField* field,
416  const Propagator* prop) const {
417 
419  const vector<const DetLayer*>& layers = geo->allETLLayers();
420 
421  auto tTrack = builder->build(track);
422 
423  for (const DetLayer* ilay : layers) {
424  const BoundDisk& disk = static_cast<const MTDRingForwardDoubleLayer*>(ilay)->specificSurface();
425  const double diskZ = disk.position().z();
426 
427  // get the outermost trajectory point on the track
428  TrajectoryStateOnSurface tsos = tTrack.outermostMeasurementState();
429  if( tsos.globalPosition().z() * diskZ < 0 ) continue; // only propagate to the disk that's on the same side
430  find_hits_in_dets(hits,ilay,tsos,prop,*theEstimator,*hitbuilder,output);
431  }
432  return output;
433 }
434 
435 
436 //below is unfortunately ripped from other places but
437 //since track producer doesn't know about MTD we have to do this
438 template<class TrackCollection>
440  const Trajectory& traj,
441  const Trajectory& trajWithMtd,
442  const reco::BeamSpot& bs,
443  const MagneticField* field,
444  const Propagator* thePropagator,
445  bool hasMTD,
446  float& pathLengthOut,
447  float& tmtdOut,
448  float& sigmatmtdOut) const {
449 
450  // get the state closest to the beamline
451  TrajectoryStateOnSurface stateForProjectionToBeamLineOnSurface =
452  traj.closestMeasurement(GlobalPoint(bs.x0(),bs.y0(),bs.z0())).updatedState();
453 
454  if UNLIKELY(!stateForProjectionToBeamLineOnSurface.isValid()) {
455  edm::LogError("CannotPropagateToBeamLine")<<"the state on the closest measurement isnot valid. skipping track.";
456  return reco::Track();
457  }
458 
459  constexpr double m_pi = 0.13957018;
460  constexpr double m_pi_inv2 = 1.0/m_pi/m_pi;
461  constexpr double m_p = 0.9382720813;
462  constexpr double m_p_inv2 = 1.0/m_p/m_p;
463  constexpr double c_cm_ns = CLHEP::c_light*CLHEP::ns/CLHEP::cm; //[cm/ns]
464  constexpr double c_inv = 1.0/c_cm_ns;
465 
466  const FreeTrajectoryState & stateForProjectionToBeamLine=*stateForProjectionToBeamLineOnSurface.freeState();
467 
468  TSCBLBuilderWithPropagator tscblBuilder(*thePropagator);
469  TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(stateForProjectionToBeamLine,bs);
470 
471  if UNLIKELY(!tscbl.isValid()) {
472  return reco::Track();
473  }
474 
476  math::XYZPoint pos( v.x(), v.y(), v.z() );
478  math::XYZVector mom( p.x(), p.y(), p.z() );
479 
480  int ndof = traj.ndof();
481 
482  double t0 = 0.;
483  double covt0t0 = -1.;
484  pathLengthOut = -1.f; // if there is no MTD flag the pathlength with -1
485  tmtdOut = 0.f;
486  sigmatmtdOut = -1.f;
487  double betaOut = 0.;
488  double covbetabeta = -1.;
489 
490  //compute path length for time backpropagation, using first MTD hit for the momentum
491  if (hasMTD) {
492 
493  bool validpropagation = true;
494  double pathlength = 0.;
495  double pathlength1 = 0.;
496  double pathlength2 = 0.;
497  for (auto it=trajWithMtd.measurements().begin(); it!=trajWithMtd.measurements().end()-1; ++it) {
498  const auto &propresult = thePropagator->propagateWithPath(it->updatedState(), (it+1)->updatedState().surface());
499  double layerpathlength = std::abs(propresult.second);
500  if (layerpathlength==0.) {
501  validpropagation = false;
502  }
503  pathlength1 += layerpathlength;
504  }
505 
506  double thit = 0.;
507  double thiterror = -1.;
508  bool validmtd = false;
509  if (trajWithMtd.direction() == alongMomentum) {
510  for (auto it=trajWithMtd.measurements().begin(); it!=trajWithMtd.measurements().end(); ++it) {
511  bool ismtd = it->recHit()->geographicalId().det() == DetId::Forward && ForwardSubdetector(it->recHit()->geographicalId().subdetId()) == FastTime;
512  if (ismtd) {
513  const auto &propresult2 = thePropagator->propagateWithPath(tscbl.trackStateAtPCA(), trajWithMtd.firstMeasurement().updatedState().surface());
514  pathlength2 = propresult2.second;
515  if (pathlength2 == 0.) {
516  validpropagation = false;
517  }
518  pathlength = pathlength1 + pathlength2;
519  const MTDTrackingRecHit *mtdhit = static_cast<const MTDTrackingRecHit*>(it->recHit()->hit());
520  thit = mtdhit->time();
521  thiterror = mtdhit->timeError();
522  validmtd = true;
523  break;
524  }
525  }
526  }
527  else {
528  for (auto it=trajWithMtd.measurements().rbegin(); it!=trajWithMtd.measurements().rend(); ++it) {
529  bool ismtd = it->recHit()->geographicalId().det() == DetId::Forward && ForwardSubdetector(it->recHit()->geographicalId().subdetId()) == FastTime;
530  if (ismtd) {
531  const auto &propresult2 = thePropagator->propagateWithPath(tscbl.trackStateAtPCA(), trajWithMtd.lastMeasurement().updatedState().surface());
532  pathlength2 = propresult2.second;
533  if (pathlength2 == 0.) {
534  validpropagation = false;
535  }
536  pathlength = pathlength1 + pathlength2;
537  const MTDTrackingRecHit *mtdhit = static_cast<const MTDTrackingRecHit*>(it->recHit()->hit());
538  thit = mtdhit->time();
539  thiterror = mtdhit->timeError();
540  validmtd = true;
541  break;
542  }
543  }
544  }
545 
546  if (validmtd && validpropagation) {
547  double magp2 = p.mag2();
548 
549  double gammasq_pi = 1. + magp2*m_pi_inv2;
550  double beta_pi = std::sqrt(1.-1./gammasq_pi);
551  double dt_pi = pathlength/beta_pi*c_inv;
552 
553  double gammasq_p = 1. + magp2*m_p_inv2;
554  double beta_p = std::sqrt(1.-1./gammasq_p);
555  double dt_p = pathlength/beta_p*c_inv;
556 
557  double dterror = dt_p - dt_pi;
558  double betaerror = beta_p - beta_pi;
559 
560  pathLengthOut = pathlength; // set path length if we've got a timing hit
561  tmtdOut = thit;
562  sigmatmtdOut = thiterror;
563  t0 = thit - dt_pi;
564  covt0t0 = thiterror*thiterror + dterror*dterror;
565  betaOut = beta_pi;
566  covbetabeta = betaerror*betaerror;
567  }
568 
569  }
570 
571  return reco::Track(traj.chiSquared(),
572  int(ndof),
573  pos, mom, tscbl.trackStateAtPCA().charge(),
575  orig.algo(),reco::TrackBase::undefQuality,t0,betaOut,covt0t0,covbetabeta);
576 }
577 
578 template<class TrackCollection>
580 
581  static const string metname = "TrackExtenderWithMTD";
582 
583  const Trajectory::RecHitContainer transRecHits = trajectory.recHits();
584 
585  // put the collection of TrackingRecHit in the event
586 
587  // sets the outermost and innermost TSOSs
588  // ToDo: validation for track states with MTD
589  TrajectoryStateOnSurface outerTSOS;
590  TrajectoryStateOnSurface innerTSOS;
591  unsigned int innerId=0, outerId=0;
593  DetId outerDetId;
594 
595  if (trajectory.direction() == alongMomentum) {
596  LogTrace(metname)<<"alongMomentum";
597  outerTSOS = trajectory.lastMeasurement().updatedState();
598  innerTSOS = trajectory.firstMeasurement().updatedState();
599  outerId = trajectory.lastMeasurement().recHit()->geographicalId().rawId();
600  innerId = trajectory.firstMeasurement().recHit()->geographicalId().rawId();
601  outerRecHit = trajectory.lastMeasurement().recHit();
602  outerDetId = trajectory.lastMeasurement().recHit()->geographicalId();
603  }
604  else if (trajectory.direction() == oppositeToMomentum) {
605  LogTrace(metname)<<"oppositeToMomentum";
606  outerTSOS = trajectory.firstMeasurement().updatedState();
607  innerTSOS = trajectory.lastMeasurement().updatedState();
608  outerId = trajectory.firstMeasurement().recHit()->geographicalId().rawId();
609  innerId = trajectory.lastMeasurement().recHit()->geographicalId().rawId();
610  outerRecHit = trajectory.firstMeasurement().recHit();
611  outerDetId = trajectory.firstMeasurement().recHit()->geographicalId();
612  }
613  else LogError(metname)<<"Wrong propagation direction!";
614 
615  const GeomDet *outerDet = gtg->idToDet(outerDetId);
616  GlobalPoint outerTSOSPos = outerTSOS.globalParameters().position();
617  bool inside = outerDet->surface().bounds().inside(outerDet->toLocal(outerTSOSPos));
618 
619 
620  GlobalPoint hitPos = (outerRecHit->isValid()) ? outerRecHit->globalPosition() : outerTSOS.globalParameters().position() ;
621 
622  if(!inside) {
623  LogTrace(metname)
624  << "The Global Muon outerMostMeasurementState is not compatible with the recHit detector!"
625  << " Setting outerMost postition to recHit position if recHit isValid: " << outerRecHit->isValid();
626  LogTrace(metname)<<"From " << outerTSOSPos << " to " << hitPos;
627  }
628 
629 
630  //build the TrackExtra
631  GlobalPoint v = (inside) ? outerTSOSPos : hitPos ;
632  GlobalVector p = outerTSOS.globalParameters().momentum();
633  math::XYZPoint outpos( v.x(), v.y(), v.z() );
634  math::XYZVector outmom( p.x(), p.y(), p.z() );
635 
636  v = innerTSOS.globalParameters().position();
637  p = innerTSOS.globalParameters().momentum();
638  math::XYZPoint inpos( v.x(), v.y(), v.z() );
639  math::XYZVector inmom( p.x(), p.y(), p.z() );
640 
641  reco::TrackExtra trackExtra(outpos, outmom, true, inpos, inmom, true,
642  outerTSOS.curvilinearError(), outerId,
643  innerTSOS.curvilinearError(), innerId,
644  trajectory.direction(),trajectory.seedRef());
645 
646  return trackExtra;
647 
648 }
649 
650 template<class TrackCollection>
652  stringstream output;
653 
654  const BoundSurface* sur=nullptr;
655  const BoundCylinder* bc=nullptr;
656  const BoundDisk* bd=nullptr;
657 
658  sur = &(layer->surface());
659  if ( (bc = dynamic_cast<const BoundCylinder*>(sur)) ) {
660  output << " Cylinder of radius: " << bc->radius() << endl;
661  }
662  else if ( (bd = dynamic_cast<const BoundDisk*>(sur)) ) {
663  output << " Disk at: " << bd->position().z() << endl;
664  }
665  return output.str();
666 }
667 
668 //define this as a plug-in
675 
#define LogDebug(id)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double z0() const
z coordinate
Definition: BeamSpot.h:68
TrackExtenderWithMTDT< reco::TrackCollection > TrackExtenderWithMTD
T mag2() const
Definition: PV3DBase.h:66
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
ConstRecHitPointer const & recHit() const
float time() const
Range equal_range(id_type i, CMP cmp, bool update=false) const
std::vector< unsigned char > Chi2sFive
reco::TrackExtra buildTrackExtra(const Trajectory &trajectory) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const std::string metname
edm::EDGetTokenT< reco::BeamSpot > bsToken_
std::unique_ptr< MeasurementEstimator > theEstimator
TrackExtenderWithMTDT(const ParameterSet &pset)
const CurvilinearTrajectoryError & curvilinearError() const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
reco::TransientTrack build(const reco::Track *p) const
T y() const
Definition: PV3DBase.h:63
string dumpLayer(const DetLayer *layer) const
edm::View< TrackType > InputCollection
GlobalPoint globalPosition() const
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:69
ConstRecHitContainer recHits() const
Definition: Trajectory.h:204
const Bounds & bounds() const
Definition: Surface.h:120
edm::ESHandle< GlobalTrackingGeometry > gtg
bool ev
const std::vector< const DetLayer * > & allBTLLayers() const
return the BTL DetLayers (barrel), inside-out
TrackCharge charge() const
reco::Track buildTrack(const reco::Track &, const Trajectory &, const Trajectory &, const reco::BeamSpot &, const MagneticField *field, const Propagator *prop, bool hasMTD, float &pathLength, float &tmtdOut, float &sigmatmtdOut) const
TrajectoryMeasurement const & closestMeasurement(GlobalPoint) const
Definition: Trajectory.cc:256
ForwardSubdetector
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
const CurvilinearTrajectoryError & curvilinearError() const
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
edm::EDGetTokenT< MTDTrackingDetSetVector > hitsToken_
PropagationDirection const & direction() const
Definition: Trajectory.cc:140
TrackAlgorithm algo() const
Definition: TrackBase.h:536
DataContainer const & measurements() const
Definition: Trajectory.h:196
std::vector< LocalTrajectoryParameters > TrajParams
virtual bool inside(const Local3DPoint &) const =0
Determine if the point is inside the bounds.
int iEvent
Definition: GenABIO.cc:224
const SurfaceType & surface() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const std::vector< const DetLayer * > & allETLLayers() const
return the ETL DetLayers (endcap), -Z to +Z
const std::string mtdRecHitBuilder_
edm::ESHandle< TransientTrackingRecHitBuilder > hitbuilder
double ndof() const
number of degrees of freedom of the fit
Definition: TrackBase.h:594
T sqrt(T t)
Definition: SSEVec.h:18
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:174
FreeTrajectoryState const * freeState(bool withErrors=true) const
T z() const
Definition: PV3DBase.h:64
RefitDirection::GeometricalDirection checkRecHitsOrdering(TransientTrackingRecHit::ConstRecHitContainer const &recHits) const
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
Definition: Propagator.cc:15
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
const std::string propagator_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::RefToBase< TrajectorySeed > seedRef(void) const
Definition: Trajectory.h:321
virtual std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const =0
#define LogTrace(id)
GlobalVector momentum() const
RefProd< PROD > getRefBeforePut()
Definition: Event.h:150
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
std::vector< ConstRecHitPointer > ConstRecHitContainer
const std::string transientTrackBuilder_
Definition: DetId.h:18
GlobalPoint position() const
int ndof(bool bon=true) const
Definition: Trajectory.cc:102
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:187
static void fillPSetDescription(edm::ParameterSetDescription &descriptions, bool DoPredictionsOnly=false, const std::string &Fitter="KFFitterForRefitInsideOut", const std::string &Smoother="KFSmootherForRefitInsideOut", const std::string &Propagator="SmartPropagatorAnyRK", const std::string &RefitDirection="alongMomentum", bool RefitRPCHits=true, const std::string &TrackerRecHitBuilder="WithTrackAngle", const std::string &MuonRecHitBuilder="MuonRecHitBuilder", const std::string &MTDRecHitBuilder="MTDRecHitBuilder")
fillDescriptions
ConstRecHitContainer RecHitContainer
Definition: Trajectory.h:46
TransientTrackingRecHit::ConstRecHitContainer tryBTLLayers(const TrackType &, const MTDTrackingDetSetVector &, const MTDDetLayerGeometry *, const MagneticField *field, const Propagator *prop) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::ESHandle< Propagator > prop
const GlobalTrajectoryParameters & globalParameters() const
ParameterSet const & getParameterSet(std::string const &) const
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
TransientTrackingRecHit::ConstRecHitContainer tryETLLayers(const TrackType &, const MTDTrackingDetSetVector &, const MTDDetLayerGeometry *, const MagneticField *field, const Propagator *prop) const
edm::ESHandle< TransientTrackBuilder > builder
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
A 2D TrackerRecHit with time and time error information.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TrackingRecHit::ConstRecHitPointer ConstRecHitPointer
std::unique_ptr< TrackTransformer > theTransformer
float chiSquared() const
Definition: Trajectory.h:262
fixed size matrix
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:509
T get() const
Definition: EventSetup.h:71
const GeomDet * idToDet(DetId) const override
double y0() const
y coordinate
Definition: BeamSpot.h:66
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
TrajectoryStateOnSurface const & updatedState() const
#define UNLIKELY(x)
Definition: Likely.h:21
TrackCollection::value_type TrackType
float timeError() const
T x() const
Definition: PV3DBase.h:62
ordering
Definition: config.py:7
T const * product() const
Definition: ESHandle.h:86
void produce(edm::Event &ev, const edm::EventSetup &es) final
edm::EDGetTokenT< InputCollection > tracksToken_
def move(src, dest)
Definition: eostools.py:511
#define constexpr
void fillValueMap(edm::Event &iEvent, const H &handle, const std::vector< T > &vec, const std::string &name) const
#define m_pi
Definition: RPCConst.cc:8
double x0() const
x coordinate
Definition: BeamSpot.h:64