CMS 3D CMS Logo

DDHGCalModuleAlgo.cc
Go to the documentation of this file.
1 // File: DDHGCalModuleAlgo.cc
3 // Description: Geometry factory class for HGCal (EE and HESil)
5 
6 #include <algorithm>
7 #include <cmath>
8 #include <map>
9 #include <string>
10 #include <unordered_set>
11 #include <vector>
12 
28 
29 //#define EDM_ML_DEBUG
30 using namespace angle_units::operators;
31 
32 class DDHGCalModuleAlgo : public DDAlgorithm {
33 public:
34  // Constructor and Destructor
35  DDHGCalModuleAlgo(); // const std::string & name);
36 
37  void initialize(const DDNumericArguments& nArgs,
38  const DDVectorArguments& vArgs,
39  const DDMapArguments& mArgs,
40  const DDStringArguments& sArgs,
41  const DDStringVectorArguments& vsArgs) override;
42  void execute(DDCompactView& cpv) override;
43 
44 protected:
45  void constructLayers(const DDLogicalPart&, DDCompactView& cpv);
46  double rMax(double z);
47  void positionSensitive(DDLogicalPart& glog, double rin, double rout, DDCompactView& cpv);
48 
49 private:
50  static constexpr double tol_ = 0.00001;
51 
52  std::vector<std::string> wafer_; // Wafers
53  std::vector<std::string> materials_; // Materials
54  std::vector<std::string> names_; // Names
55  std::vector<double> thick_; // Thickness of the material
56  std::vector<int> copyNumber_; // Initial copy numbers
57  std::vector<int> layers_; // Number of layers in a section
58  std::vector<double> layerThick_; // Thickness of each section
59  std::vector<int> layerType_; // Type of the layer
60  std::vector<int> layerSense_; // COntent of a layer (sensitive?)
61  double zMinBlock_; // Starting z-value of the block
62  double rMaxFine_; // Maximum r-value for fine wafer
63  double waferW_; // Width of the wafer
64  double waferGap_; // Gap between 2 wafers
65  int sectors_; // Sectors
66  std::vector<double> slopeB_; // Slope at the lower R
67  std::vector<double> slopeT_; // Slopes at the larger R
68  std::vector<double> zFront_; // Starting Z values for the slopes
69  std::vector<double> rMaxFront_; // Corresponding rMax's
70  std::string idNameSpace_; // Namespace of this and ALL sub-parts
71  std::unordered_set<int> copies_; // List of copy #'s
72 };
73 
75 #ifdef EDM_ML_DEBUG
76  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: Creating an instance";
77 #endif
78 }
79 
81  const DDVectorArguments& vArgs,
82  const DDMapArguments&,
83  const DDStringArguments& sArgs,
84  const DDStringVectorArguments& vsArgs) {
85  wafer_ = vsArgs["WaferName"];
86 #ifdef EDM_ML_DEBUG
87  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: " << wafer_.size() << " wafers";
88  for (unsigned int i = 0; i < wafer_.size(); ++i)
89  edm::LogVerbatim("HGCalGeom") << "Wafer[" << i << "] " << wafer_[i];
90 #endif
91  materials_ = vsArgs["MaterialNames"];
92  names_ = vsArgs["VolumeNames"];
93  thick_ = vArgs["Thickness"];
94  copyNumber_.resize(materials_.size(), 1);
95 #ifdef EDM_ML_DEBUG
96  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: " << materials_.size() << " types of volumes";
97  for (unsigned int i = 0; i < names_.size(); ++i)
98  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names_[i] << " of thickness " << thick_[i]
99  << " filled with " << materials_[i] << " first copy number " << copyNumber_[i];
100 #endif
101  layers_ = dbl_to_int(vArgs["Layers"]);
102  layerThick_ = vArgs["LayerThick"];
103 #ifdef EDM_ML_DEBUG
104  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: " << layers_.size() << " blocks";
105  for (unsigned int i = 0; i < layers_.size(); ++i)
106  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << layerThick_[i] << " with " << layers_[i]
107  << " layers";
108 #endif
109  layerType_ = dbl_to_int(vArgs["LayerType"]);
110  layerSense_ = dbl_to_int(vArgs["LayerSense"]);
111 #ifdef EDM_ML_DEBUG
112  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: " << layerType_.size() << " layers";
113  for (unsigned int i = 0; i < layerType_.size(); ++i)
114  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType_[i] << " sensitive class "
115  << layerSense_[i];
116 #endif
117  zMinBlock_ = nArgs["zMinBlock"];
118  rMaxFine_ = nArgs["rMaxFine"];
119  waferW_ = nArgs["waferW"];
120  waferGap_ = nArgs["waferGap"];
121  sectors_ = (int)(nArgs["Sectors"]);
122 #ifdef EDM_ML_DEBUG
123  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: zStart " << zMinBlock_ << " rFineCoarse " << rMaxFine_
124  << " wafer width " << waferW_ << " gap among wafers " << waferGap_ << " sectors "
125  << sectors_;
126 #endif
127  slopeB_ = vArgs["SlopeBottom"];
128  slopeT_ = vArgs["SlopeTop"];
129  zFront_ = vArgs["ZFront"];
130  rMaxFront_ = vArgs["RMaxFront"];
131 #ifdef EDM_ML_DEBUG
132  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: Bottom slopes " << slopeB_[0] << ":" << slopeB_[1] << " and "
133  << slopeT_.size() << " slopes for top";
134  for (unsigned int i = 0; i < slopeT_.size(); ++i)
135  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] Zmin " << zFront_[i] << " Rmax " << rMaxFront_[i] << " Slope "
136  << slopeT_[i];
137 #endif
138  idNameSpace_ = DDCurrentNamespace::ns();
139 #ifdef EDM_ML_DEBUG
140  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: NameSpace " << idNameSpace_;
141 #endif
142 }
143 
145 // DDHGCalModuleAlgo methods...
147 
149 #ifdef EDM_ML_DEBUG
150  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalModuleAlgo...";
151 #endif
152  copies_.clear();
153  constructLayers(parent(), cpv);
154 #ifdef EDM_ML_DEBUG
155  edm::LogVerbatim("HGCalGeom") << copies_.size() << " different wafer copy numbers";
156 #endif
157  copies_.clear();
158 #ifdef EDM_ML_DEBUG
159  edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalModuleAlgo construction";
160 #endif
161 }
162 
164 #ifdef EDM_ML_DEBUG
165  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: \t\tInside Layers";
166 #endif
167  double zi(zMinBlock_);
168  int laymin(0);
169  const double tol(0.01);
170  for (unsigned int i = 0; i < layers_.size(); i++) {
171  double zo = zi + layerThick_[i];
172  double routF = rMax(zi);
173  int laymax = laymin + layers_[i];
174  double zz = zi;
175  double thickTot(0);
176  for (int ly = laymin; ly < laymax; ++ly) {
177  int ii = layerType_[ly];
178  int copy = copyNumber_[ii];
179  double rinB = (layerSense_[ly] == 0) ? (zo * slopeB_[0]) : (zo * slopeB_[1]);
180  zz += (0.5 * thick_[ii]);
181  thickTot += thick_[ii];
182 
183  std::string name = "HGCal" + names_[ii] + std::to_string(copy);
184 #ifdef EDM_ML_DEBUG
185  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: Layer " << ly << ":" << ii << " Front " << zi << ", "
186  << routF << " Back " << zo << ", " << rinB << " superlayer thickness "
187  << layerThick_[i];
188 #endif
189  DDName matName(DDSplit(materials_[ii]).first, DDSplit(materials_[ii]).second);
190  DDMaterial matter(matName);
191  DDLogicalPart glog;
192  if (layerSense_[ly] == 0) {
193  double alpha = 1._pi / sectors_;
194  double rmax = routF * cos(alpha) - tol;
195  std::vector<double> pgonZ, pgonRin, pgonRout;
196  pgonZ.emplace_back(-0.5 * thick_[ii]);
197  pgonZ.emplace_back(0.5 * thick_[ii]);
198  pgonRin.emplace_back(rinB);
199  pgonRin.emplace_back(rinB);
200  pgonRout.emplace_back(rmax);
201  pgonRout.emplace_back(rmax);
202  DDSolid solid =
203  DDSolidFactory::polyhedra(DDName(name, idNameSpace_), sectors_, -alpha, 2._pi, pgonZ, pgonRin, pgonRout);
204  glog = DDLogicalPart(solid.ddname(), matter, solid);
205 #ifdef EDM_ML_DEBUG
206  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: " << solid.name() << " polyhedra of " << sectors_
207  << " sectors covering " << convertRadToDeg(-alpha) << ":"
208  << (360.0 + convertRadToDeg(-alpha)) << " with " << pgonZ.size() << " sections";
209  for (unsigned int k = 0; k < pgonZ.size(); ++k)
210  edm::LogVerbatim("HGCalGeom") << "[" << k << "] z " << pgonZ[k] << " R " << pgonRin[k] << ":" << pgonRout[k];
211 #endif
212  } else {
213  DDSolid solid = DDSolidFactory::tubs(DDName(name, idNameSpace_), 0.5 * thick_[ii], rinB, routF, 0.0, 2._pi);
214  glog = DDLogicalPart(solid.ddname(), matter, solid);
215 #ifdef EDM_ML_DEBUG
216  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: " << solid.name() << " Tubs made of " << matName
217  << " of dimensions " << rinB << ", " << routF << ", " << 0.5 * thick_[ii]
218  << ", 0.0, 360.0";
219 #endif
220  positionSensitive(glog, rinB, routF, cpv);
221  }
222  DDTranslation r1(0, 0, zz);
223  DDRotation rot;
224  cpv.position(glog, module, copy, r1, rot);
225  ++copyNumber_[ii];
226 #ifdef EDM_ML_DEBUG
227  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: " << glog.name() << " number " << copy << " positioned in "
228  << module.name() << " at " << r1 << " with " << rot;
229 #endif
230  zz += (0.5 * thick_[ii]);
231  } // End of loop over layers in a block
232  zi = zo;
233  laymin = laymax;
234  if (fabs(thickTot - layerThick_[i]) > tol_) {
235  if (thickTot > layerThick_[i]) {
236  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " is smaller than thickness "
237  << thickTot << " of all its components **** ERROR ****\n";
238  } else {
239  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " does not match with "
240  << thickTot << " of the components\n";
241  }
242  }
243  } // End of loop over blocks
244 }
245 
246 double DDHGCalModuleAlgo::rMax(double z) {
247  double r(0);
248 #ifdef EDM_ML_DEBUG
249  unsigned int ik(0);
250 #endif
251  for (unsigned int k = 0; k < slopeT_.size(); ++k) {
252  if (z < zFront_[k])
253  break;
254  r = rMaxFront_[k] + (z - zFront_[k]) * slopeT_[k];
255 #ifdef EDM_ML_DEBUG
256  ik = k;
257 #endif
258  }
259 #ifdef EDM_ML_DEBUG
260  edm::LogVerbatim("HGCalGeom") << "rMax : " << z << ":" << ik << ":" << r;
261 #endif
262  return r;
263 }
264 
265 void DDHGCalModuleAlgo::positionSensitive(DDLogicalPart& glog, double rin, double rout, DDCompactView& cpv) {
266  double ww = (waferW_ + waferGap_);
267  double dx = 0.5 * ww;
268  double dy = 3.0 * dx * tan(30._deg);
269  double rr = 2.0 * dx * tan(30._deg);
270  int ncol = (int)(2.0 * rout / ww) + 1;
271  int nrow = (int)(rout / (ww * tan(30._deg))) + 1;
272  int incm(0), inrm(0), kount(0);
273 #ifdef EDM_ML_DEBUG
274  edm::LogVerbatim("HGCalGeom") << glog.ddname() << " rout " << rout << " Row " << nrow << " Column " << ncol;
275 #endif
276  for (int nr = -nrow; nr <= nrow; ++nr) {
277  int inr = (nr >= 0) ? nr : -nr;
278  for (int nc = -ncol; nc <= ncol; ++nc) {
279  int inc = (nc >= 0) ? nc : -nc;
280  if (inr % 2 == inc % 2) {
281  double xpos = nc * dx;
282  double ypos = nr * dy;
283  auto const& corner = HGCalGeomTools::waferCorner(xpos, ypos, dx, rr, rin, rout, true);
284  if (corner.first == (int)(HGCalParameters::k_CornerSize)) {
285  double rpos = std::sqrt(xpos * xpos + ypos * ypos);
286  DDTranslation tran(xpos, ypos, 0.0);
288  int copy = HGCalTypes::packTypeUV(0, nc, nr);
289  DDName name = (rpos < rMaxFine_) ? DDName(DDSplit(wafer_[0]).first, DDSplit(wafer_[0]).second)
290  : DDName(DDSplit(wafer_[1]).first, DDSplit(wafer_[1]).second);
291  cpv.position(name, glog.ddname(), copy, tran, rotation);
292  if (inc > incm)
293  incm = inc;
294  if (inr > inrm)
295  inrm = inr;
296  kount++;
297  if (copies_.count(copy) == 0)
298  copies_.insert(copy);
299 #ifdef EDM_ML_DEBUG
300  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: " << name << " number " << copy << " positioned in "
301  << glog.ddname() << " at " << tran << " with " << rotation;
302 #endif
303  }
304  }
305  }
306  }
307 #ifdef EDM_ML_DEBUG
308  edm::LogVerbatim("HGCalGeom") << "DDHGCalModuleAlgo: # of columns " << incm << " # of rows " << inrm << " and "
309  << kount << " wafers for " << glog.ddname();
310 #endif
311 }
312 
313 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalModuleAlgo, "hgcal:DDHGCalModuleAlgo");
Log< level::Info, true > LogVerbatim
static AlgebraicMatrix initialize()
std::vector< double > slopeB_
float alpha
Definition: AMPTWrapper.h:105
void positionSensitive(DDLogicalPart &glog, double rin, double rout, DDCompactView &cpv)
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
std::vector< double > rMaxFront_
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
std::vector< std::string > names_
std::vector< double > thick_
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
std::string to_string(const V &value)
Definition: OMSAccess.h:77
static std::string & ns()
Log< level::Error, false > LogError
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
static constexpr uint32_t k_CornerSize
std::vector< std::string > materials_
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
std::vector< double > zFront_
static std::pair< int32_t, int32_t > waferCorner(double xpos, double ypos, double r, double R, double rMin, double rMax, bool oldBug=false)
void execute(DDCompactView &cpv) override
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
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)
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
static DDSolid tubs(const DDName &name, double zhalf, double rIn, double rOut, double startPhi, double deltaPhi)
Definition: DDSolid.cc:667
std::string idNameSpace_
ii
Definition: cuy.py:589
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
const N & name() const
Definition: DDBase.h:59
std::vector< double > layerThick_
const N & ddname() const
Definition: DDBase.h:61
std::vector< double > slopeT_
std::vector< int > layers_
std::vector< int > layerSense_
static int32_t packTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:3
#define DEFINE_EDM_PLUGIN(factory, type, name)
Log< level::Warning, false > LogWarning
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
std::vector< std::string > wafer_
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
static DDSolid polyhedra(const DDName &name, int sides, double startPhi, double deltaPhi, const std::vector< double > &z, const std::vector< double > &rmin, const std::vector< double > &rmax)
Creates a polyhedra (refere to Geant3 or Geant4 documentation)
Definition: DDSolid.cc:565
std::vector< int > layerType_
std::unordered_set< int > copies_
void constructLayers(const DDLogicalPart &, DDCompactView &cpv)
double rMax(double z)
std::vector< int > copyNumber_