CMS 3D CMS Logo

SiStripHitEfficiencyHelpers.h
Go to the documentation of this file.
1 #ifndef SiStripHitEfficiencyHelpers_H
2 #define SiStripHitEfficiencyHelpers_H
3 
4 // A bunch of helper functions to deal with menial tasks in the
5 // hit efficiency computation for the PCL workflow
6 
7 #include "TString.h"
8 #include <string>
9 #include <fmt/printf.h>
13 
14 namespace {
15 
16  enum bounds {
17  k_LayersStart = 0,
18  k_LayersAtTIBEnd = 4,
19  k_LayersAtTOBEnd = 10,
20  k_LayersAtTIDEnd = 13,
21  k_LayersAtTECEnd = 22,
22  k_END_OF_LAYERS = 23,
23  k_END_OF_LAYS_AND_RINGS = 35
24  };
25 
26  inline unsigned int checkLayer(unsigned int iidd, const TrackerTopology* tTopo) {
27  switch (DetId(iidd).subdetId()) {
29  return tTopo->tibLayer(iidd);
31  return tTopo->tobLayer(iidd) + bounds::k_LayersAtTIBEnd;
33  return tTopo->tidWheel(iidd) + bounds::k_LayersAtTOBEnd;
35  return tTopo->tecWheel(iidd) + bounds::k_LayersAtTIDEnd;
36  default:
37  return bounds::k_LayersStart;
38  }
39  }
40 
41  inline std::string layerName(unsigned int k, const bool showRings, const unsigned int nTEClayers) {
42  const std::string ringlabel{showRings ? "R" : "D"};
43  if (k > bounds::k_LayersStart && k <= bounds::k_LayersAtTIBEnd) {
44  return fmt::format("TIB L{:d}", k);
45  } else if (k > bounds::k_LayersAtTIBEnd && k <= bounds::k_LayersAtTOBEnd) {
46  return fmt::format("TOB L{:d}", k - bounds::k_LayersAtTIBEnd);
47  } else if (k > bounds::k_LayersAtTOBEnd && k <= bounds::k_LayersAtTIDEnd) {
48  return fmt::format("TID {0}{1:d}", ringlabel, k - bounds::k_LayersAtTOBEnd);
49  } else if (k > bounds::k_LayersAtTIDEnd && k <= bounds::k_LayersAtTIDEnd + nTEClayers) {
50  return fmt::format("TEC {0}{1:d}", ringlabel, k - bounds::k_LayersAtTIDEnd);
51  } else {
52  return "should never be here!";
53  }
54  }
55 
56  inline std::string layerSideName(Long_t k, const bool showRings, const unsigned int nTEClayers) {
57  const std::string ringlabel{showRings ? "R" : "D"};
58  if (k > bounds::k_LayersStart && k <= bounds::k_LayersAtTIBEnd) {
59  return fmt::format("TIB L{:d}", k);
60  } else if (k > bounds::k_LayersAtTIBEnd && k <= bounds::k_LayersAtTOBEnd) {
61  return fmt::format("TOB L{:d}", k - bounds::k_LayersAtTIBEnd);
62  } else if (k > bounds::k_LayersAtTOBEnd && k < 14) {
63  return fmt::format("TID- {0}{1:d}", ringlabel, k - bounds::k_LayersAtTOBEnd);
64  } else if (k > 13 && k < 17) {
65  return fmt::format("TID+ {0}{1:d}", ringlabel, k - 13);
66  } else if (k > 16 && k < 17 + nTEClayers) {
67  return fmt::format("TEC- {0}{1:d}", ringlabel, k - 16);
68  } else if (k > 16 + nTEClayers) {
69  return fmt::format("TEC+ {0}{1:d}", ringlabel, k - 16 - nTEClayers);
70  } else {
71  return "shoud never be here!";
72  }
73  }
74 
75  inline double checkConsistency(const StripClusterParameterEstimator::LocalValues& parameters,
76  double xx,
77  double xerr) {
78  double error = sqrt(parameters.second.xx() + xerr * xerr);
79  double separation = abs(parameters.first.x() - xx);
80  double consistency = separation / error;
81  return consistency;
82  }
83 
84  inline bool isDoubleSided(unsigned int iidd, const TrackerTopology* tTopo) {
85  unsigned int layer;
86  switch (DetId(iidd).subdetId()) {
88  layer = tTopo->tibLayer(iidd);
89  return (layer == 1 || layer == 2);
91  layer = tTopo->tobLayer(iidd) + 4;
92  return (layer == 5 || layer == 6);
94  layer = tTopo->tidRing(iidd) + 10;
95  return (layer == 11 || layer == 12);
97  layer = tTopo->tecRing(iidd) + 13;
98  return (layer == 14 || layer == 15 || layer == 18);
99  default:
100  return false;
101  }
102  }
103 
104  inline bool check2DPartner(unsigned int iidd, const std::vector<TrajectoryMeasurement>& traj) {
105  unsigned int partner_iidd = 0;
106  bool found2DPartner = false;
107  // first get the id of the other detector
108  if ((iidd & 0x3) == 1)
109  partner_iidd = iidd + 1;
110  if ((iidd & 0x3) == 2)
111  partner_iidd = iidd - 1;
112  // next look in the trajectory measurements for a measurement from that detector
113  // loop through trajectory measurements to find the partner_iidd
114  for (const auto& tm : traj) {
115  if (tm.recHit()->geographicalId().rawId() == partner_iidd) {
116  found2DPartner = true;
117  }
118  }
119  return found2DPartner;
120  }
121 
122  inline bool isInBondingExclusionZone(
123  unsigned int iidd, unsigned int TKlayers, double yloc, double yErr, const TrackerTopology* tTopo) {
124  constexpr float exclusionWidth = 0.4;
125  constexpr float TOBexclusion = 0.0;
126  constexpr float TECexRing5 = -0.89;
127  constexpr float TECexRing6 = -0.56;
128  constexpr float TECexRing7 = 0.60;
129 
130  //Added by Chris Edelmaier to do TEC bonding exclusion
131  const int subdetector = ((iidd >> 25) & 0x7);
132  const int ringnumber = ((iidd >> 5) & 0x7);
133 
134  bool inZone = false;
135  //New TOB and TEC bonding region exclusion zone
136  if ((TKlayers >= 5 && TKlayers < 11) || ((subdetector == 6) && ((ringnumber >= 5) && (ringnumber <= 7)))) {
137  //There are only 2 cases that we need to exclude for
138  float highzone = 0.0;
139  float lowzone = 0.0;
140  float higherr = yloc + 5.0 * yErr;
141  float lowerr = yloc - 5.0 * yErr;
142  if (TKlayers >= 5 && TKlayers < 11) {
143  //TOB zone
144  highzone = TOBexclusion + exclusionWidth;
145  lowzone = TOBexclusion - exclusionWidth;
146  } else if (ringnumber == 5) {
147  //TEC ring 5
148  highzone = TECexRing5 + exclusionWidth;
149  lowzone = TECexRing5 - exclusionWidth;
150  } else if (ringnumber == 6) {
151  //TEC ring 6
152  highzone = TECexRing6 + exclusionWidth;
153  lowzone = TECexRing6 - exclusionWidth;
154  } else if (ringnumber == 7) {
155  //TEC ring 7
156  highzone = TECexRing7 + exclusionWidth;
157  lowzone = TECexRing7 - exclusionWidth;
158  }
159  //Now that we have our exclusion region, we just have to properly identify it
160  if ((highzone <= higherr) && (highzone >= lowerr))
161  inZone = true;
162  if ((lowzone >= lowerr) && (lowzone <= higherr))
163  inZone = true;
164  if ((higherr <= highzone) && (higherr >= lowzone))
165  inZone = true;
166  if ((lowerr >= lowzone) && (lowerr <= highzone))
167  inZone = true;
168  }
169  return inZone;
170  }
171 
172  struct ClusterInfo {
173  float xResidual;
174  float xResidualPull;
175  float xLocal;
176  ClusterInfo(float xRes, float xResPull, float xLoc) : xResidual(xRes), xResidualPull(xResPull), xLocal(xLoc) {}
177  };
178 
179  inline float calcPhi(float x, float y) {
180  float phi = 0;
181  if ((x >= 0) && (y >= 0))
182  phi = std::atan(y / x);
183  else if ((x >= 0) && (y <= 0))
184  phi = std::atan(y / x) + 2 * M_PI;
185  else if ((x <= 0) && (y >= 0))
186  phi = std::atan(y / x) + M_PI;
187  else
188  phi = std::atan(y / x) + M_PI;
189  phi = phi * 180.0 / M_PI;
190 
191  return phi;
192  }
193 
194 } // namespace
195 #endif
std::pair< LocalPoint, LocalError > LocalValues
unsigned int tobLayer(const DetId &id) const
constexpr char const * layerName[numberOfLayers]
TString subdetector
unsigned int tidWheel(const DetId &id) const
unsigned int tecWheel(const DetId &id) const
unsigned int tecRing(const DetId &id) const
ring id
constexpr std::array< uint8_t, layerIndexSize > layer
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define M_PI
Definition: DetId.h:17
float x
unsigned int tidRing(const DetId &id) const
unsigned int tibLayer(const DetId &id) const