CMS 3D CMS Logo

RPCConeBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RPCConeBuilder
4 // Class: RPCConeBuilder
5 //
15 //
16 // Original Author: Tomasz Maciej Frueboes
17 // Created: Fri Feb 22 13:57:06 CET 2008
18 //
19 //
20 
33 
34 #include <cmath>
35 #include <vector>
36 #include <map>
37 #include <memory>
38 #include <utility>
39 
41 public:
43 
44  using ReturnType = std::unique_ptr<L1RPCConeBuilder>;
45 
47 
48 private:
50 
52 
56  std::pair<int, int> areConnected(RPCStripsRing::TIdToRindMap::iterator ref,
57  RPCStripsRing::TIdToRindMap::iterator other,
58  L1RPCConeDefinition const*);
59 
60  // ----------member data ---------------------------
65 };
66 
68  : m_towerBeg(iConfig.getParameter<int>("towerBeg")), m_towerEnd(iConfig.getParameter<int>("towerEnd")) {
69  auto cc = setWhatProduced(this);
70  m_rpcGeometryToken = cc.consumes();
71  m_l1RPCConeDefinitionToken = cc.consumes();
72 }
73 
74 // ------------ method called to produce the data ------------
76  auto pL1RPCConeBuilder = std::make_unique<L1RPCConeBuilder>();
77 
78  pL1RPCConeBuilder->setFirstTower(m_towerBeg);
79  pL1RPCConeBuilder->setLastTower(m_towerEnd);
80 
82 
83  buildCones(&iRecord.get(m_rpcGeometryToken), &iRecord.get(m_l1RPCConeDefinitionToken), ringsMap);
84 
85  // Compress all connections. Since members of this class are shared
86  // pointers this call will compress all data
87  ringsMap.begin()->second.compressConnections();
88 
89  pL1RPCConeBuilder->setConeConnectionMap(ringsMap.begin()->second.getConnectionsMap());
90 
91  pL1RPCConeBuilder->setCompressedConeConnectionMap(ringsMap.begin()->second.getCompressedConnectionsMap());
92 
93  return pL1RPCConeBuilder;
94 }
95 
97  L1RPCConeDefinition const* l1RPCConeDefinition,
98  RPCStripsRing::TIdToRindMap& ringsMap) {
99  // fetch geometrical data
100  auto uncompressedCons = std::make_shared<L1RPCConeBuilder::TConMap>();
101 
102  for (auto const& it : rpcGeom->dets()) {
103  RPCRoll const* roll = dynamic_cast<RPCRoll const*>(it);
104  if (roll == nullptr) {
105  continue;
106  }
107 
108  int ringId = RPCStripsRing::getRingId(roll);
109  auto found = ringsMap.find(ringId);
110  if (found == ringsMap.end()) {
111  ringsMap[ringId] = RPCStripsRing(roll, uncompressedCons);
112  } else {
113  found->second.addRoll(roll);
114  }
115  }
116 
117  // filtermixed strips, fill gaps with virtual strips
118  for (auto& it : ringsMap) {
119  it.second.filterOverlapingChambers();
120  it.second.fillWithVirtualStrips();
121  }
122 
123  // Xcheck, if rings are symmetrical
124  for (auto& it : ringsMap) {
125  int key = it.first;
126  int sign = key / 100 - (key / 1000) * 10;
127 
128  if (sign == 0) {
129  key += 100;
130  } else {
131  key -= 100;
132  }
133 
134  // Check if the geometry has a complete ring:
135  // note that in the case of demo chambers, the ring is not filled because only 2 sectors are added.
136  // (3014 and 4014 lack counter-rings)
137  if (key != 2000 && key != 3014 && key != 4014) { // Key 2100 has no counter-ring
138  if (it.second.size() != ringsMap[key].size()) {
139  throw cms::Exception("RPCInternal") << " Size differs for ring " << key << " +- 100 \n";
140  }
141  }
142  }
143  buildConnections(l1RPCConeDefinition, ringsMap);
144 }
145 
147  RPCStripsRing::TIdToRindMap& ringsMap) {
148  RPCStripsRing::TIdToRindMap::iterator itRef = ringsMap.begin();
149  for (; itRef != ringsMap.end(); ++itRef) { // iterate over reference rings
150 
151  RPCStripsRing::TOtherConnStructVec ringsToConnect;
152 
153  if (!itRef->second.isReferenceRing())
154  continue; // iterate over reference rings
155 
156  RPCStripsRing::TIdToRindMap::iterator itOther = ringsMap.begin();
157  for (; itOther != ringsMap.end(); ++itOther) { // iterate over nonreference rings
158 
159  if (itOther->second.isReferenceRing())
160  continue; // iterate over nonreference rings
161 
162  std::pair<int, int> pr = areConnected(itRef, itOther, l1RPCConeDefinition);
163  if (pr.first != -1) {
164  RPCStripsRing::TOtherConnStruct newOtherConn;
165  newOtherConn.m_it = itOther;
166  newOtherConn.m_logplane = pr.first;
167  newOtherConn.m_logplaneSize = pr.second;
168  ringsToConnect.push_back(newOtherConn);
169  }
170  } // OtherRings iteration ends
171 
172  std::pair<int, int> prRef = areConnected(itRef, itRef, l1RPCConeDefinition);
173  if (prRef.first == -1) {
174  throw cms::Exception("RPCConfig") << " Cannot determine logplane for reference ring " << itRef->first << "\n ";
175  }
176 
177  itRef->second.createRefConnections(ringsToConnect, prRef.first, prRef.second);
178 
179  } // RefRings iteration ends
180 }
181 
182 // first - logplane
183 // second - logplanesize
184 std::pair<int, int> RPCConeBuilder::areConnected(RPCStripsRing::TIdToRindMap::iterator ref,
185  RPCStripsRing::TIdToRindMap::iterator other,
186  L1RPCConeDefinition const* l1RPCConeDefinition) {
187  int logplane = -1;
188 
189  // Do not connect rolls lying on the oposite side of detector
190  if (ref->second.getEtaPartition() * other->second.getEtaPartition() < 0)
191  return std::make_pair(-1, 0);
192 
193  int refTowerCnt = 0;
194  int index = -1;
195  int refTower = -1;
196 
197  for (auto const& itRef : l1RPCConeDefinition->getRingToTowerVec()) {
198  if (itRef.m_etaPart != std::abs(ref->second.getEtaPartition()) ||
199  itRef.m_hwPlane != std::abs(ref->second.getHwPlane() - 1) // -1?
200  ) {
201  continue;
202  }
203 
204  ++refTowerCnt;
205  refTower = itRef.m_tower;
206 
207  for (auto const& itOther : l1RPCConeDefinition->getRingToTowerVec()) {
208  if (itOther.m_etaPart != std::abs(other->second.getEtaPartition()) ||
209  itOther.m_hwPlane != std::abs(other->second.getHwPlane() - 1) // -1?
210  ) {
211  continue;
212  }
213 
214  if (itOther.m_tower == refTower) {
215  index = itOther.m_index;
216  }
217  }
218  }
219 
220  if (refTowerCnt > 1) {
221  throw cms::Exception("RPCConeBuilder") << " Reference(?) ring " << ref->first << " "
222  << "wants to be connected to " << refTowerCnt << " towers \n";
223  }
224 
225  if (refTowerCnt == 0) {
226  throw cms::Exception("RPCConeBuilder") << " Reference(?) ring " << ref->first << " "
227  << " is not connected anywhere \n";
228  }
229 
230  int lpSize = 0;
231  if (index != -1) {
232  for (auto const& it : l1RPCConeDefinition->getRingToLPVec()) {
233  if (it.m_etaPart != std::abs(other->second.getEtaPartition()) ||
234  it.m_hwPlane != std::abs(other->second.getHwPlane() - 1) || it.m_index != index) {
235  continue;
236  }
237  logplane = it.m_LP;
238  }
239 
240  for (auto const& it : l1RPCConeDefinition->getLPSizeVec()) {
241  if (it.m_tower != std::abs(refTower) || it.m_LP != logplane - 1) {
242  continue;
243  }
244  lpSize = it.m_size;
245  }
246 
247  //FIXME
248  if (lpSize == -1) {
249  //throw cms::Exception("getLogStrip") << " lpSize==-1\n";
250  }
251  }
252  return std::make_pair(logplane, lpSize);
253 }
254 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
RPCConeBuilder(const edm::ParameterSet &)
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
std::vector< TOtherConnStruct > TOtherConnStructVec
Definition: RPCStripsRing.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: RPCGeometry.cc:24
const TRingToTowerVec & getRingToTowerVec() const
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
const TLPSizeVec & getLPSizeVec() const
edm::ESGetToken< RPCGeometry, MuonGeometryRecord > m_rpcGeometryToken
std::unique_ptr< L1RPCConeBuilder > ReturnType
const TRingToLPVec & getRingToLPVec() const
void buildConnections(L1RPCConeDefinition const *, RPCStripsRing::TIdToRindMap &)
std::map< int, RPCStripsRing > TIdToRindMap
Definition: RPCStripsRing.h:39
void buildCones(RPCGeometry const *, L1RPCConeDefinition const *, RPCStripsRing::TIdToRindMap &)
ReturnType produce(const L1RPCConeBuilderRcd &)
TIdToRindMap::iterator m_it
Definition: RPCStripsRing.h:45
std::pair< int, int > areConnected(RPCStripsRing::TIdToRindMap::iterator ref, RPCStripsRing::TIdToRindMap::iterator other, L1RPCConeDefinition const *)
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
edm::ESGetToken< L1RPCConeDefinition, L1RPCConeDefinitionRcd > m_l1RPCConeDefinitionToken