CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
TrackMerger Class Reference

#include <TrackMerger.h>

Classes

class  GlobalMomentumSort
 
class  MomentumSort
 

Public Member Functions

void init (const edm::EventSetup &iSetup)
 
TrackCandidate merge (const reco::Track &inner, const reco::Track &outer, DuplicateTrackType duplicateType) const
 
 TrackMerger (const edm::ParameterSet &iConfig, edm::ConsumesCollector)
 
 ~TrackMerger ()
 

Private Member Functions

void addSecondTrackHits (std::vector< const TrackingRecHit *> &hits, const reco::Track &outer) const
 
void sortByHitPosition (const GlobalVector &v, const std::vector< const TrackingRecHit *> &hits, TrackCandidate::RecHitContainer &ownHits) const
 

Private Attributes

edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecordbuilderToken_
 
bool debug_
 
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecordgeometryToken_
 
edm::ESGetToken< MagneticField, IdealMagneticFieldRecordmagFieldToken_
 
edm::ESHandle< TransientTrackingRecHitBuildertheBuilder
 
std::string theBuilderName
 
edm::ESHandle< TrackerGeometrytheGeometry
 
edm::ESHandle< MagneticFieldtheMagField
 
edm::ESHandle< TrackerTopologytheTrkTopo
 
edm::ESGetToken< TrackerTopology, TrackerTopologyRcdtrackerTopoToken_
 
bool useInnermostState_
 

Detailed Description

Definition at line 19 of file TrackMerger.h.

Constructor & Destructor Documentation

◆ TrackMerger()

TrackMerger::TrackMerger ( const edm::ParameterSet iConfig,
edm::ConsumesCollector  cc 
)

Definition at line 22 of file TrackMerger.cc.

23  : useInnermostState_(iConfig.getParameter<bool>("useInnermostState")),
24  debug_(false),
25  theBuilderName(iConfig.getParameter<std::string>("ttrhBuilderName")),
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::string theBuilderName
Definition: TrackMerger.h:33
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > builderToken_
Definition: TrackMerger.h:38
bool useInnermostState_
Definition: TrackMerger.h:31
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
Definition: TrackMerger.h:37
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geometryToken_
Definition: TrackMerger.h:36
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopoToken_
Definition: TrackMerger.h:39

◆ ~TrackMerger()

TrackMerger::~TrackMerger ( )

Definition at line 32 of file TrackMerger.cc.

32 {}

Member Function Documentation

◆ addSecondTrackHits()

void TrackMerger::addSecondTrackHits ( std::vector< const TrackingRecHit *> &  hits,
const reco::Track outer 
) const
private

Definition at line 147 of file TrackMerger.cc.

References TrackingRecHit::all, hfClusterShapes_cfi::hits, l1ctLayer2EG_cff::id, globals_cff::id2, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, TrackerTopology::layer(), SurfaceOrientation::outer, PRINT, theTrkTopo, and validateGeometry_cfg::valid.

Referenced by merge().

147  {
148  size_t nHitsFirstTrack = hits.size();
149  for (auto it = outer.recHitsBegin(), ed = outer.recHitsEnd(); it != ed; ++it) {
150  const TrackingRecHit *hit = &**it;
151  DetId id(hit->geographicalId());
152  const auto lay = theTrkTopo->layer(id);
153  bool shared = false;
154  bool valid = hit->isValid();
155  PRINT << " subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid " << valid
156  << " detid: " << id() << std::endl;
157  size_t iHit = 0;
158  for (auto hit2 : hits) {
159  ++iHit;
160  if (iHit > nHitsFirstTrack)
161  break;
162  DetId id2 = hit2->geographicalId();
163  if (id.subdetId() != id2.subdetId())
164  continue;
165  if (theTrkTopo->layer(id2) != lay)
166  continue;
167  if (hit->sharesInput(hit2, TrackingRecHit::all)) {
168  PRINT << " discared as duplicate of other hit" << id() << std::endl;
169  shared = true;
170  break;
171  }
172  if (hit2->isValid() && !valid) {
173  PRINT << " replacing old invalid hit on detid " << id2() << std::endl;
174  hit = hit2;
175  shared = true;
176  break;
177  }
178  PRINT << " discared as additional hit on layer that already contains hit with detid " << id() << std::endl;
179  shared = true;
180  break;
181  }
182  if (shared)
183  continue;
184  hits.push_back(hit);
185  }
186 }
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:35
unsigned int layer(const DetId &id) const
#define PRINT
Definition: TrackMerger.cc:19
Definition: DetId.h:17

◆ init()

void TrackMerger::init ( const edm::EventSetup iSetup)

Definition at line 34 of file TrackMerger.cc.

References builderToken_, geometryToken_, edm::EventSetup::getHandle(), magFieldToken_, theBuilder, theGeometry, theMagField, theTrkTopo, and trackerTopoToken_.

34  {
39 }
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:35
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > builderToken_
Definition: TrackMerger.h:38
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
Definition: TrackMerger.h:37
edm::ESHandle< TransientTrackingRecHitBuilder > theBuilder
Definition: TrackMerger.h:34
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geometryToken_
Definition: TrackMerger.h:36
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopoToken_
Definition: TrackMerger.h:39
edm::ESHandle< MagneticField > theMagField
Definition: TrackMerger.h:30
edm::ESHandle< TrackerGeometry > theGeometry
Definition: TrackMerger.h:29

◆ merge()

TrackCandidate TrackMerger::merge ( const reco::Track inner,
const reco::Track outer,
DuplicateTrackType  duplicateType 
) const

Definition at line 41 of file TrackMerger.cc.

References funct::abs(), addSecondTrackHits(), alongMomentum, debug_, Disjoint, DPRINT, hfClusterShapes_cfi::hits, l1ctLayer2EG_cff::id, SurfaceOrientation::inner, trajectoryStateTransform::innerStateOnSurface(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, TrackerTopology::layer(), nhits, oppositeToMomentum, SurfaceOrientation::outer, trajectoryStateTransform::outerStateOnSurface(), Overlapping, AlCaHLTBitMon_ParallelJobs::p, trajectoryStateTransform::persistentState(), PRINT, edm::OwnVector< T, P >::push_back(), edm::OwnVector< T, P >::reserve(), runTheMatrix::ret, groupFilesInBlocks::reverse, fileCollector::seed, jetUpdater_cfi::sort, sortByHitPosition(), DetId::subdetId(), theGeometry, theMagField, theTrkTopo, useInnermostState_, and findQualityFiles::v.

43  {
44  DPRINT("TrackMerger") << std::abs(inner.eta()) << " merging " << inner.algo() << '/' << outer.algo() << ' '
45  << inner.eta() << '/' << outer.eta() << std::endl;
46 
47  std::vector<const TrackingRecHit *> hits;
48  hits.reserve(inner.recHitsSize() + outer.recHitsSize());
49  DPRINT("TrackMerger") << "Inner track hits: " << std::endl;
50  for (auto it = inner.recHitsBegin(), ed = inner.recHitsEnd(); it != ed; ++it) {
51  hits.push_back(&**it);
52  if (debug_) {
53  DetId id(hits.back()->geographicalId());
54  PRINT << " subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid "
55  << hits.back()->isValid() << " detid: " << id() << std::endl;
56  }
57  }
58  DPRINT("TrackMerger") << "Outer track hits: " << std::endl;
59 
60  if (duplicateType == DuplicateTrackType::Disjoint) {
61 #if TRACK_SORT
62  DetId lastId(hits.back()->geographicalId());
63  int lastSubdet = lastId.subdetId();
64  unsigned int lastLayer = theTrkTopo->layer(lastId);
65  for (auto it = outer.recHitsBegin(), ed = outer.recHitsEnd(); it != ed; ++it) {
66  const TrackingRecHit *hit = &**it;
67  DetId id(hit->geographicalId());
68  int thisSubdet = id.subdetId();
69  if (thisSubdet > lastSubdet || (thisSubdet == lastSubdet && theTrkTopo->layer(id) > lastLayer)) {
70  hits.push_back(hit);
71  PRINT << " adding subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid "
72  << hit->isValid() << " detid: " << id() << std::endl;
73  } else {
74  PRINT << " skipping subdet " << thisSubdet << " layer " << theTrkTopo->layer(id) << " valid "
75  << hit->isValid() << " detid: " << id() << std::endl;
76  }
77  }
78 #else
80 #endif
81  } else if (duplicateType == DuplicateTrackType::Overlapping) {
83  }
84 
85  math::XYZVector p = (inner.innerMomentum() + outer.outerMomentum());
86  GlobalVector v(p.x(), p.y(), p.z());
87  if (!useInnermostState_)
88  v *= -1;
89 
91  unsigned int nhits = hits.size();
92  ownHits.reserve(nhits);
93 
94  if (duplicateType == DuplicateTrackType::Disjoint) {
95 #if TRACK_SORT
96  if (!useInnermostState_)
97  std::reverse(hits.begin(), hits.end());
98  for (auto hit : hits)
99  ownHits.push_back(*hit);
100 #elif DET_SORT
101  // OLD METHOD, sometimes fails
102  std::sort(hits.begin(), hits.end(), MomentumSort(v, &*theGeometry));
103  for (auto hit : hits)
104  ownHits.push_back(*hit);
105 #else
106  sortByHitPosition(v, hits, ownHits);
107 #endif
108  } else if (duplicateType == DuplicateTrackType::Overlapping) {
109  sortByHitPosition(v, hits, ownHits);
110  }
111 
114  if (useInnermostState_) {
115  pdir = alongMomentum;
116  if ((inner.outerPosition() - inner.innerPosition()).Dot(inner.momentum()) >= 0) {
117  // use inner state
118  TrajectoryStateOnSurface originalTsosIn(
120  state = trajectoryStateTransform::persistentState(originalTsosIn, DetId(inner.innerDetId()));
121  } else {
122  // use outer state
123  TrajectoryStateOnSurface originalTsosOut(
125  state = trajectoryStateTransform::persistentState(originalTsosOut, DetId(inner.outerDetId()));
126  }
127  } else {
128  pdir = oppositeToMomentum;
129  if ((outer.outerPosition() - inner.innerPosition()).Dot(inner.momentum()) >= 0) {
130  // use outer state
131  TrajectoryStateOnSurface originalTsosOut(
133  state = trajectoryStateTransform::persistentState(originalTsosOut, DetId(outer.outerDetId()));
134  } else {
135  // use inner state
136  TrajectoryStateOnSurface originalTsosIn(
138  state = trajectoryStateTransform::persistentState(originalTsosIn, DetId(outer.innerDetId()));
139  }
140  }
142  TrackCandidate ret(ownHits, seed, state, (useInnermostState_ ? inner : outer).seedRef());
143  ret.setStopReason((uint8_t)(useInnermostState_ ? inner : outer).stopReason());
144  return ret;
145 }
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:35
#define DPRINT(x)
Definition: TrackMerger.cc:18
TrajectoryStateOnSurface outerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
ret
prodAgent to be discontinued
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
PropagationDirection
unsigned int layer(const DetId &id) const
void addSecondTrackHits(std::vector< const TrackingRecHit *> &hits, const reco::Track &outer) const
Definition: TrackMerger.cc:147
void push_back(D *&d)
Definition: OwnVector.h:326
void sortByHitPosition(const GlobalVector &v, const std::vector< const TrackingRecHit *> &hits, TrackCandidate::RecHitContainer &ownHits) const
Definition: TrackMerger.cc:188
#define PRINT
Definition: TrackMerger.cc:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
bool useInnermostState_
Definition: TrackMerger.h:31
Definition: DetId.h:17
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
edm::ESHandle< MagneticField > theMagField
Definition: TrackMerger.h:30
void reserve(size_t)
Definition: OwnVector.h:320
edm::ESHandle< TrackerGeometry > theGeometry
Definition: TrackMerger.h:29
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)

◆ sortByHitPosition()

void TrackMerger::sortByHitPosition ( const GlobalVector v,
const std::vector< const TrackingRecHit *> &  hits,
TrackCandidate::RecHitContainer ownHits 
) const
private

Definition at line 188 of file TrackMerger.cc.

References TransientTrackingRecHitBuilder::build(), hfClusterShapes_cfi::hits, mps_fire::i, nhits, edm::OwnVector< T, P >::push_back(), jetUpdater_cfi::sort, theBuilder, and findQualityFiles::v.

Referenced by merge().

190  {
191  // NEW sort, more accurate
192  unsigned int nhits = hits.size();
193  std::vector<TransientTrackingRecHit::RecHitPointer> ttrh(nhits);
194  for (unsigned int i = 0; i < nhits; ++i)
195  ttrh[i] = theBuilder->build(hits[i]);
196  std::sort(ttrh.begin(), ttrh.end(), GlobalMomentumSort(v));
197  for (const auto &hit : ttrh)
198  ownHits.push_back(*hit);
199 }
void push_back(D *&d)
Definition: OwnVector.h:326
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
edm::ESHandle< TransientTrackingRecHitBuilder > theBuilder
Definition: TrackMerger.h:34

Member Data Documentation

◆ builderToken_

Definition at line 38 of file TrackMerger.h.

Referenced by init().

◆ debug_

bool TrackMerger::debug_
private

Definition at line 32 of file TrackMerger.h.

Referenced by merge().

◆ geometryToken_

edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> TrackMerger::geometryToken_
private

Definition at line 36 of file TrackMerger.h.

Referenced by init().

◆ magFieldToken_

edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> TrackMerger::magFieldToken_
private

Definition at line 37 of file TrackMerger.h.

Referenced by init().

◆ theBuilder

edm::ESHandle<TransientTrackingRecHitBuilder> TrackMerger::theBuilder
private

Definition at line 34 of file TrackMerger.h.

Referenced by init(), and sortByHitPosition().

◆ theBuilderName

std::string TrackMerger::theBuilderName
private

Definition at line 33 of file TrackMerger.h.

◆ theGeometry

edm::ESHandle<TrackerGeometry> TrackMerger::theGeometry
private

Definition at line 29 of file TrackMerger.h.

Referenced by init(), and merge().

◆ theMagField

edm::ESHandle<MagneticField> TrackMerger::theMagField
private

Definition at line 30 of file TrackMerger.h.

Referenced by init(), and merge().

◆ theTrkTopo

edm::ESHandle<TrackerTopology> TrackMerger::theTrkTopo
private

Definition at line 35 of file TrackMerger.h.

Referenced by addSecondTrackHits(), init(), and merge().

◆ trackerTopoToken_

edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> TrackMerger::trackerTopoToken_
private

Definition at line 39 of file TrackMerger.h.

Referenced by init().

◆ useInnermostState_

bool TrackMerger::useInnermostState_
private

Definition at line 31 of file TrackMerger.h.

Referenced by merge().