CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HGCDoublet.cc
Go to the documentation of this file.
1 #include "HGCDoublet.h"
2 
3 bool HGCDoublet::checkCompatibilityAndTag(std::vector<HGCDoublet> &allDoublets,
4  const std::vector<int> &innerDoublets,
5  const GlobalVector &refDir,
6  float minCosTheta,
7  float minCosPointing,
8  bool debug) {
9  int nDoublets = innerDoublets.size();
10  int constexpr VSIZE = 4;
11  int ok[VSIZE];
12  double xi[VSIZE];
13  double yi[VSIZE];
14  double zi[VSIZE];
15  int seedi[VSIZE];
16  bool siblingsClusters[VSIZE];
17  auto xo = outerX();
18  auto yo = outerY();
19  auto zo = outerZ();
20  unsigned int doubletId = theDoubletId_;
21 
22  auto loop = [&](int i, int vs) {
23  for (int j = 0; j < vs; ++j) {
24  auto otherDoubletId = innerDoublets[i + j];
25  auto &otherDoublet = allDoublets[otherDoubletId];
26  xi[j] = otherDoublet.innerX();
27  yi[j] = otherDoublet.innerY();
28  zi[j] = otherDoublet.innerZ();
29  seedi[j] = otherDoublet.seedIndex();
30  siblingsClusters[j] = otherDoublet.areSiblingClusters();
31  if (debug) {
32  LogDebug("HGCDoublet") << i + j << " is doublet " << otherDoubletId << std::endl;
33  }
34  }
35  for (int j = 0; j < vs; ++j) {
36  if (seedi[j] != seedIndex_) {
37  ok[j] = 0;
38  continue;
39  }
40  if (areSiblingClusters_ and siblingsClusters[j]) {
41  ok[j] = 1;
42  continue;
43  }
44  ok[j] = areAligned(xi[j], yi[j], zi[j], xo, yo, zo, minCosTheta, minCosPointing, refDir, debug);
45  if (debug) {
46  LogDebug("HGCDoublet") << "Are aligned for InnerDoubletId: " << i + j << " is " << ok[j] << std::endl;
47  }
48  }
49  for (int j = 0; j < vs; ++j) {
50  auto otherDoubletId = innerDoublets[i + j];
51  auto &otherDoublet = allDoublets[otherDoubletId];
52  if (ok[j]) {
53  otherDoublet.tagAsOuterNeighbor(doubletId);
54  allDoublets[doubletId].tagAsInnerNeighbor(otherDoubletId);
55  }
56  }
57  };
58  auto lim = VSIZE * (nDoublets / VSIZE);
59  for (int i = 0; i < lim; i += VSIZE)
60  loop(i, VSIZE);
61  loop(lim, nDoublets - lim);
62 
63  if (debug) {
64  LogDebug("HGCDoublet") << "Found " << innerNeighbors_.size() << " compatible doublets out of " << nDoublets
65  << " considered" << std::endl;
66  }
67  return innerNeighbors_.empty();
68 }
69 
70 int HGCDoublet::areAligned(double xi,
71  double yi,
72  double zi,
73  double xo,
74  double yo,
75  double zo,
76  float minCosTheta,
77  float minCosPointing,
78  const GlobalVector &refDir,
79  bool debug) const {
80  auto dx1 = xo - xi;
81  auto dy1 = yo - yi;
82  auto dz1 = zo - zi;
83 
84  auto dx2 = innerX() - xi;
85  auto dy2 = innerY() - yi;
86  auto dz2 = innerZ() - zi;
87 
88  // inner product
89  auto dot = dx1 * dx2 + dy1 * dy2 + dz1 * dz2;
90  auto dotsq = dot * dot;
91  // magnitudes
92  auto mag1sq = dx1 * dx1 + dy1 * dy1 + dz1 * dz1;
93  auto mag2sq = dx2 * dx2 + dy2 * dy2 + dz2 * dz2;
94 
95  auto minCosTheta_sq = minCosTheta * minCosTheta;
96  bool isWithinLimits = (dotsq > minCosTheta_sq * mag1sq * mag2sq);
97 
98  if (debug) {
99  LogDebug("HGCDoublet") << "-- Are Aligned -- dotsq: " << dotsq << " mag1sq: " << mag1sq << " mag2sq: " << mag2sq
100  << "minCosTheta_sq:" << minCosTheta_sq << " isWithinLimits: " << isWithinLimits << std::endl;
101  }
102 
103  // Now check the compatibility with the pointing origin.
104  // Pointing origin is a vector obtained by the seed (track extrapolation i.e.)
105  // or the direction wrt (0,0,0)
106  // The compatibility is checked only for the innermost doublets: the
107  // one with the outer doublets comes in by the alignment requirement of
108  // the doublets themeselves
109 
110  const GlobalVector firstDoublet(dx2, dy2, dz2);
111  const GlobalVector pointingDir = (seedIndex_ == -1) ? GlobalVector(innerX(), innerY(), innerZ()) : refDir;
112 
113  auto dot_pointing = pointingDir.dot(firstDoublet);
114  auto dot_pointing_sq = dot_pointing * dot_pointing;
115  auto mag_pointing_sq = pointingDir.mag2();
116  auto minCosPointing_sq = minCosPointing * minCosPointing;
117  bool isWithinLimitsPointing = (dot_pointing_sq > minCosPointing_sq * mag_pointing_sq * mag2sq);
118  if (debug) {
119  LogDebug("HGCDoublet") << "Pointing direction: " << pointingDir << std::endl;
120  LogDebug("HGCDoublet") << "-- Are Aligned -- dot_pointing_sq: " << dot_pointing_sq
121  << " mag_pointing_sq: " << mag_pointing_sq << " mag2sq: " << mag2sq
122  << " isWithinLimitsPointing: " << isWithinLimitsPointing << std::endl;
123  }
124  // by squaring cosTheta and multiplying by the squares of the magnitudes
125  // an equivalent comparison is made without the division and square root which are costly FP ops.
126  return isWithinLimits && isWithinLimitsPointing;
127 }
128 
129 void HGCDoublet::findNtuplets(std::vector<HGCDoublet> &allDoublets,
130  HGCntuplet &tmpNtuplet,
131  int seedIndex,
132  const bool outInDFS,
133  const unsigned int outInHops,
134  const unsigned int maxOutInHops,
135  std::vector<std::pair<unsigned int, unsigned int> > &outInToVisit) {
136  if (!alreadyVisited_ && seedIndex == seedIndex_) {
137  alreadyVisited_ = true;
138  tmpNtuplet.push_back(theDoubletId_);
139  unsigned int numberOfOuterNeighbors = outerNeighbors_.size();
140  for (unsigned int i = 0; i < numberOfOuterNeighbors; ++i) {
141  allDoublets[outerNeighbors_[i]].findNtuplets(
142  allDoublets, tmpNtuplet, seedIndex, outInDFS, outInHops, maxOutInHops, outInToVisit);
143  }
144  if (outInDFS && outInHops < maxOutInHops) {
145  for (auto inN : innerNeighbors_) {
146  outInToVisit.emplace_back(inN, outInHops + 1);
147  }
148  }
149  }
150 }
std::vector< unsigned int > HGCntuplet
Definition: HGCDoublet.h:16
T mag2() const
Definition: PV3DBase.h:63
std::vector< int > outerNeighbors_
Definition: HGCDoublet.h:98
int seedIndex_
Definition: HGCDoublet.h:113
double outerZ() const
Definition: HGCDoublet.h:50
bool alreadyVisited_
Definition: HGCDoublet.h:114
double outerX() const
Definition: HGCDoublet.h:42
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:99
const int theDoubletId_
Definition: HGCDoublet.h:101
int areAligned(double xi, double yi, double zi, double xo, double yo, double zo, float minCosTheta, float minCosPointing, const GlobalVector &refDir, bool debug=false) const
Definition: HGCDoublet.cc:70
double innerX() const
Definition: HGCDoublet.h:40
std::vector< int > innerNeighbors_
Definition: HGCDoublet.h:99
double innerY() const
Definition: HGCDoublet.h:44
void findNtuplets(std::vector< HGCDoublet > &allDoublets, HGCntuplet &tmpNtuplet, int seedIndex, const bool outInDFS, const unsigned int outInHops, const unsigned int maxOutInHops, std::vector< std::pair< unsigned int, unsigned int > > &outInToVisit)
Definition: HGCDoublet.cc:129
#define debug
Definition: HDRShower.cc:19
double outerY() const
Definition: HGCDoublet.h:46
double innerZ() const
Definition: HGCDoublet.h:48
T dot(const Basic3DVector &v) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
bool areSiblingClusters_
Definition: HGCDoublet.h:115
bool checkCompatibilityAndTag(std::vector< HGCDoublet > &allDoublets, const std::vector< int > &innerDoublets, const GlobalVector &refDir, float minCosTheta, float minCosPointing=1., bool debug=false)
Definition: HGCDoublet.cc:3
Global3DVector GlobalVector
Definition: GlobalVector.h:10
#define LogDebug(id)