CMS 3D CMS Logo

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