CMS 3D CMS Logo

CACell.h
Go to the documentation of this file.
1 #ifndef RecoPixelVertexing_PixelTriplets_src_CACell_h
2 #define RecoPixelVertexing_PixelTriplets_src_CACell_h
3 
4 #include <array>
5 #include <cmath>
6 
11 
12 class CACellStatus {
13 public:
14  unsigned char getCAState() const { return theCAState; }
15 
16  // if there is at least one left neighbor with the same state (friend), the state has to be increased by 1.
18 
19  bool isRootCell(const unsigned int minimumCAState) const { return (theCAState >= minimumCAState); }
20 
21 public:
22  unsigned char theCAState = 0;
23  unsigned char hasSameStateNeighbors = 0;
24 };
25 
26 class CACell {
27 public:
29  using CAntuple = std::vector<unsigned int>;
30  using CAntuplet = std::vector<unsigned int>;
31  using CAColl = std::vector<CACell>;
32  using CAStatusColl = std::vector<CACellStatus>;
33 
34  CACell(const HitDoublets* doublets, int doubletId, const int innerHitId, const int outerHitId)
35  : theDoublets(doublets),
36  theDoubletId(doubletId),
37  theInnerR(doublets->rv(doubletId, HitDoublets::inner)),
38  theInnerZ(doublets->z(doubletId, HitDoublets::inner)) {}
39 
40  Hit const& getInnerHit() const { return theDoublets->hit(theDoubletId, HitDoublets::inner); }
41 
42  Hit const& getOuterHit() const { return theDoublets->hit(theDoubletId, HitDoublets::outer); }
43 
44  float getInnerX() const { return theDoublets->x(theDoubletId, HitDoublets::inner); }
45 
46  float getOuterX() const { return theDoublets->x(theDoubletId, HitDoublets::outer); }
47 
48  float getInnerY() const { return theDoublets->y(theDoubletId, HitDoublets::inner); }
49 
50  float getOuterY() const { return theDoublets->y(theDoubletId, HitDoublets::outer); }
51 
52  float getInnerZ() const { return theInnerZ; }
53 
54  float getOuterZ() const { return theDoublets->z(theDoubletId, HitDoublets::outer); }
55 
56  float getInnerR() const { return theInnerR; }
57 
58  float getOuterR() const { return theDoublets->rv(theDoubletId, HitDoublets::outer); }
59 
60  float getInnerPhi() const { return theDoublets->phi(theDoubletId, HitDoublets::inner); }
61 
62  float getOuterPhi() const { return theDoublets->phi(theDoubletId, HitDoublets::outer); }
63 
64  void evolve(unsigned int me, CAStatusColl& allStatus) {
65  allStatus[me].hasSameStateNeighbors = 0;
66  auto mystate = allStatus[me].theCAState;
67 
68  for (auto oc : theOuterNeighbors) {
69  if (allStatus[oc].getCAState() == mystate) {
70  allStatus[me].hasSameStateNeighbors = 1;
71 
72  break;
73  }
74  }
75  }
76 
77  void checkAlignmentAndAct(CAColl& allCells,
78  CAntuple& innerCells,
79  const float ptmin,
80  const float region_origin_x,
81  const float region_origin_y,
82  const float region_origin_radius,
83  const float thetaCut,
84  const float phiCut,
85  const float hardPtCut,
86  std::vector<CACell::CAntuplet>* foundTriplets) {
87  int ncells = innerCells.size();
88  int constexpr VSIZE = 16;
89  int ok[VSIZE];
90  float r1[VSIZE];
91  float z1[VSIZE];
92  auto ro = getOuterR();
93  auto zo = getOuterZ();
94  unsigned int cellId = this - &allCells.front();
95  auto loop = [&](int i, int vs) {
96  for (int j = 0; j < vs; ++j) {
97  auto koc = innerCells[i + j];
98  auto& oc = allCells[koc];
99  r1[j] = oc.getInnerR();
100  z1[j] = oc.getInnerZ();
101  }
102  // this vectorize!
103  for (int j = 0; j < vs; ++j)
104  ok[j] = areAlignedRZ(r1[j], z1[j], ro, zo, ptmin, thetaCut);
105  for (int j = 0; j < vs; ++j) {
106  auto koc = innerCells[i + j];
107  auto& oc = allCells[koc];
108  if (ok[j] && haveSimilarCurvature(
109  oc, ptmin, region_origin_x, region_origin_y, region_origin_radius, phiCut, hardPtCut)) {
110  if (foundTriplets)
111  foundTriplets->emplace_back(CACell::CAntuplet{koc, cellId});
112  else {
113  oc.tagAsOuterNeighbor(cellId);
114  }
115  }
116  }
117  };
118  auto lim = VSIZE * (ncells / VSIZE);
119  for (int i = 0; i < lim; i += VSIZE)
120  loop(i, VSIZE);
121  loop(lim, ncells - lim);
122  }
123 
124  void checkAlignmentAndTag(CAColl& allCells,
125  CAntuple& innerCells,
126  const float ptmin,
127  const float region_origin_x,
128  const float region_origin_y,
129  const float region_origin_radius,
130  const float thetaCut,
131  const float phiCut,
132  const float hardPtCut) {
133  checkAlignmentAndAct(allCells,
134  innerCells,
135  ptmin,
136  region_origin_x,
137  region_origin_y,
138  region_origin_radius,
139  thetaCut,
140  phiCut,
141  hardPtCut,
142  nullptr);
143  }
145  CAntuple& innerCells,
146  std::vector<CACell::CAntuplet>& foundTriplets,
147  const float ptmin,
148  const float region_origin_x,
149  const float region_origin_y,
150  const float region_origin_radius,
151  const float thetaCut,
152  const float phiCut,
153  const float hardPtCut) {
154  checkAlignmentAndAct(allCells,
155  innerCells,
156  ptmin,
157  region_origin_x,
158  region_origin_y,
159  region_origin_radius,
160  thetaCut,
161  phiCut,
162  hardPtCut,
163  &foundTriplets);
164  }
165 
166  int areAlignedRZ(float r1, float z1, float ro, float zo, const float ptmin, const float thetaCut) const {
167  float radius_diff = std::abs(r1 - ro);
168  float distance_13_squared = radius_diff * radius_diff + (z1 - zo) * (z1 - zo);
169 
170  float pMin = ptmin * std::sqrt(distance_13_squared); //this needs to be divided by radius_diff later
171 
172  float tan_12_13_half_mul_distance_13_squared =
173  fabs(z1 * (getInnerR() - ro) + getInnerZ() * (ro - r1) + zo * (r1 - getInnerR()));
174  return tan_12_13_half_mul_distance_13_squared * pMin <= thetaCut * distance_13_squared * radius_diff;
175  }
176 
177  void tagAsOuterNeighbor(unsigned int otherCell) { theOuterNeighbors.push_back(otherCell); }
178 
179  bool haveSimilarCurvature(const CACell& otherCell,
180  const float ptmin,
181  const float region_origin_x,
182  const float region_origin_y,
183  const float region_origin_radius,
184  const float phiCut,
185  const float hardPtCut) const {
186  auto x1 = otherCell.getInnerX();
187  auto y1 = otherCell.getInnerY();
188 
189  auto x2 = getInnerX();
190  auto y2 = getInnerY();
191 
192  auto x3 = getOuterX();
193  auto y3 = getOuterY();
194 
195  float distance_13_squared = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3);
196  float tan_12_13_half_mul_distance_13_squared = std::abs(y1 * (x2 - x3) + y2 * (x3 - x1) + y3 * (x1 - x2));
197  // high pt : just straight
198  if (tan_12_13_half_mul_distance_13_squared * ptmin <= 1.0e-4f * distance_13_squared) {
199  float distance_3_beamspot_squared =
200  (x3 - region_origin_x) * (x3 - region_origin_x) + (y3 - region_origin_y) * (y3 - region_origin_y);
201 
202  float dot_bs3_13 = ((x1 - x3) * (region_origin_x - x3) + (y1 - y3) * (region_origin_y - y3));
203  float proj_bs3_on_13_squared = dot_bs3_13 * dot_bs3_13 / distance_13_squared;
204 
205  float distance_13_beamspot_squared = distance_3_beamspot_squared - proj_bs3_on_13_squared;
206 
207  return distance_13_beamspot_squared < (region_origin_radius + phiCut) * (region_origin_radius + phiCut);
208  }
209 
210  //87 cm/GeV = 1/(3.8T * 0.3)
211 
212  //take less than radius given by the hardPtCut and reject everything below
213  float minRadius = hardPtCut * 87.f; // FIXME move out and use real MagField
214 
215  auto det = (x1 - x2) * (y2 - y3) - (x2 - x3) * (y1 - y2);
216 
217  auto offset = x2 * x2 + y2 * y2;
218 
219  auto bc = (x1 * x1 + y1 * y1 - offset) * 0.5f;
220 
221  auto cd = (offset - x3 * x3 - y3 * y3) * 0.5f;
222 
223  auto idet = 1.f / det;
224 
225  auto x_center = (bc * (y2 - y3) - cd * (y1 - y2)) * idet;
226  auto y_center = (cd * (x1 - x2) - bc * (x2 - x3)) * idet;
227 
228  auto radius = std::sqrt((x2 - x_center) * (x2 - x_center) + (y2 - y_center) * (y2 - y_center));
229 
230  if (radius < minRadius)
231  return false; // hard cut on pt
232 
233  auto centers_distance_squared = (x_center - region_origin_x) * (x_center - region_origin_x) +
234  (y_center - region_origin_y) * (y_center - region_origin_y);
235  auto region_origin_radius_plus_tolerance = region_origin_radius + phiCut;
236  auto minimumOfIntersectionRange =
237  (radius - region_origin_radius_plus_tolerance) * (radius - region_origin_radius_plus_tolerance);
238 
239  if (centers_distance_squared >= minimumOfIntersectionRange) {
240  auto maximumOfIntersectionRange =
241  (radius + region_origin_radius_plus_tolerance) * (radius + region_origin_radius_plus_tolerance);
242  return centers_distance_squared <= maximumOfIntersectionRange;
243  }
244 
245  return false;
246  }
247 
248  // trying to free the track building process from hardcoded layers, leaving the visit of the graph
249  // based on the neighborhood connections between cells.
250 
251  void findNtuplets(CAColl& allCells,
252  std::vector<CAntuplet>& foundNtuplets,
253  CAntuplet& tmpNtuplet,
254  const unsigned int minHitsPerNtuplet) const {
255  // the building process for a track ends if:
256  // it has no outer neighbor
257  // it has no compatible neighbor
258  // the ntuplets is then saved if the number of hits it contains is greater than a threshold
259 
260  if (tmpNtuplet.size() == minHitsPerNtuplet - 1) {
261  foundNtuplets.push_back(tmpNtuplet);
262  } else {
263  unsigned int numberOfOuterNeighbors = theOuterNeighbors.size();
264  for (unsigned int i = 0; i < numberOfOuterNeighbors; ++i) {
265  tmpNtuplet.push_back((theOuterNeighbors[i]));
266  allCells[theOuterNeighbors[i]].findNtuplets(allCells, foundNtuplets, tmpNtuplet, minHitsPerNtuplet);
267  tmpNtuplet.pop_back();
268  }
269  }
270  }
271 
272 private:
274 
276  const int theDoubletId;
277 
278  const float theInnerR;
279  const float theInnerZ;
280 };
281 
282 #endif // RecoPixelVertexing_PixelTriplets_src_CACell_h
const float theInnerZ
Definition: CACell.h:279
const HitDoublets * theDoublets
Definition: CACell.h:275
bool haveSimilarCurvature(const CACell &otherCell, const float ptmin, const float region_origin_x, const float region_origin_y, const float region_origin_radius, const float phiCut, const float hardPtCut) const
Definition: CACell.h:179
void updateState()
Definition: CACell.h:17
float getInnerZ() const
Definition: CACell.h:52
float getOuterR() const
Definition: CACell.h:58
const int theDoubletId
Definition: CACell.h:276
std::vector< CACellStatus > CAStatusColl
Definition: CACell.h:32
float getOuterZ() const
Definition: CACell.h:54
int areAlignedRZ(float r1, float z1, float ro, float zo, const float ptmin, const float thetaCut) const
Definition: CACell.h:166
float getInnerY() const
Definition: CACell.h:48
float getOuterPhi() const
Definition: CACell.h:62
unsigned char getCAState() const
Definition: CACell.h:14
Hit const & getInnerHit() const
Definition: CACell.h:40
std::vector< unsigned int > CAntuple
Definition: CACell.h:29
bool isRootCell(const unsigned int minimumCAState) const
Definition: CACell.h:19
T sqrt(T t)
Definition: SSEVec.h:19
const float theInnerR
Definition: CACell.h:278
float getInnerR() const
Definition: CACell.h:56
float getOuterX() const
Definition: CACell.h:46
void tagAsOuterNeighbor(unsigned int otherCell)
Definition: CACell.h:177
void evolve(unsigned int me, CAStatusColl &allStatus)
Definition: CACell.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< CACell > CAColl
Definition: CACell.h:31
double f[11][100]
float getInnerX() const
Definition: CACell.h:44
float getOuterY() const
Definition: CACell.h:50
void checkAlignmentAndAct(CAColl &allCells, CAntuple &innerCells, const float ptmin, const float region_origin_x, const float region_origin_y, const float region_origin_radius, const float thetaCut, const float phiCut, const float hardPtCut, std::vector< CACell::CAntuplet > *foundTriplets)
Definition: CACell.h:77
float getInnerPhi() const
Definition: CACell.h:60
Hit const & getOuterHit() const
Definition: CACell.h:42
BaseTrackerRecHit const * Hit
void checkAlignmentAndPushTriplet(CAColl &allCells, CAntuple &innerCells, std::vector< CACell::CAntuplet > &foundTriplets, const float ptmin, const float region_origin_x, const float region_origin_y, const float region_origin_radius, const float thetaCut, const float phiCut, const float hardPtCut)
Definition: CACell.h:144
Definition: CACell.h:26
std::vector< unsigned int > CAntuplet
Definition: CACell.h:30
double ptmin
Definition: HydjetWrapper.h:84
unsigned char theCAState
Definition: CACell.h:22
CACell(const HitDoublets *doublets, int doubletId, const int innerHitId, const int outerHitId)
Definition: CACell.h:34
CAntuple theOuterNeighbors
Definition: CACell.h:273
void findNtuplets(CAColl &allCells, std::vector< CAntuplet > &foundNtuplets, CAntuplet &tmpNtuplet, const unsigned int minHitsPerNtuplet) const
Definition: CACell.h:251
unsigned char hasSameStateNeighbors
Definition: CACell.h:23
#define constexpr
void checkAlignmentAndTag(CAColl &allCells, CAntuple &innerCells, const float ptmin, const float region_origin_x, const float region_origin_y, const float region_origin_radius, const float thetaCut, const float phiCut, const float hardPtCut)
Definition: CACell.h:124