CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RBCProcessRPCDigis.cc
Go to the documentation of this file.
1 // Include files
2 
3 
4 
5 // local
9 
10 //-----------------------------------------------------------------------------
11 // Implementation file for class : RBCProcessRPCDigis
12 //
13 // 2009-04-15 : Andres Felipe Osorio Oliveros
14 //-----------------------------------------------------------------------------
15 
16 //=============================================================================
17 // Standard constructor, initializes variables
18 //=============================================================================
20  const edm::Handle<RPCDigiCollection> & digiColl )
21 {
22 
23  m_ptr_rpcGeom = & rpcGeom;
24  m_ptr_digiColl = & digiColl;
25 
26  m_lbin = dynamic_cast<RPCInputSignal*>( new RBCLinkBoardGLSignal( &m_data ) );
27 
28  m_debug = false;
29 
30  configure();
31 
32 }
33 
35 {
36 
37  m_wheelid.push_back(-2); //-2
38  m_wheelid.push_back(-1); //-1
39  m_wheelid.push_back(0); // 0
40  m_wheelid.push_back( 1); //+1
41  m_wheelid.push_back( 2); //+2
42 
43  m_sec1id.push_back(12);
44  m_sec2id.push_back(1);
45  m_sec1id.push_back(2);
46  m_sec2id.push_back(3);
47  m_sec1id.push_back(4);
48  m_sec2id.push_back(5);
49  m_sec1id.push_back(6);
50  m_sec2id.push_back(7);
51  m_sec1id.push_back(8);
52  m_sec2id.push_back(9);
53  m_sec1id.push_back(10);
54  m_sec2id.push_back(11);
55 
56  m_layermap[113] = 0; //RB1InFw
57  m_layermap[123] = 1; //RB1OutFw
58 
59  m_layermap[20213] = 2; //RB22Fw
60  m_layermap[20223] = 2; //RB22Fw
61  m_layermap[30223] = 3; //RB23Fw
62  m_layermap[30213] = 3; //RB23Fw
63  m_layermap[30212] = 4; //RB23M
64  m_layermap[30222] = 4; //RB23M
65 
66  m_layermap[313] = 5; //RB3Fw
67  m_layermap[413] = 6; //RB4Fw
68  m_layermap[111] = 7; //RB1InBk
69  m_layermap[121] = 8; //RB1OutBk
70 
71  m_layermap[20211] = 9; //RB22Bw
72  m_layermap[20221] = 9; //RB22Bw
73  m_layermap[30211] = 10; //RB23Bw
74  m_layermap[30221] = 10; //RB23Bw
75 
76  m_layermap[311] = 11; //RB3Bk
77  m_layermap[411] = 12; //RB4Bk
78 
79  m_maxBxWindow = 3;
80 
81  std::vector<int>::iterator wheel;
82 
83  for( wheel = m_wheelid.begin(); wheel != m_wheelid.end(); ++wheel)
84  m_digiCounters[(*wheel)] = new l1trigger::Counters( (*wheel) );
85 
86 }
87 
88 //=============================================================================
89 // Destructor
90 //=============================================================================
92 
93  if ( m_lbin ) delete m_lbin;
94 
95  std::vector<int>::iterator wheel;
96 
97  for( wheel = m_wheelid.begin(); wheel != m_wheelid.end(); ++wheel)
98  delete m_digiCounters[(*wheel)];
99 
100  m_sec1id.clear();
101  m_sec2id.clear();
102  m_wheelid.clear();
103  m_layermap.clear();
104 
105  reset();
106 
107 }
108 
109 //=============================================================================
111 
112  //...clean up previous data contents
113 
114  reset();
115 
116  int ndigis(0);
117 
118  for (m_detUnitItr = (*m_ptr_digiColl)->begin();
119  m_detUnitItr != (*m_ptr_digiColl)->end(); ++m_detUnitItr ) {
120 
121  if ( m_debug ) std::cout << "looping over digis 1 ..." << std::endl;
122 
123  m_digiItr = (*m_detUnitItr ).second.first;
124  int bx = (*m_digiItr).bx();
125 
126  if ( abs(bx) >= m_maxBxWindow ) {
127  if ( m_debug ) std::cout << "RBCProcessRPCDigis> found a bx bigger than max allowed: "
128  << bx << std::endl;
129  continue;
130  }
131 
132  const RPCDetId & id = (*m_detUnitItr).first;
133  const RPCRoll * roll = dynamic_cast<const RPCRoll* >( (*m_ptr_rpcGeom)->roll(id));
134 
135  if((roll->isForward())) {
136  if( m_debug ) std::cout << "RBCProcessRPCDigis: roll is forward" << std::endl;
137  continue;
138  }
139 
140  int wheel = roll->id().ring(); // -2,-1,0,+1,+2
141  int sector = roll->id().sector(); // 1 to 12
142  int layer = roll->id().layer(); // 1,2
143  int station = roll->id().station(); // 1-4
144  int blayer = getBarrelLayer( layer, station ); // 1 to 6
145  int rollid = id.roll();
146 
147  int digipos = (station * 100) + (layer * 10) + rollid;
148 
149  if ( (wheel == -1 || wheel == 0 || wheel == 1) && station == 2 && layer == 1 )
150  digipos = 30000 + digipos;
151  if ( (wheel == -2 || wheel == 2) && station == 2 && layer == 2 )
152  digipos = 30000 + digipos;
153 
154  if ( (wheel == -1 || wheel == 0 || wheel == 1) && station == 2 && layer == 2 )
155  digipos = 20000 + digipos;
156  if ( (wheel == -2 || wheel == 2) && station == 2 && layer == 1 )
157  digipos = 20000 + digipos;
158 
159  if ( m_debug ) std::cout << "Bx: " << bx << '\t'
160  << "Wheel: " << wheel << '\t'
161  << "Sector: " << sector << '\t'
162  << "Station: " << station << '\t'
163  << "Layer: " << layer << '\t'
164  << "B-Layer: " << blayer << '\t'
165  << "Roll id: " << rollid << '\t'
166  << "Digi at: " << digipos << '\n';
167 
168  //... Construct the RBCinput objects
169  std::map<int,std::vector<RPCData*> >::iterator itr;
170  itr = m_vecDataperBx.find( bx );
171 
172  if ( itr == m_vecDataperBx.end() ) {
173  if ( m_debug ) std::cout << "Found a new Bx: " << bx << std::endl;
174  std::vector<RPCData*> wheelData;
175  initialize(wheelData);
176  m_vecDataperBx[bx] = wheelData;
177  this->m_block = wheelData[ (wheel + 2) ];
178  setDigiAt( sector, digipos );
179  }
180  else{
181  this->m_block = (*itr).second[ (wheel + 2) ];
182  setDigiAt( sector, digipos );
183  }
184 
185  std::map<int, l1trigger::Counters* >::iterator wheelCounter;
186  wheelCounter = m_digiCounters.find( wheel );
187 
188  if ( wheelCounter != m_digiCounters.end() )
189  (*wheelCounter).second->incrementSector( sector );
190 
191  if ( m_debug ) std::cout << "looping over digis 2 ..." << std::endl;
192 
193  ++ndigis;
194 
195  }
196 
197  if ( m_debug ) std::cout << "size of data vectors: " << m_vecDataperBx.size() << std::endl;
198 
199  builddata();
200 
201  if ( m_debug ) {
202  std::cout << "after reset" << std::endl;
203  print_output();
204  }
205 
206  if ( m_debug ) std::cout << "RBCProcessRPCDigis: DataSize: " << m_data.size()
207  << " ndigis " << ndigis << std::endl;
208 
209  std::map<int, l1trigger::Counters* >::iterator wheelCounter;
210  for( wheelCounter = m_digiCounters.begin(); wheelCounter != m_digiCounters.end(); ++wheelCounter) {
211  (*wheelCounter).second->evalCounters();
212  if ( m_debug ) (*wheelCounter).second->printSummary();
213  }
214 
215  if ( m_data.size() <= 0 ) return 0;
216 
217  return 1;
218 
219 }
220 
222 {
223 
224  std::map<int,std::vector<RPCData*> >::iterator itr1;
225  for( itr1 = m_vecDataperBx.begin(); itr1 != m_vecDataperBx.end(); ++itr1) {
226  std::vector<RPCData*>::iterator itr2;
227  for(itr2 = (*itr1).second.begin(); itr2 != (*itr1).second.end();++itr2 )
228  if ( (*itr2) ) delete *itr2;
229  (*itr1).second.clear();
230  }
231  m_vecDataperBx.clear();
232 
233 }
234 
235 
236 void RBCProcessRPCDigis::initialize( std::vector<RPCData*> & dataVec )
237 {
238 
239  if ( m_debug ) std::cout << "initialize" << std::endl;
240 
241  int maxWheels = 5;
242  int maxRbcBrds = 6;
243 
244  for(int i=0; i < maxWheels; ++i) {
245 
246  m_block = new RPCData();
247 
249 
250  for(int j=0; j < maxRbcBrds; ++j) {
251  m_block->m_sec1[j] = m_sec1id[j];
252  m_block->m_sec2[j] = m_sec2id[j];
253  m_block->m_orsignals[j].input_sec[0].reset();
254  m_block->m_orsignals[j].input_sec[1].reset();
255  m_block->m_orsignals[j].needmapping = false;
256  m_block->m_orsignals[j].hasData = false;
257  }
258 
259  dataVec.push_back( m_block );
260 
261  }
262 
263  if ( m_debug ) std::cout << "initialize: completed" << std::endl;
264 
265 }
266 
268 {
269 
270  int bx(0);
271  int code(0);
272  int bxsign(1);
273  std::vector<RPCData*>::iterator itr;
274  std::map<int, std::vector<RPCData*> >::iterator itr2;
275 
276  itr2 = m_vecDataperBx.begin();
277  if( itr2 == ( m_vecDataperBx.end() ) ) return;
278 
279  while ( itr2 != m_vecDataperBx.end() ) {
280 
281  bx = (*itr2).first;
282 
283  if ( bx != 0 ) bxsign = ( bx / abs(bx) );
284  else bxsign = 1;
285 
286  for(itr = (*itr2).second.begin(); itr != (*itr2).second.end(); ++itr) {
287 
288  for(int k=0; k < 6; ++k) {
289 
290  code = bxsign * ( 1000000*abs(bx)
291  + 10000*(*itr)->wheelIdx()
292  + 100 *(*itr)->m_sec1[k]
293  + 1 *(*itr)->m_sec2[k] );
294 
295  RBCInput * signal = & (*itr)->m_orsignals[k];
296  signal->needmapping = false;
297 
298  if ( signal->hasData )
299  m_data.insert( std::make_pair( code , signal) );
300 
301  }
302  }
303 
304  ++itr2;
305 
306  }
307 
308  if ( m_debug ) std::cout << "builddata: completed. size of data: " << m_data.size() << std::endl;
309 
310 }
311 
312 int RBCProcessRPCDigis::getBarrelLayer( const int & _layer, const int & _station )
313 {
314 
315  //... Calculates the generic Barrel Layer (1 to 6)
316  int blayer(0);
317 
318  if ( _station < 3 ) {
319  blayer = ( (_station-1) * 2 ) + _layer;
320  }
321  else {
322  blayer = _station + 2;
323  }
324 
325  return blayer;
326 
327 }
328 
329 
330 void RBCProcessRPCDigis::setDigiAt( int sector, int digipos )
331 {
332 
333  int pos = 0;
334  int isAoB = 0;
335 
336  if ( m_debug ) std::cout << "setDigiAt" << std::endl;
337 
338  std::vector<int>::const_iterator itr;
339  itr = std::find( m_sec1id.begin(), m_sec1id.end(), sector );
340 
341  if ( itr == m_sec1id.end()) {
342  itr = std::find( m_sec2id.begin(), m_sec2id.end(), sector );
343  isAoB = 1;
344  }
345 
346  for ( pos = 0; pos < 6; ++pos ) {
347  if (this->m_block->m_sec1[pos] == sector || this->m_block->m_sec2[pos] == sector )
348  break;
349  }
350 
351  if ( m_debug ) std::cout << this->m_block->m_orsignals[pos];
352 
353  setInputBit( this->m_block->m_orsignals[pos].input_sec[ isAoB ] , digipos );
354 
355  this->m_block->m_orsignals[pos].hasData = true;
356 
357  if ( m_debug ) std::cout << this->m_block->m_orsignals[pos];
358 
359  if ( m_debug ) std::cout << "setDigiAt completed" << std::endl;
360 
361 }
362 
363 void RBCProcessRPCDigis::setInputBit( std::bitset<15> & signals , int digipos )
364 {
365 
366  int bitpos = m_layermap[digipos];
367  if( m_debug ) std::cout << "Bitpos: " << bitpos << std::endl;
368  signals.set( bitpos , 1 );
369 
370 }
371 
373 {
374 
375  std::cout << "RBCProcessRPCDigis> Output starts" << std::endl;
376 
377  std::map<int,RBCInput*>::const_iterator itr;
378  for( itr = m_data.begin(); itr != m_data.end(); ++itr) {
379  std::cout << (*itr).first << '\t' << (* (*itr).second ) << '\n';
380  }
381 
382  std::cout << "RBCProcessRPCDigis> Output ends" << std::endl;
383 
384 }
385 
int i
Definition: DBlmapReader.cc:9
RBCInput * m_orsignals
Definition: RPCData.h:55
void setInputBit(std::bitset< 15 > &, int)
RPCDigiCollection::DigiRangeIterator m_detUnitItr
void initialize(std::vector< RPCData * > &)
int * m_sec2
Definition: RPCData.h:54
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< int > m_wheelid
std::map< int, l1trigger::Counters * > m_digiCounters
virtual ~RBCProcessRPCDigis()
Destructor.
RPCDetId id() const
Definition: RPCRoll.cc:24
std::vector< int > m_sec1id
int ring() const
Definition: RPCDetId.h:72
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
const edm::ESHandle< RPCGeometry > * m_ptr_rpcGeom
std::bitset< 15 > * input_sec
Definition: RBCInput.h:64
std::vector< int > m_sec2id
RBCProcessRPCDigis()
Standard constructor.
const edm::Handle< RPCDigiCollection > * m_ptr_digiColl
int m_wheel
Definition: RPCData.h:52
void setDigiAt(int, int)
int k[5][pyjets_maxn]
int layer() const
Definition: RPCDetId.h:108
bool needmapping
Definition: RBCInput.h:75
RPCDigiCollection::const_iterator m_digiItr
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:102
string bx
Definition: rpc-layouts.py:13
RPCInputSignal * m_lbin
bool hasData
Definition: RBCInput.h:74
std::map< int, int > m_layermap
int getBarrelLayer(const int &, const int &)
tuple cout
Definition: gather_cfg.py:121
std::map< int, std::vector< RPCData * > > m_vecDataperBx
bool isForward() const
Definition: RPCRoll.cc:98
std::map< int, RBCInput * > m_data
int * m_sec1
Definition: RPCData.h:53
int station() const
Definition: RPCDetId.h:96