Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:11

0001 /*
0002  * DDHGCalWafer8.cc
0003  *
0004  *  Created on: 02-Jul-2019
0005  *      Author: rsehgal
0006  */
0007 
0008 #include "DD4hep/DetFactoryHelper.h"
0009 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0010 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/Utilities/interface/Exception.h"
0013 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0014 
0015 //#define EDM_ML_DEBUG
0016 
0017 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0018   cms::DDNamespace ns(ctxt, e, true);
0019   cms::DDAlgoArguments args(ctxt, e);
0020   std::string motherName = args.parentName();
0021   const auto& waferSize = args.value<double>("WaferSize");
0022   const auto& waferT = args.value<double>("WaferThick");
0023   const auto& waferSepar = args.value<double>("SensorSeparation");
0024   const auto& nCells = args.value<int>("NCells");
0025   const auto& cellType = args.value<int>("CellType");
0026   const auto& material = args.value<std::string>("Material");
0027   const auto& cellNames = args.value<std::vector<std::string>>("CellNames");
0028 
0029 #ifdef EDM_ML_DEBUG
0030   edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer8: Wafer 2r " << cms::convert2mm(waferSize) << " T "
0031                                 << cms::convert2mm(waferT) << " Half Separation " << cms::convert2mm(waferSepar)
0032                                 << " Cells/Wafer " << nCells << " Cell Type " << cellType << " Material " << material
0033                                 << " Names " << motherName << " NameSpace " << ns.name() << " # of cells "
0034                                 << cellNames.size();
0035   for (unsigned int k = 0; k < cellNames.size(); ++k)
0036     edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer8: Cell[" << k << "] " << cellNames[k];
0037 #endif
0038 
0039   static const double sqrt3 = std::sqrt(3.0);
0040   double rM = 0.5 * (waferSize + waferSepar);
0041   double RM2 = rM / sqrt3;
0042   double R = waferSize / (3.0 * nCells);
0043   double r = 0.5 * R * sqrt3;
0044 
0045   // Mother Wafer
0046   std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
0047   std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
0048   std::vector<double> zw = {-0.5 * waferT, 0.5 * waferT};
0049   std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0050 
0051   dd4hep::Material matter = ns.material(material);
0052 
0053   dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
0054   ns.addSolidNS(ns.prepend(motherName), solid);
0055   dd4hep::Volume glog = dd4hep::Volume(solid.name(), solid, matter);
0056   ns.addVolumeNS(glog);
0057 #ifdef EDM_ML_DEBUG
0058   edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer8: " << solid.name() << " extruded polygon made of " << material
0059                                 << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0060                                 << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0061                                 << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0062                                 << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xM.size() << " edges";
0063   for (unsigned int k = 0; k < xM.size(); ++k)
0064     edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xM[k]) << ":" << cms::convert2mm(yM[k]);
0065 #endif
0066 
0067   dd4hep::Rotation3D rotation;
0068 #ifdef EDM_ML_DEBUG
0069   int counter(0);
0070 #endif
0071   for (int u = 0; u < 2 * nCells; ++u) {
0072     for (int v = 0; v < 2 * nCells; ++v) {
0073       if (((v - u) < nCells) && (u - v) <= nCells) {
0074 #ifdef EDM_ML_DEBUG
0075         counter++;
0076 #endif
0077         int n2 = nCells / 2;
0078         double yp = (u - 0.5 * v - n2) * 2 * r;
0079         double xp = (1.5 * (v - nCells) + 1.0) * R;
0080         int cell(0);
0081         if ((u == 0) && (v == 0))
0082           cell = 7;
0083         else if ((u == 0) && (v == nCells - 1))
0084           cell = 8;
0085         else if ((u == nCells) && (v == 2 * nCells - 1))
0086           cell = 9;
0087         else if ((u == 2 * nCells - 1) && (v == 2 * nCells - 1))
0088           cell = 10;
0089         else if ((u == 2 * nCells - 1) && (v == nCells - 1))
0090           cell = 11;
0091         else if ((u == nCells) && (v == 0))
0092           cell = 12;
0093         else if (u == 0)
0094           cell = 1;
0095         else if ((v - u) == (nCells - 1))
0096           cell = 4;
0097         else if (v == (2 * nCells - 1))
0098           cell = 2;
0099         else if (u == (2 * nCells - 1))
0100           cell = 5;
0101         else if ((u - v) == nCells)
0102           cell = 3;
0103         else if (v == 0)
0104           cell = 6;
0105         dd4hep::Position tran(xp, yp, 0);
0106         int copy = HGCalTypes::packCellTypeUV(cellType, u, v);
0107         glog.placeVolume(ns.volume(cellNames[cell]), copy, dd4hep::Transform3D(rotation, tran));
0108 #ifdef EDM_ML_DEBUG
0109         edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer8: " << cellNames[cell] << " number " << copy << " position in "
0110                                       << glog.name() << " at (" << cms::convert2mm(xp) << ", " << cms::convert2mm(yp)
0111                                       << ",0)  with no rotation";
0112 #endif
0113       }
0114     }
0115   }
0116 #ifdef EDM_ML_DEBUG
0117   edm::LogVerbatim("HGCalGeom") << "\nDDHGCalWafer8::Counter : " << counter << "\n===============================\n";
0118 #endif
0119 
0120   return cms::s_executed;
0121 }
0122 
0123 // first argument is the type from the xml file
0124 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWafer8, algorithm)