00001 #include "Geometry/CaloTopology/interface/CaloTowerConstituentsMap.h"
00002 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00003 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00004 #include "FWCore/Utilities/interface/Exception.h"
00005 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00006
00007 CaloTowerConstituentsMap::CaloTowerConstituentsMap() :
00008 standardHB_(false),
00009 standardHE_(false),
00010 standardHF_(false),
00011 standardHO_(false),
00012 standardEB_(false)
00013 {
00014 }
00015
00016 CaloTowerDetId CaloTowerConstituentsMap::towerOf(const DetId& id) const {
00017 CaloTowerDetId tid;
00018
00019 edm::SortedCollection<MapItem>::const_iterator i=m_items.find(id);
00020 if (i!=m_items.end()) tid=i->tower;
00021
00022 if (tid.null()) {
00023 if (id.det()==DetId::Hcal) {
00024 HcalDetId hid(id);
00025 if ( (hid.subdet()==HcalBarrel && standardHB_ ) ||
00026 (hid.subdet()==HcalEndcap && standardHE_ ) ||
00027 (hid.subdet()==HcalOuter && standardHO_ ) ||
00028 (hid.subdet()==HcalForward && standardHF_) ) {
00029 if ((hid.subdet()==HcalForward) && hid.ietaAbs()==29)
00030 tid=CaloTowerDetId(30*hid.zside(),hid.iphi());
00031 else
00032 tid=CaloTowerDetId(hid.ieta(),hid.iphi());
00033 }
00034 } else if (id.det()==DetId::Ecal) {
00035 EcalSubdetector esd=(EcalSubdetector)id.subdetId();
00036 if (esd==EcalBarrel && standardEB_) {
00037 EBDetId ebid(id);
00038 tid=CaloTowerDetId(ebid.tower_ieta(),ebid.tower_iphi());
00039 }
00040 }
00041 }
00042
00043 return tid;
00044 }
00045
00046 void CaloTowerConstituentsMap::assign(const DetId& cell, const CaloTowerDetId& tower) {
00047 if (m_items.find(cell)!=m_items.end()) {
00048 throw cms::Exception("CaloTowers") << "Cell with id " << std::hex << cell.rawId() << std::dec << " is already mapped to a CaloTower " << m_items.find(cell)->tower << std::endl;
00049 }
00050 m_items.push_back(MapItem(cell,tower));
00051 }
00052
00053 void CaloTowerConstituentsMap::sort() {
00054 m_items.sort();
00055 }
00056
00057 std::vector<DetId> CaloTowerConstituentsMap::constituentsOf(const CaloTowerDetId& id) const {
00058 std::vector<DetId> items;
00059
00060
00061 if (!m_items.empty() && m_reverseItems.empty()) {
00062 for (edm::SortedCollection<MapItem>::const_iterator i=m_items.begin(); i!=m_items.end(); i++)
00063 m_reverseItems.insert(std::pair<CaloTowerDetId,DetId>(i->tower,i->cell));
00064 }
00065
00067 std::multimap<CaloTowerDetId,DetId>::const_iterator j;
00068 std::pair<std::multimap<CaloTowerDetId,DetId>::const_iterator,std::multimap<CaloTowerDetId,DetId>::const_iterator> range=m_reverseItems.equal_range(id);
00069 for (j=range.first; j!=range.second; j++)
00070 items.push_back(j->second);
00071
00072
00073 static HcalTopology htopo;
00074 int nd, sd;
00075
00076 if (standardHB_) {
00077 if (id.ietaAbs()<=htopo.lastHBRing()) {
00078 htopo.depthBinInformation(HcalBarrel,id.ietaAbs(),nd,sd);
00079 for (int i=0; i<nd; i++)
00080 items.push_back(HcalDetId(HcalBarrel,id.ieta(),id.iphi(),i+sd));
00081 }
00082 }
00083 if (standardHO_) {
00084 if (id.ietaAbs()<=htopo.lastHORing()) {
00085 htopo.depthBinInformation(HcalOuter,id.ietaAbs(),nd,sd);
00086 for (int i=0; i<nd; i++)
00087 items.push_back(HcalDetId(HcalOuter,id.ieta(),id.iphi(),i+sd));
00088 }
00089 }
00090 if (standardHE_) {
00091 if (id.ietaAbs()>=htopo.firstHERing() && id.ietaAbs()<=htopo.lastHERing()) {
00092 htopo.depthBinInformation(HcalEndcap,id.ietaAbs(),nd,sd);
00093 for (int i=0; i<nd; i++)
00094 items.push_back(HcalDetId(HcalEndcap,id.ieta(),id.iphi(),i+sd));
00095 }
00096 }
00097 if (standardHF_) {
00098 if (id.ietaAbs()>htopo.firstHFRing() && id.ietaAbs()<=htopo.lastHFRing()) {
00099 int ieta=id.ieta();
00100 htopo.depthBinInformation(HcalForward,id.ietaAbs(),nd,sd);
00101 for (int i=0; i<nd; i++)
00102 items.push_back(HcalDetId(HcalForward,ieta,id.iphi(),i+sd));
00103 if (id.ietaAbs() == 30) {
00104 ieta = 29*id.zside();
00105 htopo.depthBinInformation(HcalForward,ieta,nd,sd);
00106 for (int i=0; i<nd; i++)
00107 items.push_back(HcalDetId(HcalForward,ieta,id.iphi(),i+sd));
00108 }
00109 }
00110 }
00111 if (standardEB_ && id.ietaAbs()<=EBDetId::MAX_IETA/5) {
00112 HcalDetId hid(HcalBarrel,id.ieta(),id.iphi(),1);
00113 int etaMin, etaMax;
00114 if (hid.zside() == -1) {
00115 etaMin = hid.crystal_ieta_high();
00116 etaMax = hid.crystal_ieta_low();
00117 } else {
00118 etaMin = hid.crystal_ieta_low();
00119 etaMax = hid.crystal_ieta_high();
00120 }
00121 for (int ie=etaMin; ie<=etaMax; ie++)
00122 for (int ip=hid.crystal_iphi_low(); ip<=hid.crystal_iphi_high(); ip++)
00123 items.push_back(EBDetId(ie,ip));
00124 }
00125
00126 return items;
00127 }
00128
00129 void CaloTowerConstituentsMap::useStandardHB(bool use) {
00130 standardHB_=use;
00131 }
00132 void CaloTowerConstituentsMap::useStandardHE(bool use) {
00133 standardHE_=use;
00134 }
00135 void CaloTowerConstituentsMap::useStandardHO(bool use) {
00136 standardHO_=use;
00137 }
00138 void CaloTowerConstituentsMap::useStandardHF(bool use) {
00139 standardHF_=use;
00140 }
00141 void CaloTowerConstituentsMap::useStandardEB(bool use) {
00142 standardEB_=use;
00143 }