Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-06 07:38:36

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