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