CMS 3D CMS Logo

DDHGCalModule.cc
Go to the documentation of this file.
1 /*
2  * DDHGCalModule.cc
3  *
4  * Created on: 26-August-2019
5  * Author: Sunanda Banerjee
6  */
7 
9 #include "DD4hep/DetFactoryHelper.h"
16 
17 //#define EDM_ML_DEBUG
18 
19 #ifdef EDM_ML_DEBUG
20 #include <unordered_set>
21 #endif
22 using namespace cms_units::operators;
23 
24 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
25  cms::DDNamespace ns(ctxt, e, true);
27  static constexpr double tol = 0.01;
28  static constexpr double tol2 = 0.00001;
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 " << 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  for (unsigned int i = 0; i < layers.size(); i++) {
95  double zo = zi + layerThick[i];
96  double routF = HGCalGeomTools::radius(zi, zFront, rMaxFront, slopeT);
97  int laymax = laymin + layers[i];
98  double zz = zi;
99  double thickTot(0);
100  for (int ly = laymin; ly < laymax; ++ly) {
101  int ii = layerType[ly];
102  int copy = copyNumber[ii];
103  double rinB = (layerSense[ly] == 0) ? (zo * slopeB[0]) : (zo * slopeB[1]);
104  zz += (0.5 * thick[ii]);
105  thickTot += thick[ii];
106 
107  std::string name = "HGCal" + names[ii] + std::to_string(copy);
108 #ifdef EDM_ML_DEBUG
109  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: Layer " << ly << ":" << ii << " Front " << zi << ", " << routF
110  << " Back " << zo << ", " << rinB << " superlayer thickness " << layerThick[i];
111 #endif
112  dd4hep::Material matter = ns.material(materials[ii]);
113  dd4hep::Volume glog;
114  if (layerSense[ly] == 0) {
116  double rmax = routF * cos(alpha) - tol;
117  std::vector<double> pgonZ, pgonRin, pgonRout;
118  pgonZ.emplace_back(-0.5 * thick[ii]);
119  pgonZ.emplace_back(0.5 * thick[ii]);
120  pgonRin.emplace_back(rinB);
121  pgonRin.emplace_back(rinB);
122  pgonRout.emplace_back(rmax);
123  pgonRout.emplace_back(rmax);
124  dd4hep::Solid solid = dd4hep::Polyhedra(sectors, -alpha, 2 * cms_units::piRadians, pgonZ, pgonRin, pgonRout);
125  ns.addSolidNS(ns.prepend(name), solid);
126  glog = dd4hep::Volume(solid.name(), solid, matter);
127 #ifdef EDM_ML_DEBUG
128  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << solid.name() << " polyhedra of " << sectors
129  << " sectors covering " << convertRadToDeg(-alpha) << ":"
130  << (360.0 + convertRadToDeg(-alpha)) << " with " << pgonZ.size() << " sections";
131  for (unsigned int k = 0; k < pgonZ.size(); ++k)
132  edm::LogVerbatim("HGCalGeom") << "[" << k << "] z " << pgonZ[k] << " R " << pgonRin[k] << ":" << pgonRout[k];
133 #endif
134  } else {
135  dd4hep::Solid solid = dd4hep::Tube(0.5 * thick[ii], rinB, routF, 0.0, 2 * cms_units::piRadians);
136  ns.addSolidNS(ns.prepend(name), solid);
137  glog = dd4hep::Volume(solid.name(), solid, matter);
138 #ifdef EDM_ML_DEBUG
139  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << solid.name() << " Tubs made of " << materials[ii]
140  << " of dimensions " << rinB << ", " << routF << ", " << 0.5 * thick[ii]
141  << ", 0.0, 360.0";
142  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule test position in: " << glog.name() << " number " << copy;
143 #endif
144  double dx = 0.5 * waferW;
145  double dy = 3.0 * dx * tan(30._deg);
146  double rr = 2.0 * dx * tan(30._deg);
147  int ncol = static_cast<int>(2.0 * routF / waferW) + 1;
148  int nrow = static_cast<int>(routF / (waferW * tan(30._deg))) + 1;
149 #ifdef EDM_ML_DEBUG
150  int incm(0), inrm(0), kount(0), ntot(0), nin(0), nfine(0), ncoarse(0);
151  edm::LogVerbatim("HGCalGeom") << glog.name() << " rout " << routF << " Row " << nrow << " Column " << ncol;
152 #endif
153  for (int nr = -nrow; nr <= nrow; ++nr) {
154  int inr = (nr >= 0) ? nr : -nr;
155  for (int nc = -ncol; nc <= ncol; ++nc) {
156  int inc = (nc >= 0) ? nc : -nc;
157  if (inr % 2 == inc % 2) {
158  double xpos = nc * dx;
159  double ypos = nr * dy;
160  std::pair<int, int> corner = HGCalGeomTools::waferCorner(xpos, ypos, dx, rr, rinB, routF, true);
161 #ifdef EDM_ML_DEBUG
162  ++ntot;
163 #endif
164  if (corner.first > 0) {
165  int copyL = HGCalTypes::packTypeUV(0, nc, nr);
166 #ifdef EDM_ML_DEBUG
167  if (inc > incm)
168  incm = inc;
169  if (inr > inrm)
170  inrm = inr;
171  kount++;
172  copies.insert(copy);
173 #endif
174  if (corner.first == (int)(HGCalParameters::k_CornerSize)) {
175  double rpos = std::sqrt(xpos * xpos + ypos * ypos);
176  dd4hep::Position tran(xpos, ypos, 0.0);
177  dd4hep::Rotation3D rotation;
178  dd4hep::Volume glog1 = (rpos < rMaxFine) ? ns.volume(wafer[0]) : ns.volume(wafer[1]);
179  glog.placeVolume(glog1, copyL, dd4hep::Transform3D(rotation, tran));
180 #ifdef EDM_ML_DEBUG
181  ++nin;
182  if (rpos < rMaxFine)
183  ++nfine;
184  else
185  ++ncoarse;
186  edm::LogVerbatim("HGCalGeom")
187  << "DDHGCalModule: " << glog1.name() << " number " << copyL << " positioned in " << glog.name()
188  << " at " << tran << " with " << rotation;
189 #endif
190  }
191  }
192  }
193  }
194  }
195 #ifdef EDM_ML_DEBUG
196  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: # of columns " << incm << " # of rows " << inrm << " and "
197  << nin << ":" << kount << ":" << ntot << " wafers (" << nfine << ":" << ncoarse
198  << ") for " << glog.name() << " R " << rinB << ":" << routF;
199 #endif
200  }
201  dd4hep::Position r1(0, 0, zz);
202  dd4hep::Rotation3D rot;
203  module.placeVolume(glog, copy, dd4hep::Transform3D(rot, r1));
204  ++copyNumber[ii];
205 #ifdef EDM_ML_DEBUG
206  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << glog.name() << " number " << copy << " positioned in "
207  << module.name() << " at " << r1 << " with " << rot;
208 #endif
209  zz += (0.5 * thick[ii]);
210  } // End of loop over layers in a block
211  zi = zo;
212  laymin = laymax;
213  if (fabs(thickTot - layerThick[i]) > tol2) {
214  if (thickTot > layerThick[i]) {
215  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick[i] << " is smaller than thickness "
216  << thickTot << " of all its components **** ERROR ****\n";
217  } else {
218  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << layerThick[i] << " does not match with "
219  << thickTot << " of the components\n";
220  }
221  }
222  } // End of loop over blocks
223 
224 #ifdef EDM_ML_DEBUG
225  edm::LogVerbatim("HGCalGeom") << copies.size() << " different wafer copy numbers";
226  int k(0);
227  for (std::unordered_set<int>::const_iterator itr = copies.begin(); itr != copies.end(); ++itr, ++k)
228  edm::LogVerbatim("HGCalGeom") << "Copy[" << k << "] : " << (*itr);
229  edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalModule construction ...";
230 #endif
231 
232  return cms::s_executed;
233 }
234 
235 // first argument is the type from the xml file
236 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalModule, algorithm)
writedatasetfile.args
args
Definition: writedatasetfile.py:18
HGCalGeomTools::waferCorner
static std::pair< int32_t, int32_t > waferCorner(double xpos, double ypos, double r, double R, double rMin, double rMax, bool oldBug=false)
Definition: HGCalGeomTools.cc:223
mps_fire.i
i
Definition: mps_fire.py:428
cms_units::operators
Definition: CMSUnits.h:13
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
g4SimHits_cfi.Material
Material
Definition: g4SimHits_cfi.py:560
MessageLogger.h
DECLARE_DDCMS_DETELEMENT
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
cms::DDNamespace::material
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:116
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
cms::DDParsingContext
Definition: DDParsingContext.h:13
zMuMuMuonUserData.alpha
alpha
zGenParticlesMatch = cms.InputTag(""),
Definition: zMuMuMuonUserData.py:9
findQualityFiles.rr
string rr
Definition: findQualityFiles.py:185
angle_units::operators::convertRadToDeg
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
cms::DDNamespace
Definition: DDNamespace.h:16
HGCalParameters::k_CornerSize
static constexpr uint32_t k_CornerSize
Definition: HGCalParameters.h:38
distTCMET_cfi.corner
corner
Definition: distTCMET_cfi.py:38
nin
int nin
Definition: CascadeWrapper.h:114
versionedElectronIDProducer_cfi.idName
idName
Definition: versionedElectronIDProducer_cfi.py:11
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:124
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
cms::DDNamespace::prepend
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:60
PixelTestBeamValidation_cfi.Position
Position
Definition: PixelTestBeamValidation_cfi.py:75
dqmdumpme.k
k
Definition: dqmdumpme.py:60
HGCalTypes::packTypeUV
static int32_t packTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:3
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
angle_units::piRadians
constexpr long double piRadians(M_PIl)
cms::Volume
dd4hep::Volume Volume
Definition: DDFilteredView.h:47
idealTransformation.rotation
dictionary rotation
Definition: idealTransformation.py:1
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
DDPlugins.h
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
cms::DDNamespace::addSolidNS
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:221
cms::DDAlgoArguments
Definition: DDAlgoArguments.h:28
PVValHelper::dy
Definition: PVValidationHelpers.h:49
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:29
cms::s_executed
static constexpr long s_executed
Definition: DDAlgoArguments.h:16
align::Detector
Definition: StructureType.h:86
HGCalGeomTools.h
HGCalGeomTools::radius
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)
Definition: HGCalGeomTools.cc:11
diffTwoXMLs.r1
r1
Definition: diffTwoXMLs.py:53
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
HGCalGeometryMode::Polyhedra
Definition: HGCalGeometryMode.h:35
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
CMSUnits.h
Exception.h
algorithm
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
Definition: DDHGCalModule.cc:24
HGCalTypes.h
volumeBasedMagneticField_160812_cfi.sectors
sectors
Definition: volumeBasedMagneticField_160812_cfi.py:59
edm::Log
Definition: MessageLogger.h:70
cms::DDNamespace::name
std::string_view name() const
Definition: DDNamespace.h:72
HGCalParameters.h
cuy.ii
ii
Definition: cuy.py:590
cms::DDNamespace::volume
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:205
PVValHelper::dx
Definition: PVValidationHelpers.h:48
hgcalTopologyTester_cfi.layers
layers
Definition: hgcalTopologyTester_cfi.py:8
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37