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