Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:59

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