1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
//-------------------------------------------------
//
/** \class L1MuGMTReadoutRecord
*
* L1 Global Muon Trigger Readout Record
*
* Contains the data that the GMT will send to readout
* for one bunch crossing.
*/
//
//
// Author :
// H. Sakulin HEPHY Vienna
//
// Migrated to CMSSW:
// I. Mikulec
//
//--------------------------------------------------
//-----------------------
// This Class's Header --
//-----------------------
#include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutRecord.h"
//---------------
// C++ Headers --
//---------------
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
//-------------------------------
// Collaborating Class Headers --
//-------------------------------
using namespace std;
//--------------------------------------
// class L1MuGMTReadoutRecord
//--------------------------------------
//----------------
// Constructors --
//----------------
L1MuGMTReadoutRecord::L1MuGMTReadoutRecord() : m_InputCands(16), m_BarrelCands(4), m_ForwardCands(4), m_GMTCands(4) {
reset();
}
L1MuGMTReadoutRecord::L1MuGMTReadoutRecord(int bxie)
: m_InputCands(16), m_BarrelCands(4), m_ForwardCands(4), m_GMTCands(4) {
reset();
m_BxInEvent = bxie;
}
//--------------
// Destructor --
//--------------
L1MuGMTReadoutRecord::~L1MuGMTReadoutRecord() {}
//--------------
// Operations --
//--------------
/// reset the record
void L1MuGMTReadoutRecord::reset() {
m_BxNr = 0;
m_BxInEvent = 0;
m_EvNr = 0;
m_BCERR = 0;
std::vector<L1MuRegionalCand>::iterator itr;
for (itr = m_InputCands.begin(); itr != m_InputCands.end(); itr++)
(*itr).reset();
std::vector<L1MuGMTExtendedCand>::iterator itg;
for (itg = m_BarrelCands.begin(); itg != m_BarrelCands.end(); itg++)
(*itg).reset();
for (itg = m_ForwardCands.begin(); itg != m_ForwardCands.end(); itg++)
(*itg).reset();
for (itg = m_GMTCands.begin(); itg != m_GMTCands.end(); itg++)
(*itg).reset();
for (int i = 0; i < 8; i++) {
m_MIPbits[i] = 0;
m_Quietbits[i] = 0;
}
}
/// get GMT candidates vector
vector<L1MuGMTExtendedCand> L1MuGMTReadoutRecord::getGMTCands() const {
vector<L1MuGMTExtendedCand> cands;
std::vector<L1MuGMTExtendedCand>::const_iterator it;
for (it = m_BarrelCands.begin(); it != m_BarrelCands.end(); it++) {
if ((*it).getDataWord() != 0)
cands.push_back(*it);
}
for (it = m_ForwardCands.begin(); it != m_ForwardCands.end(); it++) {
if ((*it).getDataWord() != 0)
cands.push_back(*it);
}
// sort by rank
stable_sort(cands.begin(), cands.end(), L1MuGMTExtendedCand::rankRef);
return cands;
}
/// get GMT candidates vector as stored in data (no rank info)
vector<L1MuGMTExtendedCand>& L1MuGMTReadoutRecord::getGMTCandsData() { return m_GMTCands; }
/// get GMT barrel candidates vector
vector<L1MuGMTExtendedCand> L1MuGMTReadoutRecord::getGMTBrlCands() const {
vector<L1MuGMTExtendedCand> cands;
std::vector<L1MuGMTExtendedCand>::const_iterator it;
for (it = m_BarrelCands.begin(); it != m_BarrelCands.end(); it++) {
if ((*it).getDataWord() != 0)
cands.push_back(*it);
}
return cands;
}
/// get GMT forward candidates vector
vector<L1MuGMTExtendedCand> L1MuGMTReadoutRecord::getGMTFwdCands() const {
vector<L1MuGMTExtendedCand> cands;
std::vector<L1MuGMTExtendedCand>::const_iterator it;
for (it = m_ForwardCands.begin(); it != m_ForwardCands.end(); it++) {
if ((*it).getDataWord() != 0)
cands.push_back(*it);
}
return cands;
}
/// get DT candidates vector
vector<L1MuRegionalCand> L1MuGMTReadoutRecord::getDTBXCands() const {
vector<L1MuRegionalCand> cands;
for (int i = 0; i < 4; i++)
if (m_InputCands[i].getDataWord() != 0)
cands.push_back(m_InputCands[i]);
return cands;
}
/// get CSC candidates vector
vector<L1MuRegionalCand> L1MuGMTReadoutRecord::getCSCCands() const {
vector<L1MuRegionalCand> cands;
for (int i = 0; i < 4; i++)
if (m_InputCands[i + 8].getDataWord() != 0)
cands.push_back(m_InputCands[i + 8]);
return cands;
}
/// get barrel RPC candidates vector
vector<L1MuRegionalCand> L1MuGMTReadoutRecord::getBrlRPCCands() const {
vector<L1MuRegionalCand> cands;
for (int i = 0; i < 4; i++)
if (m_InputCands[i + 4].getDataWord() != 0)
cands.push_back(m_InputCands[i + 4]);
return cands;
}
/// get forward RPC candidates vector
vector<L1MuRegionalCand> L1MuGMTReadoutRecord::getFwdRPCCands() const {
vector<L1MuRegionalCand> cands;
for (int i = 0; i < 4; i++)
if (m_InputCands[i + 12].getDataWord() != 0)
cands.push_back(m_InputCands[i + 12]);
return cands;
}
/// get MIP bit
unsigned L1MuGMTReadoutRecord::getMIPbit(int eta, int phi) const {
if (phi < 0 || phi > 17 || eta < 0 || eta > 13)
return 0;
int idx = eta * 18 + phi;
int idx_word = idx / 32;
int idx_bit = idx % 32;
unsigned mask = 1 << (idx_bit - 1);
return (m_MIPbits[idx_word] & mask) ? 1 : 0;
}
/// get Quiet bit
unsigned L1MuGMTReadoutRecord::getQuietbit(int eta, int phi) const {
if (phi < 0 || phi > 17 || eta < 0 || eta > 13)
return 0;
int idx = eta * 18 + phi;
int idx_word = idx / 32;
int idx_bit = idx % 32;
unsigned mask = 1 << (idx_bit - 1);
return (m_Quietbits[idx_word] & mask) ? 1 : 0;
}
//
// Setters
//
/// set Regional Candidates
void L1MuGMTReadoutRecord::setInputCand(int nr, L1MuRegionalCand const& cand) {
if (nr >= 0 && nr < 16) {
m_InputCands[nr] = cand;
}
}
/// set Regional Candidates
void L1MuGMTReadoutRecord::setInputCand(int nr, unsigned data) {
if (nr >= 0 && nr < 16) {
m_InputCands[nr] = L1MuRegionalCand(data, m_BxInEvent);
}
}
/// set GMT barrel candidate
void L1MuGMTReadoutRecord::setGMTBrlCand(int nr, L1MuGMTExtendedCand const& cand) {
if (nr >= 0 && nr < 4) {
m_BarrelCands[nr] = cand;
}
}
/// set GMT barrel candidate
void L1MuGMTReadoutRecord::setGMTBrlCand(int nr, unsigned data, unsigned rank) {
if (nr >= 0 && nr < 4) {
m_BarrelCands[nr] = L1MuGMTExtendedCand(data, rank, m_BxInEvent);
}
}
/// set GMT forward candidate
void L1MuGMTReadoutRecord::setGMTFwdCand(int nr, L1MuGMTExtendedCand const& cand) {
if (nr >= 0 && nr < 4) {
m_ForwardCands[nr] = cand;
}
}
/// set GMT forward candidate
void L1MuGMTReadoutRecord::setGMTFwdCand(int nr, unsigned data, unsigned rank) {
if (nr >= 0 && nr < 4) {
m_ForwardCands[nr] = L1MuGMTExtendedCand(data, rank, m_BxInEvent);
}
}
/// set GMT candidate
void L1MuGMTReadoutRecord::setGMTCand(int nr, L1MuGMTExtendedCand const& cand) {
if (nr >= 0 && nr < 4) {
m_GMTCands[nr] = cand;
}
}
/// set GMT candidate
void L1MuGMTReadoutRecord::setGMTCand(int nr, unsigned data) {
if (nr >= 0 && nr < 4) {
m_GMTCands[nr] = L1MuGMTExtendedCand(data, 0, m_BxInEvent);
}
}
/// get rank of brl cand i
unsigned L1MuGMTReadoutRecord::getBrlRank(int i) const { return m_BarrelCands[i].rank(); }
/// get rank of fwd cand i
unsigned L1MuGMTReadoutRecord::getFwdRank(int i) const { return m_ForwardCands[i].rank(); }
/// set rank of brl cand i
void L1MuGMTReadoutRecord::setBrlRank(int i, unsigned value) {
if (i >= 0 && i < 4) {
m_BarrelCands[i].setRank(value);
}
}
/// set rank of fwd cand i
void L1MuGMTReadoutRecord::setFwdRank(int i, unsigned value) {
if (i >= 0 && i < 4) {
m_ForwardCands[i].setRank(value);
}
}
/// set MIP bit
void L1MuGMTReadoutRecord::setMIPbit(int eta, int phi) {
if (phi < 0 || phi > 17 || eta < 0 || eta > 13)
return;
int idx = eta * 18 + phi;
int idx_word = idx / 32;
int idx_bit = idx % 32;
unsigned mask = 1 << (idx_bit - 1);
m_MIPbits[idx_word] |= mask;
}
/// set Quiet bit
void L1MuGMTReadoutRecord::setQuietbit(int eta, int phi) {
if (phi < 0 || phi > 17 || eta < 0 || eta > 13)
return;
int idx = eta * 18 + phi;
int idx_word = idx / 32;
int idx_bit = idx % 32;
unsigned mask = 0;
if (idx_bit > 0)
mask = 1 << (idx_bit - 1);
m_Quietbits[idx_word] |= mask;
}
|