CMS 3D CMS Logo

DDHGCalCell.cc
Go to the documentation of this file.
12 
13 #include <string>
14 #include <vector>
15 
16 //#define EDM_ML_DEBUG
17 
18 class DDHGCalCell : public DDAlgorithm {
19 public:
20  // Constructor and Destructor
22 
23  void initialize(const DDNumericArguments& nArgs,
24  const DDVectorArguments& vArgs,
25  const DDMapArguments& mArgs,
26  const DDStringArguments& sArgs,
27  const DDStringVectorArguments& vsArgs) override;
28  void execute(DDCompactView& cpv) override;
29 
30 private:
31  double waferSize_; // Wafer Size
32  double waferSeparation_; // Wafer Saperation
33  int addWaferSeparation_; // Use wafer separation
34  double waferT_; // Wafer Thickness
35  double cellT_; // Cell Thickness
36  int nCells_; // Number of columns (8:12)
37  int posSens_; // Position depleted layer
38  std::string material_; // Name of the material
39  std::string fullCN_, fullSensN_; // Name of full cell
40  std::vector<std::string> truncCN_, truncSensN_; // Names of truncated cells
41  std::vector<std::string> extenCN_, extenSensN_; // Names of extended cells
42  std::vector<std::string> cornrCN_, cornrSensN_; // Names of corner cells
43  std::string nameSpace_; // Namespace to be used
44 };
45 
47  const DDVectorArguments&,
48  const DDMapArguments&,
49  const DDStringArguments& sArgs,
50  const DDStringVectorArguments& vsArgs) {
51  waferSize_ = nArgs["WaferSize"];
52  waferSeparation_ = nArgs["WaferSeparation"];
53  addWaferSeparation_ = static_cast<int>(nArgs["AddWaferSeparation"]);
54  waferT_ = nArgs["WaferThick"];
55  cellT_ = nArgs["CellThick"];
56  nCells_ = (int)(nArgs["NCells"]);
57  posSens_ = (int)(nArgs["PosSensitive"]);
58  material_ = sArgs["Material"];
59  fullCN_ = sArgs["FullCell"];
60  fullSensN_ = sArgs["FullSensitive"];
61  truncCN_ = vsArgs["TruncatedCell"];
62  truncSensN_ = vsArgs["TruncatedSensitive"];
63  extenCN_ = vsArgs["ExtendedCell"];
64  extenSensN_ = vsArgs["ExtendedSensitive"];
65  cornrCN_ = vsArgs["CornerCell"];
66  cornrSensN_ = vsArgs["CornerSensitive"];
68  if ((truncCN_.size() != truncSensN_.size()) || (extenCN_.size() != extenSensN_.size()) ||
69  (cornrCN_.size() != cornrSensN_.size()))
70  edm::LogWarning("HGCalGeom") << "The number of cells & sensitive differ:"
71  << " Truncated " << truncCN_.size() << ":" << truncSensN_.size() << " Extended "
72  << extenCN_.size() << ":" << extenSensN_.size() << " Corners " << cornrCN_.size()
73  << ":" << cornrSensN_.size();
74 #ifdef EDM_ML_DEBUG
75  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Wafer r " << waferSize_ << " T " << waferT_ << " Cell T " << cellT_
76  << " Cells/Wafer " << nCells_ << " Material " << material_ << "Sensitive Position "
77  << posSens_ << " NameSpace " << nameSpace_ << ": Full Cell: " << fullCN_ << ":"
78  << fullSensN_ << " Separation " << waferSeparation_ << ":" << addWaferSeparation_;
79  for (unsigned int k = 0; k < truncCN_.size(); ++k)
80  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Truncated Cell[" << k << "] " << truncCN_[k] << ":"
81  << truncSensN_[k];
82  for (unsigned int k = 0; k < extenCN_.size(); ++k)
83  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Extended Cell[" << k << "] " << extenCN_[k] << ":" << extenSensN_[k];
84  for (unsigned int k = 0; k < cornrCN_.size(); ++k)
85  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Corner Cell[" << k << "] " << cornrCN_[k] << ":" << cornrSensN_[k];
86 #endif
87 }
88 
91  DDMaterial matter(matName);
92 #ifdef EDM_ML_DEBUG
93  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << matName << " initialized";
94 #endif
95  DDLogicalPart glog1, glog2;
96 
97  static const double sqrt3 = std::sqrt(3.0);
98  double R =
99  (addWaferSeparation_ <= 1) ? waferSize_ / (3.0 * nCells_) : (waferSize_ + waferSeparation_) / (3.0 * nCells_);
100  double r = 0.5 * R * sqrt3;
101  double dx1 = R;
102  double dx2 = 0.5 * dx1;
103  double dx3 = 2.5 * dx2;
104  double dx4 = 0.5 * dx2;
105  double dy1 = r;
106  double dy2 = 0.5 * dy1;
107  double dy3 = 1.5 * dy1;
108  std::vector<double> xx = {
109  dx1, dx2, -dx2, -dx1, -dx2, dx2, dx3, dx1, dx4, -dx4, -dx1, -dx3, -dx3, -dx1, -dx4, dx4, dx1, dx3};
110  std::vector<double> yy = {
111  0, dy1, dy1, 0, -dy1, -dy1, dy2, dy1, dy3, dy3, dy1, dy2, -dy2, -dy1, -dy3, -dy3, -dy1, -dy2};
112  double zpos = (posSens_ == 0) ? -0.5 * (waferT_ - cellT_) : 0.5 * (waferT_ - cellT_);
113  DDTranslation tran(0, 0, zpos);
114 
115  double dx5 = (addWaferSeparation_ == 0) ? 0.0 : waferSeparation_ * 0.5;
116  double dx6 = dx5 * 0.5;
117  double dx7 = dx5;
118  double dy4 = dx5 * 0.5 * sqrt3;
119  double dy5 = dx5 * 2 / sqrt3;
120  double dy6 = dy5 * 0.5;
121  std::vector<double> txx = {dx5, dx6, -dx6, -dx5, -dx6, dx6, dx7, 0, -dx7, -dx7, 0, dx7};
122  std::vector<double> tyy = {0, dy4, dy4, 0, -dy4, -dy4, dy6, dy5, dy6, -dy6, -dy5, -dy6};
123  // First the full cell
124  std::vector<double> xw = {xx[0], xx[1], xx[2], xx[3], xx[4], xx[5]};
125  std::vector<double> yw = {yy[0], yy[1], yy[2], yy[3], yy[4], yy[5]};
126  std::vector<double> zw = {-0.5 * waferT_, 0.5 * waferT_};
127  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
129  glog1 = DDLogicalPart(solid.ddname(), matter, solid);
130 #ifdef EDM_ML_DEBUG
131  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
132  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
133  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
134  << " and " << xw.size() << " edges";
135  for (unsigned int k = 0; k < xw.size(); ++k)
136  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
137 #endif
138  std::vector<double> zc = {-0.5 * cellT_, 0.5 * cellT_};
139  solid = DDSolidFactory::extrudedpolygon(DDName(fullSensN_, nameSpace_), xw, yw, zc, zx, zy, scale);
140  glog2 = DDLogicalPart(solid.ddname(), matter, solid);
141 #ifdef EDM_ML_DEBUG
142  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
143  << " z|x|y|s (0) " << zc[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
144  << " z|x|y|s (1) " << zc[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
145  << " and " << xw.size() << " edges";
146  for (unsigned int k = 0; k < xw.size(); ++k)
147  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
148 #endif
149  DDRotation rot;
150  cpv.position(glog2, glog1, 1, tran, rot);
151 #ifdef EDM_ML_DEBUG
152  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name() << " at "
153  << tran << " with no rotation";
154 #endif
155 
156  static constexpr int ir0[] = {0, 2, 4, 1, 3, 5};
157  static constexpr int ir1[] = {1, 3, 5, 2, 4, 0};
158  static constexpr int ir2[] = {2, 4, 0, 3, 5, 1};
159  static constexpr int ir3[] = {3, 5, 1, 4, 0, 2};
160  static constexpr int ir4[] = {5, 1, 3, 0, 2, 4};
161 
162  static constexpr int tr[] = {1, 3, 5, 2, 4, 0};
163  for (unsigned int i = 0; i < truncCN_.size(); ++i) {
164  std::vector<double> xw = {xx[ir0[i]], xx[ir1[i]], xx[ir2[i]], xx[ir3[i]] + txx[tr[i]], xx[ir4[i]] + txx[tr[i]]};
165  std::vector<double> yw = {yy[ir0[i]], yy[ir1[i]], yy[ir2[i]], yy[ir3[i]] + tyy[tr[i]], yy[ir4[i]] + tyy[tr[i]]};
166  solid = DDSolidFactory::extrudedpolygon(DDName(truncCN_[i], nameSpace_), xw, yw, zw, zx, zy, scale);
167  glog1 = DDLogicalPart(solid.ddname(), matter, solid);
168 #ifdef EDM_ML_DEBUG
169  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
170  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
171  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
172  << " and " << xw.size() << " edges";
173  for (unsigned int k = 0; k < xw.size(); ++k)
174  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
175 #endif
176  solid = DDSolidFactory::extrudedpolygon(DDName(truncSensN_[i], nameSpace_), xw, yw, zc, zx, zy, scale);
177  glog2 = DDLogicalPart(solid.ddname(), matter, solid);
178 #ifdef EDM_ML_DEBUG
179  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
180  << " z|x|y|s (0) " << zc[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
181  << " z|x|y|s (1) " << zc[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
182  << " and " << xw.size() << " edges";
183  for (unsigned int k = 0; k < xw.size(); ++k)
184  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
185 #endif
186  cpv.position(glog2, glog1, 1, tran, rot);
187 #ifdef EDM_ML_DEBUG
188  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
189  << " at " << tran << " with no rotation";
190 #endif
191  }
192 
193  static constexpr int ie0[] = {1, 3, 5, 0, 2, 4};
194  static constexpr int ie1[] = {2, 4, 0, 1, 3, 5};
195  static constexpr int ie2[] = {3, 5, 1, 2, 4, 0};
196  static constexpr int ie3[] = {14, 6, 10, 12, 16, 8};
197  static constexpr int ie4[] = {17, 9, 13, 15, 7, 11};
198 
199  static constexpr int te[] = {2, 4, 0, 1, 3, 5};
200  for (unsigned int i = 0; i < extenCN_.size(); ++i) {
201  std::vector<double> xw = {xx[ie0[i]], xx[ie1[i]], xx[ie2[i]], xx[ie3[i]] + txx[te[i]], xx[ie4[i]] + txx[te[i]]};
202  std::vector<double> yw = {yy[ie0[i]], yy[ie1[i]], yy[ie2[i]], yy[ie3[i]] + tyy[te[i]], yy[ie4[i]] + tyy[te[i]]};
203  solid = DDSolidFactory::extrudedpolygon(DDName(extenCN_[i], nameSpace_), xw, yw, zw, zx, zy, scale);
204  glog1 = DDLogicalPart(solid.ddname(), matter, solid);
205 #ifdef EDM_ML_DEBUG
206  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
207  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
208  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
209  << " and " << xw.size() << " edges";
210  for (unsigned int k = 0; k < xw.size(); ++k)
211  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
212 #endif
213  solid = DDSolidFactory::extrudedpolygon(DDName(extenSensN_[i], nameSpace_), xw, yw, zc, zx, zy, scale);
214  glog2 = DDLogicalPart(solid.ddname(), matter, solid);
215 #ifdef EDM_ML_DEBUG
216  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
217  << " z|x|y|s (0) " << zc[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
218  << " z|x|y|s (1) " << zc[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
219  << " and " << xw.size() << " edges";
220  for (unsigned int k = 0; k < xw.size(); ++k)
221  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
222 #endif
223  cpv.position(glog2, glog1, 1, tran, rot);
224 #ifdef EDM_ML_DEBUG
225  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
226  << " at " << tran << " with no rotation";
227 #endif
228  }
229 
230  static constexpr int ic0[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5};
231  static constexpr int ic1[] = {1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0};
232  static constexpr int ic2[] = {10, 3, 14, 5, 6, 1, 2, 12, 4, 16, 0, 8};
233  static constexpr int ic3[] = {3, 5, 5, 1, 1, 3, 4, 4, 0, 0, 2, 2};
234  static constexpr int ic4[] = {5, 17, 1, 9, 3, 13, 15, 0, 7, 2, 11, 4};
235 
236  static constexpr int tc[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5};
237  for (unsigned int i = 0; i < cornrCN_.size(); ++i) {
238  std::vector<double> xw = {
239  xx[ic0[i]], xx[ic1[i]], xx[ic2[i]] + txx[tc[i]], xx[ic3[i]] + txx[tc[i] + 6], xx[ic4[i]] + txx[(tc[i] + 1) % 6]};
240  std::vector<double> yw = {
241  yy[ic0[i]], yy[ic1[i]], yy[ic2[i]] + tyy[tc[i]], yy[ic3[i]] + tyy[tc[i] + 6], yy[ic4[i]] + tyy[(tc[i] + 1) % 6]};
242  solid = DDSolidFactory::extrudedpolygon(DDName(cornrCN_[i], nameSpace_), xw, yw, zw, zx, zy, scale);
243  glog1 = DDLogicalPart(solid.ddname(), matter, solid);
244 #ifdef EDM_ML_DEBUG
245  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
246  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
247  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
248  << " and " << xw.size() << " edges";
249  for (unsigned int k = 0; k < xw.size(); ++k)
250  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
251 #endif
252  solid = DDSolidFactory::extrudedpolygon(DDName(cornrSensN_[i], nameSpace_), xw, yw, zc, zx, zy, scale);
253  glog2 = DDLogicalPart(solid.ddname(), matter, solid);
254 #ifdef EDM_ML_DEBUG
255  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << matName
256  << " z|x|y|s (0) " << zc[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
257  << " z|x|y|s (1) " << zc[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
258  << " and " << xw.size() << " edges";
259  for (unsigned int k = 0; k < xw.size(); ++k)
260  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
261 #endif
262  cpv.position(glog2, glog1, 1, tran, rot);
263 #ifdef EDM_ML_DEBUG
264  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
265  << " at " << tran << " with no rotation";
266 #endif
267  }
268 }
269 
270 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalCell, "hgcal:DDHGCalCell");
Log< level::Info, true > LogVerbatim
double waferSeparation_
Definition: DDHGCalCell.cc:32
int addWaferSeparation_
Definition: DDHGCalCell.cc:33
std::string fullSensN_
Definition: DDHGCalCell.cc:39
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
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
Definition: DDHGCalCell.cc:46
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
static std::string & ns()
std::vector< std::string > truncCN_
Definition: DDHGCalCell.cc:40
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
std::vector< std::string > extenSensN_
Definition: DDHGCalCell.cc:41
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
void execute(DDCompactView &cpv) override
Definition: DDHGCalCell.cc:89
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
std::string nameSpace_
Definition: DDHGCalCell.cc:43
double cellT_
Definition: DDHGCalCell.cc:35
T sqrt(T t)
Definition: SSEVec.h:19
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
double waferSize_
Definition: DDHGCalCell.cc:31
const N & name() const
Definition: DDBase.h:59
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
double waferT_
Definition: DDHGCalCell.cc:34
std::vector< std::string > cornrCN_
Definition: DDHGCalCell.cc:42
std::vector< std::string > truncSensN_
Definition: DDHGCalCell.cc:40
auto zw(V v) -> Vec2< typename std::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:71
#define DEFINE_EDM_PLUGIN(factory, type, name)
Log< level::Warning, false > LogWarning
std::string material_
Definition: DDHGCalCell.cc:38
std::vector< std::string > extenCN_
Definition: DDHGCalCell.cc:41
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
std::string fullCN_
Definition: DDHGCalCell.cc:39
std::vector< std::string > cornrSensN_
Definition: DDHGCalCell.cc:42