Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0002 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0003 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0004 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0005 #include "DetectorDescription/Core/interface/DDMaterial.h"
0006 #include "DetectorDescription/Core/interface/DDSolid.h"
0007 #include "DetectorDescription/Core/interface/DDSplit.h"
0008 #include "DetectorDescription/Core/interface/DDTypes.h"
0009 #include "DetectorDescription/Core/interface/DDutils.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/PluginManager/interface/PluginFactory.h"
0012 
0013 #include <string>
0014 #include <vector>
0015 
0016 //#define EDM_ML_DEBUG
0017 
0018 class DDHGCalCell : public DDAlgorithm {
0019 public:
0020   // Constructor and Destructor
0021   DDHGCalCell() {}
0022 
0023   void initialize(const DDNumericArguments& nArgs,
0024                   const DDVectorArguments& vArgs,
0025                   const DDMapArguments& mArgs,
0026                   const DDStringArguments& sArgs,
0027                   const DDStringVectorArguments& vsArgs) override;
0028   void execute(DDCompactView& cpv) override;
0029 
0030 private:
0031   double waferSize_;                               // Wafer Size
0032   double waferSeparation_;                         // Wafer Saperation
0033   int addWaferSeparation_;                         // Use wafer separation
0034   double waferT_;                                  // Wafer Thickness
0035   double cellT_;                                   // Cell Thickness
0036   int nCells_;                                     // Number of columns (8:12)
0037   int posSens_;                                    // Position depleted layer
0038   std::string material_;                           // Name of the material
0039   std::string fullCN_, fullSensN_;                 // Name of full cell
0040   std::vector<std::string> truncCN_, truncSensN_;  // Names of truncated cells
0041   std::vector<std::string> extenCN_, extenSensN_;  // Names of extended  cells
0042   std::vector<std::string> cornrCN_, cornrSensN_;  // Names of corner    cells
0043   std::string nameSpace_;                          // Namespace to be used
0044 };
0045 
0046 void DDHGCalCell::initialize(const DDNumericArguments& nArgs,
0047                              const DDVectorArguments&,
0048                              const DDMapArguments&,
0049                              const DDStringArguments& sArgs,
0050                              const DDStringVectorArguments& vsArgs) {
0051   waferSize_ = nArgs["WaferSize"];
0052   waferSeparation_ = nArgs["WaferSeparation"];
0053   addWaferSeparation_ = static_cast<int>(nArgs["AddWaferSeparation"]);
0054   waferT_ = nArgs["WaferThick"];
0055   cellT_ = nArgs["CellThick"];
0056   nCells_ = (int)(nArgs["NCells"]);
0057   posSens_ = (int)(nArgs["PosSensitive"]);
0058   material_ = sArgs["Material"];
0059   fullCN_ = sArgs["FullCell"];
0060   fullSensN_ = sArgs["FullSensitive"];
0061   truncCN_ = vsArgs["TruncatedCell"];
0062   truncSensN_ = vsArgs["TruncatedSensitive"];
0063   extenCN_ = vsArgs["ExtendedCell"];
0064   extenSensN_ = vsArgs["ExtendedSensitive"];
0065   cornrCN_ = vsArgs["CornerCell"];
0066   cornrSensN_ = vsArgs["CornerSensitive"];
0067   nameSpace_ = DDCurrentNamespace::ns();
0068   if ((truncCN_.size() != truncSensN_.size()) || (extenCN_.size() != extenSensN_.size()) ||
0069       (cornrCN_.size() != cornrSensN_.size()))
0070     edm::LogWarning("HGCalGeom") << "The number of cells & sensitive differ:"
0071                                  << " Truncated " << truncCN_.size() << ":" << truncSensN_.size() << " Extended "
0072                                  << extenCN_.size() << ":" << extenSensN_.size() << " Corners " << cornrCN_.size()
0073                                  << ":" << cornrSensN_.size();
0074 #ifdef EDM_ML_DEBUG
0075   edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Wafer r " << waferSize_ << " T " << waferT_ << " Cell T " << cellT_
0076                                 << " Cells/Wafer " << nCells_ << " Material " << material_ << "Sensitive Position "
0077                                 << posSens_ << " NameSpace " << nameSpace_ << ": Full Cell: " << fullCN_ << ":"
0078                                 << fullSensN_ << " Separation " << waferSeparation_ << ":" << addWaferSeparation_;
0079   for (unsigned int k = 0; k < truncCN_.size(); ++k)
0080     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Truncated Cell[" << k << "] " << truncCN_[k] << ":"
0081                                   << truncSensN_[k];
0082   for (unsigned int k = 0; k < extenCN_.size(); ++k)
0083     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Extended Cell[" << k << "] " << extenCN_[k] << ":" << extenSensN_[k];
0084   for (unsigned int k = 0; k < cornrCN_.size(); ++k)
0085     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Corner Cell[" << k << "] " << cornrCN_[k] << ":" << cornrSensN_[k];
0086 #endif
0087 }
0088 
0089 void DDHGCalCell::execute(DDCompactView& cpv) {
0090   DDName matName(DDSplit(material_).first, DDSplit(material_).second);
0091   DDMaterial matter(matName);
0092 #ifdef EDM_ML_DEBUG
0093   edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << matName << " initialized";
0094 #endif
0095   DDLogicalPart glog1, glog2;
0096 
0097   static const double sqrt3 = std::sqrt(3.0);
0098   double R =
0099       (addWaferSeparation_ <= 1) ? waferSize_ / (3.0 * nCells_) : (waferSize_ + waferSeparation_) / (3.0 * nCells_);
0100   double r = 0.5 * R * sqrt3;
0101   double dx1 = R;
0102   double dx2 = 0.5 * dx1;
0103   double dx3 = 2.5 * dx2;
0104   double dx4 = 0.5 * dx2;
0105   double dy1 = r;
0106   double dy2 = 0.5 * dy1;
0107   double dy3 = 1.5 * dy1;
0108   std::vector<double> xx = {
0109       dx1, dx2, -dx2, -dx1, -dx2, dx2, dx3, dx1, dx4, -dx4, -dx1, -dx3, -dx3, -dx1, -dx4, dx4, dx1, dx3};
0110   std::vector<double> yy = {
0111       0, dy1, dy1, 0, -dy1, -dy1, dy2, dy1, dy3, dy3, dy1, dy2, -dy2, -dy1, -dy3, -dy3, -dy1, -dy2};
0112   double zpos = (posSens_ == 0) ? -0.5 * (waferT_ - cellT_) : 0.5 * (waferT_ - cellT_);
0113   DDTranslation tran(0, 0, zpos);
0114 
0115   double dx5 = (addWaferSeparation_ == 0) ? 0.0 : waferSeparation_ * 0.5;
0116   double dx6 = dx5 * 0.5;
0117   double dx7 = dx5;
0118   double dy4 = dx5 * 0.5 * sqrt3;
0119   double dy5 = dx5 * 2 / sqrt3;
0120   double dy6 = dy5 * 0.5;
0121   std::vector<double> txx = {dx5, dx6, -dx6, -dx5, -dx6, dx6, dx7, 0, -dx7, -dx7, 0, dx7};
0122   std::vector<double> tyy = {0, dy4, dy4, 0, -dy4, -dy4, dy6, dy5, dy6, -dy6, -dy5, -dy6};
0123   // First the full cell
0124   std::vector<double> xw = {xx[0], xx[1], xx[2], xx[3], xx[4], xx[5]};
0125   std::vector<double> yw = {yy[0], yy[1], yy[2], yy[3], yy[4], yy[5]};
0126   std::vector<double> zw = {-0.5 * waferT_, 0.5 * waferT_};
0127   std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0128   DDSolid solid = DDSolidFactory::extrudedpolygon(DDName(fullCN_, nameSpace_), xw, yw, zw, zx, zy, scale);
0129   glog1 = DDLogicalPart(solid.ddname(), matter, solid);
0130 #ifdef EDM_ML_DEBUG
0131   edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
0132                                 << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0133                                 << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0134                                 << " and " << xw.size() << " edges";
0135   for (unsigned int k = 0; k < xw.size(); ++k)
0136     edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
0137 #endif
0138   std::vector<double> zc = {-0.5 * cellT_, 0.5 * cellT_};
0139   solid = DDSolidFactory::extrudedpolygon(DDName(fullSensN_, nameSpace_), xw, yw, zc, zx, zy, scale);
0140   glog2 = DDLogicalPart(solid.ddname(), matter, solid);
0141 #ifdef EDM_ML_DEBUG
0142   edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
0143                                 << " z|x|y|s (0) " << zc[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0144                                 << " z|x|y|s (1) " << zc[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0145                                 << " and " << xw.size() << " edges";
0146   for (unsigned int k = 0; k < xw.size(); ++k)
0147     edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
0148 #endif
0149   DDRotation rot;
0150   cpv.position(glog2, glog1, 1, tran, rot);
0151 #ifdef EDM_ML_DEBUG
0152   edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name() << " at "
0153                                 << tran << " with no rotation";
0154 #endif
0155 
0156   static constexpr int ir0[] = {0, 2, 4, 1, 3, 5};
0157   static constexpr int ir1[] = {1, 3, 5, 2, 4, 0};
0158   static constexpr int ir2[] = {2, 4, 0, 3, 5, 1};
0159   static constexpr int ir3[] = {3, 5, 1, 4, 0, 2};
0160   static constexpr int ir4[] = {5, 1, 3, 0, 2, 4};
0161 
0162   static constexpr int tr[] = {1, 3, 5, 2, 4, 0};
0163   for (unsigned int i = 0; i < truncCN_.size(); ++i) {
0164     std::vector<double> xw = {xx[ir0[i]], xx[ir1[i]], xx[ir2[i]], xx[ir3[i]] + txx[tr[i]], xx[ir4[i]] + txx[tr[i]]};
0165     std::vector<double> yw = {yy[ir0[i]], yy[ir1[i]], yy[ir2[i]], yy[ir3[i]] + tyy[tr[i]], yy[ir4[i]] + tyy[tr[i]]};
0166     solid = DDSolidFactory::extrudedpolygon(DDName(truncCN_[i], nameSpace_), xw, yw, zw, zx, zy, scale);
0167     glog1 = DDLogicalPart(solid.ddname(), matter, solid);
0168 #ifdef EDM_ML_DEBUG
0169     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
0170                                   << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0171                                   << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0172                                   << " and " << xw.size() << " edges";
0173     for (unsigned int k = 0; k < xw.size(); ++k)
0174       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
0175 #endif
0176     solid = DDSolidFactory::extrudedpolygon(DDName(truncSensN_[i], nameSpace_), xw, yw, zc, zx, zy, scale);
0177     glog2 = DDLogicalPart(solid.ddname(), matter, solid);
0178 #ifdef EDM_ML_DEBUG
0179     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
0180                                   << " z|x|y|s (0) " << zc[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0181                                   << " z|x|y|s (1) " << zc[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0182                                   << " and " << xw.size() << " edges";
0183     for (unsigned int k = 0; k < xw.size(); ++k)
0184       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
0185 #endif
0186     cpv.position(glog2, glog1, 1, tran, rot);
0187 #ifdef EDM_ML_DEBUG
0188     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
0189                                   << " at " << tran << " with no rotation";
0190 #endif
0191   }
0192 
0193   static constexpr int ie0[] = {1, 3, 5, 0, 2, 4};
0194   static constexpr int ie1[] = {2, 4, 0, 1, 3, 5};
0195   static constexpr int ie2[] = {3, 5, 1, 2, 4, 0};
0196   static constexpr int ie3[] = {14, 6, 10, 12, 16, 8};
0197   static constexpr int ie4[] = {17, 9, 13, 15, 7, 11};
0198 
0199   static constexpr int te[] = {2, 4, 0, 1, 3, 5};
0200   for (unsigned int i = 0; i < extenCN_.size(); ++i) {
0201     std::vector<double> xw = {xx[ie0[i]], xx[ie1[i]], xx[ie2[i]], xx[ie3[i]] + txx[te[i]], xx[ie4[i]] + txx[te[i]]};
0202     std::vector<double> yw = {yy[ie0[i]], yy[ie1[i]], yy[ie2[i]], yy[ie3[i]] + tyy[te[i]], yy[ie4[i]] + tyy[te[i]]};
0203     solid = DDSolidFactory::extrudedpolygon(DDName(extenCN_[i], nameSpace_), xw, yw, zw, zx, zy, scale);
0204     glog1 = DDLogicalPart(solid.ddname(), matter, solid);
0205 #ifdef EDM_ML_DEBUG
0206     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
0207                                   << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0208                                   << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0209                                   << " and " << xw.size() << " edges";
0210     for (unsigned int k = 0; k < xw.size(); ++k)
0211       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
0212 #endif
0213     solid = DDSolidFactory::extrudedpolygon(DDName(extenSensN_[i], nameSpace_), xw, yw, zc, zx, zy, scale);
0214     glog2 = DDLogicalPart(solid.ddname(), matter, solid);
0215 #ifdef EDM_ML_DEBUG
0216     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
0217                                   << " z|x|y|s (0) " << zc[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0218                                   << " z|x|y|s (1) " << zc[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0219                                   << " and " << xw.size() << " edges";
0220     for (unsigned int k = 0; k < xw.size(); ++k)
0221       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
0222 #endif
0223     cpv.position(glog2, glog1, 1, tran, rot);
0224 #ifdef EDM_ML_DEBUG
0225     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
0226                                   << " at " << tran << " with no rotation";
0227 #endif
0228   }
0229 
0230   static constexpr int ic0[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5};
0231   static constexpr int ic1[] = {1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0};
0232   static constexpr int ic2[] = {10, 3, 14, 5, 6, 1, 2, 12, 4, 16, 0, 8};
0233   static constexpr int ic3[] = {3, 5, 5, 1, 1, 3, 4, 4, 0, 0, 2, 2};
0234   static constexpr int ic4[] = {5, 17, 1, 9, 3, 13, 15, 0, 7, 2, 11, 4};
0235 
0236   static constexpr int tc[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5};
0237   for (unsigned int i = 0; i < cornrCN_.size(); ++i) {
0238     std::vector<double> xw = {
0239         xx[ic0[i]], xx[ic1[i]], xx[ic2[i]] + txx[tc[i]], xx[ic3[i]] + txx[tc[i] + 6], xx[ic4[i]] + txx[(tc[i] + 1) % 6]};
0240     std::vector<double> yw = {
0241         yy[ic0[i]], yy[ic1[i]], yy[ic2[i]] + tyy[tc[i]], yy[ic3[i]] + tyy[tc[i] + 6], yy[ic4[i]] + tyy[(tc[i] + 1) % 6]};
0242     solid = DDSolidFactory::extrudedpolygon(DDName(cornrCN_[i], nameSpace_), xw, yw, zw, zx, zy, scale);
0243     glog1 = DDLogicalPart(solid.ddname(), matter, solid);
0244 #ifdef EDM_ML_DEBUG
0245     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
0246                                   << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0247                                   << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0248                                   << " and " << xw.size() << " edges";
0249     for (unsigned int k = 0; k < xw.size(); ++k)
0250       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
0251 #endif
0252     solid = DDSolidFactory::extrudedpolygon(DDName(cornrSensN_[i], nameSpace_), xw, yw, zc, zx, zy, scale);
0253     glog2 = DDLogicalPart(solid.ddname(), matter, solid);
0254 #ifdef EDM_ML_DEBUG
0255     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
0256                                   << " z|x|y|s (0) " << zc[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0257                                   << " z|x|y|s (1) " << zc[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0258                                   << " and " << xw.size() << " edges";
0259     for (unsigned int k = 0; k < xw.size(); ++k)
0260       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
0261 #endif
0262     cpv.position(glog2, glog1, 1, tran, rot);
0263 #ifdef EDM_ML_DEBUG
0264     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
0265                                   << " at " << tran << " with no rotation";
0266 #endif
0267   }
0268 }
0269 
0270 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalCell, "hgcal:DDHGCalCell");