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 void replaceInString(std::string& str, const std::string& from, const std::string& to) {
27  if (from.empty())
28  return;
29  size_t start_pos = 0;
30  while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
31  str.replace(start_pos, from.length(), to);
32  start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
33  }
34  }
35 
36  inline unsigned int checkLayer(unsigned int iidd, const TrackerTopology* tTopo) {
37  switch (DetId(iidd).subdetId()) {
39  return tTopo->tibLayer(iidd);
41  return tTopo->tobLayer(iidd) + bounds::k_LayersAtTIBEnd;
43  return tTopo->tidWheel(iidd) + bounds::k_LayersAtTOBEnd;
45  return tTopo->tecWheel(iidd) + bounds::k_LayersAtTIDEnd;
46  default:
47  return bounds::k_LayersStart;
48  }
49  }
50 
51  inline std::string layerName(unsigned int k, const bool showRings, const unsigned int nTEClayers) {
52  const std::string ringlabel{showRings ? "R" : "D"};
53  if (k > bounds::k_LayersStart && k <= bounds::k_LayersAtTIBEnd) {
54  return fmt::format("TIB L{:d}", k);
55  } else if (k > bounds::k_LayersAtTIBEnd && k <= bounds::k_LayersAtTOBEnd) {
56  return fmt::format("TOB L{:d}", k - bounds::k_LayersAtTIBEnd);
57  } else if (k > bounds::k_LayersAtTOBEnd && k <= bounds::k_LayersAtTIDEnd) {
58  return fmt::format("TID {0}{1:d}", ringlabel, k - bounds::k_LayersAtTOBEnd);
59  } else if (k > bounds::k_LayersAtTIDEnd && k <= bounds::k_LayersAtTIDEnd + nTEClayers) {
60  return fmt::format("TEC {0}{1:d}", ringlabel, k - bounds::k_LayersAtTIDEnd);
61  } else {
62  return "should never be here!";
63  }
64  }
65 
66  inline std::string layerSideName(Long_t k, const bool showRings, const unsigned int nTEClayers) {
67  const std::string ringlabel{showRings ? "R" : "D"};
68  if (k > bounds::k_LayersStart && k <= bounds::k_LayersAtTIBEnd) {
69  return fmt::format("TIB L{:d}", k);
70  } else if (k > bounds::k_LayersAtTIBEnd && k <= bounds::k_LayersAtTOBEnd) {
71  return fmt::format("TOB L{:d}", k - bounds::k_LayersAtTIBEnd);
72  } else if (k > bounds::k_LayersAtTOBEnd && k < 14) {
73  return fmt::format("TID- {0}{1:d}", ringlabel, k - bounds::k_LayersAtTOBEnd);
74  } else if (k > 13 && k < 17) {
75  return fmt::format("TID+ {0}{1:d}", ringlabel, k - 13);
76  } else if (k > 16 && k < 17 + nTEClayers) {
77  return fmt::format("TEC- {0}{1:d}", ringlabel, k - 16);
78  } else if (k > 16 + nTEClayers) {
79  return fmt::format("TEC+ {0}{1:d}", ringlabel, k - 16 - nTEClayers);
80  } else {
81  return "shoud never be here!";
82  }
83  }
84 
85  inline double checkConsistency(const StripClusterParameterEstimator::LocalValues& parameters,
86  double xx,
87  double xerr) {
88  double error = sqrt(parameters.second.xx() + xerr * xerr);
89  double separation = abs(parameters.first.x() - xx);
90  double consistency = separation / error;
91  return consistency;
92  }
93 
94  inline bool isDoubleSided(unsigned int iidd, const TrackerTopology* tTopo) {
95  unsigned int layer;
96  switch (DetId(iidd).subdetId()) {
98  layer = tTopo->tibLayer(iidd);
99  return (layer == 1 || layer == 2);
101  layer = tTopo->tobLayer(iidd) + 4;
102  return (layer == 5 || layer == 6);
104  layer = tTopo->tidRing(iidd) + 10;
105  return (layer == 11 || layer == 12);
107  layer = tTopo->tecRing(iidd) + 13;
108  return (layer == 14 || layer == 15 || layer == 18);
109  default:
110  return false;
111  }
112  }
113 
114  inline bool check2DPartner(unsigned int iidd, const std::vector<TrajectoryMeasurement>& traj) {
115  unsigned int partner_iidd = 0;
116  bool found2DPartner = false;
117  // first get the id of the other detector
118  if ((iidd & 0x3) == 1)
119  partner_iidd = iidd + 1;
120  if ((iidd & 0x3) == 2)
121  partner_iidd = iidd - 1;
122  // next look in the trajectory measurements for a measurement from that detector
123  // loop through trajectory measurements to find the partner_iidd
124  for (const auto& tm : traj) {
125  if (tm.recHit()->geographicalId().rawId() == partner_iidd) {
126  found2DPartner = true;
127  }
128  }
129  return found2DPartner;
130  }
131 
132  inline bool isInBondingExclusionZone(
133  unsigned int iidd, unsigned int TKlayers, double yloc, double yErr, const TrackerTopology* tTopo) {
134  constexpr float exclusionWidth = 0.4;
135  constexpr float TOBexclusion = 0.0;
136  constexpr float TECexRing5 = -0.89;
137  constexpr float TECexRing6 = -0.56;
138  constexpr float TECexRing7 = 0.60;
139 
140  //Added by Chris Edelmaier to do TEC bonding exclusion
141  const int subdetector = ((iidd >> 25) & 0x7);
142  const int ringnumber = ((iidd >> 5) & 0x7);
143 
144  bool inZone = false;
145  //New TOB and TEC bonding region exclusion zone
146  if ((TKlayers >= 5 && TKlayers < 11) || ((subdetector == 6) && ((ringnumber >= 5) && (ringnumber <= 7)))) {
147  //There are only 2 cases that we need to exclude for
148  float highzone = 0.0;
149  float lowzone = 0.0;
150  float higherr = yloc + 5.0 * yErr;
151  float lowerr = yloc - 5.0 * yErr;
152  if (TKlayers >= 5 && TKlayers < 11) {
153  //TOB zone
154  highzone = TOBexclusion + exclusionWidth;
155  lowzone = TOBexclusion - exclusionWidth;
156  } else if (ringnumber == 5) {
157  //TEC ring 5
158  highzone = TECexRing5 + exclusionWidth;
159  lowzone = TECexRing5 - exclusionWidth;
160  } else if (ringnumber == 6) {
161  //TEC ring 6
162  highzone = TECexRing6 + exclusionWidth;
163  lowzone = TECexRing6 - exclusionWidth;
164  } else if (ringnumber == 7) {
165  //TEC ring 7
166  highzone = TECexRing7 + exclusionWidth;
167  lowzone = TECexRing7 - exclusionWidth;
168  }
169  //Now that we have our exclusion region, we just have to properly identify it
170  if ((highzone <= higherr) && (highzone >= lowerr))
171  inZone = true;
172  if ((lowzone >= lowerr) && (lowzone <= higherr))
173  inZone = true;
174  if ((higherr <= highzone) && (higherr >= lowzone))
175  inZone = true;
176  if ((lowerr >= lowzone) && (lowerr <= highzone))
177  inZone = true;
178  }
179  return inZone;
180  }
181 
182  struct ClusterInfo {
183  float xResidual;
184  float xResidualPull;
185  float xLocal;
186  ClusterInfo(float xRes, float xResPull, float xLoc) : xResidual(xRes), xResidualPull(xResPull), xLocal(xLoc) {}
187  };
188 
189  inline float calcPhi(float x, float y) {
190  float phi = 0;
191  if ((x >= 0) && (y >= 0))
192  phi = std::atan(y / x);
193  else if ((x >= 0) && (y <= 0))
194  phi = std::atan(y / x) + 2 * M_PI;
195  else if ((x <= 0) && (y >= 0))
196  phi = std::atan(y / x) + M_PI;
197  else
198  phi = std::atan(y / x) + M_PI;
199  phi = phi * 180.0 / M_PI;
200 
201  return phi;
202  }
203 
204 } // namespace
205 #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
#define str(s)