CMS 3D CMS Logo

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