CMS 3D CMS Logo

RPCConeBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RPCConeBuilder
4 // Class: RPCConeBuilder
5 //
13 //
14 // Original Author: Tomasz Maciej Frueboes
15 // Created: Fri Feb 22 13:57:06 CET 2008
16 //
17 //
18 
19 
20 // system include files
21 
22 // user include files
23 
26 
27 //#include "L1TriggerConfig/RPCConeBuilder/interface/RPCConeBuilder.h"
28 //#include "L1TriggerConfig/RPCConeBuilder/interface/RPCStripsRing.h"
29 
32 
33 
35 
36 #include <sstream>
37 #include <vector>
38 
40 
41 
43  m_towerBeg(iConfig.getParameter<int>("towerBeg")),
44  m_towerEnd(iConfig.getParameter<int>("towerEnd")),
45  m_runOnceBuildCones(false)
46  //m_rollBeg(iConfig.getParameter<int>("rollBeg")),
47  //m_rollEnd(iConfig.getParameter<int>("rollEnd")),
48  //m_hwPlaneBeg(iConfig.getParameter<int>("hwPlaneBeg")),
49  //m_hwPlaneEnd(iConfig.getParameter<int>("hwPlaneEnd"))
50 {
51 
54  );
55 
56  /* TT
57  for (int i = m_towerBeg; i <= m_towerEnd; ++i){
58 
59  std::stringstream name;
60  name << "lpSizeTower" << i;
61 
62  L1RPCConeBuilder::TLogPlaneSize newSizes =
63  iConfig.getParameter<std::vector<int> >(name.str().c_str());
64 
65  m_LPSizesInTowers.push_back(newSizes);
66 
67  }
68 
69  */
70 
71  // hw planes numbered from 0 to 5
72  // rolls from 0 to 17 (etaPartition)
73  //
74  // rollConnLP_[roll]_[hwPlane-1]
75  // rollConnLP_5_3 = cms.vint32(6, 0, 0),
76  // ----- roll 5, hwPlane 4 (3+1) is logplane 6 (OK)
77  //
78  // rollConnT_[roll]_[hwPlane-1]
79  // rollConnT_5_3 = cms.vint32(4, -1, -1),
80  // ----- roll 5, hwPlane 4 (3+1) contirubtes to tower 4 (OK)
81 
82  /*
83  for (int roll = m_rollBeg; roll <= m_rollEnd; ++roll){
84  L1RPCConeDefinition::THWplaneToTower newHwPlToTower;
85  L1RPCConeDefinition::THWplaneToLP newHWplaneToLP;
86  for (int hwpl = m_hwPlaneBeg; hwpl <= m_hwPlaneEnd; ++hwpl){
87  std::stringstream name;
88  name << "rollConnLP_" << roll << "_" << hwpl;
89 
90  L1RPCConeDefinition::TTowerList newListLP =
91  iConfig.getParameter<std::vector<int> >(name.str().c_str());
92  newHWplaneToLP.push_back(newListLP);
93 
94 
95  std::stringstream name1;
96  name1 << "rollConnT_" << roll << "_" << hwpl;
97 
98  L1RPCConeDefinition::TLPList newListT =
99  iConfig.getParameter<std::vector<int> >(name1.str().c_str());
100  newHwPlToTower.push_back(newListT);
101  }
102  m_RingsToTowers.push_back(newHwPlToTower);
103  m_RingsToLP.push_back(newHWplaneToLP);
104  }
105  */
106 }
107 
108 
109 
110 
111 //
112 // member functions
113 //
114 
115 // ------------ method called to produce the data ------------
118 //RPCConeBuilder::produce(const L1RPCConfigRcd& iRecord)
119 {
120 
121 
122  //std::cout << " RPCConeBuilder::produce called " << std::endl;
123  using namespace edm::es;
124  auto pL1RPCConeBuilder = std::make_shared<L1RPCConeBuilder>();
125 
126  pL1RPCConeBuilder->setFirstTower(m_towerBeg);
127  pL1RPCConeBuilder->setLastTower(m_towerEnd);
128 
129  /*
130  pL1RPCConeBuilder->setLPSizeForTowers(m_LPSizesInTowers);
131  pL1RPCConeBuilder->setRingsToLP(m_RingsToLP);
132  */
133 
134  //iRecord.get(m_rpcGeometry);
135  //iRecord.get(m_L1RPCConeDefinition);
137 
138  // Compress all connections. Since members of this class are shared
139  // pointers this call will compress all data
140  m_ringsMap.begin()->second.compressConnections();
141 
142  pL1RPCConeBuilder->setConeConnectionMap(m_ringsMap.begin()->second.getConnectionsMap());
143 
144  pL1RPCConeBuilder->setCompressedConeConnectionMap(
145  m_ringsMap.begin()->second.getCompressedConnectionsMap());
146 
147  m_ringsMap.clear(); // free mem
148 
149  return pL1RPCConeBuilder;
150 
151 }
152 
153 // ----------------------------------------------------------
155 
156  //std::cout << " Geometry callback called " << std::endl;
157  m_runOnceBuildCones = false; // allow re-running of buildCones
158  record.get(m_rpcGeometry);
159 
160 
161 }
162 
164 
165  //std::cout << " ConeDef callback called " << std::endl;
166  m_runOnceBuildCones = false; // allow re-running of buildCones
167 
168  //edm::ESHandle<RPCGeometry> rpcGeom;
169  record.get(m_L1RPCConeDefinition);
170 
171  //std::cout << " ConeDef callback exit " << std::endl;
172  //std::cout.flush();
173  //buildCones(rpcGeom);
174 
175 }
176 
177 
178 
180 
181 
182  if (!m_runOnceBuildCones){
183  m_runOnceBuildCones = true;
184  } else {
185  throw cms::Exception("RPCInternal") << "buildCones called twice \n";
186  }
187 
188  //std::cout << " ---> buildCones called " << std::endl;
189 
190  // fetch geometricall data
191  auto uncompressedCons = std::make_shared<L1RPCConeBuilder::TConMap>();
192 
193 
194  int rolls = 0;
195  for(TrackingGeometry::DetContainer::const_iterator it = rpcGeom->dets().begin();
196  it != rpcGeom->dets().end();
197  ++it)
198  {
199 
200  if( dynamic_cast< RPCRoll const * >( *it ) == 0 ) continue;
201 
202  ++rolls;
203  RPCRoll const* roll = dynamic_cast< RPCRoll const*>( *it );
204 
205  int ringId = RPCStripsRing::getRingId(roll);
206  if ( m_ringsMap.find(ringId) == m_ringsMap.end() ) {
207  m_ringsMap[ringId]=RPCStripsRing(roll, uncompressedCons);
208  } else {
209  m_ringsMap[ringId].addRoll(roll);
210  }
211  //RPCStripsRing sr(roll);
212 
213  }
214 
215  //std::cout << " found: " << rolls << " dets" << std::endl;
216 
217  RPCStripsRing::TIdToRindMap::iterator it = m_ringsMap.begin();
218 
219  // filtermixed strips, fill gaps with virtual strips
220  for (;it != m_ringsMap.end(); ++it){
221 
222  //int before = it->second.size();
223 
224  it->second.filterOverlapingChambers();
225  it->second.fillWithVirtualStrips();
226 
227 
228  //std::cout << it->first << " " << it->second.isReferenceRing() << " "
229  // << before << " -> "
230  // << it->second.size() << std::endl;
231 
232  // In reference plane we should have 144*8 = 1152 strips
233  //int plane = it->first/1000;
234  int etaPart = it->first%100;
235  if (it->second.isReferenceRing() && (it->second.size() != 1152)){
236 
237  if (std::abs(etaPart)>=14 || std::abs(etaPart)<=17 ) {
238  //std::cout << "etaPart " << etaPart << " size " << it->second.size() << std::endl;
239  }
240  else {
241  throw cms::Exception("RPCInternal") << "Problem: refring " << it->first
242  << " has " << it->second.size() << " strips \n";
243  }
244  }
245 
246 
247  }
248 
249  // Xcheck, if rings are symettrical
250  it = m_ringsMap.begin();
251  for (;it != m_ringsMap.end(); ++it){
252  int key = it->first;
253  int sign = key/100 - (key/1000)*10;
254 
255  if (sign == 0) {
256  key += 100;
257  } else {
258  key -= 100;
259  }
260 
261  if (key != 2000){// Hey 2100 has no counterring
262  if (it->second.size() != m_ringsMap[key].size())
263  {
264  throw cms::Exception("RPCInternal") << " Size differs for ring " << key << " +- 100 \n";
265  }
266  }
267 
268 
269  }
270 
272 }
273 
274 
276 
277 
278 
279  RPCStripsRing::TIdToRindMap::iterator itRef = m_ringsMap.begin();
280  for (;itRef != m_ringsMap.end(); ++itRef){ // iterate over reference rings
281 
282 
283  RPCStripsRing::TOtherConnStructVec ringsToConnect;
284 
285  if (!itRef->second.isReferenceRing()) continue; // iterate over reference rings
286 
287  RPCStripsRing::TIdToRindMap::iterator itOther = m_ringsMap.begin();
288  for (;itOther != m_ringsMap.end(); ++itOther){ // iterate over nonreference rings
289 
290  if (itOther->second.isReferenceRing()) continue; // iterate over nonreference rings
291 
292  std::pair<int,int> pr = areConnected(itRef, itOther);
293  if ( pr.first != -1 ) {
294  RPCStripsRing::TOtherConnStruct newOtherConn;
295  newOtherConn.m_it = itOther;
296  newOtherConn.m_logplane = pr.first;
297  newOtherConn.m_logplaneSize = pr.second;
298  ringsToConnect.push_back(newOtherConn);
299  }
300 
301 
302  } // OtherRings iteration ends
303 
304  //
305  std::pair<int,int> prRef = areConnected(itRef, itRef);
306  if (prRef.first == -1){
307  throw cms::Exception("RPCConfig") << " Cannot determine logplane for reference ring "
308  << itRef->first << "\n ";
309  }
310 
311  /*&
312  if (prRef.second != 8){
313  // XXX
314  throw cms::Exception("RPCConfig") << " logplaneSize for reference ring "
315  << itRef->first << " wrong "
316  << " logplane: " << prRef.first
317  << " etaPart: " << itRef->second.getEtaPartition()
318  << " tower: " << itRef->second.getTowerForRefRing()
319  << " hwPlane: " << itRef->second.getHwPlane()
320  << " strips " << prRef.second << "\n";
321  }*/
322 
323  itRef->second.createRefConnections(ringsToConnect, prRef.first, prRef.second);
324 
325  } // RefRings iteration ends
326 
327 
328  // Fetch connection data, and save in one place
329  /*
330  RPCStripsRing::TIdToRindMap::iterator it = m_ringsMap.begin();
331  for (;it != m_ringsMap.end(); ++it) {
332 
333  L1RPCConeBuilder::TConMap nmap = it->second.getConnectionsMap();
334  L1RPCConeBuilder::TConMap::iterator newMapIt = nmap.begin();
335  for (; newMapIt != nmap.end(); ++ newMapIt) {
336  uint32_t raw = newMapIt->first;
337  TStrip2ConVec stripsVec = newMapIt->second;
338  TStrip2ConVec::iterator stripIt = stripsVec.first
339  //unsigned char strip =
340 
341 
342  }
343 
344 
345  }*/
346 
347 }
348 
349 // first - logplane
350 // second - logplanesize
351 std::pair<int, int> RPCConeBuilder::areConnected(RPCStripsRing::TIdToRindMap::iterator ref,
352  RPCStripsRing::TIdToRindMap::iterator other){
353 
354  int logplane = -1;
355 
356  //std::cout << "Checking " << ref->first << " and " << other->first << std::endl;
357 
358  // Do not connect rolls lying on the oposite side of detector
359  if ( ref->second.getEtaPartition()*other->second.getEtaPartition()<0 )
360  return std::make_pair(-1,0);
361 
362 
363  /*std::cout << "Ref " << ref->second.getEtaPartition() << " " <<ref->second.getHwPlane() << std::endl;
364  std::cout << "Other " << other->second.getEtaPartition() << " " <<other->second.getHwPlane() << std::endl;
365  std::cout.flush();*/
366 
367  // refRing and otherRing areConnected, if they contribute to the same tower
368  /*
369  L1RPCConeDefinition::TTowerList refTowList
370  = m_L1RPCConeDefinition->getRingsToTowers().at(std::abs(ref->second.getEtaPartition()))
371  .at(ref->second.getHwPlane()-1);
372 
373 
374  L1RPCConeDefinition::TTowerList otherTowList
375  = m_L1RPCConeDefinition->getRingsToTowers().at(std::abs(other->second.getEtaPartition()))
376  .at(other->second.getHwPlane()-1);
377  */
378 
379  L1RPCConeDefinition::TRingToTowerVec::const_iterator itRef
381 
382  const L1RPCConeDefinition::TRingToTowerVec::const_iterator itEnd
384 
385  L1RPCConeDefinition::TRingToTowerVec::const_iterator itOther = itRef;
386 
387  int refTowerCnt = 0;
388  int index = -1;
389  int refTower = -1;
390 
391  for (;itRef != itEnd; ++itRef){
392  if ( itRef->m_etaPart != std::abs(ref->second.getEtaPartition())
393  || itRef->m_hwPlane != std::abs(ref->second.getHwPlane()-1) // -1?
394  ) continue;
395 
396  ++refTowerCnt;
397  refTower = itRef->m_tower;
398 
399  for (;itOther != itEnd; ++itOther){
400  if ( itOther->m_etaPart != std::abs(other->second.getEtaPartition())
401  || itOther->m_hwPlane != std::abs(other->second.getHwPlane()-1) // -1?
402  ) continue;
403 
404  if (itOther->m_tower == refTower) index = itOther->m_index;
405 
406  }
407 
408  }
409 
410  if(refTowerCnt>1){
411  throw cms::Exception("RPCConeBuilder") << " Reference(?) ring "
412  << ref->first << " "
413  << "wants to be connected to " << refTowerCnt << " towers \n";
414 
415  }
416 
417  if(refTowerCnt==0){
418  throw cms::Exception("RPCConeBuilder") << " Reference(?) ring "
419  << ref->first << " "
420  << " is not connected anywhere \n";
421 
422  }
423 
424  /*
425  if(index == -1){
426  throw cms::Exception("RPCConeBuilder") << "Wrong Index -1 \n"
427  }*/
428 
429 
430  /*
431  int refTower = -1;
432 
433  L1RPCConeDefinition::TTowerList::iterator rtlIt = refTowList.begin();
434  for (; rtlIt != refTowList.end(); ++rtlIt){
435 
436  if ( *rtlIt >= 0 && refTower < 0){
437  refTower = *rtlIt;
438  }
439  else if ( *rtlIt >= 0 && refTower >= 0) {
440  throw cms::Exception("RPCConfig") << " Reference(?) ring "
441  << ref->first << " "
442  << "wants to be connected more than one tower: "
443  << refTower << " "
444  << *rtlIt << "\n";
445 
446  }
447 
448  }
449 
450  if (refTower < 0) {
451  throw cms::Exception("RPCConfig") << " Reference(?) ring "
452  << ref->first
453  << " is not connected anywhere \n";
454  }
455 
456  L1RPCConeDefinition::TTowerList::iterator otlIt = otherTowList.begin();
457 
458  int index = -1, i = 0;
459  for (; otlIt != otherTowList.end(); ++otlIt){
460  if (*otlIt == refTower) {
461  index = i;
462  }
463  ++i;
464  }
465  */
466 
467  int lpSize = 0;
468  if (index != -1){
469  /*
470  logplane = m_L1RPCConeDefinition->getRingsToLP().at(std::abs(other->second.getEtaPartition()))
471  .at(other->second.getHwPlane()-1)
472  .at(index);*/
473  {
474  L1RPCConeDefinition::TRingToLPVec::const_iterator it = m_L1RPCConeDefinition->getRingToLPVec().begin();
475  L1RPCConeDefinition::TRingToLPVec::const_iterator itEnd = m_L1RPCConeDefinition->getRingToLPVec().end();
476  for (;it!=itEnd;++it){
477 
478  if (it->m_etaPart != std::abs(other->second.getEtaPartition())
479  || it->m_hwPlane != std::abs(other->second.getHwPlane()-1)
480  || it->m_index != index) continue;
481 
482  logplane = it->m_LP;
483 
484  }
485  }
486  //lpSize = m_L1RPCConeDefinition->getLPSizeForTowers().at(refTower).at(logplane-1);
487 
488  {
489  L1RPCConeDefinition::TLPSizeVec::const_iterator it = m_L1RPCConeDefinition->getLPSizeVec().begin();
490  L1RPCConeDefinition::TLPSizeVec::const_iterator itEnd = m_L1RPCConeDefinition->getLPSizeVec().end();
491  for (;it!=itEnd;++it){
492 
493  //std::cout << it->m_LP << " " << logplane << std::endl;
494  if (it->m_tower != std::abs(refTower) || it->m_LP != logplane-1) continue;
495  lpSize = it->m_size;
496 
497  }
498 
499  //FIXME
500  if (lpSize==-1) {
501  //throw cms::Exception("getLogStrip") << " lpSize==-1\n";
502  }
503  }
504  }
505 
506 
507  /*
508  if (logplane != -1){
509 
510  std::cout << ref->first << " <-> " << other->first
511  << " logplane " << logplane
512  << " lpsize " << lpSize
513  << std::endl;
514  }//*/
515 
516  return std::make_pair(logplane,lpSize);
517 
518 }
519 
520 
521 
edm::ESHandle< RPCGeometry > m_rpcGeometry
depends_on::OneHolder< T, TDependsOnRecord > dependsOn(void(T::*iT)(const TDependsOnRecord &))
bool m_runOnceBuildCones
RPCConeBuilder(const edm::ParameterSet &)
JetCorrectorParameters::Record record
Definition: classes.h:7
const TRingToLPVec & getRingToLPVec() const
const TRingToTowerVec & getRingToTowerVec() const
void geometryCallback(const MuonGeometryRecord &)
std::pair< int, int > areConnected(RPCStripsRing::TIdToRindMap::iterator ref, RPCStripsRing::TIdToRindMap::iterator other)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void buildCones(const edm::ESHandle< RPCGeometry > &rpcGeom)
std::vector< TOtherConnStruct > TOtherConnStructVec
Definition: RPCStripsRing.h:53
void get(HolderT &iHolder) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void coneDefCallback(const L1RPCConeDefinitionRcd &)
int m_towerBeg
Returns logplane number for this connection, if not connected returns -1. In second lpSize...
const TLPSizeVec & getLPSizeVec() const
edm::ESHandle< L1RPCConeDefinition > m_L1RPCConeDefinition
RPCStripsRing::TIdToRindMap m_ringsMap
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: RPCGeometry.cc:33
std::shared_ptr< L1RPCConeBuilder > ReturnType
ReturnType produce(const L1RPCConeBuilderRcd &)
TIdToRindMap::iterator m_it
Definition: RPCStripsRing.h:50