CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  boost::shared_ptr<L1RPCConeBuilder> pL1RPCConeBuilder( ( new 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  boost::shared_ptr<L1RPCConeBuilder::TConMap > uncompressedCons
192  = boost::shared_ptr<L1RPCConeBuilder::TConMap >(new L1RPCConeBuilder::TConMap());
193 
194 
195  int rolls = 0;
196  for(TrackingGeometry::DetContainer::const_iterator it = rpcGeom->dets().begin();
197  it != rpcGeom->dets().end();
198  ++it)
199  {
200 
201  if( dynamic_cast< RPCRoll const * >( *it ) == 0 ) continue;
202 
203  ++rolls;
204  RPCRoll const* roll = dynamic_cast< RPCRoll const*>( *it );
205 
206  int ringId = RPCStripsRing::getRingId(roll);
207  if ( m_ringsMap.find(ringId) == m_ringsMap.end() ) {
208  m_ringsMap[ringId]=RPCStripsRing(roll, uncompressedCons);
209  } else {
210  m_ringsMap[ringId].addRoll(roll);
211  }
212  //RPCStripsRing sr(roll);
213 
214  }
215 
216  //std::cout << " found: " << rolls << " dets" << std::endl;
217 
218  RPCStripsRing::TIdToRindMap::iterator it = m_ringsMap.begin();
219 
220  // filtermixed strips, fill gaps with virtual strips
221  for (;it != m_ringsMap.end(); ++it){
222 
223  //int before = it->second.size();
224 
225  it->second.filterOverlapingChambers();
226  it->second.fillWithVirtualStrips();
227 
228 
229  //std::cout << it->first << " " << it->second.isReferenceRing() << " "
230  // << before << " -> "
231  // << it->second.size() << std::endl;
232 
233  // In reference plane we should have 144*8 = 1152 strips
234  //int plane = it->first/1000;
235  int etaPart = it->first%100;
236  if (it->second.isReferenceRing() && (it->second.size() != 1152)){
237 
238  if (std::abs(etaPart)>=14 || std::abs(etaPart)<=17 ) {
239  //std::cout << "etaPart " << etaPart << " size " << it->second.size() << std::endl;
240  }
241  else {
242  throw cms::Exception("RPCInternal") << "Problem: refring " << it->first
243  << " has " << it->second.size() << " strips \n";
244  }
245  }
246 
247 
248  }
249 
250  // Xcheck, if rings are symettrical
251  it = m_ringsMap.begin();
252  for (;it != m_ringsMap.end(); ++it){
253  int key = it->first;
254  int sign = key/100 - (key/1000)*10;
255 
256  if (sign == 0) {
257  key += 100;
258  } else {
259  key -= 100;
260  }
261 
262  if (key != 2000){// Hey 2100 has no counterring
263  if (it->second.size() != m_ringsMap[key].size())
264  {
265  throw cms::Exception("RPCInternal") << " Size differs for ring " << key << " +- 100 \n";
266  }
267  }
268 
269 
270  }
271 
273 }
274 
275 
277 
278 
279 
280  RPCStripsRing::TIdToRindMap::iterator itRef = m_ringsMap.begin();
281  for (;itRef != m_ringsMap.end(); ++itRef){ // iterate over reference rings
282 
283 
284  RPCStripsRing::TOtherConnStructVec ringsToConnect;
285 
286  if (!itRef->second.isReferenceRing()) continue; // iterate over reference rings
287 
288  RPCStripsRing::TIdToRindMap::iterator itOther = m_ringsMap.begin();
289  for (;itOther != m_ringsMap.end(); ++itOther){ // iterate over nonreference rings
290 
291  if (itOther->second.isReferenceRing()) continue; // iterate over nonreference rings
292 
293  std::pair<int,int> pr = areConnected(itRef, itOther);
294  if ( pr.first != -1 ) {
295  RPCStripsRing::TOtherConnStruct newOtherConn;
296  newOtherConn.m_it = itOther;
297  newOtherConn.m_logplane = pr.first;
298  newOtherConn.m_logplaneSize = pr.second;
299  ringsToConnect.push_back(newOtherConn);
300  }
301 
302 
303  } // OtherRings iteration ends
304 
305  //
306  std::pair<int,int> prRef = areConnected(itRef, itRef);
307  if (prRef.first == -1){
308  throw cms::Exception("RPCConfig") << " Cannot determine logplane for reference ring "
309  << itRef->first << "\n ";
310  }
311 
312  /*&
313  if (prRef.second != 8){
314  // XXX
315  throw cms::Exception("RPCConfig") << " logplaneSize for reference ring "
316  << itRef->first << " wrong "
317  << " logplane: " << prRef.first
318  << " etaPart: " << itRef->second.getEtaPartition()
319  << " tower: " << itRef->second.getTowerForRefRing()
320  << " hwPlane: " << itRef->second.getHwPlane()
321  << " strips " << prRef.second << "\n";
322  }*/
323 
324  itRef->second.createRefConnections(ringsToConnect, prRef.first, prRef.second);
325 
326  } // RefRings iteration ends
327 
328 
329  // Fetch connection data, and save in one place
330  /*
331  RPCStripsRing::TIdToRindMap::iterator it = m_ringsMap.begin();
332  for (;it != m_ringsMap.end(); ++it) {
333 
334  L1RPCConeBuilder::TConMap nmap = it->second.getConnectionsMap();
335  L1RPCConeBuilder::TConMap::iterator newMapIt = nmap.begin();
336  for (; newMapIt != nmap.end(); ++ newMapIt) {
337  uint32_t raw = newMapIt->first;
338  TStrip2ConVec stripsVec = newMapIt->second;
339  TStrip2ConVec::iterator stripIt = stripsVec.first
340  //unsigned char strip =
341 
342 
343  }
344 
345 
346  }*/
347 
348 }
349 
350 // first - logplane
351 // second - logplanesize
352 std::pair<int, int> RPCConeBuilder::areConnected(RPCStripsRing::TIdToRindMap::iterator ref,
353  RPCStripsRing::TIdToRindMap::iterator other){
354 
355  int logplane = -1;
356 
357  //std::cout << "Checking " << ref->first << " and " << other->first << std::endl;
358 
359  // Do not connect rolls lying on the oposite side of detector
360  if ( ref->second.getEtaPartition()*other->second.getEtaPartition()<0 )
361  return std::make_pair(-1,0);
362 
363 
364  /*std::cout << "Ref " << ref->second.getEtaPartition() << " " <<ref->second.getHwPlane() << std::endl;
365  std::cout << "Other " << other->second.getEtaPartition() << " " <<other->second.getHwPlane() << std::endl;
366  std::cout.flush();*/
367 
368  // refRing and otherRing areConnected, if they contribute to the same tower
369  /*
370  L1RPCConeDefinition::TTowerList refTowList
371  = m_L1RPCConeDefinition->getRingsToTowers().at(std::abs(ref->second.getEtaPartition()))
372  .at(ref->second.getHwPlane()-1);
373 
374 
375  L1RPCConeDefinition::TTowerList otherTowList
376  = m_L1RPCConeDefinition->getRingsToTowers().at(std::abs(other->second.getEtaPartition()))
377  .at(other->second.getHwPlane()-1);
378  */
379 
380  L1RPCConeDefinition::TRingToTowerVec::const_iterator itRef
381  = m_L1RPCConeDefinition->getRingToTowerVec().begin();
382 
383  const L1RPCConeDefinition::TRingToTowerVec::const_iterator itEnd
384  = m_L1RPCConeDefinition->getRingToTowerVec().end();
385 
386  L1RPCConeDefinition::TRingToTowerVec::const_iterator itOther = itRef;
387 
388  int refTowerCnt = 0;
389  int index = -1;
390  int refTower = -1;
391 
392  for (;itRef != itEnd; ++itRef){
393  if ( itRef->m_etaPart != std::abs(ref->second.getEtaPartition())
394  || itRef->m_hwPlane != std::abs(ref->second.getHwPlane()-1) // -1?
395  ) continue;
396 
397  ++refTowerCnt;
398  refTower = itRef->m_tower;
399 
400  for (;itOther != itEnd; ++itOther){
401  if ( itOther->m_etaPart != std::abs(other->second.getEtaPartition())
402  || itOther->m_hwPlane != std::abs(other->second.getHwPlane()-1) // -1?
403  ) continue;
404 
405  if (itOther->m_tower == refTower) index = itOther->m_index;
406 
407  }
408 
409  }
410 
411  if(refTowerCnt>1){
412  throw cms::Exception("RPCConeBuilder") << " Reference(?) ring "
413  << ref->first << " "
414  << "wants to be connected to " << refTowerCnt << " towers \n";
415 
416  }
417 
418  if(refTowerCnt==0){
419  throw cms::Exception("RPCConeBuilder") << " Reference(?) ring "
420  << ref->first << " "
421  << " is not connected anywhere \n";
422 
423  }
424 
425  /*
426  if(index == -1){
427  throw cms::Exception("RPCConeBuilder") << "Wrong Index -1 \n"
428  }*/
429 
430 
431  /*
432  int refTower = -1;
433 
434  L1RPCConeDefinition::TTowerList::iterator rtlIt = refTowList.begin();
435  for (; rtlIt != refTowList.end(); ++rtlIt){
436 
437  if ( *rtlIt >= 0 && refTower < 0){
438  refTower = *rtlIt;
439  }
440  else if ( *rtlIt >= 0 && refTower >= 0) {
441  throw cms::Exception("RPCConfig") << " Reference(?) ring "
442  << ref->first << " "
443  << "wants to be connected more than one tower: "
444  << refTower << " "
445  << *rtlIt << "\n";
446 
447  }
448 
449  }
450 
451  if (refTower < 0) {
452  throw cms::Exception("RPCConfig") << " Reference(?) ring "
453  << ref->first
454  << " is not connected anywhere \n";
455  }
456 
457  L1RPCConeDefinition::TTowerList::iterator otlIt = otherTowList.begin();
458 
459  int index = -1, i = 0;
460  for (; otlIt != otherTowList.end(); ++otlIt){
461  if (*otlIt == refTower) {
462  index = i;
463  }
464  ++i;
465  }
466  */
467 
468  int lpSize = 0;
469  if (index != -1){
470  /*
471  logplane = m_L1RPCConeDefinition->getRingsToLP().at(std::abs(other->second.getEtaPartition()))
472  .at(other->second.getHwPlane()-1)
473  .at(index);*/
474  {
475  L1RPCConeDefinition::TRingToLPVec::const_iterator it = m_L1RPCConeDefinition->getRingToLPVec().begin();
476  L1RPCConeDefinition::TRingToLPVec::const_iterator itEnd = m_L1RPCConeDefinition->getRingToLPVec().end();
477  for (;it!=itEnd;++it){
478 
479  if (it->m_etaPart != std::abs(other->second.getEtaPartition())
480  || it->m_hwPlane != std::abs(other->second.getHwPlane()-1)
481  || it->m_index != index) continue;
482 
483  logplane = it->m_LP;
484 
485  }
486  }
487  //lpSize = m_L1RPCConeDefinition->getLPSizeForTowers().at(refTower).at(logplane-1);
488 
489  {
490  L1RPCConeDefinition::TLPSizeVec::const_iterator it = m_L1RPCConeDefinition->getLPSizeVec().begin();
491  L1RPCConeDefinition::TLPSizeVec::const_iterator itEnd = m_L1RPCConeDefinition->getLPSizeVec().end();
492  for (;it!=itEnd;++it){
493 
494  //std::cout << it->m_LP << " " << logplane << std::endl;
495  if (it->m_tower != std::abs(refTower) || it->m_LP != logplane-1) continue;
496  lpSize = it->m_size;
497 
498  }
499 
500  //FIXME
501  if (lpSize==-1) {
502  //throw cms::Exception("getLogStrip") << " lpSize==-1\n";
503  }
504  }
505  }
506 
507 
508  /*
509  if (logplane != -1){
510 
511  std::cout << ref->first << " <-> " << other->first
512  << " logplane " << logplane
513  << " lpsize " << lpSize
514  << std::endl;
515  }//*/
516 
517  return std::make_pair(logplane,lpSize);
518 
519 }
520 
521 
522 
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
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)
boost::shared_ptr< L1RPCConeBuilder > ReturnType
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...
edm::ESHandle< L1RPCConeDefinition > m_L1RPCConeDefinition
RPCStripsRing::TIdToRindMap m_ringsMap
std::map< uint32_t, TStrip2ConVec > TConMap
string const
Definition: compareJSON.py:14
list key
Definition: combine.py:13
ReturnType produce(const L1RPCConeBuilderRcd &)
volatile std::atomic< bool > shutdown_flag false
TIdToRindMap::iterator m_it
Definition: RPCStripsRing.h:50