Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDHGCalSiliconRotatedModule.cc
0003 // Description: Geometry factory class for HGCal (EE and HESil) using
0004 //              information from the file for dd4hep
0005 ///////////////////////////////////////////////////////////////////////////////
0006 #include <cmath>
0007 #include <memory>
0008 #include <sstream>
0009 #include <string>
0010 #include <unordered_set>
0011 #include <vector>
0012 
0013 #include "Geometry/HGCalCommonData/interface/HGCalCell.h"
0014 #include "Geometry/HGCalCommonData/interface/HGCalCassette.h"
0015 #include "Geometry/HGCalCommonData/interface/HGCalGeomTools.h"
0016 #include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
0017 #include "Geometry/HGCalCommonData/interface/HGCalProperty.h"
0018 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0019 #include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h"
0020 #include "Geometry/HGCalCommonData/interface/HGCalWaferType.h"
0021 #include "DD4hep/DetFactoryHelper.h"
0022 #include "DataFormats/Math/interface/angle_units.h"
0023 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0024 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0026 
0027 //#define EDM_ML_DEBUG
0028 using namespace angle_units::operators;
0029 
0030 struct HGCalSiliconRotatedModule {
0031   HGCalSiliconRotatedModule() {
0032     throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalSiliconRotatedModule";
0033   }
0034   HGCalSiliconRotatedModule(cms::DDParsingContext& ctxt, xml_h e) {
0035     cms::DDNamespace ns(ctxt, e, true);
0036     cms::DDAlgoArguments args(ctxt, e);
0037 
0038 #ifdef EDM_ML_DEBUG
0039     edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: Creating an instance";
0040 #endif
0041     static constexpr double tol1 = 0.01 * dd4hep::mm;
0042     static constexpr double tol2 = 0.00001 * dd4hep::mm;
0043 
0044     dd4hep::Volume mother = ns.volume(args.parentName());
0045     waferTypes_ = args.value<int>("WaferTypes");
0046     facingTypes_ = args.value<int>("FacingTypes");
0047     orientationTypes_ = args.value<int>("OrientationTypes");
0048     placeOffset_ = args.value<int>("PlaceOffset");
0049 #ifdef EDM_ML_DEBUG
0050     edm::LogVerbatim("HGCalGeom") << "Number of types of wafers: " << waferTypes_ << " facings: " << facingTypes_
0051                                   << " Orientations: " << orientationTypes_ << " PlaceOffset: " << placeOffset_;
0052 #endif
0053     firstLayer_ = args.value<int>("FirstLayer");
0054     absorbMode_ = args.value<int>("AbsorberMode");
0055     sensitiveMode_ = args.value<int>("SensitiveMode");
0056 #ifdef EDM_ML_DEBUG
0057     edm::LogVerbatim("HGCalGeom") << "First Layer " << firstLayer_ << " and "
0058                                   << "Absober:Sensitive mode " << absorbMode_ << ":" << sensitiveMode_;
0059 #endif
0060     zMinBlock_ = args.value<double>("zMinBlock");
0061     waferSize_ = args.value<double>("waferSize");
0062     waferSepar_ = args.value<double>("SensorSeparation");
0063     sectors_ = args.value<int>("Sectors");
0064     cassettes_ = args.value<int>("Cassettes");
0065     alpha_ = (1._pi) / sectors_;
0066     cosAlpha_ = cos(alpha_);
0067     rotstr_ = args.value<std::string>("LayerRotation");
0068 #ifdef EDM_ML_DEBUG
0069     edm::LogVerbatim("HGCalGeom") << "zStart " << cms::convert2mm(zMinBlock_) << " wafer width "
0070                                   << cms::convert2mm(waferSize_) << " separations " << cms::convert2mm(waferSepar_)
0071                                   << " sectors " << sectors_ << ":" << convertRadToDeg(alpha_) << ":" << cosAlpha_
0072                                   << " rotation matrix " << rotstr_ << " with " << cassettes_ << " cassettes";
0073 #endif
0074     waferFull_ = args.value<std::vector<std::string>>("WaferNamesFull");
0075     waferPart_ = args.value<std::vector<std::string>>("WaferNamesPartial");
0076 #ifdef EDM_ML_DEBUG
0077     edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: " << waferFull_.size() << " full and "
0078                                   << waferPart_.size() << " partial modules\nDDHGCalSiliconRotatedModule:Full Modules:";
0079     unsigned int i1max = static_cast<unsigned int>(waferFull_.size());
0080     for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
0081       std::ostringstream st1;
0082       unsigned int i2 = std::min((i1 + 2), i1max);
0083       for (unsigned int i = i1; i < i2; ++i)
0084         st1 << " [" << i << "] " << waferFull_[i];
0085       edm::LogVerbatim("HGCalGeom") << st1.str();
0086     }
0087     edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: Partial Modules:";
0088     i1max = static_cast<unsigned int>(waferPart_.size());
0089     for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
0090       std::ostringstream st1;
0091       unsigned int i2 = std::min((i1 + 2), i1max);
0092       for (unsigned int i = i1; i < i2; ++i)
0093         st1 << " [" << i << "] " << waferPart_[i];
0094       edm::LogVerbatim("HGCalGeom") << st1.str();
0095     }
0096 #endif
0097     materials_ = args.value<std::vector<std::string>>("MaterialNames");
0098     names_ = args.value<std::vector<std::string>>("VolumeNames");
0099     thick_ = args.value<std::vector<double>>("Thickness");
0100     copyNumber_.resize(materials_.size(), 1);
0101 #ifdef EDM_ML_DEBUG
0102     edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: " << materials_.size() << " types of volumes";
0103     for (unsigned int i = 0; i < names_.size(); ++i)
0104       edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names_[i] << " of thickness "
0105                                     << cms::convert2mm(thick_[i]) << " filled with " << materials_[i]
0106                                     << " first copy number " << copyNumber_[i];
0107 #endif
0108     layers_ = args.value<std::vector<int>>("Layers");
0109     layerThick_ = args.value<std::vector<double>>("LayerThick");
0110 #ifdef EDM_ML_DEBUG
0111     edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks";
0112     for (unsigned int i = 0; i < layers_.size(); ++i)
0113       edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << cms::convert2mm(layerThick_[i])
0114                                     << " with " << layers_[i] << " layers";
0115 #endif
0116     layerType_ = args.value<std::vector<int>>("LayerType");
0117     layerSense_ = args.value<std::vector<int>>("LayerSense");
0118     layerOrient_ = args.value<std::vector<int>>("LayerTypes");
0119     for (unsigned int k = 0; k < layerOrient_.size(); ++k)
0120       layerOrient_[k] = HGCalTypes::layerType(layerOrient_[k]);
0121 #ifdef EDM_ML_DEBUG
0122     for (unsigned int i = 0; i < layerOrient_.size(); ++i)
0123       edm::LogVerbatim("HGCalGeom") << "LayerTypes [" << i << "] " << layerOrient_[i];
0124 #endif
0125     if (firstLayer_ > 0) {
0126       for (unsigned int i = 0; i < layerType_.size(); ++i) {
0127         if (layerSense_[i] > 0) {
0128           int ii = layerType_[i];
0129           copyNumber_[ii] = (layerSense_[i] == 1) ? firstLayer_ : (firstLayer_ + 1);
0130 #ifdef EDM_ML_DEBUG
0131           edm::LogVerbatim("HGCalGeom") << "First copy number for layer type " << i << ":" << ii << " with "
0132                                         << materials_[ii] << " changed to " << copyNumber_[ii];
0133 #endif
0134         }
0135       }
0136     } else {
0137       firstLayer_ = 1;
0138     }
0139 #ifdef EDM_ML_DEBUG
0140     edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " layers";
0141     for (unsigned int i = 0; i < layerType_.size(); ++i)
0142       edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType_[i] << " sensitive class "
0143                                     << layerSense_[i];
0144 #endif
0145     slopeB_ = args.value<std::vector<double>>("SlopeBottom");
0146     zFrontB_ = args.value<std::vector<double>>("ZFrontBottom");
0147     rMinFront_ = args.value<std::vector<double>>("RMinFront");
0148     slopeT_ = args.value<std::vector<double>>("SlopeTop");
0149     zFrontT_ = args.value<std::vector<double>>("ZFrontTop");
0150     rMaxFront_ = args.value<std::vector<double>>("RMaxFront");
0151 #ifdef EDM_ML_DEBUG
0152     for (unsigned int i = 0; i < slopeB_.size(); ++i)
0153       edm::LogVerbatim("HGCalGeom") << "Bottom Block [" << i << "] Zmin " << cms::convert2mm(zFrontB_[i]) << " Rmin "
0154                                     << cms::convert2mm(rMinFront_[i]) << " Slope " << slopeB_[i];
0155     for (unsigned int i = 0; i < slopeT_.size(); ++i)
0156       edm::LogVerbatim("HGCalGeom") << "Top Block [" << i << "] Zmin " << cms::convert2mm(zFrontT_[i]) << " Rmax "
0157                                     << cms::convert2mm(rMaxFront_[i]) << " Slope " << slopeT_[i];
0158 #endif
0159     waferIndex_ = args.value<std::vector<int>>("WaferIndex");
0160     waferProperty_ = args.value<std::vector<int>>("WaferProperties");
0161     waferLayerStart_ = args.value<std::vector<int>>("WaferLayerStart");
0162     cassetteShift_ = args.value<std::vector<double>>("CassetteShift");
0163 #ifdef EDM_ML_DEBUG
0164     edm::LogVerbatim("HGCalGeom") << "waferProperties with " << waferIndex_.size() << " entries in "
0165                                   << waferLayerStart_.size() << " layers";
0166     for (unsigned int k = 0; k < waferLayerStart_.size(); ++k)
0167       edm::LogVerbatim("HGCalGeom") << "LayerStart[" << k << "] " << waferLayerStart_[k];
0168     for (unsigned int k = 0; k < waferIndex_.size(); ++k)
0169       edm::LogVerbatim("HGCalGeom") << "Wafer[" << k << "] " << waferIndex_[k] << " ("
0170                                     << HGCalWaferIndex::waferLayer(waferIndex_[k]) << ", "
0171                                     << HGCalWaferIndex::waferU(waferIndex_[k]) << ", "
0172                                     << HGCalWaferIndex::waferV(waferIndex_[k]) << ") : ("
0173                                     << HGCalProperty::waferThick(waferProperty_[k]) << ":"
0174                                     << HGCalProperty::waferPartial(waferProperty_[k]) << ":"
0175                                     << HGCalProperty::waferOrient(waferProperty_[k]) << ")";
0176     edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: " << cassetteShift_.size()
0177                                   << " elements for cassette shifts";
0178     unsigned int j1max = cassetteShift_.size();
0179     for (unsigned int j1 = 0; j1 < j1max; j1 += 6) {
0180       std::ostringstream st1;
0181       unsigned int j2 = std::min((j1 + 6), j1max);
0182       for (unsigned int j = j1; j < j2; ++j)
0183         st1 << " [" << j << "] " << std::setw(9) << cms::convert2mm(cassetteShift_[j]);
0184       edm::LogVerbatim("HGCalGeom") << st1.str();
0185     }
0186 
0187     edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: NameSpace " << ns.name();
0188 #endif
0189     cassette_.setParameter(cassettes_, cassetteShift_);
0190 
0191 #ifdef EDM_ML_DEBUG
0192     edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalSiliconRotatedModule...";
0193     copies_.clear();
0194 #endif
0195 
0196     double zi(zMinBlock_);
0197     int laymin(0);
0198     for (unsigned int i = 0; i < layers_.size(); ++i) {
0199       double zo = zi + layerThick_[i];
0200       double routF = HGCalGeomTools::radius(zi, zFrontT_, rMaxFront_, slopeT_);
0201       int laymax = laymin + layers_[i];
0202       double zz = zi;
0203       double thickTot(0);
0204       for (int ly = laymin; ly < laymax; ++ly) {
0205         int ii = layerType_[ly];
0206         int copy = copyNumber_[ii];
0207         double hthick = 0.5 * thick_[ii];
0208         double rinB = HGCalGeomTools::radius(zo - tol1, zFrontB_, rMinFront_, slopeB_);
0209         zz += hthick;
0210         thickTot += thick_[ii];
0211 
0212         std::string name = names_[ii] + std::to_string(copy);
0213 #ifdef EDM_ML_DEBUG
0214         edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: Layer " << ly << ":" << ii << " Front "
0215                                       << cms::convert2mm(zi) << ", " << cms::convert2mm(routF) << " Back "
0216                                       << cms::convert2mm(zo) << ", " << cms::convert2mm(rinB)
0217                                       << " superlayer thickness " << cms::convert2mm(layerThick_[i]);
0218 #endif
0219 
0220         dd4hep::Material matter = ns.material(materials_[ii]);
0221         dd4hep::Volume glog;
0222 
0223         if (layerSense_[ly] < 1) {
0224           std::vector<double> pgonZ, pgonRin, pgonRout;
0225           double rmax = routF * cosAlpha_ - tol1;
0226           HGCalGeomTools::radius(zz - hthick,
0227                                  zz + hthick,
0228                                  zFrontB_,
0229                                  rMinFront_,
0230                                  slopeB_,
0231                                  zFrontT_,
0232                                  rMaxFront_,
0233                                  slopeT_,
0234                                  -layerSense_[ly],
0235                                  pgonZ,
0236                                  pgonRin,
0237                                  pgonRout);
0238           for (unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
0239             pgonZ[isec] -= zz;
0240             if (layerSense_[ly] == 0 || absorbMode_ == 0)
0241               pgonRout[isec] = rmax;
0242             else
0243               pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1;
0244           }
0245           dd4hep::Solid solid = dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
0246           ns.addSolidNS(ns.prepend(name), solid);
0247           glog = dd4hep::Volume(solid.name(), solid, matter);
0248           ns.addVolumeNS(glog);
0249 #ifdef EDM_ML_DEBUG
0250           edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: " << solid.name() << " polyhedra of "
0251                                         << sectors_ << " sectors covering " << convertRadToDeg(-alpha_) << ":"
0252                                         << convertRadToDeg(-alpha_ + 2._pi) << " with " << pgonZ.size()
0253                                         << " sections and filled with " << matter.name();
0254           for (unsigned int k = 0; k < pgonZ.size(); ++k)
0255             edm::LogVerbatim("HGCalGeom") << "[" << k << "] z " << cms::convert2mm(pgonZ[k]) << " R "
0256                                           << cms::convert2mm(pgonRin[k]) << ":" << cms::convert2mm(pgonRout[k]);
0257 #endif
0258         } else {
0259           double rins =
0260               (sensitiveMode_ < 1) ? rinB : HGCalGeomTools::radius(zz + hthick - tol1, zFrontB_, rMinFront_, slopeB_);
0261           double routs =
0262               (sensitiveMode_ < 1) ? routF : HGCalGeomTools::radius(zz - hthick, zFrontT_, rMaxFront_, slopeT_);
0263           dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
0264           ns.addSolidNS(ns.prepend(name), solid);
0265           glog = dd4hep::Volume(solid.name(), solid, matter);
0266           ns.addVolumeNS(glog);
0267 
0268 #ifdef EDM_ML_DEBUG
0269           edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: " << solid.name() << " Tubs made of "
0270                                         << matter.name() << " of dimensions " << cms::convert2mm(rinB) << ":"
0271                                         << cms::convert2mm(rins) << ", " << cms::convert2mm(routF) << ":"
0272                                         << cms::convert2mm(routs) << ", " << cms::convert2mm(hthick)
0273                                         << ", 0.0, 360.0 and position " << glog.name() << " number " << copy << ":"
0274                                         << layerOrient_[copy - firstLayer_];
0275 #endif
0276           positionSensitive(ctxt, e, glog, (copy - firstLayer_));
0277         }
0278 
0279         dd4hep::Position r1(0, 0, zz);
0280         dd4hep::Rotation3D rot;
0281 #ifdef EDM_ML_DEBUG
0282         std::string rotName("Null");
0283 #endif
0284         if ((layerSense_[ly] > 0) && (layerOrient_[copy - firstLayer_] == HGCalTypes::WaferCenterR)) {
0285           rot = ns.rotation(rotstr_);
0286 #ifdef EDM_ML_DEBUG
0287           rotName = rotstr_;
0288 #endif
0289         }
0290         mother.placeVolume(glog, copy, dd4hep::Transform3D(rot, r1));
0291         int inc = ((layerSense_[ly] > 0) && (facingTypes_ > 1)) ? 2 : 1;
0292         copyNumber_[ii] = copy + inc;
0293 #ifdef EDM_ML_DEBUG
0294         edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: " << glog.name() << " number " << copy
0295                                       << " positioned in " << mother.name() << " at (0,0," << cms::convert2mm(zz)
0296                                       << ") with " << rotName << " rotation";
0297 #endif
0298         zz += hthick;
0299       }  // End of loop over layers in a block
0300       zi = zo;
0301       laymin = laymax;
0302       // Make consistency check of all the partitions of the block
0303       if (std::abs(thickTot - layerThick_[i]) >= tol2) {
0304         if (thickTot > layerThick_[i]) {
0305           edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick_[i])
0306                                      << " is smaller than " << cms::convert2mm(thickTot)
0307                                      << ": thickness of all its components **** ERROR ****";
0308         } else {
0309           edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick_[i])
0310                                        << " does not match with " << cms::convert2mm(thickTot) << " of the components";
0311         }
0312       }
0313     }  // End of loop over blocks
0314 
0315 #ifdef EDM_ML_DEBUG
0316     edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: " << copies_.size()
0317                                   << " different wafer copy numbers";
0318     int k(0);
0319     for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++k) {
0320       edm::LogVerbatim("HGCalGeom") << "Copy [" << k << "] : " << (*itr);
0321     }
0322     copies_.clear();
0323     edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalSiliconRotatedModule construction...";
0324 #endif
0325   }
0326 
0327   void positionSensitive(cms::DDParsingContext& ctxt, xml_h e, const dd4hep::Volume& glog, int layer) {
0328     cms::DDNamespace ns(ctxt, e, true);
0329     static const double sqrt3 = std::sqrt(3.0);
0330     int layercenter = layerOrient_[layer];
0331     int layertype = (layerOrient_[layer] == HGCalTypes::WaferCenterB) ? 1 : 0;
0332     int firstWafer = waferLayerStart_[layer];
0333     int lastWafer = ((layer + 1 < static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
0334                                                                              : static_cast<int>(waferIndex_.size()));
0335     double delx = 0.5 * (waferSize_ + waferSepar_);
0336     double dely = 2.0 * delx / sqrt3;
0337     double dy = 0.75 * dely;
0338     const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
0339 #ifdef EDM_ML_DEBUG
0340     int ium(0), ivm(0), kount(0);
0341     std::vector<int> ntype(3, 0);
0342     edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: " << glog.name() << " r " << cms::convert2mm(delx)
0343                                   << " R " << cms::convert2mm(dely) << " dy " << cms::convert2mm(dy) << " Shift "
0344                                   << cms::convert2mm(xyoff.first) << ":" << cms::convert2mm(xyoff.second)
0345                                   << " WaferSize " << cms::convert2mm((waferSize_ + waferSepar_)) << " index "
0346                                   << firstWafer << ":" << (lastWafer - 1) << " Layer Center " << layercenter << ":"
0347                                   << layertype;
0348 #endif
0349     for (int k = firstWafer; k < lastWafer; ++k) {
0350       int u = HGCalWaferIndex::waferU(waferIndex_[k]);
0351       int v = HGCalWaferIndex::waferV(waferIndex_[k]);
0352 #ifdef EDM_ML_DEBUG
0353       int iu = std::abs(u);
0354       int iv = std::abs(v);
0355 #endif
0356       int nr = 2 * v;
0357       int nc = -2 * u + v;
0358       int type = HGCalProperty::waferThick(waferProperty_[k]);
0359       int part = HGCalProperty::waferPartial(waferProperty_[k]);
0360       int orien = HGCalProperty::waferOrient(waferProperty_[k]);
0361       int cassette = HGCalProperty::waferCassette(waferProperty_[k]);
0362       int place = HGCalCell::cellPlacementIndex(1, layertype, orien);
0363       auto cshift = cassette_.getShift(layer + 1, -1, cassette);
0364       double xpos = xyoff.first - cshift.first + nc * delx;
0365       double ypos = xyoff.second + cshift.second + nr * dy;
0366 #ifdef EDM_ML_DEBUG
0367       double xorig = xyoff.first + nc * delx;
0368       double yorig = xyoff.second + nr * dy;
0369       double angle = std::atan2(yorig, xorig);
0370       edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule::Wafer: layer " << layer + 1 << " cassette "
0371                                     << cassette << " Shift " << cms::convert2mm(cshift.first) << ":"
0372                                     << cms::convert2mm(cshift.second) << " Original " << cms::convert2mm(xorig) << ":"
0373                                     << cms::convert2mm(yorig) << ":" << convertRadToDeg(angle) << " Final "
0374                                     << cms::convert2mm(xpos) << ":" << cms::convert2mm(ypos) << " u|v " << u << ":" << v
0375                                     << " type|part|orient|place " << type << ":" << part << ":" << orien << ":"
0376                                     << place;
0377 #endif
0378       std::string wafer;
0379       int i(999);
0380       if (part == HGCalTypes::WaferFull) {
0381         i = type * facingTypes_ * orientationTypes_ + place - placeOffset_;
0382         wafer = waferFull_[i];
0383 #ifdef EDM_ML_DEBUG
0384         edm::LogVerbatim("HGCalGeom") << " layertype:type:part:orien:cassette:place:offsets:ind " << layertype << ":"
0385                                       << type << ":" << part << ":" << orien << ":" << cassette << ":" << place << ":"
0386                                       << placeOffset_ << ":" << facingTypes_ << ":" << orientationTypes_ << " wafer "
0387                                       << i << ":" << wafer;
0388 #endif
0389       } else {
0390         int partoffset =
0391             (part >= HGCalTypes::WaferHDTop) ? HGCalTypes::WaferPartHDOffset : HGCalTypes::WaferPartLDOffset;
0392         i = (part - partoffset) * facingTypes_ * orientationTypes_ +
0393             HGCalTypes::WaferTypeOffset[type] * facingTypes_ * orientationTypes_ + place - placeOffset_;
0394 #ifdef EDM_ML_DEBUG
0395         edm::LogVerbatim("HGCalGeom") << " layertype:type:part:orien:cassette:place:offsets:ind " << layertype << ":"
0396                                       << type << ":" << part << ":" << orien << ":" << cassette << ":" << place << ":"
0397                                       << partoffset << ":" << HGCalTypes::WaferTypeOffset[type] << ":" << i << ":"
0398                                       << waferPart_.size();
0399 #endif
0400         wafer = waferPart_[i];
0401       }
0402       int copy = HGCalTypes::packTypeUV(type, u, v);
0403 #ifdef EDM_ML_DEBUG
0404       edm::LogVerbatim("HGCalGeom") << " DDHGCalSiliconRotatedModule: Layer"
0405                                     << HGCalWaferIndex::waferLayer(waferIndex_[k]) << " Wafer " << wafer << " number "
0406                                     << copy << " type:part:orien:ind " << type << ":" << part << ":" << orien << ":"
0407                                     << i << " layer:u:v:indx " << (layer + firstLayer_) << ":" << u << ":" << v;
0408       if (iu > ium)
0409         ium = iu;
0410       if (iv > ivm)
0411         ivm = iv;
0412       kount++;
0413       if (copies_.count(copy) == 0)
0414         copies_.insert(copy);
0415 #endif
0416       dd4hep::Position tran(xpos, ypos, 0.0);
0417       glog.placeVolume(ns.volume(wafer), copy, tran);
0418 #ifdef EDM_ML_DEBUG
0419       ++ntype[type];
0420       edm::LogVerbatim("HGCalGeom") << " DDHGCalSiliconRotatedModule: " << wafer << " number " << copy << " type "
0421                                     << layertype << ":" << type << " positioned in " << glog.name() << " at ("
0422                                     << cms::convert2mm(xpos) << "," << cms::convert2mm(ypos) << ",0) with no rotation";
0423 #endif
0424     }
0425 
0426 #ifdef EDM_ML_DEBUG
0427     edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedModule: Maximum # of u " << ium << " # of v " << ivm
0428                                   << " and " << kount << " wafers (" << ntype[0] << ":" << ntype[1] << ":" << ntype[2]
0429                                   << ") for " << glog.name();
0430 #endif
0431   }
0432 
0433   //Required data members to cache the values from XML file
0434   HGCalGeomTools geomTools_;
0435   HGCalCassette cassette_;
0436 
0437   int waferTypes_;                      // Number of wafer types
0438   int facingTypes_;                     // Types of facings of modules toward IP
0439   int orientationTypes_;                // Number of wafer orienations
0440   int placeOffset_;                     // Offset for placement
0441   int firstLayer_;                      // Copy # of the first sensitive layer
0442   int absorbMode_;                      // Absorber mode
0443   int sensitiveMode_;                   // Sensitive mode
0444   double zMinBlock_;                    // Starting z-value of the block
0445   double waferSize_;                    // Width of the wafer
0446   double waferSepar_;                   // Sensor separation
0447   int sectors_;                         // Sectors
0448   int cassettes_;                       // Cassettes
0449   std::string rotstr_;                  // Rotation matrix (if needed)
0450   std::vector<std::string> waferFull_;  // Names of full wafer modules
0451   std::vector<std::string> waferPart_;  // Names of partial wafer modules
0452   std::vector<std::string> materials_;  // names of materials
0453   std::vector<std::string> names_;      // Names of volumes
0454   std::vector<double> thick_;           // Thickness of the material
0455   std::vector<int> copyNumber_;         // Initial copy numbers
0456   std::vector<int> layers_;             // Number of layers in a section
0457   std::vector<double> layerThick_;      // Thickness of each section
0458   std::vector<int> layerType_;          // Type of the layer
0459   std::vector<int> layerSense_;         // Content of a layer (sensitive?)
0460   std::vector<double> slopeB_;          // Slope at the lower R
0461   std::vector<double> zFrontB_;         // Starting Z values for the slopes
0462   std::vector<double> rMinFront_;       // Corresponding rMin's
0463   std::vector<double> slopeT_;          // Slopes at the larger R
0464   std::vector<double> zFrontT_;         // Starting Z values for the slopes
0465   std::vector<double> rMaxFront_;       // Corresponding rMax's
0466   std::vector<int> layerOrient_;        // Layer orientation (Centering, rotations..)
0467   std::vector<int> waferIndex_;         // Wafer index for the types
0468   std::vector<int> waferProperty_;      // Wafer property
0469   std::vector<int> waferLayerStart_;    // Index of wafers in each layer
0470   std::vector<double> cassetteShift_;   // Shifts of the cassetes
0471   std::unordered_set<int> copies_;      // List of copy #'s
0472   double alpha_, cosAlpha_;
0473 };
0474 
0475 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0476   HGCalSiliconRotatedModule eeSiliconRotatedModuleAlgo(ctxt, e);
0477   return cms::s_executed;
0478 }
0479 
0480 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalSiliconRotatedModule, algorithm)