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

31  :
32  useInnermostState_(iConfig.getParameter<bool>("useInnermostState")),
33  theBuilderName(iConfig.getParameter<std::string>("ttrhBuilderName"))
34 {
35 }
T getParameter(std::string const &) const
std::string theBuilderName
Definition: TrackMerger.h:27
bool useInnermostState_
Definition: TrackMerger.h:25
TrackMerger::~TrackMerger ( )

Definition at line 37 of file TrackMerger.cc.

38 {
39 }

Member Function Documentation

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

Definition at line 145 of file TrackMerger.cc.

References TrackingRecHit::all, TrackingRecHit::geographicalId(), hcalTTPDigis_cfi::id, TrackingRecHit::isValid(), TrackerTopology::layer(), PRINT, reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), TrackingRecHit::sharesInput(), DetId::subdetId(), and theTrkTopo.

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 << " detid: " << id() << std::endl;
155  size_t iHit = 0;
156  for ( auto hit2 : hits) {
157  ++iHit; if (iHit > nHitsFirstTrack) break;
158  DetId id2 = hit2->geographicalId();
159  if (id.subdetId() != id2.subdetId()) continue;
160  if (theTrkTopo->layer(id2) != lay) continue;
161  if (hit->sharesInput(hit2, TrackingRecHit::all)) {
162  PRINT << " discared as duplicate of other hit" << id() << std::endl;
163  shared = true; break;
164  }
165  if (hit2->isValid() && !valid) {
166  PRINT << " replacing old invalid hit on detid " << id2() << std::endl;
167  hit2 = hit; shared = true; break;
168  }
169  PRINT << " discared as additional hit on layer that already contains hit with detid " << id() << std::endl;
170  shared = true; break;
171  }
172  if (shared) continue;
173  hits.push_back(hit);
174  }
175 }
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:29
virtual bool sharesInput(const TrackingRecHit *other, SharedInputType what) const
#define PRINT
Definition: TrackMerger.cc:27
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
Definition: DetId.h:18
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:109
void TrackMerger::init ( const edm::EventSetup iSetup)

Definition at line 41 of file TrackMerger.cc.

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

42 {
46  iSetup.get<TrackerTopologyRcd>().get(theTrkTopo);
47 }
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:29
std::string theBuilderName
Definition: TrackMerger.h:27
const T & get() const
Definition: EventSetup.h:55
edm::ESHandle< TransientTrackingRecHitBuilder > theBuilder
Definition: TrackMerger.h:28
edm::ESHandle< MagneticField > theMagField
Definition: TrackMerger.h:24
edm::ESHandle< TrackerGeometry > theGeometry
Definition: TrackMerger.h:23
TrackCandidate TrackMerger::merge ( const reco::Track inner,
const reco::Track outer,
DuplicateTrackType  duplicateType 
) const

Definition at line 49 of file TrackMerger.cc.

References funct::abs(), addSecondTrackHits(), reco::TrackBase::algo(), alongMomentum, debug_, Disjoint, DPRINT, reco::TrackBase::eta(), TrackingRecHit::geographicalId(), hfClusterShapes_cfi::hits, hcalTTPDigis_cfi::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(), groupFilesInBlocks::reverse, SurveyInfoScenario_cff::seed, TrackCandidate::setStopReason(), sortByHitPosition(), DetId::subdetId(), theGeometry, theMagField, theTrkTopo, useInnermostState_, and findQualityFiles::v.

50 {
51  DPRINT("TrackMerger") << std::abs(inner.eta()) << " merging " << inner.algo() << '/' << outer.algo() << ' ' << inner.eta() << '/' << outer.eta()<< std::endl;
52 
53  std::vector<const TrackingRecHit *> hits;
54  hits.reserve(inner.recHitsSize() + outer.recHitsSize());
55  DPRINT("TrackMerger") << "Inner track hits: " << std::endl;
56  for (auto it = inner.recHitsBegin(), ed = inner.recHitsEnd(); it != ed; ++it) {
57  hits.push_back(&**it);
58  if (debug_) {
59  DetId id(hits.back()->geographicalId());
60  PRINT << " subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid " << hits.back()->isValid() << " detid: " << id() << std::endl;
61  }
62  }
63  DPRINT("TrackMerger") << "Outer track hits: " << std::endl;
64 
65  if(duplicateType == DuplicateTrackType::Disjoint) {
66 #if TRACK_SORT
67  DetId lastId(hits.back()->geographicalId());
68  int lastSubdet = lastId.subdetId();
69  unsigned int lastLayer = theTrkTopo->layer(lastId);
70  for (auto it = outer.recHitsBegin(), ed = outer.recHitsEnd(); it != ed; ++it) {
71  const TrackingRecHit *hit = &**it;
72  DetId id(hit->geographicalId());
73  int thisSubdet = id.subdetId();
74  if (thisSubdet > lastSubdet || (thisSubdet == lastSubdet && theTrkTopo->layer(id) > lastLayer)) {
75  hits.push_back(hit);
76  PRINT << " adding subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid " << hit->isValid() << " detid: " << id() << std::endl;
77  } else {
78  PRINT << " skipping subdet " << thisSubdet << " layer " << theTrkTopo->layer(id) << " valid " << hit->isValid() << " detid: " << id() << std::endl;
79  }
80  }
81 #else
82  addSecondTrackHits(hits, outer);
83 #endif
84  }
85  else if(duplicateType == DuplicateTrackType::Overlapping) {
86  addSecondTrackHits(hits, outer);
87  }
88 
89  math::XYZVector p = (inner.innerMomentum() + outer.outerMomentum());
90  GlobalVector v(p.x(), p.y(), p.z());
91  if (!useInnermostState_) v *= -1;
92 
94  unsigned int nhits = hits.size();
95  ownHits.reserve(nhits);
96 
97  if(duplicateType == DuplicateTrackType::Disjoint) {
98 #if TRACK_SORT
99  if (!useInnermostState_) std::reverse(hits.begin(), hits.end());
100  for(auto hit : hits) 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) ownHits.push_back(*hit);
105 #else
106  sortByHitPosition(v, hits, ownHits);
107 #endif
108  }
109  else if(duplicateType == DuplicateTrackType::Overlapping) {
110  sortByHitPosition(v, hits, ownHits);
111  }
112 
113  PTrajectoryStateOnDet state;
115  if (useInnermostState_) {
116  pdir = alongMomentum;
117  if ((inner.outerPosition()-inner.innerPosition()).Dot(inner.momentum()) >= 0) {
118  // use inner state
120  state = trajectoryStateTransform::persistentState( originalTsosIn, DetId(inner.innerDetId()) );
121  } else {
122  // use outer state
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
131  state = trajectoryStateTransform::persistentState( originalTsosOut, DetId(outer.outerDetId()) );
132  } else {
133  // use inner state
135  state = trajectoryStateTransform::persistentState( originalTsosIn, DetId(outer.innerDetId()) );
136  }
137 
138  }
140  TrackCandidate ret(ownHits, seed, state, (useInnermostState_ ? inner : outer).seedRef());
141  ret.setStopReason((uint8_t)(useInnermostState_ ? inner : outer).stopReason());
142  return ret;
143 }
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:29
#define DPRINT(x)
Definition: TrackMerger.cc:26
TrajectoryStateOnSurface outerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:119
void sortByHitPosition(const GlobalVector &v, const std::vector< const TrackingRecHit * > &hits, TrackCandidate::RecHitContainer &ownHits) const
Definition: TrackMerger.cc:177
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
PropagationDirection
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:675
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:65
void addSecondTrackHits(std::vector< const TrackingRecHit * > &hits, const reco::Track &outer) const
Definition: TrackMerger.cc:145
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:55
TrackAlgorithm algo() const
Definition: TrackBase.h:497
void push_back(D *&d)
Definition: OwnVector.h:290
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
#define PRINT
Definition: TrackMerger.cc:27
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:94
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:104
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
bool useInnermostState_
Definition: TrackMerger.h:25
Definition: DetId.h:18
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:70
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
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:60
DetId geographicalId() const
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:99
edm::ESHandle< MagneticField > theMagField
Definition: TrackMerger.h:24
void reserve(size_t)
Definition: OwnVector.h:284
edm::ESHandle< TrackerGeometry > theGeometry
Definition: TrackMerger.h:23
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:109
void TrackMerger::sortByHitPosition ( const GlobalVector v,
const std::vector< const TrackingRecHit * > &  hits,
TrackCandidate::RecHitContainer ownHits 
) const
private

Definition at line 177 of file TrackMerger.cc.

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

Referenced by merge().

179  {
180  // NEW sort, more accurate
181  unsigned int nhits = hits.size();
182  std::vector<TransientTrackingRecHit::RecHitPointer> ttrh(nhits);
183  for (unsigned int i = 0; i < nhits; ++i) ttrh[i] = theBuilder->build(hits[i]);
184  std::sort(ttrh.begin(), ttrh.end(), GlobalMomentumSort(v));
185  for(auto hit : ttrh) ownHits.push_back(*hit);
186 }
void push_back(D *&d)
Definition: OwnVector.h:290
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
edm::ESHandle< TransientTrackingRecHitBuilder > theBuilder
Definition: TrackMerger.h:28

Member Data Documentation

bool TrackMerger::debug_
private

Definition at line 26 of file TrackMerger.h.

Referenced by merge().

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

Definition at line 28 of file TrackMerger.h.

Referenced by init(), and sortByHitPosition().

std::string TrackMerger::theBuilderName
private

Definition at line 27 of file TrackMerger.h.

Referenced by init().

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

Definition at line 23 of file TrackMerger.h.

Referenced by init(), and merge().

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

Definition at line 24 of file TrackMerger.h.

Referenced by init(), and merge().

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

Definition at line 29 of file TrackMerger.h.

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

bool TrackMerger::useInnermostState_
private

Definition at line 25 of file TrackMerger.h.

Referenced by merge().