ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigConfiguration
TrigConfL1Data
Root
L1PSNumber.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
//
7
//NAME: L1PSNumber.cxx
8
//PACKAGE: TrigConfL1Data
9
//
10
//AUTHOR: Tiago Perez (DESY) Tiago.Perez@desy.de
11
//CREATED: 19. Feb. 2010, 11:18 AM
12
//
13
//PURPOSE: Auxiliar class to handle factional prescales. This class holds the
14
// 3 numbers needed to describe a fractional prescale as S. Haas and D. Berge
15
// defined them.
16
// Typically the constructor:
17
// L1PSNumber(int64_t) from DB
18
// L1PSNumber(float) or L1PSNumber(n,m,d) form XML
19
// will be calledd and after that we can "get" the appropriate numbers
20
// for the different arrays.
22
23
24
#include "
TrigConfL1Data/L1PSNumber.h
"
25
#include <cmath>
26
#include <sstream>
27
28
29
namespace
TrigConf
{
30
31
L1PSNumber::L1PSNumber
() {
32
m_n
= 1;
33
m_m
= 1;
34
m_d
= 1;
35
m_s
= -1;
36
m_psFloat
= -1.0;
37
m_psLong
= -1;
38
}
39
43
L1PSNumber::L1PSNumber
(
const
int
ps) {
44
if
(ps >= 1) {
45
m_n
= ps;
46
m_s
= 1;
47
}
else
if
(ps < 1 && ps>-1) {
48
//invalid ps, set to default -1
49
m_n
= 1;
50
m_s
= -1;
51
}
else
{
52
m_n
= -ps;
53
m_s
= -1;
54
}
55
m_m
= 0;
56
m_d
= 0;
57
m_psFloat
= (float)
m_n
;
58
m_psLong
= (int64_t)
m_n
;
59
}
60
64
L1PSNumber::L1PSNumber
(
const
int64_t ps) {
65
L1PSNumber::setInt64
(ps);
66
}
67
71
L1PSNumber::L1PSNumber
(
const
int
nn,
const
unsigned
int
mm,
72
const
unsigned
int
dd,
const
int
ss
= 1) {
73
if
(
validate
(nn, mm, dd,
ss
)) {
74
m_psLong
=
makeLong
(
m_n
,
m_m
,
m_d
);
75
}
else
{
76
m_psLong
= -1;
77
}
78
}
79
83
L1PSNumber::L1PSNumber
(
const
float
ps) {
84
int64_t i64 =
decodeFloat
(ps);
85
setInt64
(i64);
86
}
87
93
bool
L1PSNumber::validate
(
int
nn,
unsigned
int
mm,
unsigned
int
dd,
int
ss
= 1) {
94
bool
ret =
false
;
95
if
(nn <= -1 || nn >= 1) {
96
if
(nn < 0) {
97
m_n
= -nn;
98
m_s
= -1;
99
}
else
if
(nn >= 1) {
100
m_n
= nn;
101
m_s
=
ss
;
102
}
103
m_m
= mm;
104
m_d
= dd;
105
m_psFloat
= (float)
m_s
*
m_n
* (
m_m
+
m_d
+ 1.0) / (
m_m
+ 1.0);
106
ret =
true
;
107
}
else
{
108
m_n
= 1;
109
m_s
= -1;
110
m_m
= 0;
111
m_d
= 0;
112
m_psFloat
= -1.0;
113
ret =
false
;
114
}
115
return
ret;
116
}
117
124
void
L1PSNumber::setInt64
(
const
int64_t prescaleBitArray) {
125
unsigned
int
nTemp = 1;
126
unsigned
int
mTemp = 0;
127
unsigned
int
dTemp = 0;
128
int
sTemp = -1;
129
130
uint32_t psTemp = 1;
131
// m_psLong = -1;
132
// Take care of the sign.
133
if
(prescaleBitArray < 0) {
134
sTemp = -1;
135
psTemp = (uint32_t) (-1 * prescaleBitArray);
136
}
else
{
137
sTemp = 1;
138
psTemp = (uint32_t) prescaleBitArray;
139
}
143
nTemp = psTemp&
NMASK
;
144
mTemp = ((psTemp &
MMASK
) >>
MSHIFT
);
145
dTemp = ((psTemp &
DMASK
) >>
DSHIFT
);
146
L1PSNumber::validate
(nTemp, mTemp, dTemp, sTemp);
147
m_psLong
= prescaleBitArray;
148
}
149
153
std::string
L1PSNumber::write
() {
154
std::stringstream
ss
;
155
if
(
m_m
== 0 &&
m_d
== 0) {
156
ss
<<
getInt32
();
157
}
else
{
158
ss
<<
m_psFloat
;
159
}
160
return
ss
.str();
161
}
162
167
int64_t
L1PSNumber::decodeFloat
(
const
float
psF) {
168
int64_t ret = -1;
169
int
tmpN = (int) psF;
170
float
psOne = psF / (float) tmpN;
171
float
diff
= 10;
172
unsigned
int
mm = 0;
173
unsigned
int
dd = 0;
174
float
tmpPS;
175
float
tmpDiff;
176
// If the number is larger than 2^24 ret -1.
177
if
(std::abs(tmpN) <= (
int
)
NMASK
) {
178
// if psF is Int, ret psF.
179
if
(tmpN == psF) {
180
ret = (int64_t) psF;
181
}
else
{
182
// Check the nearest Combination of N,M & D.
183
for
(
int
i = 0; i <
s_auxLength
; i++) {
184
unsigned
int
tmpM =
s_psAuxValues
[i][0];
185
unsigned
int
tmpD =
s_psAuxValues
[i][1];
186
tmpPS = (float) ((tmpM + tmpD + 1.0) / (tmpM + 1.0));
187
tmpDiff = fabs(tmpPS - psOne);
188
if
(tmpPS * tmpN >= tmpN + 1) {
189
break
;
190
}
191
if
(tmpDiff <
diff
) {
192
diff
= tmpDiff;
193
mm = tmpM;
194
dd = tmpD;
195
}
196
}
197
ret =
L1PSNumber::encodeNMD
(tmpN, mm, dd);
198
}
199
}
200
return
ret;
201
}
202
207
int64_t
L1PSNumber::encodeNMD
(
const
int
nn,
const
unsigned
int
mm,
208
const
unsigned
int
dd) {
209
int64_t ret = -1;
210
unsigned
int
nTemp = 1;
211
int
sTemp = 1;
212
if
(nn < 0) {
213
nTemp = -nn;
214
sTemp = -1;
215
}
else
{
216
nTemp = nn;
217
sTemp = 1;
218
}
219
ret =
L1PSNumber::makeLong
(nTemp, mm, dd);
220
ret = sTemp*ret;
221
return
ret;
222
}
223
228
int64_t
L1PSNumber::makeLong
(
unsigned
int
nn,
unsigned
int
mm,
229
unsigned
int
dd) {
230
int64_t ret;
231
ret = (mm & 0xF);
232
ret = (ret <<
MSHIFT
);
233
ret = (ret | ((dd & 0xF) <<
DSHIFT
));
234
ret = (ret | (nn &
NMASK
));
235
return
ret;
236
}
237
238
243
const
unsigned
int
L1PSNumber::s_psAuxValues
[79][2] = {
244
{15, 1},
245
{14, 1},
246
{13, 1},
247
{12, 1},
248
{11, 1},
249
{10, 1},
250
{9, 1},
251
{8, 1},
252
{15, 2},
253
{14, 2},
254
{13, 2},
255
{12, 2},
256
{11, 2},
257
{10, 2},
258
{15, 3},
259
{14, 3},
260
{13, 3},
261
{8, 2},
262
{12, 3},
263
{15, 4},
264
{14, 4},
265
{10, 3},
266
{13, 4},
267
{9, 3},
268
{12, 4},
269
{15, 5},
270
{14, 5},
271
{13, 5},
272
{10, 4},
273
{15, 6},
274
{12, 5},
275
{14, 6},
276
{11, 5},
277
{13, 6},
278
{15, 7},
279
{8, 4},
280
{10, 5},
281
{12, 6},
282
{14, 7},
283
{15, 8},
284
{14, 8},
285
{12, 7},
286
{10, 6},
287
{8, 5},
288
{15, 9},
289
{13, 8},
290
{11, 7},
291
{14, 9},
292
{12, 8},
293
{15, 10},
294
{10, 7},
295
{13, 9},
296
{14, 10},
297
{15, 11},
298
{12, 9},
299
{9, 7},
300
{13, 10},
301
{10, 8},
302
{14, 11},
303
{15, 12},
304
{12, 10},
305
{8, 7},
306
{13, 11},
307
{14, 12},
308
{15, 13},
309
{10, 9},
310
{11, 10},
311
{12, 11},
312
{13, 12},
313
{14, 13},
314
{15, 14},
315
{8, 8},
316
{9, 9},
317
{10, 10},
318
{11, 11},
319
{12, 12},
320
{13, 13},
321
{14, 14},
322
{15, 15}
323
};
324
325
}
L1PSNumber.h
ss
static Double_t ss
Definition
LArPhysWaveHECTool.cxx:37
diff
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition
Jet.cxx:631
TrigConf::L1PSNumber::m_d
unsigned int m_d
Definition
L1PSNumber.h:37
TrigConf::L1PSNumber::makeLong
static int64_t makeLong(unsigned int n, unsigned int m, unsigned int d)
Returns the POSITIVE int64_t of 3 ints.
Definition
L1PSNumber.cxx:228
TrigConf::L1PSNumber::write
std::string write()
Writes nicely the ps value.
Definition
L1PSNumber.cxx:153
TrigConf::L1PSNumber::NMASK
static const uint32_t NMASK
Definition
L1PSNumber.h:42
TrigConf::L1PSNumber::setInt64
void setInt64(const int64_t tmpLong)
Sets the N,M,D values from a Int64_t prescale value.
Definition
L1PSNumber.cxx:124
TrigConf::L1PSNumber::m_n
unsigned int m_n
Definition
L1PSNumber.h:35
TrigConf::L1PSNumber::getInt32
int getInt32() const
Definition
L1PSNumber.h:78
TrigConf::L1PSNumber::MSHIFT
static const int MSHIFT
Definition
L1PSNumber.h:45
TrigConf::L1PSNumber::MMASK
static const uint32_t MMASK
Definition
L1PSNumber.h:43
TrigConf::L1PSNumber::s_auxLength
static const int s_auxLength
Definition
L1PSNumber.h:55
TrigConf::L1PSNumber::validate
bool validate(const int nn, const unsigned int mm, const unsigned int dd, const int ss)
Checks whether the m_n,m_m,m_d combination is valid, i.e.
Definition
L1PSNumber.cxx:93
TrigConf::L1PSNumber::s_psAuxValues
static const unsigned int s_psAuxValues[79][2]
Help array containing the allowed MD combinations (for N=1).
Definition
L1PSNumber.h:56
TrigConf::L1PSNumber::encodeNMD
static int64_t encodeNMD(const int nn, const unsigned int mm, const unsigned int dd)
Returns INT64_T prescale number with the correct sign as it is stored in DB.
Definition
L1PSNumber.cxx:207
TrigConf::L1PSNumber::m_s
int m_s
Definition
L1PSNumber.h:38
TrigConf::L1PSNumber::m_psFloat
float m_psFloat
Definition
L1PSNumber.h:39
TrigConf::L1PSNumber::m_m
unsigned int m_m
Definition
L1PSNumber.h:36
TrigConf::L1PSNumber::L1PSNumber
L1PSNumber()
Definition
L1PSNumber.cxx:31
TrigConf::L1PSNumber::DSHIFT
static const int DSHIFT
Definition
L1PSNumber.h:46
TrigConf::L1PSNumber::DMASK
static const uint32_t DMASK
Definition
L1PSNumber.h:44
TrigConf::L1PSNumber::decodeFloat
static int64_t decodeFloat(const float psF)
Calculates the NMD combination nearest to psF.
Definition
L1PSNumber.cxx:167
TrigConf::L1PSNumber::m_psLong
int64_t m_psLong
Definition
L1PSNumber.h:40
TrigConf
Forward iterator to traverse the main components of the trigger configuration.
Definition
Config.h:22
Generated on
for ATLAS Offline Software by
1.17.0