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