CMS 3D CMS Logo

DDHGCalWaferF.cc
Go to the documentation of this file.
1 // File: DDHGCalWaferF.cc
3 // Description: Geometry factory class for a full silicon Wafer
4 // Created by Sunanda Banerjee
5 // Extended for rotated wafer by Pruthvi Suryadevara
19 
20 #include <string>
21 #include <vector>
22 #include <sstream>
23 
24 //#define EDM_ML_DEBUG
25 
26 class DDHGCalWaferF : public DDAlgorithm {
27 public:
28  // Constructor and Destructor
29  DDHGCalWaferF();
30  ~DDHGCalWaferF() 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 private:
40  std::string material_; // Material name for module with gap
41  double thick_; // Module thickness
42  double waferSize_; // Wafer size
43  double waferSepar_; // Sensor separation
44  double waferThick_; // Wafer thickness
45  std::vector<std::string> layerNames_; // Names of the layers
46  std::vector<std::string> materials_; // Materials of the layers
47  std::vector<double> layerThick_; // Thickness of layers
48  std::vector<int> layerType_; // Layer types
49  std::vector<int> copyNumber_; // Initial copy numbers
50  std::vector<int> layers_; // Number of layers in a section
51  int nCells_; // Half number of cells along u-v axis
52  int cellType_; // Cell Type (0,1,2: Fine, Course 2/3)
53  std::vector<std::string> cellNames_; // Name of the cells
54  std::string nameSpace_; // Namespace to be used
55 };
56 
58 #ifdef EDM_ML_DEBUG
59  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Creating an instance";
60 #endif
61 }
62 
64 
66  const DDVectorArguments& vArgs,
67  const DDMapArguments&,
68  const DDStringArguments& sArgs,
69  const DDStringVectorArguments& vsArgs) {
70  material_ = sArgs["ModuleMaterial"];
71  thick_ = nArgs["ModuleThickness"];
72  waferSize_ = nArgs["WaferSize"];
73  waferSepar_ = nArgs["SensorSeparation"];
74  waferThick_ = nArgs["WaferThickness"];
75 #ifdef EDM_ML_DEBUG
76  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Module " << parent().name() << " made of " << material_ << " T "
77  << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_ << " T "
78  << waferThick_;
79 #endif
80  layerNames_ = vsArgs["LayerNames"];
81  materials_ = vsArgs["LayerMaterials"];
82  layerThick_ = vArgs["LayerThickness"];
83  layerType_ = dbl_to_int(vArgs["LayerTypes"]);
84  copyNumber_.resize(materials_.size(), 1);
85 #ifdef EDM_ML_DEBUG
86  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << layerNames_.size() << " types of volumes";
87  for (unsigned int i = 0; i < layerNames_.size(); ++i)
88  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
89  << " filled with " << materials_[i] << " type " << layerType_[i];
90 #endif
91  layers_ = dbl_to_int(vArgs["Layers"]);
92 #ifdef EDM_ML_DEBUG
93  std::ostringstream st1;
94  for (unsigned int i = 0; i < layers_.size(); ++i)
95  st1 << " [" << i << "] " << layers_[i];
96  edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks" << st1.str();
97 #endif
98  nCells_ = (int)(nArgs["NCells"]);
99  cellType_ = (int)(nArgs["CellType"]);
100  cellNames_ = vsArgs["CellNames"];
102 #ifdef EDM_ML_DEBUG
103  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Cells/Wafer " << nCells_ << " Cell Type " << cellType_
104  << " NameSpace " << nameSpace_ << " # of cells " << cellNames_.size();
105  for (unsigned int k = 0; k < cellNames_.size(); ++k)
106  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Cell[" << k << "] " << cellNames_[k];
107 #endif
108 }
109 
111 #ifdef EDM_ML_DEBUG
112  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferF...";
113 #endif
114 
115  static constexpr double tol = 0.00001;
116  static const double sqrt3 = std::sqrt(3.0);
117  double rM = 0.5 * waferSize_;
118  double RM2 = rM / sqrt3;
119  double R = waferSize_ / (3.0 * nCells_);
120  double r = 0.5 * R * sqrt3;
121  double r2 = 0.5 * waferSize_;
122  double R2 = r2 / sqrt3;
123 
124  // First the mother
125  std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
126  std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
127  std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
128  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
129  DDName parentName = parent().name();
130  DDSolid solid = DDSolidFactory::extrudedpolygon(parentName, xM, yM, zw, zx, zy, scale);
132  DDMaterial matter(matName);
133  DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
134 #ifdef EDM_ML_DEBUG
135  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << solid.name() << " extruded polygon made of " << matName
136  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
137  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
138  << " and " << xM.size() << " edges";
139  for (unsigned int k = 0; k < xM.size(); ++k)
140  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xM[k] << ":" << yM[k];
141 #endif
142 
143  // Then the layers
144  std::vector<double> xL = {r2, 0, -r2, -r2, 0, r2};
145  std::vector<double> yL = {R2, 2 * R2, R2, -R2, -2 * R2, -R2};
146  std::vector<DDLogicalPart> glogs(materials_.size());
147  double zi(-0.5 * thick_), thickTot(0.0);
148  for (unsigned int l = 0; l < layers_.size(); l++) {
149  unsigned int i = layers_[l];
150  if (copyNumber_[i] == 1) {
151  if (layerType_[i] > 0) {
152  zw[0] = -0.5 * waferThick_;
153  zw[1] = 0.5 * waferThick_;
154  } else {
155  zw[0] = -0.5 * layerThick_[i];
156  zw[1] = 0.5 * layerThick_[i];
157  }
158  solid = DDSolidFactory::extrudedpolygon(layerNames_[i], xL, yL, zw, zx, zy, scale);
160  DDMaterial matter(matN);
161  glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
162 #ifdef EDM_ML_DEBUG
163  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << solid.name() << " extruded polygon made of " << matN
164  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
165  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
166  << " and " << xL.size() << " edges";
167  for (unsigned int k = 0; k < xL.size(); ++k)
168  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xL[k] << ":" << yL[k];
169 #endif
170  }
171  DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
172  DDRotation rot;
173  cpv.position(glogs[i], glogM, copyNumber_[i], tran0, rot);
174 #ifdef EDM_ML_DEBUG
175  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << glogs[i].name() << " number " << copyNumber_[i]
176  << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
177 #endif
178  ++copyNumber_[i];
179  zi += layerThick_[i];
180  thickTot += layerThick_[i];
181  if (layerType_[i] > 0) {
182  int n2 = nCells_ / 2;
183  double y0 = (cellType_ >= 3) ? 0.5 : 0.0;
184  double x0 = (cellType_ >= 3) ? 0.5 : 1.0;
185  int voff = (cellType_ >= 3) ? 0 : 1;
186  int uoff = 1 - voff;
187  int cellType = (cellType_ >= 3) ? (cellType_ - 3) : cellType_;
188  for (int u = 0; u < 2 * nCells_; ++u) {
189  for (int v = 0; v < 2 * nCells_; ++v) {
190  if (((v - u) < (nCells_ + uoff)) && (u - v) < (nCells_ + voff)) {
191  double yp = (u - 0.5 * v - n2 + y0) * 2 * r;
192  double xp = (1.5 * (v - nCells_) + x0) * R;
193  int cell(0);
194  if ((u == 0) && (v == 0))
195  cell = 7;
196  else if ((u == 0) && (v == nCells_ - voff))
197  cell = 8;
198  else if ((u == nCells_ - uoff) && (v == 2 * nCells_ - 1))
199  cell = 9;
200  else if ((u == (2 * nCells_ - 1)) && (v == 2 * nCells_ - 1))
201  cell = 10;
202  else if ((u == 2 * nCells_ - 1) && (v == (nCells_ - voff)))
203  cell = 11;
204  else if ((u == (nCells_ - uoff)) && (v == 0))
205  cell = 12;
206  else if (u == 0)
207  cell = 1;
208  else if ((v - u) == (nCells_ - voff))
209  cell = 4;
210  else if (v == (2 * nCells_ - 1))
211  cell = 2;
212  else if (u == (2 * nCells_ - 1))
213  cell = 5;
214  else if ((u - v) == (nCells_ - uoff))
215  cell = 3;
216  else if (v == 0)
217  cell = 6;
218  if ((cellType_ >= 3) && (cell != 0))
219  cell += 12;
220  DDTranslation tran(xp, yp, 0);
221  int copy = HGCalTypes::packCellTypeUV(cellType, u, v);
222  cpv.position(DDName(cellNames_[cell]), glogs[i], copy, tran, rot);
223 #ifdef EDM_ML_DEBUG
224  edm::LogVerbatim("HGCalGeom")
225  << "DDHGCalWaferF: " << cellNames_[cell] << " number " << copy << " positioned in " << glogs[i].name()
226  << " at " << tran << " with no rotation";
227 #endif
228  }
229  }
230  }
231  }
232  }
233  if (std::abs(thickTot - thick_) >= tol) {
234  if (thickTot > thick_) {
235  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
236  << ": thickness of all its components **** ERROR ****";
237  } else {
238  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
239  << " of the components";
240  }
241  }
242 }
243 
244 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferF, "hgcal:DDHGCalWaferF");
Log< level::Info, true > LogVerbatim
static int32_t packCellTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:28
void execute(DDCompactView &cpv) override
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
std::vector< int > layerType_
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
~DDHGCalWaferF() override
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
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
double waferThick_
std::vector< double > layerThick_
double waferSepar_
std::vector< int > layers_
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< std::string > materials_
std::vector< std::string > cellNames_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
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::string nameSpace_
const N & name() const
Definition: DDBase.h:59
std::vector< int > copyNumber_
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 > 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::string material_
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