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.

◆ ~TrackMerger()

TrackMerger::~TrackMerger ( )

Definition at line 31 of file TrackMerger.cc.

31 {}

Member Function Documentation

◆ addSecondTrackHits()

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

Definition at line 146 of file TrackMerger.cc.

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

References TrackingRecHit::all, hfClusterShapes_cfi::hits, triggerObjects_cff::id, globals_cff::id2, TrackerTopology::layer(), SurfaceOrientation::outer, PRINT, theTrkTopo, and RunInfoPI::valid.

Referenced by merge().

◆ init()

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

◆ merge()

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

Definition at line 40 of file TrackMerger.cc.

42  {
43  DPRINT("TrackMerger") << std::abs(inner.eta()) << " merging " << inner.algo() << '/' << outer.algo() << ' '
44  << inner.eta() << '/' << outer.eta() << std::endl;
45 
46  std::vector<const TrackingRecHit *> hits;
47  hits.reserve(inner.recHitsSize() + outer.recHitsSize());
48  DPRINT("TrackMerger") << "Inner track hits: " << std::endl;
49  for (auto it = inner.recHitsBegin(), ed = inner.recHitsEnd(); it != ed; ++it) {
50  hits.push_back(&**it);
51  if (debug_) {
52  DetId id(hits.back()->geographicalId());
53  PRINT << " subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid "
54  << hits.back()->isValid() << " detid: " << id() << std::endl;
55  }
56  }
57  DPRINT("TrackMerger") << "Outer track hits: " << std::endl;
58 
59  if (duplicateType == DuplicateTrackType::Disjoint) {
60 #if TRACK_SORT
61  DetId lastId(hits.back()->geographicalId());
62  int lastSubdet = lastId.subdetId();
63  unsigned int lastLayer = theTrkTopo->layer(lastId);
64  for (auto it = outer.recHitsBegin(), ed = outer.recHitsEnd(); it != ed; ++it) {
65  const TrackingRecHit *hit = &**it;
66  DetId id(hit->geographicalId());
67  int thisSubdet = id.subdetId();
68  if (thisSubdet > lastSubdet || (thisSubdet == lastSubdet && theTrkTopo->layer(id) > lastLayer)) {
69  hits.push_back(hit);
70  PRINT << " adding subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid "
71  << hit->isValid() << " detid: " << id() << std::endl;
72  } else {
73  PRINT << " skipping subdet " << thisSubdet << " layer " << theTrkTopo->layer(id) << " valid "
74  << hit->isValid() << " detid: " << id() << std::endl;
75  }
76  }
77 #else
79 #endif
80  } else if (duplicateType == DuplicateTrackType::Overlapping) {
82  }
83 
84  math::XYZVector p = (inner.innerMomentum() + outer.outerMomentum());
85  GlobalVector v(p.x(), p.y(), p.z());
86  if (!useInnermostState_)
87  v *= -1;
88 
90  unsigned int nhits = hits.size();
91  ownHits.reserve(nhits);
92 
93  if (duplicateType == DuplicateTrackType::Disjoint) {
94 #if TRACK_SORT
95  if (!useInnermostState_)
96  std::reverse(hits.begin(), hits.end());
97  for (auto hit : hits)
98  ownHits.push_back(*hit);
99 #elif DET_SORT
100  // OLD METHOD, sometimes fails
101  std::sort(hits.begin(), hits.end(), MomentumSort(v, &*theGeometry));
102  for (auto hit : hits)
103  ownHits.push_back(*hit);
104 #else
105  sortByHitPosition(v, hits, ownHits);
106 #endif
107  } else if (duplicateType == DuplicateTrackType::Overlapping) {
108  sortByHitPosition(v, hits, ownHits);
109  }
110 
113  if (useInnermostState_) {
114  pdir = alongMomentum;
115  if ((inner.outerPosition() - inner.innerPosition()).Dot(inner.momentum()) >= 0) {
116  // use inner state
117  TrajectoryStateOnSurface originalTsosIn(
119  state = trajectoryStateTransform::persistentState(originalTsosIn, DetId(inner.innerDetId()));
120  } else {
121  // use outer state
122  TrajectoryStateOnSurface originalTsosOut(
124  state = trajectoryStateTransform::persistentState(originalTsosOut, DetId(inner.outerDetId()));
125  }
126  } else {
127  pdir = oppositeToMomentum;
128  if ((outer.outerPosition() - inner.innerPosition()).Dot(inner.momentum()) >= 0) {
129  // use outer state
130  TrajectoryStateOnSurface originalTsosOut(
132  state = trajectoryStateTransform::persistentState(originalTsosOut, DetId(outer.outerDetId()));
133  } else {
134  // use inner state
135  TrajectoryStateOnSurface originalTsosIn(
137  state = trajectoryStateTransform::persistentState(originalTsosIn, DetId(outer.innerDetId()));
138  }
139  }
141  TrackCandidate ret(ownHits, seed, state, (useInnermostState_ ? inner : outer).seedRef());
142  ret.setStopReason((uint8_t)(useInnermostState_ ? inner : outer).stopReason());
143  return ret;
144 }

References funct::abs(), addSecondTrackHits(), alongMomentum, debug_, Disjoint, DPRINT, hfClusterShapes_cfi::hits, triggerObjects_cff::id, SurfaceOrientation::inner, trajectoryStateTransform::innerStateOnSurface(), 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, sortByHitPosition(), DetId::subdetId(), theGeometry, theMagField, theTrkTopo, useInnermostState_, and findQualityFiles::v.

◆ sortByHitPosition()

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

Definition at line 187 of file TrackMerger.cc.

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

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

Referenced by merge().

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().

Vector3DBase
Definition: Vector3DBase.h:8
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
TrackMerger::trackerTopoToken_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopoToken_
Definition: TrackMerger.h:39
PRINT
#define PRINT
Definition: TrackMerger.cc:19
mps_fire.i
i
Definition: mps_fire.py:428
edm::ESInputTag
Definition: ESInputTag.h:87
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
TrackMerger::theMagField
edm::ESHandle< MagneticField > theMagField
Definition: TrackMerger.h:30
TrackerTopology
Definition: TrackerTopology.h:16
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
trajectoryStateTransform::persistentState
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
Definition: TrajectoryStateTransform.cc:14
TrackMerger::theBuilderName
std::string theBuilderName
Definition: TrackMerger.h:33
TransientRecHitRecord
Definition: TransientRecHitRecord.h:14
oppositeToMomentum
Definition: PropagationDirection.h:4
TrackMerger::addSecondTrackHits
void addSecondTrackHits(std::vector< const TrackingRecHit * > &hits, const reco::Track &outer) const
Definition: TrackMerger.cc:146
TrackMerger::builderToken_
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > builderToken_
Definition: TrackMerger.h:38
TrackerTopology::layer
unsigned int layer(const DetId &id) const
Definition: TrackerTopology.cc:47
findQualityFiles.v
v
Definition: findQualityFiles.py:179
TransientTrackingRecHitBuilder::build
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
groupFilesInBlocks.reverse
reverse
Definition: groupFilesInBlocks.py:131
trajectoryStateTransform::outerStateOnSurface
TrajectoryStateOnSurface outerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
Definition: TrajectoryStateTransform.cc:118
fileCollector.seed
seed
Definition: fileCollector.py:127
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
DetId
Definition: DetId.h:17
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
TrackMerger::debug_
bool debug_
Definition: TrackMerger.h:32
SurfaceOrientation::inner
Definition: Surface.h:19
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
TrackMerger::useInnermostState_
bool useInnermostState_
Definition: TrackMerger.h:31
nhits
Definition: HIMultiTrackSelector.h:42
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::OwnVector::reserve
void reserve(size_t)
Definition: OwnVector.h:320
TrackMerger::magFieldToken_
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
Definition: TrackMerger.h:37
TrackingRecHit::all
Definition: TrackingRecHit.h:59
TrackCandidate
Definition: TrackCandidate.h:24
DPRINT
#define DPRINT(x)
Definition: TrackMerger.cc:18
TrackMerger::sortByHitPosition
void sortByHitPosition(const GlobalVector &v, const std::vector< const TrackingRecHit * > &hits, TrackCandidate::RecHitContainer &ownHits) const
Definition: TrackMerger.cc:187
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:148
cc
TrackMerger::geometryToken_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geometryToken_
Definition: TrackMerger.h:36
TrackingRecHit
Definition: TrackingRecHit.h:21
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
DuplicateTrackType::Overlapping
TrackMerger::theBuilder
edm::ESHandle< TransientTrackingRecHitBuilder > theBuilder
Definition: TrackMerger.h:34
PropagationDirection
PropagationDirection
Definition: PropagationDirection.h:4
TrackMerger::theGeometry
edm::ESHandle< TrackerGeometry > theGeometry
Definition: TrackMerger.h:29
TrajectorySeed
Definition: TrajectorySeed.h:18
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::OwnVector::push_back
void push_back(D *&d)
Definition: OwnVector.h:326
DuplicateTrackType::Disjoint
TrackMerger::theTrkTopo
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:35
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
RunInfoPI::valid
Definition: RunInfoPayloadInspectoHelper.h:16
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
PTrajectoryStateOnDet
Definition: PTrajectoryStateOnDet.h:10
globals_cff.id2
id2
Definition: globals_cff.py:34
SurfaceOrientation::outer
Definition: Surface.h:19
trajectoryStateTransform::innerStateOnSurface
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
Definition: TrajectoryStateTransform.cc:110
MagneticField
Definition: MagneticField.h:19
TransientTrackingRecHitBuilder
Definition: TransientTrackingRecHitBuilder.h:6
alongMomentum
Definition: PropagationDirection.h:4
hit
Definition: SiStripHitEffFromCalibTree.cc:88
edm::OwnVector< TrackingRecHit >
TrackerGeometry
Definition: TrackerGeometry.h:14