CMS 3D CMS Logo

Traj2TrackHits.h
Go to the documentation of this file.
1 #ifndef Traj2TrackHits_H
2 #define Traj2TrackHits_H
3 
6 
10 
15 
17 private:
19  bool keepOrder = false; // FIXME move to enum
20  bool removeNoDet = true; // true == as in conversion from TTRH to TRH
21 public:
22  using TrajParams = std::vector<LocalTrajectoryParameters>;
23  using Chi2sFive = std::vector<unsigned char>;
24 
25  static unsigned char toChi2x5(float chi2) {
26  float tc = std::round(5.f * chi2);
27  return std::min(tc, 255.f);
28  }
29 
30  // default for final reco::Track
32 
33  Traj2TrackHits(const TransientTrackingRecHitBuilder *builder, bool ikeepOrder, bool noNoDet = true)
34  : theCPE(static_cast<TkTransientTrackingRecHitBuilder const *>(builder)->stripClusterParameterEstimator()),
35  keepOrder(ikeepOrder),
36  removeNoDet(noNoDet) {}
37 
38  void operator()(Trajectory const &traj, TrackingRecHitCollection &hits, bool splitting) const {
39  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
40  bool along = traj.direction() == alongMomentum;
41  auto const &meas = traj.measurements();
42  hits.reserve(splitting ? 2 * meas.size() : meas.size());
43  if (!splitting) {
44  if (keepOrder | along)
45  copy(meas.begin(), meas.end(), hits);
46  else
47  copy(meas.rbegin(), meas.rend(), hits);
48  return;
49  }
50  if (keepOrder | along)
51  split(meas.begin(), meas.end(), hits, along);
52  else
53  split(meas.rbegin(), meas.rend(), hits, along);
54  hits.shrink_to_fit();
55  }
56 
57  void operator()(Trajectory const &traj,
59  TrajParams &trajParams,
60  Chi2sFive &chi2s) const {
61  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
62  bool along = traj.direction() == alongMomentum;
63  auto const &meas = traj.measurements();
64  trajParams.reserve(meas.size());
65  chi2s.reserve(meas.size());
66  if (keepOrder | along)
67  copy(meas.begin(), meas.end(), hits, trajParams, chi2s);
68  else
69  copy(meas.rbegin(), meas.rend(), hits, trajParams, chi2s);
70  }
71 
72 private:
73  template <typename HI>
74  void copy(HI itm, HI e, TrackingRecHitCollection &hits, TrajParams &trajParams, Chi2sFive &chi2s) const {
75  for (; itm != e; ++itm)
76  if ((!removeNoDet) | ((*itm).recHitR().det() != nullptr)) {
77  hits.push_back((*itm).recHitR().cloneHit());
78  trajParams.push_back((*itm).updatedState().localParameters());
79  chi2s.push_back(toChi2x5((*itm).estimate()));
80  }
81  }
82 
83  template <typename HI>
84  void copy(HI itm, HI e, TrackingRecHitCollection &hits) const {
85  for (; itm != e; ++itm)
86  if ((!removeNoDet) | ((*itm).recHitR().det() != nullptr))
87  hits.push_back((*itm).recHitR().cloneHit());
88  }
89 
90  template <typename HI>
91  void split(HI itm, HI e, TrackingRecHitCollection &hits, bool along) const {
92  for (; itm != e; ++itm) {
93  auto const &hit = *(*itm).recHit()->hit();
94  if ((removeNoDet) & ((*itm).recHitR().det() == nullptr))
95  continue;
96  if (trackerHitRTTI::isUndef(hit) || trackerHitRTTI::isNotFromCluster(hit) || (hit.dimension() != 2)) {
97  hits.push_back(hit.clone());
98  continue;
99  }
100  auto const &thit = static_cast<BaseTrackerRecHit const &>(hit);
101  auto const &clus = thit.firstClusterRef();
102  if (clus.isPixel())
103  hits.push_back(hit.clone());
104  else if (clus.isPhase2())
105  hits.push_back(hit.clone());
106  else if (thit.isMatched()) {
107  auto zdir = itm->updatedState().localDirection().z();
108  if (keepOrder & (!along))
109  zdir = -zdir;
110  split(*itm, static_cast<SiStripMatchedRecHit2D const &>(thit), hits, zdir);
111  } else if (thit.isProjected()) {
112  auto detU = static_cast<ProjectedSiStripRecHit2D const &>(thit).originalDet();
113  hits.push_back(build(*detU, clus));
114  } else
115  hits.push_back(clone(thit));
116  }
117  }
118 
119  TrackingRecHit *clone(BaseTrackerRecHit const &hit2D) const {
120  auto const &detU = *hit2D.detUnit();
121  //Use 2D SiStripRecHit in endcap
122  bool endcap = detU.type().isEndcap();
123  if (endcap)
124  return hit2D.clone();
125  return new SiStripRecHit1D(hit2D.localPosition(),
127  *hit2D.det(),
128  hit2D.firstClusterRef());
129  }
130 
131  BaseTrackerRecHit *build(GeomDetUnit const &idet, OmniClusterRef const &clus) const {
132  //Use 2D SiStripRecHit in endcap
133  bool endcap = idet.type().isEndcap();
134  auto &&lv = theCPE->localParameters(clus.stripCluster(), idet);
135  if (endcap)
136  return new SiStripRecHit2D(lv.first, lv.second, idet, clus);
137  return new SiStripRecHit1D(
138  lv.first, LocalError(lv.second.xx(), 0.f, std::numeric_limits<float>::max()), idet, clus);
139  }
140 
141  void split(TrajectoryMeasurement const &itm,
142  SiStripMatchedRecHit2D const &mhit,
144  float zdir) const {
145  const GluedGeomDet *gdet = static_cast<const GluedGeomDet *>(mhit.det());
146 
147  auto hitM = build(*gdet->monoDet(), mhit.monoClusterRef());
148  auto hitS = build(*gdet->stereoDet(), mhit.stereoClusterRef());
149 
150  // we should find a faster way
151  LocalPoint firstLocalPos = itm.updatedState().surface().toLocal(gdet->monoDet()->position());
152  LocalPoint secondLocalPos = itm.updatedState().surface().toLocal(gdet->stereoDet()->position());
153  LocalVector Delta = secondLocalPos - firstLocalPos;
154  float scalar = Delta.z() * zdir;
155  // hit along the direction
156  if (scalar < 0) {
157  hits.push_back(hitS);
158  hits.push_back(hitM);
159  } else {
160  hits.push_back(hitM);
161  hits.push_back(hitS);
162  }
163  }
164 };
165 
166 #endif
TrackingRecHit * clone(BaseTrackerRecHit const &hit2D) const
static unsigned char toChi2x5(float chi2)
bool isNotFromCluster(TrackingRecHit const &hit)
virtual void localParameters(AClusters const &clusters, ALocalValues &retValues, const GeomDetUnit &gd, const LocalTrajectoryParameters &ltp) const
T z() const
Definition: PV3DBase.h:61
void operator()(Trajectory const &traj, TrackingRecHitCollection &hits, TrajParams &trajParams, Chi2sFive &chi2s) const
OmniClusterRef const & stereoClusterRef() const
Traj2TrackHits(const TransientTrackingRecHitBuilder *builder, bool ikeepOrder, bool noNoDet=true)
std::vector< unsigned char > Chi2sFive
const SurfaceType & surface() const
virtual const GeomDetType & type() const
Definition: GeomDet.cc:69
LocalPoint toLocal(const GlobalPoint &gp) const
OmniClusterRef const & monoClusterRef() const
const GeomDet * det() const
void operator()(Trajectory const &traj, TrackingRecHitCollection &hits, bool splitting) const
DataContainer const & measurements() const
Definition: Trajectory.h:178
PropagationDirection const & direction() const
Definition: Trajectory.cc:133
void split(HI itm, HI e, TrackingRecHitCollection &hits, bool along) const
std::vector< LocalTrajectoryParameters > TrajParams
double f[11][100]
virtual const GeomDetUnit * detUnit() const
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:19
virtual TrackingRecHit * clone() const =0
LocalError localPositionError() const override
void copy(HI itm, HI e, TrackingRecHitCollection &hits) const
const StripClusterParameterEstimator * theCPE
virtual OmniClusterRef const & firstClusterRef() const =0
bool isEndcap() const
Definition: GeomDetType.cc:11
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:20
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:43
TrajectoryStateOnSurface const & updatedState() const
BaseTrackerRecHit * build(GeomDetUnit const &idet, OmniClusterRef const &clus) const
LocalPoint localPosition() const override
SiStripCluster const & stripCluster() const
bool isUndef(TrackingRecHit const &hit)
void split(TrajectoryMeasurement const &itm, SiStripMatchedRecHit2D const &mhit, TrackingRecHitCollection &hits, float zdir) const
void copy(HI itm, HI e, TrackingRecHitCollection &hits, TrajParams &trajParams, Chi2sFive &chi2s) const
float xx() const
Definition: LocalError.h:22
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .
Definition: matutil.cc:166