Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-29 02:25:51

0001 #include "Geometry/HGCalCommonData/interface/HGCalParametersFromDD.h"
0002 
0003 #include "DataFormats/Math/interface/GeantUnits.h"
0004 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0005 #include "DetectorDescription/Core/interface/DDutils.h"
0006 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0007 #include "Geometry/HGCalCommonData/interface/HGCalGeomParameters.h"
0008 #include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h"
0009 #include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
0010 
0011 //#define EDM_ML_DEBUG
0012 using namespace geant_units::operators;
0013 
0014 namespace {
0015   HGCalGeometryMode::GeometryMode getGeometryMode(const char* s, const DDsvalues_type& sv) {
0016     DDValue val(s);
0017     if (DDfetch(&sv, val)) {
0018       const std::vector<std::string>& fvec = val.strings();
0019       if (fvec.empty()) {
0020         throw cms::Exception("HGCalGeom") << "Failed to get " << s << " tag.";
0021       }
0022 
0023       HGCalStringToEnumParser<HGCalGeometryMode::GeometryMode> eparser;
0024       HGCalGeometryMode::GeometryMode result = (HGCalGeometryMode::GeometryMode)eparser.parseString(fvec[0]);
0025       return result;
0026     } else {
0027       throw cms::Exception("HGCalGeom") << "Failed to get " << s << " tag";
0028     }
0029   }
0030   HGCalGeometryMode::GeometryMode getGeometryMode(const std::string& s) {
0031     HGCalStringToEnumParser<HGCalGeometryMode::GeometryMode> eparser;
0032     HGCalGeometryMode::GeometryMode result = (HGCalGeometryMode::GeometryMode)eparser.parseString(s);
0033     return result;
0034   }
0035   HGCalGeometryMode::WaferMode getGeometryWaferMode(const char* s, const DDsvalues_type& sv) {
0036     DDValue val(s);
0037     if (DDfetch(&sv, val)) {
0038       const std::vector<std::string>& fvec = val.strings();
0039       if (fvec.empty()) {
0040         throw cms::Exception("HGCalGeom") << "Failed to get " << s << " tag.";
0041       }
0042 
0043       HGCalStringToEnumParser<HGCalGeometryMode::WaferMode> eparser;
0044       HGCalGeometryMode::WaferMode result = (HGCalGeometryMode::WaferMode)eparser.parseString(fvec[0]);
0045       return result;
0046     } else {
0047       throw cms::Exception("HGCalGeom") << "Failed to get " << s << " tag";
0048     }
0049   }
0050   HGCalGeometryMode::WaferMode getGeometryWaferMode(std::string& s) {
0051     HGCalStringToEnumParser<HGCalGeometryMode::WaferMode> eparser;
0052     HGCalGeometryMode::WaferMode result = (HGCalGeometryMode::WaferMode)eparser.parseString(s);
0053     return result;
0054   }
0055 }  // namespace
0056 
0057 bool HGCalParametersFromDD::build(const DDCompactView* cpv,
0058                                   HGCalParameters& php,
0059                                   const std::string& name,
0060                                   const std::string& namew,
0061                                   const std::string& namec,
0062                                   const std::string& namet) {
0063 #ifdef EDM_ML_DEBUG
0064   edm::LogVerbatim("HGCalGeom") << "HGCalParametersFromDD (DDD)::build called with "
0065                                 << "names " << name << ":" << namew << ":" << namec << ":" << namet;
0066 #endif
0067 
0068   // Special parameters at simulation level
0069   std::string attribute = "Volume";
0070   std::string value = name;
0071   DDValue val(attribute, value, 0.0);
0072   DDSpecificsMatchesValueFilter filter{val};
0073   DDFilteredView fv(*cpv, filter);
0074   bool ok = fv.firstChild();
0075   HGCalGeometryMode::WaferMode mode(HGCalGeometryMode::Polyhedra);
0076 #ifdef EDM_ML_DEBUG
0077   edm::LogVerbatim("HGCalGeom") << "Volume " << name << " GeometryMode ";
0078 #endif
0079   if (ok) {
0080     DDsvalues_type sv(fv.mergedSpecifics());
0081     php.mode_ = getGeometryMode("GeometryMode", sv);
0082 #ifdef EDM_ML_DEBUG
0083     edm::LogVerbatim("HGCalGeom") << "Volume " << name << " GeometryMode " << php.mode_ << ":"
0084                                   << HGCalGeometryMode::Hexagon << ":" << HGCalGeometryMode::HexagonFull << ":"
0085                                   << HGCalGeometryMode::Hexagon8 << ":" << HGCalGeometryMode::Hexagon8Full << ":"
0086                                   << HGCalGeometryMode::Hexagon8File << ":" << HGCalGeometryMode::Hexagon8Module << ":"
0087                                   << HGCalGeometryMode::Trapezoid << ":" << HGCalGeometryMode::TrapezoidFile << ":"
0088                                   << HGCalGeometryMode::TrapezoidModule;
0089 #endif
0090     php.levelZSide_ = 3;        // Default level for ZSide
0091     php.detectorType_ = 0;      // These two parameters are
0092     php.firstMixedLayer_ = -1;  // defined for post TDR geometry
0093     php.useSimWt_ = 1;          // energy weighting for SimHits
0094     php.layerRotation_ = 0;     // default layer rotation angle
0095     php.cassettes_ = 0;         // default number of cassettes
0096     php.nphiCassette_ = 0;      // default number of phi's per cassette
0097     php.phiOffset_ = 0;         // default value of phi offset for cassette
0098     std::unique_ptr<HGCalGeomParameters> geom = std::make_unique<HGCalGeomParameters>();
0099     if ((php.mode_ == HGCalGeometryMode::Hexagon) || (php.mode_ == HGCalGeometryMode::HexagonFull)) {
0100       attribute = "OnlyForHGCalNumbering";
0101       value = namet;
0102       DDValue val2(attribute, value, 0.0);
0103       DDSpecificsMatchesValueFilter filter2{val2};
0104       DDFilteredView fv2(*cpv, filter2);
0105       bool ok2 = fv2.firstChild();
0106       if (ok2) {
0107         DDsvalues_type sv2(fv2.mergedSpecifics());
0108         mode = getGeometryWaferMode("WaferMode", sv2);
0109 #ifdef EDM_ML_DEBUG
0110         edm::LogVerbatim("HGCalGeom") << "WaferMode " << mode << ":" << HGCalGeometryMode::Polyhedra << ":"
0111                                       << HGCalGeometryMode::ExtrudedPolygon;
0112 #endif
0113       }
0114       php.minTileSize_ = 0;
0115       php.waferMaskMode_ = 0;
0116       php.waferZSide_ = 0;
0117     }
0118     if ((php.mode_ == HGCalGeometryMode::Hexagon8) || (php.mode_ == HGCalGeometryMode::Hexagon8Full) ||
0119         (php.mode_ == HGCalGeometryMode::Hexagon8File) || (php.mode_ == HGCalGeometryMode::Hexagon8Module) ||
0120         (php.mode_ == HGCalGeometryMode::Hexagon8Cassette)) {
0121       php.levelT_ = dbl_to_int(getDDDArray("LevelTop", sv));
0122       php.levelZSide_ = static_cast<int>(getDDDValue("LevelZSide", sv));
0123       php.nCellsFine_ = php.nCellsCoarse_ = 0;
0124       php.firstLayer_ = 1;
0125       php.firstMixedLayer_ = static_cast<int>(getDDDValue("FirstMixedLayer", sv));
0126       php.detectorType_ = static_cast<int>(getDDDValue("DetectorType", sv));
0127       php.minTileSize_ = 0;
0128       php.waferMaskMode_ = static_cast<int>(getDDDValue("WaferMaskMode", sv));
0129       php.waferZSide_ = static_cast<int>(getDDDValue("WaferZside", sv));
0130       if ((php.mode_ == HGCalGeometryMode::Hexagon8Module) || (php.mode_ == HGCalGeometryMode::Hexagon8Cassette)) {
0131         php.useSimWt_ = static_cast<int>(getDDDValue("UseSimWt", sv));
0132         php.layerRotation_ = getDDDValue("LayerRotation", sv);
0133       }
0134       if ((php.waferMaskMode_ == HGCalGeomParameters::siliconCassetteEE) ||
0135           (php.waferMaskMode_ == HGCalGeomParameters::siliconCassetteHE))
0136         php.cassettes_ = getDDDValue("Cassettes", sv);
0137 #ifdef EDM_ML_DEBUG
0138       edm::LogVerbatim("HGCalGeom") << "Top levels " << php.levelT_[0] << ":" << php.levelT_[1] << " ZSide Level "
0139                                     << php.levelZSide_ << " first layers " << php.firstLayer_ << ":"
0140                                     << php.firstMixedLayer_ << " Det Type " << php.detectorType_ << " Wafer Mask Mode "
0141                                     << php.waferMaskMode_ << " Zside " << php.waferZSide_ << " Layer Rotation "
0142                                     << convertRadToDeg(php.layerRotation_) << " Cassettes " << php.cassettes_
0143                                     << " UseSimWt " << php.useSimWt_;
0144 #endif
0145       attribute = "OnlyForHGCalNumbering";
0146       value = namet;
0147       DDValue val2(attribute, value, 0.0);
0148       DDSpecificsMatchesValueFilter filter2{val2};
0149       DDFilteredView fv2(*cpv, filter2);
0150       bool ok2 = fv2.firstChild();
0151       if (ok2) {
0152         DDsvalues_type sv2(fv2.mergedSpecifics());
0153         mode = getGeometryWaferMode("WaferMode", sv2);
0154         php.nCellsFine_ = static_cast<int>(getDDDValue("NumberOfCellsFine", sv2));
0155         php.nCellsCoarse_ = static_cast<int>(getDDDValue("NumberOfCellsCoarse", sv2));
0156         php.waferSize_ = HGCalParameters::k_ScaleFromDDD * getDDDValue("WaferSize", sv2);
0157         php.waferThick_ = HGCalParameters::k_ScaleFromDDD * getDDDValue("WaferThickness", sv2);
0158         php.sensorSeparation_ = HGCalParameters::k_ScaleFromDDD * getDDDValue("SensorSeparation", sv2);
0159         php.mouseBite_ = HGCalParameters::k_ScaleFromDDD * getDDDValue("MouseBite", sv2);
0160         php.waferR_ = HGCalParameters::k_ScaleToDDD * php.waferSize_ * tan30deg_;
0161         php.cellSize_.emplace_back(HGCalParameters::k_ScaleToDDD * php.waferSize_ / php.nCellsFine_);
0162         php.cellSize_.emplace_back(HGCalParameters::k_ScaleToDDD * php.waferSize_ / php.nCellsCoarse_);
0163 #ifdef EDM_ML_DEBUG
0164         edm::LogVerbatim("HGCalGeom") << "WaferMode " << mode << ":" << HGCalGeometryMode::Polyhedra << ":"
0165                                       << HGCalGeometryMode::ExtrudedPolygon << " # of cells|size for fine/coarse "
0166                                       << php.nCellsFine_ << ":" << php.cellSize_[0] << ":" << php.nCellsCoarse_ << ":"
0167                                       << php.cellSize_[1] << " wafer Params " << php.waferSize_ << ":" << php.waferR_
0168                                       << ":" << php.waferThick_ << ":" << php.sensorSeparation_ << ":" << php.mouseBite_
0169                                       << ":" << php.waferR_;
0170 #endif
0171         for (int k = 0; k < 2; ++k)
0172           getCellPosition(php, k);
0173       }
0174     }
0175     if (php.mode_ == HGCalGeometryMode::Hexagon) {
0176       // Load the SpecPars
0177       php.firstLayer_ = 1;
0178       geom->loadSpecParsHexagon(fv, php, cpv, namew, namec);
0179       // Load the Geometry parameters
0180       geom->loadGeometryHexagon(fv, php, name, cpv, namew, namec, mode);
0181       // Load cell parameters
0182       geom->loadCellParsHexagon(cpv, php);
0183       // Set complete fill mode
0184       php.defineFull_ = false;
0185     } else if (php.mode_ == HGCalGeometryMode::HexagonFull) {
0186       // Load the SpecPars
0187       php.firstLayer_ = 1;
0188       geom->loadSpecParsHexagon(fv, php, cpv, namew, namec);
0189       // Load the Geometry parameters
0190       geom->loadGeometryHexagon(fv, php, name, cpv, namew, namec, mode);
0191       // Modify some constants
0192       geom->loadWaferHexagon(php);
0193       // Load cell parameters
0194       geom->loadCellParsHexagon(cpv, php);
0195       // Set complete fill mode
0196       php.defineFull_ = true;
0197     } else if (php.mode_ == HGCalGeometryMode::Hexagon8) {
0198       // Load the SpecPars
0199       geom->loadSpecParsHexagon8(fv, php);
0200       // Load Geometry parameters
0201       geom->loadGeometryHexagon8(fv, php, 1);
0202       // Set complete fill mode
0203       php.defineFull_ = false;
0204       // Load wafer positions
0205       geom->loadWaferHexagon8(php);
0206     } else if ((php.mode_ == HGCalGeometryMode::Hexagon8Full) || (php.mode_ == HGCalGeometryMode::Hexagon8File)) {
0207       // Load the SpecPars
0208       geom->loadSpecParsHexagon8(fv, php);
0209       // Load Geometry parameters
0210       geom->loadGeometryHexagon8(fv, php, 1);
0211       // Set complete fill mode
0212       php.defineFull_ = true;
0213       // Load wafer positions
0214       geom->loadWaferHexagon8(php);
0215     } else if ((php.mode_ == HGCalGeometryMode::Hexagon8Module) || (php.mode_ == HGCalGeometryMode::Hexagon8Cassette)) {
0216       // Load the SpecPars
0217       geom->loadSpecParsHexagon8(fv, php);
0218       // Load Geometry parameters
0219       geom->loadGeometryHexagonModule(cpv, php, name, namec, 1);
0220       // Set complete fill mode
0221       php.defineFull_ = true;
0222       // Load wafer positions
0223       geom->loadWaferHexagon8(php);
0224     } else if ((php.mode_ == HGCalGeometryMode::Trapezoid) || (php.mode_ == HGCalGeometryMode::TrapezoidFile) ||
0225                (php.mode_ == HGCalGeometryMode::TrapezoidModule) ||
0226                (php.mode_ == HGCalGeometryMode::TrapezoidCassette)) {
0227       // Load maximum eta & top level
0228       php.levelT_ = dbl_to_int(getDDDArray("LevelTop", sv));
0229       php.firstLayer_ = (int)(getDDDValue("FirstLayer", sv));
0230       php.firstMixedLayer_ = (int)(getDDDValue("FirstMixedLayer", sv));
0231       php.detectorType_ = (int)(getDDDValue("DetectorType", sv));
0232       php.waferThick_ = HGCalParameters::k_ScaleFromDDD * getDDDValue("WaferThickness", sv);
0233       php.minTileSize_ = HGCalParameters::k_ScaleFromDDD * getDDDValue("MinimumTileSize", sv);
0234       php.waferSize_ = php.waferR_ = 0;
0235       php.sensorSeparation_ = php.mouseBite_ = 0;
0236       php.waferMaskMode_ = static_cast<int>(getDDDValue("WaferMaskMode", sv));
0237       php.waferZSide_ = static_cast<int>(getDDDValue("WaferZside", sv));
0238       if ((php.mode_ == HGCalGeometryMode::TrapezoidModule) || (php.mode_ == HGCalGeometryMode::TrapezoidCassette))
0239         php.useSimWt_ = static_cast<int>(getDDDValue("UseSimWt", sv));
0240       if (php.waferMaskMode_ == HGCalGeomParameters::scintillatorCassette)
0241         php.cassettes_ = getDDDValue("Cassettes", sv);
0242 #ifdef EDM_ML_DEBUG
0243       edm::LogVerbatim("HGCalGeom") << "Top levels " << php.levelT_[0] << ":" << php.levelT_[1] << " first layers "
0244                                     << php.firstLayer_ << ":" << php.firstMixedLayer_ << " Det Type "
0245                                     << php.detectorType_ << "  thickenss " << php.waferThick_ << " Tile Mask Mode "
0246                                     << php.waferMaskMode_ << " Zside " << php.waferZSide_ << " Cassettes "
0247                                     << php.cassettes_ << " UseSimWt " << php.useSimWt_;
0248 #endif
0249       // Load the SpecPars
0250       geom->loadSpecParsTrapezoid(fv, php);
0251       // Load Geometry parameters
0252       geom->loadGeometryHexagon8(fv, php, php.firstLayer_);
0253       // Load cell positions
0254       geom->loadCellTrapezoid(php);
0255     } else {
0256       edm::LogError("HGCalGeom") << "Unknown Geometry type " << php.mode_ << " for HGCal " << name << ":" << namew
0257                                  << ":" << namec;
0258       throw cms::Exception("DDException")
0259           << "Unknown Geometry type " << php.mode_ << " for HGCal " << name << ":" << namew << ":" << namec;
0260     }
0261   } else {
0262     edm::LogError("HGCalGeom") << " Attribute " << val << " not found but needed.";
0263     throw cms::Exception("DDException") << "Attribute " << val << " not found but needed.";
0264   }
0265 #ifdef EDM_ML_DEBUG
0266   edm::LogVerbatim("HGCalGeom") << "Return from HGCalParametersFromDD::build"
0267                                 << " with flag " << ok;
0268 #endif
0269   return ok;
0270 }
0271 
0272 bool HGCalParametersFromDD::build(const cms::DDCompactView* cpv,
0273                                   HGCalParameters& php,
0274                                   const std::string& name,
0275                                   const std::string& namew,
0276                                   const std::string& namec,
0277                                   const std::string& namet,
0278                                   const std::string& name2) {
0279 #ifdef EDM_ML_DEBUG
0280   edm::LogVerbatim("HGCalGeom") << "HGCalParametersFromDD (DD4hep)::build called with "
0281                                 << "names " << name << ":" << namew << ":" << namec << ":" << namet << ":" << name2;
0282 #endif
0283   cms::DDVectorsMap vmap = cpv->detector()->vectors();
0284   const cms::DDFilter filter("Volume", name);
0285   cms::DDFilteredView fv((*cpv), filter);
0286   std::vector<std::string> tempS;
0287   std::vector<double> tempD;
0288   bool ok = fv.firstChild();
0289   tempS = fv.get<std::vector<std::string> >(name2, "GeometryMode");
0290   if (tempS.empty()) {
0291     tempS = fv.get<std::vector<std::string> >(name, "GeometryMode");
0292   }
0293   std::string sv = (!tempS.empty()) ? tempS[0] : "HGCalGeometryMode::Hexagon8Full";
0294   HGCalGeometryMode::WaferMode mode(HGCalGeometryMode::Polyhedra);
0295 #ifdef EDM_ML_DEBUG
0296   edm::LogVerbatim("HGCalGeom") << "Volume " << name << " GeometryMode ";
0297 #endif
0298 
0299   if (ok) {
0300     php.mode_ = getGeometryMode(sv);
0301 #ifdef EDM_ML_DEBUG
0302     edm::LogVerbatim("HGCalGeom") << "Volume " << name << " GeometryMode " << php.mode_ << ":"
0303                                   << HGCalGeometryMode::Hexagon << ":" << HGCalGeometryMode::HexagonFull << ":"
0304                                   << HGCalGeometryMode::Hexagon8 << ":" << HGCalGeometryMode::Hexagon8Full << ":"
0305                                   << HGCalGeometryMode::Hexagon8File << ":" << HGCalGeometryMode::Hexagon8Module << ":"
0306                                   << HGCalGeometryMode::Trapezoid << ":" << HGCalGeometryMode::TrapezoidFile << ":"
0307                                   << HGCalGeometryMode::TrapezoidModule << ":" << HGCalGeometryMode::Hexagon8Cassette
0308                                   << ":" << HGCalGeometryMode::TrapezoidCassette;
0309 #endif
0310     php.levelZSide_ = 3;        // Default level for ZSide
0311     php.detectorType_ = 0;      // These two parameters are
0312     php.firstMixedLayer_ = -1;  // defined for post TDR geometry
0313     php.useSimWt_ = 1;          // energy weighting for SimHits
0314     php.layerRotation_ = 0;     // default layer rotation angle
0315     php.cassettes_ = 0;         // default number of cassettes
0316     std::unique_ptr<HGCalGeomParameters> geom = std::make_unique<HGCalGeomParameters>();
0317     if ((php.mode_ == HGCalGeometryMode::Hexagon) || (php.mode_ == HGCalGeometryMode::HexagonFull)) {
0318       tempS = fv.get<std::vector<std::string> >(namet, "WaferMode");
0319       std::string sv2 = (!tempS.empty()) ? tempS[0] : "HGCalGeometryMode::Polyhedra";
0320       mode = getGeometryWaferMode(sv2);
0321 #ifdef EDM_ML_DEBUG
0322       edm::LogVerbatim("HGCalGeom") << "WaferMode " << mode << ":" << HGCalGeometryMode::Polyhedra << ":"
0323                                     << HGCalGeometryMode::ExtrudedPolygon;
0324 #endif
0325       php.minTileSize_ = 0;
0326       php.waferMaskMode_ = 0;
0327       php.waferZSide_ = 0;
0328     }
0329     if ((php.mode_ == HGCalGeometryMode::Hexagon8) || (php.mode_ == HGCalGeometryMode::Hexagon8Full) ||
0330         (php.mode_ == HGCalGeometryMode::Hexagon8File) || (php.mode_ == HGCalGeometryMode::Hexagon8Module) ||
0331         (php.mode_ == HGCalGeometryMode::Hexagon8Cassette)) {
0332       php.levelT_ = dbl_to_int(fv.get<std::vector<double> >(name, "LevelTop"));
0333       tempD = fv.get<std::vector<double> >(name, "LevelZSide");
0334       php.levelZSide_ = static_cast<int>(tempD[0]);
0335       php.nCellsFine_ = php.nCellsCoarse_ = 0;
0336       php.firstLayer_ = 1;
0337       tempD = fv.get<std::vector<double> >(name, "FirstMixedLayer");
0338       php.firstMixedLayer_ = static_cast<int>(tempD[0]);
0339       tempD = fv.get<std::vector<double> >(name, "DetectorType");
0340       php.detectorType_ = static_cast<int>(tempD[0]);
0341       php.minTileSize_ = 0;
0342       tempD = fv.get<std::vector<double> >(name, "WaferMaskMode");
0343       php.waferMaskMode_ = static_cast<int>(tempD[0]);
0344       tempD = fv.get<std::vector<double> >(name, "WaferZside");
0345       php.waferZSide_ = static_cast<int>(tempD[0]);
0346       if ((php.mode_ == HGCalGeometryMode::Hexagon8Module) || (php.mode_ == HGCalGeometryMode::Hexagon8Cassette)) {
0347         tempD = fv.get<std::vector<double> >(name, "LayerRotation");
0348         php.layerRotation_ = tempD[0];
0349         tempD = fv.get<std::vector<double> >(name, "UseSimWt");
0350         php.useSimWt_ = tempD[0];
0351       }
0352       if ((php.waferMaskMode_ == HGCalGeomParameters::siliconCassetteEE) ||
0353           (php.waferMaskMode_ == HGCalGeomParameters::siliconCassetteHE)) {
0354         tempD = fv.get<std::vector<double> >(name, "Cassettes");
0355         php.cassettes_ = static_cast<int>(tempD[0]);
0356       }
0357 #ifdef EDM_ML_DEBUG
0358       edm::LogVerbatim("HGCalGeom") << "Top levels " << php.levelT_[0] << ":" << php.levelT_[1] << " ZSide Level "
0359                                     << php.levelZSide_ << " first layers " << php.firstLayer_ << ":"
0360                                     << php.firstMixedLayer_ << " Det Type " << php.detectorType_ << " Wafer Mask Mode "
0361                                     << php.waferMaskMode_ << " ZSide " << php.waferZSide_ << " Layer Rotation "
0362                                     << convertRadToDeg(php.layerRotation_) << " Cassettes " << php.cassettes_
0363                                     << " UseSimWt " << php.useSimWt_;
0364 #endif
0365 
0366       tempS = fv.get<std::vector<std::string> >(namet, "WaferMode");
0367       std::string sv2 = (!tempS.empty()) ? tempS[0] : "HGCalGeometryMode::ExtrudedPolygon";
0368       mode = getGeometryWaferMode(sv2);
0369       tempD = fv.get<std::vector<double> >(namet, "NumberOfCellsFine");
0370       php.nCellsFine_ = static_cast<int>(tempD[0]);
0371       tempD = fv.get<std::vector<double> >(namet, "NumberOfCellsCoarse");
0372       php.nCellsCoarse_ = static_cast<int>(tempD[0]);
0373       tempD = fv.get<std::vector<double> >(namet, "WaferSize");
0374       php.waferSize_ = HGCalParameters::k_ScaleFromDD4hep * tempD[0];
0375       tempD = fv.get<std::vector<double> >(namet, "WaferThickness");
0376       php.waferThick_ = HGCalParameters::k_ScaleFromDD4hep * tempD[0];
0377       tempD = fv.get<std::vector<double> >(namet, "SensorSeparation");
0378       php.sensorSeparation_ = HGCalParameters::k_ScaleFromDD4hep * tempD[0];
0379       tempD = fv.get<std::vector<double> >(namet, "MouseBite");
0380       php.mouseBite_ = HGCalParameters::k_ScaleFromDD4hep * tempD[0];
0381       php.waferR_ = HGCalParameters::k_ScaleToDDD * php.waferSize_ * tan30deg_;
0382       php.cellSize_.emplace_back(HGCalParameters::k_ScaleToDDD * php.waferSize_ / php.nCellsFine_);
0383       php.cellSize_.emplace_back(HGCalParameters::k_ScaleToDDD * php.waferSize_ / php.nCellsCoarse_);
0384 #ifdef EDM_ML_DEBUG
0385       edm::LogVerbatim("HGCalGeom") << "WaferMode " << mode << ":" << HGCalGeometryMode::Polyhedra << ":"
0386                                     << HGCalGeometryMode::ExtrudedPolygon << " # of cells|size for fine/coarse "
0387                                     << php.nCellsFine_ << ":" << php.cellSize_[0] << ":" << php.nCellsCoarse_ << ":"
0388                                     << php.cellSize_[1] << " wafer Params " << php.waferSize_ << ":" << php.waferR_
0389                                     << ":" << php.waferThick_ << ":" << php.sensorSeparation_ << ":" << php.mouseBite_
0390                                     << ":" << php.waferR_;
0391 #endif
0392       for (int k = 0; k < 2; ++k)
0393         getCellPosition(php, k);
0394     }
0395     if (php.mode_ == HGCalGeometryMode::Hexagon) {
0396       // Load the SpecPars
0397       php.firstLayer_ = 1;
0398       geom->loadSpecParsHexagon(fv, php, name, namew, namec, name2);
0399       // Load the Geometry parameters
0400       geom->loadGeometryHexagon(cpv, php, name, namew, namec, mode);
0401       // Load cell parameters
0402       geom->loadCellParsHexagon(vmap, php);
0403       // Set complete fill mode
0404       php.defineFull_ = false;
0405     } else if (php.mode_ == HGCalGeometryMode::HexagonFull) {
0406       // Load the SpecPars
0407       php.firstLayer_ = 1;
0408       geom->loadSpecParsHexagon(fv, php, name, namew, namec, name2);
0409       // Load the Geometry parameters
0410       geom->loadGeometryHexagon(cpv, php, name, namew, namec, mode);
0411       // Modify some constants
0412       geom->loadWaferHexagon(php);
0413       // Load cell parameters
0414       geom->loadCellParsHexagon(vmap, php);
0415       // Set complete fill mode
0416       php.defineFull_ = true;
0417     } else if (php.mode_ == HGCalGeometryMode::Hexagon8) {
0418       // Load the SpecPars
0419       geom->loadSpecParsHexagon8(fv, vmap, php, name);
0420       // Load Geometry parameters
0421       geom->loadGeometryHexagon8(cpv, php, name, 1);
0422       // Set complete fill mode
0423       php.defineFull_ = false;
0424       // Load wafer positions
0425       geom->loadWaferHexagon8(php);
0426     } else if ((php.mode_ == HGCalGeometryMode::Hexagon8Full) || (php.mode_ == HGCalGeometryMode::Hexagon8File)) {
0427       // Load the SpecPars
0428       geom->loadSpecParsHexagon8(fv, vmap, php, name);
0429       // Load Geometry parameters
0430       geom->loadGeometryHexagon8(cpv, php, name, 1);
0431       // Set complete fill mode
0432       php.defineFull_ = true;
0433       // Load wafer positions
0434       geom->loadWaferHexagon8(php);
0435     } else if ((php.mode_ == HGCalGeometryMode::Hexagon8Module) || (php.mode_ == HGCalGeometryMode::Hexagon8Cassette)) {
0436       // Load the SpecPars
0437       geom->loadSpecParsHexagon8(fv, vmap, php, name);
0438       // Load Geometry parameters
0439       geom->loadGeometryHexagonModule(cpv, php, name, namec, 1);
0440       // Set complete fill mode
0441       php.defineFull_ = true;
0442       // Load wafer positions
0443       geom->loadWaferHexagon8(php);
0444     } else if ((php.mode_ == HGCalGeometryMode::Trapezoid) || (php.mode_ == HGCalGeometryMode::TrapezoidFile) ||
0445                (php.mode_ == HGCalGeometryMode::TrapezoidModule) ||
0446                (php.mode_ == HGCalGeometryMode::TrapezoidCassette)) {
0447       // Load maximum eta & top level
0448       php.levelT_ = dbl_to_int(fv.get<std::vector<double> >(name, "LevelTop"));
0449       tempD = fv.get<std::vector<double> >(name, "LevelZSide");
0450       php.levelZSide_ = static_cast<int>(tempD[0]);
0451       php.nCellsFine_ = php.nCellsCoarse_ = 0;
0452       tempD = fv.get<std::vector<double> >(name, "FirstLayer");
0453       php.firstLayer_ = static_cast<int>(tempD[0]);
0454       tempD = fv.get<std::vector<double> >(name, "FirstMixedLayer");
0455       php.firstMixedLayer_ = static_cast<int>(tempD[0]);
0456       tempD = fv.get<std::vector<double> >(name, "DetectorType");
0457       php.detectorType_ = static_cast<int>(tempD[0]);
0458       tempD = fv.get<std::vector<double> >(name, "WaferThickness");
0459       php.waferThick_ = HGCalParameters::k_ScaleFromDD4hep * tempD[0];
0460       tempD = fv.get<std::vector<double> >(name, "MinimumTileSize");
0461       php.minTileSize_ = HGCalParameters::k_ScaleFromDD4hep * tempD[0];
0462       php.waferSize_ = php.waferR_ = 0;
0463       php.sensorSeparation_ = php.mouseBite_ = 0;
0464       tempD = fv.get<std::vector<double> >(name, "WaferMaskMode");
0465       php.waferMaskMode_ = static_cast<int>(tempD[0]);
0466       tempD = fv.get<std::vector<double> >(name, "WaferZside");
0467       php.waferZSide_ = static_cast<int>(tempD[0]);
0468       if ((php.mode_ == HGCalGeometryMode::TrapezoidModule) || (php.mode_ == HGCalGeometryMode::TrapezoidCassette)) {
0469         tempD = fv.get<std::vector<double> >(name, "UseSimWt");
0470         php.useSimWt_ = tempD[0];
0471       }
0472       if (php.waferMaskMode_ == HGCalGeomParameters::scintillatorCassette) {
0473         tempD = fv.get<std::vector<double> >(name, "Cassettes");
0474         php.cassettes_ = static_cast<int>(tempD[0]);
0475       }
0476 #ifdef EDM_ML_DEBUG
0477       edm::LogVerbatim("HGCalGeom") << "Top levels " << php.levelT_[0] << ":" << php.levelT_[1] << " first layers "
0478                                     << php.firstLayer_ << ":" << php.firstMixedLayer_ << " Det Type "
0479                                     << php.detectorType_ << "  thickenss " << php.waferThick_ << " min tile size "
0480                                     << php.minTileSize_ << " Tile Mask Mode " << php.waferMaskMode_ << " ZSide "
0481                                     << php.waferZSide_ << " Cassettes " << php.cassettes_ << " UseSimWt "
0482                                     << php.useSimWt_;
0483 #endif
0484       // Load the SpecPars
0485       geom->loadSpecParsTrapezoid(fv, vmap, php, name);
0486       // Load Geometry parameters
0487       geom->loadGeometryHexagon8(cpv, php, name, php.firstLayer_);
0488       // Load cell positions
0489       geom->loadCellTrapezoid(php);
0490     } else {
0491       edm::LogError("HGCalGeom") << "Unknown Geometry type " << php.mode_ << " for HGCal " << name << ":" << namew
0492                                  << ":" << namec;
0493       throw cms::Exception("DDException")
0494           << "Unknown Geometry type " << php.mode_ << " for HGCal " << name << ":" << namew << ":" << namec;
0495     }
0496   } else {
0497     edm::LogError("HGCalGeom") << " Attribute Volume:" << name << " not found but needed.";
0498     throw cms::Exception("DDException") << "Attribute Volume:" << name << " not found but needed.";
0499   }
0500 #ifdef EDM_ML_DEBUG
0501   edm::LogVerbatim("HGCalGeom") << "Return from HGCalParametersFromDD::build"
0502                                 << " with flag " << ok;
0503 #endif
0504   return ok;
0505 }
0506 
0507 void HGCalParametersFromDD::getCellPosition(HGCalParameters& php, int type) {
0508   if (type == 1) {
0509     php.cellCoarseX_.clear();
0510     php.cellCoarseY_.clear();
0511   } else {
0512     php.cellFineX_.clear();
0513     php.cellFineY_.clear();
0514   }
0515   HGCalParameters::wafer_map cellIndex;
0516 #ifdef EDM_ML_DEBUG
0517   std::vector<int> indtypes;
0518 #endif
0519   int N = (type == 1) ? php.nCellsCoarse_ : php.nCellsFine_;
0520   double R = php.waferSize_ / (3 * N);
0521   double r = 0.5 * R * sqrt(3.0);
0522   int n2 = N / 2;
0523   int ipos(0);
0524   for (int u = 0; u < 2 * N; ++u) {
0525     for (int v = 0; v < 2 * N; ++v) {
0526       if (((v - u) < N) && (u - v) <= N) {
0527         double yp = (u - 0.5 * v - n2) * 2 * r;
0528         double xp = (1.5 * (v - N) + 1.0) * R;
0529         int id = v * 100 + u;
0530 #ifdef EDM_ML_DEBUG
0531         indtypes.emplace_back(id);
0532 #endif
0533         if (type == 1) {
0534           php.cellCoarseX_.emplace_back(xp);
0535           php.cellCoarseY_.emplace_back(yp);
0536         } else {
0537           php.cellFineX_.emplace_back(xp);
0538           php.cellFineY_.emplace_back(yp);
0539         }
0540         cellIndex[id] = ipos;
0541         ++ipos;
0542       }
0543     }
0544   }
0545   if (type == 1)
0546     php.cellCoarseIndex_ = cellIndex;
0547   else
0548     php.cellFineIndex_ = cellIndex;
0549 
0550 #ifdef EDM_ML_DEBUG
0551   if (type == 1) {
0552     edm::LogVerbatim("HGCalGeom") << "CellPosition for  type " << type << " for " << php.cellCoarseX_.size()
0553                                   << " cells";
0554     for (unsigned int k = 0; k < php.cellCoarseX_.size(); ++k) {
0555       int id = indtypes[k];
0556       edm::LogVerbatim("HGCalGeom") << "[" << k << "] ID " << id << ":" << php.cellCoarseIndex_[id] << " X "
0557                                     << php.cellCoarseX_[k] << " Y " << php.cellCoarseY_[k];
0558     }
0559   } else {
0560     edm::LogVerbatim("HGCalGeom") << "CellPosition for  type " << type << " for " << php.cellFineX_.size() << " cells";
0561     for (unsigned int k = 0; k < php.cellFineX_.size(); ++k) {
0562       int id = indtypes[k];
0563       edm::LogVerbatim("HGCalGeom") << "[" << k << "] ID " << id << ":" << php.cellFineIndex_[k] << " X "
0564                                     << php.cellFineX_[k] << " Y " << php.cellFineY_[k];
0565     }
0566   }
0567 #endif
0568 }
0569 
0570 double HGCalParametersFromDD::getDDDValue(const char* s, const DDsvalues_type& sv) {
0571   DDValue val(s);
0572   if (DDfetch(&sv, val)) {
0573     const std::vector<double>& fvec = val.doubles();
0574     if (fvec.empty()) {
0575       throw cms::Exception("HGCalGeom") << "Failed to get " << s << " tag.";
0576     }
0577     return fvec[0];
0578   } else {
0579     throw cms::Exception("HGCalGeom") << "Failed to get " << s << " tag";
0580   }
0581 }
0582 
0583 std::vector<double> HGCalParametersFromDD::getDDDArray(const char* s, const DDsvalues_type& sv) {
0584   DDValue val(s);
0585   if (DDfetch(&sv, val)) {
0586     const std::vector<double>& fvec = val.doubles();
0587     if (fvec.empty()) {
0588       throw cms::Exception("HGCalGeom") << "Failed to get " << s << " tag.";
0589     }
0590     return fvec;
0591   } else {
0592     throw cms::Exception("HGCalGeom") << "Failed to get " << s << " tag";
0593   }
0594 }