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

20  :
21  useInnermostState_(iConfig.getParameter<bool>("useInnermostState")),
22  debug_(iConfig.getUntrackedParameter<bool>("debug",false)),
23  theBuilderName(iConfig.getParameter<std::string>("ttrhBuilderName"))
24 {
25 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::string theBuilderName
Definition: TrackMerger.h:25
bool useInnermostState_
Definition: TrackMerger.h:23
TrackMerger::~TrackMerger ( )

Definition at line 27 of file TrackMerger.cc.

28 {
29 }

Member Function Documentation

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

Definition at line 31 of file TrackMerger.cc.

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

Referenced by DuplicateTrackMerger::produce().

32 {
36  iSetup.get<TrackerTopologyRcd>().get(theTrkTopo);
37 }
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:27
std::string theBuilderName
Definition: TrackMerger.h:25
const T & get() const
Definition: EventSetup.h:55
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 39 of file TrackMerger.cc.

References TrackingRecHit::all, alongMomentum, gather_cfg::cout, debug_, 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(), edm::OwnVector< T, P >::push_back(), reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), reco::Track::recHitsSize(), edm::OwnVector< T, P >::reserve(), fileCollector::seed, TrackingRecHit::sharesInput(), python.multivaluedict::sort(), DetId::subdetId(), theBuilder, theGeometry, theMagField, theTrkTopo, useInnermostState_, and findQualityFiles::v.

Referenced by DuplicateTrackMerger::produce().

40 {
41  std::vector<const TrackingRecHit *> hits;
42  hits.reserve(inner.recHitsSize() + outer.recHitsSize());
43  if (debug_) std::cout << "Inner track hits: " << std::endl;
44  for (trackingRecHit_iterator it = inner.recHitsBegin(), ed = inner.recHitsEnd(); it != ed; ++it) {
45  hits.push_back(&**it);
46  if (debug_) {
47  DetId id(hits.back()->geographicalId());
48  std::cout << " subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid " << hits.back()->isValid() << " detid: " << id() << std::endl;
49  }
50  }
51  if (debug_) std::cout << "Outer track hits: " << std::endl;
52 
53 #if TRACK_SORT
54  DetId lastId(hits.back()->geographicalId());
55  int lastSubdet = lastId.subdetId();
56  unsigned int lastLayer = theTrkTopo->layer(lastId);
57  for (trackingRecHit_iterator it = outer.recHitsBegin(), ed = outer.recHitsEnd(); it != ed; ++it) {
58  const TrackingRecHit *hit = &**it;
59  DetId id(hit->geographicalId());
60  int thisSubdet = id.subdetId();
61  if (thisSubdet > lastSubdet || (thisSubdet == lastSubdet && theTrkTopo->layer(id) > lastLayer)) {
62  hits.push_back(hit);
63  if (debug_) std::cout << " adding subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid " << hit->isValid() << " detid: " << id() << std::endl;
64  } else {
65  if (debug_) std::cout << " skipping subdet " << thisSubdet << " layer " << theTrkTopo->layer(id) << " valid " << hit->isValid() << " detid: " << id() << std::endl;
66  }
67  }
68 #else
69  size_t nHitsFirstTrack = hits.size();
70  for (trackingRecHit_iterator it = outer.recHitsBegin(), ed = outer.recHitsEnd(); it != ed; ++it) {
71  const TrackingRecHit *hit = &**it;
72  DetId id(hit->geographicalId());
73  int lay = theTrkTopo->layer(id);
74  bool shared = false;
75  bool valid = hit->isValid();
76  if (debug_) std::cout << " subdet " << id.subdetId() << " layer " << theTrkTopo->layer(id) << " valid " << valid << " detid: " << id() << std::endl;
77  size_t iHit = 0;
78  foreach(const TrackingRecHit *& hit2, hits) {
79  ++iHit; if (iHit > nHitsFirstTrack) break;
80  DetId id2 = hit2->geographicalId();
81  if (id.subdetId() != id2.subdetId()) continue;
82  if (theTrkTopo->layer(id2) != lay) continue;
83  if (hit->sharesInput(hit2, TrackingRecHit::all)) {
84  if (debug_) std::cout << " discared as duplicate of other hit" << id() << std::endl;
85  shared = true; break;
86  }
87  if (hit2->isValid() && !valid) {
88  if (debug_) std::cout << " replacing old invalid hit on detid " << id2() << std::endl;
89  hit2 = hit; shared = true; break;
90  }
91  if (debug_) std::cout << " discared as additional hit on layer that already contains hit with detid " << id() << std::endl;
92  shared = true; break;
93  }
94  if (shared) continue;
95  hits.push_back(hit);
96  }
97 #endif
98 
99  math::XYZVector p = (inner.innerMomentum() + outer.outerMomentum());
100  GlobalVector v(p.x(), p.y(), p.z());
101  if (!useInnermostState_) v *= -1;
102 
104  unsigned int nhits = hits.size();
105  ownHits.reserve(nhits);
106 
107 #if TRACK_SORT
108  if (!useInnermostState_) std::reverse(hits.begin(), hits.end());
109  foreach(const TrackingRecHit * hit, hits) {
110  ownHits.push_back(*hit);
111  }
112 #elif DET_SORT
113  // OLD METHOD, sometimes fails
114  std::sort(hits.begin(), hits.end(), MomentumSort(v, &*theGeometry));
115 
116  foreach(const TrackingRecHit * hit, hits) {
117  ownHits.push_back(*hit);
118  }
119 #else
120  // NEW sort, more accurate
121  std::vector<TransientTrackingRecHit::RecHitPointer> ttrh(nhits);
122  for (unsigned int i = 0; i < nhits; ++i) ttrh[i] = theBuilder->build(hits[i]);
123  std::sort(ttrh.begin(), ttrh.end(), GlobalMomentumSort(v));
124 
125  foreach(const TransientTrackingRecHit::RecHitPointer & hit, ttrh) {
126  ownHits.push_back(*hit->hit());
127  }
128 #endif
129 
130  PTrajectoryStateOnDet state;
132  if (useInnermostState_) {
133  pdir = alongMomentum;
134  if ((inner.outerPosition()-inner.innerPosition()).Dot(inner.momentum()) >= 0) {
135  // use inner state
137  state = trajectoryStateTransform::persistentState( originalTsosIn, DetId(inner.innerDetId()) );
138  } else {
139  // use outer state
141  state = trajectoryStateTransform::persistentState( originalTsosOut, DetId(inner.outerDetId()) );
142  }
143  } else {
144  pdir = oppositeToMomentum;
145  if ((outer.outerPosition()-inner.innerPosition()).Dot(inner.momentum()) >= 0) {
146  // use outer state
148  state = trajectoryStateTransform::persistentState( originalTsosOut, DetId(outer.outerDetId()) );
149  } else {
150  // use inner state
152  state = trajectoryStateTransform::persistentState( originalTsosIn, DetId(outer.innerDetId()) );
153  }
154 
155  }
157  return TrackCandidate(ownHits, seed, state, (useInnermostState_ ? inner : outer).seedRef());
158 }
edm::ESHandle< TrackerTopology > theTrkTopo
Definition: TrackMerger.h:27
int i
Definition: DBlmapReader.cc:9
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:628
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
void push_back(D *&d)
Definition: OwnVector.h:280
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:94
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
std::shared_ptr< TrackingRecHit const > RecHitPointer
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
tuple cout
Definition: gather_cfg.py:121
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:274
edm::ESHandle< TrackerGeometry > theGeometry
Definition: TrackMerger.h:21
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
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().