CMS 3D CMS Logo

L1ParticleMap.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger
4 // Class : L1ParticleMap
5 //
8 //
9 // Original Author: Werner Sun
10 // Created: Wed Jul 26 14:42:56 EDT 2006
11 //
12 
13 // system include files
14 
15 // user include files
21 
22 using namespace l1extra;
23 
24 //
25 // constants, enums and typedefs
26 //
27 
28 //
29 // static data member definitions
30 //
31 
32 // EG = isolated OR non-isolated
33 // Jet = central OR forward OR tau
34 const std::string L1ParticleMap::triggerNames_[kNumOfL1TriggerTypes] = {"L1_SingleMu3",
35  "L1_SingleMu5",
36  "L1_SingleMu7",
37  "L1_SingleMu10",
38  "L1_SingleMu14",
39  "L1_SingleMu20",
40  "L1_SingleMu25",
41  "L1_SingleIsoEG5",
42  "L1_SingleIsoEG8",
43  "L1_SingleIsoEG10",
44  "L1_SingleIsoEG12",
45  "L1_SingleIsoEG15",
46  "L1_SingleIsoEG20",
47  "L1_SingleIsoEG25",
48  "L1_SingleEG5",
49  "L1_SingleEG8",
50  "L1_SingleEG10",
51  "L1_SingleEG12",
52  "L1_SingleEG15",
53  "L1_SingleEG20",
54  "L1_SingleEG25",
55  "L1_SingleJet15",
56  "L1_SingleJet20",
57  "L1_SingleJet30",
58  "L1_SingleJet50",
59  "L1_SingleJet70",
60  "L1_SingleJet100",
61  "L1_SingleJet150",
62  "L1_SingleJet200",
63  "L1_SingleTauJet10",
64  "L1_SingleTauJet20",
65  "L1_SingleTauJet30",
66  "L1_SingleTauJet35",
67  "L1_SingleTauJet40",
68  "L1_SingleTauJet60",
69  "L1_SingleTauJet80",
70  "L1_SingleTauJet100",
71  "L1_HTT100",
72  "L1_HTT200",
73  "L1_HTT250",
74  "L1_HTT300",
75  "L1_HTT400",
76  "L1_HTT500",
77  "L1_ETM10",
78  "L1_ETM15",
79  "L1_ETM20",
80  "L1_ETM30",
81  "L1_ETM40",
82  "L1_ETM50",
83  "L1_ETM60",
84  "L1_ETT60",
85  "L1_DoubleMu3",
86  "L1_DoubleIsoEG8",
87  "L1_DoubleIsoEG10",
88  "L1_DoubleEG5",
89  "L1_DoubleEG10",
90  "L1_DoubleEG15",
91  "L1_DoubleJet70",
92  "L1_DoubleJet100",
93  "L1_DoubleTauJet20",
94  "L1_DoubleTauJet30",
95  "L1_DoubleTauJet35",
96  "L1_DoubleTauJet40",
97  "L1_Mu3_IsoEG5",
98  "L1_Mu5_IsoEG10",
99  "L1_Mu3_EG12",
100  "L1_Mu3_Jet15",
101  "L1_Mu5_Jet15",
102  "L1_Mu3_Jet70",
103  "L1_Mu5_Jet20",
104  "L1_Mu5_TauJet20",
105  "L1_Mu5_TauJet30",
106  "L1_IsoEG10_EG10",
107  "L1_IsoEG10_Jet15",
108  "L1_IsoEG10_Jet20",
109  "L1_IsoEG10_Jet30",
110  "L1_IsoEG10_Jet70",
111  "L1_IsoEG10_TauJet20",
112  "L1_IsoEG10_TauJet30",
113  "L1_EG10_Jet15",
114  "L1_EG12_Jet20",
115  "L1_EG12_Jet70",
116  "L1_EG12_TauJet40",
117  "L1_Jet70_TauJet40",
118  "L1_Mu3_HTT200",
119  "L1_IsoEG10_HTT200",
120  "L1_EG12_HTT200",
121  "L1_Jet70_HTT200",
122  "L1_TauJet40_HTT200",
123  "L1_Mu3_ETM30",
124  "L1_IsoEG10_ETM30",
125  "L1_EG12_ETM30",
126  "L1_Jet70_ETM40",
127  "L1_TauJet20_ETM20",
128  "L1_TauJet30_ETM30",
129  "L1_TauJet30_ETM40",
130  "L1_HTT100_ETM30",
131  "L1_TripleMu3",
132  "L1_TripleIsoEG5",
133  "L1_TripleEG10",
134  "L1_TripleJet50",
135  "L1_TripleTauJet40",
136  "L1_DoubleMu3_IsoEG5",
137  "L1_DoubleMu3_EG10",
138  "L1_DoubleIsoEG5_Mu3",
139  "L1_DoubleEG10_Mu3",
140  "L1_DoubleMu3_HTT200",
141  "L1_DoubleIsoEG5_HTT200",
142  "L1_DoubleEG10_HTT200",
143  "L1_DoubleJet50_HTT200",
144  "L1_DoubleTauJet40_HTT200",
145  "L1_DoubleMu3_ETM20",
146  "L1_DoubleIsoEG5_ETM20",
147  "L1_DoubleEG10_ETM20",
148  "L1_DoubleJet50_ETM20",
149  "L1_DoubleTauJet40_ETM20",
150  "L1_QuadJet30",
151  "L1_ExclusiveDoubleIsoEG4",
152  "L1_ExclusiveDoubleJet60",
153  "L1_ExclusiveJet25_Gap_Jet25",
154  "L1_IsoEG10_Jet20_ForJet10",
155  "L1_MinBias_HTT10",
156  "L1_ZeroBias"};
157 
158 namespace {
159  enum IndexComboStates { kUnset, kSetting, kSet };
160 }
161 
162 //
163 // constructors and destructor
164 //
166 
168  bool triggerDecision,
170  const L1EmParticleVectorRef& emParticles,
171  const L1JetParticleVectorRef& jetParticles,
172  const L1MuonParticleVectorRef& muonParticles,
173  const L1EtMissParticleRefProd& etMissParticle,
174  const L1IndexComboVector& indexCombos)
175  : triggerType_(triggerType),
176  triggerDecision_(triggerDecision),
177  indexCombosState_{static_cast<char>(!indexCombos.empty() ? kSet : IndexComboStates::kUnset)},
178  objectTypes_(objectTypes),
179  emParticles_(emParticles),
180  jetParticles_(jetParticles),
181  muonParticles_(muonParticles),
182  etMissParticle_(etMissParticle),
183  indexCombos_(indexCombos) {}
184 
186  : triggerType_(rhs.triggerType_),
187  triggerDecision_(rhs.triggerDecision_),
188  indexCombosState_(IndexComboStates::kUnset),
189  objectTypes_(rhs.objectTypes_),
190  emParticles_(rhs.emParticles_),
191  jetParticles_(rhs.jetParticles_),
192  muonParticles_(rhs.muonParticles_),
193  etMissParticle_(rhs.etMissParticle_),
194  indexCombos_() {
195  // do actual copying here;
196  if (rhs.indexCombosState_.load(std::memory_order_acquire) == kSet) {
198  indexCombosState_.store(kSet, std::memory_order_release);
199  }
200 }
201 
203 
204 //
205 // assignment operators
206 //
208  //An exception safe implementation is
209  L1ParticleMap temp(rhs);
210  swap(temp);
211 
212  return *this;
213 }
214 
215 //
216 // member functions
217 //
221  indexCombosState_.store(
222  rhs.indexCombosState_.exchange(indexCombosState_.load(std::memory_order_acquire), std::memory_order_acq_rel),
223  std::memory_order_release);
230 }
231 
232 //
233 // const member functions
234 //
235 
237  if (kSet != indexCombosState_.load(std::memory_order_acquire)) {
238  setIndexCombos();
239  }
240  return indexCombos_;
241 }
242 
244  // Determine the number of non-global objects. There should be 0 or 1.
245  int numNonGlobal = 0;
246  L1ObjectType nonGlobalType = kNumOfL1ObjectTypes;
247  int nonGlobalIndex = -1;
248 
249  L1IndexComboVector tempIndexCombos;
250  for (int i = 0; i < numOfObjects(); ++i) {
252  ++numNonGlobal;
253  nonGlobalType = objectTypes_[i];
254  nonGlobalIndex = i;
255  }
256  }
257 
258  if (numNonGlobal == 0) {
259  // Dummy entry for each object type.
260  L1IndexCombo tmpCombo;
261  tmpCombo.reserve(numOfObjects());
262  for (int i = 0; i < numOfObjects(); ++i) {
263  tmpCombo.push_back(0);
264  }
265 
266  tempIndexCombos.push_back(tmpCombo);
267  } else if (numNonGlobal == 1) {
268  int nParticles = 0;
269 
270  if (nonGlobalType == kEM) {
271  nParticles = emParticles_.size();
272  } else if (nonGlobalType == kJet) {
273  nParticles = jetParticles_.size();
274  } else if (nonGlobalType == kMuon) {
275  nParticles = muonParticles_.size();
276  }
277 
278  tempIndexCombos.reserve(nParticles);
279  for (int i = 0; i < nParticles; ++i) {
280  L1IndexCombo tmpCombo;
281  tmpCombo.reserve(numOfObjects());
282  for (int j = 0; j < numOfObjects(); ++j) {
283  if (j == nonGlobalIndex) {
284  tmpCombo.push_back(i);
285  } else {
286  tmpCombo.push_back(0);
287  }
288  }
289 
290  tempIndexCombos.push_back(tmpCombo);
291  }
292  }
293  char expected = IndexComboStates::kUnset;
294  if (indexCombosState_.compare_exchange_strong(expected, kSetting, std::memory_order_acq_rel)) {
295  //If this was read from an old file, it is possible that indexCombos_ is already set.
296  // This is the only safe place to check since we know no other thread can be attempting
297  // to change this value.
298  if (indexCombos_.empty()) {
299  indexCombos_.swap(tempIndexCombos);
300  }
301  indexCombosState_.store(kSet, std::memory_order_release);
302  } else {
303  //have to wait
304  while (kSet != indexCombosState_.load(std::memory_order_acquire)) {
305  hardware_pause();
306  }
307  }
308 }
309 
310 const reco::LeafCandidate* L1ParticleMap::candidateInCombo(int aIndexInCombo, const L1IndexCombo& aCombo) const {
311  L1ObjectType type = objectTypes_[aIndexInCombo];
312  int particleInList = aCombo[aIndexInCombo];
313 
314  if (type == kEM) {
315  return dynamic_cast<const reco::LeafCandidate*>(emParticles_[particleInList].get());
316  } else if (type == kJet) {
317  return dynamic_cast<const reco::LeafCandidate*>(jetParticles_[particleInList].get());
318  } else if (type == kMuon) {
319  return dynamic_cast<const reco::LeafCandidate*>(muonParticles_[particleInList].get());
320  } else if (type == kEtMiss || type == kEtTotal || type == kEtHad) {
321  return dynamic_cast<const reco::LeafCandidate*>(etMissParticle_.get());
322  } else {
323  return nullptr;
324  }
325 }
326 
327 const L1EmParticle* L1ParticleMap::emParticleInCombo(int aIndexInCombo, const L1IndexCombo& aCombo) const {
328  L1ObjectType type = objectTypes_[aIndexInCombo];
329  int particleInList = aCombo[aIndexInCombo];
330 
331  if (type == kEM) {
332  return emParticles_[particleInList].get();
333  } else {
334  return nullptr;
335  }
336 }
337 
338 const L1JetParticle* L1ParticleMap::jetParticleInCombo(int aIndexInCombo, const L1IndexCombo& aCombo) const {
339  L1ObjectType type = objectTypes_[aIndexInCombo];
340  int particleInList = aCombo[aIndexInCombo];
341 
342  if (type == kJet) {
343  return jetParticles_[particleInList].get();
344  } else {
345  return nullptr;
346  }
347 }
348 
349 const L1MuonParticle* L1ParticleMap::muonParticleInCombo(int aIndexInCombo, const L1IndexCombo& aCombo) const {
350  L1ObjectType type = objectTypes_[aIndexInCombo];
351  int particleInList = aCombo[aIndexInCombo];
352 
353  if (type == kMuon) {
354  return muonParticles_[particleInList].get();
355  } else {
356  return nullptr;
357  }
358 }
359 
360 const L1EtMissParticle* L1ParticleMap::etMissParticleInCombo(int aIndexInCombo, const L1IndexCombo& aCombo) const {
361  L1ObjectType type = objectTypes_[aIndexInCombo];
362 
363  if (type == kEtMiss || type == kEtTotal || type == kEtHad) {
364  return etMissParticle_.get();
365  } else {
366  return nullptr;
367  }
368 }
369 
370 std::vector<const reco::LeafCandidate*> L1ParticleMap::candidateCombo(const L1IndexCombo& aCombo) const {
371  std::vector<const reco::LeafCandidate*> tmp;
372 
373  tmp.reserve(numOfObjects());
374  for (int i = 0; i < numOfObjects(); ++i) {
375  tmp.push_back(candidateInCombo(i, aCombo));
376  }
377 
378  return tmp;
379 }
380 
381 //
382 // static member functions
383 //
385 
387  for (int i = 0; i < kNumOfL1TriggerTypes; ++i) {
388  if (triggerNames_[i] == name) {
389  return (L1TriggerType)i;
390  }
391  }
392 
393  return kNumOfL1TriggerTypes;
394 }
395 
397  return type == kEtMiss || type == kEtTotal || type == kEtHad;
398 }
const L1EtMissParticle * etMissParticleInCombo(int aIndexInCombo, const L1IndexCombo &aCombo) const
L1TriggerType triggerType() const
const L1EmParticle * emParticleInCombo(int aIndexInCombo, const L1IndexCombo &aCombo) const
std::atomic< char > indexCombosState_
void swap(L1ParticleMap &)
std::vector< unsigned int > L1IndexCombo
std::vector< L1ObjectType > L1ObjectTypeVector
L1IndexComboVector indexCombos_
const char * kSet
L1ParticleMap & operator=(const L1ParticleMap &)
static const std::string triggerNames_[kNumOfL1TriggerTypes]
const std::string & triggerName() const
std::vector< L1JetParticleRef > L1JetParticleVectorRef
std::vector< L1MuonParticleRef > L1MuonParticleVectorRef
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
const reco::LeafCandidate * candidateInCombo(int aIndexInCombo, const L1IndexCombo &aCombo) const
std::vector< const reco::LeafCandidate * > candidateCombo(const L1IndexCombo &aCombo) const
L1EtMissParticleRefProd etMissParticle_
const L1IndexComboVector & indexCombos() const
product_type const * get() const
Definition: RefProd.h:106
L1EmParticleVectorRef emParticles_
std::vector< L1IndexCombo > L1IndexComboVector
L1MuonParticleVectorRef muonParticles_
static bool objectTypeIsGlobal(L1ObjectType type)
const L1MuonParticle * muonParticleInCombo(int aIndexInCombo, const L1IndexCombo &aCombo) const
std::vector< L1EmParticleRef > L1EmParticleVectorRef
L1JetParticleVectorRef jetParticles_
L1ObjectTypeVector objectTypes_
const L1JetParticle * jetParticleInCombo(int aIndexInCombo, const L1IndexCombo &aCombo) const
tmp
align.sh
Definition: createJobs.py:716
void setIndexCombos() const
L1TriggerType triggerType_
IndexComboStates