Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:05

0001 #include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h"
0004 
0005 #include <array>
0006 
0007 //#define EDM_ML_DEBUG
0008 
0009 HGCalParameters::HGCalParameters(const std::string& nam) : name_(nam), nCells_(0), waferMaskMode_(0) {
0010 #ifdef EDM_ML_DEBUG
0011   edm::LogVerbatim("HGCalGeom") << "Construct HGCalParameters for " << name_;
0012 #endif
0013 }
0014 
0015 void HGCalParameters::fillModule(const HGCalParameters::hgtrap& mytr, bool reco) {
0016   if (reco) {
0017     moduleLayR_.emplace_back(mytr.lay);
0018     moduleBlR_.emplace_back(mytr.bl);
0019     moduleTlR_.emplace_back(mytr.tl);
0020     moduleHR_.emplace_back(mytr.h);
0021     moduleDzR_.emplace_back(mytr.dz);
0022     moduleAlphaR_.emplace_back(mytr.alpha);
0023     moduleCellR_.emplace_back(mytr.cellSize);
0024   } else {
0025     moduleLayS_.emplace_back(mytr.lay);
0026     moduleBlS_.emplace_back(mytr.bl);
0027     moduleTlS_.emplace_back(mytr.tl);
0028     moduleHS_.emplace_back(mytr.h);
0029     moduleDzS_.emplace_back(mytr.dz);
0030     moduleAlphaS_.emplace_back(mytr.alpha);
0031     moduleCellS_.emplace_back(mytr.cellSize);
0032   }
0033 }
0034 
0035 HGCalParameters::hgtrap HGCalParameters::getModule(unsigned int k, bool reco) const {
0036   HGCalParameters::hgtrap mytr;
0037   if (reco) {
0038     if (k < moduleLayR_.size()) {
0039       mytr.lay = moduleLayR_[k];
0040       mytr.bl = moduleBlR_[k];
0041       mytr.tl = moduleTlR_[k];
0042       mytr.h = moduleHR_[k];
0043       mytr.dz = moduleDzR_[k];
0044       mytr.alpha = moduleAlphaR_[k];
0045       mytr.cellSize = moduleCellR_[k];
0046     } else {
0047       mytr.lay = -1;
0048       mytr.bl = mytr.tl = mytr.h = mytr.dz = mytr.alpha = mytr.cellSize = 0;
0049     }
0050   } else {
0051     if (k < moduleLayS_.size()) {
0052       mytr.lay = moduleLayS_[k];
0053       mytr.bl = moduleBlS_[k];
0054       mytr.tl = moduleTlS_[k];
0055       mytr.h = moduleHS_[k];
0056       mytr.dz = moduleDzS_[k];
0057       mytr.alpha = moduleAlphaS_[k];
0058       mytr.cellSize = moduleCellS_[k];
0059     } else {
0060       mytr.lay = -1;
0061       mytr.bl = mytr.tl = mytr.h = mytr.dz = mytr.alpha = mytr.cellSize = 0;
0062     }
0063   }
0064   return mytr;
0065 }
0066 
0067 void HGCalParameters::fillTrForm(const HGCalParameters::hgtrform& mytr) {
0068   int zp = (mytr.zp == 1) ? 1 : 0;
0069   uint32_t indx = ((zp & kMaskZside) << kShiftZside);
0070   indx |= ((mytr.lay & kMaskLayer) << kShiftLayer);
0071   indx |= ((mytr.sec & kMaskSector) << kShiftSector);
0072   indx |= ((mytr.subsec & kMaskSubSec) << kShiftSubSec);
0073 #ifdef EDM_ML_DEBUG
0074   edm::LogVerbatim("HGCalGeom") << "ZP " << zp << ":" << kMaskZside << ":" << kShiftZside
0075                                 << ((zp & kMaskZside) << kShiftZside) << " Lay " << mytr.lay << ":" << kMaskLayer << ":"
0076                                 << kShiftLayer << ":" << ((mytr.lay & kMaskLayer) << kShiftLayer) << " Sector "
0077                                 << mytr.sec << ":" << kMaskSector << ":" << kShiftSector << ":"
0078                                 << ((mytr.sec & kMaskSector) << kShiftSector) << " SubSec " << mytr.subsec << ":"
0079                                 << kMaskSubSec << ":" << kShiftSubSec << ":"
0080                                 << ((mytr.subsec & kMaskSubSec) << kShiftSubSec) << " Index " << std::hex << indx
0081                                 << std::dec;
0082 #endif
0083   trformIndex_.emplace_back(indx);
0084   trformTranX_.emplace_back(mytr.h3v.x());
0085   trformTranY_.emplace_back(mytr.h3v.y());
0086   trformTranZ_.emplace_back(mytr.h3v.z());
0087   trformRotXX_.emplace_back((std::abs(mytr.hr.xx()) > tol) ? mytr.hr.xx() : 0);
0088   trformRotYX_.emplace_back((std::abs(mytr.hr.yx()) > tol) ? mytr.hr.yx() : 0);
0089   trformRotZX_.emplace_back((std::abs(mytr.hr.zx()) > tol) ? mytr.hr.zx() : 0);
0090   trformRotXY_.emplace_back((std::abs(mytr.hr.xy()) > tol) ? mytr.hr.xy() : 0);
0091   trformRotYY_.emplace_back((std::abs(mytr.hr.yy()) > tol) ? mytr.hr.yy() : 0);
0092   trformRotZY_.emplace_back((std::abs(mytr.hr.zy()) > tol) ? mytr.hr.zy() : 0);
0093   trformRotXZ_.emplace_back((std::abs(mytr.hr.xz()) > tol) ? mytr.hr.xz() : 0);
0094   trformRotYZ_.emplace_back((std::abs(mytr.hr.yz()) > tol) ? mytr.hr.yz() : 0);
0095   trformRotZZ_.emplace_back((std::abs(mytr.hr.zz()) > tol) ? mytr.hr.zz() : 0);
0096 #ifdef EDM_ML_DEBUG
0097   unsigned int k = trformIndex_.size() - 1;
0098   edm::LogVerbatim("HGCalGeom") << "HGCalParameters[" << k << "] Index " << std::hex << trformIndex_[k] << std::dec
0099                                 << " (" << mytr.zp << ", " << mytr.lay << ", " << mytr.sec << ", " << mytr.subsec
0100                                 << ") Translation (" << trformTranX_[k] << ", " << trformTranY_[k] << ", "
0101                                 << trformTranZ_[k] << ") Rotation (" << trformRotXX_[k] << ", " << trformRotYX_[k]
0102                                 << ", " << trformRotZX_[k] << ", " << trformRotXY_[k] << ", " << trformRotYY_[k] << ", "
0103                                 << trformRotZY_[k] << ", " << trformRotXZ_[k] << ", " << trformRotYZ_[k] << ", "
0104                                 << trformRotZZ_[k];
0105 #endif
0106 }
0107 
0108 HGCalParameters::hgtrform HGCalParameters::getTrForm(unsigned int k) const {
0109   HGCalParameters::hgtrform mytr;
0110   if (k < trformIndex_.size()) {
0111     const auto& id = getID(k);
0112     mytr.zp = id[0];
0113     mytr.lay = id[1];
0114     mytr.sec = id[2];
0115     mytr.subsec = id[3];
0116     mytr.h3v = CLHEP::Hep3Vector(trformTranX_[k], trformTranY_[k], trformTranZ_[k]);
0117     const CLHEP::HepRep3x3 rotation(trformRotXX_[k],
0118                                     trformRotXY_[k],
0119                                     trformRotXZ_[k],
0120                                     trformRotYX_[k],
0121                                     trformRotYY_[k],
0122                                     trformRotYZ_[k],
0123                                     trformRotZX_[k],
0124                                     trformRotZY_[k],
0125                                     trformRotZZ_[k]);
0126     mytr.hr = CLHEP::HepRotation(rotation);
0127   } else {
0128     mytr.zp = mytr.lay = mytr.sec = mytr.subsec = 0;
0129   }
0130 #ifdef EDM_ML_DEBUG
0131   edm::LogVerbatim("HGCalGeom") << "HGCalParameters[" << k << "] Index " << std::hex << trformIndex_[k] << std::dec
0132                                 << " (" << mytr.zp << ", " << mytr.lay << ", " << mytr.sec << ", " << mytr.subsec
0133                                 << ") Translation (" << mytr.h3v.x() << ", " << mytr.h3v.y() << ", " << mytr.h3v.z()
0134                                 << ") Rotation (" << mytr.hr.xx() << ", " << mytr.hr.yx() << ", " << mytr.hr.zx()
0135                                 << ", " << mytr.hr.xy() << ", " << mytr.hr.yy() << ", " << mytr.hr.zy() << ", "
0136                                 << mytr.hr.xz() << ", " << mytr.hr.yz() << ", " << mytr.hr.zz();
0137 #endif
0138   return mytr;
0139 }
0140 
0141 void HGCalParameters::addTrForm(const CLHEP::Hep3Vector& h3v) {
0142   unsigned int k = trformTranX_.size();
0143   if (k > 0) {
0144     trformTranX_[k - 1] += h3v.x();
0145     trformTranY_[k - 1] += h3v.y();
0146     trformTranZ_[k - 1] += h3v.z();
0147   }
0148 }
0149 
0150 void HGCalParameters::scaleTrForm(double scale) {
0151   unsigned int k = trformTranX_.size();
0152   if (k > 0) {
0153     trformTranX_[k - 1] *= scale;
0154     trformTranY_[k - 1] *= scale;
0155     trformTranZ_[k - 1] *= scale;
0156   }
0157 }
0158 
0159 std::array<int, 4> HGCalParameters::getID(unsigned int k) const {
0160   int zp = ((trformIndex_[k] >> kShiftZside) & kMaskZside);
0161   if (zp != 1)
0162     zp = -1;
0163   int lay = ((trformIndex_[k] >> kShiftLayer) & kMaskLayer);
0164   int sec = ((trformIndex_[k] >> kShiftSector) & kMaskSector);
0165   int subsec = ((trformIndex_[k] >> kShiftSubSec) & kMaskSubSec);
0166   return std::array<int, 4>{{zp, lay, sec, subsec}};
0167 }
0168 
0169 #include "FWCore/Utilities/interface/typelookup.h"
0170 
0171 TYPELOOKUP_DATA_REG(HGCalParameters);