CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
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) m_config = new L1MuGMTConfig(ps);
88  m_writeLUTsAndRegs = ps.getUntrackedParameter<bool>("WriteLUTsAndRegs",false);
89 
90  // build GMT
91  if ( L1MuGMTConfig::Debug(1) ) edm::LogVerbatim("GMT_info");
92  if ( L1MuGMTConfig::Debug(1) ) edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger building ****";
93  if ( L1MuGMTConfig::Debug(1) ) edm::LogVerbatim("GMT_info");
94 
95  // create new PSB
96  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT PSB";
97  m_PSB = new L1MuGMTPSB(*this);
98 
99  // create new matcher
100  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT Matcher (0,1)";
101  m_Matcher[0] = new L1MuGMTMatcher(*this,0); // barrel
102  m_Matcher[1] = new L1MuGMTMatcher(*this,1); // endcap
103 
104  // create new cancel-out units
105  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT Cancel Out Unit (0,1,2,3)";
106  m_CancelOutUnit[0] = new L1MuGMTCancelOutUnit(*this,0); // barrel
107  m_CancelOutUnit[1] = new L1MuGMTCancelOutUnit(*this,1); // endcap
108  m_CancelOutUnit[2] = new L1MuGMTCancelOutUnit(*this,2); // CSC/bRPC
109  m_CancelOutUnit[3] = new L1MuGMTCancelOutUnit(*this,3); // DT/fRPC
110 
111  // create new MIP & ISO bit assignment units
112  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT MIP & ISO bit Assigment Unit (0,1)";
113  m_MipIsoAU[0] = new L1MuGMTMipIsoAU(*this,0); // barrel
114  m_MipIsoAU[1] = new L1MuGMTMipIsoAU(*this,1); // endcap
115 
116  // create new Merger
117  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT Merger (0,1)";
118  m_Merger[0] = new L1MuGMTMerger(*this,0); // barrel
119  m_Merger[1] = new L1MuGMTMerger(*this,1); // endcap
120 
121  // create new sorter
122  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT Sorter";
123  m_Sorter = new L1MuGMTSorter(*this); // barrel
124 
126 }
127 
128 //--------------
129 // Destructor --
130 //--------------
132 
133  if(m_db) delete m_db;
134  m_db = 0;
135 
136  delete m_Sorter;
137  delete m_Merger[1]; // endcap Merger
138  delete m_Merger[0]; // barrel Merger
139  delete m_MipIsoAU[1]; // barrel MIP & ISO bit assignment unit
140  delete m_MipIsoAU[0]; // barrel MIP & ISO bit assignment unit
141  delete m_CancelOutUnit[3]; // DT/fRPC cancel-out unit (in endcap chip)
142  delete m_CancelOutUnit[2]; // CSC/bRPC cancel-out unit (in barrel chip)
143  delete m_CancelOutUnit[1]; // endcap DT/CSC cancel out unit
144  delete m_CancelOutUnit[0]; // barrel DT/CSC cancel out unit
145  delete m_Matcher[1]; // endcap matcher
146  delete m_Matcher[0]; // barrel matcher
147  delete m_PSB;
148 
149  if(m_config) delete m_config;
150  m_config = 0;
151 
152  // copied from produce() by Jim B, 7 Aug 2007
153  std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
154  for ( ;irr!=m_ReadoutRingbuffer.end(); irr++) delete (*irr);
155  m_ReadoutRingbuffer.clear();
156  // end Jim B edit
157 
158 }
159 
160 //--------------
161 // Operations --
162 //--------------
163 
165 
166 }
167 
169 
170  // configure from the event setup
171 
172  unsigned long long L1MuGMTScalesCacheID = es.get< L1MuGMTScalesRcd >().cacheIdentifier();
173  if(L1MuGMTScalesCacheID != m_L1MuGMTScalesCacheID) {
174  edm::ESHandle< L1MuGMTScales > gmtscales_h;
175  es.get< L1MuGMTScalesRcd >().get( gmtscales_h );
176  m_config->setGMTScales( gmtscales_h.product() );
177  }
178 
179  unsigned long long L1MuTriggerScalesCacheID = es.get< L1MuTriggerScalesRcd >().cacheIdentifier();
180  if(L1MuTriggerScalesCacheID != m_L1MuTriggerScalesCacheID) {
182  es.get< L1MuTriggerScalesRcd >().get( trigscales_h );
183  m_config->setTriggerScales( trigscales_h.product() );
184  }
185 
186  unsigned long long L1MuTriggerPtScaleCacheID = es.get< L1MuTriggerPtScaleRcd >().cacheIdentifier();
187  if(L1MuTriggerPtScaleCacheID != m_L1MuTriggerPtScaleCacheID) {
189  es.get< L1MuTriggerPtScaleRcd >().get( trigptscale_h );
190  m_config->setTriggerPtScale( trigptscale_h.product() );
191  }
192 
193  unsigned long long L1MuGMTParametersCacheID = es.get< L1MuGMTParametersRcd >().cacheIdentifier();
194  if(L1MuGMTParametersCacheID != m_L1MuGMTParametersCacheID) {
196  es.get< L1MuGMTParametersRcd >().get( gmtparams_h );
197  m_config->setGMTParams( gmtparams_h.product() );
199  }
200 
201  unsigned long long L1MuGMTChannelMaskCacheID = es.get< L1MuGMTChannelMaskRcd >().cacheIdentifier();
202  if(L1MuGMTChannelMaskCacheID != m_L1MuGMTChannelMaskCacheID) {
204  es.get< L1MuGMTChannelMaskRcd >().get( gmtchanmask_h );
205  m_config->setGMTChanMask( gmtchanmask_h.product() );
206  if ( L1MuGMTConfig::Debug(1) ) {
207  std::string onoff;
208  const L1MuGMTChannelMask* theChannelMask = L1MuGMTConfig::getGMTChanMask();
209  unsigned mask = theChannelMask->getSubsystemMask();
210 
211  edm::LogVerbatim("GMT_info");
212  edm::LogVerbatim("GMT_info") << " GMT input Channel Mask:" << std::hex << mask << std::dec;
213  onoff = mask&1 ? "OFF" : "ON";
214  edm::LogVerbatim("GMT_info") << " DT input " << onoff;
215  onoff = mask&2 ? "OFF" : "ON";
216  edm::LogVerbatim("GMT_info") << " RPCb input " << onoff;
217  onoff = mask&4 ? "OFF" : "ON";
218  edm::LogVerbatim("GMT_info") << " CSC input " << onoff;
219  onoff = mask&8 ? "OFF" : "ON";
220  edm::LogVerbatim("GMT_info") << " RPCf input " << onoff;
221  edm::LogVerbatim("GMT_info");
222  }
223  }
224 
225  unsigned long long L1CaloGeometryCacheID = es.get< L1CaloGeometryRecord >().cacheIdentifier();
226  if(L1CaloGeometryCacheID != m_L1CaloGeometryCacheID) {
228  es.get< L1CaloGeometryRecord >().get( caloGeom_h ) ;
229  m_config->setCaloGeom( caloGeom_h.product() ) ;
230  }
231 
233 
234  // write LUTs and Regs if required
235 
236  if(m_writeLUTsAndRegs) {
237  std::string dir = "gmtconfig";
238 
239  mkdir(dir.c_str(), S_ISUID|S_ISGID|S_ISVTX|S_IRUSR|S_IWUSR|S_IXUSR);
240 
241  m_config->dumpLUTs(dir);
242  m_config->dumpRegs(dir);
243  }
244 
245  // process the event
246  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info");
247  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger processing ****";
248  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info");
249 
250  int bx_min = L1MuGMTConfig::getBxMin();
251  int bx_max = L1MuGMTConfig::getBxMax();
252 
253  m_ExtendedCands.clear();
254 
255  // clear readout ring buffer
256  std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
257  for ( ;irr!=m_ReadoutRingbuffer.end(); irr++) delete (*irr);
258  m_ReadoutRingbuffer.clear();
259 
260  if(m_db) m_db->reset(); // reset debug block
261 
262  for ( int bx = bx_min; bx <= bx_max; bx++ ) {
263  m_db->SetBX(bx);
264 
265  // create new element in readout ring buffer
266  m_ReadoutRingbuffer.push_back( new L1MuGMTReadoutRecord(bx) );
267 
268  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "L1GlobalMuonTrigger processing bunch-crossing : " << bx;
269 
270  // get data into the data buffer
271  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT PSB";
272  if ( m_PSB ) {
273  m_PSB->receiveData(e,bx);
274  if ( L1MuGMTConfig::Debug(4) ) m_PSB->print();
275  }
276 
277  if ( m_PSB && !m_PSB->empty() ) {
278 
279  // run matcher
280  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT barrel Matcher";
281  if ( m_Matcher[0] ) m_Matcher[0]->run();
282  if ( L1MuGMTConfig::Debug(3) && m_Matcher[0] ) m_Matcher[0]->print();
283  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT endcap Matcher";
284  if ( m_Matcher[1] ) m_Matcher[1]->run();
285  if ( L1MuGMTConfig::Debug(3) && m_Matcher[1] ) m_Matcher[1]->print();
286 
287  // run cancel-out units
288  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT barrel Cancel Out Unit";
289  if ( m_CancelOutUnit[0] ) m_CancelOutUnit[0]->run();
291 
292  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT endcap Cancel Out Unit";
293  if ( m_CancelOutUnit[1] ) m_CancelOutUnit[1]->run();
295 
296  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT CSC/fRPC Cancel Out Unit";
297  if ( m_CancelOutUnit[2] ) m_CancelOutUnit[2]->run();
299 
300  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT DT/bRPC Cancel Out Unit";
301  if ( m_CancelOutUnit[3] ) m_CancelOutUnit[3]->run();
303 
304  // run MIP & ISO bit assignment units
305  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT barrel MIP & ISO bit Assignment Unit";
306  if ( m_MipIsoAU[0] ) m_MipIsoAU[0]->run();
307  if ( L1MuGMTConfig::Debug(3) && m_MipIsoAU[0] ) m_MipIsoAU[0]->print();
308  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT endcap MIP & ISO bit Assignment Unit";
309  if ( m_MipIsoAU[1] ) m_MipIsoAU[1]->run();
310  if ( L1MuGMTConfig::Debug(3) && m_MipIsoAU[1] ) m_MipIsoAU[1]->print();
311 
312  // run Merger
313  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT barrel Merger";
314  if ( m_Merger[0] ) m_Merger[0]->run();
315  if ( L1MuGMTConfig::Debug(3) && m_Merger[0] ) m_Merger[0]->print();
316  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT endcap Merger";
317  if ( m_Merger[1] ) m_Merger[1]->run();
318  if ( L1MuGMTConfig::Debug(3) && m_Merger[1] ) m_Merger[1]->print();
319 
320  // run sorter
321  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT Sorter";
322  if ( m_Sorter ) m_Sorter->run();
324 
325  // store found track candidates in a container
326  if ( m_Sorter->numberOfCands() > 0 ) {
327  const std::vector<const L1MuGMTExtendedCand*>& gmt_cont = m_Sorter->Cands();
328  std::vector<const L1MuGMTExtendedCand*>::const_iterator iexc;
329  for ( iexc = gmt_cont.begin(); iexc != gmt_cont.end(); iexc++ ) {
330  if ( *iexc ) m_ExtendedCands.push_back( **iexc );
331  }
332  }
333 
334  // reset GMT
335  reset();
336 
337  }
338  }
339 
340  // produce the output
341  std::auto_ptr<std::vector<L1MuGMTCand> > GMTCands(new std::vector<L1MuGMTCand>);
342  std::vector<L1MuGMTExtendedCand>::const_iterator iexc;
343  for(iexc=m_ExtendedCands.begin(); iexc!=m_ExtendedCands.end(); iexc++) {
344  GMTCands->push_back(*iexc);
345  }
346  e.put(GMTCands);
347 
348  std::auto_ptr<L1MuGMTReadoutCollection> GMTRRC(getReadoutCollection());
349  e.put(GMTRRC);
350 
351  if( m_sendMipIso ) {
352  std::auto_ptr<std::vector<unsigned> > mipiso(new std::vector<unsigned>);
353  for(int i=0; i<32; i++) {
354  mipiso->push_back(m_db->IsMIPISO(0,i));
355  }
356  e.put(mipiso);
357  }
358 
359 // delete registers and LUTs
361 }
362 
363 //
364 // reset GMT
365 //
367 
368  if ( m_PSB ) m_PSB->reset();
369  if ( m_Matcher[0] ) m_Matcher[0]->reset();
370  if ( m_Matcher[1] ) m_Matcher[1]->reset();
371  if ( m_CancelOutUnit[0] ) m_CancelOutUnit[0]->reset();
372  if ( m_CancelOutUnit[1] ) m_CancelOutUnit[1]->reset();
373  if ( m_CancelOutUnit[2] ) m_CancelOutUnit[2]->reset();
374  if ( m_CancelOutUnit[3] ) m_CancelOutUnit[3]->reset();
375  if ( m_MipIsoAU[0] ) m_MipIsoAU[0]->reset();
376  if ( m_MipIsoAU[1] ) m_MipIsoAU[1]->reset();
377  if ( m_Merger[0] ) m_Merger[0]->reset();
378  if ( m_Merger[1] ) m_Merger[1]->reset();
379  if ( m_Sorter) m_Sorter->reset();
380 
381 }
382 
383 // get the GMT readout data for the triggered bx
384 std::auto_ptr<L1MuGMTReadoutCollection> L1MuGlobalMuonTrigger::getReadoutCollection() {
385 
386  int bx_min_ro = L1MuGMTConfig::getBxMinRo();
387  int bx_max_ro = L1MuGMTConfig::getBxMaxRo();
388  int bx_size = bx_max_ro - bx_min_ro + 1;
389 
390  std::auto_ptr<L1MuGMTReadoutCollection> rrc(new L1MuGMTReadoutCollection(bx_size));
391 
392  for (int bx = bx_min_ro; bx <= bx_max_ro; bx++) {
393  std::vector<L1MuGMTReadoutRecord*>::const_iterator iter = m_ReadoutRingbuffer.begin();
394 
395  for ( ;iter!=m_ReadoutRingbuffer.end(); iter++) {
396 
397  if ( (*iter)->getBxInEvent() == bx ) {
398  rrc->addRecord(**iter);
399  break;
400  }
401  }
402 
403  }
404 
405  return rrc;
406 }
407 
408 // static data members
409 
void setGMTChanMask(const L1MuGMTChannelMask *gmtchanmask)
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
unsigned long long m_L1MuTriggerScalesCacheID
std::vector< L1MuGMTReadoutRecord * > m_ReadoutRingbuffer
unsigned long long m_L1MuGMTChannelMaskCacheID
void print() const
print PSB
Definition: L1MuGMTPSB.cc:215
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
void print()
print cancel-out bits
bool empty() const
are there any data in the PSB
Definition: L1MuGMTPSB.cc:307
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:194
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:64
unsigned long long m_L1CaloGeometryCacheID
virtual void run()
run Sorter
void run()
run GMT MIP &amp; ISO bit assignment unit
std::auto_ptr< L1MuGMTReadoutCollection > getReadoutCollection()
void setGMTScales(const L1MuGMTScales *gmtscales)
unsigned long long m_L1MuTriggerPtScaleCacheID
static bool Debug()
L1MuGMTMipIsoAU * m_MipIsoAU[2]
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
static const L1MuGMTChannelMask * getGMTChanMask()
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]
const T & get() const
Definition: EventSetup.h:55
void reset()
clear Matcher
T const * product() const
Definition: ESHandle.h:62
void run()
run GMT Merger
void setGMTParams(const L1MuGMTParameters *gmtparams)
void clearLUTsRegs()
void receiveData(edm::Event &e, int bx)
receive muon candidates
Definition: L1MuGMTPSB.cc:86
void reset()
Reset the debug block.
static L1MuGMTConfig * m_config
unsigned long long m_L1MuGMTParametersCacheID
void createLUTsRegs()
static int getBxMax()
static L1MuGMTDebugBlock * m_db
dbl *** dir
Definition: mlp_gen.cc:35
virtual void produce(edm::Event &, const edm::EventSetup &)
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:61