Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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