CMS 3D CMS Logo

Functions
DDHGCalModule.cc File Reference
#include "DataFormats/Math/interface/CMSUnits.h"
#include "DD4hep/DetFactoryHelper.h"
#include "DetectorDescription/DDCMS/interface/DDPlugins.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"

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 23 of file DDHGCalModule.cc.

References cms::DDNamespace::addSolidNS(), zMuMuMuonUserData::alpha, writedatasetfile::args, angle_units::operators::convertRadToDeg(), filterCSVwithJSON::copy, distTCMET_cfi::corner, funct::cos(), PVValHelper::dx, PVValHelper::dy, mps_fire::i, versionedElectronIDProducer_cfi::idName, cuy::ii, dqmdumpme::k, HGCalParameters::k_CornerSize, hgcalTopologyTester_cfi::layers, cms::DDNamespace::material(), g4SimHits_cfi::Material, Skims_PA_cff::name, cms::DDNamespace::name(), names, nin, EgHLTOffHistBins_cfi::nr, cms::DDAlgoArguments::parentName(), angle_units::piRadians(), HGCalGeometryMode::Polyhedra, cms::DDNamespace::prepend(), diffTwoXMLs::r1, HGCalGeomTools::radius(), makeMuonMisalignmentScenario::rot, idealTransformation::rotation, findQualityFiles::rr, volumeBasedMagneticField_1103l_cfi::sectors, mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, funct::tan(), cms::DDAlgoArguments::value(), cms::DDNamespace::volume(), HGCalGeomTools::waferCorner(), and geometryCSVtoXML::zz.

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

Definition at line 240 of file DDHGCalModule.cc.