CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
35 L1ParticleMap::triggerNames_[ kNumOfL1TriggerTypes ] = {
36  "L1_SingleMu3",
37  "L1_SingleMu5",
38  "L1_SingleMu7",
39  "L1_SingleMu10",
40  "L1_SingleMu14",
41  "L1_SingleMu20",
42  "L1_SingleMu25",
43  "L1_SingleIsoEG5",
44  "L1_SingleIsoEG8",
45  "L1_SingleIsoEG10",
46  "L1_SingleIsoEG12",
47  "L1_SingleIsoEG15",
48  "L1_SingleIsoEG20",
49  "L1_SingleIsoEG25",
50  "L1_SingleEG5",
51  "L1_SingleEG8",
52  "L1_SingleEG10",
53  "L1_SingleEG12",
54  "L1_SingleEG15",
55  "L1_SingleEG20",
56  "L1_SingleEG25",
57  "L1_SingleJet15",
58  "L1_SingleJet20",
59  "L1_SingleJet30",
60  "L1_SingleJet50",
61  "L1_SingleJet70",
62  "L1_SingleJet100",
63  "L1_SingleJet150",
64  "L1_SingleJet200",
65  "L1_SingleTauJet10",
66  "L1_SingleTauJet20",
67  "L1_SingleTauJet30",
68  "L1_SingleTauJet35",
69  "L1_SingleTauJet40",
70  "L1_SingleTauJet60",
71  "L1_SingleTauJet80",
72  "L1_SingleTauJet100",
73  "L1_HTT100",
74  "L1_HTT200",
75  "L1_HTT250",
76  "L1_HTT300",
77  "L1_HTT400",
78  "L1_HTT500",
79  "L1_ETM10",
80  "L1_ETM15",
81  "L1_ETM20",
82  "L1_ETM30",
83  "L1_ETM40",
84  "L1_ETM50",
85  "L1_ETM60",
86  "L1_ETT60",
87  "L1_DoubleMu3",
88  "L1_DoubleIsoEG8",
89  "L1_DoubleIsoEG10",
90  "L1_DoubleEG5",
91  "L1_DoubleEG10",
92  "L1_DoubleEG15",
93  "L1_DoubleJet70",
94  "L1_DoubleJet100",
95  "L1_DoubleTauJet20",
96  "L1_DoubleTauJet30",
97  "L1_DoubleTauJet35",
98  "L1_DoubleTauJet40",
99  "L1_Mu3_IsoEG5",
100  "L1_Mu5_IsoEG10",
101  "L1_Mu3_EG12",
102  "L1_Mu3_Jet15",
103  "L1_Mu5_Jet15",
104  "L1_Mu3_Jet70",
105  "L1_Mu5_Jet20",
106  "L1_Mu5_TauJet20",
107  "L1_Mu5_TauJet30",
108  "L1_IsoEG10_EG10",
109  "L1_IsoEG10_Jet15",
110  "L1_IsoEG10_Jet20",
111  "L1_IsoEG10_Jet30",
112  "L1_IsoEG10_Jet70",
113  "L1_IsoEG10_TauJet20",
114  "L1_IsoEG10_TauJet30",
115  "L1_EG10_Jet15",
116  "L1_EG12_Jet20",
117  "L1_EG12_Jet70",
118  "L1_EG12_TauJet40",
119  "L1_Jet70_TauJet40",
120  "L1_Mu3_HTT200",
121  "L1_IsoEG10_HTT200",
122  "L1_EG12_HTT200",
123  "L1_Jet70_HTT200",
124  "L1_TauJet40_HTT200",
125  "L1_Mu3_ETM30",
126  "L1_IsoEG10_ETM30",
127  "L1_EG12_ETM30",
128  "L1_Jet70_ETM40",
129  "L1_TauJet20_ETM20",
130  "L1_TauJet30_ETM30",
131  "L1_TauJet30_ETM40",
132  "L1_HTT100_ETM30",
133  "L1_TripleMu3",
134  "L1_TripleIsoEG5",
135  "L1_TripleEG10",
136  "L1_TripleJet50",
137  "L1_TripleTauJet40",
138  "L1_DoubleMu3_IsoEG5",
139  "L1_DoubleMu3_EG10",
140  "L1_DoubleIsoEG5_Mu3",
141  "L1_DoubleEG10_Mu3",
142  "L1_DoubleMu3_HTT200",
143  "L1_DoubleIsoEG5_HTT200",
144  "L1_DoubleEG10_HTT200",
145  "L1_DoubleJet50_HTT200",
146  "L1_DoubleTauJet40_HTT200",
147  "L1_DoubleMu3_ETM20",
148  "L1_DoubleIsoEG5_ETM20",
149  "L1_DoubleEG10_ETM20",
150  "L1_DoubleJet50_ETM20",
151  "L1_DoubleTauJet40_ETM20",
152  "L1_QuadJet30",
153  "L1_ExclusiveDoubleIsoEG4",
154  "L1_ExclusiveDoubleJet60",
155  "L1_ExclusiveJet25_Gap_Jet25",
156  "L1_IsoEG10_Jet20_ForJet10",
157  "L1_MinBias_HTT10",
158  "L1_ZeroBias"
159 } ;
160 
161 namespace {
163  kUnset,
164  kSetting,
165  kSet
166  };
167 }
168 
169 //
170 // constructors and destructor
171 //
173 {
174 }
175 
178  bool triggerDecision,
179  const L1ObjectTypeVector& objectTypes,
180  const L1EmParticleVectorRef& emParticles,
181  const L1JetParticleVectorRef& jetParticles,
182  const L1MuonParticleVectorRef& muonParticles,
183  const L1EtMissParticleRefProd& etMissParticle,
184  const L1IndexComboVector& indexCombos )
185  : triggerType_( triggerType ),
186  triggerDecision_( triggerDecision ),
187  indexCombosState_{static_cast<char>(indexCombos.size()>0? kSet:kUnset)},
188  objectTypes_( objectTypes ),
189  emParticles_( emParticles ),
190  jetParticles_( jetParticles ),
191  muonParticles_( muonParticles ),
192  etMissParticle_( etMissParticle ),
193  indexCombos_( indexCombos )
194 {
195 }
196 
200  indexCombosState_(kUnset),
206  indexCombos_()
207 {
208  // do actual copying here;
209  if(rhs.indexCombosState_.load(std::memory_order_acquire) == kSet) {
211  indexCombosState_.store(kSet,std::memory_order_release);
212  }
213 }
214 
216 {
217 }
218 
219 //
220 // assignment operators
221 //
223 {
224  //An exception safe implementation is
225  L1ParticleMap temp(rhs);
226  swap(temp);
227 
228  return *this;
229 }
230 
231 //
232 // member functions
233 //
234 void
238  indexCombosState_.store(rhs.indexCombosState_.exchange(indexCombosState_.load(std::memory_order_acquire),std::memory_order_acq_rel),std::memory_order_release);
245 }
246 
247 //
248 // const member functions
249 //
250 
253 {
254  if(kSet != indexCombosState_.load(std::memory_order_acquire)) {
255  setIndexCombos();
256  }
257  return indexCombos_ ;
258 }
259 
260 void
262  // Determine the number of non-global objects. There should be 0 or 1.
263  int numNonGlobal = 0 ;
264  L1ObjectType nonGlobalType = kNumOfL1ObjectTypes ;
265  int nonGlobalIndex = -1 ;
266 
267  L1IndexComboVector tempIndexCombos;
268  for( int i = 0 ; i < numOfObjects() ; ++i )
269  {
270  if( !objectTypeIsGlobal( objectTypes_[ i ] ) )
271  {
272  ++numNonGlobal ;
273  nonGlobalType = objectTypes_[ i ] ;
274  nonGlobalIndex = i ;
275  }
276  }
277 
278  if( numNonGlobal == 0 )
279  {
280  // Dummy entry for each object type.
281  L1IndexCombo tmpCombo ;
282  tmpCombo.reserve(numOfObjects());
283  for( int i = 0 ; i < numOfObjects() ; ++i )
284  {
285  tmpCombo.push_back( 0 ) ;
286  }
287 
288  tempIndexCombos.push_back( tmpCombo ) ;
289  }
290  else if( numNonGlobal == 1 )
291  {
292  int nParticles = 0 ;
293 
294  if( nonGlobalType == kEM )
295  {
296  nParticles = emParticles_.size() ;
297  }
298  else if( nonGlobalType == kJet )
299  {
300  nParticles = jetParticles_.size() ;
301  }
302  else if( nonGlobalType == kMuon )
303  {
304  nParticles = muonParticles_.size() ;
305  }
306 
307  tempIndexCombos.reserve(nParticles);
308  for( int i = 0 ; i < nParticles ; ++i )
309  {
310  L1IndexCombo tmpCombo ;
311  tmpCombo.reserve(numOfObjects());
312  for( int j = 0 ; j < numOfObjects() ; ++j )
313  {
314  if( j == nonGlobalIndex )
315  {
316  tmpCombo.push_back( i ) ;
317  }
318  else
319  {
320  tmpCombo.push_back( 0 ) ;
321  }
322  }
323 
324  tempIndexCombos.push_back( tmpCombo ) ;
325  }
326  }
327  char expected = kUnset;
328  if(indexCombosState_.compare_exchange_strong(expected,kSetting,std::memory_order_acq_rel)) {
329  //If this was read from an old file, it is possible that indexCombos_ is already set.
330  // This is the only safe place to check since we know no other thread can be attempting
331  // to change this value.
332  if(indexCombos_.empty()) {
333  indexCombos_.swap(tempIndexCombos);
334  }
335  indexCombosState_.store(kSet, std::memory_order_release);
336  } else {
337  //have to wait
338  while(kSet != indexCombosState_.load(std::memory_order_acquire)) {
339  hardware_pause();
340  }
341  }
342 }
343 
344 
345 const reco::LeafCandidate*
347  const L1IndexCombo& aCombo ) const
348 {
349  L1ObjectType type = objectTypes_[ aIndexInCombo ] ;
350  int particleInList = aCombo[ aIndexInCombo ] ;
351 
352  if( type == kEM )
353  {
354  return dynamic_cast< const reco::LeafCandidate* >(
355  emParticles_[ particleInList ].get() ) ;
356  }
357  else if( type == kJet )
358  {
359  return dynamic_cast< const reco::LeafCandidate* >(
360  jetParticles_[ particleInList ].get() ) ;
361  }
362  else if( type == kMuon )
363  {
364  return dynamic_cast< const reco::LeafCandidate* >(
365  muonParticles_[ particleInList ].get() ) ;
366  }
367  else if( type == kEtMiss || type == kEtTotal || type == kEtHad )
368  {
369  return dynamic_cast< const reco::LeafCandidate* >(
370  etMissParticle_.get() ) ;
371  }
372  else
373  {
374  return 0 ;
375  }
376 }
377 
378 const L1EmParticle*
380  const L1IndexCombo& aCombo ) const
381 {
382  L1ObjectType type = objectTypes_[ aIndexInCombo ] ;
383  int particleInList = aCombo[ aIndexInCombo ] ;
384 
385  if( type == kEM )
386  {
387  return emParticles_[ particleInList ].get() ;
388  }
389  else
390  {
391  return 0 ;
392  }
393 }
394 
395 const L1JetParticle*
397  const L1IndexCombo& aCombo ) const
398 {
399  L1ObjectType type = objectTypes_[ aIndexInCombo ] ;
400  int particleInList = aCombo[ aIndexInCombo ] ;
401 
402  if( type == kJet )
403  {
404  return jetParticles_[ particleInList ].get() ;
405  }
406  else
407  {
408  return 0 ;
409  }
410 }
411 
412 const L1MuonParticle*
414  const L1IndexCombo& aCombo ) const
415 {
416  L1ObjectType type = objectTypes_[ aIndexInCombo ] ;
417  int particleInList = aCombo[ aIndexInCombo ] ;
418 
419  if( type == kMuon )
420  {
421  return muonParticles_[ particleInList ].get() ;
422  }
423  else
424  {
425  return 0 ;
426  }
427 }
428 
429 const L1EtMissParticle*
431  const L1IndexCombo& aCombo ) const
432 {
433  L1ObjectType type = objectTypes_[ aIndexInCombo ] ;
434 
435  if( type == kEtMiss || type == kEtTotal || type == kEtHad )
436  {
437  return etMissParticle_.get() ;
438  }
439  else
440  {
441  return 0 ;
442  }
443 }
444 
445 std::vector< const reco::LeafCandidate* >
447 {
448  std::vector< const reco::LeafCandidate* > tmp ;
449 
450  for( int i = 0 ; i < numOfObjects() ; ++i )
451  {
452  tmp.push_back( candidateInCombo( i, aCombo ) ) ;
453  }
454 
455  return tmp ;
456 }
457 
458 //
459 // static member functions
460 //
461 const std::string&
463 {
464  return triggerNames_[ type ] ;
465 }
466 
469 {
470  for( int i = 0 ; i < kNumOfL1TriggerTypes ; ++i )
471  {
472  if( triggerNames_[ i ] == name )
473  {
474  return ( L1TriggerType ) i ;
475  }
476  }
477 
478  return kNumOfL1TriggerTypes ;
479 }
480 
481 bool
483 {
484  return type == kEtMiss || type == kEtTotal || type == kEtHad ;
485 }
std::vector< L1EmParticleRef > L1EmParticleVectorRef
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
std::atomic< char > indexCombosState_
void swap(L1ParticleMap &)
std::vector< L1JetParticleRef > L1JetParticleVectorRef
const std::string & triggerName() const
const L1JetParticle * jetParticleInCombo(int aIndexInCombo, const L1IndexCombo &aCombo) const
L1IndexComboVector indexCombos_
const L1EtMissParticle * etMissParticleInCombo(int aIndexInCombo, const L1IndexCombo &aCombo) const
const char * kSet
int numOfObjects() const
L1ParticleMap & operator=(const L1ParticleMap &)
static const std::string triggerNames_[kNumOfL1TriggerTypes]
std::vector< unsigned int > L1IndexCombo
const L1MuonParticle * muonParticleInCombo(int aIndexInCombo, const L1IndexCombo &aCombo) const
std::vector< L1IndexCombo > L1IndexComboVector
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
int j
Definition: DBlmapReader.cc:9
L1EtMissParticleRefProd etMissParticle_
const L1EmParticle * emParticleInCombo(int aIndexInCombo, const L1IndexCombo &aCombo) const
void setIndexCombos() const
std::vector< const reco::LeafCandidate * > candidateCombo(const L1IndexCombo &aCombo) const
L1EmParticleVectorRef emParticles_
L1MuonParticleVectorRef muonParticles_
product_type const * get() const
Definition: RefProd.h:113
static bool objectTypeIsGlobal(L1ObjectType type)
L1TriggerType triggerType() const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
const reco::LeafCandidate * candidateInCombo(int aIndexInCombo, const L1IndexCombo &aCombo) const
const L1IndexComboVector & indexCombos() const
std::vector< L1ObjectType > L1ObjectTypeVector
std::vector< L1MuonParticleRef > L1MuonParticleVectorRef
L1JetParticleVectorRef jetParticles_
L1ObjectTypeVector objectTypes_
L1TriggerType triggerType_
IndexComboStates