CMS 3D CMS Logo

RPCStripsRing.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RPCConeBuilder
4 // Class : RPCStripsRing
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Tomasz Fruboes
10 // Created: Tue Feb 26 15:13:10 CET 2008
11 //
12 
13 // system include files
14 
15 // user include files
16 //#include "L1TriggerConfig/RPCConeBuilder/interface/RPCStripsRing.h"
22 
24  : m_hwPlane(-1),
25  m_etaPartition(99),
26  m_region(-2),
27  m_isReferenceRing(false),
28  m_didVirtuals(false),
29  m_didFiltering(false) {}
30 
31 RPCStripsRing::RPCStripsRing(const RPCRoll* roll, std::shared_ptr<L1RPCConeBuilder::TConMap> cmap)
32  : m_didVirtuals(false), m_didFiltering(false), m_connectionsMap(cmap) {
33  RPCDetId detId = roll->id();
34  RPCGeomServ grs(detId);
35 
38 
39  m_isReferenceRing = false;
40 
41  m_region = detId.region();
42 
43  int ring = detId.ring();
44 
45  if (m_region == 0 && std::abs(ring) < 2 && m_hwPlane == 2) // for barell wheel -1,0,1 refplane is hwPlane=2
46  m_isReferenceRing = true;
47  else if (m_region == 0 && std::abs(ring) == 2 && m_hwPlane == 6) // for barell wheel -2,2 refplane is hwPlane=6
48  m_isReferenceRing = true;
49  else if (m_region != 0 && m_hwPlane == 2) // for endcaps
50  m_isReferenceRing = true;
51 
52  if (getRingId() == 2008 || getRingId() == 2108) //exception: endcaps;hwplane 2;farest roll from beam
53  m_isReferenceRing = false;
54 
55  addRoll(roll);
56 }
57 
59  // RPCDetId detId = roll->id();
60 
61  if (getRingId() != getRingId(roll)) {
62  throw cms::Exception("RPCInternal") << "RPCStripsRing::addRoll ringsIds dont match \n";
63  }
64 
65  //iterate over the strips of this roll
66  for (int i = 1; i <= roll->nstrips(); i++) {
67  LocalPoint lStripCentre = roll->centreOfStrip(i);
68  GlobalPoint gStripCentre = roll->toGlobal(lStripCentre);
69  float phiRaw = gStripCentre.phi();
70 
71  TStrip newStrip(roll->id().rawId(), i);
72  (*this)[phiRaw] = newStrip;
73  }
74 }
75 
76 int RPCStripsRing::getRingId(int etaPart, int hwPlane) {
77  int sign = 1; // positive
78  if (etaPart < 0) {
79  sign = 0;
80  }
81 
82  return 1000 * (hwPlane) + //1...6
83  100 * (sign) + //
84  1 * (std::abs(etaPart)); //-17...17
85 }
86 
88 
90  RPCDetId detId = roll->id();
91  RPCGeomServ grs(detId);
92  int etaPartition = grs.eta_partition();
93  int hwPlane = calculateHwPlane(roll);
94 
95  return getRingId(etaPartition, hwPlane);
96 }
97 
98 // hwPlane is station number for endcaps
99 // for barrell numbering goes 1 5 2 6 3 4 (first number means plane closest to the beam)
101  int hwPlane = -1;
102  RPCDetId detId = roll->id();
103  int station = detId.station();
104  int layer = detId.layer();
105  int region = detId.region();
106 
107  if (region != 0) { // endcaps
108  hwPlane = station;
109  }
110  // Now comes the barell
111  else if (station > 2) {
112  hwPlane = station;
113  } else if (station == 1 && layer == 1) {
114  hwPlane = 1;
115  } else if (station == 1 && layer == 2) {
116  hwPlane = 5;
117  } else if (station == 2 && layer == 1) {
118  hwPlane = 2;
119  } else if (station == 2 && layer == 2) {
120  hwPlane = 6;
121  }
122 
123  /*if (hwPlane < 1)
124  std::cout << "prb: " << hwPlane << " "
125  << region << " "
126  << station << " "
127  << layer << std::endl;*/
128  if (hwPlane < 0) {
129  throw cms::Exception("RPCInternal") << "Calculated negative hwplane \n";
130  }
131 
132  return hwPlane;
133 }
134 
136  if (m_didFiltering)
137  return;
138  m_didFiltering = true;
139 
140  if (m_region != 0 || m_hwPlane != 4)
141  return;
142 
143  typedef std::map<uint32_t, int> TDetId2StripNo;
144  TDetId2StripNo det2stripNo;
145 
146  // Note: we begin in middle of first chamber (ch1), we have to handle that
147  int ch1EndStrips = 0; // no of strips on the end of the map (first=last chamber of map)
148 
149  // How many strips has each chamber?
150  RPCStripsRing::iterator it = this->begin();
151  uint32_t ch1Det = it->second.m_detRawId;
152  for (; it != this->end(); ++it) {
153  if (det2stripNo.find(it->second.m_detRawId) == det2stripNo.end()) {
154  det2stripNo[it->second.m_detRawId] = 1; // Add new chamber to a map, set strip cnt to 1
155  } else {
156  ++det2stripNo[it->second.m_detRawId]; // Increase strip count of a chamber
157  }
158 
159  if (det2stripNo.size() != 1 && ch1Det == it->second.m_detRawId) {
160  ++ch1EndStrips;
161  }
162  }
163 
164  det2stripNo[ch1Det] -= ch1EndStrips;
165 
166  // std::cout << ch1BegStrips << " " << ch1EndStrips << std::endl;
167 
168  //TDetId2StripNo::iterator itIds = det2stripNo.begin();
169  //for(;itIds!=det2stripNo.end();++itIds){
170  // std::cout << itIds->first << " " << itIds->second << std::endl;
171  // }
172 
173  it = this->begin();
174  uint32_t lastDet = it->second.m_detRawId;
175  while (it != this->end()) {
176  if (det2stripNo[it->second.m_detRawId] < 0) {
177  throw cms::Exception("RPCInternal") << " RPCStripsRing::filterOverlapingChambers() - no strips left \n";
178  }
179  if (it->second.m_detRawId == lastDet) {
180  --det2stripNo[lastDet];
181  ++it;
182  } else if (det2stripNo[lastDet] == 0) { // no more strips left in lastDet, proceed to new det
183 
184  if (lastDet == ch1Det) {
185  det2stripNo[ch1Det] += ch1EndStrips;
186  }
187 
188  lastDet = it->second.m_detRawId;
189  --det2stripNo[lastDet];
190  ++it;
191  } else { // there are still strips in last det, delete current strip
192  --det2stripNo[it->second.m_detRawId];
193  RPCStripsRing::iterator itErase = it;
194  ++it;
195  //std::cout << "Removing strip " << it->second.m_detRawId << " " << (int)it->second.m_strip << std::endl;
196  this->erase(itErase);
197  }
198  }
199 }
200 
202  if (m_didVirtuals)
203  return;
204  m_didVirtuals = true;
205 
206  const float pi = 3.141592654;
207  double dphi = 2.0 * pi / 1152; // defines angular granulation of strips.
208 
209  RPCStripsRing stripsToInsert;
210 
211  float delta = 0;
212  int stripsToAdd = 0;
213 
214  RPCStripsRing::iterator it = this->begin();
215  RPCStripsRing::iterator itLast = this->begin();
216  for (; it != this->end(); ++it) {
217  /*std::cout << it->first << " "
218  << it->second.m_detRawId << " "
219  << (int)it->second.m_strip << std::endl;
220  */
221 
222  delta = it->first - itLast->first;
223  if (it == itLast || // skip first loop iteration
224  itLast->second.m_detRawId == it->second.m_detRawId || // insert strips between two chambers only
225  delta < 0) {
226  itLast = it;
227  continue;
228  }
229 
230  stripsToAdd = (int)std::floor(delta / dphi) - 1;
231  //std::cout << delta << " " << stripsToAdd << std::endl;
232 
233  if (isReferenceRing() && m_hwPlane == 6)
234  ++stripsToAdd;
235 
236  for (int i = 0; i < stripsToAdd; ++i) {
237  stripsToInsert[itLast->first + dphi * (i + 1)] = TStrip();
238  }
239 
240  itLast = it;
241  }
242  // TODO: check delta between first and last strip in map
243 
244  this->insert(stripsToInsert.begin(), stripsToInsert.end());
245 }
246 void RPCStripsRing::createRefConnections(TOtherConnStructVec& otherRings, int logplane, int logplaneSize) {
247  //*
248  /*std::cout << "RefCon for " << getRingId()
249  << " (" << getEtaPartition()<< ")"
250  << " tower: " << getTowerForRefRing()
251  << " ; connected: "
252  << otherRings.size()
253  << std::endl
254  << std::endl;
255  //*/
256 
257  // XXX - TODO: warning on wrong logplaneSize
258 
259  if (!this->isReferenceRing()) {
260  throw cms::Exception("RPCInternal") << " RPCStripsRing::createRefConnections "
261  << " called for non-reference ring \n";
262  }
263 
264  /*
265  if (logplaneSize!=8) {
266  throw cms::Exception("RPCInternal") << " RPCStripsRing::createRefConnections "
267  << " called for lpSize " << logplaneSize << " \n";
268 
269  }*/
270  const float pi = 3.141592654;
271  const float offset = (5. / 360.) * 2 * pi; // XXX
272 
273  //find first reference strip of first PAC (the strip with phi ~= 5deg)
274  RPCStripsRing::iterator starEndIt = this->begin();
275  while ((++starEndIt)->first < offset)
276  ;
277 
278  RPCStripsRing::iterator it = starEndIt;
279  //--starEndIt;
280 
281  float angle = 0;
282  int curPACno = -1;
283  int curStripNo = 0;
284  int curBegStripNo = 0;
285 
286  bool firstIter = true;
287 
288  while (it != starEndIt || firstIter) { // iterate over strips
289 
290  firstIter = false;
291  // New PAC
292  if (curStripNo % logplaneSize == 0) {
293  ++curPACno;
294  curBegStripNo = curStripNo;
295  RPCStripsRing::iterator plus8 = it;
296  bool skipOccured = false;
297  for (int i = 0; i < 7; ++i) {
298  ++plus8;
299  if (plus8 == this->end()) {
300  plus8 = this->begin();
301  skipOccured = true;
302  }
303  }
304 
305  // calculate angle
306  float phi = it->first;
307  float phiP8 = plus8->first;
308  if (skipOccured) {
309  // phiP8 is negative
310  // phi is positive
311  // xcheck
312  if (phi * phiP8 > 0) {
313  throw cms::Exception("RPCInternal") << " RPCStripsRing::createRefConnections phi/phi8 error \n";
314  }
315  angle = (2 * pi + phiP8 + phi) / 2;
316  if (angle > pi) { // should land on positive side
317  angle -= 2 * pi;
318  }
319 
320  if (std::abs(angle) > pi) {
321  throw cms::Exception("RPCInternal") << " RPCStripsRing::createRefConnections "
322  << " problem with angle calc \n";
323  }
324  } else {
325  angle = (phiP8 + phi) / 2;
326  }
327  //std::cout << curPACno << " " << phiP8 << " " << phi << " " << angle << std::endl;
328 
329  TOtherConnStructVec::iterator itOt = otherRings.begin();
330  for (; itOt != otherRings.end(); ++itOt) {
331  itOt->m_it->second.createOtherConnections(
332  getTowerForRefRing(), curPACno, itOt->m_logplane, itOt->m_logplaneSize, angle);
333  }
334  }
335 
336  if (!it->second.isVirtual()) {
338  newCon.m_tower = getTowerForRefRing();
339  newCon.m_PAC = curPACno;
340  newCon.m_logplane = logplane;
341  newCon.m_logstrip = curStripNo - curBegStripNo;
342  //std::cout << " Adding con for " << it->second.m_detRawId << std::endl;
343  (*m_connectionsMap)[it->second.m_detRawId][it->second.m_strip].push_back(newCon);
344  //std::cout << " Adding ref connection " << std::endl;
345  }
346  ++curStripNo;
347  ++it;
348  if (it == this->end()) {
349  it = this->begin();
350  }
351 
352  } // iteration over strips ends
353 
354  //std::cout << " refcon: " << curPACno << " PACs" << std::endl;
355  //std::cout << "After refCon: " << m_connectionsMap.size() << std::endl;
356 }
357 
358 void RPCStripsRing::createOtherConnections(int tower, int PACno, int logplane, int logplaneSize, float angle) {
359  //std::cout << " OtherCon for " << getRingId() << std::endl;
360 
361  if (this->isReferenceRing()) {
362  throw cms::Exception("RPCInternal") << " RPCStripsRing::createOtherConnections "
363  << " called for reference ring \n";
364  }
365 
366  RPCStripsRing::const_iterator it = this->lower_bound(angle);
367 
368  if (it == this->end())
369  it = this->begin();
370 
371  for (int i = 0; i < logplaneSize / 2; i++) {
372  if (it == this->begin())
373  it = this->end(); // (m_stripPhiMap.end()--) is ok.
374 
375  --it;
376  }
377 
378  for (int i = 0; i < logplaneSize; i++) {
379  if (!it->second.isVirtual()) {
381  newCon.m_tower = tower;
382  newCon.m_PAC = PACno;
383  newCon.m_logplane = logplane;
384  newCon.m_logstrip = i;
385  (*m_connectionsMap)[it->second.m_detRawId][it->second.m_strip].push_back(newCon);
386  //std::cout << " Adding other connection " << std::endl;
387  }
388 
389  ++it;
390  if (it == this->end())
391  it = this->begin();
392  }
393 }
394 
395 // Defines to which tower this ring (only ref ring) belongs
397  int ret = 0;
398 
399  if (!this->isReferenceRing()) {
400  throw cms::Exception("RPCInternal") << " RPCStripsRing::getTowerForRefRing() "
401  << " called for non reference ring \n";
402  }
403 
404  int etaAbs = std::abs(getEtaPartition());
405  if (etaAbs < 8) {
406  ret = getEtaPartition();
407  } else if (etaAbs > 8) {
408  int sign = (getEtaPartition() > 0 ? 1 : -1);
409  ret = getEtaPartition() - sign;
410  } else {
411  throw cms::Exception("RPCInternal") << " RPCStripsRing::getTowerForRefRing() "
412  << " called for etaPartition 8 \n";
413  }
414 
415  return ret;
416 }
417 /*
418  struct TStripCon{
419  signed char m_tower;
420  unsigned char m_PAC;
421  unsigned char m_logplane;
422  unsigned char m_logstrip;
423  };
424  typedef std::vector<TStripCon> TStripConVec;
425  typedef std::map<unsigned char, TStripConVec> TStrip2ConVec;
426  typedef std::map<uint32_t, TStrip2ConVec> TConMap;
427 
428  // compressed connections
429  struct TCompressedCon{
430  signed char m_tower;
431  unsigned char m_PAC;
432  signed char m_offset;
433  signed char m_mul;
434  };
435  typedef std::vector<TCompressedCon> TCompressedConVec;
436  typedef std::map<uint32_t, TCompressedConVec> TCompressedConMap;
437 
438 */
439 
441  L1RPCConeBuilder::TConMap::iterator itChamber = m_connectionsMap->begin();
442 
443  auto uncompressedConsLeft = std::make_shared<L1RPCConeBuilder::TConMap>();
444 
445  m_compressedConnectionMap = std::make_shared<L1RPCConeBuilder::TCompressedConMap>();
446 
447  int compressedCons = 0, uncompressedConsBefore = 0, uncompressedConsAfter = 0;
448 
449  // int offsetMin =0, offsetMax =0;
450 
451  for (; itChamber != m_connectionsMap->end(); ++itChamber) {
452  uint32_t detId = itChamber->first;
453 
454  for (L1RPCConeBuilder::TStrip2ConVec::iterator itStrip = itChamber->second.begin();
455  itStrip != itChamber->second.end();
456  ++itStrip) {
457  // Iterate over strip Connections
458  for (L1RPCConeBuilder::TStripConVec::iterator itConn = itStrip->second.begin(); itConn != itStrip->second.end();
459  ++itConn) {
460  // Check if this connection isn't allready present in the compressed map
461  ++uncompressedConsBefore;
462  bool alreadyDone = false;
464  // iterate over the vec, check element by element
465  for (L1RPCConeBuilder::TCompressedConVec::iterator itCompConn = (*m_compressedConnectionMap)[detId].begin();
466  itCompConn != (*m_compressedConnectionMap)[detId].end();
467  ++itCompConn) {
468  if (itCompConn->m_tower == itConn->m_tower && itCompConn->m_PAC == itConn->m_PAC &&
469  itCompConn->m_logplane == itConn->m_logplane) // connection allready compressed
470  {
471  alreadyDone = true;
472 
473  int logStrip = itCompConn->m_mul * itStrip->first + itCompConn->m_offset;
474  if (logStrip != itConn->m_logstrip) {
475  //copy the problematic connection to the "safe" map
476  (*uncompressedConsLeft)[detId][itStrip->first].push_back(*itConn);
477  ++uncompressedConsAfter;
478  edm::LogWarning("RPCTriggerConfig")
479  << " Compression failed for det " << detId << " strip " << (int)itStrip->first << " . Got "
480  << (int)logStrip << " expected " << (int)itConn->m_logstrip << std::endl;
481  } else {
482  itCompConn->addStrip(itStrip->first);
483  }
484  }
485  } // compressed connection iteration end
486  }
487  //if (detId==637569977) std::cout << " Buld cons for strip " << (int)itStrip->first << std::endl;
488 
489  if (!alreadyDone) {
490  // find another strip contributing to the same PAC,tower,logplane
491  L1RPCConeBuilder::TStrip2ConVec::iterator itStripOther = itStrip;
492  ++itStripOther;
493  bool otherStripFound = false;
494  signed char mul = 1;
495  for (; itStripOther != itChamber->second.end() && !otherStripFound; ++itStripOther) {
496  for (L1RPCConeBuilder::TStripConVec::iterator itConnOther = itStripOther->second.begin();
497  itConnOther != itStripOther->second.end();
498  ++itConnOther) {
499  if (itConnOther->m_tower == itConn->m_tower && itConnOther->m_PAC == itConn->m_PAC &&
500  itConnOther->m_logplane == itConn->m_logplane) // connection to same PAC,logplane
501  {
502  otherStripFound = true;
503  if ((itStripOther->first - itStrip->first) * (itConnOther->m_logstrip - itConn->m_logstrip) < 0) {
504  mul = -1;
505  }
506  break;
507  }
508  } // otherConnections iter ends
509  } // otherStrip iter ends
510 
511  /*
512  if (itConn->m_tower==3 && itConn->m_PAC==73 && itConn->m_logplane==4 && detId==637569977){
513  std::cout << " Buld cons for strip " << (int)itStrip->first;
514  if (otherStripFound)
515  std::cout << " other strip " << itStrip->first;
516  else
517  std::cout << " no other strip ";
518 
519  std::cout << std::endl;
520 
521  }*/
522 
524  nCompConn.m_tower = itConn->m_tower;
525  nCompConn.m_PAC = itConn->m_PAC;
526  nCompConn.m_logplane = itConn->m_logplane;
527  nCompConn.m_mul = mul;
528  nCompConn.m_offset = itConn->m_logstrip - mul * (signed short)(itStrip->first);
529  nCompConn.addStrip(itStrip->first);
530 
531  if (otherStripFound) {
532  } else {
533  // uncompressedConsLeft[detId][itStrip->first].push_back(*itConn);
534  // ++uncompressedConsAfter;
535  }
536  (*m_compressedConnectionMap)[detId].push_back(nCompConn);
537  ++compressedCons;
538 
539  } // if(!allreadyDone)
540  } // iterate on connections
541  } // iterate on strips
542  } // iterate on chambers
543 
544  // 159 -87
545  //std::cout << offsetMax << " TT " << offsetMin << std::endl;
546 
547  edm::LogInfo("RPCTriggerConfig") << " Compressed: " << compressedCons << " "
549  << " Uncompressed before: " << uncompressedConsBefore << " "
550  << sizeof(L1RPCConeBuilder::TStripCon)
551  << " Uncompressed after: " << uncompressedConsAfter << " "
552  << sizeof(L1RPCConeBuilder::TStripCon);
553  m_connectionsMap = uncompressedConsLeft;
554 }
std::shared_ptr< L1RPCConeBuilder::TConMap > m_connectionsMap
Definition: RPCStripsRing.h:92
void compressConnections()
int getTowerForRefRing()
void fillWithVirtualStrips()
ret
prodAgent to be discontinued
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
void addStrip(unsigned char strip)
virtual int eta_partition()
Definition: RPCGeomServ.cc:230
const Double_t pi
void createOtherConnections(int tower, int PACno, int logplane, int logplanesize, float angle)
bool isReferenceRing()
Definition: RPCStripsRing.h:73
void filterOverlapingChambers()
std::vector< TOtherConnStruct > TOtherConnStructVec
Definition: RPCStripsRing.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:50
int getEtaPartition()
Definition: RPCStripsRing.h:72
Log< level::Info, false > LogInfo
bool m_isReferenceRing
Definition: RPCStripsRing.h:88
void addRoll(const RPCRoll *roll)
std::shared_ptr< L1RPCConeBuilder::TCompressedConMap > m_compressedConnectionMap
Definition: RPCStripsRing.h:93
static int calculateHwPlane(const RPCRoll *roll)
Calculate ringId for any given RPCRoll.
void createRefConnections(TOtherConnStructVec &otherRings, int logplane, int logplaneSize)
Log< level::Warning, false > LogWarning
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11