Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-24 22:29:48

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDHGCalMixLayer.cc
0003 // Description: Geometry factory class for HGCal (Mix) adopted for DD4hep
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include <cmath>
0007 #include <memory>
0008 #include <string>
0009 #include <unordered_set>
0010 #include <vector>
0011 
0012 #include "Geometry/HGCalCommonData/interface/HGCalGeomTools.h"
0013 #include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
0014 #include "Geometry/HGCalCommonData/interface/HGCalProperty.h"
0015 #include "Geometry/HGCalCommonData/interface/HGCalTileIndex.h"
0016 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0017 #include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h"
0018 #include "Geometry/HGCalCommonData/interface/HGCalWaferType.h"
0019 #include "DD4hep/DetFactoryHelper.h"
0020 #include "DataFormats/Math/interface/angle_units.h"
0021 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0022 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 
0025 //#define EDM_ML_DEBUG
0026 using namespace angle_units::operators;
0027 
0028 struct HGCalMixLayer {
0029   HGCalMixLayer() { throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalMixLayer"; }
0030   HGCalMixLayer(cms::DDParsingContext& ctxt, xml_h e) {
0031     cms::DDNamespace ns(ctxt, e, true);
0032     cms::DDAlgoArguments args(ctxt, e);
0033 
0034 #ifdef EDM_ML_DEBUG
0035     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Creating an instance";
0036 #endif
0037 
0038     static constexpr double tol1 = 0.01 * dd4hep::mm;
0039     dd4hep::Volume mother = ns.volume(args.parentName());
0040 
0041     waferTypes_ = args.value<int>("WaferTypes");
0042     facingTypes_ = args.value<int>("FacingTypes");
0043     partialTypes_ = args.value<int>("PartialTypes");
0044     orientationTypes_ = args.value<int>("OrientationTypes");
0045     phiBinsScint_ = args.value<int>("NPhiBinScint");
0046 #ifdef EDM_ML_DEBUG
0047     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer::Number of types of wafers: " << waferTypes_
0048                                   << " facings: " << facingTypes_ << " partials: " << partialTypes_
0049                                   << " Orientations: " << orientationTypes_ << "; number of cells along phi "
0050                                   << phiBinsScint_;
0051 #endif
0052     firstLayer_ = args.value<int>("FirstLayer");
0053     absorbMode_ = args.value<int>("AbsorberMode");
0054     sensitiveMode_ = args.value<int>("SensitiveMode");
0055 #ifdef EDM_ML_DEBUG
0056     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer::First Layer " << firstLayer_ << " and "
0057                                   << "Absober:Sensitive mode " << absorbMode_ << ":" << sensitiveMode_;
0058 #endif
0059     zMinBlock_ = args.value<double>("zMinBlock");
0060     waferSize_ = args.value<double>("waferSize");
0061     waferSepar_ = args.value<double>("SensorSeparation");
0062     sectors_ = args.value<int>("Sectors");
0063     alpha_ = (1._pi) / sectors_;
0064     cosAlpha_ = cos(alpha_);
0065 #ifdef EDM_ML_DEBUG
0066     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: zStart " << cms::convert2mm(zMinBlock_) << " wafer width "
0067                                   << cms::convert2mm(waferSize_) << " separations " << cms::convert2mm(waferSepar_)
0068                                   << " sectors " << sectors_ << ":" << convertRadToDeg(alpha_) << ":" << cosAlpha_;
0069 #endif
0070     slopeB_ = args.value<std::vector<double>>("SlopeBottom");
0071     zFrontB_ = args.value<std::vector<double>>("ZFrontBottom");
0072     rMinFront_ = args.value<std::vector<double>>("RMinFront");
0073     slopeT_ = args.value<std::vector<double>>("SlopeTop");
0074     zFrontT_ = args.value<std::vector<double>>("ZFrontTop");
0075     rMaxFront_ = args.value<std::vector<double>>("RMaxFront");
0076 #ifdef EDM_ML_DEBUG
0077     for (unsigned int i = 0; i < slopeB_.size(); ++i)
0078       edm::LogVerbatim("HGCalGeom") << "Bottom Block [" << i << "] Zmin " << cms::convert2mm(zFrontB_[i]) << " Rmin "
0079                                     << cms::convert2mm(rMinFront_[i]) << " Slope " << slopeB_[i];
0080     for (unsigned int i = 0; i < slopeT_.size(); ++i)
0081       edm::LogVerbatim("HGCalGeom") << "Top Block [" << i << "] Zmin " << cms::convert2mm(zFrontT_[i]) << " Rmax "
0082                                     << cms::convert2mm(rMaxFront_[i]) << " Slope " << slopeT_[i];
0083 #endif
0084 
0085     waferFull_ = args.value<std::vector<std::string>>("WaferNamesFull");
0086     waferPart_ = args.value<std::vector<std::string>>("WaferNamesPartial");
0087 #ifdef EDM_ML_DEBUG
0088     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << waferFull_.size() << " full and " << waferPart_.size()
0089                                   << " partial modules\nDDHGCalMixLayer:Full Modules:";
0090     unsigned int i1max = static_cast<unsigned int>(waferFull_.size());
0091     for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
0092       std::ostringstream st1;
0093       unsigned int i2 = std::min((i1 + 2), i1max);
0094       for (unsigned int i = i1; i < i2; ++i)
0095         st1 << " [" << i << "] " << waferFull_[i];
0096       edm::LogVerbatim("HGCalGeom") << st1.str() << std::endl;
0097     }
0098     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Partial Modules:";
0099     i1max = static_cast<unsigned int>(waferPart_.size());
0100     for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
0101       std::ostringstream st1;
0102       unsigned int i2 = std::min((i1 + 2), i1max);
0103       for (unsigned int i = i1; i < i2; ++i)
0104         st1 << " [" << i << "] " << waferPart_[i];
0105       edm::LogVerbatim("HGCalGeom") << st1.str() << std::endl;
0106     }
0107 #endif
0108 
0109     materials_ = args.value<std::vector<std::string>>("MaterialNames");
0110     names_ = args.value<std::vector<std::string>>("VolumeNames");
0111     thick_ = args.value<std::vector<double>>("Thickness");
0112     copyNumber_.resize(materials_.size(), 1);
0113 #ifdef EDM_ML_DEBUG
0114     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << materials_.size() << " types of volumes";
0115     for (unsigned int i = 0; i < names_.size(); ++i)
0116       edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names_[i] << " of thickness "
0117                                     << cms::convert2mm(thick_[i]) << " filled with " << materials_[i]
0118                                     << " first copy number " << copyNumber_[i];
0119 #endif
0120     layers_ = args.value<std::vector<int>>("Layers");
0121     layerThick_ = args.value<std::vector<double>>("LayerThick");
0122 #ifdef EDM_ML_DEBUG
0123     edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks";
0124     for (unsigned int i = 0; i < layers_.size(); ++i)
0125       edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << cms::convert2mm(layerThick_[i])
0126                                     << " with " << layers_[i] << " layers";
0127 #endif
0128     layerType_ = args.value<std::vector<int>>("LayerType");
0129     layerSense_ = args.value<std::vector<int>>("LayerSense");
0130     layerOrient_ = args.value<std::vector<int>>("LayerTypes");
0131     for (unsigned int k = 0; k < layerOrient_.size(); ++k)
0132       layerOrient_[k] = HGCalTypes::layerType(layerOrient_[k]);
0133 #ifdef EDM_ML_DEBUG
0134     for (unsigned int i = 0; i < layerOrient_.size(); ++i)
0135       edm::LogVerbatim("HGCalGeom") << "LayerTypes [" << i << "] " << layerOrient_[i];
0136 #endif
0137     if (firstLayer_ > 0) {
0138       for (unsigned int i = 0; i < layerType_.size(); ++i) {
0139         if (layerSense_[i] > 0) {
0140           int ii = layerType_[i];
0141           copyNumber_[ii] = firstLayer_;
0142 #ifdef EDM_ML_DEBUG
0143           edm::LogVerbatim("HGCalGeom") << "First copy number for layer type " << i << ":" << ii << " with "
0144                                         << materials_[ii] << " changed to " << copyNumber_[ii];
0145 #endif
0146           break;
0147         }
0148       }
0149     } else {
0150       firstLayer_ = 1;
0151     }
0152 #ifdef EDM_ML_DEBUG
0153     edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " layers";
0154     for (unsigned int i = 0; i < layerType_.size(); ++i)
0155       edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType_[i] << " sensitive class "
0156                                     << layerSense_[i];
0157 #endif
0158     materialTop_ = args.value<std::vector<std::string>>("TopMaterialNames");
0159     namesTop_ = args.value<std::vector<std::string>>("TopVolumeNames");
0160     layerThickTop_ = args.value<std::vector<double>>("TopLayerThickness");
0161     layerTypeTop_ = args.value<std::vector<int>>("TopLayerType");
0162     copyNumberTop_.resize(materialTop_.size(), firstLayer_);
0163 #ifdef EDM_ML_DEBUG
0164     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << materialTop_.size() << " types of volumes in the top part";
0165     for (unsigned int i = 0; i < materialTop_.size(); ++i)
0166       edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << namesTop_[i] << " of thickness "
0167                                     << cms::convert2mm(layerThickTop_[i]) << " filled with " << materialTop_[i]
0168                                     << " first copy number " << copyNumberTop_[i];
0169     edm::LogVerbatim("HGCalGeom") << "There are " << layerTypeTop_.size() << " layers in the top part";
0170     for (unsigned int i = 0; i < layerTypeTop_.size(); ++i)
0171       edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerTypeTop_[i];
0172 #endif
0173     waferIndex_ = args.value<std::vector<int>>("WaferIndex");
0174     waferProperty_ = args.value<std::vector<int>>("WaferProperties");
0175     waferLayerStart_ = args.value<std::vector<int>>("WaferLayerStart");
0176 #ifdef EDM_ML_DEBUG
0177     edm::LogVerbatim("HGCalGeom") << "waferProperties with " << waferIndex_.size() << " entries in "
0178                                   << waferLayerStart_.size() << " layers";
0179     for (unsigned int k = 0; k < waferLayerStart_.size(); ++k)
0180       edm::LogVerbatim("HGCalGeom") << "LayerStart[" << k << "] " << waferLayerStart_[k];
0181     for (unsigned int k = 0; k < waferIndex_.size(); ++k)
0182       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << waferIndex_[k] << " ("
0183                                     << HGCalWaferIndex::waferLayer(waferIndex_[k]) << ", "
0184                                     << HGCalWaferIndex::waferU(waferIndex_[k]) << ", "
0185                                     << HGCalWaferIndex::waferV(waferIndex_[k]) << ") : ("
0186                                     << HGCalProperty::waferThick(waferProperty_[k]) << ":"
0187                                     << HGCalProperty::waferPartial(waferProperty_[k]) << ":"
0188                                     << HGCalProperty::waferOrient(waferProperty_[k]) << ")";
0189 #endif
0190     tileRMin_ = args.value<std::vector<double>>("TileRMin");
0191     tileRMax_ = args.value<std::vector<double>>("TileRMax");
0192     tileIndex_ = args.value<std::vector<int>>("TileLayerRings");
0193     tilePhis_ = args.value<std::vector<int>>("TilePhiRange");
0194     tileLayerStart_ = args.value<std::vector<int>>("TileLayerStart");
0195 #ifdef EDM_ML_DEBUG
0196     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer:: with " << tileRMin_.size() << " rings";
0197     for (unsigned int k = 0; k < tileRMin_.size(); ++k)
0198       edm::LogVerbatim("HGCalGeom") << "Ring[" << k << "] " << cms::convert2mm(tileRMin_[k]) << " : "
0199                                     << cms::convert2mm(tileRMax_[k]);
0200     edm::LogVerbatim("HGCalGeom") << "TileProperties with " << tileIndex_.size() << " entries in "
0201                                   << tileLayerStart_.size() << " layers";
0202     for (unsigned int k = 0; k < tileLayerStart_.size(); ++k)
0203       edm::LogVerbatim("HGCalGeom") << "LayerStart[" << k << "] " << tileLayerStart_[k];
0204     for (unsigned int k = 0; k < tileIndex_.size(); ++k)
0205       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << tileIndex_[k] << " ("
0206                                     << "Layer " << std::get<0>(HGCalTileIndex::tileUnpack(tileIndex_[k])) << " Ring "
0207                                     << std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[k])) << ":"
0208                                     << std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[k])) << ") Phi "
0209                                     << std::get<1>(HGCalTileIndex::tileUnpack(tilePhis_[k])) << ":"
0210                                     << std::get<2>(HGCalTileIndex::tileUnpack(tilePhis_[k]));
0211 #endif
0212 
0213 #ifdef EDM_ML_DEBUG
0214     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: NameSpace " << ns.name();
0215 
0216     edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalMixLayer...";
0217     copies_.clear();
0218 #endif
0219 
0220     double zi(zMinBlock_);
0221     int laymin(0);
0222     for (unsigned int i = 0; i < layers_.size(); i++) {
0223       double zo = zi + layerThick_[i];
0224       double routF = HGCalGeomTools::radius(zi, zFrontT_, rMaxFront_, slopeT_);
0225       int laymax = laymin + layers_[i];
0226       double zz = zi;
0227       double thickTot(0);
0228       for (int ly = laymin; ly < laymax; ++ly) {
0229         int ii = layerType_[ly];
0230         int copy = copyNumber_[ii];
0231         double hthick = 0.5 * thick_[ii];
0232         double rinB = HGCalGeomTools::radius(zo, zFrontB_, rMinFront_, slopeB_);
0233         zz += hthick;
0234         thickTot += thick_[ii];
0235 
0236         std::string name = names_[ii] + std::to_string(copy);
0237 #ifdef EDM_ML_DEBUG
0238         edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Layer " << ly << ":" << ii << " Front "
0239                                       << cms::convert2mm(zi) << ", " << cms::convert2mm(routF) << " Back "
0240                                       << cms::convert2mm(zo) << ", " << cms::convert2mm(rinB)
0241                                       << " superlayer thickness " << cms::convert2mm(layerThick_[i]);
0242 #endif
0243 
0244         dd4hep::Material matter = ns.material(materials_[ii]);
0245         dd4hep::Volume glog;
0246 
0247         if (layerSense_[ly] < 1) {
0248           std::vector<double> pgonZ, pgonRin, pgonRout;
0249           double rmax =
0250               (std::min(routF, HGCalGeomTools::radius(zz + hthick, zFrontT_, rMaxFront_, slopeT_)) * cosAlpha_) - tol1;
0251           HGCalGeomTools::radius(zz - hthick,
0252                                  zz + hthick,
0253                                  zFrontB_,
0254                                  rMinFront_,
0255                                  slopeB_,
0256                                  zFrontT_,
0257                                  rMaxFront_,
0258                                  slopeT_,
0259                                  -layerSense_[ly],
0260                                  pgonZ,
0261                                  pgonRin,
0262                                  pgonRout);
0263           for (unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
0264             pgonZ[isec] -= zz;
0265             if (layerSense_[ly] == 0 || absorbMode_ == 0)
0266               pgonRout[isec] = rmax;
0267             else
0268               pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1;
0269           }
0270 
0271           dd4hep::Solid solid = dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
0272           ns.addSolidNS(ns.prepend(name), solid);
0273           glog = dd4hep::Volume(solid.name(), solid, matter);
0274           ns.addVolumeNS(glog);
0275 #ifdef EDM_ML_DEBUG
0276           edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << solid.name() << " polyhedra of " << sectors_
0277                                         << " sectors covering " << convertRadToDeg(-alpha_) << ":"
0278                                         << convertRadToDeg(-alpha_ + 2._pi) << " with " << pgonZ.size() << " sections";
0279           for (unsigned int k = 0; k < pgonZ.size(); ++k)
0280             edm::LogVerbatim("HGCalGeom") << "[" << k << "] z " << cms::convert2mm(pgonZ[k]) << " R "
0281                                           << cms::convert2mm(pgonRin[k]) << ":" << cms::convert2mm(pgonRout[k]);
0282 #endif
0283         } else {
0284           double rins =
0285               (sensitiveMode_ < 1) ? rinB : HGCalGeomTools::radius(zz + hthick, zFrontB_, rMinFront_, slopeB_);
0286           double routs =
0287               (sensitiveMode_ < 1) ? routF : HGCalGeomTools::radius(zz - hthick, zFrontT_, rMaxFront_, slopeT_);
0288           dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
0289           ns.addSolidNS(ns.prepend(name), solid);
0290           glog = dd4hep::Volume(solid.name(), solid, matter);
0291           ns.addVolumeNS(glog);
0292 
0293 #ifdef EDM_ML_DEBUG
0294           edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << solid.name() << " Tubs made of " << matter.name()
0295                                         << " of dimensions " << cms::convert2mm(rinB) << ":" << cms::convert2mm(rins)
0296                                         << ", " << cms::convert2mm(routF) << ":" << cms::convert2mm(routs) << ", "
0297                                         << cms::convert2mm(hthick) << ", 0.0, 360.0 and positioned in: " << glog.name()
0298                                         << " number " << copy;
0299 #endif
0300           positionMix(ctxt, e, glog, name, copy, thick_[ii], matter);
0301         }
0302 
0303         dd4hep::Position r1(0, 0, zz);
0304         mother.placeVolume(glog, copy, r1);
0305         ++copyNumber_[ii];
0306 #ifdef EDM_ML_DEBUG
0307         edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << glog.name() << " number " << copy << " positioned in "
0308                                       << mother.name() << " at (0,0," << cms::convert2mm(zz) << ") with no rotation";
0309 #endif
0310         zz += hthick;
0311       }  // End of loop over layers in a block
0312       zi = zo;
0313       laymin = laymax;
0314       if (std::abs(thickTot - layerThick_[i]) > tol2_) {
0315         if (thickTot > layerThick_[i]) {
0316           edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick_[i])
0317                                      << " is smaller than " << cms::convert2mm(thickTot)
0318                                      << ": thickness of all its components **** ERROR ****";
0319         } else {
0320           edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick_[i])
0321                                        << " does not match with " << cms::convert2mm(thickTot) << " of the components";
0322         }
0323       }
0324     }  // End of loop over blocks
0325 
0326 #ifdef EDM_ML_DEBUG
0327     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << copies_.size() << " different wafer copy numbers";
0328     int k(0);
0329     for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++k) {
0330       edm::LogVerbatim("HGCalGeom") << "Copy [" << k << "] : " << (*itr);
0331     }
0332     copies_.clear();
0333     edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalMixLayer construction...";
0334 #endif
0335   }
0336 
0337   void positionMix(cms::DDParsingContext& ctxt,
0338                    xml_h e,
0339                    const dd4hep::Volume& glog,
0340                    const std::string& nameM,
0341                    int copyM,
0342                    double thick,
0343                    const dd4hep::Material& matter) {
0344     cms::DDNamespace ns(ctxt, e, true);
0345 
0346     // Make the top part first
0347     for (unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
0348       int ii = layerTypeTop_[ly];
0349       copyNumberTop_[ii] = copyM;
0350     }
0351     double hthick = 0.5 * thick;
0352     double dphi = (2._pi) / phiBinsScint_;
0353     double thickTot(0), zpos(-hthick);
0354     for (unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
0355       int ii = layerTypeTop_[ly];
0356       int copy = copyNumberTop_[ii];
0357       int layer = copy - firstLayer_;
0358       double hthickl = 0.5 * layerThickTop_[ii];
0359       thickTot += layerThickTop_[ii];
0360       zpos += hthickl;
0361       dd4hep::Material matter1 = ns.material(materialTop_[ii]);
0362       unsigned int k = 0;
0363       int firstTile = tileLayerStart_[layer];
0364       int lastTile = ((layer + 1 < static_cast<int>(tileLayerStart_.size())) ? tileLayerStart_[layer + 1]
0365                                                                              : static_cast<int>(tileIndex_.size()));
0366 #ifdef EDM_ML_DEBUG
0367       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Layer " << ly << ":" << ii << " Copy " << copy << " Tiles "
0368                                     << firstTile << ":" << lastTile;
0369 #endif
0370       for (int ti = firstTile; ti < lastTile; ++ti) {
0371         double r1 = tileRMin_[std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) - 1];
0372         double r2 = tileRMax_[std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) - 1];
0373         int fimin = std::get<1>(HGCalTileIndex::tileUnpack(tilePhis_[ti]));
0374         int fimax = std::get<2>(HGCalTileIndex::tileUnpack(tilePhis_[ti]));
0375         double phi1 = dphi * (fimin - 1);
0376         double phi2 = dphi * (fimax - fimin + 1);
0377 #ifdef EDM_ML_DEBUG
0378         edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Layer " << copy << " iR "
0379                                       << std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[ly])) << ":"
0380                                       << std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[ly])) << " R "
0381                                       << cms::convert2mm(r1) << ":" << cms::convert2mm(r2) << " Thick "
0382                                       << cms::convert2mm((2.0 * hthickl)) << " phi " << fimin << ":" << fimax << ":"
0383                                       << convertRadToDeg(phi1) << ":" << convertRadToDeg(phi2);
0384 #endif
0385         std::string name = namesTop_[ii] + "L" + std::to_string(copy) + "F" + std::to_string(k);
0386         ++k;
0387         dd4hep::Solid solid = dd4hep::Tube(r1, r2, hthickl, phi1, phi2);
0388         ns.addSolidNS(ns.prepend(name), solid);
0389         dd4hep::Volume glog1 = dd4hep::Volume(solid.name(), solid, matter1);
0390         ns.addVolumeNS(glog1);
0391 #ifdef EDM_ML_DEBUG
0392         edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << glog1.name() << " Tubs made of " << materialTop_[ii]
0393                                       << " of dimensions " << cms::convert2mm(r1) << ", " << cms::convert2mm(r2) << ", "
0394                                       << cms::convert2mm(hthickl) << ", " << convertRadToDeg(phi1) << ", "
0395                                       << convertRadToDeg(phi2);
0396 #endif
0397         dd4hep::Position tran(0, 0, zpos);
0398         glog.placeVolume(glog1, copy, tran);
0399 #ifdef EDM_ML_DEBUG
0400         edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Position " << glog1.name() << " number " << copy << " in "
0401                                       << glog.name() << " at (0, 0, " << cms::convert2mm(zpos) << ") with no rotation";
0402 #endif
0403       }
0404       ++copyNumberTop_[ii];
0405       zpos += hthickl;
0406     }
0407     if (std::abs(thickTot - thick) > tol2_) {
0408       if (thickTot > thick) {
0409         edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick) << " is smaller than "
0410                                    << cms::convert2mm(thickTot)
0411                                    << ": thickness of all its components in the top part **** ERROR ****";
0412       } else {
0413         edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick)
0414                                      << " does not match with " << cms::convert2mm(thickTot)
0415                                      << " of the components in top part";
0416       }
0417     }
0418 
0419     // Make the bottom part next
0420     int layer = (copyM - firstLayer_);
0421     static const double sqrt3 = std::sqrt(3.0);
0422     int layercenter = layerOrient_[layer];
0423     int layerType = (layerOrient_[layer] == HGCalTypes::WaferCenterB) ? 1 : 0;
0424     int firstWafer = waferLayerStart_[layer];
0425     int lastWafer = ((layer + 1 < static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
0426                                                                              : static_cast<int>(waferIndex_.size()));
0427     double r = 0.5 * (waferSize_ + waferSepar_);
0428     double R = 2.0 * r / sqrt3;
0429     double dy = 0.75 * R;
0430     const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
0431 #ifdef EDM_ML_DEBUG
0432     int ium(0), ivm(0), kount(0);
0433     std::vector<int> ntype(3, 0);
0434     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << glog.name() << "  r " << cms::convert2mm(r) << " R "
0435                                   << cms::convert2mm(R) << " dy " << cms::convert2mm(dy) << " Shift "
0436                                   << cms::convert2mm(xyoff.first) << ":" << cms::convert2mm(xyoff.second)
0437                                   << " WaferSize " << cms::convert2mm((waferSize_ + waferSepar_)) << " index "
0438                                   << firstWafer << ":" << (lastWafer - 1);
0439 #endif
0440     for (int k = firstWafer; k < lastWafer; ++k) {
0441       int u = HGCalWaferIndex::waferU(waferIndex_[k]);
0442       int v = HGCalWaferIndex::waferV(waferIndex_[k]);
0443 #ifdef EDM_ML_DEBUG
0444       int iu = std::abs(u);
0445       int iv = std::abs(v);
0446 #endif
0447       int nr = 2 * v;
0448       int nc = -2 * u + v;
0449       double xpos = xyoff.first + nc * r;
0450       double ypos = xyoff.second + nr * dy;
0451       int type = HGCalProperty::waferThick(waferProperty_[k]);
0452       int part = HGCalProperty::waferPartial(waferProperty_[k]);
0453       int orien = HGCalProperty::waferOrient(waferProperty_[k]);
0454       std::string wafer;
0455       int i(999);
0456       if (part == HGCalTypes::WaferFull) {
0457         i = layerType * waferTypes_ + type;
0458         wafer = waferFull_[i];
0459       } else {
0460         i = (part - 1) * waferTypes_ * facingTypes_ * orientationTypes_ + layerType * waferTypes_ * orientationTypes_ +
0461             type * orientationTypes_ + orien;
0462 #ifdef EDM_ML_DEBUG
0463         edm::LogVerbatim("HGCalGeom") << " layertype:type:part:orien:ind " << layerType << ":" << type << ":" << part
0464                                       << ":" << orien << ":" << i << ":" << waferPart_.size();
0465 #endif
0466         wafer = waferPart_[i];
0467       }
0468       int copy = HGCalTypes::packTypeUV(type, u, v);
0469 #ifdef EDM_ML_DEBUG
0470       edm::LogVerbatim("HGCalGeom") << " DDHGCalMixLayer: Layer " << HGCalWaferIndex::waferLayer(waferIndex_[k])
0471                                     << " Wafer " << wafer << " number " << copy << " type :part:orien:ind " << type
0472                                     << ":" << part << ":" << orien << ":" << i << " layer:u:v " << (layer + firstLayer_)
0473                                     << ":" << u << ":" << v;
0474       if (iu > ium)
0475         ium = iu;
0476       if (iv > ivm)
0477         ivm = iv;
0478       kount++;
0479       if (copies_.count(copy) == 0)
0480         copies_.insert(copy);
0481 #endif
0482       dd4hep::Position tran(xpos, ypos, 0.0);
0483       glog.placeVolume(ns.volume(wafer), copy, tran);
0484 #ifdef EDM_ML_DEBUG
0485       ++ntype[type];
0486       edm::LogVerbatim("HGCalGeom") << " DDHGCalMixLayer: " << wafer << " number " << copy << " type " << layerType
0487                                     << ":" << type << " positioned in " << glog.name() << " at ("
0488                                     << cms::convert2mm(xpos) << "," << cms::convert2mm(ypos) << ",0) with no rotation";
0489 #endif
0490     }
0491 
0492 #ifdef EDM_ML_DEBUG
0493     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Maximum # of u " << ium << " # of v " << ivm << " and " << kount
0494                                   << " wafers (" << ntype[0] << ":" << ntype[1] << ":" << ntype[2] << ") for "
0495                                   << glog.name();
0496 #endif
0497   }
0498 
0499   //Required data members to cache the values from XML file
0500   HGCalGeomTools geomTools_;
0501   static constexpr double tol2_ = 0.00001 * dd4hep::mm;
0502 
0503   int waferTypes_;                        // Number of wafer types
0504   int facingTypes_;                       // Types of facings of modules toward IP
0505   int partialTypes_;                      // Number of partial wafer types
0506   int orientationTypes_;                  // Number of partial wafer orienations
0507   int phiBinsScint_;                      // Maximum number of cells along phi
0508   int firstLayer_;                        // Copy # of the first sensitive layer
0509   int absorbMode_;                        // Absorber mode
0510   int sensitiveMode_;                     // Sensitive mode
0511   double zMinBlock_;                      // Starting z-value of the block
0512   double waferSize_;                      // Width of the wafer
0513   double waferSepar_;                     // Sensor separation
0514   int sectors_;                           // Sectors
0515   std::vector<double> slopeB_;            // Slope at the lower R
0516   std::vector<double> zFrontB_;           // Starting Z values for the slopes
0517   std::vector<double> rMinFront_;         // Corresponding rMin's
0518   std::vector<double> slopeT_;            // Slopes at the larger R
0519   std::vector<double> zFrontT_;           // Starting Z values for the slopes
0520   std::vector<double> rMaxFront_;         // Corresponding rMax's
0521   std::vector<std::string> waferFull_;    // Names of full wafer modules
0522   std::vector<std::string> waferPart_;    // Names of partial wafer modules
0523   std::vector<std::string> materials_;    // Materials
0524   std::vector<std::string> names_;        // Names
0525   std::vector<double> thick_;             // Thickness of the material
0526   std::vector<int> copyNumber_;           // Initial copy numbers
0527   std::vector<int> layers_;               // Number of layers in a section
0528   std::vector<double> layerThick_;        // Thickness of each section
0529   std::vector<int> layerType_;            // Type of the layer
0530   std::vector<int> layerSense_;           // Content of a layer (sensitive?)
0531   std::vector<std::string> materialTop_;  // Materials of top layers
0532   std::vector<std::string> namesTop_;     // Names of top layers
0533   std::vector<double> layerThickTop_;     // Thickness of the top sections
0534   std::vector<int> layerTypeTop_;         // Type of the Top layer
0535   std::vector<int> copyNumberTop_;        // Initial copy numbers (top section)
0536   std::vector<int> layerOrient_;          // Layer orientation of silicon layers
0537   std::vector<int> waferIndex_;           // Wafer index for the types
0538   std::vector<int> waferProperty_;        // Wafer property
0539   std::vector<int> waferLayerStart_;      // Start index of wafers in each layer
0540   std::vector<double> tileRMin_;          // Minimum radius of each ring
0541   std::vector<double> tileRMax_;          // Maximum radius of each ring
0542   std::vector<int> tileIndex_;            // Index of tile (layer/start|end ring)
0543   std::vector<int> tilePhis_;             // Tile phi range for each index
0544   std::vector<int> tileLayerStart_;       // Start index of tiles in each layer
0545   std::unordered_set<int> copies_;        // List of copy #'s
0546   double alpha_, cosAlpha_;
0547 };
0548 
0549 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0550   HGCalMixLayer healgo(ctxt, e);
0551   return cms::s_executed;
0552 }
0553 
0554 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalMixLayer, algorithm)