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