CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
52 
53 //----------------
54 // Constructors --
55 //----------------
57  produces<std::vector<L1MuGMTCand> >();
58  produces<L1MuGMTReadoutCollection>();
59  m_sendMipIso = ps.getUntrackedParameter<bool>("SendMipIso", false);
60  if (m_sendMipIso) {
61  produces<std::vector<unsigned> >();
62  }
63 
70 
71  m_ExtendedCands.reserve(20);
72 
73  // set configuration parameters
74  if (!m_config)
75  m_config = new L1MuGMTConfig(ps);
76  m_writeLUTsAndRegs = ps.getUntrackedParameter<bool>("WriteLUTsAndRegs", false);
77 
78  // build GMT
79  if (L1MuGMTConfig::Debug(1))
80  edm::LogVerbatim("GMT_info");
81  if (L1MuGMTConfig::Debug(1))
82  edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger building ****";
83  if (L1MuGMTConfig::Debug(1))
84  edm::LogVerbatim("GMT_info");
85 
86  // create new PSB
87  if (L1MuGMTConfig::Debug(2))
88  edm::LogVerbatim("GMT_info") << "creating GMT PSB";
89  m_PSB = new L1MuGMTPSB(*this, consumesCollector());
90 
91  // create new matcher
92  if (L1MuGMTConfig::Debug(2))
93  edm::LogVerbatim("GMT_info") << "creating GMT Matcher (0,1)";
94  m_Matcher[0] = new L1MuGMTMatcher(*this, 0); // barrel
95  m_Matcher[1] = new L1MuGMTMatcher(*this, 1); // endcap
96 
97  // create new cancel-out units
98  if (L1MuGMTConfig::Debug(2))
99  edm::LogVerbatim("GMT_info") << "creating GMT Cancel Out Unit (0,1,2,3)";
100  m_CancelOutUnit[0] = new L1MuGMTCancelOutUnit(*this, 0); // barrel
101  m_CancelOutUnit[1] = new L1MuGMTCancelOutUnit(*this, 1); // endcap
102  m_CancelOutUnit[2] = new L1MuGMTCancelOutUnit(*this, 2); // CSC/bRPC
103  m_CancelOutUnit[3] = new L1MuGMTCancelOutUnit(*this, 3); // DT/fRPC
104 
105  // create new MIP & ISO bit assignment units
106  if (L1MuGMTConfig::Debug(2))
107  edm::LogVerbatim("GMT_info") << "creating GMT MIP & ISO bit Assigment Unit (0,1)";
108  m_MipIsoAU[0] = new L1MuGMTMipIsoAU(*this, 0); // barrel
109  m_MipIsoAU[1] = new L1MuGMTMipIsoAU(*this, 1); // endcap
110 
111  // create new Merger
112  if (L1MuGMTConfig::Debug(2))
113  edm::LogVerbatim("GMT_info") << "creating GMT Merger (0,1)";
114  m_Merger[0] = new L1MuGMTMerger(*this, 0); // barrel
115  m_Merger[1] = new L1MuGMTMerger(*this, 1); // endcap
116 
117  // create new sorter
118  if (L1MuGMTConfig::Debug(2))
119  edm::LogVerbatim("GMT_info") << "creating GMT Sorter";
120  m_Sorter = new L1MuGMTSorter(*this); // barrel
121 
122  if (!m_db)
124  usesResource("L1MuGlobalMuonTrigger");
126  m_gmtScalesToken = esConsumes<L1MuGMTScales, L1MuGMTScalesRcd>();
127  m_trigScalesToken = esConsumes<L1MuTriggerScales, L1MuTriggerScalesRcd>();
128  m_trigPtScaleToken = esConsumes<L1MuTriggerPtScale, L1MuTriggerPtScaleRcd>();
129  m_gmtParamsToken = esConsumes<L1MuGMTParameters, L1MuGMTParametersRcd>();
130  m_gmtChanMaskToken = esConsumes<L1MuGMTChannelMask, L1MuGMTChannelMaskRcd>();
131  m_caloGeomToken = esConsumes<L1CaloGeometry, L1CaloGeometryRecord>();
132 }
133 
134 //--------------
135 // Destructor --
136 //--------------
138  if (m_db)
139  delete m_db;
140  m_db = nullptr;
141 
142  delete m_Sorter;
143  delete m_Merger[1]; // endcap Merger
144  delete m_Merger[0]; // barrel Merger
145  delete m_MipIsoAU[1]; // barrel MIP & ISO bit assignment unit
146  delete m_MipIsoAU[0]; // barrel MIP & ISO bit assignment unit
147  delete m_CancelOutUnit[3]; // DT/fRPC cancel-out unit (in endcap chip)
148  delete m_CancelOutUnit[2]; // CSC/bRPC cancel-out unit (in barrel chip)
149  delete m_CancelOutUnit[1]; // endcap DT/CSC cancel out unit
150  delete m_CancelOutUnit[0]; // barrel DT/CSC cancel out unit
151  delete m_Matcher[1]; // endcap matcher
152  delete m_Matcher[0]; // barrel matcher
153  delete m_PSB;
154 
155  if (m_config)
156  delete m_config;
157  m_config = nullptr;
158 
159  // copied from produce() by Jim B, 7 Aug 2007
160  std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
161  for (; irr != m_ReadoutRingbuffer.end(); irr++)
162  delete (*irr);
163  m_ReadoutRingbuffer.clear();
164  // end Jim B edit
165 }
166 
167 //--------------
168 // Operations --
169 //--------------
170 
172 
174  // configure from the event setup
175 
176  unsigned long long L1MuGMTScalesCacheID = es.get<L1MuGMTScalesRcd>().cacheIdentifier();
177  if (L1MuGMTScalesCacheID != m_L1MuGMTScalesCacheID) {
179  m_config->setGMTScales(gmtscales_h.product());
180  }
181 
182  unsigned long long L1MuTriggerScalesCacheID = es.get<L1MuTriggerScalesRcd>().cacheIdentifier();
183  if (L1MuTriggerScalesCacheID != m_L1MuTriggerScalesCacheID) {
185  m_config->setTriggerScales(trigscales_h.product());
186  }
187 
188  unsigned long long L1MuTriggerPtScaleCacheID = es.get<L1MuTriggerPtScaleRcd>().cacheIdentifier();
189  if (L1MuTriggerPtScaleCacheID != m_L1MuTriggerPtScaleCacheID) {
191  m_config->setTriggerPtScale(trigptscale_h.product());
192  }
193 
194  unsigned long long L1MuGMTParametersCacheID = es.get<L1MuGMTParametersRcd>().cacheIdentifier();
195  if (L1MuGMTParametersCacheID != m_L1MuGMTParametersCacheID) {
197  m_config->setGMTParams(gmtparams_h.product());
199  }
200 
201  unsigned long long L1MuGMTChannelMaskCacheID = es.get<L1MuGMTChannelMaskRcd>().cacheIdentifier();
202  if (L1MuGMTChannelMaskCacheID != m_L1MuGMTChannelMaskCacheID) {
204  m_config->setGMTChanMask(gmtchanmask_h.product());
205  if (L1MuGMTConfig::Debug(1)) {
206  std::string onoff;
207  const L1MuGMTChannelMask* theChannelMask = L1MuGMTConfig::getGMTChanMask();
208  unsigned mask = theChannelMask->getSubsystemMask();
209 
210  edm::LogVerbatim("GMT_info");
211  edm::LogVerbatim("GMT_info") << " GMT input Channel Mask:" << std::hex << mask << std::dec;
212  onoff = mask & 1 ? "OFF" : "ON";
213  edm::LogVerbatim("GMT_info") << " DT input " << onoff;
214  onoff = mask & 2 ? "OFF" : "ON";
215  edm::LogVerbatim("GMT_info") << " RPCb input " << onoff;
216  onoff = mask & 4 ? "OFF" : "ON";
217  edm::LogVerbatim("GMT_info") << " CSC input " << onoff;
218  onoff = mask & 8 ? "OFF" : "ON";
219  edm::LogVerbatim("GMT_info") << " RPCf input " << onoff;
220  edm::LogVerbatim("GMT_info");
221  }
222  }
223 
224  unsigned long long L1CaloGeometryCacheID = es.get<L1CaloGeometryRecord>().cacheIdentifier();
225  if (L1CaloGeometryCacheID != m_L1CaloGeometryCacheID) {
227  m_config->setCaloGeom(caloGeom_h.product());
228  }
229 
231 
232  // write LUTs and Regs if required
233 
234  if (m_writeLUTsAndRegs) {
235  std::string dir = "gmtconfig";
236 
237  mkdir(dir.c_str(), S_ISUID | S_ISGID | S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR);
238 
239  m_config->dumpLUTs(dir);
240  m_config->dumpRegs(dir);
241  }
242 
243  // process the event
244  if (L1MuGMTConfig::Debug(2))
245  edm::LogVerbatim("GMT_info");
246  if (L1MuGMTConfig::Debug(2))
247  edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger processing ****";
248  if (L1MuGMTConfig::Debug(2))
249  edm::LogVerbatim("GMT_info");
250 
251  int bx_min = L1MuGMTConfig::getBxMin();
252  int bx_max = L1MuGMTConfig::getBxMax();
253 
254  m_ExtendedCands.clear();
255 
256  // clear readout ring buffer
257  std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
258  for (; irr != m_ReadoutRingbuffer.end(); irr++)
259  delete (*irr);
260  m_ReadoutRingbuffer.clear();
261 
262  if (m_db)
263  m_db->reset(); // reset debug block
264 
265  for (int bx = bx_min; bx <= bx_max; bx++) {
266  m_db->SetBX(bx);
267 
268  // create new element in readout ring buffer
270 
271  if (L1MuGMTConfig::Debug(2))
272  edm::LogVerbatim("GMT_info") << "L1GlobalMuonTrigger processing bunch-crossing : " << bx;
273 
274  // get data into the data buffer
275  if (L1MuGMTConfig::Debug(2))
276  edm::LogVerbatim("GMT_info") << "running GMT PSB";
277  if (m_PSB) {
278  m_PSB->receiveData(e, bx);
279  if (L1MuGMTConfig::Debug(4))
280  m_PSB->print();
281  }
282 
283  if (m_PSB && !m_PSB->empty()) {
284  // run matcher
285  if (L1MuGMTConfig::Debug(2))
286  edm::LogVerbatim("GMT_info") << "running GMT barrel Matcher";
287  if (m_Matcher[0])
288  m_Matcher[0]->run();
289  if (L1MuGMTConfig::Debug(3) && m_Matcher[0])
290  m_Matcher[0]->print();
291  if (L1MuGMTConfig::Debug(2))
292  edm::LogVerbatim("GMT_info") << "running GMT endcap Matcher";
293  if (m_Matcher[1])
294  m_Matcher[1]->run();
295  if (L1MuGMTConfig::Debug(3) && m_Matcher[1])
296  m_Matcher[1]->print();
297 
298  // run cancel-out units
299  if (L1MuGMTConfig::Debug(2))
300  edm::LogVerbatim("GMT_info") << "running GMT barrel Cancel Out Unit";
301  if (m_CancelOutUnit[0])
302  m_CancelOutUnit[0]->run();
304  m_CancelOutUnit[0]->print();
305 
306  if (L1MuGMTConfig::Debug(2))
307  edm::LogVerbatim("GMT_info") << "running GMT endcap Cancel Out Unit";
308  if (m_CancelOutUnit[1])
309  m_CancelOutUnit[1]->run();
311  m_CancelOutUnit[1]->print();
312 
313  if (L1MuGMTConfig::Debug(2))
314  edm::LogVerbatim("GMT_info") << "running GMT CSC/fRPC Cancel Out Unit";
315  if (m_CancelOutUnit[2])
316  m_CancelOutUnit[2]->run();
318  m_CancelOutUnit[2]->print();
319 
320  if (L1MuGMTConfig::Debug(2))
321  edm::LogVerbatim("GMT_info") << "running GMT DT/bRPC Cancel Out Unit";
322  if (m_CancelOutUnit[3])
323  m_CancelOutUnit[3]->run();
325  m_CancelOutUnit[3]->print();
326 
327  // run MIP & ISO bit assignment units
328  if (L1MuGMTConfig::Debug(2))
329  edm::LogVerbatim("GMT_info") << "running GMT barrel MIP & ISO bit Assignment Unit";
330  if (m_MipIsoAU[0])
331  m_MipIsoAU[0]->run();
332  if (L1MuGMTConfig::Debug(3) && m_MipIsoAU[0])
333  m_MipIsoAU[0]->print();
334  if (L1MuGMTConfig::Debug(2))
335  edm::LogVerbatim("GMT_info") << "running GMT endcap MIP & ISO bit Assignment Unit";
336  if (m_MipIsoAU[1])
337  m_MipIsoAU[1]->run();
338  if (L1MuGMTConfig::Debug(3) && m_MipIsoAU[1])
339  m_MipIsoAU[1]->print();
340 
341  // run Merger
342  if (L1MuGMTConfig::Debug(2))
343  edm::LogVerbatim("GMT_info") << "running GMT barrel Merger";
344  if (m_Merger[0])
345  m_Merger[0]->run();
346  if (L1MuGMTConfig::Debug(3) && m_Merger[0])
347  m_Merger[0]->print();
348  if (L1MuGMTConfig::Debug(2))
349  edm::LogVerbatim("GMT_info") << "running GMT endcap Merger";
350  if (m_Merger[1])
351  m_Merger[1]->run();
352  if (L1MuGMTConfig::Debug(3) && m_Merger[1])
353  m_Merger[1]->print();
354 
355  // run sorter
356  if (L1MuGMTConfig::Debug(2))
357  edm::LogVerbatim("GMT_info") << "running GMT Sorter";
358  if (m_Sorter)
359  m_Sorter->run();
360  if (L1MuGMTConfig::Debug(1) && m_Sorter)
361  m_Sorter->print();
362 
363  // store found track candidates in a container
364  if (m_Sorter->numberOfCands() > 0) {
365  const std::vector<const L1MuGMTExtendedCand*>& gmt_cont = m_Sorter->Cands();
366  std::vector<const L1MuGMTExtendedCand*>::const_iterator iexc;
367  for (iexc = gmt_cont.begin(); iexc != gmt_cont.end(); iexc++) {
368  if (*iexc)
369  m_ExtendedCands.push_back(**iexc);
370  }
371  }
372 
373  // reset GMT
374  reset();
375  }
376  }
377 
378  // produce the output
379  std::unique_ptr<std::vector<L1MuGMTCand> > GMTCands(new std::vector<L1MuGMTCand>);
380  std::vector<L1MuGMTExtendedCand>::const_iterator iexc;
381  for (iexc = m_ExtendedCands.begin(); iexc != m_ExtendedCands.end(); iexc++) {
382  GMTCands->push_back(*iexc);
383  }
384  e.put(std::move(GMTCands));
385 
386  std::unique_ptr<L1MuGMTReadoutCollection> GMTRRC(getReadoutCollection());
387  e.put(std::move(GMTRRC));
388 
389  if (m_sendMipIso) {
390  std::unique_ptr<std::vector<unsigned> > mipiso(new std::vector<unsigned>);
391  for (int i = 0; i < 32; i++) {
392  mipiso->push_back(m_db->IsMIPISO(0, i));
393  }
394  e.put(std::move(mipiso));
395  }
396 
397  // delete registers and LUTs
399 }
400 
401 //
402 // reset GMT
403 //
405  if (m_PSB)
406  m_PSB->reset();
407  if (m_Matcher[0])
408  m_Matcher[0]->reset();
409  if (m_Matcher[1])
410  m_Matcher[1]->reset();
411  if (m_CancelOutUnit[0])
412  m_CancelOutUnit[0]->reset();
413  if (m_CancelOutUnit[1])
414  m_CancelOutUnit[1]->reset();
415  if (m_CancelOutUnit[2])
416  m_CancelOutUnit[2]->reset();
417  if (m_CancelOutUnit[3])
418  m_CancelOutUnit[3]->reset();
419  if (m_MipIsoAU[0])
420  m_MipIsoAU[0]->reset();
421  if (m_MipIsoAU[1])
422  m_MipIsoAU[1]->reset();
423  if (m_Merger[0])
424  m_Merger[0]->reset();
425  if (m_Merger[1])
426  m_Merger[1]->reset();
427  if (m_Sorter)
428  m_Sorter->reset();
429 }
430 
431 // get the GMT readout data for the triggered bx
432 std::unique_ptr<L1MuGMTReadoutCollection> L1MuGlobalMuonTrigger::getReadoutCollection() {
433  int bx_min_ro = L1MuGMTConfig::getBxMinRo();
434  int bx_max_ro = L1MuGMTConfig::getBxMaxRo();
435  int bx_size = bx_max_ro - bx_min_ro + 1;
436 
437  std::unique_ptr<L1MuGMTReadoutCollection> rrc(new L1MuGMTReadoutCollection(bx_size));
438 
439  for (int bx = bx_min_ro; bx <= bx_max_ro; bx++) {
440  std::vector<L1MuGMTReadoutRecord*>::const_iterator iter = m_ReadoutRingbuffer.begin();
441 
442  for (; iter != m_ReadoutRingbuffer.end(); iter++) {
443  if ((*iter)->getBxInEvent() == bx) {
444  rrc->addRecord(**iter);
445  break;
446  }
447  }
448  }
449 
450  return rrc;
451 }
452 
453 // static data members
454 
Log< level::Info, true > LogVerbatim
void setGMTChanMask(const L1MuGMTChannelMask *gmtchanmask)
T getUntrackedParameter(std::string const &, T const &) const
edm::ESGetToken< L1MuTriggerPtScale, L1MuTriggerPtScaleRcd > m_trigPtScaleToken
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:133
unsigned long long m_L1MuGMTChannelMaskCacheID
void print() const
print PSB
Definition: L1MuGMTPSB.cc:212
edm::ESGetToken< L1MuGMTParameters, L1MuGMTParametersRcd > m_gmtParamsToken
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 &amp; ISO bit assignment
edm::ESGetToken< L1MuTriggerScales, L1MuTriggerScalesRcd > m_trigScalesToken
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 &amp; 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 &amp; 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.
def move
Definition: eostools.py:511
edm::ESGetToken< L1MuGMTScales, L1MuGMTScalesRcd > m_gmtScalesToken
edm::ESGetToken< L1CaloGeometry, L1CaloGeometryRecord > m_caloGeomToken
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
T const * product() const
Definition: ESHandle.h:86
void run()
run GMT Merger
void setGMTParams(const L1MuGMTParameters *gmtparams)
void clearLUTsRegs()
def mkdir
Definition: eostools.py:251
void receiveData(edm::Event &e, int bx)
receive muon candidates
Definition: L1MuGMTPSB.cc:86
edm::ESGetToken< L1MuGMTChannelMask, L1MuGMTChannelMaskRcd > m_gmtChanMaskToken
T get() const
Definition: EventSetup.h:88
void reset()
Reset the debug block.
static L1MuGMTConfig * m_config
unsigned long long m_L1MuGMTParametersCacheID
void createLUTsRegs()
static int getBxMax()
static L1MuGMTDebugBlock * m_db
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
void setTriggerScales(const L1MuTriggerScales *trigscales)
void run()
run cancel-out unit
int numberOfCands() const
return number of found muon candidates after sorter
Definition: L1MuGMTSorter.h:57