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