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