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)
 
 ~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

bool debug_
 
edm::ESHandle< TransientTrackingRecHitBuildertheBuilder
 
std::string theBuilderName
 
edm::ESHandle< TrackerGeometrytheGeometry
 
edm::ESHandle< MagneticFieldtheMagField
 
edm::ESHandle< TrackerTopologytheTrkTopo
 
bool useInnermostState_
 

Detailed Description

Definition at line 14 of file TrackMerger.h.

Constructor & Destructor Documentation

TrackMerger::TrackMerger ( const edm::ParameterSet iConfig)

Definition at line 27 of file TrackMerger.cc.

28  : useInnermostState_(iConfig.getParameter<bool>("useInnermostState")),
29  theBuilderName(iConfig.getParameter<std::string>("ttrhBuilderName")) {}
T getParameter(std::string const &) const
std::string theBuilderName
Definition: TrackMerger.h:28
bool useInnermostState_
Definition: TrackMerger.h:26
TrackMerger::~TrackMerger ( )

Definition at line 31 of file TrackMerger.cc.

31 {}

Member Function Documentation

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

Definition at line 146 of file TrackMerger.cc.

References TrackingRecHit::all, TrackingRecHit::geographicalId(), triggerObjects_cff::id, globals_cff::id2, TrackingRecHit::isValid(), TrackerTopology::layer(), PRINT, reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), TrackingRecHit::sharesInput(), DetId::subdetId(), theTrkTopo, and validateGeometry_cfg::valid.

Referenced by merge().

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 }
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:30
virtual bool sharesInput(const TrackingRecHit *other, SharedInputType what) const
#define PRINT
Definition: TrackMerger.cc:24
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
Definition: DetId.h:17
bool isValid() const
unsigned int layer(const DetId &id) const
DetId geographicalId() const
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:91
void TrackMerger::init ( const edm::EventSetup iSetup)

Definition at line 33 of file TrackMerger.cc.

References edm::EventSetup::get(), theBuilder, theBuilderName, theGeometry, theMagField, and theTrkTopo.

33  {
37  iSetup.get<TrackerTopologyRcd>().get(theTrkTopo);
38 }
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:30
std::string theBuilderName
Definition: TrackMerger.h:28
edm::ESHandle< TransientTrackingRecHitBuilder > theBuilder
Definition: TrackMerger.h:29
T get() const
Definition: EventSetup.h:73
edm::ESHandle< MagneticField > theMagField
Definition: TrackMerger.h:25
edm::ESHandle< TrackerGeometry > theGeometry
Definition: TrackMerger.h:24
TrackCandidate TrackMerger::merge ( const reco::Track inner,
const reco::Track outer,
DuplicateTrackType  duplicateType 
) const

Definition at line 40 of file TrackMerger.cc.

References funct::abs(), addSecondTrackHits(), reco::TrackBase::algo(), alongMomentum, debug_, Disjoint, DPRINT, reco::TrackBase::eta(), TrackingRecHit::geographicalId(), hfClusterShapes_cfi::hits, triggerObjects_cff::id, reco::Track::innerDetId(), reco::Track::innerMomentum(), reco::Track::innerPosition(), trajectoryStateTransform::innerStateOnSurface(), TrackingRecHit::isValid(), TrackerTopology::layer(), reco::TrackBase::momentum(), nhits, oppositeToMomentum, reco::Track::outerDetId(), reco::Track::outerMomentum(), reco::Track::outerPosition(), trajectoryStateTransform::outerStateOnSurface(), Overlapping, AlCaHLTBitMon_ParallelJobs::p, trajectoryStateTransform::persistentState(), PRINT, edm::OwnVector< T, P >::push_back(), reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), reco::Track::recHitsSize(), edm::OwnVector< T, P >::reserve(), runTheMatrix::ret, groupFilesInBlocks::reverse, SurveyInfoScenario_cff::seed, TrackCandidate::setStopReason(), sortByHitPosition(), DetId::subdetId(), theGeometry, theMagField, theTrkTopo, useInnermostState_, and findQualityFiles::v.

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
78  addSecondTrackHits(hits, outer);
79 #endif
80  } else if (duplicateType == DuplicateTrackType::Overlapping) {
81  addSecondTrackHits(hits, outer);
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 
111  PTrajectoryStateOnDet state;
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 }
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:30
#define DPRINT(x)
Definition: TrackMerger.cc:23
TrajectoryStateOnSurface outerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
ret
prodAgent to be discontinued
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:97
void sortByHitPosition(const GlobalVector &v, const std::vector< const TrackingRecHit * > &hits, TrackCandidate::RecHitContainer &ownHits) const
Definition: TrackMerger.cc:187
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
PropagationDirection
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:629
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:62
void addSecondTrackHits(std::vector< const TrackingRecHit * > &hits, const reco::Track &outer) const
Definition: TrackMerger.cc:146
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:56
TrackAlgorithm algo() const
Definition: TrackBase.h:526
void push_back(D *&d)
Definition: OwnVector.h:326
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:617
#define PRINT
Definition: TrackMerger.cc:24
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:79
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
bool useInnermostState_
Definition: TrackMerger.h:26
Definition: DetId.h:17
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:65
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
bool isValid() const
unsigned int layer(const DetId &id) const
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:59
DetId geographicalId() const
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:82
edm::ESHandle< MagneticField > theMagField
Definition: TrackMerger.h:25
void reserve(size_t)
Definition: OwnVector.h:320
edm::ESHandle< TrackerGeometry > theGeometry
Definition: TrackMerger.h:24
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:91
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.

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

Referenced by merge().

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 (auto hit : ttrh)
197  ownHits.push_back(*hit);
198 }
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:29

Member Data Documentation

bool TrackMerger::debug_
private

Definition at line 27 of file TrackMerger.h.

Referenced by merge().

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

Definition at line 29 of file TrackMerger.h.

Referenced by init(), and sortByHitPosition().

std::string TrackMerger::theBuilderName
private

Definition at line 28 of file TrackMerger.h.

Referenced by init().

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

Definition at line 24 of file TrackMerger.h.

Referenced by init(), and merge().

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

Definition at line 25 of file TrackMerger.h.

Referenced by init(), and merge().

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

Definition at line 30 of file TrackMerger.h.

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

bool TrackMerger::useInnermostState_
private

Definition at line 26 of file TrackMerger.h.

Referenced by merge().