CMS 3D CMS Logo

DDAHcalModuleAlgo.cc
Go to the documentation of this file.
1 // File: DDAHcalModuleAlgo.cc
3 // Description: Geometry factory class for HGCal (EE and HESil)
5 
6 #include <algorithm>
7 #include <cmath>
8 #include <string>
9 #include <vector>
10 
23 
24 //#define EDM_ML_DEBUG
25 
26 class DDAHcalModuleAlgo : public DDAlgorithm {
27 public:
28  // Constructor and Destructor
29  DDAHcalModuleAlgo(); // const std::string & name);
30  ~DDAHcalModuleAlgo() override;
31 
32  void initialize(const DDNumericArguments& nArgs,
33  const DDVectorArguments& vArgs,
34  const DDMapArguments& mArgs,
35  const DDStringArguments& sArgs,
36  const DDStringVectorArguments& vsArgs) override;
37  void execute(DDCompactView& cpv) override;
38 
39 protected:
40  void constructLayers(const DDLogicalPart&, DDCompactView& cpv);
42 
43 private:
44  std::string tile; // Scintillator tile
45  std::vector<std::string> materials; // Materials
46  std::vector<std::string> names; // Names
47  std::vector<double> thick; // Thickness of the material
48  std::vector<int> copyNumber; // Initial copy numbers
49  std::vector<int> layers; // Number of layers in a section
50  std::vector<double> layerThick; // Thickness of each section
51  std::vector<int> layerType; // Type of the layer
52  std::vector<int> layerSense; // Content of a layer (sensitive?)
53  std::vector<double> widths; // Width (passive, active)
54  std::vector<double> heights; // Heights (passive, active)
55  std::vector<int> tileN; // # of tiles (along x, y)
56  std::vector<double> tileStep; // Separation between tiles (x, y)
57  double zMinBlock; // Starting z-value of the block
58  std::string idNameSpace; // Namespace of this and ALL sub-parts
59 };
60 
62 #ifdef EDM_ML_DEBUG
63  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: Creating an instance";
64 #endif
65 }
66 
68 
70  const DDVectorArguments& vArgs,
71  const DDMapArguments&,
72  const DDStringArguments& sArgs,
73  const DDStringVectorArguments& vsArgs) {
74  tile = sArgs["TileName"];
75 #ifdef EDM_ML_DEBUG
76  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: Tile " << tile;
77 #endif
78  materials = vsArgs["MaterialNames"];
79  names = vsArgs["VolumeNames"];
80  thick = vArgs["Thickness"];
81  for (unsigned int i = 0; i < materials.size(); ++i) {
82  copyNumber.emplace_back(1);
83  }
84 #ifdef EDM_ML_DEBUG
85  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << materials.size() << " types of volumes";
86  for (unsigned int i = 0; i < names.size(); ++i)
87  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names[i] << " of thickness " << thick[i]
88  << " filled with " << materials[i] << " first copy number " << copyNumber[i];
89 #endif
90  layers = dbl_to_int(vArgs["Layers"]);
91  layerThick = vArgs["LayerThick"];
92 #ifdef EDM_ML_DEBUG
93  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << layers.size() << " blocks";
94  for (unsigned int i = 0; i < layers.size(); ++i)
95  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << layerThick[i] << " with " << layers[i]
96  << " layers";
97 #endif
98  layerType = dbl_to_int(vArgs["LayerType"]);
99  layerSense = dbl_to_int(vArgs["LayerSense"]);
100 #ifdef EDM_ML_DEBUG
101  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << layerType.size() << " layers";
102  for (unsigned int i = 0; i < layerType.size(); ++i)
103  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType[i] << " sensitive class "
104  << layerSense[i];
105 #endif
106  widths = vArgs["Widths"];
107  heights = vArgs["Heights"];
108 #ifdef EDM_ML_DEBUG
109  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << widths.size() << " sizes for width "
110  << "and height:";
111  for (unsigned int i = 0; i < widths.size(); ++i)
112  edm::LogVerbatim("HGCalGeom") << " [" << i << "] " << widths[i] << ":" << heights[i];
113 #endif
114  tileN = dbl_to_int(vArgs["TileN"]);
115  tileStep = vArgs["TileStep"];
116 #ifdef EDM_ML_DEBUG
117  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << tileN.size() << " tile positioning parameters";
118  for (unsigned int i = 0; i < tileN.size(); ++i)
119  edm::LogVerbatim("HGCalGeom") << " [" << i << "] " << tileN[i] << ":" << tileStep[i];
120 #endif
121  zMinBlock = nArgs["zMinBlock"];
123 #ifdef EDM_ML_DEBUG
124  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: zStart " << zMinBlock << " NameSpace " << idNameSpace;
125 #endif
126 }
127 
129 // DDAHcalModuleAlgo methods...
131 
133 #ifdef EDM_ML_DEBUG
134  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDAHcalModuleAlgo...";
135 #endif
136  constructLayers(parent(), cpv);
137 #ifdef EDM_ML_DEBUG
138  edm::LogVerbatim("HGCalGeom") << "<<== End of DDAHcalModuleAlgo construction";
139 #endif
140 }
141 
143 #ifdef EDM_ML_DEBUG
144  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo test: \t\tInside Layers";
145 #endif
146  double zi(zMinBlock);
147  int laymin(0);
148  for (unsigned int i = 0; i < layers.size(); i++) {
149  double zo = zi + layerThick[i];
150  int laymax = laymin + layers[i];
151  double zz = zi;
152  double thickTot(0);
153  for (int ly = laymin; ly < laymax; ++ly) {
154  int ii = layerType[ly];
155  int copy = copyNumber[ii];
156  zz += (0.5 * thick[ii]);
157  thickTot += thick[ii];
158 
159  std::string name = "HGCal" + names[ii] + std::to_string(copy);
160 #ifdef EDM_ML_DEBUG
161  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo test: Layer " << ly << ":" << ii << " Front " << zi
162  << " Back " << zo << " superlayer thickness " << layerThick[i];
163 #endif
164  DDName matName(DDSplit(materials[ii]).first, DDSplit(materials[ii]).second);
165  DDMaterial matter(matName);
166  DDLogicalPart glog;
167  if (layerSense[ly] == 0) {
168  DDSolid solid =
169  DDSolidFactory::box(DDName(name, idNameSpace), 0.5 * widths[0], 0.5 * heights[0], 0.5 * thick[ii]);
170  glog = DDLogicalPart(solid.ddname(), matter, solid);
171 #ifdef EDM_ML_DEBUG
172  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << solid.name() << " Box made of " << matName
173  << " of dimensions " << 0.5 * widths[0] << ", " << 0.5 * heights[0] << ", "
174  << 0.5 * thick[ii];
175 #endif
176  } else {
177  DDSolid solid =
178  DDSolidFactory::box(DDName(name, idNameSpace), 0.5 * widths[1], 0.5 * heights[1], 0.5 * thick[ii]);
179  glog = DDLogicalPart(solid.ddname(), matter, solid);
180 #ifdef EDM_ML_DEBUG
181  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << solid.name() << " Box made of " << matName
182  << " of dimensions " << 0.5 * widths[1] << ", " << 0.5 * heights[1] << ", "
183  << 0.5 * thick[ii];
184 #endif
185  positionSensitive(glog, cpv);
186  }
187  DDTranslation r1(0, 0, zz);
188  DDRotation rot;
189  cpv.position(glog, module, copy, r1, rot);
190  ++copyNumber[ii];
191 #ifdef EDM_ML_DEBUG
192  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << glog.name() << " number " << copy << " positioned in "
193  << module.name() << " at " << r1 << " with " << rot;
194 #endif
195  zz += (0.5 * thick[ii]);
196  } // End of loop over layers in a block
197  zi = zo;
198  laymin = laymax;
199  if (fabs(thickTot - layerThick[i]) < 0.00001) {
200  } else if (thickTot > layerThick[i]) {
201  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick[i] << " is smaller than thickness "
202  << thickTot << " of all its components **** ERROR ****\n";
203  } else if (thickTot < layerThick[i]) {
204  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << layerThick[i] << " does not match with "
205  << thickTot << " of the components\n";
206  }
207  } // End of loop over blocks
208 }
209 
211  int ncol = tileN[0] / 2;
212  int nrow = tileN[1] / 2;
213 #ifdef EDM_ML_DEBUG
214  int kount(0);
215  edm::LogVerbatim("HGCalGeom") << glog.ddname() << " Row " << nrow << " Column " << ncol;
216 #endif
217  for (int nr = -nrow; nr <= nrow; ++nr) {
218  int inr = (nr >= 0) ? nr : -nr;
219  double ypos = (nr >= 0) ? (inr - 0.5) * tileStep[1] : -(inr - 0.5) * tileStep[1];
220  for (int nc = -ncol; nc <= ncol; ++nc) {
221  int inc = (nc >= 0) ? nc : -nc;
222  double xpos = (nc >= 0) ? (inc - 0.5) * tileStep[0] : -(inc - 0.5) * tileStep[0];
223  if (nr != 0 && nc != 0) {
224  DDTranslation tran(xpos, ypos, 0.0);
226  int copy = inr * AHCalParameters::kColumn_ + inc;
227  if (nc < 0)
229  if (nr < 0)
232  cpv.position(name, glog.ddname(), copy, tran, rotation);
233 #ifdef EDM_ML_DEBUG
234  kount++;
235  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << name << " number " << copy << " positioned in "
236  << glog.ddname() << " at " << tran << " with " << rotation;
237 #endif
238  }
239  }
240  }
241 #ifdef EDM_ML_DEBUG
242  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << kount << " tiles for " << glog.ddname();
243 #endif
244 }
245 
246 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDAHcalModuleAlgo, "hgcal:DDAHcalModuleAlgo");
std::vector< int > layerType
std::vector< std::string > materials
static constexpr int kSignRowColumn_
std::vector< double > widths
void constructLayers(const DDLogicalPart &, DDCompactView &cpv)
const N & name() const
Definition: DDBase.h:59
std::vector< int > copyNumber
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
~DDAHcalModuleAlgo() override
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
std::vector< double > heights
void execute(DDCompactView &cpv) override
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
std::vector< int > dbl_to_int(const std::vector< double > &vecdbl)
Converts a std::vector of doubles to a std::vector of int.
Definition: DDutils.h:7
std::vector< double > thick
std::vector< std::string > names
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
static DDSolid box(const DDName &name, double xHalf, double yHalf, double zHalf)
Creates a box with side length 2*xHalf, 2*yHalf, 2*zHalf.
Definition: DDSolid.cc:533
ii
Definition: cuy.py:590
static constexpr int kRowColumn_
std::vector< double > layerThick
std::vector< double > tileStep
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
std::vector< int > layers
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< int > tileN
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
Definition: vlib.h:198
static constexpr int kColumn_
Constants used.
std::vector< int > layerSense
void positionSensitive(DDLogicalPart &glog, DDCompactView &cpv)
const N & ddname() const
Definition: DDBase.h:61