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  int rolls = 0;
103  for (auto const& it : rpcGeom->dets()) {
104  RPCRoll const* roll = dynamic_cast<RPCRoll const*>(it);
105  if (roll == nullptr) {
106  continue;
107  }
108 
109  ++rolls;
110 
111  int ringId = RPCStripsRing::getRingId(roll);
112  auto found = ringsMap.find(ringId);
113  if (found == ringsMap.end()) {
114  ringsMap[ringId] = RPCStripsRing(roll, uncompressedCons);
115  } else {
116  found->second.addRoll(roll);
117  }
118  }
119 
120  // filtermixed strips, fill gaps with virtual strips
121  for (auto& it : ringsMap) {
122  it.second.filterOverlapingChambers();
123  it.second.fillWithVirtualStrips();
124  }
125 
126  // Xcheck, if rings are symmetrical
127  for (auto& it : ringsMap) {
128  int key = it.first;
129  int sign = key / 100 - (key / 1000) * 10;
130 
131  if (sign == 0) {
132  key += 100;
133  } else {
134  key -= 100;
135  }
136 
137  // Check if the geometry has a complete ring:
138  // note that in the case of demo chambers, the ring is not filled because only 2 sectors are added.
139  // (3014 and 4014 lack counter-rings)
140  if (key != 2000 && key != 3014 && key != 4014) { // Key 2100 has no counter-ring
141  if (it.second.size() != ringsMap[key].size()) {
142  throw cms::Exception("RPCInternal") << " Size differs for ring " << key << " +- 100 \n";
143  }
144  }
145  }
146  buildConnections(l1RPCConeDefinition, ringsMap);
147 }
148 
150  RPCStripsRing::TIdToRindMap& ringsMap) {
151  RPCStripsRing::TIdToRindMap::iterator itRef = ringsMap.begin();
152  for (; itRef != ringsMap.end(); ++itRef) { // iterate over reference rings
153 
154  RPCStripsRing::TOtherConnStructVec ringsToConnect;
155 
156  if (!itRef->second.isReferenceRing())
157  continue; // iterate over reference rings
158 
159  RPCStripsRing::TIdToRindMap::iterator itOther = ringsMap.begin();
160  for (; itOther != ringsMap.end(); ++itOther) { // iterate over nonreference rings
161 
162  if (itOther->second.isReferenceRing())
163  continue; // iterate over nonreference rings
164 
165  std::pair<int, int> pr = areConnected(itRef, itOther, l1RPCConeDefinition);
166  if (pr.first != -1) {
167  RPCStripsRing::TOtherConnStruct newOtherConn;
168  newOtherConn.m_it = itOther;
169  newOtherConn.m_logplane = pr.first;
170  newOtherConn.m_logplaneSize = pr.second;
171  ringsToConnect.push_back(newOtherConn);
172  }
173  } // OtherRings iteration ends
174 
175  std::pair<int, int> prRef = areConnected(itRef, itRef, l1RPCConeDefinition);
176  if (prRef.first == -1) {
177  throw cms::Exception("RPCConfig") << " Cannot determine logplane for reference ring " << itRef->first << "\n ";
178  }
179 
180  itRef->second.createRefConnections(ringsToConnect, prRef.first, prRef.second);
181 
182  } // RefRings iteration ends
183 }
184 
185 // first - logplane
186 // second - logplanesize
187 std::pair<int, int> RPCConeBuilder::areConnected(RPCStripsRing::TIdToRindMap::iterator ref,
188  RPCStripsRing::TIdToRindMap::iterator other,
189  L1RPCConeDefinition const* l1RPCConeDefinition) {
190  int logplane = -1;
191 
192  // Do not connect rolls lying on the oposite side of detector
193  if (ref->second.getEtaPartition() * other->second.getEtaPartition() < 0)
194  return std::make_pair(-1, 0);
195 
196  int refTowerCnt = 0;
197  int index = -1;
198  int refTower = -1;
199 
200  for (auto const& itRef : l1RPCConeDefinition->getRingToTowerVec()) {
201  if (itRef.m_etaPart != std::abs(ref->second.getEtaPartition()) ||
202  itRef.m_hwPlane != std::abs(ref->second.getHwPlane() - 1) // -1?
203  ) {
204  continue;
205  }
206 
207  ++refTowerCnt;
208  refTower = itRef.m_tower;
209 
210  for (auto const& itOther : l1RPCConeDefinition->getRingToTowerVec()) {
211  if (itOther.m_etaPart != std::abs(other->second.getEtaPartition()) ||
212  itOther.m_hwPlane != std::abs(other->second.getHwPlane() - 1) // -1?
213  ) {
214  continue;
215  }
216 
217  if (itOther.m_tower == refTower) {
218  index = itOther.m_index;
219  }
220  }
221  }
222 
223  if (refTowerCnt > 1) {
224  throw cms::Exception("RPCConeBuilder") << " Reference(?) ring " << ref->first << " "
225  << "wants to be connected to " << refTowerCnt << " towers \n";
226  }
227 
228  if (refTowerCnt == 0) {
229  throw cms::Exception("RPCConeBuilder") << " Reference(?) ring " << ref->first << " "
230  << " is not connected anywhere \n";
231  }
232 
233  int lpSize = 0;
234  if (index != -1) {
235  for (auto const& it : l1RPCConeDefinition->getRingToLPVec()) {
236  if (it.m_etaPart != std::abs(other->second.getEtaPartition()) ||
237  it.m_hwPlane != std::abs(other->second.getHwPlane() - 1) || it.m_index != index) {
238  continue;
239  }
240  logplane = it.m_LP;
241  }
242 
243  for (auto const& it : l1RPCConeDefinition->getLPSizeVec()) {
244  if (it.m_tower != std::abs(refTower) || it.m_LP != logplane - 1) {
245  continue;
246  }
247  lpSize = it.m_size;
248  }
249 
250  //FIXME
251  if (lpSize == -1) {
252  //throw cms::Exception("getLogStrip") << " lpSize==-1\n";
253  }
254  }
255  return std::make_pair(logplane, lpSize);
256 }
257 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
RPCConeBuilder(const edm::ParameterSet &)
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