CMS 3D CMS Logo

DDHGCalTBModule.cc
Go to the documentation of this file.
2 #include "DD4hep/DetFactoryHelper.h"
9 
10 //#define EDM_ML_DEBUG
11 
12 #ifdef EDM_ML_DEBUG
13 #include <unordered_set>
14 #endif
15 using namespace cms_units::operators;
16 
17 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
18  cms::DDNamespace ns(ctxt, e, true);
20  static constexpr double tol2 = 0.00001;
21 
22  const auto& wafers = args.value<std::vector<std::string> >("WaferName"); // Wafers
23  const auto& covers = args.value<std::vector<std::string> >("CoverName"); // Insensitive layers of hexagonal size
24 #ifdef EDM_ML_DEBUG
25  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << wafers.size() << " wafers";
26  unsigned int i(0);
27  for (auto wafer : wafers) {
28  edm::LogVerbatim("HGCalGeom") << "Wafer[" << i << "] " << wafer;
29  ++i;
30  }
31  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << covers.size() << " covers";
32  i = 0;
33  for (auto cover : covers) {
34  edm::LogVerbatim("HGCalGeom") << "Cover[" << i << "] " << cover;
35  ++i;
36  }
37 #endif
38  const auto& materials = args.value<std::vector<std::string> >("MaterialNames"); // Materials
39  const auto& names = args.value<std::vector<std::string> >("VolumeNames"); // Names
40  const auto& thick = args.value<std::vector<double> >("Thickness"); // Thickness of the material
41  std::vector<int> copyNumber; // Initial copy numbers
42  copyNumber.resize(materials.size(), 1);
43 #ifdef EDM_ML_DEBUG
44  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << 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 #ifdef EDM_ML_DEBUG
52  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << layers.size() << " blocks";
53  for (unsigned int i = 0; i < layers.size(); ++i)
54  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << layerThick[i] << " with " << layers[i]
55  << " layers";
56 #endif
57  const auto& layerType = args.value<std::vector<int> >("LayerType"); // Type of the layer
58  const auto& layerSense = args.value<std::vector<int> >("LayerSense"); // Content of a layer (sensitive?)
59 #ifdef EDM_ML_DEBUG
60  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << layerType.size() << " layers";
61  for (unsigned int i = 0; i < layerType.size(); ++i)
62  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType[i] << " sensitive class "
63  << layerSense[i];
64 #endif
65  const auto& zMinBlock = args.value<double>("zMinBlock"); // Starting z-value of the block
66  const auto& rMaxFine = args.value<double>("rMaxFine"); // Maximum r-value for fine wafer
67  const auto& waferW = args.value<double>("waferW"); // Width of the wafer
68  const auto& waferGap = args.value<double>("waferGap"); // Gap between 2 wafers
69  const auto& absorbW = args.value<double>("absorberW"); // Width of the absorber
70  const auto& absorbH = args.value<double>("absorberH"); // Height of the absorber
71 #ifdef EDM_ML_DEBUG
72  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: zStart " << zMinBlock << " rFineCoarse " << rMaxFine
73  << " wafer width " << waferW << " gap among wafers " << waferGap << " absorber width "
74  << absorbW << " absorber height " << absorbH;
75 #endif
76  const auto& slopeB = args.value<std::vector<double> >("SlopeBottom"); // Slope at the lower R
77  const auto& slopeT = args.value<std::vector<double> >("SlopeTop"); // Slopes at the larger R
78  const auto& zFront = args.value<std::vector<double> >("ZFront"); // Starting Z values for the slopes
79  const auto& rMaxFront = args.value<std::vector<double> >("RMaxFront"); // Corresponding rMax's
80 #ifdef EDM_ML_DEBUG
81  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: Bottom slopes " << slopeB[0] << ":" << slopeB[1] << " and "
82  << slopeT.size() << " slopes for top";
83  for (unsigned int i = 0; i < slopeT.size(); ++i)
84  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] Zmin " << zFront[i] << " Rmax " << rMaxFront[i] << " Slope "
85  << slopeT[i];
86 #endif
87  std::string idNameSpace = static_cast<std::string>(ns.name()); // Namespace of this and ALL sub-parts
88  const auto& idName = args.parentName(); // Name of the "parent" volume.
89 #ifdef EDM_ML_DEBUG
90  std::unordered_set<int> copies; // List of copy #'s
91  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: NameSpace " << idNameSpace << " Mother " << idName;
92 #endif
93 
94  // Mother module
95  dd4hep::Volume module = ns.volume(idName);
96 #ifdef EDM_ML_DEBUG
97  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalTBModule...";
98 #endif
99 
100  double zi(zMinBlock);
101  double ww = (waferW + waferGap);
102  double dx = 0.5 * ww;
103  double dy = 3.0 * dx * tan(30._deg);
104  double rr = 2.0 * dx * tan(30._deg);
105  int laymin(0);
106  for (unsigned int i = 0; i < layers.size(); i++) {
107  double zo = zi + layerThick[i];
108  double routF = HGCalGeomTools::radius(zi, zFront, rMaxFront, slopeT);
109  int laymax = laymin + layers[i];
110  double zz = zi;
111  double thickTot(0);
112  for (int ly = laymin; ly < laymax; ++ly) {
113  int ii = layerType[ly];
114  int copy = copyNumber[ii];
115  double rinB = (layerSense[ly] == 0) ? (zo * slopeB[0]) : (zo * slopeB[1]);
116  zz += (0.5 * thick[ii]);
117  thickTot += thick[ii];
118 
119  std::string name = "HGCal" + names[ii] + std::to_string(copy);
120 #ifdef EDM_ML_DEBUG
121  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: Layer " << ly << ":" << ii << " Front " << zi << ", " << routF
122  << " Back " << zo << ", " << rinB << " superlayer thickness " << layerThick[i];
123 #endif
124 
125  dd4hep::Material matter = ns.material(materials[ii]);
126  dd4hep::Volume glog;
127  if (layerSense[ly] == 0) {
128  dd4hep::Solid solid = dd4hep::Box(absorbW, absorbH, 0.5 * thick[ii]);
129  ns.addSolidNS(ns.prepend(name), solid);
130  glog = dd4hep::Volume(solid.name(), solid, matter);
131 #ifdef EDM_ML_DEBUG
132  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule test: " << solid.name() << " box of dimension " << absorbW
133  << ":" << absorbH << ":" << 0.5 * thick[ii];
134 #endif
135  } else {
136  dd4hep::Solid solid = dd4hep::Tube(rinB, routF, 0.5 * thick[ii], 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") << "DDHGCalTBModule: " << solid.name() << " Tubs made of " << materials[ii]
141  << " of dimensions " << rinB << ", " << routF << ", " << 0.5 * thick[ii]
142  << ", 0.0, 360.0";
143 #endif
144  int ncol = static_cast<int>(2.0 * routF / ww) + 1;
145  int nrow = static_cast<int>(routF / (ww * tan(30._deg))) + 1;
146 #ifdef EDM_ML_DEBUG
147  int incm(0), inrm(0), kount(0), ntot(0), nin(0), nfine(0), ncoarse(0);
148  edm::LogVerbatim("HGCalGeom") << glog.name() << " rout " << routF << " Row " << nrow << " Column " << ncol;
149 #endif
150  double xc[6], yc[6];
151  for (int nr = -nrow; nr <= nrow; ++nr) {
152  int inr = (nr >= 0) ? nr : -nr;
153  for (int nc = -ncol; nc <= ncol; ++nc) {
154  int inc = (nc >= 0) ? nc : -nc;
155  if (inr % 2 == inc % 2) {
156  double xpos = nc * dx;
157  double ypos = nr * dy;
158  xc[0] = xpos + dx;
159  yc[0] = ypos - 0.5 * rr;
160  xc[1] = xpos + dx;
161  yc[1] = ypos + 0.5 * rr;
162  xc[2] = xpos;
163  yc[2] = ypos + rr;
164  xc[3] = xpos - dx;
165  yc[3] = ypos + 0.5 * rr;
166  xc[4] = xpos + dx;
167  yc[4] = ypos - 0.5 * rr;
168  xc[5] = xpos;
169  yc[5] = ypos - rr;
170  bool cornerAll(true);
171  for (int k = 0; k < 6; ++k) {
172  double rpos = std::sqrt(xc[k] * xc[k] + yc[k] * yc[k]);
173  if (rpos < rinB || rpos > routF)
174  cornerAll = false;
175  }
176 #ifdef EDM_ML_DEBUG
177  ++ntot;
178 #endif
179  if (cornerAll) {
180  dd4hep::Volume glog1;
181  if (layerSense[ly] == 1) {
182  double rpos = std::sqrt(xpos * xpos + ypos * ypos);
183  glog1 = (rpos < rMaxFine) ? ns.volume(wafers[0]) : ns.volume(wafers[1]);
184 #ifdef EDM_ML_DEBUG
185  ++nin;
186  if (rpos < rMaxFine)
187  ++nfine;
188  else
189  ++ncoarse;
190 #endif
191  } else {
192  glog1 = ns.volume(covers[layerSense[ly] - 2]);
193  }
194  int copyL = HGCalTypes::packTypeUV(0, nc, nr);
195 #ifdef EDM_ML_DEBUG
196  if (inc > incm)
197  incm = inc;
198  if (inr > inrm)
199  inrm = inr;
200  kount++;
201  copies.insert(copy);
202 #endif
203  dd4hep::Position tran(xpos, ypos, 0.0);
204  glog.placeVolume(glog1, copyL, tran);
205 #ifdef EDM_ML_DEBUG
206  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << glog1.name() << " number " << copyL
207  << " positioned in " << glog.name() << " at " << tran;
208 #endif
209  }
210  }
211  }
212  }
213 #ifdef EDM_ML_DEBUG
214  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: # of columns " << incm << " # of rows " << inrm << " and "
215  << nin << ":" << kount << ":" << ntot << " wafers (" << nfine << ":" << ncoarse
216  << ") for " << glog.name() << " R " << rinB << ":" << routF;
217 #endif
218  }
219  dd4hep::Position r1(0, 0, zz);
220  module.placeVolume(glog, copy, r1);
221  ++copyNumber[ii];
222 #ifdef EDM_ML_DEBUG
223  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule test: " << glog.name() << " number " << copy
224  << " positioned in " << module.name() << " at " << r1;
225 #endif
226  zz += (0.5 * thick[ii]);
227  } // End of loop over layers in a block
228  zi = zo;
229  laymin = laymax;
230  if (fabs(thickTot - layerThick[i]) > tol2) {
231  if (thickTot > layerThick[i]) {
232  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick[i] << " is smaller than thickness "
233  << thickTot << " of all its components **** ERROR ****\n";
234  } else {
235  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << layerThick[i] << " does not match with "
236  << thickTot << " of the components\n";
237  }
238  }
239  } // End of loop over blocks
240 
241  return cms::s_executed;
242 }
243 
244 // first argument is the type from the xml file
245 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalTBModule, algorithm)
writedatasetfile.args
args
Definition: writedatasetfile.py:18
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
findQualityFiles.rr
string rr
Definition: findQualityFiles.py:185
cms::DDNamespace
Definition: DDNamespace.h:16
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
algorithm
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
Definition: DDHGCalTBModule.cc:17
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
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
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
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
CMSUnits.h
Exception.h
HGCalTypes.h
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