CMS 3D CMS Logo

DDHGCalTBModuleX.cc
Go to the documentation of this file.
1 /*
2  * DDHGCalTBModuleX.cc
3  *
4  * Created on: 27-Aug-2019
5  * Author: S. Banerjee
6  */
7 
8 #include <unordered_set>
9 
11 #include "DD4hep/DetFactoryHelper.h"
16 
17 //#define EDM_ML_DEBUG
18 using namespace geant_units::operators;
19 
20 namespace DDHGCalGeom {
22  const std::vector<std::string>& wafers,
23  const std::vector<std::string>& covers,
24  const std::vector<int>& layerType,
25  const std::vector<int>& layerSense,
26  const std::vector<int>& maxModule,
27  const std::vector<std::string>& names,
28  const std::vector<std::string>& materials,
29  std::vector<int>& copyNumber,
30  const std::vector<double>& layerThick,
31  const double& absorbW,
32  const double& absorbH,
33  const double& waferTot,
34  const double& rMax,
35  const double& rMaxFine,
36  std::unordered_set<int>& copies,
37  int firstLayer,
38  int lastLayer,
39  double zFront,
40  double totalWidth,
41  bool ignoreCenter,
43  static constexpr double tolerance = 0.00001;
44  static const double tan30deg = tan(30._deg);
45  double zi(zFront), thickTot(0);
46  for (int ly = firstLayer; ly <= lastLayer; ++ly) {
47  int ii = layerType[ly];
48  int copy = copyNumber[ii];
49  double zz = zi + (0.5 * layerThick[ii]);
50  double zo = zi + layerThick[ii];
51  thickTot += layerThick[ii];
52 
53  std::string name = "HGCal" + names[ii] + std::to_string(copy);
54 #ifdef EDM_ML_DEBUG
55  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: " << name << " Layer " << ly << ":" << ii << " Z "
56  << convertCmToMm(zi) << ":" << convertCmToMm(zo) << " Thick "
57  << convertCmToMm(layerThick[ii]) << " Sense " << layerSense[ly];
58 #endif
59  dd4hep::Material matter = ns.material(materials[ii]);
60  dd4hep::Volume glog;
61  if (layerSense[ly] == 0) {
62  dd4hep::Solid solid = dd4hep::Box(absorbW, absorbH, 0.5 * layerThick[ii]);
63  ns.addSolidNS(ns.prepend(name), solid);
64  glog = dd4hep::Volume(solid.name(), solid, matter);
65 #ifdef EDM_ML_DEBUG
66  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: " << solid.name() << " box of dimension "
67  << convertCmToMm(absorbW) << ":" << convertCmToMm(absorbH) << ":"
68  << convertCmToMm(0.5 * layerThick[ii]);
69 #endif
70  dd4hep::Position r1(0, 0, zz);
71  module.placeVolume(glog, copy, r1);
72 #ifdef EDM_ML_DEBUG
73  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: " << glog.name() << " number " << copy << " positioned in "
74  << module.name() << " at " << r1 << " with no rotation";
75 #endif
76  } else if (layerSense[ly] > 0) {
77  double dx = 0.5 * waferTot;
78  double dy = 3.0 * dx * tan30deg;
79  double rr = 2.0 * dx * tan30deg;
80  int ncol = (int)(2.0 * rMax / waferTot) + 1;
81  int nrow = (int)(rMax / (waferTot * tan30deg)) + 1;
82 #ifdef EDM_ML_DEBUG
83  int incm(0), inrm(0);
84  edm::LogVerbatim("HGCalGeom") << module.name() << " Copy " << copy << " Type " << layerSense[ly] << " rout "
85  << convertCmToMm(rMax) << " Row " << nrow << " column " << ncol << " ncrMax "
86  << maxModule[ly] << " Z " << convertCmToMm(zz) << " Center " << ignoreCenter
87  << " name " << name << " matter " << matter.name();
88  int kount(0);
89 #endif
90  if (maxModule[ly] >= 0) {
91  nrow = std::min(nrow, maxModule[ly]);
92  ncol = std::min(ncol, maxModule[ly]);
93  }
94  for (int nr = -nrow; nr <= nrow; ++nr) {
95  int inr = std::abs(nr);
96  for (int nc = -ncol; nc <= ncol; ++nc) {
97  int inc = std::abs(nc);
98  if ((inr % 2 == inc % 2) && (!ignoreCenter || nc != 0 || nr != 0)) {
99  double xpos = nc * dx;
100  double ypos = nr * dy;
101  double xc[6], yc[6];
102  xc[0] = xpos + dx;
103  yc[0] = ypos - 0.5 * rr;
104  xc[1] = xpos + dx;
105  yc[1] = ypos + 0.5 * rr;
106  xc[2] = xpos;
107  yc[2] = ypos + rr;
108  xc[3] = xpos - dx;
109  yc[3] = ypos + 0.5 * rr;
110  xc[4] = xpos + dx;
111  yc[4] = ypos - 0.5 * rr;
112  xc[5] = xpos;
113  yc[5] = ypos - rr;
114  bool cornerAll(true);
115  for (int k = 0; k < 6; ++k) {
116  double rpos = std::sqrt(xc[k] * xc[k] + yc[k] * yc[k]);
117  if (rpos > rMax)
118  cornerAll = false;
119  }
120  if (cornerAll) {
121  double rpos = std::sqrt(xpos * xpos + ypos * ypos);
122  dd4hep::Position tran(xpos, ypos, zz);
123  int copyx = inr * 100 + inc;
124  if (nc < 0)
125  copyx += 10000;
126  if (nr < 0)
127  copyx += 100000;
128  if (layerSense[ly] == 1) {
129  dd4hep::Solid solid = ns.solid(covers[0]);
130  std::string name0 = name + "M" + std::to_string(copyx);
131  name0 = ns.prepend(name0);
132  dd4hep::Volume glog1 = dd4hep::Volume(name0, solid, matter);
133  module.placeVolume(glog1, copy, tran);
134 #ifdef EDM_ML_DEBUG
135  edm::LogVerbatim("HGCalGeom")
136  << "DDHGCalTBModuleX: " << glog1.name() << " number " << copy << " positioned in "
137  << module.name() << " at " << tran << " with no rotation";
138 #endif
139  dd4hep::Volume glog2 = (rpos < rMaxFine) ? ns.volume(wafers[0]) : ns.volume(wafers[1]);
140  glog1.placeVolume(glog2, copyx);
141 #ifdef EDM_ML_DEBUG
142  edm::LogVerbatim("HGCalGeom")
143  << "DDHGCalTBModuleX: " << glog2.name() << " number " << copyx << " positioned in "
144  << glog1.name() << " at (0, 0, 0) with no rotation";
145 #endif
146  if (layerSense[ly] == 1)
147  copies.insert(copy);
148  } else {
149  dd4hep::Volume glog2 = ns.volume(covers[layerSense[ly] - 1]);
150  copyx += (copy * 1000000);
151  module.placeVolume(glog2, copyx, tran);
152 #ifdef EDM_ML_DEBUG
153  edm::LogVerbatim("HGCalGeom")
154  << "DDHGCalTBModuleX: " << glog2.name() << " number " << copyx << " positioned in "
155  << module.name() << " at " << tran << " with no rotation";
156 #endif
157  }
158 #ifdef EDM_ML_DEBUG
159  if (inc > incm)
160  incm = inc;
161  if (inr > inrm)
162  inrm = inr;
163  kount++;
164 #endif
165  }
166  }
167  }
168  }
169 #ifdef EDM_ML_DEBUG
170  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: # of columns " << incm << " # of rows " << inrm << " and "
171  << kount << " wafers for " << module.name();
172 #endif
173  }
174  ++copyNumber[ii];
175  zi = zo;
176  } // End of loop over layers in a block
177 
178  if (fabs(thickTot - totalWidth) < tolerance) {
179  } else if (thickTot > totalWidth) {
180  edm::LogError("HGCalGeom") << "Thickness of the partition " << totalWidth << " is smaller than " << thickTot
181  << ": total thickness of all its components in " << module.name() << " Layers "
182  << firstLayer << ":" << lastLayer << ":" << ignoreCenter << "**** ERROR ****";
183  } else if (thickTot < totalWidth) {
184  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << totalWidth << " does not match with " << thickTot
185  << " of the components in " << module.name() << " Layers " << firstLayer << ":"
186  << lastLayer << ":" << ignoreCenter;
187  }
188  }
189 } // namespace DDHGCalGeom
190 
191 static long algorithm(dd4hep::Detector& /* description */,
192  cms::DDParsingContext& ctxt,
193  xml_h e,
194  dd4hep::SensitiveDetector& /* sens */) {
195  cms::DDNamespace ns(ctxt, e, true);
196  cms::DDAlgoArguments args(ctxt, e);
197 
198  const auto& wafers = args.value<std::vector<std::string> >("WaferName"); // Wafers
199  const auto& covers = args.value<std::vector<std::string> >("CoverName"); // Insensitive layers of hexagonal size
200  const auto& genMat = args.value<std::string>("GeneralMaterial"); // General material used for blocks
201 #ifdef EDM_ML_DEBUG
202  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: Material " << genMat << " with " << wafers.size() << " wafers";
203  unsigned int i(0);
204  for (auto wafer : wafers) {
205  edm::LogVerbatim("HGCalGeom") << "Wafer[" << i << "] " << wafer;
206  ++i;
207  }
208  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: " << covers.size() << " covers";
209  i = 0;
210  for (auto cover : covers) {
211  edm::LogVerbatim("HGCalGeom") << "Cover[" << i << "] " << cover;
212  ++i;
213  }
214 #endif
215  const auto& materials = args.value<std::vector<std::string> >("MaterialNames"); // Material names in each layer
216  const auto& names = args.value<std::vector<std::string> >("VolumeNames"); // Names of each layer
217  const auto& layerThick = args.value<std::vector<double> >("Thickness"); // Thickness of the material
218  std::vector<int> copyNumber; // Copy numbers (initiated to 1)
219  for (unsigned int k = 0; k < layerThick.size(); ++k) {
220  copyNumber.emplace_back(1);
221  }
222 #ifdef EDM_ML_DEBUG
223  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: " << materials.size() << " types of volumes";
224  for (unsigned int i = 0; i < names.size(); ++i)
225  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names[i] << " of thickness "
226  << convertCmToMm(layerThick[i]) << " filled with " << materials[i]
227  << " first copy number " << copyNumber[i];
228 #endif
229  const auto& blockThick = args.value<std::vector<double> >("BlockThick"); // Thickness of each section
230  const auto& inOut = args.value<int>("InOut"); // Number of inner+outer parts
231  const auto& layerFrontIn = args.value<std::vector<int> >("LayerFrontIn"); // First layer index (inner) in block
232  const auto& layerBackIn = args.value<std::vector<int> >("LayerBackIn"); // Last layer index (inner) in block
233  std::vector<int> layerFrontOut; // First layer index (outner) in block
234  std::vector<int> layerBackOut; // Last layer index (outner) in block
235  if (inOut > 1) {
236  layerFrontOut = args.value<std::vector<int> >("LayerFrontOut");
237  layerBackOut = args.value<std::vector<int> >("LayerBackOut");
238  }
239 #ifdef EDM_ML_DEBUG
240  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: " << blockThick.size() << " blocks with in/out " << inOut;
241  for (unsigned int i = 0; i < blockThick.size(); ++i) {
242  if (inOut > 1)
243  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << convertCmToMm(blockThick[i])
244  << " with inner layers " << layerFrontIn[i] << ":" << layerBackIn[i]
245  << " and outer layers " << layerFrontOut[i] << ":" << layerBackOut[i];
246  else
247  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << convertCmToMm(blockThick[i])
248  << " with inner layers " << layerFrontIn[i] << ":" << layerBackIn[i];
249  }
250 #endif
251  const auto& layerType = args.value<std::vector<int> >("LayerType"); // Type of the layer
252  const auto& layerSense = args.value<std::vector<int> >("LayerSense"); // Content of a layer
253  const auto& maxModule = args.value<std::vector<int> >("MaxModule"); // Maximum # of row/column
254 #ifdef EDM_ML_DEBUG
255  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: " << layerType.size() << " layers";
256  for (unsigned int i = 0; i < layerType.size(); ++i)
257  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType[i] << " sensitive class "
258  << layerSense[i] << " and " << maxModule[i] << " maximum row/columns";
259 #endif
260  const auto& zMinBlock = args.value<double>("zMinBlock"); // Starting z-value of the block
261  const auto& rMaxFine = args.value<double>("rMaxFine"); // Maximum r-value for fine wafer
262  const auto& waferW = args.value<double>("waferW"); // Width of the wafer
263  const auto& waferGap = args.value<double>("waferGap"); // Gap between 2 wafers
264  const auto& absorbW = args.value<double>("absorberW"); // Width of the absorber
265  const auto& absorbH = args.value<double>("absorberH"); // Height of the absorber
266  const auto& rMax = args.value<double>("rMax"); // Maximum radial extent
267  const auto& rMaxB = args.value<double>("rMaxB"); // Maximum radial extent of a block
268  double waferTot = waferW + waferGap;
269  std::string idName = DDSplit(args.parentName()).first;
270 #ifdef EDM_ML_DEBUG
271  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: zStart " << convertCmToMm(zMinBlock) << " rFineCoarse "
272  << convertCmToMm(rMaxFine) << " wafer width " << convertCmToMm(waferW)
273  << " gap among wafers " << convertCmToMm(waferGap) << " absorber width "
274  << convertCmToMm(absorbW) << " absorber height " << convertCmToMm(absorbH) << " rMax "
275  << convertCmToMm(rMax) << ":" << convertCmToMm(rMaxB);
276  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: NameSpace " << ns.name() << " Parent Name " << idName;
277 #endif
278  std::unordered_set<int> copies; // List of copy #'s
279  copies.clear();
280 
281  dd4hep::Volume parent = ns.volume(args.parentName());
282  double zi(zMinBlock);
283  for (unsigned int i = 0; i < blockThick.size(); i++) {
284  double zo = zi + blockThick[i];
285  std::string name = idName + "Block" + std::to_string(i);
286 #ifdef EDM_ML_DEBUG
287  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: Block " << i << ":" << name << " z " << convertCmToMm(zi) << ":"
288  << convertCmToMm(zo) << " R " << convertCmToMm(rMaxB) << " T "
289  << convertCmToMm(blockThick[i]);
290 #endif
291  dd4hep::Material matter = ns.material(genMat);
292  dd4hep::Solid solid = dd4hep::Tube(0, rMaxB, 0.5 * blockThick[i], 0.0, 2._pi);
293  ns.addSolidNS(ns.prepend(name), solid);
294  dd4hep::Volume glog = dd4hep::Volume(solid.name(), solid, matter);
295  double zz = zi + 0.5 * blockThick[i];
296  dd4hep::Position r1(0, 0, zz);
297  parent.placeVolume(glog, i, r1);
298 #ifdef EDM_ML_DEBUG
299  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: " << glog.name() << " number " << i << " positioned in "
300  << args.parentName() << " at " << r1 << " with no rotation";
301  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: \t\tInside Block " << i << " Layers " << layerFrontIn[i] << ":"
302  << layerBackIn[i] << " zFront " << convertCmToMm(-0.5 * blockThick[i])
303  << " thickness " << convertCmToMm(blockThick[i]) << " ignore Center 0";
304 #endif
306  wafers,
307  covers,
308  layerType,
309  layerSense,
310  maxModule,
311  names,
312  materials,
313  copyNumber,
314  layerThick,
315  absorbW,
316  absorbH,
317  waferTot,
318  rMax,
319  rMaxFine,
320  copies,
321  layerFrontIn[i],
322  layerBackIn[i],
323  -0.5 * blockThick[i],
324  blockThick[i],
325  false,
326  glog);
327  if (inOut > 1) {
328 #ifdef EDM_ML_DEBUG
329  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: \t\tInside Block " << i << " Layers " << layerFrontOut[i]
330  << ":" << layerBackOut[i] << " zFront " << convertCmToMm(-0.5 * blockThick[i])
331  << " thickness " << convertCmToMm(blockThick[i]) << " ignore Center 1";
332 #endif
334  wafers,
335  covers,
336  layerType,
337  layerSense,
338  maxModule,
339  names,
340  materials,
341  copyNumber,
342  layerThick,
343  absorbW,
344  absorbH,
345  waferTot,
346  rMax,
347  rMaxFine,
348  copies,
349  layerFrontOut[i],
350  layerBackOut[i],
351  -0.5 * blockThick[i],
352  blockThick[i],
353  true,
354  glog);
355  }
356  zi = zo;
357  }
358 #ifdef EDM_ML_DEBUG
359  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: All blocks are placed in " << convertCmToMm(zMinBlock) << ":"
360  << convertCmToMm(zi) << " with " << copies.size() << " different wafer copy numbers";
361 #endif
362 
363  return 1;
364 }
365 
366 // first argument is the type from the xml file
367 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalTBModuleX, algorithm)
writedatasetfile.args
args
Definition: writedatasetfile.py:18
photonAnalyzer_cfi.rMax
rMax
Definition: photonAnalyzer_cfi.py:91
mps_fire.i
i
Definition: mps_fire.py:355
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
g4SimHits_cfi.Material
Material
Definition: g4SimHits_cfi.py:547
MessageLogger.h
cms::DDNamespace::solid
dd4hep::Solid solid(const std::string &name) const
Definition: DDNamespace.cc:225
DECLARE_DDCMS_DETELEMENT
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:30
cms::DDNamespace::material
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:121
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
min
T min(T a, T b)
Definition: MathUtil.h:58
cms::DDParsingContext
Definition: DDParsingContext.h:14
findQualityFiles.rr
string rr
Definition: findQualityFiles.py:185
cms::DDNamespace
Definition: DDNamespace.h:16
DDSplit.h
versionedElectronIDProducer_cfi.idName
idName
Definition: versionedElectronIDProducer_cfi.py:11
geant_units::operators
Definition: GeantUnits.h:18
dqmdumpme.first
first
Definition: dqmdumpme.py:55
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:122
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
cms::DDNamespace::prepend
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:66
PixelTestBeamValidation_cfi.Position
Position
Definition: PixelTestBeamValidation_cfi.py:62
dqmdumpme.k
k
Definition: dqmdumpme.py:60
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
cms::Volume
dd4hep::Volume Volume
Definition: DDFilteredView.h:45
edm::LogError
Definition: MessageLogger.h:183
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
geant_units::operators::convertCmToMm
constexpr NumType convertCmToMm(NumType centimeters)
Definition: GeantUnits.h:68
GeantUnits.h
DDPlugins.h
algorithm
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e, dd4hep::SensitiveDetector &)
Definition: DDHGCalTBModuleX.cc:191
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
createfilelist.int
int
Definition: createfilelist.py:10
tolerance
const double tolerance
Definition: HGCalGeomParameters.cc:27
edm::LogVerbatim
Definition: MessageLogger.h:297
cms::DDNamespace::addSolidNS
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:206
cms::DDAlgoArguments
Definition: DDAlgoArguments.h:28
PVValHelper::dy
Definition: PVValidationHelpers.h:49
module
Definition: vlib.h:198
align::Detector
Definition: StructureType.h:86
DDHGCalGeom::constructLayers
void constructLayers(const cms::DDNamespace &ns, const std::vector< std::string > &wafers, const std::vector< std::string > &covers, const std::vector< int > &layerType, const std::vector< int > &layerSense, const std::vector< int > &maxModule, const std::vector< std::string > &names, const std::vector< std::string > &materials, std::vector< int > &copyNumber, const std::vector< double > &layerThick, const double &absorbW, const double &absorbH, const double &waferTot, const double &rMax, const double &rMaxFine, std::unordered_set< int > &copies, int firstLayer, int lastLayer, double zFront, double totalWidth, bool ignoreCenter, dd4hep::Volume &module)
Definition: DDHGCalTBModuleX.cc:21
diffTwoXMLs.r1
r1
Definition: diffTwoXMLs.py:53
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
Exception.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
cms::DDNamespace::name
std::string_view name() const
Definition: DDNamespace.h:68
class-composition.parent
parent
Definition: class-composition.py:88
cuy.ii
ii
Definition: cuy.py:590
cms::DDNamespace::volume
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:190
PVValHelper::dx
Definition: PVValidationHelpers.h:48
DDHGCalGeom
Definition: DDHGCalTBModuleX.cc:20
DDSplit
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = ':'
Definition: DDSplit.cc:3
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37