CMS 3D CMS Logo

CaloTowerConstituentsMap.cc

Go to the documentation of this file.
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; // null to start with
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)  // special handling for tower 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   // build reverse map if needed
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   // dealing with topo dependency...
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       if (id.ietaAbs()==29) ieta=id.zside()*30;
00101       htopo.depthBinInformation(HcalForward,id.ietaAbs(),nd,sd);
00102       for (int i=0; i<nd; i++)
00103         items.push_back(HcalDetId(HcalForward,ieta,id.iphi(),i+sd));
00104     }
00105   }
00106   if (standardEB_ && id.ietaAbs()<EBDetId::MAX_IETA/5) {
00107     HcalDetId hid(HcalBarrel,id.ieta(),id.iphi(),1); // for the limits
00108     for (int ie=hid.crystal_ieta_low(); ie<=hid.crystal_ieta_high(); ie++)
00109       for (int ip=hid.crystal_iphi_low(); ip<=hid.crystal_iphi_high(); ip++)
00110         items.push_back(EBDetId(ie,ip));
00111   }
00112 
00113   return items;
00114 }
00115 
00116 void CaloTowerConstituentsMap::useStandardHB(bool use) {
00117   standardHB_=use;
00118 }
00119 void CaloTowerConstituentsMap::useStandardHE(bool use) {
00120   standardHE_=use;
00121 }
00122 void CaloTowerConstituentsMap::useStandardHO(bool use) {
00123   standardHO_=use;
00124 }
00125 void CaloTowerConstituentsMap::useStandardHF(bool use) {
00126   standardHF_=use;
00127 }
00128 void CaloTowerConstituentsMap::useStandardEB(bool use) {
00129   standardEB_=use;
00130 }

Generated on Tue Jun 9 17:37:17 2009 for CMSSW by  doxygen 1.5.4