CMS 3D CMS Logo

RPCTechnicalTrigger.cc
Go to the documentation of this file.
1 // $Id:
2 
3 //-----------------------------------------------------------------------------
4 // Implementation file for class : RPCTechnicalTrigger
5 //
6 // 2008-10-15 : Andres Osorio
7 //-----------------------------------------------------------------------------
8 
9 //=============================================================================
10 // Standard constructor, initializes variables
11 //=============================================================================
12 
13 // Include files
14 
15 // local
20 
23 
24 //=============================================================================
25 // Standard constructor, initializes variables
26 //=============================================================================
27 
29 
30  //...........................................................................
31 
32  std::string configFile = iConfig.getParameter<std::string>("ConfigFile");
33  m_verbosity = iConfig.getUntrackedParameter<int>("Verbosity", 0);
34  m_rpcDigiLabel = iConfig.getParameter<edm::InputTag>("RPCDigiLabel");
35  m_ttBits = iConfig.getParameter< std::vector<unsigned> >("BitNumbers");
36  m_ttNames = iConfig.getParameter< std::vector<std::string> >("BitNames");
37  m_useEventSetup = iConfig.getUntrackedParameter<int>("UseEventSetup", 0);
38  m_useRPCSimLink = iConfig.getUntrackedParameter<int>("UseRPCSimLink", 0);
39  m_rpcSimLinkInstance = iConfig.getParameter<edm::InputTag>("RPCSimLinkInstance");
40 
41  edm::FileInPath f1("L1Trigger/RPCTechnicalTrigger/data/" + configFile);
42  m_configFile = f1.fullPath();
43 
44  if ( m_verbosity ) {
45  LogTrace("RPCTechnicalTrigger")
46  << m_rpcDigiLabel << '\n'
47  << std::endl;
48 
49  LogTrace("RPCTechnicalTrigger")
50  << "\nConfiguration file used for UseEventSetup = 0 \n" << m_configFile << '\n'
51  << std::endl;
52  }
53 
54  //...........................................................................
55  //... There are three Technical Trigger Units Boards: 1 can handle 2 Wheels
56  //... n_Wheels sets the number of wheels attached to board with index boardIndex
57 
58  m_boardIndex[0] = 1;
59  m_boardIndex[1] = 2;
60  m_boardIndex[2] = 3;
61 
62  m_nWheels[0] = 2;
63  m_nWheels[1] = 1;
64  m_nWheels[2] = 2;
65 
66  m_ttu[0] = new TTUEmulator( m_boardIndex[0] , m_nWheels[0] );
67  m_ttu[1] = new TTUEmulator( m_boardIndex[1] , m_nWheels[1] );
68  m_ttu[2] = new TTUEmulator( m_boardIndex[2] , m_nWheels[2] );
69 
70  //... This is second line that delivers in parallel a second trigger
71  m_ttuRbcLine[0] = new TTUEmulator( m_boardIndex[0] , m_nWheels[0] );
72  m_ttuRbcLine[1] = new TTUEmulator( m_boardIndex[1] , m_nWheels[1] );
73  m_ttuRbcLine[2] = new TTUEmulator( m_boardIndex[2] , m_nWheels[2] );
74 
75  m_WheelTtu[-2] = 3;
76  m_WheelTtu[-1] = 3;
77  m_WheelTtu[0 ] = 2;
78  m_WheelTtu[1 ] = 1;
79  m_WheelTtu[2 ] = 1;
80 
81  //...........................................................................
82  //For the pointing Logic: declare here the first sector of each quadrant
83  //
84  m_quadrants.push_back(2);
85  m_quadrants.push_back(3);
86  m_quadrants.push_back(4);
87  m_quadrants.push_back(5);
88  m_quadrants.push_back(6);
89  m_quadrants.push_back(7);
90  m_quadrants.push_back(8);
91  m_quadrants.push_back(9);
92  m_quadrants.push_back(10);
93  m_quadrants.push_back(11);
94 
95  //...........................................................................
96 
97  m_ievt = 0;
98  m_cand = 0;
99  m_maxTtuBoards = 3;
100  m_maxBits = 5;
101  m_hasConfig = false;
102  m_readConfig = NULL;
103  produces<L1GtTechnicalTriggerRecord>();
104  consumes<RPCDigiCollection>(m_rpcDigiLabel);
105  consumes<edm::DetSetVector<RPCDigiSimLink> >(edm::InputTag("simMuonRPCDigis", "RPCDigiSimLink",""));
106 }
107 
108 
110 {
111 
112  LogDebug("RPCTechnicalTrigger") << "RPCTechnicalTrigger: object starts deletion" << std::endl;
113 
114  if ( m_hasConfig ) {
115 
116  delete m_ttu[0];
117  delete m_ttu[1];
118  delete m_ttu[2];
119 
120  delete m_ttuRbcLine[0];
121  delete m_ttuRbcLine[1];
122  delete m_ttuRbcLine[2];
123 
124  if ( m_readConfig )
125  delete m_readConfig;
126 
127  }
128 
129  m_WheelTtu.clear();
130 
131  LogDebug("RPCTechnicalTrigger") << "RPCTechnicalTrigger: object deleted" << '\n';
132 
133 }
134 
135 //=============================================================================
137 
138 
139  bool status(false);
140 
142 
144 
145  std::unique_ptr<L1GtTechnicalTriggerRecord> output(new L1GtTechnicalTriggerRecord());
146 
147  if ( m_useRPCSimLink == 0 ) {
148  iEvent.getByLabel(m_rpcDigiLabel, pIn);
149  if ( ! pIn.isValid() ) {
150  edm::LogError("RPCTechnicalTrigger") << "can't find RPCDigiCollection with label: "
151  << m_rpcDigiLabel << '\n';
152  iEvent.put(std::move(output));
153  return;
154  }
155  m_signal = dynamic_cast<ProcessInputSignal*>(new RBCProcessRPCDigis( m_rpcGeometry, pIn ));
156 
157  } else {
158 
159  iEvent.getByLabel("simMuonRPCDigis", "RPCDigiSimLink", simIn);
160 
161  if ( ! simIn.isValid() ) {
162  edm::LogError("RPCTechnicalTrigger") << "can't find RPCDigiCollection with label: "
163  << m_rpcDigiLabel << '\n';
164  iEvent.put(std::move(output));
165  return;
166  }
167  m_signal = dynamic_cast<ProcessInputSignal*>(new RBCProcessRPCSimDigis( m_rpcGeometry, simIn ));
168  }
169 
170  LogDebug("RPCTechnicalTrigger") << "signal object created" << '\n';
171 
172  if ( ! m_hasConfig ) {
173  edm::LogError("RPCTechnicalTrigger") << "cannot read hardware configuration \n";
174  iEvent.put(std::move(output));
175  return;
176  }
177 
178  status = m_signal->next();
179 
180  if ( !status) {
181  delete m_signal;
182  iEvent.put(std::move(output));
183  return;
184  }
185 
187 
188  std::vector<L1GtTechnicalTrigger> ttVec( m_ttBits.size() );
189 
190  //. distribute data to different TTU emulator instances and process it
191 
192  m_triggerbits.reset();
193 
194  std::vector<TTUEmulator::TriggerResponse*>::const_iterator outItr;
195 
196  for(int k=0; k < m_maxTtuBoards; ++k) {
197 
198  m_ttu[k]->processTtu( m_input );
199 
200  //work out Pointing Logic to Tracker
202  m_ttuRbcLine[k]->processTtu( m_input , (*m_firstSector) );
203 
204  //...for trigger 1
205  for( outItr = m_ttu[k]->m_triggerBxVec.begin(); outItr != m_ttu[k]->m_triggerBxVec.end(); ++outItr )
206  m_serializedInfoLine1.push_back( new TTUResults( k, (*outItr)->m_bx, (*outItr)->m_trigger[0], (*outItr)->m_trigger[1] ) );
208 
209  //...for trigger 2
210  for( outItr = m_ttuRbcLine[k]->m_triggerBxVec.begin(); outItr != m_ttuRbcLine[k]->m_triggerBxVec.end(); ++outItr )
211  m_serializedInfoLine2.push_back( new TTUResults( k,
212  (*outItr)->m_bx,
213  (*outItr)->m_trigger[0],
214  (*outItr)->m_trigger[1],
215  (*outItr)->m_wedge ) );
216 
218 
219  }
220 
221  //.. write results to technical trigger bits
222  int bx(0);
223  int infoSize(0);
224 
225  infoSize = m_serializedInfoLine1.size();
226 
227  std::vector<RPCTechnicalTrigger::TTUResults*>::const_iterator ttuItr;
228 
229  std::sort( m_serializedInfoLine1.begin(), m_serializedInfoLine1.end(), sortByBx() );
230 
231  for( ttuItr = m_serializedInfoLine1.begin(); ttuItr != m_serializedInfoLine1.end(); ++ttuItr ) {
232  if ( m_verbosity && abs( (*ttuItr)->m_bx ) <= 1 )
233  std::cout << "RPCTechnicalTrigger> "
234  << (*ttuItr)->m_ttuidx << '\t'
235  << (*ttuItr)->m_bx << '\t'
236  << (*ttuItr)->m_trigWheel1 << '\t'
237  << (*ttuItr)->m_trigWheel2 << '\n';
238  }
239 
240  bool has_bx0 = false;
241 
242  for(int k = 0; k < infoSize; k+=m_maxTtuBoards) {
243 
244  bx = m_serializedInfoLine1[k]->m_bx;
245 
246  if ( bx == 0 ) {
247 
248  m_triggerbits.set(0, m_serializedInfoLine1[k]->m_trigWheel2);
249  m_triggerbits.set(1, m_serializedInfoLine1[k]->m_trigWheel1);
250  m_triggerbits.set(2, m_serializedInfoLine1[k+1]->m_trigWheel1);
251  m_triggerbits.set(3, m_serializedInfoLine1[k+2]->m_trigWheel1);
252  m_triggerbits.set(4, m_serializedInfoLine1[k+2]->m_trigWheel2);
253 
254  bool five_wheels_OR = m_triggerbits.any();
255 
256  ttVec.at(0)=L1GtTechnicalTrigger(m_ttNames.at(0), m_ttBits.at(0), bx, five_wheels_OR ) ; // bit 24 = Or 5 wheels in TTU mode
257  ttVec.at(2)=L1GtTechnicalTrigger(m_ttNames.at(2), m_ttBits.at(2), bx, m_triggerbits[0] ) ; // bit 26
258  ttVec.at(3)=L1GtTechnicalTrigger(m_ttNames.at(3), m_ttBits.at(3), bx, m_triggerbits[1] ) ; // bit 27
259  ttVec.at(4)=L1GtTechnicalTrigger(m_ttNames.at(4), m_ttBits.at(4), bx, m_triggerbits[2] ) ; // bit 28
260  ttVec.at(5)=L1GtTechnicalTrigger(m_ttNames.at(5), m_ttBits.at(5), bx, m_triggerbits[3] ) ; // bit 29
261  ttVec.at(6)=L1GtTechnicalTrigger(m_ttNames.at(6), m_ttBits.at(6), bx, m_triggerbits[4] ) ; // bit 30
262 
263  m_triggerbits.reset();
264 
265  has_bx0 = true;
266 
267  break;
268 
269  } else continue;
270 
271  }
272 
273  infoSize = m_serializedInfoLine2.size();
274 
275  std::sort( m_serializedInfoLine2.begin(), m_serializedInfoLine2.end(), sortByBx() );
276 
277  for( ttuItr = m_serializedInfoLine2.begin(); ttuItr != m_serializedInfoLine2.end(); ++ttuItr ) {
278  if ( m_verbosity && abs ( (*ttuItr)->m_bx ) <= 1 )
279  std::cout << "RPCTechnicalTrigger> "
280  << (*ttuItr)->m_ttuidx << '\t'
281  << (*ttuItr)->m_bx << '\t'
282  << (*ttuItr)->m_trigWheel1 << '\t'
283  << (*ttuItr)->m_trigWheel2 << '\t'
284  << (*ttuItr)->m_wedge << '\n';
285  }
286 
287  infoSize = convertToMap( m_serializedInfoLine2 );
288 
289  std::bitset<8> triggerCoincidence;
290  triggerCoincidence.reset();
291 
292  // searchCoincidence( W-2 , W0 )
293  bool result = searchCoincidence( -2, 0 );
294  triggerCoincidence.set(0, result );
295 
296  // searchCoincidence( W-2 , W+1 )
297  result = searchCoincidence( -2, 1 );
298  triggerCoincidence.set(1, result );
299 
300  // searchCoincidence( W-1 , W0 )
301  result = searchCoincidence( -1, 0 );
302  triggerCoincidence.set(2, result );
303 
304  // searchCoincidence( W-1 , W+1 )
305  result = searchCoincidence( -1, 1 );
306  triggerCoincidence.set(3, result );
307 
308  // searchCoincidence( W-1 , W+2 )
309  result = searchCoincidence( -1, 2 );
310  triggerCoincidence.set(4, result );
311 
312  // searchCoincidence( W0 , W0 )
313  result = searchCoincidence( 0 , 0 );
314  triggerCoincidence.set(5, result );
315 
316  // searchCoincidence( W+1 , W0 )
317  result = searchCoincidence( 1, 0 );
318  triggerCoincidence.set(6, result );
319 
320  // searchCoincidence( W+2 , W0 )
321  result = searchCoincidence( 2, 0 );
322  triggerCoincidence.set(7, result );
323 
324  bool five_wheels_OR = triggerCoincidence.any();
325 
326  if ( m_verbosity ) std::cout << "RPCTechnicalTrigger> pointing trigger: " << five_wheels_OR << '\n';
327 
328  ttVec.at(1)=L1GtTechnicalTrigger(m_ttNames.at(1), m_ttBits.at(1), bx, five_wheels_OR ) ; // bit 25 = Or 5 wheels in RBC mode
329 
330  triggerCoincidence.reset();
331 
332  //...check that data appeared at bx=0
333 
334  if ( ! has_bx0 ) {
335  iEvent.put(std::move(output));
336  status = Reset();
337  ++m_ievt;
338  LogDebug("RPCTechnicalTrigger") << "RPCTechnicalTrigger> end of event loop" << std::endl;
339  return;
340 
341  }
342 
343  output->setGtTechnicalTrigger(ttVec);
344  iEvent.put(std::move(output));
345 
346  //.... all done
347 
348  status = Reset();
349  ++m_ievt;
350  LogDebug("RPCTechnicalTrigger") << "RPCTechnicalTrigger> end of event loop" << std::endl;
351 
352 }
353 
355 {
356 
357  m_input->clear();
358  m_triggerbits.reset();
359  std::vector<TTUResults*>::iterator itrRes;
360 
361  for( itrRes=m_serializedInfoLine1.begin(); itrRes!=m_serializedInfoLine1.end(); ++itrRes)
362  delete (*itrRes);
363 
364  for( itrRes=m_serializedInfoLine2.begin(); itrRes!=m_serializedInfoLine2.end(); ++itrRes)
365  delete (*itrRes);
366 
367  m_serializedInfoLine1.clear();
368  m_serializedInfoLine2.clear();
369  m_ttuResultsByQuadrant.clear();
370 
371  delete m_signal;
372 
373  return true;
374 
375 }
376 
377 // ------------ method called once each job just before starting event loop ------------
378 void RPCTechnicalTrigger::beginRun(edm::Run const& iRun, const edm::EventSetup& evtSetup)
379 {
380  LogDebug("RPCTechnicalTrigger") << "RPCTechnicalTrigger::beginRun> starts" << std::endl;
381 
382  //. Set up RPC geometry
383 
384  evtSetup.get<MuonGeometryRecord>().get( m_rpcGeometry );
385 
386  //.. Get Board Specifications (hardware configuration)
387 
388  if ( m_useEventSetup >= 1 ) {
389 
391  evtSetup.get<RBCBoardSpecsRcd>().get(pRBCSpecs);
392 
394  evtSetup.get<TTUBoardSpecsRcd>().get(pTTUSpecs);
395 
396  if ( !pRBCSpecs.isValid() || !pTTUSpecs.isValid() ) {
397  edm::LogError("RPCTechnicalTrigger") << "can't find RBC/TTU BoardSpecsRcd" << '\n';
398  m_hasConfig = false;
399  }
400  else {
401  m_rbcspecs = pRBCSpecs.product();
402  m_ttuspecs = pTTUSpecs.product();
403  m_hasConfig = true;
404  }
405 
406  } else {
407 
408  // read hardware configuration from file
410 
411  if ( m_readConfig->m_hasConfig ) {
415  m_hasConfig = true;
416  }
417 
418  else m_hasConfig = false;
419 
420  }
421 
422  if ( m_hasConfig ) {
423 
424  //... Initialize all
425 
426  for (int k=0; k < m_maxTtuBoards; ++k ) {
427 
428  m_ttu[k]->SetLineId ( 1 );
429  m_ttuRbcLine[k]->SetLineId( 2 );
430 
433 
434  m_ttu[k]->initialise();
436  }
437 
438  }
439 
440 }
441 
442 //
443 int RPCTechnicalTrigger::convertToMap( const std::vector<TTUResults*> & ttuResults )
444 {
445 
446  std::vector<TTUResults*>::const_iterator itr = ttuResults.begin();
447 
448  while ( itr != ttuResults.end() ) {
449 
450  if ( (*itr)->m_bx != 0 ) {
451  ++itr;
452  continue;
453  }
454 
455  int key(0);
456  key = 1000 * ( (*itr)->m_ttuidx + 1 ) + 1*(*itr)->m_wedge;
457  m_ttuResultsByQuadrant[ key ] = (*itr);
458  ++itr;
459 
460  }
461 
462  return m_ttuResultsByQuadrant.size();
463 
464 }
465 
466 //...RBC pointing logic to tracker bit 25: hardwired
467 bool RPCTechnicalTrigger::searchCoincidence( int wheel1, int wheel2 )
468 {
469 
470  std::map<int, TTUResults*>::iterator itr;
471  bool topRight(false);
472  bool botLeft(false);
473 
474  int indxW1 = m_WheelTtu[wheel1];
475  int indxW2 = m_WheelTtu[wheel2];
476 
477  int k(0);
478  int key(0);
479  bool finalTrigger(false);
480  int maxTopQuadrants = 4;
481 
482  //work out Pointing Logic to Tracker
483 
484  for( m_firstSector = m_quadrants.begin(); m_firstSector != m_quadrants.end(); ++m_firstSector) {
485 
486  key = 1000 * ( indxW1 ) + (*m_firstSector);
487 
488  itr = m_ttuResultsByQuadrant.find( key );
489  if ( itr != m_ttuResultsByQuadrant.end() )
490  topRight = (*itr).second->getTriggerForWheel(wheel1);
491 
492  //std::cout << "W1: " << wheel1 << " " << "sec: " << (*m_firstSector) << " dec: " << topRight << '\n';
493 
494  key = 1000 * ( indxW2 ) + (*m_firstSector) + 5;
495 
496  itr = m_ttuResultsByQuadrant.find( key );
497 
498  if ( itr != m_ttuResultsByQuadrant.end() )
499  botLeft = (*itr).second->getTriggerForWheel(wheel2);
500 
501  //std::cout << "W2: " << wheel2 << " " << "sec: " << (*m_firstSector) + 5 << " dec: " << botLeft << '\n';
502 
503  finalTrigger |= ( topRight && botLeft );
504 
505  ++k;
506 
507  if ( k > maxTopQuadrants)
508  break;
509 
510  }
511 
512  //Try the opposite now
513 
514  k=0;
515 
516  for( m_firstSector = m_quadrants.begin(); m_firstSector != m_quadrants.end(); ++m_firstSector) {
517 
518  key = 1000 * ( indxW2 ) + (*m_firstSector);
519 
520  itr = m_ttuResultsByQuadrant.find( key );
521  if ( itr != m_ttuResultsByQuadrant.end() )
522  topRight = (*itr).second->getTriggerForWheel(wheel1);
523 
524  //std::cout << "W1: " << wheel1 << " " << "sec: " << (*m_firstSector) << " dec: " << topRight << '\n';
525 
526  key = 1000 * ( indxW1 ) + (*m_firstSector) + 5;
527 
528  itr = m_ttuResultsByQuadrant.find( key );
529 
530  if ( itr != m_ttuResultsByQuadrant.end() )
531  botLeft = (*itr).second->getTriggerForWheel(wheel2);
532 
533  //std::cout << "W2: " << wheel2 << " " << "sec: " << (*m_firstSector) + 5 << " dec: " << botLeft << '\n';
534 
535  finalTrigger |= ( topRight && botLeft );
536 
537  ++k;
538 
539  if ( k > maxTopQuadrants)
540  break;
541 
542  }
543 
544  return finalTrigger;
545 
546 }
547 
548 // ------------ method called once each job just after ending the event loop ------------
549 
551 {
552 
553  LogDebug("RPCTechnicalTrigger") << "RPCTechnicalTrigger::endJob>" << std::endl;
554 
555 }
556 
558 {
559 
560  LogDebug("RPCTechnicalTrigger") << "RPCTechnicalTrigger::Printing TTU emulators info>" << std::endl;
561 
562  for (int k=0; k < m_maxTtuBoards; ++k ) {
563  m_ttu[k]->printinfo();
565  }
566 
567 
568 }
569 
570 
571 //define this as a plug-in
#define LogDebug(id)
edm::InputTag m_rpcSimLinkInstance
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::map< int, int > m_WheelTtu
virtual RPCInputSignal * retrievedata()=0
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
std::vector< TTUResults * > m_serializedInfoLine1
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::ESHandle< RPCGeometry > m_rpcGeometry
TTUBoardSpecs * getTtuSpecs()
virtual void clear()=0
Destructor.
#define NULL
Definition: scimark2.h:8
std::vector< int > m_quadrants
std::bitset< 5 > m_triggerbits
RBCBoardSpecs * getRbcSpecs()
std::vector< TriggerResponse * > m_triggerBxVec
Definition: TTUEmulator.h:112
ProcessInputSignal * m_signal
virtual void beginRun(edm::Run const &, const edm::EventSetup &) override final
void clearTriggerResponse()
Definition: TTUEmulator.cc:324
int iEvent
Definition: GenABIO.cc:230
std::map< int, TTUResults * > m_ttuResultsByQuadrant
TTUEmulator * m_ttu[3]
std::vector< TTUResults * > m_serializedInfoLine2
RPCTechnicalTrigger(const edm::ParameterSet &)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool initialise()
Definition: TTUEmulator.cc:133
bool isValid() const
Definition: HandleBase.h:74
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:416
#define LogTrace(id)
std::vector< unsigned > m_ttBits
void SetLineId(int)
Definition: TTUEmulator.cc:149
TTUConfigurator * m_readConfig
int k[5][pyjets_maxn]
const TTUBoardSpecs * m_ttuspecs
void printinfo()
Definition: TTUEmulator.cc:336
void processTtu(RPCInputSignal *)
Definition: TTUEmulator.cc:162
virtual int next()=0
std::vector< std::string > m_ttNames
std::vector< int >::iterator m_firstSector
const T & get() const
Definition: EventSetup.h:55
TTUEmulator * m_ttuRbcLine[3]
edm::InputTag m_rpcDigiLabel
const RBCBoardSpecs * m_rbcspecs
virtual void endJob() override
RPCInputSignal * m_input
bool isValid() const
Definition: ESHandle.h:47
T const * product() const
Definition: ESHandle.h:86
int convertToMap(const std::vector< TTUResults * > &)
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:42
bool searchCoincidence(int, int)
void setSpecifications(const TTUBoardSpecs *, const RBCBoardSpecs *)
Definition: TTUEmulator.cc:118
virtual void produce(edm::Event &, const edm::EventSetup &) override