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