CMS 3D CMS Logo

PixelTrackUtilities.h
Go to the documentation of this file.
1 #ifndef CUDADataFormats_Track_PixelTrackUtilities_h
2 #define CUDADataFormats_Track_PixelTrackUtilities_h
3 
4 #include <Eigen/Dense>
5 #include <Eigen/Core>
9 
10 namespace pixelTrack {
11 
12  enum class Quality : uint8_t { bad = 0, edup, dup, loose, strict, tight, highPurity, notQuality };
14  const std::string qualityName[qualitySize]{"bad", "edup", "dup", "loose", "strict", "tight", "highPurity"};
17  return static_cast<Quality>(qp);
18  }
19 
20 } // namespace pixelTrack
21 
22 template <typename TrackerTraits>
23 struct TrackSoA {
24  static constexpr int32_t S = TrackerTraits::maxNumberOfTuples;
25  static constexpr int32_t H = TrackerTraits::avgHitsPerTrack;
26  // Aliases in order to not confuse the GENERATE_SOA_LAYOUT
27  // macro with weird colons and angled brackets.
28  using Vector5f = Eigen::Matrix<float, 5, 1>;
29  using Vector15f = Eigen::Matrix<float, 15, 1>;
31 
32  using hindex_type = uint32_t;
33 
35 
38  SOA_COLUMN(float, chi2),
39  SOA_COLUMN(int8_t, nLayers),
40  SOA_COLUMN(float, eta),
41  SOA_COLUMN(float, pt),
43  SOA_EIGEN_COLUMN(Vector15f, covariance),
44  SOA_SCALAR(int, nTracks),
45  SOA_SCALAR(HitContainer, hitIndices),
46  SOA_SCALAR(HitContainer, detIndices))
47 };
48 
49 // Methods that operate on View and ConstView of the TrackSoA, and cannot be class methods.
50 
51 template <typename TrackerTraits>
54  using TrackSoAConstView = typename TrackSoA<TrackerTraits>::template TrackSoALayout<>::ConstView;
56 
57  // State at the Beam spot
58  // phi,tip,1/pt,cotan(theta),zip
59  static __host__ __device__ inline float charge(const TrackSoAConstView &tracks, int32_t i) {
60  return std::copysign(1.f, tracks[i].state()(2));
61  }
62 
63  static constexpr __host__ __device__ inline float phi(const TrackSoAConstView &tracks, int32_t i) {
64  return tracks[i].state()(0);
65  }
66 
67  static constexpr __host__ __device__ inline float tip(const TrackSoAConstView &tracks, int32_t i) {
68  return tracks[i].state()(1);
69  }
70 
71  static constexpr __host__ __device__ inline float zip(const TrackSoAConstView &tracks, int32_t i) {
72  return tracks[i].state()(4);
73  }
74 
75  static constexpr __host__ __device__ inline bool isTriplet(const TrackSoAConstView &tracks, int i) {
76  return tracks[i].nLayers() == 3;
77  }
78 
79  template <typename V3, typename M3, typename V2, typename M2>
80  static constexpr __host__ __device__ inline void copyFromCircle(
81  TrackSoAView &tracks, V3 const &cp, M3 const &ccov, V2 const &lp, M2 const &lcov, float b, int32_t i) {
82  tracks[i].state() << cp.template cast<float>(), lp.template cast<float>();
83 
84  tracks[i].state()(2) = tracks[i].state()(2) * b;
85  auto cov = tracks[i].covariance();
86  cov(0) = ccov(0, 0);
87  cov(1) = ccov(0, 1);
88  cov(2) = b * float(ccov(0, 2));
89  cov(4) = cov(3) = 0;
90  cov(5) = ccov(1, 1);
91  cov(6) = b * float(ccov(1, 2));
92  cov(8) = cov(7) = 0;
93  cov(9) = b * b * float(ccov(2, 2));
94  cov(11) = cov(10) = 0;
95  cov(12) = lcov(0, 0);
96  cov(13) = lcov(0, 1);
97  cov(14) = lcov(1, 1);
98  }
99 
100  template <typename V5, typename M5>
102  V5 const &v,
103  M5 const &cov,
104  int32_t i) {
105  tracks[i].state() = v.template cast<float>();
106  for (int j = 0, ind = 0; j < 5; ++j)
107  for (auto k = j; k < 5; ++k)
108  tracks[i].covariance()(ind++) = cov(j, k);
109  }
110 
111  template <typename V5, typename M5>
113  V5 &v,
114  M5 &cov,
115  int32_t i) {
116  v = tracks[i].state().template cast<typename V5::Scalar>();
117  for (int j = 0, ind = 0; j < 5; ++j) {
118  cov(j, j) = tracks[i].covariance()(ind++);
119  for (auto k = j + 1; k < 5; ++k)
120  cov(k, j) = cov(j, k) = tracks[i].covariance()(ind++);
121  }
122  }
124  static constexpr __host__ __device__ inline int computeNumberOfLayers(const TrackSoAConstView &tracks, int32_t i) {
125  auto pdet = tracks.detIndices().begin(i);
126  int nl = 1;
127  auto ol = pixelTopology::getLayer<TrackerTraits>(*pdet);
128  for (; pdet < tracks.detIndices().end(i); ++pdet) {
129  auto il = pixelTopology::getLayer<TrackerTraits>(*pdet);
130  if (il != ol)
131  ++nl;
132  ol = il;
133  }
134  return nl;
135  }
137  static constexpr __host__ __device__ inline int nHits(const TrackSoAConstView &tracks, int i) {
138  return tracks.detIndices().size(i);
139  }
140 };
141 
142 namespace pixelTrack {
143 
144  template <typename TrackerTraits, typename Enable = void>
145  struct QualityCutsT {};
146 
147  template <typename TrackerTraits>
148  struct QualityCutsT<TrackerTraits, pixelTopology::isPhase1Topology<TrackerTraits>> {
150  using TrackSoAConstView = typename TrackSoA<TrackerTraits>::template TrackSoALayout<>::ConstView;
152  // chi2 cut = chi2Scale * (chi2Coeff[0] + pT/GeV * (chi2Coeff[1] + pT/GeV * (chi2Coeff[2] + pT/GeV * chi2Coeff[3])))
153  float chi2Coeff[4];
154  float chi2MaxPt; // GeV
155  float chi2Scale;
157  struct Region {
158  float maxTip; // cm
159  float minPt; // GeV
160  float maxZip; // cm
161  };
163  Region triplet;
164  Region quadruplet;
166  __device__ __forceinline__ bool isHP(const TrackSoAConstView &tracks, int nHits, int it) const {
167  // impose "region cuts" based on the fit results (phi, Tip, pt, cotan(theta)), Zip)
168  // default cuts:
169  // - for triplets: |Tip| < 0.3 cm, pT > 0.5 GeV, |Zip| < 12.0 cm
170  // - for quadruplets: |Tip| < 0.5 cm, pT > 0.3 GeV, |Zip| < 12.0 cm
171  // (see CAHitNtupletGeneratorGPU.cc)
172  auto const &region = (nHits > 3) ? quadruplet : triplet;
173  return (std::abs(tracksHelper::tip(tracks, it)) < region.maxTip) and (tracks.pt(it) > region.minPt) and
174  (std::abs(tracksHelper::zip(tracks, it)) < region.maxZip);
175  }
177  __device__ __forceinline__ bool strictCut(const TrackSoAConstView &tracks, int it) const {
178  auto roughLog = [](float x) {
179  // max diff [0.5,12] at 1.25 0.16143
180  // average diff 0.0662998
181  union IF {
182  uint32_t i;
183  float f;
184  };
185  IF z;
186  z.f = x;
187  uint32_t lsb = 1 < 21;
188  z.i += lsb;
189  z.i >>= 21;
190  auto f = z.i & 3;
191  int ex = int(z.i >> 2) - 127;
192 
193  // log2(1+0.25*f)
194  // averaged over bins
195  const float frac[4] = {0.160497f, 0.452172f, 0.694562f, 0.901964f};
196  return float(ex) + frac[f];
197  };
199  float pt = std::min<float>(tracks.pt(it), chi2MaxPt);
200  float chi2Cut = chi2Scale * (chi2Coeff[0] + roughLog(pt) * chi2Coeff[1]);
201  if (tracks.chi2(it) >= chi2Cut) {
202 #ifdef NTUPLE_FIT_DEBUG
203  printf("Bad chi2 %d pt %f eta %f chi2 %f\n", it, tracks.pt(it), tracks.eta(it), tracks.chi2(it));
204 #endif
205  return true;
206  }
207  return false;
208  }
209  };
210 
211  template <typename TrackerTraits>
212  struct QualityCutsT<TrackerTraits, pixelTopology::isPhase2Topology<TrackerTraits>> {
214  using TrackSoAConstView = typename TrackSoA<TrackerTraits>::template TrackSoALayout<>::ConstView;
217  float maxChi2;
218  float minPt;
219  float maxTip;
220  float maxZip;
222  __device__ __forceinline__ bool isHP(const TrackSoAConstView &tracks, int nHits, int it) const {
223  return (std::abs(tracksHelper::tip(tracks, it)) < maxTip) and (tracks.pt(it) > minPt) and
225  }
226  __device__ __forceinline__ bool strictCut(const TrackSoAConstView &tracks, int it) const {
227  return tracks.chi2(it) >= maxChi2;
228  }
229  };
230 
231 } // namespace pixelTrack
232 
233 template <typename TrackerTraits>
234 using TrackLayout = typename TrackSoA<TrackerTraits>::template TrackSoALayout<>;
235 template <typename TrackerTraits>
237 template <typename TrackerTraits>
238 using TrackSoAConstView = typename TrackSoA<TrackerTraits>::template TrackSoALayout<>::ConstView;
239 
242 
243 #endif
static constexpr __host__ __device__ void copyToDense(const TrackSoAConstView &tracks, V5 &v, M5 &cov, int32_t i)
#define __forceinline__
Definition: cudaCompat.h:22
static constexpr __host__ __device__ float tip(const TrackSoAConstView &tracks, int32_t i)
typename TrackSoA< TrackerTraits >::template TrackSoALayout<>::ConstView TrackSoAConstView
Quality qualityByName(std::string const &name)
#define __host__
static constexpr __host__ __device__ float zip(const TrackSoAConstView &tracks, int32_t i)
static constexpr int32_t H
typename TrackSoA< TrackerTraits >::template TrackSoALayout<> TrackLayout
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float zip(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:90
Eigen::Matrix< float, 5, 1 > Vector5f
typename std::enable_if< std::is_base_of< Phase2, T >::value >::type isPhase2Topology
const std::string qualityName[qualitySize]
typename TrackSoA< TrackerTraits >::template TrackSoALayout<>::View TrackSoAView
minPt
Definition: PV_cfg.py:223
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
typename TrackSoA< TrackerTraits >::template TrackSoALayout<>::View TrackSoAView
typename TrackSoA< TrackerTraits >::template TrackSoALayout<>::ConstView TrackSoAConstView
static constexpr __host__ __device__ float phi(const TrackSoAConstView &tracks, int32_t i)
string quality
#define GENERATE_SOA_LAYOUT(CLASS,...)
Definition: SoALayout.h:431
#define SOA_SCALAR(TYPE, NAME)
Definition: SoACommon.h:563
static constexpr __host__ __device__ int computeNumberOfLayers(const TrackSoAConstView &tracks, int32_t i)
constexpr uint32_t qualitySize
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
typename TrackSoA< TrackerTraits >::template TrackSoALayout<>::View TrackSoAView
typename std::enable_if< std::is_base_of< Phase1, T >::value >::type isPhase1Topology
static __host__ __device__ float charge(const TrackSoAConstView &tracks, int32_t i)
static constexpr __host__ __device__ int nHits(const TrackSoAConstView &tracks, int i)
typename TrackSoA< TrackerTraits >::hindex_type hindex_type
double b
Definition: hdecay.h:120
uint32_t hindex_type
static constexpr __host__ __device__ bool isTriplet(const TrackSoAConstView &tracks, int i)
typename TrackSoA< TrackerTraits >::template TrackSoALayout<>::View TrackSoAView
float x
static constexpr __host__ __device__ void copyFromCircle(TrackSoAView &tracks, V3 const &cp, M3 const &ccov, V2 const &lp, M2 const &lcov, float b, int32_t i)
#define SOA_EIGEN_COLUMN(TYPE, NAME)
Definition: SoACommon.h:565
typename TrackSoA< TrackerTraits >::template TrackSoALayout<>::ConstView TrackSoAConstView
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
Eigen::Matrix< float, 15, 1 > Vector15f
#define __device__
#define SOA_COLUMN(TYPE, NAME)
Definition: SoACommon.h:564
static constexpr __host__ __device__ void copyFromDense(TrackSoAView &tracks, V5 const &v, M5 const &cov, int32_t i)
typename TrackSoA< TrackerTraits >::template TrackSoALayout<>::ConstView TrackSoAConstView