Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:49:45

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