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