CMS 3D CMS Logo

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