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;
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
Vector3DBase< float, LocalTag >
GeomDet::position
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:43
Traj2TrackHits::Chi2sFive
std::vector< unsigned char > Chi2sFive
Definition: Traj2TrackHits.h:23
Traj2TrackHits::copy
void copy(HI itm, HI e, TrackingRecHitCollection &hits) const
Definition: Traj2TrackHits.h:84
GeomDet
Definition: GeomDet.h:27
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
Trajectory::direction
PropagationDirection const & direction() const
Definition: Trajectory.cc:133
Traj2TrackHits::toChi2x5
static unsigned char toChi2x5(float chi2)
Definition: Traj2TrackHits.h:25
GeomDet::type
virtual const GeomDetType & type() const
Definition: GeomDet.cc:69
min
T min(T a, T b)
Definition: MathUtil.h:58
TrackingRecHit::det
const GeomDet * det() const
Definition: TrackingRecHit.h:122
GeomDetType.h
GluedGeomDet::monoDet
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:19
GluedGeomDet.h
trackerHitRTTI::isUndef
bool isUndef(TrackingRecHit const &hit)
Definition: trackerHitRTTI.h:24
SiStripRecHit2D
Definition: SiStripRecHit2D.h:7
TrackingRecHitFwd.h
Traj2TrackHits::Traj2TrackHits
Traj2TrackHits(const TransientTrackingRecHitBuilder *builder, bool ikeepOrder, bool noNoDet=true)
Definition: Traj2TrackHits.h:33
TrajectoryMeasurement::updatedState
TrajectoryStateOnSurface const & updatedState() const
Definition: TrajectoryMeasurement.h:184
trackerHitRTTI::isNotFromCluster
bool isNotFromCluster(TrackingRecHit const &hit)
Definition: trackerHitRTTI.h:25
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
makeMuonMisalignmentScenario.endcap
endcap
Definition: makeMuonMisalignmentScenario.py:320
watchdog.const
const
Definition: watchdog.py:83
Traj2TrackHits::keepOrder
bool keepOrder
Definition: Traj2TrackHits.h:19
OmniClusterRef
Definition: OmniClusterRef.h:12
Traj2TrackHits::operator()
void operator()(Trajectory const &traj, TrackingRecHitCollection &hits, TrajParams &trajParams, Chi2sFive &chi2s) const
Definition: Traj2TrackHits.h:57
TkTransientTrackingRecHitBuilder.h
Traj2TrackHits::clone
TrackingRecHit * clone(BaseTrackerRecHit const &hit2D) const
Definition: Traj2TrackHits.h:119
TkTransientTrackingRecHitBuilder
Definition: TkTransientTrackingRecHitBuilder.h:15
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
StripClusterParameterEstimator
Definition: StripClusterParameterEstimator.h:25
BaseTrackerRecHit
Definition: BaseTrackerRecHit.h:15
LocalError::xx
float xx() const
Definition: LocalError.h:22
OmniClusterRef::stripCluster
SiStripCluster const & stripCluster() const
Definition: OmniClusterRef.h:55
hitfit::scalar
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .
Definition: matutil.cc:166
Point3DBase< float, LocalTag >
Traj2TrackHits::operator()
void operator()(Trajectory const &traj, TrackingRecHitCollection &hits, bool splitting) const
Definition: Traj2TrackHits.h:38
GluedGeomDet
Definition: GluedGeomDet.h:7
BaseTrackerRecHit::localPositionError
LocalError localPositionError() const override
Definition: BaseTrackerRecHit.h:61
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
LocalError
Definition: LocalError.h:12
SiStripMatchedRecHit2D::stereoClusterRef
OmniClusterRef const & stereoClusterRef() const
Definition: SiStripMatchedRecHit2D.h:34
Traj2TrackHits::split
void split(HI itm, HI e, TrackingRecHitCollection &hits, bool along) const
Definition: Traj2TrackHits.h:91
Traj2TrackHits
Definition: Traj2TrackHits.h:16
Traj2TrackHits::build
BaseTrackerRecHit * build(GeomDetUnit const &idet, OmniClusterRef const &clus) const
Definition: Traj2TrackHits.h:131
Traj2TrackHits::Traj2TrackHits
Traj2TrackHits()
Definition: Traj2TrackHits.h:31
BaseTrackerRecHit::firstClusterRef
virtual OmniClusterRef const & firstClusterRef() const =0
ProjectedSiStripRecHit2D.h
StripClusterParameterEstimator::localParameters
virtual void localParameters(AClusters const &clusters, ALocalValues &retValues, const GeomDetUnit &gd, const LocalTrajectoryParameters &ltp) const
Definition: StripClusterParameterEstimator.h:32
SiStripRecHit1D
Definition: SiStripRecHit1D.h:8
SiStripMatchedRecHit2D::monoClusterRef
OmniClusterRef const & monoClusterRef() const
Definition: SiStripMatchedRecHit2D.h:35
TrackingRecHit::clone
virtual TrackingRecHit * clone() const =0
Trajectory::measurements
DataContainer const & measurements() const
Definition: Trajectory.h:178
TrackingRecHit
Definition: TrackingRecHit.h:21
SiStripRecHit1D.h
GluedGeomDet::stereoDet
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:20
Trajectory.h
Traj2TrackHits::TrajParams
std::vector< LocalTrajectoryParameters > TrajParams
Definition: Traj2TrackHits.h:22
BaseTrackerRecHit::localPosition
LocalPoint localPosition() const override
Definition: BaseTrackerRecHit.h:56
GeomDetType::isEndcap
bool isEndcap() const
Definition: GeomDetType.cc:11
SiStripMatchedRecHit2D
Definition: SiStripMatchedRecHit2D.h:8
Traj2TrackHits::theCPE
const StripClusterParameterEstimator * theCPE
Definition: Traj2TrackHits.h:18
Trajectory
Definition: Trajectory.h:38
GloballyPositioned::toLocal
LocalPoint toLocal(const GlobalPoint &gp) const
Definition: GloballyPositioned.h:98
StripClusterParameterEstimator.h
TrajectoryStateOnSurface::surface
const SurfaceType & surface() const
Definition: TrajectoryStateOnSurface.h:78
SiStripMatchedRecHit2D.h
Traj2TrackHits::split
void split(TrajectoryMeasurement const &itm, SiStripMatchedRecHit2D const &mhit, TrackingRecHitCollection &hits, float zdir) const
Definition: Traj2TrackHits.h:141
TransientTrackingRecHitBuilder
Definition: TransientTrackingRecHitBuilder.h:6
TrajectoryMeasurement
Definition: TrajectoryMeasurement.h:25
TrackingRecHit::detUnit
virtual const GeomDetUnit * detUnit() const
Definition: TrackingRecHit.cc:29
Traj2TrackHits::removeNoDet
bool removeNoDet
Definition: Traj2TrackHits.h:20
alongMomentum
Definition: PropagationDirection.h:4
Traj2TrackHits::copy
void copy(HI itm, HI e, TrackingRecHitCollection &hits, TrajParams &trajParams, Chi2sFive &chi2s) const
Definition: Traj2TrackHits.h:74
hit
Definition: SiStripHitEffFromCalibTree.cc:88
edm::OwnVector< TrackingRecHit >
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37