Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-08-22 04:57:42

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDHGCalMixRotatedFineFineCassette.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/HGCalCell.h"
0019 #include "Geometry/HGCalCommonData/interface/HGCalCassette.h"
0020 #include "Geometry/HGCalCommonData/interface/HGCalGeomTools.h"
0021 #include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
0022 #include "Geometry/HGCalCommonData/interface/HGCalProperty.h"
0023 #include "Geometry/HGCalCommonData/interface/HGCalTileIndex.h"
0024 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0025 #include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h"
0026 #include "Geometry/HGCalCommonData/interface/HGCalWaferType.h"
0027 
0028 #include <cmath>
0029 #include <memory>
0030 #include <string>
0031 #include <unordered_set>
0032 #include <vector>
0033 
0034 //#define EDM_ML_DEBUG
0035 using namespace angle_units::operators;
0036 
0037 class DDHGCalMixRotatedFineCassette : public DDAlgorithm {
0038 public:
0039   DDHGCalMixRotatedFineCassette();
0040 
0041   void initialize(const DDNumericArguments& nArgs,
0042                   const DDVectorArguments& vArgs,
0043                   const DDMapArguments& mArgs,
0044                   const DDStringArguments& sArgs,
0045                   const DDStringVectorArguments& vsArgs) override;
0046   void execute(DDCompactView& cpv) override;
0047 
0048 protected:
0049   void constructLayers(const DDLogicalPart&, DDCompactView& cpv);
0050   void positionMix(const DDLogicalPart& glog,
0051                    const std::string& nameM,
0052                    int copyM,
0053                    double thick,
0054                    const DDMaterial& matter,
0055                    int absType,
0056                    bool fine,
0057                    DDCompactView& cpv);
0058 
0059 private:
0060   HGCalGeomTools geomTools_;
0061   HGCalCassette cassette_;
0062 
0063   static constexpr double tol1_ = 0.01;
0064   static constexpr double tol2_ = 0.00001;
0065 
0066   int waferTypes_;                         // Number of wafer types
0067   int passiveTypes_;                       // Number of passive types
0068   int facingTypes_;                        // Types of facings of modules toward IP
0069   int orientationTypes_;                   // Number of partial wafer orienations
0070   int partialTypes_;                       // Number of partial types
0071   int placeOffset_;                        // Offset for placement
0072   int phiBinsScint_;                       // Maximum number of cells along phi (coarse)
0073   int phiBinsFineScint_;                   // Maximum number of cells along phi (fine)
0074   int firstFineLayer_;                     // Copy # of the first Fine sensitive layer
0075   int firstCoarseLayer_;                   // Copy # of the first Coarse sensitive layer
0076   int absorbMode_;                         // Absorber mode
0077   int sensitiveMode_;                      // Sensitive mode
0078   int passiveMode_;                        // Mode for passive components
0079   double zMinBlock_;                       // Starting z-value of the block
0080   double waferSize_;                       // Width of the wafer
0081   double waferSepar_;                      // Sensor separation
0082   int sectors_;                            // Sectors
0083   int cassettes_;                          // Cassettes
0084   std::vector<double> slopeB_;             // Slope at the lower R
0085   std::vector<double> zFrontB_;            // Starting Z values for the slopes
0086   std::vector<double> rMinFront_;          // Corresponding rMin's
0087   std::vector<double> slopeT_;             // Slopes at the larger R
0088   std::vector<double> zFrontT_;            // Starting Z values for the slopes
0089   std::vector<double> rMaxFront_;          // Corresponding rMax's
0090   std::vector<std::string> waferFull_;     // Names of full wafer modules
0091   std::vector<std::string> waferPart_;     // Names of partial wafer modules
0092   std::vector<std::string> passiveFull_;   // Names of full passive modules
0093   std::vector<std::string> passivePart_;   // Names of partial passive modules
0094   std::vector<std::string> materials_;     // Materials
0095   std::vector<std::string> names_;         // Names
0096   std::vector<double> thick_;              // Thickness of the material
0097   std::vector<int> copyNumber_;            // Initial copy numbers
0098   std::vector<int> layers_;                // Number of layers in a section
0099   std::vector<double> layerThick_;         // Thickness of each section
0100   std::vector<int> layerType_;             // Type of the layer
0101   std::vector<int> layerSense_;            // Content of a layer (sensitive?)
0102   std::vector<std::string> materialTop_;   // Materials of top layers
0103   std::vector<std::string> namesTop_;      // Names of top layers
0104   std::vector<double> layerThickTop_;      // Thickness of the top sections
0105   std::vector<int> layerTypeTop_;          // Type of the Top layer
0106   std::vector<int> copyNumberTop_;         // Initial copy numbers (top section)
0107   int coverTypeTop_;                       // Type of the Top layer cover
0108   int coverTopLayers_;                     // Number of cover layers in top section
0109   std::vector<int> copyNumberCoverTop_;    // Initial copy number of top cover
0110   std::vector<int> layerOrient_;           // Layer orientation for the silicon component
0111   std::vector<int> waferIndex_;            // Wafer index for the types
0112   std::vector<int> waferProperty_;         // Wafer property
0113   std::vector<int> waferLayerStart_;       // Start index of wafers in each layer
0114   std::vector<double> cassetteShift_;      // Shifts of the cassetes
0115   std::vector<double> tileFineRMin_;       // Minimum radius of each fine ring
0116   std::vector<double> tileFineRMax_;       // Maximum radius of each fine ring
0117   std::vector<int> tileFineIndex_;         // Index of tile (layer/start|end fine ring)
0118   std::vector<int> tileFinePhis_;          // Tile phi range for each index in fine ring
0119   std::vector<int> tileFineLayerStart_;    // Start index of tiles in each fine layer
0120   std::vector<double> tileCoarseRMin_;     // Minimum radius of each coarse ring
0121   std::vector<double> tileCoarseRMax_;     // Maximum radius of each coarse ring
0122   std::vector<int> tileCoarseIndex_;       // Index of tile (layer/start|end coarse ring)
0123   std::vector<int> tileCoarsePhis_;        // Tile phi range for each index in coarse ring
0124   std::vector<int> tileCoarseLayerStart_;  // Start index of tiles in each coarse layer
0125   std::vector<double> cassetteShiftScnt_;  // Shifts of the cassetes for scintillators
0126   std::string nameSpace_;                  // Namespace of this and ALL sub-parts
0127   std::unordered_set<int> copies_;         // List of copy #'s
0128   double alpha_, cosAlpha_;
0129 };
0130 
0131 DDHGCalMixRotatedFineCassette::DDHGCalMixRotatedFineCassette() {
0132 #ifdef EDM_ML_DEBUG
0133   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Creating an instance";
0134 #endif
0135 }
0136 
0137 void DDHGCalMixRotatedFineCassette::initialize(const DDNumericArguments& nArgs,
0138                                                const DDVectorArguments& vArgs,
0139                                                const DDMapArguments&,
0140                                                const DDStringArguments& sArgs,
0141                                                const DDStringVectorArguments& vsArgs) {
0142   waferTypes_ = static_cast<int>(nArgs["WaferTypes"]);
0143   passiveTypes_ = static_cast<int>(nArgs["PassiveTypes"]);
0144   facingTypes_ = static_cast<int>(nArgs["FacingTypes"]);
0145   orientationTypes_ = static_cast<int>(nArgs["OrientationTypes"]);
0146   partialTypes_ = static_cast<int>(nArgs["PartialTypes"]);
0147   placeOffset_ = static_cast<int>(nArgs["PlaceOffset"]);
0148   phiBinsScint_ = static_cast<int>(nArgs["NPhiBinScint"]);
0149   phiBinsFineScint_ = static_cast<int>(nArgs["NPhiBinFineScint"]);
0150 #ifdef EDM_ML_DEBUG
0151   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette::Number of types of wafers: " << waferTypes_
0152                                 << " passives: " << passiveTypes_ << " facings: " << facingTypes_
0153                                 << " Orientations: " << orientationTypes_ << " PartialTypes: " << partialTypes_
0154                                 << " PlaceOffset: " << placeOffset_ << "; number of cells along phi "
0155                                 << phiBinsFineScint_ << ":" << phiBinsScint_;
0156 #endif
0157   firstFineLayer_ = static_cast<int>(nArgs["FirstFineLayer"]);
0158   firstCoarseLayer_ = static_cast<int>(nArgs["FirstCoarseLayer"]);
0159   absorbMode_ = static_cast<int>(nArgs["AbsorberMode"]);
0160   sensitiveMode_ = static_cast<int>(nArgs["SensitiveMode"]);
0161   passiveMode_ = static_cast<int>(nArgs["PassiveMode"]);
0162 #ifdef EDM_ML_DEBUG
0163   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette::First Layers " << firstFineLayer_ << ":"
0164                                 << firstCoarseLayer_ << " and Absober:Sensitive mode " << absorbMode_ << ":"
0165                                 << sensitiveMode_ << ":" << passiveMode_;
0166 #endif
0167   zMinBlock_ = nArgs["zMinBlock"];
0168   waferSize_ = nArgs["waferSize"];
0169   waferSepar_ = nArgs["SensorSeparation"];
0170   sectors_ = static_cast<int>(nArgs["Sectors"]);
0171   cassettes_ = static_cast<int>(nArgs["Cassettes"]);
0172   alpha_ = (1._pi) / sectors_;
0173   cosAlpha_ = cos(alpha_);
0174 #ifdef EDM_ML_DEBUG
0175   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: zStart " << zMinBlock_ << " wafer width "
0176                                 << waferSize_ << " separations " << waferSepar_ << " sectors " << sectors_ << ":"
0177                                 << convertRadToDeg(alpha_) << ":" << cosAlpha_ << " with " << cassettes_
0178                                 << " cassettes";
0179 #endif
0180   slopeB_ = vArgs["SlopeBottom"];
0181   zFrontB_ = vArgs["ZFrontBottom"];
0182   rMinFront_ = vArgs["RMinFront"];
0183   slopeT_ = vArgs["SlopeTop"];
0184   zFrontT_ = vArgs["ZFrontTop"];
0185   rMaxFront_ = vArgs["RMaxFront"];
0186 #ifdef EDM_ML_DEBUG
0187   for (unsigned int i = 0; i < slopeB_.size(); ++i)
0188     edm::LogVerbatim("HGCalGeom") << "Bottom Block [" << i << "] Zmin " << zFrontB_[i] << " Rmin " << rMinFront_[i]
0189                                   << " Slope " << slopeB_[i];
0190   for (unsigned int i = 0; i < slopeT_.size(); ++i)
0191     edm::LogVerbatim("HGCalGeom") << "Top Block [" << i << "] Zmin " << zFrontT_[i] << " Rmax " << rMaxFront_[i]
0192                                   << " Slope " << slopeT_[i];
0193 #endif
0194   waferFull_ = vsArgs["WaferNamesFull"];
0195   waferPart_ = vsArgs["WaferNamesPartial"];
0196 #ifdef EDM_ML_DEBUG
0197   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: " << waferFull_.size() << " full and "
0198                                 << waferPart_.size() << " partial modules\nDDHGCalMixRotatedFineCassette:Full Modules:";
0199   unsigned int i1max = static_cast<unsigned int>(waferFull_.size());
0200   for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
0201     std::ostringstream st1;
0202     unsigned int i2 = std::min((i1 + 2), i1max);
0203     for (unsigned int i = i1; i < i2; ++i)
0204       st1 << " [" << i << "] " << waferFull_[i];
0205     edm::LogVerbatim("HGCalGeom") << st1.str();
0206   }
0207   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Partial Modules:";
0208   i1max = static_cast<unsigned int>(waferPart_.size());
0209   for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
0210     std::ostringstream st1;
0211     unsigned int i2 = std::min((i1 + 2), i1max);
0212     for (unsigned int i = i1; i < i2; ++i)
0213       st1 << " [" << i << "] " << waferPart_[i];
0214     edm::LogVerbatim("HGCalGeom") << st1.str();
0215   }
0216 #endif
0217   passiveFull_ = vsArgs["PassiveNamesFull"];
0218   passivePart_ = vsArgs["PassiveNamesPartial"];
0219 #ifdef EDM_ML_DEBUG
0220   edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: " << passiveFull_.size() << " full and "
0221                                 << passivePart_.size() << " partial passive modules";
0222   i1max = static_cast<unsigned int>(passiveFull_.size());
0223   for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
0224     std::ostringstream st1;
0225     unsigned int i2 = std::min((i1 + 2), i1max);
0226     for (unsigned int i = i1; i < i2; ++i)
0227       st1 << " [" << i << "] " << passiveFull_[i];
0228     edm::LogVerbatim("HGCalGeom") << st1.str();
0229   }
0230   edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: Partial Modules:";
0231   i1max = static_cast<unsigned int>(passivePart_.size());
0232   for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
0233     std::ostringstream st1;
0234     unsigned int i2 = std::min((i1 + 2), i1max);
0235     for (unsigned int i = i1; i < i2; ++i)
0236       st1 << " [" << i << "] " << passivePart_[i];
0237     edm::LogVerbatim("HGCalGeom") << st1.str();
0238   }
0239 #endif
0240   materials_ = vsArgs["MaterialNames"];
0241   names_ = vsArgs["VolumeNames"];
0242   thick_ = vArgs["Thickness"];
0243   copyNumber_.resize(materials_.size(), 1);
0244 #ifdef EDM_ML_DEBUG
0245   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: " << materials_.size() << " types of volumes";
0246   for (unsigned int i = 0; i < names_.size(); ++i)
0247     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names_[i] << " of thickness " << thick_[i]
0248                                   << " filled with " << materials_[i] << " first copy number " << copyNumber_[i];
0249 #endif
0250   layers_ = dbl_to_int(vArgs["Layers"]);
0251   layerThick_ = vArgs["LayerThick"];
0252 #ifdef EDM_ML_DEBUG
0253   edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks";
0254   for (unsigned int i = 0; i < layers_.size(); ++i)
0255     edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << layerThick_[i] << " with " << layers_[i]
0256                                   << " layers";
0257 #endif
0258   layerType_ = dbl_to_int(vArgs["LayerType"]);
0259   layerSense_ = dbl_to_int(vArgs["LayerSense"]);
0260   layerOrient_ = dbl_to_int(vArgs["LayerTypes"]);
0261   for (unsigned int k = 0; k < layerOrient_.size(); ++k)
0262     layerOrient_[k] = HGCalTypes::layerType(layerOrient_[k]);
0263 #ifdef EDM_ML_DEBUG
0264   for (unsigned int i = 0; i < layerOrient_.size(); ++i)
0265     edm::LogVerbatim("HGCalGeom") << "LayerOrient [" << i << "] " << layerOrient_[i];
0266 #endif
0267   if (firstFineLayer_ > 0) {
0268     for (unsigned int i = 0; i < layerType_.size(); ++i) {
0269       if (layerSense_[i] != 0) {
0270         int ii = layerType_[i];
0271         copyNumber_[ii] = firstFineLayer_;
0272 #ifdef EDM_ML_DEBUG
0273         edm::LogVerbatim("HGCalGeom") << "First copy number for layer type " << i << ":" << ii << " with "
0274                                       << materials_[ii] << " changed to " << copyNumber_[ii];
0275 #endif
0276       }
0277     }
0278   } else {
0279     firstFineLayer_ = 1;
0280   }
0281 #ifdef EDM_ML_DEBUG
0282   edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " layers";
0283   for (unsigned int i = 0; i < layerType_.size(); ++i)
0284     edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType_[i] << " sensitive class "
0285                                   << layerSense_[i];
0286 #endif
0287   materialTop_ = vsArgs["TopMaterialNames"];
0288   namesTop_ = vsArgs["TopVolumeNames"];
0289   layerThickTop_ = vArgs["TopLayerThickness"];
0290   layerTypeTop_ = dbl_to_int(vArgs["TopLayerType"]);
0291   copyNumberTop_.resize(materialTop_.size(), firstFineLayer_);
0292   coverTypeTop_ = static_cast<int>(nArgs["TopCoverLayerType"]);
0293   coverTopLayers_ = static_cast<int>(nArgs["TopCoverLayers"]);
0294   copyNumberCoverTop_.resize(coverTopLayers_, firstFineLayer_);
0295 #ifdef EDM_ML_DEBUG
0296   std::ostringstream st0;
0297   for (int k = 0; k < coverTopLayers_; ++k)
0298     st0 << " " << copyNumberCoverTop_[k];
0299   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: " << materialTop_.size()
0300                                 << " types of volumes in the top part; " << coverTopLayers_ << " covers of Type "
0301                                 << coverTypeTop_ << " with initial copy numbers: " << st0.str();
0302   for (unsigned int i = 0; i < materialTop_.size(); ++i)
0303     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << namesTop_[i] << " of thickness " << layerThickTop_[i]
0304                                   << " filled with " << materialTop_[i] << " first copy number " << copyNumberTop_[i];
0305   edm::LogVerbatim("HGCalGeom") << "There are " << layerTypeTop_.size() << " layers in the top part";
0306   for (unsigned int i = 0; i < layerTypeTop_.size(); ++i)
0307     edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerTypeTop_[i];
0308 #endif
0309   waferIndex_ = dbl_to_int(vArgs["WaferIndex"]);
0310   waferProperty_ = dbl_to_int(vArgs["WaferProperties"]);
0311   waferLayerStart_ = dbl_to_int(vArgs["WaferLayerStart"]);
0312   cassetteShift_ = vArgs["CassetteShift"];
0313 #ifdef EDM_ML_DEBUG
0314   edm::LogVerbatim("HGCalGeom") << "waferProperties with " << waferIndex_.size() << " entries in "
0315                                 << waferLayerStart_.size() << " layers";
0316   for (unsigned int k = 0; k < waferLayerStart_.size(); ++k)
0317     edm::LogVerbatim("HGCalGeom") << "LayerStart[" << k << "] " << waferLayerStart_[k];
0318   for (unsigned int k = 0; k < waferIndex_.size(); ++k)
0319     edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << waferIndex_[k] << " ("
0320                                   << HGCalWaferIndex::waferLayer(waferIndex_[k]) << ", "
0321                                   << HGCalWaferIndex::waferU(waferIndex_[k]) << ", "
0322                                   << HGCalWaferIndex::waferV(waferIndex_[k]) << ") : ("
0323                                   << HGCalProperty::waferThick(waferProperty_[k]) << ":"
0324                                   << HGCalProperty::waferPartial(waferProperty_[k]) << ":"
0325                                   << HGCalProperty::waferOrient(waferProperty_[k]) << ")";
0326   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: " << cassetteShift_.size()
0327                                 << " elements for cassette shifts";
0328   unsigned int j1max = cassetteShift_.size();
0329   for (unsigned int j1 = 0; j1 < j1max; j1 += 6) {
0330     std::ostringstream st1;
0331     unsigned int j2 = std::min((j1 + 6), j1max);
0332     for (unsigned int j = j1; j < j2; ++j)
0333       st1 << " [" << j << "] " << std::setw(9) << cassetteShift_[j];
0334     edm::LogVerbatim("HGCalGeom") << st1.str();
0335   }
0336 #endif
0337   tileFineRMin_ = vArgs["Tile6RMin"];
0338   tileFineRMax_ = vArgs["Tile6RMax"];
0339   tileFineIndex_ = dbl_to_int(vArgs["Tile6LayerRings"]);
0340   tileFinePhis_ = dbl_to_int(vArgs["Tile6PhiRange"]);
0341   tileFineLayerStart_ = dbl_to_int(vArgs["Tile6LayerStart"]);
0342   tileCoarseRMin_ = vArgs["TileRMin"];
0343   tileCoarseRMax_ = vArgs["TileRMax"];
0344   tileCoarseIndex_ = dbl_to_int(vArgs["TileLayerRings"]);
0345   tileCoarsePhis_ = dbl_to_int(vArgs["TilePhiRange"]);
0346   tileCoarseLayerStart_ = dbl_to_int(vArgs["TileLayerStart"]);
0347 #ifdef EDM_ML_DEBUG
0348   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette:: with " << tileFineRMin_.size() << ":"
0349                                 << tileCoarseRMin_.size() << " rings";
0350   for (unsigned int k = 0; k < tileFineRMin_.size(); ++k)
0351     edm::LogVerbatim("HGCalGeom") << "Fine Ring[" << k << "] " << tileFineRMin_[k] << " : " << tileFineRMax_[k];
0352   for (unsigned int k = 0; k < tileCoarseRMin_.size(); ++k)
0353     edm::LogVerbatim("HGCalGeom") << "Coarse Ring[" << k << "] " << tileCoarseRMin_[k] << " : " << tileCoarseRMax_[k];
0354   edm::LogVerbatim("HGCalGeom") << "TileProperties with " << tileFineIndex_.size() << ":" << tileCoarseIndex_.size()
0355                                 << " entries in " << tileFineLayerStart_.size() << ":" << tileCoarseLayerStart_.size()
0356                                 << " layers";
0357   for (unsigned int k = 0; k < tileFineLayerStart_.size(); ++k)
0358     edm::LogVerbatim("HGCalGeom") << "FineLayerStart[" << k << "] " << tileFineLayerStart_[k];
0359   for (unsigned int k = 0; k < tileCoarseLayerStart_.size(); ++k)
0360     edm::LogVerbatim("HGCalGeom") << "CoarseLayerStart[" << k << "] " << tileCoarseLayerStart_[k];
0361   for (unsigned int k = 0; k < tileFineIndex_.size(); ++k)
0362     edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << tileFineIndex_[k] << " ("
0363                                   << "Layer " << std::get<0>(HGCalTileIndex::tileUnpack(tileFineIndex_[k])) << " Ring "
0364                                   << std::get<1>(HGCalTileIndex::tileUnpack(tileFineIndex_[k])) << ":"
0365                                   << std::get<2>(HGCalTileIndex::tileUnpack(tileFineIndex_[k])) << ") Phi "
0366                                   << std::get<1>(HGCalTileIndex::tileUnpack(tileFinePhis_[k])) << ":"
0367                                   << std::get<2>(HGCalTileIndex::tileUnpack(tileFinePhis_[k]));
0368   for (unsigned int k = 0; k < tileCoarseIndex_.size(); ++k)
0369     edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << tileCoarseIndex_[k] << " ("
0370                                   << "Layer " << std::get<0>(HGCalTileIndex::tileUnpack(tileCoarseIndex_[k]))
0371                                   << " Ring " << std::get<1>(HGCalTileIndex::tileUnpack(tileCoarseIndex_[k])) << ":"
0372                                   << std::get<2>(HGCalTileIndex::tileUnpack(tileCoarseIndex_[k])) << ") Phi "
0373                                   << std::get<1>(HGCalTileIndex::tileUnpack(tileCoarsePhis_[k])) << ":"
0374                                   << std::get<2>(HGCalTileIndex::tileUnpack(tileCoarsePhis_[k]));
0375 #endif
0376   std::vector<double> retract = vArgs["ScintRetract"];
0377   double dphi = M_PI / cassettes_;
0378   for (int k = 0; k < cassettes_; ++k) {
0379     double phi = (2 * k + 1) * dphi;
0380     cassetteShiftScnt_.emplace_back(retract[k] * cos(phi));
0381     cassetteShiftScnt_.emplace_back(retract[k] * sin(phi));
0382   }
0383 #ifdef EDM_ML_DEBUG
0384   unsigned int j2max = cassetteShiftScnt_.size();
0385   for (unsigned int j1 = 0; j1 < j2max; j1 += 6) {
0386     std::ostringstream st1;
0387     unsigned int j2 = std::min((j1 + 6), j2max);
0388     for (unsigned int j = j1; j < j2; ++j)
0389       st1 << " [" << j << "] " << std::setw(9) << cassetteShiftScnt_[j];
0390     edm::LogVerbatim("HGCalGeom") << st1.str();
0391   }
0392 #endif
0393   nameSpace_ = DDCurrentNamespace::ns();
0394 #ifdef EDM_ML_DEBUG
0395   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: NameSpace " << nameSpace_ << ":";
0396 #endif
0397   cassette_.setParameter(cassettes_, cassetteShift_, false);
0398   cassette_.setParameterScint(cassetteShiftScnt_);
0399 }
0400 
0401 ////////////////////////////////////////////////////////////////////
0402 // DDHGCalMixRotatedFineCassette methods...
0403 ////////////////////////////////////////////////////////////////////
0404 
0405 void DDHGCalMixRotatedFineCassette::execute(DDCompactView& cpv) {
0406 #ifdef EDM_ML_DEBUG
0407   edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalMixRotatedFineCassette...";
0408   copies_.clear();
0409 #endif
0410   constructLayers(parent(), cpv);
0411 #ifdef EDM_ML_DEBUG
0412   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: " << copies_.size()
0413                                 << " different wafer copy numbers";
0414   int k(0);
0415   for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++k) {
0416     edm::LogVerbatim("HGCalGeom") << "Copy [" << k << "] : " << (*itr);
0417   }
0418   copies_.clear();
0419   edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalMixRotatedFineCassette construction...";
0420 #endif
0421 }
0422 
0423 void DDHGCalMixRotatedFineCassette::constructLayers(const DDLogicalPart& module, DDCompactView& cpv) {
0424   double zi(zMinBlock_);
0425   int laymin(0);
0426   unsigned int fineLayers = static_cast<unsigned int>(firstCoarseLayer_ - firstFineLayer_);
0427   for (unsigned int i = 0; i < layers_.size(); i++) {
0428     double zo = zi + layerThick_[i];
0429     double routF = HGCalGeomTools::radius(zi, zFrontT_, rMaxFront_, slopeT_);
0430     int laymax = laymin + layers_[i];
0431     double zz = zi;
0432     double thickTot(0);
0433     bool fine = (i < fineLayers) ? true : false;
0434     for (int ly = laymin; ly < laymax; ++ly) {
0435       int ii = layerType_[ly];
0436       int copy = copyNumber_[ii];
0437       double hthick = 0.5 * thick_[ii];
0438       double rinB = HGCalGeomTools::radius(zo, zFrontB_, rMinFront_, slopeB_);
0439       zz += hthick;
0440       thickTot += thick_[ii];
0441 
0442       std::string name = names_[ii] + std::to_string(copy);
0443 #ifdef EDM_ML_DEBUG
0444       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Layer " << ly << ":" << ii << " Front " << zi
0445                                     << ", " << routF << " Back " << zo << ", " << rinB << " superlayer thickness "
0446                                     << layerThick_[i];
0447 #endif
0448       DDName matName(DDSplit(materials_[ii]).first, DDSplit(materials_[ii]).second);
0449       DDMaterial matter(matName);
0450       DDLogicalPart glog;
0451       if (layerSense_[ly] == 0) {
0452         std::vector<double> pgonZ, pgonRin, pgonRout;
0453         double rmax =
0454             (std::min(routF, HGCalGeomTools::radius(zz + hthick, zFrontT_, rMaxFront_, slopeT_)) * cosAlpha_) - tol1_;
0455         HGCalGeomTools::radius(zz - hthick,
0456                                zz + hthick,
0457                                zFrontB_,
0458                                rMinFront_,
0459                                slopeB_,
0460                                zFrontT_,
0461                                rMaxFront_,
0462                                slopeT_,
0463                                -layerSense_[ly],
0464                                pgonZ,
0465                                pgonRin,
0466                                pgonRout);
0467         for (unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
0468           pgonZ[isec] -= zz;
0469           if (layerSense_[ly] == 0 || absorbMode_ == 0)
0470             pgonRout[isec] = rmax;
0471           else
0472             pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1_;
0473         }
0474         DDSolid solid =
0475             DDSolidFactory::polyhedra(DDName(name, nameSpace_), sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
0476         glog = DDLogicalPart(solid.ddname(), matter, solid);
0477 #ifdef EDM_ML_DEBUG
0478         edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: " << solid.name() << " polyhedra of "
0479                                       << sectors_ << " sectors covering " << convertRadToDeg(-alpha_) << ":"
0480                                       << convertRadToDeg(-alpha_ + 2._pi) << " with " << pgonZ.size() << " sections";
0481         for (unsigned int k = 0; k < pgonZ.size(); ++k)
0482           edm::LogVerbatim("HGCalGeom") << "[" << k << "] z " << pgonZ[k] << " R " << pgonRin[k] << ":" << pgonRout[k];
0483 #endif
0484       } else {
0485         int mode = (layerSense_[ly] > 0) ? sensitiveMode_ : absorbMode_;
0486         double rins = (mode < 1) ? rinB : HGCalGeomTools::radius(zz + hthick, zFrontB_, rMinFront_, slopeB_);
0487         double routs = (mode < 1) ? routF : HGCalGeomTools::radius(zz - hthick, zFrontT_, rMaxFront_, slopeT_);
0488         DDSolid solid = DDSolidFactory::tubs(DDName(name, nameSpace_), hthick, rins, routs, 0.0, 2._pi);
0489         glog = DDLogicalPart(solid.ddname(), matter, solid);
0490 #ifdef EDM_ML_DEBUG
0491         edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: " << solid.name() << " Tubs made of "
0492                                       << matName << " of dimensions " << rinB << ":" << rins << ", " << routF << ":"
0493                                       << routs << ", " << hthick << ", 0.0, 360.0 and positioned in: " << glog.name()
0494                                       << " number " << copy;
0495 #endif
0496         positionMix(glog, name, copy, thick_[ii], matter, -layerSense_[ly], fine, cpv);
0497       }
0498       DDTranslation r1(0, 0, zz);
0499       DDRotation rot;
0500       cpv.position(glog, module, copy, r1, rot);
0501       ++copyNumber_[ii];
0502 #ifdef EDM_ML_DEBUG
0503       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: " << glog.name() << " number " << copy
0504                                     << " positioned in " << module.name() << " at " << r1 << " with no rotation";
0505 #endif
0506       zz += hthick;
0507     }  // End of loop over layers in a block
0508     zi = zo;
0509     laymin = laymax;
0510     // Make consistency check of all the partitions of the block
0511     if (std::abs(thickTot - layerThick_[i]) >= tol2_) {
0512       if (thickTot > layerThick_[i]) {
0513         edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " is smaller than " << thickTot
0514                                    << ": thickness of all its components **** ERROR ****";
0515       } else {
0516         edm::LogWarning("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " does not match with "
0517                                      << thickTot << " of the components";
0518       }
0519     }
0520   }  // End of loop over blocks
0521 }
0522 
0523 void DDHGCalMixRotatedFineCassette::positionMix(const DDLogicalPart& glog,
0524                                                 const std::string& nameM,
0525                                                 int copyM,
0526                                                 double thick,
0527                                                 const DDMaterial& matter,
0528                                                 int absType,
0529                                                 bool fine,
0530                                                 DDCompactView& cpv) {
0531   DDRotation rot;
0532 
0533   // Make the top part first
0534   for (unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
0535     int ii = layerTypeTop_[ly];
0536     copyNumberTop_[ii] = copyM;
0537   }
0538   double hthick = 0.5 * thick;
0539   double dphi = (fine) ? ((2._pi) / phiBinsFineScint_) : ((2._pi) / phiBinsScint_);
0540   double thickTot(0), zpos(-hthick);
0541 #ifdef EDM_ML_DEBUG
0542   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Entry to positionMix with Name " << nameM << " copy "
0543                                 << copyM << " Thick " << thick << " AbsType " << absType << " Fine " << fine << " dphi "
0544                                 << convertRadToDeg(dphi);
0545 #endif
0546   if (absType < 0) {
0547     for (unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
0548       int ii = layerTypeTop_[ly];
0549       int copy = copyNumberTop_[ii];
0550       int layer = (fine) ? (copy - firstFineLayer_) : (copy - firstCoarseLayer_);
0551       double hthickl = 0.5 * layerThickTop_[ii];
0552       thickTot += layerThickTop_[ii];
0553       zpos += hthickl;
0554       DDName matName(DDSplit(materialTop_[ii]).first, DDSplit(materialTop_[ii]).second);
0555       DDMaterial matter1(matName);
0556       unsigned int k = 0;
0557       int firstTile = (fine) ? tileFineLayerStart_[layer] : tileCoarseLayerStart_[layer];
0558       int lastTile = (fine) ? ((layer + 1 < static_cast<int>(tileFineLayerStart_.size()))
0559                                    ? tileFineLayerStart_[layer + 1]
0560                                    : static_cast<int>(tileFineIndex_.size()))
0561                             : ((layer + 1 < static_cast<int>(tileCoarseLayerStart_.size()))
0562                                    ? tileCoarseLayerStart_[layer + 1]
0563                                    : static_cast<int>(tileCoarseIndex_.size()));
0564 #ifdef EDM_ML_DEBUG
0565       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Layer " << ly << ":" << ii << ":" << layer
0566                                     << " Copy " << copy << " Tiles " << firstTile << ":" << lastTile << " Size "
0567                                     << tileFineIndex_.size() << ":" << tileCoarseIndex_.size() << " Fine " << fine
0568                                     << " absType " << absType;
0569 #endif
0570       for (int ti = firstTile; ti < lastTile; ++ti) {
0571         double r1, r2;
0572         int cassette, fimin, fimax;
0573 #ifdef EDM_ML_DEBUG
0574         edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: ti " << ti << ":" << fine << " index "
0575                                       << tileFineIndex_.size() << ":" << tileCoarseIndex_.size() << " Phis "
0576                                       << tileFinePhis_.size() << ":" << tileCoarsePhis_.size();
0577 #endif
0578         if (fine) {
0579           r1 = tileFineRMin_[std::get<1>(HGCalTileIndex::tileUnpack(tileFineIndex_[ti])) - 1];
0580           r2 = tileFineRMax_[std::get<2>(HGCalTileIndex::tileUnpack(tileFineIndex_[ti])) - 1];
0581           cassette = std::get<0>(HGCalTileIndex::tileUnpack(tileFinePhis_[ti]));
0582           fimin = std::get<1>(HGCalTileIndex::tileUnpack(tileFinePhis_[ti]));
0583           fimax = std::get<2>(HGCalTileIndex::tileUnpack(tileFinePhis_[ti]));
0584         } else {
0585           r1 = tileCoarseRMin_[std::get<1>(HGCalTileIndex::tileUnpack(tileCoarseIndex_[ti])) - 1];
0586           r2 = tileCoarseRMax_[std::get<2>(HGCalTileIndex::tileUnpack(tileCoarseIndex_[ti])) - 1];
0587           cassette = std::get<0>(HGCalTileIndex::tileUnpack(tileCoarsePhis_[ti]));
0588           fimin = std::get<1>(HGCalTileIndex::tileUnpack(tileCoarsePhis_[ti]));
0589           fimax = std::get<2>(HGCalTileIndex::tileUnpack(tileCoarsePhis_[ti]));
0590         }
0591 #ifdef EDM_ML_DEBUG
0592         edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Casstee|Fimin|Fimax " << cassette << ":"
0593                                       << fimin << ":" << fimax;
0594 #endif
0595         double phi1 = dphi * (fimin - 1);
0596         double phi2 = dphi * (fimax - fimin + 1);
0597         auto cshift = cassette_.getShift(layer + 1, 1, cassette, true);
0598 #ifdef EDM_ML_DEBUG
0599         int cassette0 = HGCalCassette::cassetteType(2, 1, cassette);  //
0600         int ir1 = (fine) ? std::get<1>(HGCalTileIndex::tileUnpack(tileFineIndex_[ti]))
0601                          : std::get<1>(HGCalTileIndex::tileUnpack(tileCoarseIndex_[ti]));
0602         int ir2 = (fine) ? std::get<2>(HGCalTileIndex::tileUnpack(tileFineIndex_[ti]))
0603                          : std::get<2>(HGCalTileIndex::tileUnpack(tileCoarseIndex_[ti]));
0604         edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Layer " << copy << ":" << (layer + 1) << " iR "
0605                                       << ir1 << ":" << ir2 << " R " << r1 << ":" << r2 << " Thick " << (2.0 * hthickl)
0606                                       << " phi " << fimin << ":" << fimax << ":" << convertRadToDeg(phi1) << ":"
0607                                       << convertRadToDeg(phi2) << " cassette " << cassette << ":" << cassette0
0608                                       << " Shift " << cshift.first << ":" << cshift.second;
0609 #endif
0610         std::string name = namesTop_[ii] + "L" + std::to_string(copy) + "F" + std::to_string(k);
0611         ++k;
0612         DDSolid solid = DDSolidFactory::tubs(DDName(name, nameSpace_), hthickl, r1, r2, phi1, phi2);
0613         DDLogicalPart glog1 = DDLogicalPart(solid.ddname(), matter1, solid);
0614 #ifdef EDM_ML_DEBUG
0615         edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: " << glog1.name() << " Tubs made of "
0616                                       << matName << " of dimensions " << r1 << ", " << r2 << ", " << hthickl << ", "
0617                                       << convertRadToDeg(phi1) << ", " << convertRadToDeg(phi2);
0618 #endif
0619         DDTranslation tran(-cshift.first, cshift.second, zpos);
0620         cpv.position(glog1, glog, copy, tran, rot);
0621 #ifdef EDM_ML_DEBUG
0622         edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Position " << glog1.name() << " number "
0623                                       << copy << " in " << glog.name() << " at " << tran << " with no rotation";
0624 #endif
0625       }
0626       ++copyNumberTop_[ii];
0627       zpos += hthickl;
0628     }
0629     if (std::abs(thickTot - thick) >= tol2_) {
0630       if (thickTot > thick) {
0631         edm::LogError("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Thickness of the partition " << thick
0632                                    << " is smaller than " << thickTot
0633                                    << ": thickness of all its components in the top part **** ERROR ****";
0634       } else {
0635         edm::LogWarning("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Thickness of the partition " << thick
0636                                      << " does not match with " << thickTot << " of the components in top part";
0637       }
0638     }
0639   } else {
0640     int ii = coverTypeTop_;
0641     int copy = copyNumberCoverTop_[absType - 1];
0642     int layer = (fine) ? (copy - firstFineLayer_) : (copy - firstCoarseLayer_);
0643     double hthickl = 0.5 * layerThickTop_[ii];
0644     zpos += hthickl;
0645     DDName matName(DDSplit(materialTop_[ii]).first, DDSplit(materialTop_[ii]).second);
0646     DDMaterial matter1(matName);
0647     unsigned int k = 0;
0648     int firstTile = (fine) ? tileFineLayerStart_[layer] : tileCoarseLayerStart_[layer];
0649     int lastTile =
0650         (fine) ? ((layer + 1 < static_cast<int>(tileFineLayerStart_.size())) ? tileFineLayerStart_[layer + 1]
0651                                                                              : static_cast<int>(tileFineIndex_.size()))
0652                : ((layer + 1 < static_cast<int>(tileCoarseLayerStart_.size()))
0653                       ? tileCoarseLayerStart_[layer + 1]
0654                       : static_cast<int>(tileCoarseIndex_.size()));
0655 #ifdef EDM_ML_DEBUG
0656     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: TOP Layer " << ii << ":" << layer << " Copy "
0657                                   << copy << " Tiles " << firstTile << ":" << lastTile << " Size "
0658                                   << tileFineIndex_.size() << ":" << tileCoarseIndex_.size() << " Fine " << fine
0659                                   << " absType " << absType;
0660 #endif
0661     for (int ti = firstTile; ti < lastTile; ++ti) {
0662       double r1, r2;
0663       int cassette, fimin, fimax;
0664 #ifdef EDM_ML_DEBUG
0665       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: ti " << ti << ":" << fine << " index "
0666                                     << tileFineIndex_.size() << ":" << tileCoarseIndex_.size() << " Phis "
0667                                     << tileFinePhis_.size() << ":" << tileCoarsePhis_.size();
0668 #endif
0669       if (fine) {
0670         r1 = tileFineRMin_[std::get<1>(HGCalTileIndex::tileUnpack(tileFineIndex_[ti])) - 1];
0671         r2 = tileFineRMax_[std::get<2>(HGCalTileIndex::tileUnpack(tileFineIndex_[ti])) - 1];
0672         cassette = std::get<0>(HGCalTileIndex::tileUnpack(tileFinePhis_[ti]));
0673         fimin = std::get<1>(HGCalTileIndex::tileUnpack(tileFinePhis_[ti]));
0674         fimax = std::get<2>(HGCalTileIndex::tileUnpack(tileFinePhis_[ti]));
0675       } else {
0676         r1 = tileCoarseRMin_[std::get<1>(HGCalTileIndex::tileUnpack(tileCoarseIndex_[ti])) - 1];
0677         r2 = tileCoarseRMax_[std::get<2>(HGCalTileIndex::tileUnpack(tileCoarseIndex_[ti])) - 1];
0678         cassette = std::get<0>(HGCalTileIndex::tileUnpack(tileCoarsePhis_[ti]));
0679         fimin = std::get<1>(HGCalTileIndex::tileUnpack(tileCoarsePhis_[ti]));
0680         fimax = std::get<2>(HGCalTileIndex::tileUnpack(tileCoarsePhis_[ti]));
0681       }
0682 #ifdef EDM_ML_DEBUG
0683       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Casstee|Fimin|Fimax " << cassette << ":" << fimin
0684                                     << ":" << fimax;
0685 #endif
0686       double phi1 = dphi * (fimin - 1);
0687       double phi2 = dphi * (fimax - fimin + 1);
0688       auto cshift = cassette_.getShift(layer + 1, 1, cassette, true);
0689 #ifdef EDM_ML_DEBUG
0690       int cassette0 = HGCalCassette::cassetteType(2, 1, cassette);  //
0691       int ir1 = (fine) ? std::get<1>(HGCalTileIndex::tileUnpack(tileFineIndex_[ti]))
0692                        : std::get<1>(HGCalTileIndex::tileUnpack(tileCoarseIndex_[ti]));
0693       int ir2 = (fine) ? std::get<2>(HGCalTileIndex::tileUnpack(tileFineIndex_[ti]))
0694                        : std::get<2>(HGCalTileIndex::tileUnpack(tileCoarseIndex_[ti]));
0695       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Layer " << copy << ":" << (layer + 1) << " iR "
0696                                     << ir1 << ":" << ir2 << " R " << r1 << ":" << r2 << " Thick " << (2.0 * hthickl)
0697                                     << " phi " << fimin << ":" << fimax << ":" << convertRadToDeg(phi1) << ":"
0698                                     << convertRadToDeg(phi2) << " cassette " << cassette << ":" << cassette0
0699                                     << " Shift " << cshift.first << ":" << cshift.second;
0700 #endif
0701       std::string name = namesTop_[ii] + "L" + std::to_string(copy) + "F" + std::to_string(k);
0702       ++k;
0703       DDSolid solid = DDSolidFactory::tubs(DDName(name, nameSpace_), hthickl, r1, r2, phi1, phi2);
0704       DDLogicalPart glog1 = DDLogicalPart(solid.ddname(), matter1, solid);
0705 #ifdef EDM_ML_DEBUG
0706       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: " << glog1.name() << " Tubs made of " << matName
0707                                     << " of dimensions " << r1 << ", " << r2 << ", " << hthickl << ", "
0708                                     << convertRadToDeg(phi1) << ", " << convertRadToDeg(phi2);
0709 #endif
0710       DDTranslation tran(-cshift.first, cshift.second, zpos);
0711       cpv.position(glog1, glog, copy, tran, rot);
0712 #ifdef EDM_ML_DEBUG
0713       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Position " << glog1.name() << " number " << copy
0714                                     << " in " << glog.name() << " at " << tran << " with no rotation";
0715 #endif
0716     }
0717     ++copyNumberCoverTop_[absType - 1];
0718   }
0719 
0720   // Make the bottom part next
0721   int layer = (copyM - firstFineLayer_);
0722 #ifdef EDM_ML_DEBUG
0723   edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Start bottom section for layer " << layer
0724                                 << " absType " << absType;
0725 #endif
0726   if (absType > 0) {
0727 #ifdef EDM_ML_DEBUG
0728     int kount(0);
0729 #endif
0730     for (int k = 0; k < cassettes_; ++k) {
0731       int cassette = k + 1;
0732       auto cshift = cassette_.getShift(layer + 1, -1, cassette);
0733       double xpos = -cshift.first;
0734       double ypos = cshift.second;
0735       int i = layer * cassettes_ + k;
0736 #ifdef EDM_ML_DEBUG
0737       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette::Passive: layer " << layer + 1 << " cassette "
0738                                     << cassette << " Shift " << cshift.first << ":" << cshift.second << " PassiveIndex "
0739                                     << i << ":" << passiveFull_.size() << ":" << passivePart_.size();
0740 #endif
0741       std::string passive = (absType <= waferTypes_) ? passiveFull_[i] : passivePart_[i];
0742 #ifdef EDM_ML_DEBUG
0743       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Passive " << passive << " number " << cassette
0744                                     << " pos " << xpos << ":" << ypos;
0745       kount++;
0746 #endif
0747       DDTranslation tran(xpos, ypos, 0.0);
0748       DDRotation rotation;
0749       DDName name = DDName(DDSplit(passive).first, DDSplit(passive).second);
0750       cpv.position(name, glog.ddname(), cassette, tran, rotation);
0751 #ifdef EDM_ML_DEBUG
0752       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: " << name << " number " << cassette
0753                                     << " positioned in " << glog.ddname() << " at " << tran << " with no rotation";
0754 #endif
0755     }
0756 #ifdef EDM_ML_DEBUG
0757     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: " << kount << " passives of type " << absType
0758                                   << " for " << glog.ddname();
0759 #endif
0760   } else {
0761     static const double sqrt3 = std::sqrt(3.0);
0762     int layercenter = layerOrient_[layer];
0763     int layertype = HGCalTypes::layerFrontBack(layerOrient_[layer]);
0764     int firstWafer = waferLayerStart_[layer];
0765     int lastWafer = ((layer + 1 < static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
0766                                                                              : static_cast<int>(waferIndex_.size()));
0767     double delx = 0.5 * (waferSize_ + waferSepar_);
0768     double dely = 2.0 * delx / sqrt3;
0769     double dy = 0.75 * dely;
0770     const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
0771 #ifdef EDM_ML_DEBUG
0772     int ium(0), ivm(0), kount(0);
0773     std::vector<int> ntype(3, 0);
0774     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette::Bottom: " << glog.ddname() << "  r " << delx
0775                                   << " R " << dely << " dy " << dy << " Shift " << xyoff.first << ":" << xyoff.second
0776                                   << " WaferSize " << (waferSize_ + waferSepar_) << " index " << firstWafer << ":"
0777 
0778                                   << (lastWafer - 1) << " Copy " << copyM << ":" << layer;
0779 #endif
0780     for (int k = firstWafer; k < lastWafer; ++k) {
0781       int u = HGCalWaferIndex::waferU(waferIndex_[k]);
0782       int v = HGCalWaferIndex::waferV(waferIndex_[k]);
0783 #ifdef EDM_ML_DEBUG
0784       int iu = std::abs(u);
0785       int iv = std::abs(v);
0786 #endif
0787       int nr = 2 * v;
0788       int nc = -2 * u + v;
0789       int type = HGCalProperty::waferThick(waferProperty_[k]);
0790       int part = HGCalProperty::waferPartial(waferProperty_[k]);
0791       int orien = HGCalProperty::waferOrient(waferProperty_[k]);
0792       int cassette = HGCalProperty::waferCassette(waferProperty_[k]);
0793       int place = HGCalCell::cellPlacementIndex(1, layertype, orien);
0794 #ifdef EDM_ML_DEBUG
0795       edm::LogVerbatim("HGCalGeom")
0796           << "DDHGCalMixRotatedFineCassette::index:Property:layertype:type:part:orien:cassette:place:offsets:ind " << k
0797           << ":" << waferProperty_[k] << ":" << layertype << ":" << type << ":" << part << ":" << orien << ":"
0798           << cassette << ":" << place;
0799 #endif
0800       auto cshift = cassette_.getShift(layer + 1, -1, cassette, false);
0801       double xpos = xyoff.first - cshift.first + nc * delx;
0802       double ypos = xyoff.second + cshift.second + nr * dy;
0803 #ifdef EDM_ML_DEBUG
0804       double xorig = xyoff.first + nc * delx;
0805       double yorig = xyoff.second + nr * dy;
0806       double angle = std::atan2(yorig, xorig);
0807       edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette::Wafer: layer " << layer + 1 << " cassette "
0808                                     << cassette << " Shift " << cshift.first << ":" << cshift.second << " Original "
0809                                     << xorig << ":" << yorig << ":" << convertRadToDeg(angle) << " Final " << xpos
0810                                     << ":" << ypos;
0811 #endif
0812       std::string wafer;
0813       int i(999);
0814       if (part == HGCalTypes::WaferFull) {
0815         i = type * facingTypes_ * orientationTypes_ + place - placeOffset_;
0816 #ifdef EDM_ML_DEBUG
0817         edm::LogVerbatim("HGCalGeom") << " FullWafer type:place:ind " << type << ":" << place << ":" << i << ":"
0818                                       << waferFull_.size();
0819 #endif
0820         wafer = waferFull_[i];
0821       } else {
0822         int partoffset =
0823             (part >= HGCalTypes::WaferHDTop) ? HGCalTypes::WaferPartHDOffset : HGCalTypes::WaferPartLDOffset;
0824         i = (part - partoffset) * facingTypes_ * orientationTypes_ +
0825             HGCalTypes::WaferTypeOffset[type] * facingTypes_ * orientationTypes_ + place - placeOffset_;
0826 #ifdef EDM_ML_DEBUG
0827         edm::LogVerbatim("HGCalGeom") << " layertype:type:part:orien:cassette:place:offsets:ind " << layertype << ":"
0828                                       << type << ":" << part << ":" << orien << ":" << cassette << ":" << place << ":"
0829                                       << partoffset << ":" << HGCalTypes::WaferTypeOffset[type] << ":" << i << ":"
0830                                       << waferPart_.size();
0831 #endif
0832         wafer = waferPart_[i];
0833       }
0834       int copy = HGCalTypes::packTypeUV(type, u, v);
0835 #ifdef EDM_ML_DEBUG
0836       edm::LogVerbatim("HGCalGeom") << " DDHGCalMixRotatedFineCassette: Layer "
0837                                     << HGCalWaferIndex::waferLayer(waferIndex_[k]) << " Wafer " << wafer << " number "
0838                                     << copy << " type :part:orien:ind " << type << ":" << part << ":" << orien << ":"
0839                                     << i << " layer:u:v " << (layer + firstFineLayer_) << ":" << u << ":" << v;
0840       if (iu > ium)
0841         ium = iu;
0842       if (iv > ivm)
0843         ivm = iv;
0844       kount++;
0845       if (copies_.count(copy) == 0)
0846         copies_.insert(copy);
0847 #endif
0848       DDTranslation tran(xpos, ypos, 0.0);
0849       DDName name = DDName(DDSplit(wafer).first, DDSplit(wafer).second);
0850       cpv.position(name, glog.ddname(), copy, tran, rot);
0851 #ifdef EDM_ML_DEBUG
0852       ++ntype[type];
0853       edm::LogVerbatim("HGCalGeom") << " DDHGCalMixRotatedFineCassette: " << name << " number " << copy << " type "
0854                                     << layertype << ":" << type << " positioned in " << glog.ddname() << " at " << tran
0855                                     << " with no rotation";
0856 #endif
0857     }
0858 #ifdef EDM_ML_DEBUG
0859     edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedFineCassette: Maximum # of u " << ium << " # of v " << ivm
0860                                   << " and " << kount << " wafers (" << ntype[0] << ":" << ntype[1] << ":" << ntype[2]
0861                                   << ") for " << glog.ddname();
0862 #endif
0863   }
0864 }
0865 
0866 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalMixRotatedFineCassette, "hgcal:DDHGCalMixRotatedFineCassette");