CMS 3D CMS Logo

RBCProcessRPCSimDigis.cc
Go to the documentation of this file.
1 // Include files
2 
3 // local
7 #include "GeometryConstants.h"
8 
9 //-----------------------------------------------------------------------------
10 // Implementation file for class : RBCProcessRPCSimDigis
11 //
12 // 2009-09-20 : Andres Felipe Osorio Oliveros
13 //-----------------------------------------------------------------------------
14 using namespace rpctechnicaltrigger;
15 
16 
18  const edm::Handle<edm::DetSetVector<RPCDigiSimLink> > & digiSimLink)
19 {
20 
21  m_ptr_rpcGeom = & rpcGeom;
22  m_ptr_digiSimLink = & digiSimLink;
23 
24  m_lbin = std::make_unique<RBCLinkBoardGLSignal>( &m_data ) ;
25 
26  m_debug = false;
27  m_maxBxWindow = 3;
28 
29 }
30 
31 //=============================================================================
32 // Destructor
33 //=============================================================================
35  reset();
36 }
37 
38 //=============================================================================
40 
41  //...clean up previous data contents
42 
43  reset();
44 
45  int ndigis(0);
46 
47  for( m_linkItr = (*m_ptr_digiSimLink)->begin();
48  m_linkItr != (*m_ptr_digiSimLink)->end();
49  ++m_linkItr ) {
50 
51  for ( m_digiItr = m_linkItr->data.begin();
52  m_digiItr != m_linkItr->data.end();
53  ++m_digiItr ) {
54 
55  if ( m_debug ) std::cout << "looping over digis 1 ..." << std::endl;
56 
57  int bx = (*m_digiItr).getBx();
58 
59  if ( abs(bx) >= m_maxBxWindow ) {
60  if ( m_debug ) std::cout << "RBCProcessRPCSimDigis> found a bx bigger than max allowed: "
61  << bx << std::endl;
62  continue;
63  }
64 
65  uint32_t detid = m_digiItr->getDetUnitId();
66  const RPCDetId id( detid );
67  const RPCRoll * roll = dynamic_cast<const RPCRoll* >( (*m_ptr_rpcGeom)->roll(id));
68 
69  if((roll->isForward())) {
70  if( m_debug ) std::cout << "RBCProcessRPCSimDigis: roll is forward" << std::endl;
71  continue;
72  }
73 
74  int wheel = roll->id().ring(); // -2,-1,0,+1,+2
75  int sector = roll->id().sector(); // 1 to 12
76  int layer = roll->id().layer(); // 1,2
77  int station = roll->id().station(); // 1-4
78  int blayer = getBarrelLayer( layer, station ); // 1 to 6
79  int rollid = id.roll();
80 
81  int digipos = (station * 100) + (layer * 10) + rollid;
82 
83  if ( (wheel == -1 || wheel == 0 || wheel == 1) && station == 2 && layer == 1 )
84  digipos = 30000 + digipos;
85  if ( (wheel == -2 || wheel == 2) && station == 2 && layer == 2 )
86  digipos = 30000 + digipos;
87 
88  if ( (wheel == -1 || wheel == 0 || wheel == 1) && station == 2 && layer == 2 )
89  digipos = 20000 + digipos;
90  if ( (wheel == -2 || wheel == 2) && station == 2 && layer == 1 )
91  digipos = 20000 + digipos;
92 
93  if ( m_debug ) std::cout << "Bx: " << bx << '\t'
94  << "Wheel: " << wheel << '\t'
95  << "Sector: " << sector << '\t'
96  << "Station: " << station << '\t'
97  << "Layer: " << layer << '\t'
98  << "B-Layer: " << blayer << '\t'
99  << "Roll id: " << rollid << '\t'
100  << "Digi at: " << digipos << '\n';
101 
102  //... Construct the RBCinput objects
103  auto itr = m_vecDataperBx.find( bx );
104 
105  if ( itr == m_vecDataperBx.end() ) {
106  if ( m_debug ) std::cout << "Found a new Bx: " << bx << std::endl;
107  auto& wheelData = m_vecDataperBx[bx];
108  initialize(wheelData);
109  auto& block = wheelData[ (wheel + 2) ];
110  setDigiAt( sector, digipos, block );
111  }
112  else{
113  auto& block = (*itr).second[ (wheel + 2) ];
114  setDigiAt( sector, digipos, block );
115  }
116 
117  if ( m_debug ) std::cout << "looping over digis 2 ..." << std::endl;
118 
119  ++ndigis;
120 
121  }
122 
123  }
124 
125  if ( m_debug ) std::cout << "size of data vectors: " << m_vecDataperBx.size() << std::endl;
126 
127  builddata();
128 
129  if ( m_debug ) {
130  std::cout << "after reset" << std::endl;
131  print_output();
132  }
133 
134  if ( m_debug ) std::cout << "RBCProcessRPCSimDigis: DataSize: " << m_data.size()
135  << " ndigis " << ndigis << std::endl;
136 
137  if ( m_data.empty() ) return 0;
138 
139  return 1;
140 
141 }
142 
144 {
145 
146  m_vecDataperBx.clear();
147 
148 }
149 
150 
151 void RBCProcessRPCSimDigis::initialize( std::vector<RPCData> & dataVec )
152 {
153 
154  if ( m_debug ) std::cout << "initialize" << std::endl;
155 
156  constexpr int maxWheels = 5;
157  constexpr int maxRbcBrds = 6;
158 
159  dataVec.reserve(maxWheels);
160  for(int i=0; i < maxWheels; ++i) {
161 
162  auto& block = dataVec.emplace_back();
163 
164  block.m_wheel = s_wheelid[i];
165 
166  for(int j=0; j < maxRbcBrds; ++j) {
167  block.m_sec1[j] = s_sec1id[j];
168  block.m_sec2[j] = s_sec2id[j];
169  block.m_orsignals[j].input_sec[0].reset();
170  block.m_orsignals[j].input_sec[1].reset();
171  block.m_orsignals[j].needmapping = false;
172  block.m_orsignals[j].hasData = false;
173  }
174  }
175 
176  if ( m_debug ) std::cout << "initialize: completed" << std::endl;
177 
178 }
179 
181 {
182 
183  int code(0);
184 
185  for(auto& dataPerBx: m_vecDataperBx) {
186 
187  int bx = dataPerBx.first;
188 
189  int bxsign;
190  if ( bx != 0 ) bxsign = ( bx / abs(bx) );
191  else bxsign = 1;
192 
193  for(auto& item : dataPerBx.second) {
194 
195  for(int k=0; k < 6; ++k) {
196 
197  code = bxsign * ( 1000000*abs(bx)
198  + 10000*item.wheelIdx()
199  + 100 *item.m_sec1[k]
200  + 1 *item.m_sec2[k] );
201 
202 
203  RBCInput * signal = & item.m_orsignals[k];
204  signal->needmapping = false;
205 
206  if ( signal->hasData )
207  m_data.insert( std::make_pair( code , signal) );
208 
209  }
210  }
211  }
212 
213  if ( m_debug and not m_vecDataperBx.empty()) std::cout << "builddata: completed. size of data: " << m_data.size() << std::endl;
214 
215 }
216 
217 int RBCProcessRPCSimDigis::getBarrelLayer( const int & _layer, const int & _station )
218 {
219 
220  //... Calculates the generic Barrel Layer (1 to 6)
221  int blayer(0);
222 
223  if ( _station < 3 ) {
224  blayer = ( (_station-1) * 2 ) + _layer;
225  }
226  else {
227  blayer = _station + 2;
228  }
229 
230  return blayer;
231 
232 }
233 
234 
235 void RBCProcessRPCSimDigis::setDigiAt( int sector, int digipos, RPCData& block )
236 {
237 
238  int pos = 0;
239  int isAoB = 0;
240 
241  if ( m_debug ) std::cout << "setDigiAt" << std::endl;
242 
243  auto itr = std::find( s_sec1id.begin(), s_sec1id.end(), sector );
244 
245  if ( itr == s_sec1id.end()) {
246  itr = std::find( s_sec2id.begin(), s_sec2id.end(), sector );
247  isAoB = 1;
248  }
249 
250  for ( pos = 0; pos < 6; ++pos ) {
251  if (block.m_sec1[pos] == sector || block.m_sec2[pos] == sector )
252  break;
253  }
254 
255  if ( m_debug ) std::cout << block.m_orsignals[pos];
256 
257  setInputBit( block.m_orsignals[pos].input_sec[ isAoB ] , digipos );
258 
259  block.m_orsignals[pos].hasData = true;
260 
261  if ( m_debug ) std::cout << block.m_orsignals[pos];
262 
263  if ( m_debug ) std::cout << "setDigiAt completed" << std::endl;
264 
265 }
266 
267 void RBCProcessRPCSimDigis::setInputBit( std::bitset<15> & signals , int digipos )
268 {
269 
270  int bitpos = s_layermap.at(digipos);
271  if( m_debug ) std::cout << "Bitpos: " << bitpos << std::endl;
272  signals.set( bitpos , true );
273 
274 }
275 
277 {
278 
279  std::cout << "RBCProcessRPCSimDigis> Output starts" << std::endl;
280 
281  std::map<int,RBCInput*>::const_iterator itr;
282  for( itr = m_data.begin(); itr != m_data.end(); ++itr) {
283  std::cout << (*itr).first << '\t' << (* (*itr).second ) << '\n';
284  }
285 
286  std::cout << "RBCProcessRPCSimDigis> Output ends" << std::endl;
287 
288 }
289 
static AlgebraicMatrix initialize()
std::array< RBCInput, 6 > m_orsignals
Definition: RPCData.h:52
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
#define constexpr
~RBCProcessRPCSimDigis() override
Destructor.
constexpr std::array< int, 6 > s_sec2id
RBCProcessRPCSimDigis()
Standard constructor.
RPCDetId id() const
Definition: RPCRoll.cc:24
int ring() const
Definition: RPCDetId.h:72
int getBarrelLayer(const int &, const int &)
void setDigiAt(int, int, RPCData &)
constexpr std::array< int, 6 > s_sec1id
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void initialize(std::vector< RPCData > &)
const std::map< int, int > s_layermap
constexpr std::array< int, 5 > s_wheelid
void setInputBit(std::bitset< 15 > &, int)
int k[5][pyjets_maxn]
int layer() const
Definition: RPCDetId.h:108
bool needmapping
Definition: RBCInput.h:52
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:102
std::array< int,6 > m_sec2
Definition: RPCData.h:51
bool isForward() const
Definition: RPCRoll.cc:98
void reset(double vett[256])
Definition: TPedValues.cc:11
std::array< int, 6 > m_sec1
Definition: RPCData.h:50
int station() const
Definition: RPCDetId.h:96