00001 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00002 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00003 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00004 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00005 #include "DataFormats/DetId/interface/DetId.h"
00006
00007 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
00008 #include "DataFormats/EcalDetId/interface/EcalTriggerElectronicsId.h"
00009
00010 #include "FWCore/Utilities/interface/Exception.h"
00011
00012
00013 using boost::multi_index_container;
00014 using namespace boost::multi_index;
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 EcalElectronicsMapping::EcalElectronicsMapping() {
00037
00038
00039
00040
00041 int ilm = MIN_LM_EBM;
00042 for (int dcc=MIN_DCCID_EBM; dcc <= MAX_DCCID_EBM; dcc++) {
00043 LaserMonitoringMap_EB[dcc] = ilm;
00044 ilm += 2;
00045 }
00046 ilm = MIN_LM_EBP;
00047 for (int dcc=MIN_DCCID_EBP; dcc <= MAX_DCCID_EBP; dcc++) {
00048 LaserMonitoringMap_EB[dcc] = ilm;
00049 ilm += 2;
00050 }
00051
00052
00053
00054
00055 ilm = MIN_LM_EEM;
00056 for (int dcc=MIN_DCCID_EEM; dcc <= MAX_DCCID_EEM; dcc++) {
00057 LaserMonitoringMap_EE[dcc] = ilm;
00058 ilm += 1;
00059 if (dcc == 8) ilm += 1;
00060 }
00061 ilm = MIN_LM_EEP;
00062 for (int dcc=MIN_DCCID_EEP; dcc <= MAX_DCCID_EEP; dcc++) {
00063 LaserMonitoringMap_EE[dcc] = ilm;
00064 ilm += 1;
00065 if (dcc == 53) ilm += 1;
00066 }
00067
00068 }
00069
00070
00071 int EcalElectronicsMapping::DCCid(const EBDetId& id) const
00072
00073
00074
00075
00076
00077 {
00078 int dcc = id.ism();
00079 if (id.zside() < 0) {
00080 dcc += DCCID_PHI0_EBM - 19;
00081 }
00082 else {
00083 dcc += DCCID_PHI0_EBP -1;
00084 }
00085 return dcc;
00086 }
00087
00088
00089 int EcalElectronicsMapping::TCCid(const EBDetId& id) const
00090
00091
00092
00093
00094
00095 {
00096 int tcc = id.ism();
00097 if (id.zside() < 0) {
00098 tcc += TCCID_PHI0_EBM - 19;
00099 }
00100 else {
00101 tcc += TCCID_PHI0_EBP -1;
00102 }
00103 return tcc;
00104 }
00105
00106
00107
00108 int EcalElectronicsMapping::iTT(const EcalTrigTowerDetId& id) const
00109
00110
00111
00112
00113
00114 {
00115 if ( id.subDet() == EcalBarrel )
00116 {
00117 int ie = id.ietaAbs() -1;
00118 int ip;
00119 int phi = id.iphi();
00120 phi += 2;
00121 if (phi > 72) phi = phi-72;
00122 if (id.zside() < 0) {
00123 ip = (( phi -1 ) % kEBTowersInPhi ) + 1;
00124 } else {
00125 ip = kEBTowersInPhi - ((phi -1 ) % kEBTowersInPhi );
00126 }
00127
00128 return (ie * kEBTowersInPhi) + ip;
00129 }
00130 else if ( id.subDet() == EcalEndcap) {
00131 int ie = id.ietaAbs();
00132 bool inner = (ie >= iEEEtaMinInner);
00133 if (inner) {
00134 ie = ie - iEEEtaMinInner;
00135 ie = ie % kEETowersInEtaPerInnerTCC;
00136 }
00137 else {
00138 ie = ie - iEEEtaMinOuter;
00139 ie = ie % kEETowersInEtaPerOuterTCC;
00140 }
00141
00142 int ip = id.iphi();
00143 ip = (ip + 1) % (kEETowersInPhiPerQuadrant*4);
00144
00145
00146 ip = ip % kEETowersInPhiPerTCC;
00147 int itt = kEETowersInPhiPerTCC * ie + ip + 1;
00148 return itt;
00149 }
00150 else {
00151 throw cms::Exception("InvalidDetId") << " Wrong EcalTrigTowerDetId in EcalElectronicsMapping::iTT. " ;
00152 return 0;
00153 }
00154
00155 }
00156
00157
00158 int EcalElectronicsMapping::TCCid(const EcalTrigTowerDetId& id) const {
00159
00160 if ( id.subDet() == EcalBarrel )
00161 {
00162 int phi = id.iphi() +2;
00163 if (phi > 72) phi = phi-72;
00164 int tcc = ( phi - 1 ) / kEBTowersInPhi + 1;
00165 if ( id.zside() < 0 ) tcc += 18;
00166 if (id.zside() < 0) {
00167 tcc += TCCID_PHI0_EBM - 19;
00168 }
00169 else {
00170 tcc += TCCID_PHI0_EBP -1;
00171 }
00172 return tcc;
00173 }
00174
00175 else if ( id.subDet() == EcalEndcap )
00176 {
00177 int ie = id.ietaAbs();
00178 bool inner = (ie >= iEEEtaMinInner);
00179 int ip = id.iphi();
00180 ip = (ip + 1) % (kEETowersInPhiPerQuadrant*4);
00181
00182
00183 int Phiindex = ip / 4;
00184 if (inner) {
00185 if (id.ieta()> 0) Phiindex += TCCID_PHI0_EEP_IN;
00186 else Phiindex += TCCID_PHI0_EEM_IN;
00187 }
00188 else {
00189 if (id.ieta() > 0) Phiindex += TCCID_PHI0_EEP_OUT;
00190 else Phiindex += TCCID_PHI0_EEM_OUT;
00191 }
00192 return Phiindex;
00193 }
00194 else {
00195 throw cms::Exception("InvalidDetId") << " Wrong EcalTrigTowerDetId in EcalElectronicsMapping::TCCid.";
00196 return 0;
00197 }
00198 }
00199
00200
00201
00202 int EcalElectronicsMapping::DCCid(const EcalTrigTowerDetId& id) const {
00203
00204
00205
00206
00207 if ( id.subDet() == EcalBarrel )
00208 {
00209 int phi = id.iphi() +2;
00210 if (phi > 72) phi = phi-72;
00211 int dcc = ( phi - 1 ) / kEBTowersInPhi + 1;
00212 if ( id.zside() < 0 ) dcc += 18;
00213 if (id.zside() < 0) {
00214 dcc += DCCID_PHI0_EBM - 19;
00215 }
00216 else {
00217 dcc += DCCID_PHI0_EBP -1;
00218 }
00219 return dcc;
00220 }
00221 else if ( id.subDet() == EcalEndcap)
00222 {
00223 int tccid = TCCid(id);
00224 int dcc=0;
00225 int offset = 0;
00226 if (tccid >= 73) {
00227 tccid = tccid-72;
00228 offset = 45;
00229 }
00230 if (tccid == 24 || tccid == 25 || tccid == 6 || tccid == 7) dcc=4;
00231 if (tccid == 26 || tccid == 27 || tccid == 8 || tccid == 9) dcc=5;
00232 if (tccid == 28 || tccid == 29 || tccid == 10 || tccid == 11) dcc=6;
00233 if (tccid == 30 || tccid == 31 || tccid == 12 || tccid == 13) dcc=7;
00234 if (tccid == 32 || tccid == 33 || tccid == 14 || tccid == 15) dcc=8;
00235 if (tccid == 34 || tccid == 35 || tccid == 16 || tccid == 17) dcc=9;
00236 if (tccid == 36 || tccid == 19 || tccid == 18 || tccid == 1) dcc=1;
00237 if (tccid == 20 || tccid == 21 || tccid == 2 || tccid == 3) dcc=2;
00238 if (tccid == 22 || tccid == 23 || tccid == 4 || tccid == 5) dcc=3;
00239 dcc += offset;
00240 return dcc;
00241 }
00242 else {
00243 throw cms::Exception("InvalidDetId") << " Wrong EcalTrigTowerDetId in EcalElectronicsMapping::DCCid.";
00244 return 0;
00245 }
00246
00247 }
00248
00249 EcalTrigTowerDetId EcalElectronicsMapping::getTrigTowerDetId(int TCCid, int iTT) const {
00250
00251
00252
00253 EcalSubdetector sub = subdet(TCCid, TCCMODE);
00254 int zIndex = zside(TCCid, TCCMODE);
00255
00256 if (sub == EcalBarrel) {
00257
00258 int DCCid =0;
00259 int jtower = iTT-1;
00260 if (zIndex > 0) DCCid = TCCid - TCCID_PHI0_EBP + DCCID_PHI0_EBP;
00261 else DCCid = TCCid - TCCID_PHI0_EBM + DCCID_PHI0_EBM;
00262 int SMid = (zIndex > 0) ? DCCid - 27 : DCCid + 9;
00263
00264 int etaTT = jtower / kTowersInPhi +1;
00265 int phiTT;
00266
00267 if (zIndex > 0)
00268 phiTT=(SMid - 1) * kTowersInPhi + (kTowersInPhi -(jtower % kTowersInPhi)) -1;
00269 else
00270 phiTT=(SMid - 19)* kTowersInPhi + jtower % kTowersInPhi;
00271 phiTT ++;
00272 phiTT = phiTT -2;
00273 if (phiTT <= 0) phiTT = 72+phiTT;
00274 EcalTrigTowerDetId tdetid(zIndex, EcalBarrel, etaTT, phiTT,EcalTrigTowerDetId::SUBDETIJMODE);
00275 return tdetid;
00276 }
00277
00278 else if (sub == EcalEndcap) {
00279
00280 bool EEminus = (zIndex <0);
00281 bool EEplus = (zIndex >0);
00282 if ( (!EEminus) && (!EEplus) )
00283 throw cms::Exception("InvalidDetId") <<
00284 "EcalElectronicsMapping: Cannot create EcalTrigTowerDetId object. " ;
00285 int iz = 0;
00286 int tcc = TCCid;
00287 if (tcc <= TCCID_PHI0_EEM_OUT+kTCCinPhi) iz = -1;
00288 else if (tcc >= TCCID_PHI0_EEP_OUT) iz = +1;
00289
00290 bool inner = false;
00291 if (iz < 0 && tcc >= TCCID_PHI0_EEM_IN && tcc <= TCCID_PHI0_EEM_IN+kTCCinPhi) inner=true;
00292 if (iz > 0 && tcc >= TCCID_PHI0_EEP_IN && tcc <= TCCID_PHI0_EEP_IN+kTCCinPhi) inner=true;
00293 bool outer = !inner;
00294
00295 int ieta = iTT / kEETowersInPhiPerTCC;
00296 int iphi = (iTT-1) % kEETowersInPhiPerTCC;
00297 if (inner) ieta += iEEEtaMinInner;
00298 else ieta += iEEEtaMinOuter;
00299 if (iz < 0) ieta = -ieta;
00300
00301 int TCC_origin = 0;
00302 if (inner && iz < 0) TCC_origin=TCCID_PHI0_EEM_IN;
00303 if (outer && iz < 0) TCC_origin=TCCID_PHI0_EEM_OUT;
00304 if (inner && iz > 0) TCC_origin=TCCID_PHI0_EEP_IN;
00305 if (outer && iz > 0) TCC_origin=TCCID_PHI0_EEP_OUT;
00306 tcc = tcc - TCC_origin;
00307
00308 iphi += kEETowersInPhiPerTCC * tcc;
00309 iphi = (iphi -2 + 4*kEETowersInPhiPerQuadrant) % (4*kEETowersInPhiPerQuadrant) + 1;
00310
00311 int tower_i = abs(ieta);
00312 int tower_j = iphi;
00313 EcalTrigTowerDetId tdetid(zIndex, EcalEndcap, tower_i, tower_j,EcalTrigTowerDetId::SUBDETIJMODE);
00314 return tdetid;
00315
00316 }
00317 else {
00318 throw cms::Exception("InvalidDetId") <<
00319 " Wrong indices in EcalElectronicsMapping::getTrigTowerDetId. TCCid = " << TCCid << " iTT = " << iTT << ".";
00320 }
00321
00322
00323 }
00324
00325
00326
00327
00328
00329 EcalElectronicsId EcalElectronicsMapping::getElectronicsId(const DetId& id) const {
00330
00331 EcalSubdetector subdet = EcalSubdetector(id.subdetId());
00332 if (subdet == EcalBarrel) {
00333 const EBDetId ebdetid = EBDetId(id);
00334
00335 int dcc = DCCid(ebdetid);
00336 bool EBPlus = (zside(dcc,DCCMODE) > 0);
00337 bool EBMinus = !EBPlus;
00338
00339 EcalTrigTowerDetId trigtower = ebdetid.tower();
00340
00341 int tower = iTT(trigtower);
00342
00343 int ieta = EBDetId(id).ietaAbs();
00344 int iphi = EBDetId(id).iphi();
00345 int strip(0);
00346 int channel(0);
00347 bool RightTower = rightTower(tower);
00348 if (RightTower) {
00349 strip = (ieta-1)%5;
00350 if (strip%2 == 0) {
00351 if (EBMinus) channel = (iphi-1) %5;
00352 if (EBPlus) channel = 4 -( (iphi-1) %5 );
00353 }
00354 else {
00355 if (EBMinus) channel = 4 -( (iphi-1) %5 );
00356 if (EBPlus) channel = (iphi-1) %5;
00357 }
00358 }
00359 else {
00360 strip = 4 - ( (ieta-1)%5 );
00361 if (strip%2 == 0) {
00362 if (EBMinus) channel = 4 -( (iphi-1) %5 );
00363 if (EBPlus) channel = (iphi-1) %5;
00364 }
00365 else {
00366 if (EBMinus) channel = (iphi-1) %5;
00367 if (EBPlus) channel = 4 -( (iphi-1) %5 );
00368 }
00369 }
00370 strip += 1;
00371 channel += 1;
00372
00373 EcalElectronicsId elid = EcalElectronicsId(dcc,tower,strip,channel);
00374
00375 return elid;
00376 }
00377 else if (subdet == EcalEndcap) {
00378 EcalElectronicsMap_by_DetId::const_iterator it=get<0>(m_items).find(id);
00379 EcalElectronicsId elid = it -> elid;
00380 return elid;
00381 }
00382 else {
00383 throw cms::Exception("InvalidDetId") <<
00384 " Wrong DetId in EcalElectronicsMapping::getElectronicsId.";
00385 }
00386
00387 }
00388
00389
00390 EcalTriggerElectronicsId EcalElectronicsMapping::getTriggerElectronicsId(const DetId& id) const {
00391 EcalSubdetector subdet = EcalSubdetector(id.subdetId());
00392
00393 if (subdet == EcalBarrel) {
00394
00395 const EcalElectronicsId& elid = getElectronicsId(id);
00396 EcalTriggerElectronicsId trelid = getTriggerElectronicsId(elid);
00397 return trelid;
00398 }
00399 else if (subdet == EcalEndcap) {
00400 EcalElectronicsMap_by_DetId::const_iterator it=get<0>(m_items).find(id);
00401 EcalTriggerElectronicsId trelid = it -> trelid;
00402 return trelid;
00403 }
00404 else {
00405 throw cms::Exception("InvalidDetId") <<
00406 " Wrong DetId in EcalElectronicsMapping::getTriggerElectronicsId.";
00407 }
00408 }
00409
00410
00411 DetId EcalElectronicsMapping::getDetId(const EcalElectronicsId& id) const {
00412 EcalSubdetector subdet = id.subdet();
00413
00414 if (subdet == EcalBarrel) {
00415 int dcc = id.dccId();
00416 int tower = id.towerId();
00417 int strip = id.stripId();
00418 int channel = id.xtalId();
00419
00420 int smid = 0;
00421 int iphi = 0;
00422 bool EBPlus = (id.zside() > 0);
00423 bool EBMinus = !EBPlus;
00424
00425 if (id.zside() < 0) {
00426 smid = dcc + 19 - DCCID_PHI0_EBM;
00427 iphi = (smid - 19) * kCrystalsInPhi;
00428 iphi += 5 * ( (tower-1) % kTowersInPhi );
00429 }
00430 else {
00431 smid = dcc +1 - DCCID_PHI0_EBP;
00432 iphi = (smid - 1) * kCrystalsInPhi;
00433 iphi += 5 * (
00434 kTowersInPhi - ( (tower-1) % kTowersInPhi ) -1
00435 );
00436 }
00437 bool RightTower = rightTower(tower);
00438 int ieta = 5 * ((tower-1) / kTowersInPhi) + 1;
00439 if (RightTower) {
00440 ieta += (strip-1);
00441 if (strip%2 == 1) {
00442 if (EBMinus) iphi += (channel-1) +1;
00443 if (EBPlus) iphi += (4 - (channel-1)) +1;
00444 }
00445 else {
00446 if (EBMinus) iphi += (4 - (channel-1)) +1;
00447 if (EBPlus) iphi += (channel-1) +1;
00448 }
00449 }
00450 else {
00451 ieta += 4 - (strip-1);
00452 if (strip%2 == 1) {
00453 if (EBMinus) iphi += (4 - (channel-1)) +1;
00454 if (EBPlus) iphi += (channel-1) +1;
00455 }
00456 else {
00457 if (EBMinus) iphi += (channel-1) +1;
00458 if (EBPlus) iphi += (4 - (channel-1)) +1;
00459 }
00460 }
00461 if (id.zside() < 0) ieta = -ieta;
00462
00463 EBDetId e(ieta,iphi,EBDetId::ETAPHIMODE);
00464 return e;
00465 }
00466
00467 else if (subdet == EcalEndcap) {
00468 EcalElectronicsMap_by_ElectronicsId::const_iterator it=get<1>(m_items).find(id);
00469 DetId cell = it -> cell;
00470 return cell;
00471 }
00472 else throw cms::Exception("InvalidDetId") << "Wrong EcalElectronicsId in EcalElectronicsMapping::getDetId." ;
00473 }
00474
00475
00476 EcalTriggerElectronicsId EcalElectronicsMapping::getTriggerElectronicsId(const EcalElectronicsId& id) const {
00477
00478 EcalSubdetector subdet = id.subdet();
00479
00480 if (subdet == EcalBarrel) {
00481 int strip = id.stripId();
00482 int xtal = id.xtalId();
00483 int tower = id.towerId();
00484 int tcc = id.dccId();
00485 if (id.zside() < 0) {
00486 tcc += TCCID_PHI0_EBM - DCCID_PHI0_EBM;
00487 }
00488 else {
00489 tcc += TCCID_PHI0_EBP - DCCID_PHI0_EBP;
00490 }
00491 EcalTriggerElectronicsId trelid(tcc,tower,strip,xtal);
00492 return trelid;
00493
00494 }
00495 else if (subdet == EcalEndcap) {
00496 EcalElectronicsMap_by_ElectronicsId::const_iterator it=get<1>(m_items).find(id);
00497 EcalTriggerElectronicsId trelid = it -> trelid;
00498 return trelid;
00499 }
00500 else throw cms::Exception("InvalidDetId") << "Wrong EcalElectronicsId in EcalElectronicsMapping::getTriggerElectronicsId.";
00501 }
00502
00503
00504 DetId EcalElectronicsMapping::getDetId(const EcalTriggerElectronicsId& id) const {
00505
00506 EcalSubdetector subdet = id.subdet();
00507
00508 if (subdet == EcalBarrel) {
00509 const EcalElectronicsId& elid = getElectronicsId(id);
00510 DetId cell = getDetId(elid);
00511 return cell;
00512 }
00513 else if (subdet == EcalEndcap) {
00514 EcalElectronicsMap_by_TriggerElectronicsId::const_iterator it=get<2>(m_items).find(id);
00515 DetId cell = it -> cell;
00516 return cell;
00517 }
00518 else throw cms::Exception("InvalidDetId") << "Wrong EcalTriggerElectronicsId in EcalElectronicsMapping::getDetId." ;
00519 }
00520
00521
00522
00523 EcalElectronicsId EcalElectronicsMapping::getElectronicsId(const EcalTriggerElectronicsId& id) const {
00524
00525 EcalSubdetector subdet = id.subdet();
00526
00527 if (subdet == EcalBarrel) {
00528 int strip = id.pseudoStripId();
00529 int xtal = id.channelId();
00530 int tower = id.ttId();
00531 int dcc = id.tccId();
00532 if (id.zside() < 0) {
00533 dcc -= TCCID_PHI0_EBM - DCCID_PHI0_EBM;
00534 }
00535 else {
00536 dcc -= TCCID_PHI0_EBP - DCCID_PHI0_EBP;
00537 }
00538 EcalElectronicsId elid(dcc,tower,strip,xtal);
00539 return elid;
00540 }
00541 else if (subdet == EcalEndcap) {
00542 EcalElectronicsMap_by_TriggerElectronicsId::const_iterator it=get<2>(m_items).find(id);
00543 EcalElectronicsId elid = it -> elid;
00544 return elid;
00545 }
00546 else throw cms::Exception("InvalidDetId") << "Wrong EcalTriggerElectronicsId in EcalElectronicsMapping::getElectronicsId.";
00547 }
00548
00549
00550
00551
00552 std::vector<DetId> EcalElectronicsMapping::dccConstituents(int dccId) const {
00553
00554 EcalSubdetector sub = subdet(dccId,DCCMODE);
00555 std::vector<DetId> items;
00556
00557 if (sub == EcalBarrel) {
00558 for (int tower=1; tower <= kEBTowersPerSM; tower++) {
00559 std::vector<DetId> xtals = dccTowerConstituents(dccId,tower);
00560 int size = xtals.size();
00561 for (int i=0; i < size; i++) {
00562 DetId detid = xtals[i];
00563 items.push_back(detid);
00564 }
00565 }
00566 return items;
00567 }
00568 else if (sub == EcalEndcap) {
00569 EcalElectronicsMap_by_DccId::const_iterator lb,ub;
00570 boost::tuples::tie(lb,ub)=get<3>(m_items).equal_range(dccId);
00571 while (lb != ub) {
00572 DetId cell = lb -> cell;
00573 items.push_back(cell);
00574 ++ lb;
00575 }
00576 return items;
00577 }
00578 else throw cms::Exception("InvalidDetId") << "Wrong dccId = " << dccId << " in EcalElectronicsMapping::dccConstituents. ";
00579 }
00580
00581
00582
00583 std::vector<DetId> EcalElectronicsMapping::dccTowerConstituents(int dccId, int tower) const {
00584
00585 EcalSubdetector sub = subdet(dccId,DCCMODE);
00586 std::vector<DetId> items;
00587
00588 if (sub == EcalBarrel) {
00589 int iz = zside(dccId, DCCMODE);
00590 int smid = 0;
00591 int iphi = 0;
00592 if (iz < 0) {
00593 smid = dccId + 19 - DCCID_PHI0_EBM;
00594 iphi = (smid - 19) * kCrystalsInPhi;
00595 iphi += 5 * ( (tower-1) % kTowersInPhi );
00596 }
00597 else {
00598 smid = dccId +1 - DCCID_PHI0_EBP;
00599 iphi = (smid - 1) * kCrystalsInPhi;
00600 iphi += 5 * (
00601 kTowersInPhi - ( (tower-1) % kTowersInPhi ) -1
00602 );
00603 }
00604 int ieta = 5 * ((tower-1) / kTowersInPhi) + 1;
00605 for (int ip=1; ip <=5; ip++) {
00606 for (int ie=0; ie <=4; ie++) {
00607 int ieta_xtal = ieta + ie;
00608 int iphi_xtal = iphi + ip;
00609 if (iz < 0) ieta_xtal = -ieta_xtal;
00610 EBDetId ebdetid(ieta_xtal,iphi_xtal,EBDetId::ETAPHIMODE);
00611 items.push_back(ebdetid);
00612 }
00613 }
00614 return items;
00615 }
00616
00617 else if (sub == EcalEndcap) {
00618 EcalElectronicsMap_by_DccId_and_TowerId::const_iterator lb,ub;
00619 boost::tuples::tie(lb,ub)=get<4>(m_items).equal_range(boost::make_tuple(int(dccId), int(tower)));
00620 while (lb != ub) {
00621 DetId cell = lb -> cell;
00622 items.push_back(cell);
00623 ++ lb;
00624 }
00625 return items;
00626 }
00627 else throw cms::Exception("InvalidDetId") <<
00628 "Wrong dccId = " << dccId << " tower = " << tower << " in EcalElectronicsMapping::dccTowerConstituents.";
00629 }
00630
00631
00632
00633 std::vector<DetId> EcalElectronicsMapping::stripConstituents(int dccId, int tower, int strip) const {
00634
00635 EcalSubdetector sub = subdet(dccId,DCCMODE);
00636 std::vector<DetId> items;
00637
00638 if (sub == EcalBarrel) {
00639
00640 int iz = zside(dccId, DCCMODE);
00641 bool RightTower = rightTower(tower);
00642 int smid = 0;
00643 int iphi = 0;
00644 if (iz < 0) {
00645 smid = dccId + 19 - DCCID_PHI0_EBM;
00646 iphi = (smid - 19) * kCrystalsInPhi;
00647 iphi += 5 * ( (tower-1) % kTowersInPhi );
00648 }
00649 else {
00650 smid = dccId +1 - DCCID_PHI0_EBP;
00651 iphi = (smid - 1) * kCrystalsInPhi;
00652 iphi += 5 * (
00653 kTowersInPhi - ( (tower-1) % kTowersInPhi ) -1
00654 );
00655 }
00656 int ieta = 5 * ((tower-1) / kTowersInPhi) + 1;
00657 if (RightTower) {
00658 ieta += (strip-1);
00659 }
00660 else {
00661 ieta += 4 - (strip-1);
00662 }
00663 for (int ip=1; ip <=5; ip++) {
00664 int ieta_xtal = ieta ;
00665 int iphi_xtal = iphi + ip;
00666 if (iz < 0) ieta_xtal = -ieta_xtal;
00667 EBDetId ebdetid(ieta_xtal,iphi_xtal,EBDetId::ETAPHIMODE);
00668 items.push_back(ebdetid);
00669 }
00670
00671 return items;
00672 }
00673 else {
00674 EcalElectronicsMap_by_DccId_TowerId_and_StripId::const_iterator lb,ub;
00675 boost::tuples::tie(lb,ub)=get<5>(m_items).equal_range(boost::make_tuple(int(dccId), int(tower), int(strip)));
00676 while (lb != ub) {
00677 DetId cell = lb -> cell;
00678 items.push_back(cell);
00679 ++ lb;
00680 }
00681 return items;
00682 }
00683
00684 }
00685
00686
00687 std::vector<DetId> EcalElectronicsMapping::tccConstituents(int tccId) const {
00688
00689 EcalSubdetector sub = subdet(tccId,TCCMODE);
00690 std::vector<DetId> items;
00691
00692 if (sub == EcalBarrel) {
00693 int iz = zside(tccId,TCCMODE);
00694 int dccId = tccId;
00695 if (iz > 0) dccId = dccId - TCCID_PHI0_EBP + DCCID_PHI0_EBP;
00696 else dccId = dccId - TCCID_PHI0_EBM + DCCID_PHI0_EBM;
00697 items = dccConstituents(dccId);
00698 return items;
00699 }
00700 else {
00701 EcalElectronicsMap_by_TccId::const_iterator lb,ub;
00702 boost::tuples::tie(lb,ub)=get<6>(m_items).equal_range(tccId);
00703 while (lb != ub) {
00704 DetId cell = lb -> cell;
00705 items.push_back(cell);
00706 ++ lb;
00707 }
00708 return items;
00709 }
00710 }
00711
00712
00713
00714 std::vector<DetId> EcalElectronicsMapping::ttConstituents(int tccId, int tt) const {
00715
00716 EcalSubdetector sub = subdet(tccId,TCCMODE);
00717 std::vector<DetId> items;
00718
00719 if (sub == EcalBarrel) {
00720 int iz = zside(tccId,TCCMODE);
00721 int dccId = tccId;
00722 if (iz > 0) dccId = dccId - TCCID_PHI0_EBP + DCCID_PHI0_EBP;
00723 else dccId = dccId - TCCID_PHI0_EBM + DCCID_PHI0_EBM;
00724 items = dccTowerConstituents(dccId,tt);
00725 return items;
00726 }
00727 else {
00728 EcalElectronicsMap_by_TccId_and_TtId::const_iterator lb,ub;
00729 boost::tuples::tie(lb,ub)=get<7>(m_items).equal_range(boost::make_tuple(int(tccId), int(tt)));
00730 while (lb != ub) {
00731 DetId cell = lb -> cell;
00732 items.push_back(cell);
00733 ++ lb;
00734 }
00735 return items;
00736 }
00737 }
00738
00739
00740 std::vector<DetId> EcalElectronicsMapping::pseudoStripConstituents(int tccId, int tt, int pseudostrip) const {
00741
00742 EcalSubdetector sub = subdet(tccId,TCCMODE);
00743 std::vector<DetId> items;
00744
00745 if (sub == EcalBarrel) {
00746 int iz = zside(tccId,TCCMODE);
00747 int dccId = tccId;
00748 if (iz > 0) dccId = dccId - TCCID_PHI0_EBP + DCCID_PHI0_EBP;
00749 else dccId = dccId - TCCID_PHI0_EBM + DCCID_PHI0_EBM;
00750 items = stripConstituents(dccId,tt,pseudostrip);
00751 return items;
00752 }
00753 else {
00754 EcalElectronicsMap_by_TccId_TtId_and_PseudostripId::const_iterator lb,ub;
00755 boost::tuples::tie(lb,ub)=get<8>(m_items).equal_range(boost::make_tuple(int(tccId), int(tt), int(pseudostrip)));
00756 while (lb != ub) {
00757 DetId cell = lb -> cell;
00758 items.push_back(cell);
00759 ++ lb;
00760 }
00761 return items;
00762 }
00763 }
00764
00765 void EcalElectronicsMapping::assign(const DetId& cell, const EcalElectronicsId& elid, const EcalTriggerElectronicsId& tower) {
00766
00767 m_items.insert(MapItem(cell, elid, tower));
00768 }
00769
00770
00771 std::pair<int, int> EcalElectronicsMapping::getDCCandSC(EcalScDetId id) const {
00772
00773
00774
00775
00776
00777
00778 std::pair<int,int> ind;
00779 EEDetId dum;
00780 int ix = id.ix();
00781 int iy = id.iy();
00782 int zside = id.zside();
00783 ix = (ix-1)*5 +1;
00784 iy = (iy-1)*5 +1;
00785 ix = 5 * (ix/5) +1;
00786 iy = 5 * (iy/5) +1;
00787 int ix_c = ix;
00788 int iy_c = iy;
00789 if (! dum.validDetId(ix_c,iy_c,zside) ) {
00790 ix_c = ix +4;
00791 iy_c = iy ;
00792 if ( ! dum.validDetId(ix_c,iy_c,zside) ) {
00793 ix_c = ix +4;
00794 iy_c = iy +4;
00795 if ( ! dum.validDetId(ix_c,iy_c,zside) ) {
00796 ix_c = ix;
00797 iy_c = iy +4;
00798 }
00799 }
00800 }
00801 EEDetId eedetid(ix_c,iy_c,zside,EEDetId::XYMODE);
00802 EcalElectronicsId elid = getElectronicsId(eedetid);
00803 int Dccid = elid.dccId();
00804 int DCC_Channel = elid.towerId();
00805 ind.first = Dccid;
00806 ind.second = DCC_Channel;
00807 return ind;
00808 }
00809
00810
00811
00812 EcalScDetId EcalElectronicsMapping::getEcalScDetId(int DCCid, int DCC_Channel) const {
00813
00814
00815
00816 std::vector<DetId> xtals = dccTowerConstituents(DCCid, DCC_Channel);
00817 if (xtals.size() == 0) throw cms::Exception("InvalidDetId") <<
00818 "EcalElectronicsMapping : can not create EcalScDetId for DCC " << DCCid <<
00819 " and DCC_Channel " << DCC_Channel << ".";
00820
00821 EEDetId eedetid = xtals[0];
00822 int ix = eedetid.ix();
00823 int iy = eedetid.iy();
00824 int iz = eedetid.zside();
00825 int ix_SC = (ix-1)/5 + 1;
00826 int iy_SC = (iy-1)/5 + 1;
00827 EcalScDetId scdetid(ix_SC,iy_SC,iz);
00828 return scdetid;
00829
00830 }
00831
00832
00833
00834 EcalSubdetector EcalElectronicsMapping::subdet(int dcctcc, int mode) const {
00835 if (mode == DCCMODE) {
00836 if ( (dcctcc >= MIN_DCCID_EBM && dcctcc <= MAX_DCCID_EBM) ||
00837 (dcctcc >= MIN_DCCID_EBP && dcctcc <= MAX_DCCID_EBP) ) return EcalBarrel;
00838 else return EcalEndcap;
00839 }
00840 else if (mode == TCCMODE) {
00841 if ( (dcctcc >= MIN_TCCID_EBM && dcctcc <= MAX_TCCID_EBM) ||
00842 (dcctcc >= MIN_TCCID_EBP && dcctcc <= MAX_TCCID_EBP) ) return EcalBarrel;
00843 else return EcalEndcap;
00844 }
00845 else throw cms::Exception("InvalidDetId") << " Wrong mode in EcalElectronicsMapping::subdet " << mode << ".";
00846 }
00847
00848
00849 int EcalElectronicsMapping::zside(int dcctcc, int mode) const {
00850 if (mode == DCCMODE) {
00851 if (dcctcc >= MIN_DCCID_EBM && dcctcc <= MAX_DCCID_EBM) return -1;
00852 if (dcctcc >= MIN_DCCID_EBP && dcctcc <= MAX_DCCID_EBP) return +1;
00853 if (dcctcc >= MIN_DCCID_EEM && dcctcc <= MAX_DCCID_EEM) return -1;
00854 if (dcctcc >= MIN_DCCID_EEP && dcctcc <= MAX_DCCID_EEP) return +1;
00855 }
00856 else if (mode == TCCMODE) {
00857 if (dcctcc >= MIN_TCCID_EBM && dcctcc <= MAX_TCCID_EBM) return -1;
00858 if (dcctcc >= MIN_TCCID_EBP && dcctcc <= MAX_TCCID_EBP) return +1;
00859 if (dcctcc >= MIN_TCCID_EEM && dcctcc <= MAX_TCCID_EEM) return -1;
00860 if (dcctcc >= MIN_TCCID_EEP && dcctcc <= MAX_TCCID_EEP) return +1;
00861 }
00862 else {
00863 throw cms::Exception("InvalidDetId") << " Wrong mode in EcalElectronicsMapping::zside " << mode << ".";
00864 }
00865 return 0;
00866 }
00867
00868
00869
00870 bool EcalElectronicsMapping::rightTower(int tower) const {
00871
00872
00873 if ((tower>12 && tower<21) || (tower>28 && tower<37) ||
00874 (tower>44 && tower<53) || (tower>60 && tower<69))
00875 return true;
00876 else
00877 return false;
00878 }
00879
00880
00881 int EcalElectronicsMapping::DCCBoundary(int FED)const {
00882
00883 if (FED >= MIN_DCCID_EEM && FED <= MAX_DCCID_EEM) return MIN_DCCID_EEM;
00884 if (FED >= MIN_DCCID_EBM && FED <= MAX_DCCID_EBM) return MIN_DCCID_EBM;
00885 if (FED >= MIN_DCCID_EBP && FED <= MAX_DCCID_EBP) return MIN_DCCID_EBP;
00886 if (FED >= MIN_DCCID_EEP && FED <= MAX_DCCID_EEP) return MIN_DCCID_EEP;
00887 return -1;
00888
00889 }
00890
00891
00892 std::vector<int> EcalElectronicsMapping::GetListofFEDs(const EcalEtaPhiRegion region) const {
00893 std::vector<int> FEDs;
00894 GetListofFEDs(region, FEDs);
00895 return FEDs;
00896 }
00897 void EcalElectronicsMapping::GetListofFEDs(const EcalEtaPhiRegion region, std::vector<int> & FEDs) const {
00898
00899
00900
00901
00902
00903 double radTodeg = 180. / Geom::pi();
00904
00905 bool debug = false;
00906
00907 double etalow = region.etaLow();
00908 double philow = region.phiLow() * radTodeg;
00909 if (debug) std::cout << " etalow philow " << etalow << " " << philow << std::endl;
00910 int FED_LB = GetFED(etalow,philow);
00911
00912 double phihigh = region.phiHigh() * radTodeg;
00913 if (debug) std::cout << " etalow phihigh " << etalow << " " << phihigh << std::endl;
00914 int FED_LT = GetFED(etalow,phihigh);
00915
00916 int DCC_BoundaryL = DCCBoundary(FED_LB);
00917 int deltaL = 18;
00918 if (FED_LB < MIN_DCCID_EBM || FED_LB > MAX_DCCID_EBP) deltaL=9;
00919
00920 if (philow < -170 && phihigh > 170) {
00921 FED_LB = DCC_BoundaryL;
00922 FED_LT = DCC_BoundaryL + deltaL -1;
00923 }
00924 if (debug) std::cout << " FED_LB FED_LT " << FED_LB << " " << FED_LT << std::endl;
00925
00926
00927 int iL=FED_LB;
00928 bool dummy = true;
00929 int idx = 0;
00930 while ( dummy ) {
00931 iL = (FED_LB - DCC_BoundaryL + idx ) % deltaL + DCC_BoundaryL;
00932 FEDs.push_back(iL);
00933 if (debug) std::cout << " add fed " << iL << std::endl;
00934 if ( iL == FED_LT) break;
00935 idx ++;
00936 }
00937
00938 double etahigh = region.etaHigh();
00939 int FED_RB = GetFED(etahigh, philow);
00940 if (FED_RB == FED_LB) return;
00941
00942 int FED_RT = GetFED(etahigh, phihigh);
00943
00944 if (debug) std::cout << "etahigh philow phihigh " << etahigh << " " << philow << " " << phihigh << std::endl;
00945 int DCC_BoundaryR = DCCBoundary(FED_RB);
00946 int deltaR = 18;
00947 if (FED_RB < MIN_DCCID_EBM || FED_RB > MAX_DCCID_EBP) deltaR=9;
00948
00949 if (philow < -170 && phihigh > 170) {
00950 FED_RB = DCC_BoundaryR;
00951 FED_RT = DCC_BoundaryR + deltaR-1;
00952 }
00953 if (debug) std::cout << " FED_RB FED_RT " << FED_RB << " " << FED_RT << std::endl;
00954
00955 int iR=FED_RB;
00956 idx = 0;
00957 while ( dummy ) {
00958 iR = (FED_RB - DCC_BoundaryR + idx) % deltaR + DCC_BoundaryR;
00959 FEDs.push_back(iR);
00960 if (debug) std::cout << " add fed " << iR << std::endl;
00961 if ( iR == FED_RT) break;
00962 idx ++;
00963 }
00964
00965
00966 if (FED_LB >= MIN_DCCID_EBM && FED_LB <= MAX_DCCID_EBM &&
00967 FED_RB >= MIN_DCCID_EEP && FED_RB <= MAX_DCCID_EEP) {
00968 int minR = FED_LB + 18;
00969 int maxR = FED_LT + 18;
00970 int iR = minR;
00971 int idx = 0;
00972 while ( dummy ) {
00973 iR = (minR - MIN_DCCID_EBP + idx) % 18 + MIN_DCCID_EBP;
00974 FEDs.push_back(iR);
00975 if (debug) std::cout << " add fed " << iR << std::endl;
00976 if ( iR == maxR) break;
00977 idx ++;
00978 }
00979 return;
00980 }
00981
00982 if (FED_LB >= MIN_DCCID_EEM && FED_LB <= MAX_DCCID_EEM &&
00983 FED_RB >= MIN_DCCID_EBP && FED_RB <= MAX_DCCID_EBP) {
00984 int minL = FED_RB - 18;
00985 int maxL = FED_RT - 18;
00986 int iL = minL;
00987 int idx = 0;
00988 while ( dummy ) {
00989 iL = (minL - MIN_DCCID_EBM + idx) % 18 + MIN_DCCID_EBM;
00990 FEDs.push_back(iL);
00991 if (debug) std::cout << " add fed " << iL << std::endl;
00992 if (iL == maxL) break;
00993 idx ++;
00994 }
00995 return;
00996 }
00997
00998 if (FED_LB >= MIN_DCCID_EEM && FED_LB <= MAX_DCCID_EEM &&
00999 FED_RB >= MIN_DCCID_EEP && FED_RB <= MAX_DCCID_EEP) {
01000 int minL = (FED_LB-1)*2 + MIN_DCCID_EBM;
01001 if (minL == MIN_DCCID_EBM) minL=MAX_DCCID_EBM;
01002 else minL = minL -1;
01003 int maxL = (FED_LT-1)*2 + MIN_DCCID_EBM;
01004 int iL = minL;
01005 int idx = 0;
01006 while (dummy) {
01007 iL = (minL - MIN_DCCID_EBM + idx) % 18 + MIN_DCCID_EBM;
01008 FEDs.push_back(iL);
01009 if (debug) std::cout << " add fed " << iL << std::endl;
01010 if (iL == maxL) break;
01011 idx ++;
01012 }
01013 int minR = minL + 18;
01014 int maxR = maxL + 18;
01015 int iR = minR;
01016 idx = 0;
01017 while (dummy) {
01018 iR = (minR - MIN_DCCID_EBP + idx) % 18 + MIN_DCCID_EBP;
01019 FEDs.push_back(iR);
01020 if (debug) std::cout << " add fed " << iR << std::endl;
01021 if (iR == maxR) break;
01022 idx ++;
01023 }
01024 }
01025
01026 return;
01027
01028 }
01029
01030 int EcalElectronicsMapping::GetFED(double eta, double phi) const {
01031
01032
01033
01034
01035 int DCC_Phi0 = 0;
01036 bool IsBarrel = true;
01037 if (fabs(eta) > 1.479) IsBarrel = false;
01038 bool Positive = (eta > 0);
01039
01040 if (IsBarrel && Positive) DCC_Phi0 = DCCID_PHI0_EBP;
01041 if (IsBarrel && (!Positive)) DCC_Phi0 = DCCID_PHI0_EBM;
01042 if ((!IsBarrel) && Positive) DCC_Phi0 = MIN_DCCID_EEP;
01043 if ((!IsBarrel) && (!Positive)) DCC_Phi0 = MIN_DCCID_EEM;
01044
01045
01046 if (phi < 0) phi += 360;
01047 if (phi > 360.) phi = 360. ;
01048 if (phi < 0) phi = 0. ;
01049
01050 if (IsBarrel) phi = phi - 350;
01051 else phi = phi - 330;
01052 if (phi < 0) phi += 360;
01053 int iphi = -1;
01054 if (IsBarrel) iphi = (int)(phi / 20.);
01055 else iphi = (int)(phi / 40.);
01056
01057
01058
01059 int DCC = iphi + DCC_Phi0;
01060
01061 return DCC;
01062 }
01063
01064
01065 int EcalElectronicsMapping::getLMNumber(const DetId& id) const {
01066
01067
01068
01069 EcalSubdetector subdet = EcalSubdetector(id.subdetId());
01070
01071 if (subdet == EcalBarrel) {
01072 const EBDetId ebdetid = EBDetId(id);
01073 int dccid = DCCid(ebdetid);
01074 std::map<int, int>::const_iterator it = LaserMonitoringMap_EB.find(dccid);
01075 if (it != LaserMonitoringMap_EB.end() ) {
01076 int ilm = it -> second;
01077 int iETA = ebdetid.ietaSM();
01078 int iPHI = ebdetid.iphiSM();
01079 if (iPHI > 10 && iETA>5) {ilm ++; } ;
01080 return ilm;
01081 }
01082 else throw cms::Exception("InvalidDCCId") << "Wrong DCCId (EB) in EcalElectronicsMapping::getLMNumber.";
01083 }
01084
01085 else if (subdet == EcalEndcap) {
01086 EcalElectronicsId elid = getElectronicsId(id);
01087 int dccid = elid.dccId();
01088 EEDetId eedetid = EEDetId(id);
01089 std::map<int, int>::const_iterator it = LaserMonitoringMap_EE.find(dccid);
01090 if (it != LaserMonitoringMap_EB.end() ) {
01091 int ilm = it -> second;
01092 if (dccid == 8) {
01093 int ix = eedetid.ix();
01094 if (ix > 50) ilm += 1;
01095 }
01096 if (dccid == 53) {
01097 int ix = eedetid.ix();
01098 if (ix > 50) ilm += 1;
01099 }
01100 return ilm;
01101 }
01102 else throw cms::Exception("InvalidDCCId") << "Wrong DCCId (EE) in EcalElectronicsMapping::getLMNumber.";
01103 }
01104
01105 return -1;
01106 }
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118