CMS 3D CMS Logo

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