CMS 3D CMS Logo

Util.h
Go to the documentation of this file.
1 #ifndef L1Trigger_TrackFindingTracklet_interface_Util_h
2 #define L1Trigger_TrackFindingTracklet_interface_Util_h
3 
4 #include <sstream>
5 #include <cassert>
6 #include <cmath>
7 #include <algorithm>
8 
11 
12 namespace trklet {
13 
14  //Converts string in binary to hex (used in writing out memory content)
15  inline std::string hexFormat(const std::string& binary) {
16  std::stringstream ss;
17 
18  unsigned int radix = 1, value = 0;
19  for (int i = binary.length() - 1; i >= 0; i--) {
20  if (binary.at(i) != '0' && binary.at(i) != '1')
21  continue;
22  value += (binary.at(i) - '0') * radix;
23  if (radix == 8) {
24  ss << std::hex << value;
25  radix = 1;
26  value = 0;
27  } else
28  radix <<= 1;
29  }
30  if (radix != 1)
31  ss << std::hex << value;
32 
33  std::string str = ss.str() + "x0";
34  std::reverse(str.begin(), str.end());
35  return str;
36  }
37 
38  //Should be optimized by layer - now first implementation to make sure it works OK
39  inline int bendencode(double bend, bool isPS) {
40  int ibend = 2.0 * bend;
41 
42  assert(std::abs(ibend - 2.0 * bend) < 0.1);
43 
44  if (isPS) {
45  if (ibend == 0 || ibend == 1)
46  return 0;
47  if (ibend == 2 || ibend == 3)
48  return 1;
49  if (ibend == 4 || ibend == 5)
50  return 2;
51  if (ibend >= 6)
52  return 3;
53  if (ibend == -1 || ibend == -2)
54  return 4;
55  if (ibend == -3 || ibend == -4)
56  return 5;
57  if (ibend == -5 || ibend == -6)
58  return 6;
59  if (ibend <= -7)
60  return 7;
61 
62  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__
63  << " Unknown bendencode for PS module for bend = " << bend
64  << " ibend = " << ibend;
65  }
66 
67  if (ibend == 0 || ibend == 1)
68  return 0;
69  if (ibend == 2 || ibend == 3)
70  return 1;
71  if (ibend == 4 || ibend == 5)
72  return 2;
73  if (ibend == 6 || ibend == 7)
74  return 3;
75  if (ibend == 8 || ibend == 9)
76  return 4;
77  if (ibend == 10 || ibend == 11)
78  return 5;
79  if (ibend == 12 || ibend == 13)
80  return 6;
81  if (ibend >= 14)
82  return 7;
83  if (ibend == -1 || ibend == -2)
84  return 8;
85  if (ibend == -3 || ibend == -4)
86  return 9;
87  if (ibend == -5 || ibend == -6)
88  return 10;
89  if (ibend == -7 || ibend == -8)
90  return 11;
91  if (ibend == -9 || ibend == -10)
92  return 12;
93  if (ibend == -11 || ibend == -12)
94  return 13;
95  if (ibend == -13 || ibend == -14)
96  return 14;
97  if (ibend <= -15)
98  return 15;
99 
100  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__
101  << " Unknown bendencode for 2S module for bend = " << bend
102  << " ibend = " << ibend;
103  }
104 
105  //Should be optimized by layer - now first implementation to make sure it works OK
106  inline double benddecode(int ibend, bool isPS) {
107  if (isPS) {
108  if (ibend == 0)
109  return 0.25;
110  if (ibend == 1)
111  return 1.25;
112  if (ibend == 2)
113  return 2.25;
114  if (ibend == 3)
115  return 3.25;
116  if (ibend == 4)
117  return -0.75;
118  if (ibend == 5)
119  return -1.75;
120  if (ibend == 6)
121  return -2.75;
122  if (ibend == 7)
123  return -3.75;
124 
125  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__
126  << " Unknown benddecode for PS module for ibend = " << ibend;
127  }
128 
129  if (ibend == 0)
130  return 0.25;
131  if (ibend == 1)
132  return 1.25;
133  if (ibend == 2)
134  return 2.25;
135  if (ibend == 3)
136  return 3.25;
137  if (ibend == 4)
138  return 4.25;
139  if (ibend == 5)
140  return 5.25;
141  if (ibend == 6)
142  return 6.25;
143  if (ibend == 7)
144  return 7.25;
145  if (ibend == 8)
146  return -0.75;
147  if (ibend == 9)
148  return -1.75;
149  if (ibend == 10)
150  return -2.75;
151  if (ibend == 11)
152  return -3.75;
153  if (ibend == 12)
154  return -4.75;
155  if (ibend == 13)
156  return -5.75;
157  if (ibend == 14)
158  return -6.75;
159  if (ibend == 15)
160  return -7.75;
161 
162  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__
163  << " Unknown benddecode for 2S module for ibend = " << ibend;
164  }
165 
166  inline double bend(double r, double rinv, double stripPitch) {
167  constexpr double dr = 0.18;
168  double delta = r * dr * 0.5 * rinv;
169  double bend = -delta / stripPitch;
170  return bend;
171  }
172 
173  inline double rinv(double phi1, double phi2, double r1, double r2) {
174  if (r2 <= r1) { //can not form tracklet
175  return 20.0;
176  }
177 
178  double dphi = phi2 - phi1;
179  double dr = r2 - r1;
180 
181  return 2.0 * sin(dphi) / dr / sqrt(1.0 + 2 * r1 * r2 * (1.0 - cos(dphi)) / (dr * dr));
182  }
183 
184 }; // namespace trklet
185 #endif
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
trklet::bendencode
int bendencode(double bend, bool isPS)
Definition: Util.h:39
cms::cuda::assert
assert(be >=bs)
groupFilesInBlocks.reverse
reverse
Definition: groupFilesInBlocks.py:131
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
str
#define str(s)
Definition: TestProcessor.cc:52
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
trklet::rinv
double rinv(double phi1, double phi2, double r1, double r2)
Definition: Util.h:173
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
value
Definition: value.py:1
trklet
Definition: AllProjectionsMemory.h:9
alignCSCRings.r
r
Definition: alignCSCRings.py:93
diffTwoXMLs.r1
r1
Definition: diffTwoXMLs.py:53
trklet::bend
double bend(double r, double rinv, double stripPitch)
Definition: Util.h:166
relativeConstraints.value
value
Definition: relativeConstraints.py:53
flavorHistoryFilter_cfi.dr
dr
Definition: flavorHistoryFilter_cfi.py:37
Exception
Definition: hltDiff.cc:245
Exception.h
trklet::benddecode
double benddecode(int ibend, bool isPS)
Definition: Util.h:106
trklet::hexFormat
std::string hexFormat(const std::string &binary)
Definition: Util.h:15
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22