Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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