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