CMS 3D CMS Logo

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