Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-01-03 23:24:35

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