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(const HcalTopology * topology) :
00008 m_topology(topology),
00009 standardHB_(false),
00010 standardHE_(false),
00011 standardHF_(false),
00012 standardHO_(false),
00013 standardEB_(false)
00014 {
00015 }
00016
00017 CaloTowerDetId CaloTowerConstituentsMap::towerOf(const DetId& id) const {
00018 CaloTowerDetId tid;
00019
00020 edm::SortedCollection<MapItem>::const_iterator i=m_items.find(id);
00021 if (i!=m_items.end()) tid=i->tower;
00022
00023 if (tid.null()) {
00024 if (id.det()==DetId::Hcal) {
00025 HcalDetId hid(id);
00026 if ( (hid.subdet()==HcalBarrel && standardHB_ ) ||
00027 (hid.subdet()==HcalEndcap && standardHE_ ) ||
00028 (hid.subdet()==HcalOuter && standardHO_ ) ||
00029 (hid.subdet()==HcalForward && standardHF_) ) {
00030 if ((hid.subdet()==HcalForward) && hid.ietaAbs()==29)
00031 tid=CaloTowerDetId(30*hid.zside(),hid.iphi());
00032 else
00033 tid=CaloTowerDetId(hid.ieta(),hid.iphi());
00034 }
00035 } else if (id.det()==DetId::Ecal) {
00036 EcalSubdetector esd=(EcalSubdetector)id.subdetId();
00037 if (esd==EcalBarrel && standardEB_) {
00038 EBDetId ebid(id);
00039 tid=CaloTowerDetId(ebid.tower_ieta(),ebid.tower_iphi());
00040 }
00041 }
00042 }
00043
00044 return tid;
00045 }
00046
00047 void CaloTowerConstituentsMap::assign(const DetId& cell, const CaloTowerDetId& tower) {
00048 if (m_items.find(cell)!=m_items.end()) {
00049 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;
00050 }
00051 m_items.push_back(MapItem(cell,tower));
00052 }
00053
00054 void CaloTowerConstituentsMap::sort() {
00055 m_items.sort();
00056 }
00057
00058 std::vector<DetId> CaloTowerConstituentsMap::constituentsOf(const CaloTowerDetId& id) const {
00059 std::vector<DetId> items;
00060
00061
00062 if (!m_items.empty() && m_reverseItems.empty()) {
00063 for (edm::SortedCollection<MapItem>::const_iterator i=m_items.begin(); i!=m_items.end(); i++)
00064 m_reverseItems.insert(std::pair<CaloTowerDetId,DetId>(i->tower,i->cell));
00065 }
00066
00068 std::multimap<CaloTowerDetId,DetId>::const_iterator j;
00069 std::pair<std::multimap<CaloTowerDetId,DetId>::const_iterator,std::multimap<CaloTowerDetId,DetId>::const_iterator> range=m_reverseItems.equal_range(id);
00070 for (j=range.first; j!=range.second; j++)
00071 items.push_back(j->second);
00072
00073
00074 int nd, sd;
00075
00076 if (standardHB_) {
00077 if (id.ietaAbs()<=m_topology->lastHBRing()) {
00078 m_topology->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()<=m_topology->lastHORing()) {
00085 m_topology->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()>=m_topology->firstHERing() && id.ietaAbs()<=m_topology->lastHERing()) {
00092 m_topology->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()>m_topology->firstHFRing() && id.ietaAbs()<=m_topology->lastHFRing()) {
00099 int ieta=id.ieta();
00100 m_topology->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 m_topology->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 }