Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-14 02:40:56

0001 #include "DD4hep/DetFactoryHelper.h"
0002 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0003 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 
0007 //#define EDM_ML_DEBUG
0008 
0009 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0010   cms::DDNamespace ns(ctxt, e, true);
0011   cms::DDAlgoArguments args(ctxt, e);
0012   // Header section of original DDHGCalCell.h
0013   double waferSize = args.value<double>("WaferSize");                // size of wafer
0014   double waferSeparation = args.value<double>("WaferSeparation");    // Wafer Separation
0015   int addWaferSeparation = args.value<int>("AddWaferSeparation");    // Use wafer separation
0016   double waferT = args.value<double>("WaferThick");                  // Thickness of wafer
0017   double cellT = args.value<double>("CellThick");                    // Thickness of depletion layer
0018   int nCells = args.value<int>("NCells");                            // Number of cells
0019   int posSens = args.value<int>("PosSensitive");                     // Position of delpletion layer within wafer
0020   std::string material = args.value<std::string>("Material");        // Material
0021   std::string fullCN = args.value<std::string>("FullCell");          // Name of the full cell
0022   std::string fullSensN = args.value<std::string>("FullSensitive");  // Name of the sensitive part for a full cell
0023   std::vector<std::string> truncCN =
0024       args.value<std::vector<std::string> >("TruncatedCell");  // Names of truncated cells
0025   std::vector<std::string> truncSensN =
0026       args.value<std::vector<std::string> >("TruncatedSensitive");  // Names of the sensitive parts for truncated cells
0027   std::vector<std::string> extenCN = args.value<std::vector<std::string> >("ExtendedCell");  // Names of extended cells
0028   std::vector<std::string> extenSensN =
0029       args.value<std::vector<std::string> >("ExtendedSensitive");  // Names of the sensitive parts for extended cells
0030   std::vector<std::string> cornrCN = args.value<std::vector<std::string> >("CornerCell");  // Names of the corner cells
0031   std::vector<std::string> cornrSensN =
0032       args.value<std::vector<std::string> >("CornerSensitive");  // Names of the sensitive parts for corner cells
0033 
0034   if ((truncCN.size() != truncSensN.size()) || (extenCN.size() != extenSensN.size()) ||
0035       (cornrCN.size() != cornrSensN.size())) {
0036     edm::LogError("HGCalGeom") << "The number of cells & sensitive differ:"
0037                                << " Truncated " << truncCN.size() << ":" << truncSensN.size() << " Extended "
0038                                << extenCN.size() << ":" << extenSensN.size() << " Corners " << cornrCN.size() << ":"
0039                                << cornrSensN.size();
0040     throw cms::Exception("DDException") << "The number of cells & sensitive "
0041                                         << "differ: Truncated " << truncCN.size() << ":" << truncSensN.size()
0042                                         << " Extended " << extenCN.size() << ":" << extenSensN.size() << " Corners "
0043                                         << cornrCN.size() << ":" << cornrSensN.size();
0044   }
0045   if ((truncCN.size() < 3) || (extenCN.size() < 3) || (cornrCN.size() < 6)) {
0046     edm::LogError("HGCalGeom") << "DDHGCalCell: The number of cells does not"
0047                                << " match with Standard: Truncated " << truncCN.size() << " < 3 Extended "
0048                                << extenCN.size() << " < 3"
0049                                << " Corners " << cornrCN.size() << " < 6";
0050     throw cms::Exception("DDException") << "Wrong size of truncated|extended"
0051                                         << "|corner cells: " << truncCN.size() << ":" << extenCN.size() << ":"
0052                                         << cornrCN.size();
0053   }
0054 #ifdef EDM_ML_DEBUG
0055   edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Wafer r " << cms::convert2mm(waferSize) << " T "
0056                                 << cms::convert2mm(waferT) << " Cell T " << cms::convert2mm(cellT) << " Cells/Wafer "
0057                                 << nCells << " Material " << material << "Sensitive Position " << posSens
0058                                 << " NameSpace " << ns.name() << " Full Cell: " << fullCN << ":" << fullSensN;
0059   for (unsigned int k = 0; k < truncCN.size(); ++k)
0060     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Truncated Cell[" << k << "] " << truncCN[k] << ":" << truncSensN[k];
0061   for (unsigned int k = 0; k < extenCN.size(); ++k)
0062     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Extended Cell[" << k << "] " << extenCN[k] << ":" << extenSensN[k];
0063   for (unsigned int k = 0; k < cornrCN.size(); ++k)
0064     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Corner Cell[" << k << "] " << cornrCN[k] << ":" << cornrSensN[k];
0065 #endif
0066 
0067   dd4hep::Material matter = ns.material(material);
0068 #ifdef EDM_ML_DEBUG
0069   edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << material << " initialized";
0070 #endif
0071   dd4hep::Volume glog1, glog2;
0072 
0073   static const double sqrt3 = std::sqrt(3.0);
0074   static const double waf2cell = 3.0;
0075   static const double cornerfac = 2.5;
0076   double R =
0077       (addWaferSeparation == 0) ? waferSize / (waf2cell * nCells) : (waferSize + waferSeparation) / (waf2cell * nCells);
0078   double r = 0.5 * R * sqrt3;
0079   double dx1 = R;
0080   double dx2 = 0.5 * dx1;
0081   double dx3 = cornerfac * dx2;
0082   double dx4 = 0.5 * dx2;
0083   double dx5 = (addWaferSeparation == 0) ? 0.0 : waferSeparation * 0.5;
0084   double dx6 = dx5 * 0.5;
0085   double dx7 = dx5;
0086   double dy1 = r;
0087   double dy2 = 0.5 * dy1;
0088   double dy3 = 1.5 * dy1;
0089   double dy4 = dx5 * 0.5 * sqrt3;
0090   double dy5 = dx5 * 2 / sqrt3;
0091   double dy6 = dy5 * 0.5;
0092   std::vector<double> xx = {
0093       dx1, dx2, -dx2, -dx1, -dx2, dx2, dx3, dx1, dx4, -dx4, -dx1, -dx3, -dx3, -dx1, -dx4, dx4, dx1, dx3};
0094   std::vector<double> yy = {
0095       0, dy1, dy1, 0, -dy1, -dy1, dy2, dy1, dy3, dy3, dy1, dy2, -dy2, -dy1, -dy3, -dy3, -dy1, -dy2};
0096   std::vector<double> txx = {dx5, dx6, -dx6, -dx5, -dx6, dx6, dx7, 0, -dx7, -dx7, 0, dx7};
0097   std::vector<double> tyy = {0, dy4, dy4, 0, -dy4, -dy4, dy6, dy5, dy6, -dy6, -dy5, -dy6};
0098   double zpos = (posSens == 0) ? -0.5 * (waferT - cellT) : 0.5 * (waferT - cellT);
0099   dd4hep::Position tran(0, 0, zpos);
0100 
0101   // First the full cell
0102   std::vector<double> xw = {xx[0], xx[1], xx[2], xx[3], xx[4], xx[5]};
0103   std::vector<double> yw = {yy[0], yy[1], yy[2], yy[3], yy[4], yy[5]};
0104   std::vector<double> zw = {-0.5 * waferT, 0.5 * waferT};
0105   std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0106   dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xw, yw, zw, zx, zy, scale);
0107   ns.addSolidNS(ns.prepend(fullCN), solid);
0108   glog1 = dd4hep::Volume(solid.name(), solid, matter);
0109   ns.addVolumeNS(glog1);
0110 #ifdef EDM_ML_DEBUG
0111   edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
0112                                 << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0113                                 << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0114                                 << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0115                                 << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xw.size() << " edges";
0116   for (unsigned int k = 0; k < xw.size(); ++k)
0117     edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xw[k]) << ":" << cms::convert2mm(yw[k]);
0118 #endif
0119   std::vector<double> zc = {-0.5 * cellT, 0.5 * cellT};
0120   solid = dd4hep::ExtrudedPolygon(xw, yw, zc, zx, zy, scale);
0121   ns.addSolidNS(ns.prepend(fullSensN), solid);
0122   glog2 = dd4hep::Volume(solid.name(), solid, matter);
0123   ns.addVolumeNS(glog2);
0124 #ifdef EDM_ML_DEBUG
0125   edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
0126                                 << " z|x|y|s (0) " << cms::convert2mm(zc[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0127                                 << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0128                                 << cms::convert2mm(zc[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0129                                 << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xw.size() << " edges";
0130   for (unsigned int k = 0; k < xw.size(); ++k)
0131     edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xw[k]) << ":" << cms::convert2mm(yw[k]);
0132 #endif
0133 
0134   glog1.placeVolume(glog2, 1, tran);
0135 #ifdef EDM_ML_DEBUG
0136   edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
0137                                 << " at (0,0," << cms::convert2mm(zpos) << ") with no rotation";
0138 #endif
0139 
0140   static constexpr int ir0[] = {0, 2, 4, 1, 3, 5};
0141   static constexpr int ir1[] = {1, 3, 5, 2, 4, 0};
0142   static constexpr int ir2[] = {2, 4, 0, 3, 5, 1};
0143   static constexpr int ir3[] = {3, 5, 1, 4, 0, 2};
0144   static constexpr int ir4[] = {5, 1, 3, 0, 2, 4};
0145   static constexpr int tr[] = {1, 3, 5, 2, 4, 0};
0146   for (unsigned int i = 0; i < truncCN.size(); ++i) {
0147     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]]};
0148     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]]};
0149 
0150     solid = dd4hep::ExtrudedPolygon(xw, yw, zw, zx, zy, scale);
0151     ns.addSolidNS(ns.prepend(truncCN[i]), solid);
0152     glog1 = dd4hep::Volume(solid.name(), solid, matter);
0153     ns.addVolumeNS(glog1);
0154 #ifdef EDM_ML_DEBUG
0155     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
0156                                   << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0157                                   << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0158                                   << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0159                                   << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xw.size() << " edges";
0160     for (unsigned int k = 0; k < xw.size(); ++k)
0161       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xw[k]) << ":" << cms::convert2mm(yw[k]);
0162 #endif
0163 
0164     solid = dd4hep::ExtrudedPolygon(xw, yw, zc, zx, zy, scale);
0165     ns.addSolidNS(ns.prepend(truncSensN[i]), solid);
0166     glog2 = dd4hep::Volume(solid.name(), solid, matter);
0167     ns.addVolumeNS(glog2);
0168 #ifdef EDM_ML_DEBUG
0169     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
0170                                   << " z|x|y|s (0) " << cms::convert2mm(zc[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0171                                   << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0172                                   << cms::convert2mm(zc[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0173                                   << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xw.size() << " edges";
0174     for (unsigned int k = 0; k < xw.size(); ++k)
0175       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xw[k]) << ":" << cms::convert2mm(yw[k]);
0176 #endif
0177     glog1.placeVolume(glog2, 1, tran);
0178 #ifdef EDM_ML_DEBUG
0179     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
0180                                   << " at (0,0," << cms::convert2mm(zpos) << ") with no rotation";
0181 #endif
0182   }
0183 
0184   static constexpr int ie0[] = {1, 3, 5, 0, 2, 4};
0185   static constexpr int ie1[] = {2, 4, 0, 1, 3, 5};
0186   static constexpr int ie2[] = {3, 5, 1, 2, 4, 0};
0187   static constexpr int ie3[] = {14, 6, 10, 12, 16, 8};
0188   static constexpr int ie4[] = {17, 9, 13, 15, 7, 11};
0189   static constexpr int te[] = {2, 4, 0, 1, 3, 5};
0190   for (unsigned int i = 0; i < extenCN.size(); ++i) {
0191     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]]};
0192     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]]};
0193     solid = dd4hep::ExtrudedPolygon(xw, yw, zw, zx, zy, scale);
0194     ns.addSolidNS(ns.prepend(extenCN[i]), solid);
0195     glog1 = dd4hep::Volume(solid.name(), solid, matter);
0196     ns.addVolumeNS(glog1);
0197 #ifdef EDM_ML_DEBUG
0198     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
0199                                   << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0200                                   << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0201                                   << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0202                                   << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xw.size() << " edges";
0203     for (unsigned int k = 0; k < xw.size(); ++k)
0204       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xw[k]) << ":" << cms::convert2mm(yw[k]);
0205 #endif
0206     solid = dd4hep::ExtrudedPolygon(xw, yw, zc, zx, zy, scale);
0207     ns.addSolidNS(ns.prepend(extenSensN[i]), solid);
0208     glog2 = dd4hep::Volume(solid.name(), solid, matter);
0209     ns.addVolumeNS(glog2);
0210 #ifdef EDM_ML_DEBUG
0211     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
0212                                   << " z|x|y|s (0) " << cms::convert2mm(zc[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0213                                   << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0214                                   << cms::convert2mm(zc[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0215                                   << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xw.size() << " edges";
0216     for (unsigned int k = 0; k < xw.size(); ++k)
0217       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xw[k]) << ":" << cms::convert2mm(yw[k]);
0218 #endif
0219     glog1.placeVolume(glog2, 1, tran);
0220 #ifdef EDM_ML_DEBUG
0221     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
0222                                   << " at (0,0," << cms::convert2mm(zpos) << ") with no rotation";
0223 #endif
0224   }
0225 
0226   static constexpr int ic0[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5};
0227   static constexpr int ic1[] = {1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0};
0228   static constexpr int ic2[] = {10, 3, 14, 5, 6, 1, 2, 12, 4, 16, 0, 8};
0229   static constexpr int ic3[] = {3, 5, 5, 1, 1, 3, 4, 4, 0, 0, 2, 2};
0230   static constexpr int ic4[] = {5, 17, 1, 9, 3, 13, 15, 0, 7, 2, 11, 4};
0231   static constexpr int tc[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5};
0232   for (unsigned int i = 0; i < cornrCN.size(); ++i) {
0233     std::vector<double> xw = {
0234         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]};
0235     std::vector<double> yw = {
0236         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]};
0237     solid = dd4hep::ExtrudedPolygon(xw, yw, zw, zx, zy, scale);
0238     ns.addSolidNS(ns.prepend(cornrCN[i]), solid);
0239     glog1 = dd4hep::Volume(solid.name(), solid, matter);
0240     ns.addVolumeNS(glog1);
0241 #ifdef EDM_ML_DEBUG
0242     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
0243                                   << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0244                                   << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0245                                   << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0246                                   << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xw.size() << " edges";
0247     for (unsigned int k = 0; k < xw.size(); ++k)
0248       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xw[k]) << ":" << cms::convert2mm(yw[k]);
0249 #endif
0250     solid = dd4hep::ExtrudedPolygon(xw, yw, zc, zx, zy, scale);
0251     ns.addSolidNS(ns.prepend(cornrSensN[i]), solid);
0252     glog2 = dd4hep::Volume(solid.name(), solid, matter);
0253     ns.addVolumeNS(glog2);
0254 #ifdef EDM_ML_DEBUG
0255     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
0256                                   << " z|x|y|s (0) " << cms::convert2mm(zc[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0257                                   << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0258                                   << cms::convert2mm(zc[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0259                                   << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xw.size() << " edges";
0260     for (unsigned int k = 0; k < xw.size(); ++k)
0261       edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xw[k]) << ":" << cms::convert2mm(yw[k]);
0262 #endif
0263     glog1.placeVolume(glog2, 1, tran);
0264 #ifdef EDM_ML_DEBUG
0265     edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
0266                                   << " at (0,0," << cms::convert2mm(zpos) << ") with no rotation";
0267 #endif
0268   }
0269   return cms::s_executed;
0270 }
0271 
0272 // first argument is the type from the xml file
0273 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalCell, algorithm)