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 // $Date: 2010/02/12 12:07:37 $
9 // $Revision: 1.14 $
10 //
11 // Author :
12 // Norbert Neumeister CERN EP
13 // Hannes Sakulin HEPHY Vienna
14 // Ivan Mikulec HEPHY Vienna
15 //
16 //--------------------------------------------------
17 
18 //-----------------------
19 // This Class's Header --
20 //-----------------------
21 
23 
24 //---------------
25 // C++ Headers --
26 //---------------
27 
28 #include <iostream>
29 #include <sys/stat.h>
30 #include <sys/types.h>
31 
32 //-------------------------------
33 // Collaborating Class Headers --
34 //-------------------------------
35 
47 
49 
51 
64 
67 
68 //----------------
69 // Constructors --
70 //----------------
72  produces<std::vector<L1MuGMTCand> >();
73  produces<L1MuGMTReadoutCollection>();
74  m_sendMipIso = ps.getUntrackedParameter<bool>("SendMipIso",false);
75  if( m_sendMipIso ) {
76  produces<std::vector<unsigned> >();
77  }
78 
85 
86  m_ExtendedCands.reserve(20);
87 
88  // set configuration parameters
89  if(!m_config) m_config = new L1MuGMTConfig(ps);
90  m_writeLUTsAndRegs = ps.getUntrackedParameter<bool>("WriteLUTsAndRegs",false);
91 
92  // build GMT
93  if ( L1MuGMTConfig::Debug(1) ) edm::LogVerbatim("GMT_info");
94  if ( L1MuGMTConfig::Debug(1) ) edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger building ****";
95  if ( L1MuGMTConfig::Debug(1) ) edm::LogVerbatim("GMT_info");
96 
97  // create new PSB
98  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT PSB";
99  m_PSB = new L1MuGMTPSB(*this);
100 
101  // create new matcher
102  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT Matcher (0,1)";
103  m_Matcher[0] = new L1MuGMTMatcher(*this,0); // barrel
104  m_Matcher[1] = new L1MuGMTMatcher(*this,1); // endcap
105 
106  // create new cancel-out units
107  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT Cancel Out Unit (0,1,2,3)";
108  m_CancelOutUnit[0] = new L1MuGMTCancelOutUnit(*this,0); // barrel
109  m_CancelOutUnit[1] = new L1MuGMTCancelOutUnit(*this,1); // endcap
110  m_CancelOutUnit[2] = new L1MuGMTCancelOutUnit(*this,2); // CSC/bRPC
111  m_CancelOutUnit[3] = new L1MuGMTCancelOutUnit(*this,3); // DT/fRPC
112 
113  // create new MIP & ISO bit assignment units
114  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT MIP & ISO bit Assigment Unit (0,1)";
115  m_MipIsoAU[0] = new L1MuGMTMipIsoAU(*this,0); // barrel
116  m_MipIsoAU[1] = new L1MuGMTMipIsoAU(*this,1); // endcap
117 
118  // create new Merger
119  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT Merger (0,1)";
120  m_Merger[0] = new L1MuGMTMerger(*this,0); // barrel
121  m_Merger[1] = new L1MuGMTMerger(*this,1); // endcap
122 
123  // create new sorter
124  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "creating GMT Sorter";
125  m_Sorter = new L1MuGMTSorter(*this); // barrel
126 
128 }
129 
130 //--------------
131 // Destructor --
132 //--------------
134 
135  if(m_db) delete m_db;
136  m_db = 0;
137 
138  delete m_Sorter;
139  delete m_Merger[1]; // endcap Merger
140  delete m_Merger[0]; // barrel Merger
141  delete m_MipIsoAU[1]; // barrel MIP & ISO bit assignment unit
142  delete m_MipIsoAU[0]; // barrel MIP & ISO bit assignment unit
143  delete m_CancelOutUnit[3]; // DT/fRPC cancel-out unit (in endcap chip)
144  delete m_CancelOutUnit[2]; // CSC/bRPC cancel-out unit (in barrel chip)
145  delete m_CancelOutUnit[1]; // endcap DT/CSC cancel out unit
146  delete m_CancelOutUnit[0]; // barrel DT/CSC cancel out unit
147  delete m_Matcher[1]; // endcap matcher
148  delete m_Matcher[0]; // barrel matcher
149  delete m_PSB;
150 
151  if(m_config) delete m_config;
152  m_config = 0;
153 
154  // copied from produce() by Jim B, 7 Aug 2007
155  std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
156  for ( ;irr!=m_ReadoutRingbuffer.end(); irr++) delete (*irr);
157  m_ReadoutRingbuffer.clear();
158  // end Jim B edit
159 
160 }
161 
162 //--------------
163 // Operations --
164 //--------------
165 
167 
168 }
169 
171 
172  // configure from the event setup
173 
174  unsigned long long L1MuGMTScalesCacheID = es.get< L1MuGMTScalesRcd >().cacheIdentifier();
175  if(L1MuGMTScalesCacheID != m_L1MuGMTScalesCacheID) {
176  edm::ESHandle< L1MuGMTScales > gmtscales_h;
177  es.get< L1MuGMTScalesRcd >().get( gmtscales_h );
178  m_config->setGMTScales( gmtscales_h.product() );
179  }
180 
181  unsigned long long L1MuTriggerScalesCacheID = es.get< L1MuTriggerScalesRcd >().cacheIdentifier();
182  if(L1MuTriggerScalesCacheID != m_L1MuTriggerScalesCacheID) {
184  es.get< L1MuTriggerScalesRcd >().get( trigscales_h );
185  m_config->setTriggerScales( trigscales_h.product() );
186  }
187 
188  unsigned long long L1MuTriggerPtScaleCacheID = es.get< L1MuTriggerPtScaleRcd >().cacheIdentifier();
189  if(L1MuTriggerPtScaleCacheID != m_L1MuTriggerPtScaleCacheID) {
191  es.get< L1MuTriggerPtScaleRcd >().get( trigptscale_h );
192  m_config->setTriggerPtScale( trigptscale_h.product() );
193  }
194 
195  unsigned long long L1MuGMTParametersCacheID = es.get< L1MuGMTParametersRcd >().cacheIdentifier();
196  if(L1MuGMTParametersCacheID != m_L1MuGMTParametersCacheID) {
198  es.get< L1MuGMTParametersRcd >().get( gmtparams_h );
199  m_config->setGMTParams( gmtparams_h.product() );
201  }
202 
203  unsigned long long L1MuGMTChannelMaskCacheID = es.get< L1MuGMTChannelMaskRcd >().cacheIdentifier();
204  if(L1MuGMTChannelMaskCacheID != m_L1MuGMTChannelMaskCacheID) {
206  es.get< L1MuGMTChannelMaskRcd >().get( gmtchanmask_h );
207  m_config->setGMTChanMask( gmtchanmask_h.product() );
208  if ( L1MuGMTConfig::Debug(1) ) {
209  std::string onoff;
210  const L1MuGMTChannelMask* theChannelMask = L1MuGMTConfig::getGMTChanMask();
211  unsigned mask = theChannelMask->getSubsystemMask();
212 
213  edm::LogVerbatim("GMT_info");
214  edm::LogVerbatim("GMT_info") << " GMT input Channel Mask:" << std::hex << mask << std::dec;
215  onoff = mask&1 ? "OFF" : "ON";
216  edm::LogVerbatim("GMT_info") << " DT input " << onoff;
217  onoff = mask&2 ? "OFF" : "ON";
218  edm::LogVerbatim("GMT_info") << " RPCb input " << onoff;
219  onoff = mask&4 ? "OFF" : "ON";
220  edm::LogVerbatim("GMT_info") << " CSC input " << onoff;
221  onoff = mask&8 ? "OFF" : "ON";
222  edm::LogVerbatim("GMT_info") << " RPCf input " << onoff;
223  edm::LogVerbatim("GMT_info");
224  }
225  }
226 
227  unsigned long long L1CaloGeometryCacheID = es.get< L1CaloGeometryRecord >().cacheIdentifier();
228  if(L1CaloGeometryCacheID != m_L1CaloGeometryCacheID) {
230  es.get< L1CaloGeometryRecord >().get( caloGeom_h ) ;
231  m_config->setCaloGeom( caloGeom_h.product() ) ;
232  }
233 
235 
236  // write LUTs and Regs if required
237 
238  if(m_writeLUTsAndRegs) {
239  std::string dir = "gmtconfig";
240 
241  mkdir(dir.c_str(), S_ISUID|S_ISGID|S_ISVTX|S_IRUSR|S_IWUSR|S_IXUSR);
242 
243  m_config->dumpLUTs(dir);
244  m_config->dumpRegs(dir);
245  }
246 
247  // process the event
248  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info");
249  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "**** L1GlobalMuonTrigger processing ****";
250  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info");
251 
252  int bx_min = L1MuGMTConfig::getBxMin();
253  int bx_max = L1MuGMTConfig::getBxMax();
254 
255  m_ExtendedCands.clear();
256 
257  // clear readout ring buffer
258  std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
259  for ( ;irr!=m_ReadoutRingbuffer.end(); irr++) delete (*irr);
260  m_ReadoutRingbuffer.clear();
261 
262  if(m_db) m_db->reset(); // reset debug block
263 
264  for ( int bx = bx_min; bx <= bx_max; bx++ ) {
265  m_db->SetBX(bx);
266 
267  // create new element in readout ring buffer
268  m_ReadoutRingbuffer.push_back( new L1MuGMTReadoutRecord(bx) );
269 
270  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "L1GlobalMuonTrigger processing bunch-crossing : " << bx;
271 
272  // get data into the data buffer
273  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT PSB";
274  if ( m_PSB ) {
275  m_PSB->receiveData(e,bx);
276  if ( L1MuGMTConfig::Debug(4) ) m_PSB->print();
277  }
278 
279  if ( m_PSB && !m_PSB->empty() ) {
280 
281  // run matcher
282  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT barrel Matcher";
283  if ( m_Matcher[0] ) m_Matcher[0]->run();
284  if ( L1MuGMTConfig::Debug(3) && m_Matcher[0] ) m_Matcher[0]->print();
285  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT endcap Matcher";
286  if ( m_Matcher[1] ) m_Matcher[1]->run();
287  if ( L1MuGMTConfig::Debug(3) && m_Matcher[1] ) m_Matcher[1]->print();
288 
289  // run cancel-out units
290  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT barrel Cancel Out Unit";
291  if ( m_CancelOutUnit[0] ) m_CancelOutUnit[0]->run();
293 
294  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT endcap Cancel Out Unit";
295  if ( m_CancelOutUnit[1] ) m_CancelOutUnit[1]->run();
297 
298  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT CSC/fRPC Cancel Out Unit";
299  if ( m_CancelOutUnit[2] ) m_CancelOutUnit[2]->run();
301 
302  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT DT/bRPC Cancel Out Unit";
303  if ( m_CancelOutUnit[3] ) m_CancelOutUnit[3]->run();
305 
306  // run MIP & ISO bit assignment units
307  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT barrel MIP & ISO bit Assignment Unit";
308  if ( m_MipIsoAU[0] ) m_MipIsoAU[0]->run();
309  if ( L1MuGMTConfig::Debug(3) && m_MipIsoAU[0] ) m_MipIsoAU[0]->print();
310  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT endcap MIP & ISO bit Assignment Unit";
311  if ( m_MipIsoAU[1] ) m_MipIsoAU[1]->run();
312  if ( L1MuGMTConfig::Debug(3) && m_MipIsoAU[1] ) m_MipIsoAU[1]->print();
313 
314  // run Merger
315  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT barrel Merger";
316  if ( m_Merger[0] ) m_Merger[0]->run();
317  if ( L1MuGMTConfig::Debug(3) && m_Merger[0] ) m_Merger[0]->print();
318  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT endcap Merger";
319  if ( m_Merger[1] ) m_Merger[1]->run();
320  if ( L1MuGMTConfig::Debug(3) && m_Merger[1] ) m_Merger[1]->print();
321 
322  // run sorter
323  if ( L1MuGMTConfig::Debug(2) ) edm::LogVerbatim("GMT_info") << "running GMT Sorter";
324  if ( m_Sorter ) m_Sorter->run();
326 
327  // store found track candidates in a container
328  if ( m_Sorter->numberOfCands() > 0 ) {
329  const std::vector<const L1MuGMTExtendedCand*>& gmt_cont = m_Sorter->Cands();
330  std::vector<const L1MuGMTExtendedCand*>::const_iterator iexc;
331  for ( iexc = gmt_cont.begin(); iexc != gmt_cont.end(); iexc++ ) {
332  if ( *iexc ) m_ExtendedCands.push_back( **iexc );
333  }
334  }
335 
336  // reset GMT
337  reset();
338 
339  }
340  }
341 
342  // produce the output
343  std::auto_ptr<std::vector<L1MuGMTCand> > GMTCands(new std::vector<L1MuGMTCand>);
344  std::vector<L1MuGMTExtendedCand>::const_iterator iexc;
345  for(iexc=m_ExtendedCands.begin(); iexc!=m_ExtendedCands.end(); iexc++) {
346  GMTCands->push_back(*iexc);
347  }
348  e.put(GMTCands);
349 
350  std::auto_ptr<L1MuGMTReadoutCollection> GMTRRC(getReadoutCollection());
351  e.put(GMTRRC);
352 
353  if( m_sendMipIso ) {
354  std::auto_ptr<std::vector<unsigned> > mipiso(new std::vector<unsigned>);
355  for(int i=0; i<32; i++) {
356  mipiso->push_back(m_db->IsMIPISO(0,i));
357  }
358  e.put(mipiso);
359  }
360 
361 // delete registers and LUTs
363 }
364 
365 //
366 // reset GMT
367 //
369 
370  if ( m_PSB ) m_PSB->reset();
371  if ( m_Matcher[0] ) m_Matcher[0]->reset();
372  if ( m_Matcher[1] ) m_Matcher[1]->reset();
373  if ( m_CancelOutUnit[0] ) m_CancelOutUnit[0]->reset();
374  if ( m_CancelOutUnit[1] ) m_CancelOutUnit[1]->reset();
375  if ( m_CancelOutUnit[2] ) m_CancelOutUnit[2]->reset();
376  if ( m_CancelOutUnit[3] ) m_CancelOutUnit[3]->reset();
377  if ( m_MipIsoAU[0] ) m_MipIsoAU[0]->reset();
378  if ( m_MipIsoAU[1] ) m_MipIsoAU[1]->reset();
379  if ( m_Merger[0] ) m_Merger[0]->reset();
380  if ( m_Merger[1] ) m_Merger[1]->reset();
381  if ( m_Sorter) m_Sorter->reset();
382 
383 }
384 
385 // get the GMT readout data for the triggered bx
386 std::auto_ptr<L1MuGMTReadoutCollection> L1MuGlobalMuonTrigger::getReadoutCollection() {
387 
388  int bx_min_ro = L1MuGMTConfig::getBxMinRo();
389  int bx_max_ro = L1MuGMTConfig::getBxMaxRo();
390  int bx_size = bx_max_ro - bx_min_ro + 1;
391 
392  std::auto_ptr<L1MuGMTReadoutCollection> rrc(new L1MuGMTReadoutCollection(bx_size));
393 
394  for (int bx = bx_min_ro; bx <= bx_max_ro; bx++) {
395  std::vector<L1MuGMTReadoutRecord*>::const_iterator iter = m_ReadoutRingbuffer.begin();
396 
397  for ( ;iter!=m_ReadoutRingbuffer.end(); iter++) {
398 
399  if ( (*iter)->getBxInEvent() == bx ) {
400  rrc->addRecord(**iter);
401  break;
402  }
403  }
404 
405  }
406 
407  return rrc;
408 }
409 
410 // static data members
411 
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:217
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:309
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:196
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:66
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:85
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: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
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:63