CMS 3D CMS Logo

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