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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
|
// -*- C++ -*-
//
// Package: L1Trigger
// Class : L1ParticleMap
//
/**\class L1ParticleMap \file L1ParticleMap.cc DataFormats/L1Trigger/src/L1ParticleMap.cc \author Werner Sun
*/
//
// Original Author: Werner Sun
// Created: Wed Jul 26 14:42:56 EDT 2006
//
// system include files
// user include files
#include "DataFormats/L1Trigger/interface/L1ParticleMap.h"
#include "DataFormats/L1Trigger/interface/L1EmParticle.h"
#include "DataFormats/L1Trigger/interface/L1JetParticle.h"
#include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
#include "FWCore/Concurrency/interface/hardware_pause.h"
using namespace l1extra;
//
// constants, enums and typedefs
//
//
// static data member definitions
//
// EG = isolated OR non-isolated
// Jet = central OR forward OR tau
const std::string L1ParticleMap::triggerNames_[kNumOfL1TriggerTypes] = {"L1_SingleMu3",
"L1_SingleMu5",
"L1_SingleMu7",
"L1_SingleMu10",
"L1_SingleMu14",
"L1_SingleMu20",
"L1_SingleMu25",
"L1_SingleIsoEG5",
"L1_SingleIsoEG8",
"L1_SingleIsoEG10",
"L1_SingleIsoEG12",
"L1_SingleIsoEG15",
"L1_SingleIsoEG20",
"L1_SingleIsoEG25",
"L1_SingleEG5",
"L1_SingleEG8",
"L1_SingleEG10",
"L1_SingleEG12",
"L1_SingleEG15",
"L1_SingleEG20",
"L1_SingleEG25",
"L1_SingleJet15",
"L1_SingleJet20",
"L1_SingleJet30",
"L1_SingleJet50",
"L1_SingleJet70",
"L1_SingleJet100",
"L1_SingleJet150",
"L1_SingleJet200",
"L1_SingleTauJet10",
"L1_SingleTauJet20",
"L1_SingleTauJet30",
"L1_SingleTauJet35",
"L1_SingleTauJet40",
"L1_SingleTauJet60",
"L1_SingleTauJet80",
"L1_SingleTauJet100",
"L1_HTT100",
"L1_HTT200",
"L1_HTT250",
"L1_HTT300",
"L1_HTT400",
"L1_HTT500",
"L1_ETM10",
"L1_ETM15",
"L1_ETM20",
"L1_ETM30",
"L1_ETM40",
"L1_ETM50",
"L1_ETM60",
"L1_ETT60",
"L1_DoubleMu3",
"L1_DoubleIsoEG8",
"L1_DoubleIsoEG10",
"L1_DoubleEG5",
"L1_DoubleEG10",
"L1_DoubleEG15",
"L1_DoubleJet70",
"L1_DoubleJet100",
"L1_DoubleTauJet20",
"L1_DoubleTauJet30",
"L1_DoubleTauJet35",
"L1_DoubleTauJet40",
"L1_Mu3_IsoEG5",
"L1_Mu5_IsoEG10",
"L1_Mu3_EG12",
"L1_Mu3_Jet15",
"L1_Mu5_Jet15",
"L1_Mu3_Jet70",
"L1_Mu5_Jet20",
"L1_Mu5_TauJet20",
"L1_Mu5_TauJet30",
"L1_IsoEG10_EG10",
"L1_IsoEG10_Jet15",
"L1_IsoEG10_Jet20",
"L1_IsoEG10_Jet30",
"L1_IsoEG10_Jet70",
"L1_IsoEG10_TauJet20",
"L1_IsoEG10_TauJet30",
"L1_EG10_Jet15",
"L1_EG12_Jet20",
"L1_EG12_Jet70",
"L1_EG12_TauJet40",
"L1_Jet70_TauJet40",
"L1_Mu3_HTT200",
"L1_IsoEG10_HTT200",
"L1_EG12_HTT200",
"L1_Jet70_HTT200",
"L1_TauJet40_HTT200",
"L1_Mu3_ETM30",
"L1_IsoEG10_ETM30",
"L1_EG12_ETM30",
"L1_Jet70_ETM40",
"L1_TauJet20_ETM20",
"L1_TauJet30_ETM30",
"L1_TauJet30_ETM40",
"L1_HTT100_ETM30",
"L1_TripleMu3",
"L1_TripleIsoEG5",
"L1_TripleEG10",
"L1_TripleJet50",
"L1_TripleTauJet40",
"L1_DoubleMu3_IsoEG5",
"L1_DoubleMu3_EG10",
"L1_DoubleIsoEG5_Mu3",
"L1_DoubleEG10_Mu3",
"L1_DoubleMu3_HTT200",
"L1_DoubleIsoEG5_HTT200",
"L1_DoubleEG10_HTT200",
"L1_DoubleJet50_HTT200",
"L1_DoubleTauJet40_HTT200",
"L1_DoubleMu3_ETM20",
"L1_DoubleIsoEG5_ETM20",
"L1_DoubleEG10_ETM20",
"L1_DoubleJet50_ETM20",
"L1_DoubleTauJet40_ETM20",
"L1_QuadJet30",
"L1_ExclusiveDoubleIsoEG4",
"L1_ExclusiveDoubleJet60",
"L1_ExclusiveJet25_Gap_Jet25",
"L1_IsoEG10_Jet20_ForJet10",
"L1_MinBias_HTT10",
"L1_ZeroBias"};
namespace {
enum IndexComboStates { kUnset, kSetting, kSet };
}
//
// constructors and destructor
//
L1ParticleMap::L1ParticleMap() {}
L1ParticleMap::L1ParticleMap(L1TriggerType triggerType,
bool triggerDecision,
const L1ObjectTypeVector& objectTypes,
const L1EmParticleVectorRef& emParticles,
const L1JetParticleVectorRef& jetParticles,
const L1MuonParticleVectorRef& muonParticles,
const L1EtMissParticleRefProd& etMissParticle,
const L1IndexComboVector& indexCombos)
: triggerType_(triggerType),
triggerDecision_(triggerDecision),
indexCombosState_{static_cast<char>(!indexCombos.empty() ? kSet : IndexComboStates::kUnset)},
objectTypes_(objectTypes),
emParticles_(emParticles),
jetParticles_(jetParticles),
muonParticles_(muonParticles),
etMissParticle_(etMissParticle),
indexCombos_(indexCombos) {}
L1ParticleMap::L1ParticleMap(const L1ParticleMap& rhs)
: triggerType_(rhs.triggerType_),
triggerDecision_(rhs.triggerDecision_),
indexCombosState_(IndexComboStates::kUnset),
objectTypes_(rhs.objectTypes_),
emParticles_(rhs.emParticles_),
jetParticles_(rhs.jetParticles_),
muonParticles_(rhs.muonParticles_),
etMissParticle_(rhs.etMissParticle_),
indexCombos_() {
// do actual copying here;
if (rhs.indexCombosState_.load(std::memory_order_acquire) == kSet) {
indexCombos_ = rhs.indexCombos_;
indexCombosState_.store(kSet, std::memory_order_release);
}
}
L1ParticleMap::~L1ParticleMap() {}
//
// assignment operators
//
L1ParticleMap& L1ParticleMap::operator=(const L1ParticleMap& rhs) {
//An exception safe implementation is
L1ParticleMap temp(rhs);
swap(temp);
return *this;
}
//
// member functions
//
void L1ParticleMap::swap(L1ParticleMap& rhs) {
std::swap(triggerType_, rhs.triggerType_);
std::swap(triggerDecision_, rhs.triggerDecision_);
indexCombosState_.store(
rhs.indexCombosState_.exchange(indexCombosState_.load(std::memory_order_acquire), std::memory_order_acq_rel),
std::memory_order_release);
std::swap(objectTypes_, rhs.objectTypes_);
std::swap(emParticles_, rhs.emParticles_);
std::swap(jetParticles_, rhs.jetParticles_);
std::swap(muonParticles_, rhs.muonParticles_);
std::swap(etMissParticle_, rhs.etMissParticle_);
std::swap(indexCombos_, rhs.indexCombos_);
}
//
// const member functions
//
const L1ParticleMap::L1IndexComboVector& L1ParticleMap::indexCombos() const {
if (kSet != indexCombosState_.load(std::memory_order_acquire)) {
setIndexCombos();
}
return indexCombos_;
}
void L1ParticleMap::setIndexCombos() const {
// Determine the number of non-global objects. There should be 0 or 1.
int numNonGlobal = 0;
L1ObjectType nonGlobalType = kNumOfL1ObjectTypes;
int nonGlobalIndex = -1;
L1IndexComboVector tempIndexCombos;
for (int i = 0; i < numOfObjects(); ++i) {
if (!objectTypeIsGlobal(objectTypes_[i])) {
++numNonGlobal;
nonGlobalType = objectTypes_[i];
nonGlobalIndex = i;
}
}
if (numNonGlobal == 0) {
// Dummy entry for each object type.
L1IndexCombo tmpCombo;
tmpCombo.reserve(numOfObjects());
for (int i = 0; i < numOfObjects(); ++i) {
tmpCombo.push_back(0);
}
tempIndexCombos.push_back(tmpCombo);
} else if (numNonGlobal == 1) {
int nParticles = 0;
if (nonGlobalType == kEM) {
nParticles = emParticles_.size();
} else if (nonGlobalType == kJet) {
nParticles = jetParticles_.size();
} else if (nonGlobalType == kMuon) {
nParticles = muonParticles_.size();
}
tempIndexCombos.reserve(nParticles);
for (int i = 0; i < nParticles; ++i) {
L1IndexCombo tmpCombo;
tmpCombo.reserve(numOfObjects());
for (int j = 0; j < numOfObjects(); ++j) {
if (j == nonGlobalIndex) {
tmpCombo.push_back(i);
} else {
tmpCombo.push_back(0);
}
}
tempIndexCombos.push_back(tmpCombo);
}
}
char expected = IndexComboStates::kUnset;
if (indexCombosState_.compare_exchange_strong(expected, kSetting, std::memory_order_acq_rel)) {
//If this was read from an old file, it is possible that indexCombos_ is already set.
// This is the only safe place to check since we know no other thread can be attempting
// to change this value.
if (indexCombos_.empty()) {
indexCombos_.swap(tempIndexCombos);
}
indexCombosState_.store(kSet, std::memory_order_release);
} else {
//have to wait
while (kSet != indexCombosState_.load(std::memory_order_acquire)) {
hardware_pause();
}
}
}
const reco::LeafCandidate* L1ParticleMap::candidateInCombo(int aIndexInCombo, const L1IndexCombo& aCombo) const {
L1ObjectType type = objectTypes_[aIndexInCombo];
int particleInList = aCombo[aIndexInCombo];
if (type == kEM) {
return dynamic_cast<const reco::LeafCandidate*>(emParticles_[particleInList].get());
} else if (type == kJet) {
return dynamic_cast<const reco::LeafCandidate*>(jetParticles_[particleInList].get());
} else if (type == kMuon) {
return dynamic_cast<const reco::LeafCandidate*>(muonParticles_[particleInList].get());
} else if (type == kEtMiss || type == kEtTotal || type == kEtHad) {
return dynamic_cast<const reco::LeafCandidate*>(etMissParticle_.get());
} else {
return nullptr;
}
}
const L1EmParticle* L1ParticleMap::emParticleInCombo(int aIndexInCombo, const L1IndexCombo& aCombo) const {
L1ObjectType type = objectTypes_[aIndexInCombo];
int particleInList = aCombo[aIndexInCombo];
if (type == kEM) {
return emParticles_[particleInList].get();
} else {
return nullptr;
}
}
const L1JetParticle* L1ParticleMap::jetParticleInCombo(int aIndexInCombo, const L1IndexCombo& aCombo) const {
L1ObjectType type = objectTypes_[aIndexInCombo];
int particleInList = aCombo[aIndexInCombo];
if (type == kJet) {
return jetParticles_[particleInList].get();
} else {
return nullptr;
}
}
const L1MuonParticle* L1ParticleMap::muonParticleInCombo(int aIndexInCombo, const L1IndexCombo& aCombo) const {
L1ObjectType type = objectTypes_[aIndexInCombo];
int particleInList = aCombo[aIndexInCombo];
if (type == kMuon) {
return muonParticles_[particleInList].get();
} else {
return nullptr;
}
}
const L1EtMissParticle* L1ParticleMap::etMissParticleInCombo(int aIndexInCombo, const L1IndexCombo& aCombo) const {
L1ObjectType type = objectTypes_[aIndexInCombo];
if (type == kEtMiss || type == kEtTotal || type == kEtHad) {
return etMissParticle_.get();
} else {
return nullptr;
}
}
std::vector<const reco::LeafCandidate*> L1ParticleMap::candidateCombo(const L1IndexCombo& aCombo) const {
std::vector<const reco::LeafCandidate*> tmp;
tmp.reserve(numOfObjects());
for (int i = 0; i < numOfObjects(); ++i) {
tmp.push_back(candidateInCombo(i, aCombo));
}
return tmp;
}
//
// static member functions
//
const std::string& L1ParticleMap::triggerName(L1TriggerType type) { return triggerNames_[type]; }
L1ParticleMap::L1TriggerType L1ParticleMap::triggerType(const std::string& name) {
for (int i = 0; i < kNumOfL1TriggerTypes; ++i) {
if (triggerNames_[i] == name) {
return (L1TriggerType)i;
}
}
return kNumOfL1TriggerTypes;
}
bool L1ParticleMap::objectTypeIsGlobal(L1ObjectType type) {
return type == kEtMiss || type == kEtTotal || type == kEtHad;
}
|