Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "L1Trigger/RPCTrigger/interface/RPCStripsRing.h"
00019 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
00020 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00021 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023
00024 RPCStripsRing::RPCStripsRing() :
00025 m_hwPlane(-1),
00026 m_etaPartition(99),
00027 m_region(-2),
00028 m_isReferenceRing(false),
00029 m_didVirtuals(false),
00030 m_didFiltering(false)
00031 {
00032
00033 }
00034
00035 RPCStripsRing::RPCStripsRing(const RPCRoll * roll,
00036 boost::shared_ptr<L1RPCConeBuilder::TConMap > cmap) :
00037 m_didVirtuals(false),
00038 m_didFiltering(false),
00039 m_connectionsMap(cmap)
00040 {
00041
00042 RPCDetId detId = roll->id();
00043 RPCGeomServ grs(detId);
00044
00045 m_etaPartition = grs.eta_partition();
00046 m_hwPlane = calculateHwPlane(roll);
00047
00048 m_isReferenceRing = false;
00049
00050 m_region = detId.region();
00051
00052 int ring = detId.ring();
00053
00054 if (m_region == 0 && std::abs(ring)<2 && m_hwPlane == 2)
00055 m_isReferenceRing = true;
00056 else if (m_region == 0 && std::abs(ring)==2 && m_hwPlane == 6)
00057 m_isReferenceRing = true;
00058 else if (m_region != 0 && m_hwPlane == 2)
00059 m_isReferenceRing = true;
00060
00061
00062 if( getRingId() == 2008 || getRingId() == 2108)
00063 m_isReferenceRing = false;
00064
00065 addRoll(roll);
00066 }
00067
00068
00069 void RPCStripsRing::addRoll(const RPCRoll * roll){
00070
00071
00072
00073 if (getRingId() != getRingId(roll) ){
00074 throw cms::Exception("RPCInternal") << "RPCStripsRing::addRoll ringsIds dont match \n";
00075 }
00076
00077
00078 for (int i=1; i<=roll->nstrips(); i++ ) {
00079
00080 LocalPoint lStripCentre = roll->centreOfStrip(i);
00081 GlobalPoint gStripCentre = roll->toGlobal(lStripCentre);
00082 float phiRaw = gStripCentre.phi();
00083
00084 TStrip newStrip(roll->id().rawId(), i);
00085 (*this)[phiRaw] = newStrip;
00086
00087 }
00088
00089 }
00090
00091 int RPCStripsRing::getRingId(int etaPart, int hwPlane){
00092
00093 int sign = 1;
00094 if (etaPart < 0){
00095 sign = 0;
00096 }
00097
00098 return 1000*(hwPlane) +
00099 100*( sign ) +
00100 1*( std::abs(etaPart) );
00101
00102 }
00103
00104 int RPCStripsRing::getRingId(){
00105
00106 return getRingId(m_etaPartition, m_hwPlane);
00107
00108 }
00109
00110 int RPCStripsRing::getRingId(const RPCRoll * roll) {
00111
00112
00113 RPCDetId detId = roll->id();
00114 RPCGeomServ grs(detId);
00115 int etaPartition = grs.eta_partition();
00116 int hwPlane = calculateHwPlane(roll);
00117
00118 return getRingId(etaPartition, hwPlane);
00119
00120 }
00121
00122
00123
00124
00125 int RPCStripsRing::calculateHwPlane(const RPCRoll * roll){
00126
00127 int hwPlane = -1;
00128 RPCDetId detId = roll->id();
00129 int station = detId.station();
00130 int layer = detId.layer();
00131 int region = detId.region();
00132
00133 if (region != 0){
00134 hwPlane = station;
00135 }
00136
00137 else if ( station > 2 ){
00138 hwPlane = station;
00139 }
00140 else if ( station == 1 && layer == 1) {
00141 hwPlane = 1;
00142 }
00143 else if ( station == 1 && layer == 2) {
00144 hwPlane = 5;
00145 }
00146 else if ( station == 2 && layer == 1) {
00147 hwPlane = 2;
00148 }
00149 else if ( station == 2 && layer == 2) {
00150 hwPlane = 6;
00151 }
00152
00153
00154
00155
00156
00157
00158 if (hwPlane < 0) {
00159 throw cms::Exception("RPCInternal") << "Calculated negative hwplane \n";
00160 }
00161
00162
00163 return hwPlane;
00164
00165 }
00166
00167 void RPCStripsRing::filterOverlapingChambers(){
00168
00169 if(m_didFiltering) return;
00170 m_didFiltering = true;
00171
00172 if (m_region != 0 || m_hwPlane != 4)
00173 return;
00174
00175 typedef std::map<uint32_t,int> TDetId2StripNo;
00176 TDetId2StripNo det2stripNo;
00177
00178
00179 int ch1BegStrips = 0;
00180 int ch1EndStrips = 0;
00181
00182
00183 RPCStripsRing::iterator it = this->begin();
00184 uint32_t ch1Det = it->second.m_detRawId;
00185 for (; it!=this->end(); ++it){
00186
00187 if ( det2stripNo.find(it->second.m_detRawId) == det2stripNo.end()){
00188 det2stripNo[it->second.m_detRawId]=1;
00189 } else {
00190 ++det2stripNo[it->second.m_detRawId];
00191 }
00192
00193 if (det2stripNo.size() == 1 && ch1Det == it->second.m_detRawId) {
00194 ++ch1BegStrips;
00195 } else if (ch1Det == it->second.m_detRawId){
00196 ++ch1EndStrips;
00197 }
00198
00199 }
00200
00201 det2stripNo[ch1Det]-=ch1EndStrips;
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 it = this->begin();
00213 uint32_t lastDet = it->second.m_detRawId;
00214 while ( it!=this->end() ){
00215
00216 if (det2stripNo[it->second.m_detRawId] < 0) {
00217 throw cms::Exception("RPCInternal") << " RPCStripsRing::filterOverlapingChambers() - no strips left \n";
00218 }
00219 if ( it->second.m_detRawId == lastDet) {
00220 --det2stripNo[lastDet];
00221 ++it;
00222 } else if (det2stripNo[lastDet] == 0) {
00223
00224 if (lastDet == ch1Det) {
00225 det2stripNo[ch1Det]+=ch1EndStrips;
00226 }
00227
00228 lastDet = it->second.m_detRawId;
00229 --det2stripNo[lastDet];
00230 ++it;
00231 } else {
00232 --det2stripNo[it->second.m_detRawId];
00233 RPCStripsRing::iterator itErase = it;
00234 ++it;
00235
00236 this->erase(itErase);
00237 }
00238
00239 }
00240
00241
00242
00243 }
00244
00245 void RPCStripsRing::fillWithVirtualStrips()
00246 {
00247
00248
00249 if(m_didVirtuals) return;
00250 m_didVirtuals = true;
00251
00252 const float pi = 3.141592654;
00253 double dphi=2.0*pi/1152;
00254
00255 RPCStripsRing stripsToInsert;
00256
00257
00258 float delta = 0;
00259 int stripsToAdd = 0;
00260
00261
00262 RPCStripsRing::iterator it = this->begin();
00263 RPCStripsRing::iterator itLast = this->begin();
00264 for (; it!=this->end(); ++it){
00265
00266
00267
00268
00269
00270
00271 delta = it->first - itLast->first;
00272 if (it == itLast ||
00273 itLast->second.m_detRawId == it->second.m_detRawId ||
00274 delta < 0)
00275 {
00276 itLast = it;
00277 continue;
00278 }
00279
00280
00281 stripsToAdd = (int)std::floor(delta/dphi)-1;
00282
00283
00284 if ( isReferenceRing() && m_hwPlane==6) ++stripsToAdd;
00285
00286 for (int i = 0;i<stripsToAdd;++i){
00287
00288 stripsToInsert[itLast->first+dphi*(i+1)]=TStrip();
00289
00290 }
00291
00292 itLast = it;
00293 }
00294
00295
00296 this->insert(stripsToInsert.begin(),stripsToInsert.end());
00297
00298
00299
00300 }
00301 void RPCStripsRing::createRefConnections(TOtherConnStructVec & otherRings, int logplane, int logplaneSize)
00302 {
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 if(!this->isReferenceRing()){
00316 throw cms::Exception("RPCInternal") << " RPCStripsRing::createRefConnections "
00317 << " called for non-reference ring \n";
00318 }
00319
00320
00321
00322
00323
00324
00325
00326 const float pi = 3.141592654;
00327 const float offset = (5./360.)*2*pi;
00328
00329
00330 RPCStripsRing::iterator starEndIt = this->begin();
00331 while ( (++starEndIt)->first < offset );
00332
00333 RPCStripsRing::iterator it = starEndIt;
00334
00335
00336 float angle = 0;
00337 int curPACno = -1;
00338 int curStripNo = 0;
00339 int curBegStripNo=0;
00340
00341 bool firstIter = true;
00342
00343 while(it!=starEndIt || firstIter ) {
00344
00345
00346 firstIter = false;
00347
00348 if(curStripNo%logplaneSize==0){
00349 ++curPACno;
00350 curBegStripNo=curStripNo;
00351 RPCStripsRing::iterator plus8 = it;
00352 bool skipOccured = false;
00353 for (int i=0;i<7;++i){
00354 ++plus8;
00355 if (plus8==this->end()){
00356 plus8=this->begin();
00357 skipOccured = true;
00358 }
00359 }
00360
00361
00362 float phi= it->first;
00363 float phiP8= plus8->first;
00364 if (skipOccured){
00365
00366
00367
00368 if (phi*phiP8 > 0){
00369 throw cms::Exception("RPCInternal") << " RPCStripsRing::createRefConnections phi/phi8 error \n";
00370 }
00371 angle = (2*pi+phiP8+phi)/2;
00372 if(angle > pi){
00373 angle -= 2*pi;
00374 }
00375
00376 if (std::abs(angle) > pi) {
00377 throw cms::Exception("RPCInternal") << " RPCStripsRing::createRefConnections "
00378 << " problem with angle calc \n";
00379 }
00380 }
00381 else {
00382 angle = (phiP8+phi)/2;
00383 }
00384
00385
00386
00387 TOtherConnStructVec::iterator itOt = otherRings.begin();
00388 for (;itOt!=otherRings.end();++itOt){
00389 itOt->m_it->second.createOtherConnections(getTowerForRefRing(),
00390 curPACno,
00391 itOt->m_logplane,
00392 itOt->m_logplaneSize,
00393 angle);
00394 }
00395 }
00396
00397
00398 if ( !it->second.isVirtual() ){
00399 L1RPCConeBuilder::TStripCon newCon;
00400 newCon.m_tower = getTowerForRefRing();
00401 newCon.m_PAC = curPACno;
00402 newCon.m_logplane = logplane;
00403 newCon.m_logstrip=curStripNo-curBegStripNo;
00404
00405 (*m_connectionsMap)[it->second.m_detRawId][it->second.m_strip].push_back(newCon);
00406
00407 }
00408 ++curStripNo;
00409 ++it;
00410 if (it==this->end()){
00411 it=this->begin();
00412 }
00413
00414 }
00415
00416
00417
00418
00419 }
00420
00421 void RPCStripsRing::createOtherConnections(int tower, int PACno, int logplane, int logplaneSize, float angle) {
00422
00423
00424
00425 if(this->isReferenceRing()){
00426 throw cms::Exception("RPCInternal") << " RPCStripsRing::createOtherConnections "
00427 << " called for reference ring \n";
00428 }
00429
00430
00431 RPCStripsRing::const_iterator it = this->lower_bound(angle);
00432
00433
00434 if (it == this->end())
00435 it = this->begin();
00436
00437 for (int i=0; i < logplaneSize/2; i++){
00438
00439 if (it==this->begin())
00440 it=this->end();
00441
00442 --it;
00443 }
00444
00445
00446 for (int i=0; i < logplaneSize; i++){
00447
00448 if (! it->second.isVirtual() ){
00449 L1RPCConeBuilder::TStripCon newCon;
00450 newCon.m_tower = tower;
00451 newCon.m_PAC = PACno;
00452 newCon.m_logplane = logplane;
00453 newCon.m_logstrip= i;
00454 (*m_connectionsMap)[it->second.m_detRawId][it->second.m_strip].push_back(newCon);
00455
00456 }
00457
00458 ++it;
00459 if (it==this->end())
00460 it=this->begin();
00461 }
00462
00463 }
00464
00465
00466 int RPCStripsRing::getTowerForRefRing(){
00467
00468 int ret = 0;
00469
00470 if(!this->isReferenceRing()){
00471 throw cms::Exception("RPCInternal") << " RPCStripsRing::getTowerForRefRing() "
00472 << " called for non reference ring \n";
00473 }
00474
00475 int etaAbs = std::abs(getEtaPartition());
00476 if (etaAbs < 8) {
00477 ret = getEtaPartition();
00478 } else if (etaAbs > 8) {
00479 int sign = (getEtaPartition() > 0 ? 1 : -1);
00480 ret = getEtaPartition()-sign;
00481 } else {
00482 throw cms::Exception("RPCInternal") << " RPCStripsRing::getTowerForRefRing() "
00483 << " called for etaPartition 8 \n";
00484 }
00485
00486
00487
00488 return ret;
00489
00490 }
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515 void RPCStripsRing::compressConnections(){
00516
00517
00518 L1RPCConeBuilder::TConMap::iterator itChamber = m_connectionsMap->begin();
00519
00520 boost::shared_ptr<L1RPCConeBuilder::TConMap > uncompressedConsLeft
00521 = boost::shared_ptr<L1RPCConeBuilder::TConMap >(new L1RPCConeBuilder::TConMap());
00522
00523 m_compressedConnectionMap =
00524 boost::shared_ptr<L1RPCConeBuilder::TCompressedConMap >
00525 (new L1RPCConeBuilder::TCompressedConMap());
00526
00527
00528 int compressedCons = 0, uncompressedConsBefore = 0, uncompressedConsAfter = 0;
00529
00530
00531
00532 for( ;itChamber!=m_connectionsMap->end(); ++itChamber ){
00533
00534 uint32_t detId = itChamber->first;
00535
00536 for (L1RPCConeBuilder::TStrip2ConVec::iterator itStrip = itChamber->second.begin();
00537 itStrip!=itChamber->second.end();
00538 ++itStrip)
00539 {
00540
00541
00542 for(L1RPCConeBuilder::TStripConVec::iterator itConn = itStrip->second.begin();
00543 itConn!=itStrip->second.end();
00544 ++itConn)
00545 {
00546
00547 ++uncompressedConsBefore;
00548 bool alreadyDone=false;
00549 if (m_compressedConnectionMap->find(detId)!=m_compressedConnectionMap->end()){
00550
00551
00552 for(L1RPCConeBuilder::TCompressedConVec::iterator itCompConn=(*m_compressedConnectionMap)[detId].begin();
00553 itCompConn!=(*m_compressedConnectionMap)[detId].end();
00554 ++itCompConn)
00555 {
00556 if (itCompConn->m_tower == itConn->m_tower
00557 && itCompConn->m_PAC == itConn->m_PAC
00558 && itCompConn->m_logplane == itConn->m_logplane)
00559 {
00560 alreadyDone=true;
00561
00562 int logStrip = itCompConn->m_mul*itStrip->first+itCompConn->m_offset;
00563 if (logStrip != itConn->m_logstrip){
00564
00565 (*uncompressedConsLeft)[detId][itStrip->first].push_back(*itConn);
00566 ++uncompressedConsAfter;
00567 edm::LogWarning("RPCTriggerConfig") << " Compression failed for det " << detId
00568 << " strip " << (int)itStrip->first
00569 << " . Got " << (int)logStrip
00570 << " expected " << (int)itConn->m_logstrip
00571 << std::endl;
00572 } else {
00573 itCompConn->addStrip(itStrip->first);
00574 }
00575
00576 }
00577 }
00578 }
00579
00580
00581
00582 if (!alreadyDone){
00583
00584 L1RPCConeBuilder::TStrip2ConVec::iterator itStripOther = itStrip;
00585 ++itStripOther;
00586 bool otherStripFound = false;
00587 signed char mul = 1;
00588 for (;itStripOther!=itChamber->second.end() && !otherStripFound;
00589 ++itStripOther)
00590 {
00591 for(L1RPCConeBuilder::TStripConVec::iterator itConnOther = itStripOther->second.begin();
00592 itConnOther!=itStripOther->second.end();
00593 ++itConnOther)
00594 {
00595 if (itConnOther->m_tower == itConn->m_tower
00596 && itConnOther->m_PAC == itConn->m_PAC
00597 && itConnOther->m_logplane == itConn->m_logplane)
00598 {
00599 otherStripFound = true;
00600 if ( (itStripOther->first-itStrip->first)*(itConnOther->m_logstrip-itConn->m_logstrip) < 0 ){
00601 mul = -1;
00602 }
00603 break;
00604 }
00605 }
00606 }
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620 L1RPCConeBuilder::TCompressedCon nCompConn;
00621 nCompConn.m_tower = itConn->m_tower;
00622 nCompConn.m_PAC = itConn->m_PAC;
00623 nCompConn.m_logplane = itConn->m_logplane;
00624 nCompConn.m_mul = mul;
00625 nCompConn.m_offset = itConn->m_logstrip - mul*(signed short)(itStrip->first);
00626 nCompConn.addStrip(itStrip->first);
00627
00628 if (otherStripFound){
00629
00630 } else {
00631
00632
00633
00634 }
00635 (*m_compressedConnectionMap)[detId].push_back(nCompConn);
00636 ++compressedCons;
00637
00638
00639 }
00640 }
00641 }
00642 }
00643
00644
00645
00646
00647 edm::LogInfo("RPCTriggerConfig")
00648 << " Compressed: " << compressedCons<< " " << sizeof(L1RPCConeBuilder::TCompressedCon)
00649 << " Uncompressed before: " << uncompressedConsBefore<< " " << sizeof(L1RPCConeBuilder::TStripCon)
00650 << " Uncompressed after: " << uncompressedConsAfter << " " << sizeof(L1RPCConeBuilder::TStripCon);
00651 m_connectionsMap = uncompressedConsLeft;
00652
00653 }
00654