CMS 3D CMS Logo

Functions
DDHGCalModule.cc File Reference
#include "DataFormats/Math/interface/angle_units.h"
#include "DD4hep/DetFactoryHelper.h"
#include "DetectorDescription/DDCMS/interface/DDPlugins.h"
#include "DetectorDescription/DDCMS/interface/DDutils.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "Geometry/HGCalCommonData/interface/HGCalGeomTools.h"
#include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
#include "Geometry/HGCalCommonData/interface/HGCalTypes.h"

Go to the source code of this file.

Functions

static long algorithm (dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
 
 DD4HEP_OPEN_PLUGIN (dd4hep, ddcms_det_element_DDCMS_hgcal_DDHGCalModule)
 

Function Documentation

◆ algorithm()

static long algorithm ( dd4hep::Detector &  ,
cms::DDParsingContext ctxt,
xml_h  e 
)
static

Definition at line 24 of file DDHGCalModule.cc.

References cms::DDNamespace::addSolidNS(), simBeamSpotPI::alpha, writedatasetfile::args, cms::convert2mm(), angle_units::operators::convertRadToDeg(), filterCSVwithJSON::copy, TCMET_cfi::corner, funct::cos(), PVValHelper::dx, PVValHelper::dy, MillePedeFileConverter_cfg::e, mps_fire::i, versionedElectronIDProducer_cfi::idName, cuy::ii, dqmdumpme::k, HGCalParameters::k_CornerSize, hgcalTBTopologyTester_cfi::layers, cms::DDNamespace::material(), g4SimHits_cfi::Material, Skims_PA_cff::name, cms::DDNamespace::name(), names, EgHLTOffHistBins_cfi::nr, gpuPixelDoublets::ntot, HGCalTypes::packTypeUV(), HGCalGeometryMode::Polyhedra, PixelTestBeamValidation_cfi::Position, cms::DDNamespace::prepend(), HGCalGeomTools::radius(), makeMuonMisalignmentScenario::rot, idealTransformation::rotation, findQualityFiles::rr, cms::s_executed, volumeBasedMagneticField_160812_cfi::sectors, mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, funct::tan(), to_string(), cms::DDNamespace::volume(), HGCalGeomTools::waferCorner(), and geometryCSVtoXML::zz.

24  {
25  cms::DDNamespace ns(ctxt, e, true);
27  static constexpr double tol = 0.01 * dd4hep::mm;
28  static constexpr double tol2 = 0.00001 * dd4hep::mm;
29 
30  const auto& wafer = args.value<std::vector<std::string> >("WaferName"); // Wafers
31  auto materials = args.value<std::vector<std::string> >("MaterialNames"); // Materials
32  const auto& names = args.value<std::vector<std::string> >("VolumeNames"); // Names
33  const auto& thick = args.value<std::vector<double> >("Thickness"); // Thickness of the material
34  std::vector<int> copyNumber; // Initial copy numbers
35  copyNumber.resize(materials.size(), 1);
36  for (unsigned int i = 0; i < materials.size(); ++i) {
37  if (materials[i] == "materials:M_NEMAFR4plate")
38  materials[i] = "materials:M_NEMA FR4 plate";
39  }
40 #ifdef EDM_ML_DEBUG
41  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << wafer.size() << " wafers";
42  for (unsigned int i = 0; i < wafer.size(); ++i)
43  edm::LogVerbatim("HGCalGeom") << "Wafer[" << i << "] " << wafer[i];
44  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << materials.size() << " types of volumes";
45  for (unsigned int i = 0; i < names.size(); ++i)
46  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names[i] << " of thickness "
47  << cms::convert2mm(thick[i]) << " filled with " << materials[i]
48  << " first copy number " << copyNumber[i];
49 #endif
50  const auto& layers = args.value<std::vector<int> >("Layers"); // Number of layers in a section
51  const auto& layerThick = args.value<std::vector<double> >("LayerThick"); // Thickness of each section
52  const auto& layerType = args.value<std::vector<int> >("LayerType"); // Type of the layer
53  const auto& layerSense = args.value<std::vector<int> >("LayerSense"); // Content of a layer (sensitive?)
54 #ifdef EDM_ML_DEBUG
55  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << layers.size() << " blocks";
56  for (unsigned int i = 0; i < layers.size(); ++i)
57  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << cms::convert2mm(layerThick[i]) << " with "
58  << layers[i] << " layers";
59  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << layerType.size() << " layers";
60  for (unsigned int i = 0; i < layerType.size(); ++i)
61  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType[i] << " sensitive class "
62  << layerSense[i];
63 #endif
64  double zMinBlock = args.value<double>("zMinBlock"); // Starting z-value of the block
65  double rMaxFine = args.value<double>("rMaxFine"); // Maximum r-value for fine wafer
66  double waferW = args.value<double>("waferW"); // Width of the wafer
67  int sectors = args.value<int>("Sectors"); // Sectors
68 #ifdef EDM_ML_DEBUG
69  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: zStart " << cms::convert2mm(zMinBlock) << " rFineCoarse "
70  << cms::convert2mm(rMaxFine) << " wafer width " << cms::convert2mm(waferW)
71  << " sectors " << sectors;
72 #endif
73  const auto& slopeB = args.value<std::vector<double> >("SlopeBottom"); // Slope at the lower R
74  const auto& slopeT = args.value<std::vector<double> >("SlopeTop"); // Slopes at the larger R
75  const auto& zFront = args.value<std::vector<double> >("ZFront"); // Starting Z values for the slopes
76  const auto& rMaxFront = args.value<std::vector<double> >("RMaxFront"); // Corresponding rMax's
77 #ifdef EDM_ML_DEBUG
78  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: Bottom slopes " << slopeB[0] << ":" << slopeB[1] << " and "
79  << slopeT.size() << " slopes for top";
80  for (unsigned int i = 0; i < slopeT.size(); ++i)
81  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] Zmin " << cms::convert2mm(zFront[i]) << " Rmax "
82  << cms::convert2mm(rMaxFront[i]) << " Slope " << slopeT[i];
83 #endif
84  std::string idNameSpace = static_cast<std::string>(ns.name()); // Namespace of this and ALL sub-parts
85  const auto& idName = args.parentName(); // Name of the "parent" volume.
86 #ifdef EDM_ML_DEBUG
87  std::unordered_set<int> copies; // List of copy #'s
88  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: NameSpace " << idNameSpace << " Mother " << idName;
89 #endif
90 
91  // Mother module
92  dd4hep::Volume module = ns.volume(idName);
93 
94  double zi(zMinBlock);
95  int laymin(0);
96  for (unsigned int i = 0; i < layers.size(); i++) {
97  double zo = zi + layerThick[i];
98  double routF = HGCalGeomTools::radius(zi, zFront, rMaxFront, slopeT);
99  int laymax = laymin + layers[i];
100  double zz = zi;
101  double thickTot(0);
102  for (int ly = laymin; ly < laymax; ++ly) {
103  int ii = layerType[ly];
104  int copy = copyNumber[ii];
105  double rinB = (layerSense[ly] == 0) ? (zo * slopeB[0]) : (zo * slopeB[1]);
106  zz += (0.5 * thick[ii]);
107  thickTot += thick[ii];
108 
109  std::string name = "HGCal" + names[ii] + std::to_string(copy);
110 #ifdef EDM_ML_DEBUG
111  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: Layer " << ly << ":" << ii << " Front " << cms::convert2mm(zi)
112  << ", " << cms::convert2mm(routF) << " Back " << cms::convert2mm(zo) << ", "
113  << cms::convert2mm(rinB) << " superlayer thickness "
114  << cms::convert2mm(layerThick[i]);
115 #endif
116  dd4hep::Material matter = ns.material(materials[ii]);
117  dd4hep::Volume glog;
118  if (layerSense[ly] == 0) {
119  double alpha = 1._pi / sectors;
120  double rmax = routF * cos(alpha) - tol;
121  std::vector<double> pgonZ, pgonRin, pgonRout;
122  pgonZ.emplace_back(-0.5 * thick[ii]);
123  pgonZ.emplace_back(0.5 * thick[ii]);
124  pgonRin.emplace_back(rinB);
125  pgonRin.emplace_back(rinB);
126  pgonRout.emplace_back(rmax);
127  pgonRout.emplace_back(rmax);
128  dd4hep::Solid solid = dd4hep::Polyhedra(sectors, -alpha, 2._pi, pgonZ, pgonRin, pgonRout);
129  ns.addSolidNS(ns.prepend(name), solid);
130  glog = dd4hep::Volume(solid.name(), solid, matter);
131 #ifdef EDM_ML_DEBUG
132  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << solid.name() << " polyhedra of " << sectors
133  << " sectors covering " << convertRadToDeg(-alpha) << ":"
134  << (360.0 + convertRadToDeg(-alpha)) << " with " << pgonZ.size() << " sections";
135  for (unsigned int k = 0; k < pgonZ.size(); ++k)
136  edm::LogVerbatim("HGCalGeom") << "[" << k << "] z " << cms::convert2mm(pgonZ[k]) << " R "
137  << cms::convert2mm(pgonRin[k]) << ":" << cms::convert2mm(pgonRout[k]);
138 #endif
139  } else {
140  dd4hep::Solid solid = dd4hep::Tube(0.5 * thick[ii], rinB, routF, 0.0, 2._pi);
141  ns.addSolidNS(ns.prepend(name), solid);
142  glog = dd4hep::Volume(solid.name(), solid, matter);
143 #ifdef EDM_ML_DEBUG
144  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << solid.name() << " Tubs made of " << materials[ii]
145  << " of dimensions " << cms::convert2mm(rinB) << ", " << cms::convert2mm(routF)
146  << ", " << cms::convert2mm(0.5 * thick[ii]) << ", 0.0, 360.0";
147  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule test position in: " << glog.name() << " number " << copy;
148 #endif
149  double dx = 0.5 * waferW;
150  double dy = 3.0 * dx * tan(30._deg);
151  double rr = 2.0 * dx * tan(30._deg);
152  int ncol = static_cast<int>(2.0 * routF / waferW) + 1;
153  int nrow = static_cast<int>(routF / (waferW * tan(30._deg))) + 1;
154 #ifdef EDM_ML_DEBUG
155  int incm(0), inrm(0), kount(0), ntot(0), nin(0), nfine(0), ncoarse(0);
156  edm::LogVerbatim("HGCalGeom") << glog.name() << " rout " << cms::convert2mm(routF) << " Row " << nrow
157  << " Column " << ncol;
158 #endif
159  for (int nr = -nrow; nr <= nrow; ++nr) {
160  int inr = (nr >= 0) ? nr : -nr;
161  for (int nc = -ncol; nc <= ncol; ++nc) {
162  int inc = (nc >= 0) ? nc : -nc;
163  if (inr % 2 == inc % 2) {
164  double xpos = nc * dx;
165  double ypos = nr * dy;
166  std::pair<int, int> corner = HGCalGeomTools::waferCorner(xpos, ypos, dx, rr, rinB, routF, true);
167 #ifdef EDM_ML_DEBUG
168  ++ntot;
169 #endif
170  if (corner.first > 0) {
171  int copyL = HGCalTypes::packTypeUV(0, nc, nr);
172 #ifdef EDM_ML_DEBUG
173  if (inc > incm)
174  incm = inc;
175  if (inr > inrm)
176  inrm = inr;
177  kount++;
178  copies.insert(copy);
179 #endif
180  if (corner.first == (int)(HGCalParameters::k_CornerSize)) {
181  double rpos = std::sqrt(xpos * xpos + ypos * ypos);
182  dd4hep::Position tran(xpos, ypos, 0.0);
183  dd4hep::Rotation3D rotation;
184  dd4hep::Volume glog1 = (rpos < rMaxFine) ? ns.volume(wafer[0]) : ns.volume(wafer[1]);
185  glog.placeVolume(glog1, copyL, dd4hep::Transform3D(rotation, tran));
186 #ifdef EDM_ML_DEBUG
187  ++nin;
188  if (rpos < rMaxFine)
189  ++nfine;
190  else
191  ++ncoarse;
192  edm::LogVerbatim("HGCalGeom")
193  << "DDHGCalModule: " << glog1.name() << " number " << copyL << " positioned in " << glog.name()
194  << " at (" << cms::convert2mm(xpos) << "," << cms::convert2mm(ypos) << ",0) with " << rotation;
195 #endif
196  }
197  }
198  }
199  }
200  }
201 #ifdef EDM_ML_DEBUG
202  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: # of columns " << incm << " # of rows " << inrm << " and "
203  << nin << ":" << kount << ":" << ntot << " wafers (" << nfine << ":" << ncoarse
204  << ") for " << glog.name() << " R " << cms::convert2mm(rinB) << ":"
205  << cms::convert2mm(routF);
206 #endif
207  }
208  dd4hep::Position r1(0, 0, zz);
209  dd4hep::Rotation3D rot;
210  module.placeVolume(glog, copy, dd4hep::Transform3D(rot, r1));
211  ++copyNumber[ii];
212 #ifdef EDM_ML_DEBUG
213  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << glog.name() << " number " << copy << " positioned in "
214  << module.name() << " at (0,0," << cms::convert2mm(zz) << ") with no rotation";
215 #endif
216  zz += (0.5 * thick[ii]);
217  } // End of loop over layers in a block
218  zi = zo;
219  laymin = laymax;
220  if (fabs(thickTot - layerThick[i]) > tol2) {
221  if (thickTot > layerThick[i]) {
222  edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick[i])
223  << " is smaller than thickness " << cms::convert2mm(thickTot)
224  << " of all its components **** ERROR ****\n";
225  } else {
226  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick[i])
227  << " does not match with " << cms::convert2mm(thickTot) << " of the components\n";
228  }
229  }
230  } // End of loop over blocks
231 
232 #ifdef EDM_ML_DEBUG
233  edm::LogVerbatim("HGCalGeom") << copies.size() << " different wafer copy numbers";
234  int k(0);
235  for (std::unordered_set<int>::const_iterator itr = copies.begin(); itr != copies.end(); ++itr, ++k)
236  edm::LogVerbatim("HGCalGeom") << "Copy[" << k << "] : " << (*itr);
237  edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalModule construction ...";
238 #endif
239 
240  return cms::s_executed;
241 }
Log< level::Info, true > LogVerbatim
static void radius(double zf, double zb, std::vector< double > const &zFront1, std::vector< double > const &rFront1, std::vector< double > const &slope1, std::vector< double > const &zFront2, std::vector< double > const &rFront2, std::vector< double > const &slope2, int flag, std::vector< double > &zz, std::vector< double > &rin, std::vector< double > &rout)
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
Log< level::Error, false > LogError
const std::string names[nVars_]
static std::string to_string(const XMLCh *ch)
static constexpr uint32_t k_CornerSize
static std::pair< int32_t, int32_t > waferCorner(double xpos, double ypos, double r, double R, double rMin, double rMax, bool oldBug=false)
static constexpr long s_executed
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
dd4hep::Volume Volume
ii
Definition: cuy.py:589
static int32_t packTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:3
Log< level::Warning, false > LogWarning
__shared__ uint32_t ntot

◆ DD4HEP_OPEN_PLUGIN()

DD4HEP_OPEN_PLUGIN ( dd4hep  ,
ddcms_det_element_DDCMS_hgcal_DDHGCalModule   
)

Definition at line 244 of file DDHGCalModule.cc.