CMS 3D CMS Logo

seedtestMPlex.cc
Go to the documentation of this file.
1 #include "seedtestMPlex.h"
2 #include "oneapi/tbb/parallel_for.h"
3 
4 // #define DEBUG
5 #include "Debug.h"
6 
7 namespace mkfit {
8 
9  inline void intersectThirdLayer(
10  const float a, const float b, const float hit1_x, const float hit1_y, float& lay2_x, float& lay2_y) {
11  const float a2 = a * a;
12  const float b2 = b * b;
13  const float a2b2 = a2 + b2;
14  const float lay2rad2 = (Config::fRadialSpacing * Config::fRadialSpacing) * 9.0f; // average third radius squared
15  const float maxCurvR2 = Config::maxCurvR * Config::maxCurvR;
16 
17  const float quad =
18  std::sqrt(2.0f * maxCurvR2 * (a2b2 + lay2rad2) - (a2b2 - lay2rad2) * (a2b2 - lay2rad2) - maxCurvR2 * maxCurvR2);
19  const float pos[2] = {(a2 * a + a * (b2 + lay2rad2 - maxCurvR2) - b * quad) / a2b2,
20  (b2 * b + b * (a2 + lay2rad2 - maxCurvR2) + a * quad) / a2b2};
21  const float neg[2] = {(a2 * a + a * (b2 + lay2rad2 - maxCurvR2) + b * quad) / a2b2,
22  (b2 * b + b * (a2 + lay2rad2 - maxCurvR2) - a * quad) / a2b2};
23 
24  // since we have two intersection points, arbitrate which one is closer to layer2 hit
25  if (getHypot(pos[0] - hit1_x, pos[1] - hit1_y) < getHypot(neg[0] - hit1_x, neg[1] - hit1_y)) {
26  lay2_x = pos[0];
27  lay2_y = pos[1];
28  } else {
29  lay2_x = neg[0];
30  lay2_y = neg[1];
31  }
32  }
33 
34  void findSeedsByRoadSearch(TripletIdxConVec& seed_idcs,
35  std::vector<LayerOfHits>& evt_lay_hits,
36  int lay1_size,
37  Event*& ev) {
38 #ifdef DEBUG
39  bool debug(false);
40 #endif
41 
42  // MIMI hack: Config::nlayers_per_seed = 4
43  // const float seed_z2cut = (Config::nlayers_per_seed * Config::fRadialSpacing) / std::tan(2.0f*std::atan(std::exp(-1.0f*Config::dEtaSeedTrip)));
44 #ifdef DEBUG
45  const float seed_z2cut =
46  (4 * Config::fRadialSpacing) / std::tan(2.0f * std::atan(std::exp(-1.0f * Config::dEtaSeedTrip)));
47 #endif
48 
49  // 0 = first layer, 1 = second layer, 2 = third layer
50  const LayerOfHits& lay1_hits = evt_lay_hits[1];
51  LayerOfHits& lay0_hits = evt_lay_hits[0];
52  LayerOfHits& lay2_hits = evt_lay_hits[2];
53 
54  tbb::parallel_for(
55  tbb::blocked_range<int>(0, lay1_size, std::max(1, Config::numHitsPerTask)),
56  [&](const tbb::blocked_range<int>& i) {
57  TripletIdxVec temp_thr_seed_idcs;
58  for (int ihit1 = i.begin(); ihit1 < i.end(); ++ihit1) {
59  const Hit& hit1 = lay1_hits.refHit(ihit1);
60  const float hit1_z = hit1.z();
61 
62  dprint("ihit1: " << ihit1 << " mcTrackID: " << hit1.mcTrackID(ev->simHitsInfo_) << " phi: " << hit1.phi()
63  << " z: " << hit1.z());
64  dprint(" predphi: " << hit1.phi() << "+/-" << Config::lay01angdiff << " predz: " << hit1.z() / 2.0f << "+/-"
65  << Config::seed_z0cut / 2.0f << std::endl);
66 
67  std::vector<int> cand_hit0_indices; // pass by reference
68  // MIMI lay0_hits.selectHitIndices(hit1_z/2.0f,hit1.phi(),Config::seed_z0cut/2.0f,Config::lay01angdiff,cand_hit0_indices,true,false);
69  // loop over first layer hits
70  for (auto&& ihit0 : cand_hit0_indices) {
71  const Hit& hit0 = lay0_hits.refHit(ihit0);
72  const float hit0_z = hit0.z();
73  const float hit0_x = hit0.x();
74  const float hit0_y = hit0.y();
75  const float hit1_x = hit1.x();
76  const float hit1_y = hit1.y();
77  const float hit01_r2 = getRad2(hit0_x - hit1_x, hit0_y - hit1_y);
78 
79  const float quad = std::sqrt((4.0f * Config::maxCurvR * Config::maxCurvR - hit01_r2) / hit01_r2);
80 
81  // center of negative curved track
82  const float aneg = 0.5f * ((hit0_x + hit1_x) - (hit0_y - hit1_y) * quad);
83  const float bneg = 0.5f * ((hit0_y + hit1_y) + (hit0_x - hit1_x) * quad);
84 
85  // negative points of intersection with third layer
86  float lay2_negx = 0.0f, lay2_negy = 0.0f;
87  intersectThirdLayer(aneg, bneg, hit1_x, hit1_y, lay2_negx, lay2_negy);
88 #ifdef DEBUG
89  const float lay2_negphi = getPhi(lay2_negx, lay2_negy);
90 #endif
91 
92  // center of positive curved track
93  const float apos = 0.5f * ((hit0_x + hit1_x) + (hit0_y - hit1_y) * quad);
94  const float bpos = 0.5f * ((hit0_y + hit1_y) - (hit0_x - hit1_x) * quad);
95 
96  // positive points of intersection with third layer
97  float lay2_posx = 0.0f, lay2_posy = 0.0f;
98  intersectThirdLayer(apos, bpos, hit1_x, hit1_y, lay2_posx, lay2_posy);
99 #ifdef DEBUG
100  const float lay2_posphi = getPhi(lay2_posx, lay2_posy);
101 #endif
102 
103  std::vector<int> cand_hit2_indices;
104  // MIMI lay2_hits.selectHitIndices((2.0f*hit1_z-hit0_z),(lay2_posphi+lay2_negphi)/2.0f,
105  // MIMI seed_z2cut,(lay2_posphi-lay2_negphi)/2.0f,
106  // MIMI cand_hit2_indices,true,false);
107 
108  dprint(" ihit0: " << ihit0 << " mcTrackID: " << hit0.mcTrackID(ev->simHitsInfo_) << " phi: " << hit0.phi()
109  << " z: " << hit0.z());
110  dprint(" predphi: " << (lay2_posphi + lay2_negphi) / 2.0f << "+/-" << (lay2_posphi - lay2_negphi) / 2.0f
111  << " predz: " << 2.0f * hit1_z - hit0_z << "+/-" << seed_z2cut << std::endl);
112 
113  // loop over candidate third layer hits
114  //temp_thr_seed_idcs.reserve(temp_thr_seed_idcs.size()+cand_hit2_indices.size());
115 #pragma omp simd
116  for (size_t idx = 0; idx < cand_hit2_indices.size(); ++idx) {
117  const int ihit2 = cand_hit2_indices[idx];
118  const Hit& hit2 = lay2_hits.refHit(ihit2);
119 
120  const float lay1_predz = (hit0_z + hit2.z()) / 2.0f;
121  // filter by residual of second layer hit
122  if (std::abs(lay1_predz - hit1_z) > Config::seed_z1cut)
123  continue;
124 
125  const float hit2_x = hit2.x();
126  const float hit2_y = hit2.y();
127 
128  // now fit a circle, extract pT and d0 from center and radius
129  const float mr = (hit1_y - hit0_y) / (hit1_x - hit0_x);
130  const float mt = (hit2_y - hit1_y) / (hit2_x - hit1_x);
131  const float a = (mr * mt * (hit2_y - hit0_y) + mr * (hit1_x + hit2_x) - mt * (hit0_x + hit1_x)) /
132  (2.0f * (mr - mt));
133  const float b = -1.0f * (a - (hit0_x + hit1_x) / 2.0f) / mr + (hit0_y + hit1_y) / 2.0f;
134  const float r = getHypot(hit0_x - a, hit0_y - b);
135 
136  // filter by d0 cut 5mm, pT cut 0.5 GeV (radius of 0.5 GeV track)
137  if ((r < Config::maxCurvR) || (std::abs(getHypot(a, b) - r) > Config::seed_d0cut))
138  continue;
139 
140  dprint(" ihit2: " << ihit2 << " mcTrackID: " << hit2.mcTrackID(ev->simHitsInfo_)
141  << " phi: " << hit2.phi() << " z: " << hit2.z());
142 
143  temp_thr_seed_idcs.emplace_back(TripletIdx{{ihit0, ihit1, ihit2}});
144  } // end loop over third layer matches
145  } // end loop over first layer matches
146  } // end chunk of hits for parallel for
147  seed_idcs.grow_by(temp_thr_seed_idcs.begin(), temp_thr_seed_idcs.end());
148  }); // end parallel for loop over second layer hits
149  }
150 
151 } // end namespace mkfit
float x() const
Definition: Hit.h:162
constexpr float dEtaSeedTrip
constexpr float lay01angdiff
float phi() const
Definition: Hit.h:168
void intersectThirdLayer(const float a, const float b, const float hit1_x, const float hit1_y, float &lay2_x, float &lay2_y)
Definition: seedtestMPlex.cc:9
int mcTrackID(const MCHitInfoVec &globalMCHitInfo) const
Definition: Hit.h:189
std::array< int, 3 > TripletIdx
Definition: TrackExtra.h:41
constexpr float seed_d0cut
void findSeedsByRoadSearch(TripletIdxConVec &seed_idcs, std::vector< LayerOfHits > &evt_lay_hits, int lay1_size, Event *&ev)
T sqrt(T t)
Definition: SSEVec.h:19
float getRad2(float x, float y)
Definition: Hit.h:30
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
float getHypot(float x, float y)
Definition: Hit.h:47
bias2_t b2[25]
Definition: b2.h:9
float y() const
Definition: Hit.h:163
#define debug
Definition: HDRShower.cc:19
constexpr float seed_z1cut
double b
Definition: hdecay.h:120
float getPhi(float x, float y)
Definition: Hit.h:34
#define dprint(x)
Definition: Debug.h:95
float z() const
Definition: Hit.h:164
double a
Definition: hdecay.h:121
constexpr float seed_z0cut
constexpr float maxCurvR
std::vector< TripletIdx > TripletIdxVec
Definition: TrackExtra.h:42
const Hit & refHit(int i) const