00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "L1TriggerConfig/RPCTriggerConfig/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
00023 L1RPCConeBuilder::TConMap RPCStripsRing::m_connectionsMap = L1RPCConeBuilder::TConMap();
00024
00025 RPCStripsRing::RPCStripsRing() :
00026 m_hwPlane(-1),
00027 m_etaPartition(99),
00028 m_region(-2),
00029 m_isReferenceRing(false),
00030 m_didVirtuals(false),
00031 m_didFiltering(false)
00032 {
00033
00034 }
00035
00036 RPCStripsRing::RPCStripsRing(const RPCRoll * roll) :
00037 m_didVirtuals(false),
00038 m_didFiltering(false)
00039 {
00040
00041 RPCDetId detId = roll->id();
00042 RPCGeomServ grs(detId);
00043
00044 m_etaPartition = grs.eta_partition();
00045 m_hwPlane = calculateHwPlane(roll);
00046
00047 m_isReferenceRing = false;
00048
00049 m_region = detId.region();
00050
00051 int ring = detId.ring();
00052
00053 if (m_region == 0 && std::abs(ring)<2 && m_hwPlane == 2)
00054 m_isReferenceRing = true;
00055 else if (m_region == 0 && std::abs(ring)==2 && m_hwPlane == 6)
00056 m_isReferenceRing = true;
00057 else if (m_region != 0 && m_hwPlane == 2)
00058 m_isReferenceRing = true;
00059
00060
00061 if( getRingId() == 2008 || getRingId() == 2108)
00062 m_isReferenceRing = false;
00063
00064 addRoll(roll);
00065 }
00066
00067
00068 void RPCStripsRing::addRoll(const RPCRoll * roll){
00069
00070
00071
00072 if (getRingId() != getRingId(roll) ){
00073 throw cms::Exception("RPCInternal") << "RPCStripsRing::addRoll ringsIds dont match \n";
00074 }
00075
00076
00077 for (int i=1; i<=roll->nstrips(); i++ ) {
00078
00079 LocalPoint lStripCentre = roll->centreOfStrip(i);
00080 GlobalPoint gStripCentre = roll->toGlobal(lStripCentre);
00081 float phiRaw = gStripCentre.phi();
00082
00083 TStrip newStrip(roll->id().rawId(), i);
00084 (*this)[phiRaw] = newStrip;
00085
00086 }
00087
00088 }
00089
00090 int RPCStripsRing::getRingId(int etaPart, int hwPlane){
00091
00092 int sign = 1;
00093 if (etaPart < 0){
00094 sign = 0;
00095 }
00096
00097 return 1000*(hwPlane) +
00098 100*( sign ) +
00099 1*( std::abs(etaPart) );
00100
00101 }
00102
00103 int RPCStripsRing::getRingId(){
00104
00105 return getRingId(m_etaPartition, m_hwPlane);
00106
00107 }
00108
00109 int RPCStripsRing::getRingId(const RPCRoll * roll) {
00110
00111
00112 RPCDetId detId = roll->id();
00113 RPCGeomServ grs(detId);
00114 int etaPartition = grs.eta_partition();
00115 int hwPlane = calculateHwPlane(roll);
00116
00117 return getRingId(etaPartition, hwPlane);
00118
00119 }
00120
00121
00122
00123 int RPCStripsRing::calculateHwPlane(const RPCRoll * roll){
00124
00125 int hwPlane = -1;
00126 RPCDetId detId = roll->id();
00127 int station = detId.station();
00128 int layer = detId.layer();
00129 int region = detId.region();
00130
00131 if (region != 0){
00132 hwPlane = station;
00133 }
00134
00135 else if ( station > 2 ){
00136 hwPlane = station;
00137 }
00138 else if ( station == 1 && layer == 1) {
00139 hwPlane = 1;
00140 }
00141 else if ( station == 1 && layer == 2) {
00142 hwPlane = 5;
00143 }
00144 else if ( station == 2 && layer == 1) {
00145 hwPlane = 2;
00146 }
00147 else if ( station == 2 && layer == 2) {
00148 hwPlane = 6;
00149 }
00150
00151
00152
00153
00154
00155
00156 if (hwPlane < 0) {
00157 throw cms::Exception("RPCInternal") << "Calculated negative hwplane \n";
00158 }
00159
00160
00161 return hwPlane;
00162
00163 }
00164
00165 void RPCStripsRing::filterOverlapingChambers(){
00166
00167 if(m_didFiltering) return;
00168 m_didFiltering = true;
00169
00170 if (m_region != 0 || m_hwPlane != 4)
00171 return;
00172
00173 typedef std::map<uint32_t,int> TDetId2StripNo;
00174 TDetId2StripNo det2stripNo;
00175
00176
00177
00178
00179
00180
00181 int ch1BegStrips = 0;
00182 int ch1EndStrips = 0;
00183
00184
00185 RPCStripsRing::iterator it = this->begin();
00186 uint32_t ch1Det = it->second.m_detRawId;
00187 for (; it!=this->end(); ++it){
00188
00189 if ( det2stripNo.find(it->second.m_detRawId) == det2stripNo.end()){
00190 det2stripNo[it->second.m_detRawId]=1;
00191
00192 } else {
00193 ++det2stripNo[it->second.m_detRawId];
00194 }
00195
00196 if (det2stripNo.size() == 1 && ch1Det == it->second.m_detRawId) {
00197 ++ch1BegStrips;
00198 } else if (ch1Det == it->second.m_detRawId){
00199 ++ch1EndStrips;
00200 }
00201
00202 }
00203
00204 det2stripNo[ch1Det]-=ch1EndStrips;
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 it = this->begin();
00216 uint32_t lastDet = it->second.m_detRawId;
00217 while ( it!=this->end() ){
00218
00219 if (det2stripNo[it->second.m_detRawId] < 0) {
00220 throw cms::Exception("RPCInternal") << " RPCStripsRing::filterOverlapingChambers() - no strips left \n";
00221 }
00222 if ( it->second.m_detRawId == lastDet) {
00223 --det2stripNo[lastDet];
00224 ++it;
00225 } else if (det2stripNo[lastDet] == 0) {
00226
00227 if (lastDet == ch1Det) {
00228 det2stripNo[ch1Det]+=ch1EndStrips;
00229 }
00230
00231 lastDet = it->second.m_detRawId;
00232 --det2stripNo[lastDet];
00233 ++it;
00234 } else {
00235 --det2stripNo[it->second.m_detRawId];
00236 RPCStripsRing::iterator itErase = it;
00237 ++it;
00238
00239 this->erase(itErase);
00240 }
00241
00242 }
00243
00244
00245
00246 }
00247
00248 void RPCStripsRing::fillWithVirtualStrips()
00249 {
00250
00251
00252 if(m_didVirtuals) return;
00253 m_didVirtuals = true;
00254
00255 const float pi = 3.141592654;
00256 double dphi=2.0*pi/1152;
00257
00258 RPCStripsRing stripsToInsert;
00259
00260
00261 float delta = 0;
00262 int stripsToAdd = 0;
00263
00264
00265 RPCStripsRing::iterator it = this->begin();
00266 RPCStripsRing::iterator itLast = this->begin();
00267 for (; it!=this->end(); ++it){
00268
00269
00270
00271
00272
00273
00274 delta = it->first - itLast->first;
00275 if (it == itLast ||
00276 itLast->second.m_detRawId == it->second.m_detRawId ||
00277 delta < 0)
00278 {
00279 itLast = it;
00280 continue;
00281 }
00282
00283
00284 stripsToAdd = (int)std::floor(delta/dphi)-1;
00285
00286
00287 if ( isReferenceRing() && m_hwPlane==6) ++stripsToAdd;
00288
00289 for (int i = 0;i<stripsToAdd;++i){
00290
00291 stripsToInsert[itLast->first+dphi*(i+1)]=TStrip();
00292
00293 }
00294
00295 itLast = it;
00296 }
00297
00298
00299 this->insert(stripsToInsert.begin(),stripsToInsert.end());
00300
00301
00302
00303 }
00304 void RPCStripsRing::createRefConnections(TOtherConnStructVec & otherRings, int logplane, int logplaneSize)
00305 {
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 if(!this->isReferenceRing()){
00319 throw cms::Exception("RPCInternal") << " RPCStripsRing::createRefConnections "
00320 << " called for non-reference ring \n";
00321 }
00322
00323 if (logplaneSize!=8) {
00324 throw cms::Exception("RPCInternal") << " RPCStripsRing::createRefConnections "
00325 << " called for lpSize " << logplaneSize << " \n";
00326
00327 }
00328 const float pi = 3.141592654;
00329 const float offset = (5./360.)*2*pi;
00330
00331
00332 RPCStripsRing::iterator starEndIt = this->begin();
00333 while ( (++starEndIt)->first < offset );
00334
00335 RPCStripsRing::iterator it = starEndIt;
00336 --starEndIt;
00337
00338 float angle = 0;
00339 int curPACno = -1;
00340 int curStripNo = 0;
00341 int curBegStripNo=0;
00342
00343 while(it!=starEndIt) {
00344
00345
00346 if(curStripNo%logplaneSize==0){
00347 ++curPACno;
00348 curBegStripNo=curStripNo;
00349 RPCStripsRing::iterator plus8 = it;
00350 bool skipOccured = false;
00351 for (int i=0;i<7;++i){
00352 ++plus8;
00353 if (plus8==this->end()){
00354 plus8=this->begin();
00355 skipOccured = true;
00356 }
00357 }
00358
00359
00360 float phi= it->first;
00361 float phiP8= plus8->first;
00362 if (skipOccured){
00363
00364
00365
00366 if (phi*phiP8 > 0){
00367 throw cms::Exception("RPCInternal") << " RPCStripsRing::createRefConnections phi/phi8 error \n";
00368 }
00369 angle = (2*pi+phiP8+phi)/2;
00370 if(angle > pi){
00371 angle -= 2*pi;
00372 }
00373
00374 if (std::abs(angle) > pi) {
00375 throw cms::Exception("RPCInternal") << " RPCStripsRing::createRefConnections "
00376 << " problem with angle calc \n";
00377 }
00378 }
00379 else {
00380 angle = (phiP8+phi)/2;
00381 }
00382
00383
00384
00385 TOtherConnStructVec::iterator itOt = otherRings.begin();
00386 for (;itOt!=otherRings.end();++itOt){
00387 itOt->m_it->second.createOtherConnections(getTowerForRefRing(),
00388 curPACno,
00389 itOt->m_logplane,
00390 itOt->m_logplaneSize,
00391 angle);
00392 }
00393 }
00394
00395
00396 if ( !it->second.isVirtual() ){
00397 L1RPCConeBuilder::TStripCon newCon;
00398 newCon.m_tower = getTowerForRefRing();
00399 newCon.m_PAC = curPACno;
00400 newCon.m_logplane = logplane;
00401 newCon.m_logstrip=curStripNo-curBegStripNo;
00402
00403 m_connectionsMap[it->second.m_detRawId][it->second.m_strip].push_back(newCon);
00404
00405 }
00406 ++curStripNo;
00407 ++it;
00408 if (it==this->end()){
00409 it=this->begin();
00410 }
00411
00412 }
00413
00414
00415
00416
00417 }
00418
00419 void RPCStripsRing::createOtherConnections(int tower, int PACno, int logplane, int logplaneSize, float angle) {
00420
00421
00422
00423 if(this->isReferenceRing()){
00424 throw cms::Exception("RPCInternal") << " RPCStripsRing::createOtherConnections "
00425 << " called for reference ring \n";
00426 }
00427
00428
00429 RPCStripsRing::const_iterator it = this->lower_bound(angle);
00430
00431
00432 if (it == this->end())
00433 it = this->begin();
00434
00435 for (int i=0; i < logplaneSize/2; i++){
00436
00437 if (it==this->begin())
00438 it=this->end();
00439
00440 --it;
00441 }
00442
00443
00444 for (int i=0; i < logplaneSize; i++){
00445
00446 if (! it->second.isVirtual() ){
00447 L1RPCConeBuilder::TStripCon newCon;
00448 newCon.m_tower = tower;
00449 newCon.m_PAC = PACno;
00450 newCon.m_logplane = logplane;
00451 newCon.m_logstrip= i;
00452 m_connectionsMap[it->second.m_detRawId][it->second.m_strip].push_back(newCon);
00453
00454 }
00455
00456 ++it;
00457 if (it==this->end())
00458 it=this->begin();
00459 }
00460
00461 }
00462
00463
00464 int RPCStripsRing::getTowerForRefRing(){
00465
00466 int ret = 0;
00467
00468 if(!this->isReferenceRing()){
00469 throw cms::Exception("RPCInternal") << " RPCStripsRing::getTowerForRefRing() "
00470 << " called for non reference ring \n";
00471 }
00472
00473 int etaAbs = std::abs(getEtaPartition());
00474 if (etaAbs < 8) {
00475 ret = getEtaPartition();
00476 } else if (etaAbs > 8) {
00477 int sign = (getEtaPartition() > 0 ? 1 : -1);
00478 ret = getEtaPartition()-sign;
00479 } else {
00480 throw cms::Exception("RPCInternal") << " RPCStripsRing::getTowerForRefRing() "
00481 << " called for etaPartition 8 \n";
00482 }
00483
00484
00485
00486 return ret;
00487
00488 }
00489
00490
00491