CMS 3D CMS Logo

DDHGCalWaferFullRotated.cc
Go to the documentation of this file.
1 // File: DDHGCalWaferFullRotated.cc
3 // Description: Geometry factory class for a full silicon Wafer
4 // Created by Sunanda Banerjee, Pruthvi Suryadevara, Indranil Das
19 
20 #include <string>
21 #include <vector>
22 #include <sstream>
23 
24 //#define EDM_ML_DEBUG
25 
26 class DDHGCalWaferFullRotated : public DDAlgorithm {
27 public:
28  // Constructor and Destructor
30  ~DDHGCalWaferFullRotated() override = default;
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 private:
40  std::string material_; // Material name for module with gap
41  std::string waferTag_; // Tag for type pf wafer
42  double thick_; // Module thickness
43  double waferSize_; // Wafer size
44  double waferSepar_; // Sensor separation
45  double waferThick_; // Wafer thickness
46  std::vector<std::string> layerNames_; // Names of the layers
47  std::vector<std::string> materials_; // Materials of the layers
48  std::vector<std::string> tag_; // Tag of placement index
49  std::vector<double> layerThick_; // Thickness of layers
50  std::vector<int> layerType_; // Layer types
51  std::vector<int> copyNumber_; // Initial copy numbers
52  std::vector<int> layers_; // Number of layers in a section
53  std::vector<int> orient_; // Orientation of wafer
54  std::vector<int> face_; // Front or back of cooling layer
55  int nCells_; // Half number of cells along u-v axis
56  int cellType_; // Cell Type (0,1,2: Fine, Course 2/3)
57  std::vector<int> cellOffset_; // Offset of cells of each type
58  std::vector<std::string> cellNames_; // Name of the cells
59  std::string nameSpace_; // Namespace to be used
60 };
61 
63 #ifdef EDM_ML_DEBUG
64  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Creating an instance";
65 #endif
66 }
67 
69  const DDVectorArguments& vArgs,
70  const DDMapArguments&,
71  const DDStringArguments& sArgs,
72  const DDStringVectorArguments& vsArgs) {
73  material_ = sArgs["ModuleMaterial"];
74  thick_ = nArgs["ModuleThickness"];
75  waferSize_ = nArgs["WaferSize"];
76  waferSepar_ = nArgs["SensorSeparation"];
77  waferThick_ = nArgs["WaferThickness"];
78  waferTag_ = sArgs["WaferTag"];
79 #ifdef EDM_ML_DEBUG
80  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Module " << parent().name() << " made of " << material_
81  << " T " << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_
82  << " T " << waferThick_;
83 #endif
84  orient_ = dbl_to_int(vArgs["WaferOrient"]);
85  face_ = dbl_to_int(vArgs["WaferFace"]);
86  tag_ = vsArgs["WaferPlacementIndex"];
87  layerNames_ = vsArgs["LayerNames"];
88  materials_ = vsArgs["LayerMaterials"];
89  layerThick_ = vArgs["LayerThickness"];
90  layerType_ = dbl_to_int(vArgs["LayerTypes"]);
91  copyNumber_.resize(materials_.size(), 1);
92 #ifdef EDM_ML_DEBUG
93  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << layerNames_.size() << " types of volumes";
94  for (unsigned int i = 0; i < layerNames_.size(); ++i)
95  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
96  << " filled with " << materials_[i] << " type " << layerType_[i];
97 #endif
98  layers_ = dbl_to_int(vArgs["Layers"]);
99 #ifdef EDM_ML_DEBUG
100  std::ostringstream st1;
101  for (unsigned int i = 0; i < layers_.size(); ++i)
102  st1 << " [" << i << "] " << layers_[i];
103  edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks" << st1.str();
104 #endif
105  nCells_ = static_cast<int>(nArgs["NCells"]);
106  if (nCells_ > 0) {
107  cellType_ = static_cast<int>(nArgs["CellType"]);
108  cellNames_ = vsArgs["CellNames"];
109  cellOffset_ = dbl_to_int(vArgs["CellOffset"]);
110  } else {
111  cellType_ = -1;
112  }
114 #ifdef EDM_ML_DEBUG
115  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cells/Wafer " << nCells_ << " Cell Type " << cellType_
116  << " NameSpace " << nameSpace_ << ": # of cells " << cellNames_.size();
117  std::ostringstream st2;
118  for (unsigned int i = 0; i < cellOffset_.size(); ++i)
119  st2 << " [" << i << "] " << cellOffset_[i];
120  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << cellOffset_.size() << " types of cells with offsets "
121  << st2.str();
122  for (unsigned int k = 0; k < cellNames_.size(); ++k)
123  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cell[" << k << "] " << cellNames_[k];
124 #endif
125 }
126 
128 #ifdef EDM_ML_DEBUG
129  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferFullRotated...";
130 #endif
131 
132  static constexpr double tol = 0.00001;
133  static const double sqrt3 = std::sqrt(3.0);
134  double rM = 0.5 * waferSize_;
135  double RM2 = rM / sqrt3;
136  double r2 = 0.5 * waferSize_;
137  double R2 = r2 / sqrt3;
138  const int nFine(nCells_), nCoarse(nCells_);
139  HGCalCell wafer((waferSize_ + waferSepar_), nFine, nCoarse);
140  for (unsigned int k = 0; k < tag_.size(); ++k) {
141  // First the mother
142  std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
143  std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
144  std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
145  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
146  std::string parentName = parent().name().name();
147  parentName = parentName + tag_[k] + waferTag_;
148  DDSolid solid = DDSolidFactory::extrudedpolygon(parentName, xM, yM, zw, zx, zy, scale);
150  DDMaterial matter(matName);
151  DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
152 #ifdef EDM_ML_DEBUG
153  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
154  << matName << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
155  << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
156  << scale[1] << " and " << xM.size() << " edges";
157  for (unsigned int kk = 0; kk < xM.size(); ++kk)
158  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
159 #endif
160 
161  // Then the layers
162  std::vector<double> xL = {r2, 0, -r2, -r2, 0, r2};
163  std::vector<double> yL = {R2, 2 * R2, R2, -R2, -2 * R2, -R2};
164  std::vector<DDLogicalPart> glogs(materials_.size());
165  for (unsigned int ii = 0; ii < copyNumber_.size(); ii++) {
166  copyNumber_[ii] = 1;
167  }
168  double zi(-0.5 * thick_), thickTot(0.0);
169  for (unsigned int l = 0; l < layers_.size(); l++) {
170  unsigned int i = layers_[l];
171  if (copyNumber_[i] == 1) {
172  if (layerType_[i] > 0) {
173  zw[0] = -0.5 * waferThick_;
174  zw[1] = 0.5 * waferThick_;
175  } else {
176  zw[0] = -0.5 * layerThick_[i];
177  zw[1] = 0.5 * layerThick_[i];
178  }
180  solid = DDSolidFactory::extrudedpolygon(layerName, xL, yL, zw, zx, zy, scale);
182  DDMaterial matter(matN);
183  glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
184 
185 #ifdef EDM_ML_DEBUG
186  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
187  << matN << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
188  << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
189  << scale[1] << " and " << xL.size() << " edges";
190  for (unsigned int kk = 0; kk < xL.size(); ++kk)
191  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xL[kk] << ":" << yL[kk];
192 #endif
193  }
194  DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
195  DDRotation rot;
196  cpv.position(glogs[i], glogM, copyNumber_[i], tran0, rot);
197 #ifdef EDM_ML_DEBUG
198  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << glogs[i].name() << " number " << copyNumber_[i]
199  << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
200 #endif
201  ++copyNumber_[i];
202  zi += layerThick_[i];
203  thickTot += layerThick_[i];
204  if ((layerType_[i] > 0) && (nCells_ > 0)) {
205  for (int u = 0; u < 2 * nCells_; ++u) {
206  for (int v = 0; v < 2 * nCells_; ++v) {
207  if (((v - u) < nCells_) && ((u - v) <= nCells_)) {
208  int placeIndex = wafer.cellPlacementIndex(1, HGCalTypes::waferFrontBack(face_[k]), orient_[k]);
209  std::pair<double, double> xy1 = wafer.cellUV2XY1(u, v, placeIndex, cellType_);
210  double yp = xy1.second;
211  double xp = xy1.first;
212  int cell(0);
213  std::pair<int, int> cell1 = wafer.cellUV2Cell(u, v, placeIndex, cellType_);
214  cell = cell1.first + cellOffset_[cell1.second];
215  DDTranslation tran(xp, yp, 0);
217  cpv.position(DDName(cellNames_[cell]), glogs[i], copy, tran, rot);
218 #ifdef EDM_ML_DEBUG
219  edm::LogVerbatim("HGCalGeom")
220  << "DDHGCalWaferFullRotated: " << cellNames_[cell] << " number " << copy << " positioned in "
221  << glogs[i].name() << " at " << tran << " with no rotation";
222 #endif
223  }
224  }
225  }
226  }
227  }
228  if (std::abs(thickTot - thick_) >= tol) {
229  if (thickTot > thick_) {
230  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
231  << ": thickness of all its components **** ERROR ****";
232  } else {
233  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
234  << " of the components";
235  }
236  }
237  }
238 }
239 
240 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferFullRotated, "hgcal:DDHGCalWaferFullRotated");
Log< level::Info, true > LogVerbatim
void execute(DDCompactView &cpv) override
static int32_t cellPlacementIndex(int32_t iz, int32_t frontBack, int32_t orient)
Definition: HGCalCell.cc:230
static int32_t packCellTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:28
constexpr char const * layerName[numberOfLayers]
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
~DDHGCalWaferFullRotated() override=default
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
static std::string & ns()
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
Log< level::Error, false > LogError
std::pair< int32_t, int32_t > cellUV2Cell(int32_t u, int32_t v, int32_t placementIndex, int32_t type)
Definition: HGCalCell.cc:94
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
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)
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< double > layerThick_
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
static int32_t waferFrontBack(int32_t index)
Definition: HGCalTypes.h:126
std::vector< std::string > cellNames_
std::vector< std::string > tag_
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::pair< double, double > cellUV2XY1(int32_t u, int32_t v, int32_t placementIndex, int32_t type)
Definition: HGCalCell.cc:13
static DDSolid extrudedpolygon(const DDName &name, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &zx, const std::vector< double > &zy, const std::vector< double > &zscale)
Definition: DDSolid.cc:584
const N & ddname() const
Definition: DDBase.h:61
std::vector< std::string > materials_
std::vector< std::string > layerNames_
auto zw(V v) -> Vec2< typename std::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:75
#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
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7