CMS 3D CMS Logo

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