Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:48:27

0001 #include "Geometry/HGCalCommonData/interface/FastTimeDDDConstants.h"
0002 
0003 #include "DataFormats/Math/interface/GeantUnits.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 
0007 //#define EDM_ML_DEBUG
0008 using namespace geant_units::operators;
0009 
0010 FastTimeDDDConstants::FastTimeDDDConstants(const FastTimeParameters* ft) : ftpar_(ft) {
0011 #ifdef EDM_ML_DEBUG
0012   edm::LogVerbatim("HGCalGeom") << "FastTimeDDDConstants::FastTimeDDDConstants "
0013                                 << "( const FastTimeParameters* ft ) constructor";
0014 #endif
0015   initialize();
0016 }
0017 
0018 FastTimeDDDConstants::~FastTimeDDDConstants() {
0019 #ifdef EDM_ML_DEBUG
0020   edm::LogVerbatim("HGCalGeom") << "FastTimeDDDConstants:destructed!!!";
0021 #endif
0022 }
0023 
0024 std::pair<int, int> FastTimeDDDConstants::getZPhi(double z, double phi) const {
0025   if (phi < 0)
0026     phi += (2 * geant_units::piRadians);
0027   int iz = (int)(z / dZBarrel_) + 1;
0028   if (iz > ftpar_->nZBarrel_)
0029     iz = ftpar_->nZBarrel_;
0030   int iphi = (int)(phi / dPhiBarrel_) + 1;
0031   if (iphi > ftpar_->nPhiBarrel_)
0032     iphi = 1;
0033 #ifdef EDM_ML_DEBUG
0034   edm::LogVerbatim("HGCalGeom") << "FastTimeDDDConstants:Barrel z|phi " << z << " " << convertRadToDeg(phi)
0035                                 << " iz|iphi " << iz << " " << iphi;
0036 #endif
0037   return std::pair<int, int>(iz, iphi);
0038 }
0039 
0040 std::pair<int, int> FastTimeDDDConstants::getEtaPhi(double r, double phi) const {
0041   if (phi < 0)
0042     phi += (2 * geant_units::piRadians);
0043   int ir(ftpar_->nEtaEndcap_);
0044   for (unsigned int k = 1; k < rLimits_.size(); ++k) {
0045     if (r > rLimits_[k]) {
0046       ir = k;
0047       break;
0048     }
0049   }
0050   int iphi = (int)(phi / dPhiEndcap_) + 1;
0051   if (iphi > ftpar_->nPhiEndcap_)
0052     iphi = 1;
0053 #ifdef EDM_ML_DEBUG
0054   edm::LogVerbatim("HGCalGeom") << "FastTimeDDDConstants:Endcap r|phi " << r << " " << convertRadToDeg(phi)
0055                                 << " ir|iphi " << ir << " " << iphi;
0056 #endif
0057   return std::pair<int, int>(ir, iphi);
0058 }
0059 
0060 GlobalPoint FastTimeDDDConstants::getPosition(int type, int izeta, int iphi, int zside) const {
0061   double x(0), y(0), z(0);
0062   if (type == 1) {
0063     double phi = (iphi - 0.5) * dPhiBarrel_;
0064     x = ftpar_->geomParBarrel_[2] * cos(phi);
0065     y = ftpar_->geomParBarrel_[2] * sin(phi);
0066     z = ftpar_->geomParBarrel_[0] + (izeta - 0.5) * dZBarrel_;
0067   } else if (type == 2) {
0068     double phi = (iphi - 0.5) * dPhiEndcap_;
0069     double r = (izeta <= 0 || izeta >= (int)(rLimits_.size())) ? 0 : 0.5 * (rLimits_[izeta - 1] + rLimits_[izeta]);
0070     x = (zside < 0) ? -r * cos(phi) : r * cos(phi);
0071     y = r * sin(phi);
0072     z = ftpar_->geomParEndcap_[2];
0073   }
0074   if (zside < 0)
0075     z = -z;
0076   GlobalPoint p(x, y, z);
0077   return p;
0078 }
0079 
0080 std::vector<GlobalPoint> FastTimeDDDConstants::getCorners(int type, int izeta, int iphi, int zside) const {
0081   double x(0), y(0), z(0), dx(0), dz(0), r(0), phi(0);
0082   if (type == 1) {
0083     phi = (iphi - 0.5) * dPhiBarrel_;
0084     r = ftpar_->geomParBarrel_[2];
0085     x = r * cos(phi);
0086     y = r * sin(phi);
0087     z = ftpar_->geomParBarrel_[0] + (izeta - 0.5) * dZBarrel_;
0088     dx = 0.5 * ftpar_->geomParBarrel_[3];
0089     dz = 0.5 * dZBarrel_;
0090   } else if (type == 2) {
0091     phi = (iphi - 0.5) * dPhiEndcap_;
0092     r = (izeta <= 0 || izeta >= (int)(rLimits_.size())) ? 0 : 0.5 * (rLimits_[izeta - 1] + rLimits_[izeta]);
0093     x = (zside < 0) ? -r * cos(phi) : r * cos(phi);
0094     y = r * sin(phi);
0095     z = ftpar_->geomParEndcap_[2];
0096     dx = 0.5 * r * dPhiEndcap_;
0097     dz = 0.5 * ftpar_->geomParEndcap_[3];
0098   }
0099   if (zside < 0) {
0100     z = -z;
0101     dz = -dz;
0102   }
0103   static constexpr int signx[8] = {-1, -1, 1, 1, -1, -1, 1, 1};
0104   static constexpr int signy[8] = {-1, 1, 1, -1, -1, 1, 1, -1};
0105   static constexpr int signz[8] = {-1, -1, -1, -1, 1, 1, 1, 1};
0106   std::vector<GlobalPoint> pts;
0107   for (unsigned int i = 0; i != 8; ++i) {
0108     GlobalPoint p(x + signx[i] * dx, y + signy[i] * dx, z + signz[i] * dz);
0109     pts.emplace_back(p);
0110   }
0111   return pts;
0112 }
0113 
0114 int FastTimeDDDConstants::getCells(int type) const {
0115   int numb(0);
0116   if (type == 1) {
0117     numb = (ftpar_->nZBarrel_) * (ftpar_->nPhiBarrel_);
0118   } else if (type == 2) {
0119     numb = (ftpar_->nEtaEndcap_) * (ftpar_->nPhiEndcap_);
0120   }
0121   return numb;
0122 }
0123 
0124 double FastTimeDDDConstants::getRin(int type) const {
0125   double value(0);
0126   if (type == 1) {
0127     value = (ftpar_->geomParBarrel_[2]);
0128   } else if (type == 2) {
0129     value = (ftpar_->geomParEndcap_[0]);
0130   }
0131   return value;
0132 }
0133 
0134 double FastTimeDDDConstants::getRout(int type) const {
0135   double value(0);
0136   if (type == 1) {
0137     value = (ftpar_->geomParBarrel_[2] + ftpar_->geomParBarrel_[3]);
0138   } else if (type == 2) {
0139     value = (ftpar_->geomParEndcap_[1]);
0140   }
0141   return value;
0142 }
0143 
0144 double FastTimeDDDConstants::getZHalf(int type) const {
0145   double value(0);
0146   if (type == 1) {
0147     value = 0.5 * (ftpar_->geomParBarrel_[1] - ftpar_->geomParBarrel_[0]);
0148   } else if (type == 2) {
0149     value = (ftpar_->geomParEndcap_[3]);
0150   }
0151   return value;
0152 }
0153 
0154 double FastTimeDDDConstants::getZPos(int type) const {
0155   double value(0);
0156   if (type == 1) {
0157     value = 0.5 * (ftpar_->geomParBarrel_[1] + ftpar_->geomParBarrel_[0]);
0158   } else if (type == 2) {
0159     value = (ftpar_->geomParEndcap_[2]);
0160   }
0161   return value;
0162 }
0163 
0164 bool FastTimeDDDConstants::isValidXY(int type, int izeta, int iphi) const {
0165   bool ok(false);
0166   if (type == 1) {
0167     ok = ((izeta > 0) && (izeta <= ftpar_->nZBarrel_) && (iphi > 0) && (iphi <= ftpar_->nPhiBarrel_));
0168   } else if (type == 2) {
0169     ok = ((izeta > 0) && (izeta <= ftpar_->nEtaEndcap_) && (iphi > 0) && (iphi <= ftpar_->nPhiEndcap_));
0170   }
0171   return ok;
0172 }
0173 
0174 int FastTimeDDDConstants::numberEtaZ(int type) const {
0175   int numb(0);
0176   if (type == 1) {
0177     numb = (ftpar_->nZBarrel_);
0178   } else if (type == 2) {
0179     numb = (ftpar_->nEtaEndcap_);
0180   }
0181   return numb;
0182 }
0183 
0184 int FastTimeDDDConstants::numberPhi(int type) const {
0185   int numb(0);
0186   if (type == 1) {
0187     numb = (ftpar_->nPhiBarrel_);
0188   } else if (type == 2) {
0189     numb = (ftpar_->nPhiEndcap_);
0190   }
0191   return numb;
0192 }
0193 
0194 void FastTimeDDDConstants::initialize() {
0195   double thmin = atan(ftpar_->geomParEndcap_[0] / ftpar_->geomParEndcap_[2]);
0196   etaMax_ = -log(0.5 * thmin);
0197   double thmax = atan(ftpar_->geomParEndcap_[1] / ftpar_->geomParEndcap_[2]);
0198   etaMin_ = -log(0.5 * thmax);
0199   dEta_ = (etaMax_ - etaMin_) / ftpar_->nEtaEndcap_;
0200 #ifdef EDM_ML_DEBUG
0201   edm::LogVerbatim("HGCalGeom") << "Theta range " << convertRadToDeg(thmin) << ":" << convertRadToDeg(thmax)
0202                                 << " Eta range " << etaMin_ << ":" << etaMax_ << ":" << dEta_;
0203 #endif
0204   for (int k = 0; k <= ftpar_->nEtaEndcap_; ++k) {
0205     double eta = etaMin_ + k * dEta_;
0206     double theta = 2.0 * atan(exp(-eta));
0207     double rval = (ftpar_->geomParEndcap_[2]) * tan(theta);
0208     rLimits_.emplace_back(rval);
0209   }
0210   dZBarrel_ = ftpar_->geomParBarrel_[1] / ftpar_->nZBarrel_;
0211   dPhiBarrel_ = (2 * geant_units::piRadians) / ftpar_->nPhiBarrel_;
0212   dPhiEndcap_ = (2 * geant_units::piRadians) / ftpar_->nPhiEndcap_;
0213 #ifdef EDM_ML_DEBUG
0214   edm::LogVerbatim("HGCalGeom") << "FastTimeDDDConstants initialized with " << ftpar_->nZBarrel_ << ":"
0215                                 << ftpar_->nPhiBarrel_ << ":" << getCells(1) << " cells for barrel; dz|dphi "
0216                                 << dZBarrel_ << "|" << dPhiBarrel_ << " and " << ftpar_->nEtaEndcap_ << ":"
0217                                 << ftpar_->nPhiEndcap_ << ":" << getCells(2) << " cells for endcap; dphi "
0218                                 << dPhiEndcap_ << " The Limits in R are";
0219   for (unsigned int k = 0; k < rLimits_.size(); ++k)
0220     edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << rLimits_[k] << " ";
0221 #endif
0222 }
0223 
0224 #include "FWCore/Utilities/interface/typelookup.h"
0225 
0226 TYPELOOKUP_DATA_REG(FastTimeDDDConstants);