Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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