CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public 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) const
 
 TrackMerger (const edm::ParameterSet &iConfig)
 
 ~TrackMerger ()
 

Private Attributes

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

Detailed Description

Definition at line 12 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:25
bool useInnermostState_
Definition: TrackMerger.h:23
TrackMerger::~TrackMerger ( )

Definition at line 37 of file TrackMerger.cc.

38 {
39 }

Member Function Documentation

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:27
std::string theBuilderName
Definition: TrackMerger.h:25
const T & get() const
Definition: EventSetup.h:56
edm::ESHandle< TransientTrackingRecHitBuilder > theBuilder
Definition: TrackMerger.h:26
edm::ESHandle< MagneticField > theMagField
Definition: TrackMerger.h:22
edm::ESHandle< TrackerGeometry > theGeometry
Definition: TrackMerger.h:21
TrackCandidate TrackMerger::merge ( const reco::Track inner,
const reco::Track outer 
) const

Definition at line 49 of file TrackMerger.cc.

References funct::abs(), reco::TrackBase::algo(), TrackingRecHit::all, alongMomentum, debug_, DPRINT, reco::TrackBase::eta(), TrackingRecHit::geographicalId(), i, reco::Track::innerDetId(), reco::Track::innerMomentum(), reco::Track::innerPosition(), trajectoryStateTransform::innerStateOnSurface(), edm::ESHandleBase::isValid(), TrackingRecHit::isValid(), reco::TrackBase::momentum(), nhits, oppositeToMomentum, reco::Track::outerDetId(), reco::Track::outerMomentum(), reco::Track::outerPosition(), trajectoryStateTransform::outerStateOnSurface(), 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, fileCollector::seed, TrackCandidate::setStopReason(), TrackingRecHit::sharesInput(), DetId::subdetId(), theBuilder, 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 TRACK_SORT
66  DetId lastId(hits.back()->geographicalId());
67  int lastSubdet = lastId.subdetId();
68  unsigned int lastLayer = theTrkTopo->layer(lastId);
69  for (auto it = outer.recHitsBegin(), ed = outer.recHitsEnd(); it != ed; ++it) {
70  const TrackingRecHit *hit = &**it;
71  DetId id(hit->geographicalId());
72  int thisSubdet = id.subdetId();
73  if (thisSubdet > lastSubdet || (thisSubdet == lastSubdet && theTrkTopo->layer(id) > lastLayer)) {
74  hits.push_back(hit);
75  PRINT << " adding subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid " << hit->isValid() << " detid: " << id() << std::endl;
76  } else {
77  PRINT << " skipping subdet " << thisSubdet << " layer " << theTrkTopo->layer(id) << " valid " << hit->isValid() << " detid: " << id() << std::endl;
78  }
79  }
80 #else
81  size_t nHitsFirstTrack = hits.size();
82  for (auto it = outer.recHitsBegin(), ed = outer.recHitsEnd(); it != ed; ++it) {
83  const TrackingRecHit *hit = &**it;
84  DetId id(hit->geographicalId());
85  int lay = theTrkTopo->layer(id);
86  bool shared = false;
87  bool valid = hit->isValid();
88  PRINT << " subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid " << valid << " detid: " << id() << std::endl;
89  size_t iHit = 0;
90  for ( auto hit2 : hits) {
91  ++iHit; if (iHit > nHitsFirstTrack) break;
92  DetId id2 = hit2->geographicalId();
93  if (id.subdetId() != id2.subdetId()) continue;
94  if (theTrkTopo->layer(id2) != lay) continue;
95  if (hit->sharesInput(hit2, TrackingRecHit::all)) {
96  PRINT << " discared as duplicate of other hit" << id() << std::endl;
97  shared = true; break;
98  }
99  if (hit2->isValid() && !valid) {
100  PRINT << " replacing old invalid hit on detid " << id2() << std::endl;
101  hit2 = hit; shared = true; break;
102  }
103  PRINT << " discared as additional hit on layer that already contains hit with detid " << id() << std::endl;
104  shared = true; break;
105  }
106  if (shared) continue;
107  hits.push_back(hit);
108  }
109 #endif
110 
111  math::XYZVector p = (inner.innerMomentum() + outer.outerMomentum());
112  GlobalVector v(p.x(), p.y(), p.z());
113  if (!useInnermostState_) v *= -1;
114 
116  unsigned int nhits = hits.size();
117  ownHits.reserve(nhits);
118 
119 #if TRACK_SORT
120  if (!useInnermostState_) std::reverse(hits.begin(), hits.end());
121  for(auto hit : hits) ownHits.push_back(*hit);
122 #elif DET_SORT
123  // OLD METHOD, sometimes fails
124  std::sort(hits.begin(), hits.end(), MomentumSort(v, &*theGeometry));
125  for(auto hit : hits) ownHits.push_back(*hit);
126 #else
127  // NEW sort, more accurate
128  std::vector<TransientTrackingRecHit::RecHitPointer> ttrh(nhits);
129  for (unsigned int i = 0; i < nhits; ++i) ttrh[i] = theBuilder->build(hits[i]);
130  std::sort(ttrh.begin(), ttrh.end(), GlobalMomentumSort(v));
131  for(auto hit : ttrh) ownHits.push_back(*hit);
132 #endif
133 
134  PTrajectoryStateOnDet state;
136  if (useInnermostState_) {
137  pdir = alongMomentum;
138  if ((inner.outerPosition()-inner.innerPosition()).Dot(inner.momentum()) >= 0) {
139  // use inner state
141  state = trajectoryStateTransform::persistentState( originalTsosIn, DetId(inner.innerDetId()) );
142  } else {
143  // use outer state
145  state = trajectoryStateTransform::persistentState( originalTsosOut, DetId(inner.outerDetId()) );
146  }
147  } else {
148  pdir = oppositeToMomentum;
149  if ((outer.outerPosition()-inner.innerPosition()).Dot(inner.momentum()) >= 0) {
150  // use outer state
152  state = trajectoryStateTransform::persistentState( originalTsosOut, DetId(outer.outerDetId()) );
153  } else {
154  // use inner state
156  state = trajectoryStateTransform::persistentState( originalTsosIn, DetId(outer.innerDetId()) );
157  }
158 
159  }
161  TrackCandidate ret(ownHits, seed, state, (useInnermostState_ ? inner : outer).seedRef());
162  ret.setStopReason((uint8_t)(useInnermostState_ ? inner : outer).stopReason());
163  return ret;
164 }
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:27
int i
Definition: DBlmapReader.cc:9
tuple ret
prodAgent to be discontinued
#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
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
virtual bool sharesInput(const TrackingRecHit *other, SharedInputType what) const
PropagationDirection
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:670
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:65
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:55
TrackAlgorithm algo() const
Definition: TrackBase.h:492
void push_back(D *&d)
Definition: OwnVector.h:290
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:646
#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:23
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
edm::ESHandle< TransientTrackingRecHitBuilder > theBuilder
Definition: TrackMerger.h:26
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:60
DetId geographicalId() const
bool isValid() const
Definition: ESHandle.h:47
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:22
void reserve(size_t)
Definition: OwnVector.h:284
edm::ESHandle< TrackerGeometry > theGeometry
Definition: TrackMerger.h:21
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

Member Data Documentation

bool TrackMerger::debug_
private

Definition at line 24 of file TrackMerger.h.

Referenced by merge().

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

Definition at line 26 of file TrackMerger.h.

Referenced by init(), and merge().

std::string TrackMerger::theBuilderName
private

Definition at line 25 of file TrackMerger.h.

Referenced by init().

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

Definition at line 21 of file TrackMerger.h.

Referenced by init(), and merge().

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

Definition at line 22 of file TrackMerger.h.

Referenced by init(), and merge().

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

Definition at line 27 of file TrackMerger.h.

Referenced by init(), and merge().

bool TrackMerger::useInnermostState_
private

Definition at line 23 of file TrackMerger.h.

Referenced by merge().