CMS 3D CMS Logo

L1MuGlobalMuonTrigger.cc
Go to the documentation of this file.
1 //---------------------------------------------
2 //
3 // \class L1MuGlobalMuonTrigger
4 //
5 // Description: L1 Global Muon Trigger
6 //
7 //
8 //
9 // Author :
10 // Norbert Neumeister CERN EP
11 // Hannes Sakulin HEPHY Vienna
12 // Ivan Mikulec HEPHY Vienna
13 //
14 //--------------------------------------------------
15 
16 //-----------------------
17 // This Class's Header --
18 //-----------------------
19 
21 
22 //---------------
23 // C++ Headers --
24 //---------------
25 
26 #include <iostream>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 
30 //-------------------------------
31 // Collaborating Class Headers --
32 //-------------------------------
33 
45 
47 
49 
62 
65 
66 //----------------
67 // Constructors --
68 //----------------
70  produces<std::vector<L1MuGMTCand> >();
71  produces<L1MuGMTReadoutCollection>();
72  m_sendMipIso = ps.getUntrackedParameter<bool>("SendMipIso", false);
73  if (m_sendMipIso) {
74  produces<std::vector<unsigned> >();
75  }
76 
83 
84  m_ExtendedCands.reserve(20);
85 
86  // set configuration parameters
87  if (!m_config)
88  m_config = new L1MuGMTConfig(ps);
89  m_writeLUTsAndRegs = ps.getUntrackedParameter<bool>("WriteLUTsAndRegs", false);
90 
91  // build GMT
92  if (L1MuGMTConfig::Debug(1))
93  edm::LogVerbatim("GMT_info");
94  if (L1MuGMTConfig::Debug(1))
95  edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger building ****";
96  if (L1MuGMTConfig::Debug(1))
97  edm::LogVerbatim("GMT_info");
98 
99  // create new PSB
100  if (L1MuGMTConfig::Debug(2))
101  edm::LogVerbatim("GMT_info") << "creating GMT PSB";
102  m_PSB = new L1MuGMTPSB(*this, consumesCollector());
103 
104  // create new matcher
105  if (L1MuGMTConfig::Debug(2))
106  edm::LogVerbatim("GMT_info") << "creating GMT Matcher (0,1)";
107  m_Matcher[0] = new L1MuGMTMatcher(*this, 0); // barrel
108  m_Matcher[1] = new L1MuGMTMatcher(*this, 1); // endcap
109 
110  // create new cancel-out units
111  if (L1MuGMTConfig::Debug(2))
112  edm::LogVerbatim("GMT_info") << "creating GMT Cancel Out Unit (0,1,2,3)";
113  m_CancelOutUnit[0] = new L1MuGMTCancelOutUnit(*this, 0); // barrel
114  m_CancelOutUnit[1] = new L1MuGMTCancelOutUnit(*this, 1); // endcap
115  m_CancelOutUnit[2] = new L1MuGMTCancelOutUnit(*this, 2); // CSC/bRPC
116  m_CancelOutUnit[3] = new L1MuGMTCancelOutUnit(*this, 3); // DT/fRPC
117 
118  // create new MIP & ISO bit assignment units
119  if (L1MuGMTConfig::Debug(2))
120  edm::LogVerbatim("GMT_info") << "creating GMT MIP & ISO bit Assigment Unit (0,1)";
121  m_MipIsoAU[0] = new L1MuGMTMipIsoAU(*this, 0); // barrel
122  m_MipIsoAU[1] = new L1MuGMTMipIsoAU(*this, 1); // endcap
123 
124  // create new Merger
125  if (L1MuGMTConfig::Debug(2))
126  edm::LogVerbatim("GMT_info") << "creating GMT Merger (0,1)";
127  m_Merger[0] = new L1MuGMTMerger(*this, 0); // barrel
128  m_Merger[1] = new L1MuGMTMerger(*this, 1); // endcap
129 
130  // create new sorter
131  if (L1MuGMTConfig::Debug(2))
132  edm::LogVerbatim("GMT_info") << "creating GMT Sorter";
133  m_Sorter = new L1MuGMTSorter(*this); // barrel
134 
135  if (!m_db)
137  usesResource("L1MuGlobalMuonTrigger");
138 }
139 
140 //--------------
141 // Destructor --
142 //--------------
144  if (m_db)
145  delete m_db;
146  m_db = nullptr;
147 
148  delete m_Sorter;
149  delete m_Merger[1]; // endcap Merger
150  delete m_Merger[0]; // barrel Merger
151  delete m_MipIsoAU[1]; // barrel MIP & ISO bit assignment unit
152  delete m_MipIsoAU[0]; // barrel MIP & ISO bit assignment unit
153  delete m_CancelOutUnit[3]; // DT/fRPC cancel-out unit (in endcap chip)
154  delete m_CancelOutUnit[2]; // CSC/bRPC cancel-out unit (in barrel chip)
155  delete m_CancelOutUnit[1]; // endcap DT/CSC cancel out unit
156  delete m_CancelOutUnit[0]; // barrel DT/CSC cancel out unit
157  delete m_Matcher[1]; // endcap matcher
158  delete m_Matcher[0]; // barrel matcher
159  delete m_PSB;
160 
161  if (m_config)
162  delete m_config;
163  m_config = nullptr;
164 
165  // copied from produce() by Jim B, 7 Aug 2007
166  std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
167  for (; irr != m_ReadoutRingbuffer.end(); irr++)
168  delete (*irr);
169  m_ReadoutRingbuffer.clear();
170  // end Jim B edit
171 }
172 
173 //--------------
174 // Operations --
175 //--------------
176 
178 
180  // configure from the event setup
181 
182  unsigned long long L1MuGMTScalesCacheID = es.get<L1MuGMTScalesRcd>().cacheIdentifier();
183  if (L1MuGMTScalesCacheID != m_L1MuGMTScalesCacheID) {
184  edm::ESHandle<L1MuGMTScales> gmtscales_h;
185  es.get<L1MuGMTScalesRcd>().get(gmtscales_h);
186  m_config->setGMTScales(gmtscales_h.product());
187  }
188 
189  unsigned long long L1MuTriggerScalesCacheID = es.get<L1MuTriggerScalesRcd>().cacheIdentifier();
190  if (L1MuTriggerScalesCacheID != m_L1MuTriggerScalesCacheID) {
192  es.get<L1MuTriggerScalesRcd>().get(trigscales_h);
193  m_config->setTriggerScales(trigscales_h.product());
194  }
195 
196  unsigned long long L1MuTriggerPtScaleCacheID = es.get<L1MuTriggerPtScaleRcd>().cacheIdentifier();
197  if (L1MuTriggerPtScaleCacheID != m_L1MuTriggerPtScaleCacheID) {
198  edm::ESHandle<L1MuTriggerPtScale> trigptscale_h;
199  es.get<L1MuTriggerPtScaleRcd>().get(trigptscale_h);
200  m_config->setTriggerPtScale(trigptscale_h.product());
201  }
202 
203  unsigned long long L1MuGMTParametersCacheID = es.get<L1MuGMTParametersRcd>().cacheIdentifier();
204  if (L1MuGMTParametersCacheID != m_L1MuGMTParametersCacheID) {
206  es.get<L1MuGMTParametersRcd>().get(gmtparams_h);
207  m_config->setGMTParams(gmtparams_h.product());
209  }
210 
211  unsigned long long L1MuGMTChannelMaskCacheID = es.get<L1MuGMTChannelMaskRcd>().cacheIdentifier();
212  if (L1MuGMTChannelMaskCacheID != m_L1MuGMTChannelMaskCacheID) {
213  edm::ESHandle<L1MuGMTChannelMask> gmtchanmask_h;
214  es.get<L1MuGMTChannelMaskRcd>().get(gmtchanmask_h);
215  m_config->setGMTChanMask(gmtchanmask_h.product());
216  if (L1MuGMTConfig::Debug(1)) {
217  std::string onoff;
218  const L1MuGMTChannelMask* theChannelMask = L1MuGMTConfig::getGMTChanMask();
219  unsigned mask = theChannelMask->getSubsystemMask();
220 
221  edm::LogVerbatim("GMT_info");
222  edm::LogVerbatim("GMT_info") << " GMT input Channel Mask:" << std::hex << mask << std::dec;
223  onoff = mask & 1 ? "OFF" : "ON";
224  edm::LogVerbatim("GMT_info") << " DT input " << onoff;
225  onoff = mask & 2 ? "OFF" : "ON";
226  edm::LogVerbatim("GMT_info") << " RPCb input " << onoff;
227  onoff = mask & 4 ? "OFF" : "ON";
228  edm::LogVerbatim("GMT_info") << " CSC input " << onoff;
229  onoff = mask & 8 ? "OFF" : "ON";
230  edm::LogVerbatim("GMT_info") << " RPCf input " << onoff;
231  edm::LogVerbatim("GMT_info");
232  }
233  }
234 
235  unsigned long long L1CaloGeometryCacheID = es.get<L1CaloGeometryRecord>().cacheIdentifier();
236  if (L1CaloGeometryCacheID != m_L1CaloGeometryCacheID) {
238  es.get<L1CaloGeometryRecord>().get(caloGeom_h);
239  m_config->setCaloGeom(caloGeom_h.product());
240  }
241 
243 
244  // write LUTs and Regs if required
245 
246  if (m_writeLUTsAndRegs) {
247  std::string dir = "gmtconfig";
248 
249  mkdir(dir.c_str(), S_ISUID | S_ISGID | S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR);
250 
251  m_config->dumpLUTs(dir);
252  m_config->dumpRegs(dir);
253  }
254 
255  // process the event
256  if (L1MuGMTConfig::Debug(2))
257  edm::LogVerbatim("GMT_info");
258  if (L1MuGMTConfig::Debug(2))
259  edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger processing ****";
260  if (L1MuGMTConfig::Debug(2))
261  edm::LogVerbatim("GMT_info");
262 
263  int bx_min = L1MuGMTConfig::getBxMin();
264  int bx_max = L1MuGMTConfig::getBxMax();
265 
266  m_ExtendedCands.clear();
267 
268  // clear readout ring buffer
269  std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
270  for (; irr != m_ReadoutRingbuffer.end(); irr++)
271  delete (*irr);
272  m_ReadoutRingbuffer.clear();
273 
274  if (m_db)
275  m_db->reset(); // reset debug block
276 
277  for (int bx = bx_min; bx <= bx_max; bx++) {
278  m_db->SetBX(bx);
279 
280  // create new element in readout ring buffer
282 
283  if (L1MuGMTConfig::Debug(2))
284  edm::LogVerbatim("GMT_info") << "L1GlobalMuonTrigger processing bunch-crossing : " << bx;
285 
286  // get data into the data buffer
287  if (L1MuGMTConfig::Debug(2))
288  edm::LogVerbatim("GMT_info") << "running GMT PSB";
289  if (m_PSB) {
290  m_PSB->receiveData(e, bx);
291  if (L1MuGMTConfig::Debug(4))
292  m_PSB->print();
293  }
294 
295  if (m_PSB && !m_PSB->empty()) {
296  // run matcher
297  if (L1MuGMTConfig::Debug(2))
298  edm::LogVerbatim("GMT_info") << "running GMT barrel Matcher";
299  if (m_Matcher[0])
300  m_Matcher[0]->run();
301  if (L1MuGMTConfig::Debug(3) && m_Matcher[0])
302  m_Matcher[0]->print();
303  if (L1MuGMTConfig::Debug(2))
304  edm::LogVerbatim("GMT_info") << "running GMT endcap Matcher";
305  if (m_Matcher[1])
306  m_Matcher[1]->run();
307  if (L1MuGMTConfig::Debug(3) && m_Matcher[1])
308  m_Matcher[1]->print();
309 
310  // run cancel-out units
311  if (L1MuGMTConfig::Debug(2))
312  edm::LogVerbatim("GMT_info") << "running GMT barrel Cancel Out Unit";
313  if (m_CancelOutUnit[0])
314  m_CancelOutUnit[0]->run();
316  m_CancelOutUnit[0]->print();
317 
318  if (L1MuGMTConfig::Debug(2))
319  edm::LogVerbatim("GMT_info") << "running GMT endcap Cancel Out Unit";
320  if (m_CancelOutUnit[1])
321  m_CancelOutUnit[1]->run();
323  m_CancelOutUnit[1]->print();
324 
325  if (L1MuGMTConfig::Debug(2))
326  edm::LogVerbatim("GMT_info") << "running GMT CSC/fRPC Cancel Out Unit";
327  if (m_CancelOutUnit[2])
328  m_CancelOutUnit[2]->run();
330  m_CancelOutUnit[2]->print();
331 
332  if (L1MuGMTConfig::Debug(2))
333  edm::LogVerbatim("GMT_info") << "running GMT DT/bRPC Cancel Out Unit";
334  if (m_CancelOutUnit[3])
335  m_CancelOutUnit[3]->run();
337  m_CancelOutUnit[3]->print();
338 
339  // run MIP & ISO bit assignment units
340  if (L1MuGMTConfig::Debug(2))
341  edm::LogVerbatim("GMT_info") << "running GMT barrel MIP & ISO bit Assignment Unit";
342  if (m_MipIsoAU[0])
343  m_MipIsoAU[0]->run();
344  if (L1MuGMTConfig::Debug(3) && m_MipIsoAU[0])
345  m_MipIsoAU[0]->print();
346  if (L1MuGMTConfig::Debug(2))
347  edm::LogVerbatim("GMT_info") << "running GMT endcap MIP & ISO bit Assignment Unit";
348  if (m_MipIsoAU[1])
349  m_MipIsoAU[1]->run();
350  if (L1MuGMTConfig::Debug(3) && m_MipIsoAU[1])
351  m_MipIsoAU[1]->print();
352 
353  // run Merger
354  if (L1MuGMTConfig::Debug(2))
355  edm::LogVerbatim("GMT_info") << "running GMT barrel Merger";
356  if (m_Merger[0])
357  m_Merger[0]->run();
358  if (L1MuGMTConfig::Debug(3) && m_Merger[0])
359  m_Merger[0]->print();
360  if (L1MuGMTConfig::Debug(2))
361  edm::LogVerbatim("GMT_info") << "running GMT endcap Merger";
362  if (m_Merger[1])
363  m_Merger[1]->run();
364  if (L1MuGMTConfig::Debug(3) && m_Merger[1])
365  m_Merger[1]->print();
366 
367  // run sorter
368  if (L1MuGMTConfig::Debug(2))
369  edm::LogVerbatim("GMT_info") << "running GMT Sorter";
370  if (m_Sorter)
371  m_Sorter->run();
372  if (L1MuGMTConfig::Debug(1) && m_Sorter)
373  m_Sorter->print();
374 
375  // store found track candidates in a container
376  if (m_Sorter->numberOfCands() > 0) {
377  const std::vector<const L1MuGMTExtendedCand*>& gmt_cont = m_Sorter->Cands();
378  std::vector<const L1MuGMTExtendedCand*>::const_iterator iexc;
379  for (iexc = gmt_cont.begin(); iexc != gmt_cont.end(); iexc++) {
380  if (*iexc)
381  m_ExtendedCands.push_back(**iexc);
382  }
383  }
384 
385  // reset GMT
386  reset();
387  }
388  }
389 
390  // produce the output
391  std::unique_ptr<std::vector<L1MuGMTCand> > GMTCands(new std::vector<L1MuGMTCand>);
392  std::vector<L1MuGMTExtendedCand>::const_iterator iexc;
393  for (iexc = m_ExtendedCands.begin(); iexc != m_ExtendedCands.end(); iexc++) {
394  GMTCands->push_back(*iexc);
395  }
396  e.put(std::move(GMTCands));
397 
398  std::unique_ptr<L1MuGMTReadoutCollection> GMTRRC(getReadoutCollection());
399  e.put(std::move(GMTRRC));
400 
401  if (m_sendMipIso) {
402  std::unique_ptr<std::vector<unsigned> > mipiso(new std::vector<unsigned>);
403  for (int i = 0; i < 32; i++) {
404  mipiso->push_back(m_db->IsMIPISO(0, i));
405  }
406  e.put(std::move(mipiso));
407  }
408 
409  // delete registers and LUTs
411 }
412 
413 //
414 // reset GMT
415 //
417  if (m_PSB)
418  m_PSB->reset();
419  if (m_Matcher[0])
420  m_Matcher[0]->reset();
421  if (m_Matcher[1])
422  m_Matcher[1]->reset();
423  if (m_CancelOutUnit[0])
424  m_CancelOutUnit[0]->reset();
425  if (m_CancelOutUnit[1])
426  m_CancelOutUnit[1]->reset();
427  if (m_CancelOutUnit[2])
428  m_CancelOutUnit[2]->reset();
429  if (m_CancelOutUnit[3])
430  m_CancelOutUnit[3]->reset();
431  if (m_MipIsoAU[0])
432  m_MipIsoAU[0]->reset();
433  if (m_MipIsoAU[1])
434  m_MipIsoAU[1]->reset();
435  if (m_Merger[0])
436  m_Merger[0]->reset();
437  if (m_Merger[1])
438  m_Merger[1]->reset();
439  if (m_Sorter)
440  m_Sorter->reset();
441 }
442 
443 // get the GMT readout data for the triggered bx
444 std::unique_ptr<L1MuGMTReadoutCollection> L1MuGlobalMuonTrigger::getReadoutCollection() {
445  int bx_min_ro = L1MuGMTConfig::getBxMinRo();
446  int bx_max_ro = L1MuGMTConfig::getBxMaxRo();
447  int bx_size = bx_max_ro - bx_min_ro + 1;
448 
449  std::unique_ptr<L1MuGMTReadoutCollection> rrc(new L1MuGMTReadoutCollection(bx_size));
450 
451  for (int bx = bx_min_ro; bx <= bx_max_ro; bx++) {
452  std::vector<L1MuGMTReadoutRecord*>::const_iterator iter = m_ReadoutRingbuffer.begin();
453 
454  for (; iter != m_ReadoutRingbuffer.end(); iter++) {
455  if ((*iter)->getBxInEvent() == bx) {
456  rrc->addRecord(**iter);
457  break;
458  }
459  }
460  }
461 
462  return rrc;
463 }
464 
465 // static data members
466 
void setGMTChanMask(const L1MuGMTChannelMask *gmtchanmask)
T getUntrackedParameter(std::string const &, T const &) const
unsigned long long m_L1MuTriggerScalesCacheID
std::vector< L1MuGMTReadoutRecord * > m_ReadoutRingbuffer
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
unsigned long long m_L1MuGMTChannelMaskCacheID
void print() const
print PSB
Definition: L1MuGMTPSB.cc:212
void SetBX(int bx)
Set the current bunch crossing.
void setTriggerPtScale(const L1MuTriggerPtScale *trigptscale)
void dumpRegs(std::string dir)
std::vector< L1MuGMTExtendedCand > m_ExtendedCands
void reset()
clear cancel-out unit
void print() const
print results after MIP & ISO bit assignment
void print()
print cancel-out bits
bool empty() const
are there any data in the PSB
Definition: L1MuGMTPSB.cc:287
void produce(edm::Event &, const edm::EventSetup &) override
virtual void reset()
reset Sorter
unsigned getSubsystemMask() const
void reset()
clear MIP & ISO bit assignment unit
L1MuGlobalMuonTrigger(const edm::ParameterSet &)
void reset()
clear PSB
Definition: L1MuGMTPSB.cc:191
void run()
run Matcher
void print()
print matching results
const std::vector< const L1MuGMTExtendedCand * > & Cands() const
return std::vector with all muon candidates
Definition: L1MuGMTSorter.h:60
unsigned long long m_L1CaloGeometryCacheID
virtual void run()
run Sorter
void run()
run GMT MIP & ISO bit assignment unit
void setGMTScales(const L1MuGMTScales *gmtscales)
unsigned long long m_L1MuTriggerPtScaleCacheID
static bool Debug()
L1MuGMTMipIsoAU * m_MipIsoAU[2]
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
static const L1MuGMTChannelMask * getGMTChanMask()
std::unique_ptr< L1MuGMTReadoutCollection > getReadoutCollection()
unsigned IsMIPISO(int bx, int idx)
Get stored MIP/ISO select bits.
static int getBxMaxRo()
L1MuGMTMatcher * m_Matcher[2]
void dumpLUTs(std::string dir)
static int getBxMinRo()
L1MuGMTMerger * m_Merger[2]
void setCaloGeom(const L1CaloGeometry *caloGeom)
void print() const
print results after selection
void reset()
clear Merger
unsigned long long m_L1MuGMTScalesCacheID
static int getBxMin()
void print()
print results after sorting
L1MuGMTCancelOutUnit * m_CancelOutUnit[4]
void reset()
clear Matcher
void run()
run GMT Merger
void setGMTParams(const L1MuGMTParameters *gmtparams)
def mkdir(path)
Definition: eostools.py:251
void clearLUTsRegs()
void receiveData(edm::Event &e, int bx)
receive muon candidates
Definition: L1MuGMTPSB.cc:86
T get() const
Definition: EventSetup.h:73
void reset()
Reset the debug block.
static L1MuGMTConfig * m_config
unsigned long long m_L1MuGMTParametersCacheID
void createLUTsRegs()
static int getBxMax()
static L1MuGMTDebugBlock * m_db
void setTriggerScales(const L1MuTriggerScales *trigscales)
void run()
run cancel-out unit
T const * product() const
Definition: ESHandle.h:86
int numberOfCands() const
return number of found muon candidates after sorter
Definition: L1MuGMTSorter.h:57
def move(src, dest)
Definition: eostools.py:511