Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-17 23:36:22

0001 #include "Geometry/HcalCommonData/interface/HcalLayerDepthMap.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "FWCore/Utilities/interface/Exception.h"
0005 #include <algorithm>
0006 #include <sstream>
0007 
0008 //#define EDM_ML_DEBUG
0009 
0010 HcalLayerDepthMap::HcalLayerDepthMap() {
0011   subdet_ = 0;
0012   ietaMin_ = ietaMax_ = 0;
0013   depthMin_ = 99;
0014   depthMax_ = -1;
0015   dep29C_ = 2;
0016   wtl0C_ = 1.;
0017 }
0018 
0019 HcalLayerDepthMap::~HcalLayerDepthMap() {}
0020 
0021 void HcalLayerDepthMap::initialize(const int subdet,
0022                                    const int ietaMax,
0023                                    const int dep16C,
0024                                    const int dep29C,
0025                                    const double wtl0C,
0026                                    std::vector<int> const& iphi,
0027                                    std::vector<int> const& ieta,
0028                                    std::vector<int> const& layer,
0029                                    std::vector<int> const& depth) {
0030   subdet_ = subdet;
0031   ietaMin_ = ietaMax_ = ietaMax;
0032   dep16C_ = dep16C;
0033   dep29C_ = dep29C;
0034   wtl0C_ = wtl0C;
0035   iphi_.insert(iphi_.end(), iphi.begin(), iphi.end());
0036   layer2Depth_.clear();
0037   depth2LayerF_.clear();
0038   depth2LayerB_.clear();
0039   depthMin_ = 99;
0040   depthMax_ = -1;
0041   for (unsigned int k = 0; k < ieta.size(); ++k) {
0042     if (ieta[k] < ietaMin_)
0043       ietaMin_ = ieta[k];
0044     if (depth[k] < depthMin_)
0045       depthMin_ = depth[k];
0046     if (depth[k] > depthMax_)
0047       depthMax_ = depth[k];
0048   }
0049   //Assume ieta, layer, depth are in increasing order of ieta and depth
0050   for (unsigned int k1 = 0; k1 < ieta.size(); ++k1) {
0051     int ietaMin = ieta[k1];
0052     int ietaMax = ietaMax_;
0053     int layMin = layer[k1];
0054     int layMax = (k1 + 1 < ieta.size()) ? (layer[k1 + 1] - 1) : maxLayers_;
0055     for (unsigned int k2 = k1 + 1; k2 < ieta.size(); ++k2) {
0056       if (ieta[k2] > ieta[k1]) {
0057         ietaMax = ieta[k2] - 1;
0058         if (k2 == k1 + 1)
0059           layMax = maxLayers_;
0060         break;
0061       }
0062     }
0063     for (int eta = ietaMin; eta <= ietaMax; ++eta) {
0064       depth2LayerF_[std::pair<int, int>(eta, depth[k1])] = layMin;
0065       depth2LayerB_[std::pair<int, int>(eta, depth[k1])] = layMax;
0066       for (int lay = layMin; lay <= layMax; ++lay)
0067         layer2Depth_[std::pair<int, int>(eta, lay)] = depth[k1];
0068     }
0069   }
0070   for (int eta = ietaMin_; eta <= ietaMax_; ++eta) {
0071     int dmin(99), dmax(-1);
0072     for (auto& itr : layer2Depth_) {
0073       if ((itr.first).first == eta) {
0074         if ((itr.second) < dmin)
0075           dmin = (itr.second);
0076         if ((itr.second) > dmax)
0077           dmax = (itr.second);
0078       }
0079     }
0080     if (subdet == 2) {
0081       if (eta == ietaMin_)
0082         dmin = dep16C_;
0083       else if (eta == ietaMax_)
0084         dmax = dep29C_;
0085     }
0086     depthsEta_[eta] = std::pair<int, int>(dmin, dmax);
0087   }
0088 #ifdef EDM_ML_DEBUG
0089   std::ostringstream st1;
0090   st1 << "HcalLayerDepthMap: Subdet " << subdet_ << " iEta " << ietaMin_ << ":" << ietaMax_ << " depth " << depthMin_
0091       << ":" << depthMax_ << "\nMaximum Depth for last HE towers " << dep29C_ << " Layer 0 Weight " << wtl0C_
0092       << " iPhi";
0093   for (unsigned int k = 0; k < iphi_.size(); ++k)
0094     st1 << ":" << iphi_[k];
0095   edm::LogVerbatim("HCalGeom") << st1.str();
0096   edm::LogVerbatim("HCalGeom") << "Layer2Depth_ with " << layer2Depth_.size() << " elements" << std::endl;
0097   for (std::map<std::pair<int, int>, int>::iterator itr = layer2Depth_.begin(); itr != layer2Depth_.end(); ++itr)
0098     edm::LogVerbatim("HCalGeom") << "iEta " << (itr->first).first << " Layer " << (itr->first).second << " Depth "
0099                                  << itr->second;
0100   edm::LogVerbatim("HCalGeom") << "Depth2LayerFront with " << depth2LayerF_.size() << " elemsts";
0101   for (std::map<std::pair<int, int>, int>::iterator itr = depth2LayerF_.begin(); itr != depth2LayerF_.end(); ++itr)
0102     edm::LogVerbatim("HCalGeom") << "iEta " << (itr->first).first << " Depth " << (itr->first).second << " Layer "
0103                                  << itr->second;
0104   edm::LogVerbatim("HCalGeom") << "Depth2LayerBack with " << depth2LayerB_.size() << " elemets";
0105   for (std::map<std::pair<int, int>, int>::iterator itr = depth2LayerB_.begin(); itr != depth2LayerB_.end(); ++itr)
0106     edm::LogVerbatim("HCalGeom") << "iEta " << (itr->first).first << " Depth " << (itr->first).second << " Layer "
0107                                  << itr->second;
0108   edm::LogVerbatim("HCalGeom") << "DepthsEta_ with " << depthsEta_.size() << " elements";
0109   for (std::map<int, std::pair<int, int> >::iterator itr = depthsEta_.begin(); itr != depthsEta_.end(); ++itr)
0110     edm::LogVerbatim("HCalGeom") << "iEta " << itr->first << " Depths " << (itr->second).first << ":"
0111                                  << (itr->second).second;
0112 #endif
0113 }
0114 
0115 int HcalLayerDepthMap::getDepth(
0116     const int subdet, const int ieta, const int iphi, const int zside, const int layer) const {
0117   int depth(-1);
0118   if (isValid(subdet, iphi, zside)) {
0119     std::map<std::pair<int, int>, int>::const_iterator itr = layer2Depth_.find(std::pair<int, int>(ieta, layer));
0120     if (itr != layer2Depth_.end())
0121       depth = itr->second;
0122   }
0123 #ifdef EDM_ML_DEBUG
0124   edm::LogVerbatim("HCalGeom") << "Debug Info -- getDepth::Input " << subdet << ":" << ieta << ":" << iphi << ":"
0125                                << zside << ":" << layer << " Output " << depth;
0126 #endif
0127   return depth;
0128 }
0129 
0130 int HcalLayerDepthMap::getDepth16(const int subdet, const int iphi, const int zside) const {
0131   int depth(-1);
0132   if (isValid(subdet, iphi, zside))
0133     depth = dep16C_;
0134 #ifdef EDM_ML_DEBUG
0135   edm::LogVerbatim("HCalGeom") << "Debug info -- getDepth16::Input " << subdet << ":" << iphi << ":" << zside
0136                                << " Output " << depth;
0137 #endif
0138   return depth;
0139 }
0140 
0141 int HcalLayerDepthMap::getDepthMin(const int subdet, const int iphi, const int zside) const {
0142   int depth = (isValid(subdet, iphi, zside)) ? depthMin_ : -1;
0143 #ifdef EDM_ML_DEBUG
0144   edm::LogVerbatim("HCalGeom") << "Debug info -- getDepthMin::Input " << subdet << ":" << iphi << ":" << zside
0145                                << " Output " << depth;
0146 #endif
0147   return depth;
0148 }
0149 
0150 int HcalLayerDepthMap::getDepthMax(const int subdet, const int iphi, const int zside) const {
0151   int depth = (isValid(subdet, iphi, zside)) ? depthMax_ : -1;
0152 #ifdef EDM_ML_DEBUG
0153   edm::LogVerbatim("HCalGeom") << "Debug info -- getDepthMax::Input " << subdet << ":" << iphi << ":" << zside
0154                                << " Output " << depth;
0155 #endif
0156   return depth;
0157 }
0158 
0159 int HcalLayerDepthMap::getDepthMax(const int subdet, const int ieta, const int iphi, const int zside) const {
0160   int depth = (isValid(subdet, iphi, zside)) ? getDepth(subdet, ieta, iphi, zside, maxLayers_) : -1;
0161 #ifdef EDM_ML_DEBUG
0162   edm::LogVerbatim("HCalGeom") << "Debug info -- getDepthMax::Input " << subdet << ":" << iphi << ":" << zside
0163                                << " Output " << depth;
0164 #endif
0165   return depth;
0166 }
0167 
0168 std::pair<int, int> HcalLayerDepthMap::getDepths(const int eta) const {
0169   std::map<int, std::pair<int, int> >::const_iterator itr = depthsEta_.find(eta);
0170   if (itr == depthsEta_.end())
0171     return std::pair<int, int>(-1, -1);
0172   else
0173     return itr->second;
0174 }
0175 
0176 int HcalLayerDepthMap::getLayerFront(
0177     const int subdet, const int ieta, const int iphi, const int zside, const int depth) const {
0178   int layer(-1);
0179   if (isValid(subdet, iphi, zside)) {
0180     std::map<std::pair<int, int>, int>::const_iterator itr = depth2LayerF_.find(std::pair<int, int>(ieta, depth));
0181     if (itr != depth2LayerF_.end())
0182       layer = itr->second;
0183   }
0184 #ifdef EDM_ML_DEBUG
0185   edm::LogVerbatim("HCalGeom") << "Debug info -- getLayerFront::Input " << subdet << ":" << ieta << ":" << iphi << ":"
0186                                << zside << ":" << depth << " Output " << layer;
0187 #endif
0188   return layer;
0189 }
0190 
0191 int HcalLayerDepthMap::getLayerBack(
0192     const int subdet, const int ieta, const int iphi, const int zside, const int depth) const {
0193   int layer(-1);
0194   if (isValid(subdet, iphi, zside)) {
0195     std::map<std::pair<int, int>, int>::const_iterator itr = depth2LayerB_.find(std::pair<int, int>(ieta, depth));
0196     if (itr != depth2LayerB_.end())
0197       layer = itr->second;
0198   }
0199 #ifdef EDM_ML_DEBUG
0200   edm::LogVerbatim("HCalGeom") << "Debug info -- getLayerBack::Input " << subdet << ":" << ieta << ":" << iphi << ":"
0201                                << zside << ":" << depth << " Output " << layer;
0202 #endif
0203   return layer;
0204 }
0205 
0206 void HcalLayerDepthMap::getLayerDepth(
0207     const int subdet, const int eta, const int phi, const int zside, std::map<int, int>& layers) const {
0208   layers.clear();
0209   if (isValid(subdet, phi, zside)) {
0210     for (const auto& itr : layer2Depth_) {
0211       if ((itr.first).first == eta) {
0212         layers[((itr.first).second) + 1] = (itr.second);
0213       }
0214     }
0215   }
0216 #ifdef EDM_ML_DEBUG
0217   edm::LogVerbatim("HCalGeom") << "Debug info -- getLayerDepth::Input " << subdet << ":" << eta << ":" << phi << ":"
0218                                << zside << " Output " << layers.size() << " entries";
0219   std::ostringstream st1;
0220   for (std::map<int, int>::iterator itr = layers.begin(); itr != layers.end(); ++itr)
0221     st1 << " [" << itr->first << "] " << itr->second;
0222   edm::LogVerbatim("HCalGeom") << st1.str();
0223 #endif
0224 }
0225 
0226 void HcalLayerDepthMap::getLayerDepth(const int eta, std::map<int, int>& layers) const {
0227   layers.clear();
0228   if (subdet_ > 0) {
0229     for (const auto& itr : layer2Depth_) {
0230       if ((itr.first).first == eta) {
0231         layers[((itr.first).second) + 1] = (itr.second);
0232       }
0233     }
0234   }
0235 #ifdef EDM_ML_DEBUG
0236   edm::LogVerbatim("HCalGeom") << "Debug info -- getLayerDepth::Input " << eta << " Output " << layers.size()
0237                                << " entries";
0238   std::ostringstream st1;
0239   for (std::map<int, int>::iterator itr = layers.begin(); itr != layers.end(); ++itr)
0240     st1 << " [" << itr->first << "] " << itr->second;
0241   edm::LogVerbatim("HCalGeom") << st1.str();
0242 #endif
0243 }
0244 
0245 int HcalLayerDepthMap::getMaxDepthLastHE(const int subdet, const int iphi, const int zside) const {
0246   int depth = isValid(subdet, iphi, zside) ? dep29C_ : -1;
0247 #ifdef EDM_ML_DEBUG
0248   edm::LogVerbatim("HCalGeom") << "Debug info -- getMaxDepthLastHE::Input " << subdet << ":" << iphi << ":" << zside
0249                                << " Output " << depth;
0250 #endif
0251   return depth;
0252 }
0253 
0254 double HcalLayerDepthMap::getLayer0Wt(const int subdet, const int iphi, const int zside) const {
0255   double wt = isValid(subdet, iphi, zside) ? wtl0C_ : -1.0;
0256 #ifdef EDM_ML_DEBUG
0257   edm::LogVerbatim("HCalGeom") << "Debug info -- getLayer0Wt::Input " << subdet << ":" << iphi << ":" << zside
0258                                << " Output " << wt;
0259 #endif
0260   return wt;
0261 }
0262 
0263 bool HcalLayerDepthMap::isValid(const int subdet, const int iphi, const int zside) const {
0264   bool flag(false);
0265   int kphi = (zside > 0) ? iphi : -iphi;
0266   if (subdet == subdet_)
0267     flag = (std::find(iphi_.begin(), iphi_.end(), kphi) != iphi_.end());
0268   return flag;
0269 }
0270 
0271 int HcalLayerDepthMap::validDet(std::vector<int>& phi) const {
0272   phi.insert(phi.end(), iphi_.begin(), iphi_.end());
0273   return subdet_;
0274 }