Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:42

0001 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
0002 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0003 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0004 
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 
0009 EcalTrigTowerConstituentsMap::EcalTrigTowerConstituentsMap() {}
0010 
0011 EcalTrigTowerDetId EcalTrigTowerConstituentsMap::towerOf(const DetId& id) const {
0012   if (id.det() == DetId::Ecal && id.subdetId() == EcalBarrel) {
0013     //--------------------
0014     // Ecal Barrel
0015     //--------------------
0016     EBDetId myId(id);
0017     return myId.tower();
0018   } else if (id.det() == DetId::Ecal && id.subdetId() == EcalEndcap) {
0019     //--------------------
0020     // Ecal Endcap
0021     //--------------------
0022     EEDetId originalId(id);
0023     // DetId wrappedId=wrapEEDetId(id);
0024     DetId wrappedId(originalId);
0025     EcalTowerMap::const_iterator i = m_items.find(wrappedId);
0026     if (i != m_items.end()) {
0027       int etaTower = i->tower.ietaAbs();
0028       int phiTower = i->tower.iphi();
0029       //trigger tower <-> crystal maping read
0030       //..........from file and done only for 1 quadrant
0031       //move from quadrant 1 to the actual one:
0032       // phiTower = changeTowerQuadrant(phiTower, 1, originalId.iquadrant());
0033       // std::cout << originalId.zside() <<  " " << etaTower << " " << phiTower << std::endl;
0034       return EcalTrigTowerDetId(originalId.zside(), EcalEndcap, etaTower, phiTower);
0035     }
0036   }
0037   return EcalTrigTowerDetId(0);
0038 }
0039 
0040 DetId EcalTrigTowerConstituentsMap::wrapEEDetId(const DetId& eeid) const {
0041   if (!(eeid.det() == DetId::Ecal && eeid.subdetId() == EcalEndcap))
0042     return EEDetId(0);
0043 
0044   EEDetId myId(eeid);
0045   switch ((myId.iquadrant() - 1) % 4) {
0046     case 0:
0047       return DetId(EEDetId(myId.ix(), myId.iy(), 1, EEDetId::XYMODE));
0048       break;
0049     case 1:
0050       return DetId(EEDetId(101 - myId.ix(), myId.iy(), 1, EEDetId::XYMODE));
0051       break;
0052     case 2:
0053       return DetId(EEDetId(101 - myId.ix(), 101 - myId.iy(), 1, EEDetId::XYMODE));
0054       break;
0055     case 3:
0056       return DetId(EEDetId(myId.ix(), 101 - myId.iy(), 1, EEDetId::XYMODE));
0057       break;
0058     default:
0059       /*should never be reached*/
0060       edm::LogError("EcalTrigTowerConstituentsMapError") << "This should never be reached. Profound error!";
0061   }
0062   return EEDetId(0);
0063 }
0064 
0065 DetId EcalTrigTowerConstituentsMap::wrapEcalTrigTowerDetId(const DetId& id) const {
0066   EcalTrigTowerDetId etid(id);
0067 
0068   if (!(etid.det() == DetId::Ecal && etid.subdetId() == EcalTriggerTower && etid.subDet() == EcalEndcap))
0069     return EcalTrigTowerDetId(0);
0070 
0071   switch ((etid.iquadrant() - 1) % 4) {
0072     case 0:
0073       return DetId(EcalTrigTowerDetId(1, EcalEndcap, etid.ietaAbs(), etid.iphi()));
0074       break;
0075     case 1:
0076       return DetId(EcalTrigTowerDetId(
0077           1, EcalEndcap, etid.ietaAbs(), EcalTrigTowerDetId::kEETowersInPhiPerQuadrant * 2 - etid.iphi() + 1));
0078       break;
0079     case 2:
0080       return DetId(EcalTrigTowerDetId(
0081           1, EcalEndcap, etid.ietaAbs(), etid.iphi() - EcalTrigTowerDetId::kEETowersInPhiPerQuadrant * 2));
0082       break;
0083     case 3:
0084       return DetId(EcalTrigTowerDetId(
0085           1, EcalEndcap, etid.ietaAbs(), EcalTrigTowerDetId::kEETowersInPhiPerQuadrant * 4 - etid.iphi() + 1));
0086       break;
0087     default:
0088       /*should never be reached*/
0089       edm::LogError("EcalTrigTowerConstituentsMapError") << "This should never be reached. Profound error!";
0090   }
0091   return EcalTrigTowerDetId(0);
0092 }
0093 
0094 DetId EcalTrigTowerConstituentsMap::changeEEDetIdQuadrantAndZ(const DetId& fromid,
0095                                                               const int& toQuadrant,
0096                                                               const int& tozside) const {
0097   if (!(fromid.det() == DetId::Ecal && fromid.subdetId() == EcalEndcap))
0098     return EEDetId(0);
0099 
0100   EEDetId myId(fromid);
0101   int dQuadrant = toQuadrant - myId.iquadrant();
0102   switch (dQuadrant % 4) {
0103     case 0:
0104       return DetId(EEDetId(myId.ix(), myId.iy(), tozside, EEDetId::XYMODE));
0105       break;
0106     case 1:
0107       /* adjacent tower: they are symetric*/
0108       return DetId(EEDetId(101 - myId.ix(), myId.iy(), tozside, EEDetId::XYMODE));
0109       break;
0110     case 2:
0111       /* opposite quadrant: they are identical*/
0112       return DetId(EEDetId(101 - myId.ix(), 101 - myId.iy(), tozside, EEDetId::XYMODE));
0113       break;
0114     case 3:
0115       /* adjacent tower: they are symetric*/
0116       return DetId(EEDetId(myId.ix(), 101 - myId.iy(), tozside, EEDetId::XYMODE));
0117       break;
0118     default:
0119       /*should never be reached*/
0120       edm::LogError("EcalTrigTowerConstituentsMapError") << "This should never be reached. Profound error!";
0121   }
0122   return EEDetId(0);
0123 }
0124 
0125 int EcalTrigTowerConstituentsMap::changeTowerQuadrant(int phiTower, int fromQuadrant, int toQuadrant) const {
0126   int newPhiTower = phiTower;
0127   int dQuadrant = toQuadrant - fromQuadrant;
0128 
0129   switch (dQuadrant % 4) {
0130     case 0:
0131       newPhiTower = phiTower;
0132       break;
0133     case 1:
0134       /* adjacent tower: they are symetric*/
0135       newPhiTower = EcalTrigTowerDetId::kEETowersInPhiPerQuadrant * 2 - phiTower + 1;
0136       break;
0137     case 2:
0138       /* opposite quadrant: they are identical*/
0139       newPhiTower = phiTower + EcalTrigTowerDetId::kEETowersInPhiPerQuadrant * 2;
0140       break;
0141     case 3:
0142       /* adjacent tower: they are symetric*/
0143       newPhiTower = EcalTrigTowerDetId::kEETowersInPhiPerQuadrant * 4 - phiTower + 1;
0144       break;
0145     default:
0146       /*should never be reached*/
0147       edm::LogError("EcalTrigTowerConstituentsMapError") << "This should never be reached. Profound error!";
0148   }
0149   return newPhiTower;
0150 }
0151 
0152 void EcalTrigTowerConstituentsMap::assign(const DetId& cell, const EcalTrigTowerDetId& tower) {
0153   if (m_items.find(cell) != m_items.end()) {
0154     throw cms::Exception("EcalTrigTowers")
0155         << "Cell with id " << std::hex << cell.rawId() << std::dec << " is already mapped to a EcalTrigTower "
0156         << m_items.find(cell)->tower << std::endl;
0157   }
0158 
0159   m_items.insert(MapItem(cell, tower));
0160 }
0161 
0162 std::vector<DetId> EcalTrigTowerConstituentsMap::constituentsOf(const EcalTrigTowerDetId& id) const {
0163   std::vector<DetId> items;
0164 
0165   if (id.det() == DetId::Ecal && id.subdetId() == EcalTriggerTower && id.subDet() == EcalBarrel) {
0166     //--------------------
0167     // Ecal Barrel
0168     //--------------------
0169     // trigger towers are 5x5 crystals in the barrel
0170     int etaxtalMin = (id.ietaAbs() - 1) * 5 + 1;
0171     int phixtalMin = ((id.iphi() - 1) * 5 + 11) % 360;
0172     if (phixtalMin <= 0)
0173       phixtalMin += 360;
0174     int etaxtalMax = id.ietaAbs() * 5;
0175     int phixtalMax = ((id.iphi()) * 5 + 10) % 360;
0176     if (phixtalMax <= 0)
0177       phixtalMax += 360;
0178     for (int e = etaxtalMin; e <= etaxtalMax; e++)
0179       for (int p = phixtalMin; p <= phixtalMax; p++)
0180         items.emplace_back(DetId(EBDetId(id.zside() * e, p, EBDetId::ETAPHIMODE)));
0181   } else if (id.det() == DetId::Ecal && id.subdetId() == EcalTriggerTower && id.subDet() == EcalEndcap) {
0182     //--------------------
0183     // Ecal Endcap
0184     //--------------------
0185     //DetId myId=wrapEcalTrigTowerDetId(id);
0186     EcalTowerMap_by_towerDetId::const_iterator lb, ub;
0187     //boost::tuples::tie(lb,ub)=get<1>(m_items).equal_range(myId);
0188     boost::tuples::tie(lb, ub) = boost::get<1>(m_items).equal_range(id);
0189     while (lb != ub) {
0190       //EEDetId mappedId((*lb).cell);
0191       //items.emplace_back(changeEEDetIdQuadrantAndZ(mappedId,id.iquadrant(),id.zside()));
0192       items.emplace_back((*lb).cell);
0193       ++lb;
0194     }
0195   }
0196 
0197   return items;
0198 }