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