CMS 3D CMS Logo

DDAHcalModuleAlgo.cc
Go to the documentation of this file.
1 /*
2  * DDAHcalModuleAlgo.cc
3  *
4  * Created on: 27-August-2019
5  * Author: Sunanda Banerjee
6  */
7 
9 #include "DD4hep/DetFactoryHelper.h"
14 
15 //#define EDM_ML_DEBUG
16 using namespace cms_units::operators;
17 
18 static long algorithm(dd4hep::Detector& /* description */,
20  xml_h e,
21  dd4hep::SensitiveDetector& /* sens */) {
22  cms::DDNamespace ns(ctxt, e, true);
24 
25  const auto& tile = args.value<std::string>("TileName"); // Scintillator tile
26  const auto& materials = args.value<std::vector<std::string> >("MaterialNames"); // Materials
27  const auto& names = args.value<std::vector<std::string> >("VolumeNames"); // Names
28  const auto& thick = args.value<std::vector<double> >("Thickness"); // Thickness of the material
29  std::vector<int> copyNumber; // Initial copy numbers
30  for (unsigned int i = 0; i < materials.size(); ++i)
31  copyNumber.emplace_back(1);
32 #ifdef EDM_ML_DEBUG
33  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: Tile " << tile;
34  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << materials.size() << " types of volumes";
35  for (unsigned int i = 0; i < names.size(); ++i)
36  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names[i] << " of thickness " << thick[i]
37  << " filled with " << materials[i] << " first copy number " << copyNumber[i];
38 #endif
39  const auto& layers = args.value<std::vector<int> >("Layers"); // Number of layers in a section
40  const auto& layerThick = args.value<std::vector<double> >("LayerThick"); // Thickness of each section
41  const auto& layerType = args.value<std::vector<int> >("LayerType"); // Type of the layer
42  const auto& layerSense = args.value<std::vector<int> >("LayerSense"); // Content of a layer (sensitive?)
43 #ifdef EDM_ML_DEBUG
44  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << layers.size() << " blocks";
45  for (unsigned int i = 0; i < layers.size(); ++i)
46  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << layerThick[i] << " with " << layers[i]
47  << " layers";
48  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << layerType.size() << " layers";
49  for (unsigned int i = 0; i < layerType.size(); ++i)
50  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType[i] << " sensitive class "
51  << layerSense[i];
52 #endif
53  const auto& widths = args.value<std::vector<double> >("Widths"); // Width (passive, active)
54  const auto& heights = args.value<std::vector<double> >("Heights"); // Heights (passive, active)
55  const auto& tileN = args.value<std::vector<int> >("TileN"); // # of tiles (along x, y)
56  const auto& tileStep = args.value<std::vector<double> >("TileStep"); // Separation between tiles (x, y)
57 #ifdef EDM_ML_DEBUG
58  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << widths.size() << " sizes for width "
59  << "and height:";
60  for (unsigned int i = 0; i < widths.size(); ++i)
61  edm::LogVerbatim("HGCalGeom") << " [" << i << "] " << widths[i] << ":" << heights[i];
62  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << tileN.size() << " tile positioning parameters";
63  for (unsigned int i = 0; i < tileN.size(); ++i)
64  edm::LogVerbatim("HGCalGeom") << " [" << i << "] " << tileN[i] << ":" << tileStep[i];
65 #endif
66  const auto& zMinBlock = args.value<double>("zMinBlock"); // Starting z-value of the block
67 #ifdef EDM_ML_DEBUG
68  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: zStart " << zMinBlock << " NameSpace " << ns.name();
69 #endif
70 
71  // Mother module
72  dd4hep::Volume module = ns.volume(args.parentName());
73 
74  double zi(zMinBlock);
75  int laymin(0);
76  for (unsigned int i = 0; i < layers.size(); i++) {
77  double zo = zi + layerThick[i];
78  int laymax = laymin + layers[i];
79  double zz = zi;
80  double thickTot(0);
81  for (int ly = laymin; ly < laymax; ++ly) {
82  int ii = layerType[ly];
83  int copy = copyNumber[ii];
84  zz += (0.5 * thick[ii]);
85  thickTot += thick[ii];
86 
87  std::string name = "HGCal" + names[ii] + std::to_string(copy);
88 #ifdef EDM_ML_DEBUG
89  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo test: Layer " << ly << ":" << ii << " Front " << zi
90  << " Back " << zo << " superlayer thickness " << layerThick[i];
91 #endif
92  dd4hep::Material matter = ns.material(materials[ii]);
93  dd4hep::Volume glog;
94  if (layerSense[ly] == 0) {
95  dd4hep::Solid solid = dd4hep::Box(0.5 * widths[0], 0.5 * heights[0], 0.5 * thick[ii]);
96  ns.addSolidNS(ns.prepend(name), solid);
97  glog = dd4hep::Volume(solid.name(), solid, matter);
98 #ifdef EDM_ML_DEBUG
99  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << solid.name() << " Box made of " << materials[ii]
100  << " of dimensions " << 0.5 * widths[0] << ", " << 0.5 * heights[0] << ", "
101  << 0.5 * thick[ii];
102 #endif
103  } else {
104  dd4hep::Solid solid = dd4hep::Box(0.5 * widths[1], 0.5 * heights[1], 0.5 * thick[ii]);
105  ns.addSolidNS(ns.prepend(name), solid);
106  glog = dd4hep::Volume(solid.name(), solid, matter);
107 #ifdef EDM_ML_DEBUG
108  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << solid.name() << " Box made of " << materials[ii]
109  << " of dimensions " << 0.5 * widths[1] << ", " << 0.5 * heights[1] << ", "
110  << 0.5 * thick[ii];
111 #endif
112  int ncol = tileN[0] / 2;
113  int nrow = tileN[1] / 2;
114 #ifdef EDM_ML_DEBUG
115  int kount(0);
116  edm::LogVerbatim("HGCalGeom") << glog.name() << " Row " << nrow << " Column " << ncol;
117 #endif
118  for (int nr = -nrow; nr <= nrow; ++nr) {
119  int inr = (nr >= 0) ? nr : -nr;
120  double ypos = (nr >= 0) ? (inr - 0.5) * tileStep[1] : -(inr - 0.5) * tileStep[1];
121  for (int nc = -ncol; nc <= ncol; ++nc) {
122  int inc = (nc >= 0) ? nc : -nc;
123  double xpos = (nc >= 0) ? (inc - 0.5) * tileStep[0] : -(inc - 0.5) * tileStep[0];
124  if (nr != 0 && nc != 0) {
125  dd4hep::Position tran(xpos, ypos, 0.0);
126  dd4hep::Rotation3D rotation;
127  int copy = inr * AHCalParameters::kColumn_ + inc;
128  if (nc < 0)
130  if (nr < 0)
132  dd4hep::Volume glog1 = ns.volume(tile);
133  glog.placeVolume(glog1, copy, dd4hep::Transform3D(rotation, tran));
134 #ifdef EDM_ML_DEBUG
135  kount++;
136  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << tile << " number " << copy << " positioned in "
137  << glog.name() << " at " << tran << " with " << rotation;
138 #endif
139  }
140  }
141  }
142 #ifdef EDM_ML_DEBUG
143  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << kount << " tiles for " << glog.name();
144 #endif
145  }
146  dd4hep::Position r1(0, 0, zz);
147  dd4hep::Rotation3D rot;
148  module.placeVolume(glog, copy, dd4hep::Transform3D(rot, r1));
149  ++copyNumber[ii];
150 #ifdef EDM_ML_DEBUG
151  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << glog.name() << " number " << copy << " positioned in "
152  << module.name() << " at " << r1 << " with " << rot;
153 #endif
154  zz += (0.5 * thick[ii]);
155  } // End of loop over layers in a block
156  zi = zo;
157  laymin = laymax;
158  if (fabs(thickTot - layerThick[i]) < 0.00001) {
159  } else if (thickTot > layerThick[i]) {
160  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick[i] << " is smaller than thickness "
161  << thickTot << " of all its components **** ERROR ****\n";
162  } else if (thickTot < layerThick[i]) {
163  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << layerThick[i] << " does not match with "
164  << thickTot << " of the components\n";
165  }
166  } // End of loop over blocks
167 
168  return 1;
169 }
170 
171 // first argument is the type from the xml file
172 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDAHcalModuleAlgo, algorithm)
writedatasetfile.args
args
Definition: writedatasetfile.py:18
mps_fire.i
i
Definition: mps_fire.py:355
cms_units::operators
Definition: CMSUnits.h:13
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
g4SimHits_cfi.Material
Material
Definition: g4SimHits_cfi.py:547
algorithm
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e, dd4hep::SensitiveDetector &)
Definition: DDAHcalModuleAlgo.cc:18
MessageLogger.h
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
cms::DDParsingContext
Definition: DDParsingContext.h:14
cms::DDNamespace
Definition: DDNamespace.h:16
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:122
cms::DDNamespace::prepend
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:66
PixelTestBeamValidation_cfi.Position
Position
Definition: PixelTestBeamValidation_cfi.py:62
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
cms::Volume
dd4hep::Volume Volume
Definition: DDFilteredView.h:45
AHCalParameters::kSignRowColumn_
static constexpr int kSignRowColumn_
Definition: AHCalParameters.h:31
idealTransformation.rotation
dictionary rotation
Definition: idealTransformation.py:1
edm::LogError
Definition: MessageLogger.h:183
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
DDPlugins.h
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
AHCalParameters::kColumn_
static constexpr int kColumn_
Constants used.
Definition: AHCalParameters.h:27
module
Definition: vlib.h:198
align::Detector
Definition: StructureType.h:86
AHCalParameters.h
diffTwoXMLs.r1
r1
Definition: diffTwoXMLs.py:53
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
CMSUnits.h
Exception.h
AHCalParameters::kRowColumn_
static constexpr int kRowColumn_
Definition: AHCalParameters.h:30
cms::DDNamespace::name
std::string_view name() const
Definition: DDNamespace.h:68
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
hgcalTopologyTester_cfi.layers
layers
Definition: hgcalTopologyTester_cfi.py:8
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37