CMS 3D CMS Logo

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