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 148 of file TrackMerger.cc.

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

Referenced by merge().

148  {
149  size_t nHitsFirstTrack = hits.size();
150  for (auto it = outer.recHitsBegin(), ed = outer.recHitsEnd(); it != ed; ++it) {
151  const TrackingRecHit *hit = &**it;
152  DetId id(hit->geographicalId());
153  const auto lay = theTrkTopo->layer(id);
154  bool shared = false;
155  bool valid = hit->isValid();
156  PRINT << " subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid " << valid
157  << " detid: " << id() << std::endl;
158  size_t iHit = 0;
159  for (auto hit2 : hits) {
160  ++iHit;
161  if (iHit > nHitsFirstTrack)
162  break;
163  DetId id2 = hit2->geographicalId();
164  if (id.subdetId() != id2.subdetId())
165  continue;
166  if (theTrkTopo->layer(id2) != lay)
167  continue;
168  if (hit->sharesInput(hit2, TrackingRecHit::all)) {
169  PRINT << " discared as duplicate of other hit" << id() << std::endl;
170  shared = true;
171  break;
172  }
173  if (hit2->isValid() && !valid) {
174  PRINT << " replacing old invalid hit on detid " << id2() << std::endl;
175  hit = hit2;
176  shared = true;
177  break;
178  }
179  PRINT << " discared as additional hit on layer that already contains hit with detid " << id() << std::endl;
180  shared = true;
181  break;
182  }
183  if (shared)
184  continue;
185  hits.push_back(hit);
186  }
187 }
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, EcalPhiSymFlatTableProducers_cfi::id, SurfaceOrientation::inner, trajectoryStateTransform::innerStateOnSurface(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, TrackerTopology::layer(), TrackingDataMCValidation_Standalone_cff::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(), suppress, 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  [[clang::suppress]]
54  DetId id(hits.back()->geographicalId());
55  PRINT << " subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid "
56  << hits.back()->isValid() << " detid: " << id() << std::endl;
57  }
58  }
59  DPRINT("TrackMerger") << "Outer track hits: " << std::endl;
60 
61  if (duplicateType == DuplicateTrackType::Disjoint) {
62 #if TRACK_SORT
63  DetId lastId(hits.back()->geographicalId());
64  int lastSubdet = lastId.subdetId();
65  unsigned int lastLayer = theTrkTopo->layer(lastId);
66  for (auto it = outer.recHitsBegin(), ed = outer.recHitsEnd(); it != ed; ++it) {
67  const TrackingRecHit *hit = &**it;
68  DetId id(hit->geographicalId());
69  int thisSubdet = id.subdetId();
70  if (thisSubdet > lastSubdet || (thisSubdet == lastSubdet && theTrkTopo->layer(id) > lastLayer)) {
71  hits.push_back(hit);
72  PRINT << " adding subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid "
73  << hit->isValid() << " detid: " << id() << std::endl;
74  } else {
75  PRINT << " skipping subdet " << thisSubdet << " layer " << theTrkTopo->layer(id) << " valid "
76  << hit->isValid() << " detid: " << id() << std::endl;
77  }
78  }
79 #else
81 #endif
82  } else if (duplicateType == DuplicateTrackType::Overlapping) {
84  }
85 
86  math::XYZVector p = (inner.innerMomentum() + outer.outerMomentum());
87  GlobalVector v(p.x(), p.y(), p.z());
88  if (!useInnermostState_)
89  v *= -1;
90 
92  unsigned int nhits = hits.size();
93  ownHits.reserve(nhits);
94 
95  if (duplicateType == DuplicateTrackType::Disjoint) {
96 #if TRACK_SORT
97  if (!useInnermostState_)
98  std::reverse(hits.begin(), hits.end());
99  for (auto hit : hits)
100  ownHits.push_back(*hit);
101 #elif DET_SORT
102  // OLD METHOD, sometimes fails
103  std::sort(hits.begin(), hits.end(), MomentumSort(v, &*theGeometry));
104  for (auto hit : hits)
105  ownHits.push_back(*hit);
106 #else
107  sortByHitPosition(v, hits, ownHits);
108 #endif
109  } else if (duplicateType == DuplicateTrackType::Overlapping) {
110  sortByHitPosition(v, hits, ownHits);
111  }
112 
115  if (useInnermostState_) {
116  pdir = alongMomentum;
117  if ((inner.outerPosition() - inner.innerPosition()).Dot(inner.momentum()) >= 0) {
118  // use inner state
119  TrajectoryStateOnSurface originalTsosIn(
121  state = trajectoryStateTransform::persistentState(originalTsosIn, DetId(inner.innerDetId()));
122  } else {
123  // use outer state
124  TrajectoryStateOnSurface originalTsosOut(
126  state = trajectoryStateTransform::persistentState(originalTsosOut, DetId(inner.outerDetId()));
127  }
128  } else {
129  pdir = oppositeToMomentum;
130  if ((outer.outerPosition() - inner.innerPosition()).Dot(inner.momentum()) >= 0) {
131  // use outer state
132  TrajectoryStateOnSurface originalTsosOut(
134  state = trajectoryStateTransform::persistentState(originalTsosOut, DetId(outer.outerDetId()));
135  } else {
136  // use inner state
137  TrajectoryStateOnSurface originalTsosIn(
139  state = trajectoryStateTransform::persistentState(originalTsosIn, DetId(outer.innerDetId()));
140  }
141  }
143  TrackCandidate ret(ownHits, seed, state, (useInnermostState_ ? inner : outer).seedRef());
144  ret.setStopReason((uint8_t)(useInnermostState_ ? inner : outer).stopReason());
145  return ret;
146 }
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:148
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:189
#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 189 of file TrackMerger.cc.

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

Referenced by merge().

191  {
192  // NEW sort, more accurate
193  unsigned int nhits = hits.size();
194  std::vector<TransientTrackingRecHit::RecHitPointer> ttrh(nhits);
195  for (unsigned int i = 0; i < nhits; ++i)
196  ttrh[i] = theBuilder->build(hits[i]);
197  std::sort(ttrh.begin(), ttrh.end(), GlobalMomentumSort(v));
198  for (const auto &hit : ttrh)
199  ownHits.push_back(*hit);
200 }
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().