CMS 3D CMS Logo

DDHGCalWaferPartialRotated.cc
Go to the documentation of this file.
15 
16 #include <string>
17 #include <vector>
18 #include <sstream>
19 
20 //#define EDM_ML_DEBUG
21 
22 class DDHGCalWaferPartialRotated : public DDAlgorithm {
23 public:
24  // Constructor and Destructor
26  ~DDHGCalWaferPartialRotated() override = default;
27 
28  void initialize(const DDNumericArguments& nArgs,
29  const DDVectorArguments& vArgs,
30  const DDMapArguments& mArgs,
31  const DDStringArguments& sArgs,
32  const DDStringVectorArguments& vsArgs) override;
33  void execute(DDCompactView& cpv) override;
34 
35 private:
36  std::string material_; // Material name for module with gap
37  std::string waferTag_; // Tag for type of wafer
38  double thick_; // Module thickness
39  double waferSize_; // Wafer size
40  double waferSepar_; // Sensor separation
41  double waferThick_; // Wafer thickness
42  std::vector<std::string> tags_; // Tags to be added to each name
43  std::vector<int> partialTypes_; // Type of partial wafer
44  std::vector<int> placementIndex_;
45  std::vector<std::string> placementIndexTags_; // Plaement index of the wafers
46  std::vector<std::string> layerNames_; // Names of the layers
47  std::vector<std::string> materials_; // Materials of the layers
48  std::vector<double> layerThick_; // Thickness of layers
49  std::vector<int> layerType_; // Layer types
50  std::vector<int> layers_; // Number of layers in a section
51  std::string senseName_; // Name of the sensitive layer
52  double senseT_; // Thickness of sensitive layer
53  int senseType_; // Cell Type (0,1,2: Fine, Course 2/3)
54  std::string nameSpace_; // Namespace to be used
55 };
56 
58 #ifdef EDM_ML_DEBUG
59  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: Creating an instance";
60 #endif
61 }
62 
64  const DDVectorArguments& vArgs,
65  const DDMapArguments&,
66  const DDStringArguments& sArgs,
67  const DDStringVectorArguments& vsArgs) {
68  material_ = sArgs["ModuleMaterial"];
69  thick_ = nArgs["ModuleThickness"];
70  waferSize_ = nArgs["WaferSize"];
71  waferThick_ = nArgs["WaferThickness"];
72  waferTag_ = sArgs["WaferTag"];
73 #ifdef EDM_ML_DEBUG
74  waferSepar_ = nArgs["SensorSeparation"];
75  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: Module " << parent().name() << " made of " << material_
76  << " T " << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_
77  << " T " << waferThick_;
78 #endif
79  tags_ = vsArgs["Tags"];
80  partialTypes_ = dbl_to_int(vArgs["PartialTypes"]);
81  placementIndex_ = dbl_to_int(vArgs["PlacementIndex"]);
82  placementIndexTags_ = vsArgs["PlacementIndexTags"];
83 #ifdef EDM_ML_DEBUG
84  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << tags_.size() << " variations of wafer types";
85  for (unsigned int k = 0; k < tags_.size(); ++k) {
86  for (unsigned int m = 0; m < placementIndex_.size(); ++m) {
87  edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags_[k] << " Partial " << partialTypes_[k]
88  << " Placement Index " << placementIndex_[m] << " Tag " << placementIndexTags_[m];
89  }
90  }
91 #endif
92  layerNames_ = vsArgs["LayerNames"];
93  materials_ = vsArgs["LayerMaterials"];
94  layerThick_ = vArgs["LayerThickness"];
95  layerType_ = dbl_to_int(vArgs["LayerTypes"]);
96 #ifdef EDM_ML_DEBUG
97  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << layerNames_.size() << " types of volumes";
98  for (unsigned int i = 0; i < layerNames_.size(); ++i)
99  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
100  << " filled with " << materials_[i] << " type " << layerType_[i];
101 #endif
102  layers_ = dbl_to_int(vArgs["Layers"]);
103 #ifdef EDM_ML_DEBUG
104  std::ostringstream st1;
105  for (unsigned int i = 0; i < layers_.size(); ++i)
106  st1 << " [" << i << "] " << layers_[i];
107  edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks" << st1.str();
108 #endif
109  senseName_ = sArgs["SenseName"];
110  senseT_ = nArgs["SenseThick"];
111  senseType_ = static_cast<int>(nArgs["SenseType"]);
113 #ifdef EDM_ML_DEBUG
114  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: NameSpace " << nameSpace_ << " Sensitive Layer Name "
115  << senseName_ << " Thickness " << senseT_ << " Type " << senseType_;
116 #endif
117 }
118 
120 #ifdef EDM_ML_DEBUG
121  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferPartialRotated...";
122 #endif
123 
124  static constexpr double tol = 0.00001;
125  static const double sqrt3 = std::sqrt(3.0);
126  double r = 0.5 * waferSize_;
127  double R = 2.0 * r / sqrt3;
128  std::string parentName = parent().name().name();
129 
130  // Loop over all types
131  for (unsigned int k = 0; k < tags_.size(); ++k) {
132  for (unsigned int m = 0; m < placementIndex_.size(); ++m) {
133  // First the mother
134  std::string mother = parentName + placementIndexTags_[m] + waferTag_ + tags_[k];
135  std::vector<std::pair<double, double> > wxy =
137  std::vector<double> xM, yM;
138  for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
139  xM.emplace_back(wxy[i].first);
140  yM.emplace_back(wxy[i].second);
141  }
142  std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
143  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
144  DDSolid solid = DDSolidFactory::extrudedpolygon(mother, xM, yM, zw, zx, zy, scale);
146  DDMaterial matter(matName);
147  DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
148 #ifdef EDM_ML_DEBUG
149  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << solid.name() << " extruded polygon made of "
150  << matName << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
151  << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
152  << scale[1] << " partial " << partialTypes_[k] << " placement index "
153  << placementIndex_[m] << " and " << xM.size() << " edges";
154  for (unsigned int j = 0; j < xM.size(); ++j)
155  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xM[j] << ":" << yM[j];
156 #endif
157 
158  // Then the layers
160  std::vector<double> xL, yL;
161  for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
162  xL.emplace_back(wxy[i].first);
163  yL.emplace_back(wxy[i].second);
164  }
165  std::vector<DDLogicalPart> glogs(materials_.size());
166  std::vector<int> copyNumber(materials_.size(), 1);
167  double zi(-0.5 * thick_), thickTot(0.0);
168  for (unsigned int l = 0; l < layers_.size(); l++) {
169  unsigned int i = layers_[l];
170 #ifdef EDM_ML_DEBUG
171  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated:Layer " << l << ":" << i << " T " << layerThick_[i]
172  << " Copy " << copyNumber[i];
173 #endif
174  DDRotation rot;
175  if (copyNumber[i] == 1) {
176  if (layerType_[i] > 0) {
177  zw[0] = -0.5 * waferThick_;
178  zw[1] = 0.5 * waferThick_;
179  } else {
180  zw[0] = -0.5 * layerThick_[i];
181  zw[1] = 0.5 * layerThick_[i];
182  }
184  solid = DDSolidFactory::extrudedpolygon(lname, xL, yL, zw, zx, zy, scale);
186  DDMaterial matter(matN);
187  glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
188 #ifdef EDM_ML_DEBUG
189  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << solid.name()
190  << " extruded polygon made of " << matN << " z|x|y|s (0) " << zw[0] << ":"
191  << zx[0] << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":"
192  << zx[1] << ":" << zy[1] << ":" << scale[1] << " partial " << partialTypes_[k]
193  << " placement index " << placementIndex_[m] << " and " << xL.size()
194  << " edges";
195  for (unsigned int j = 0; j < xL.size(); ++j)
196  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xL[j] << ":" << yL[j];
197 #endif
198  if (layerType_[i] > 0) {
200  zw[0] = -0.5 * senseT_;
201  zw[1] = 0.5 * senseT_;
202  solid = DDSolidFactory::extrudedpolygon(sname, xL, yL, zw, zx, zy, scale);
203  DDLogicalPart glog = DDLogicalPart(solid.ddname(), matter, solid);
204 #ifdef EDM_ML_DEBUG
205  edm::LogVerbatim("HGCalGeom")
206  << "DDHGCalWaferPartialRotated: " << solid.name() << " extruded polygon made of " << matN
207  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) "
208  << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1] << " partial " << partialTypes_[k]
209  << " placement index " << placementIndex_[m] << " and " << xL.size() << " edges";
210  for (unsigned int j = 0; j < xL.size(); ++j)
211  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xL[j] << ":" << yL[j];
212 #endif
213  auto posSense = HGCalCell::cellOrient(placementIndex_[m]);
214  double zpos = (posSense.second > 0) ? -0.5 * (waferThick_ - senseT_) : 0.5 * (waferThick_ - senseT_);
215  DDTranslation tran(0, 0, zpos);
216  int copy = 10 + senseType_;
217  cpv.position(glog, glogs[i], copy, tran, rot);
218 #ifdef EDM_ML_DEBUG
219  edm::LogVerbatim("HGCalGeom")
220  << "DDHGCalWaferPartialRotated: " << glog.name() << " number " << copy << " positioned in "
221  << glogs[i].name() << " at " << tran << " with no rotation";
222 #endif
223  }
224  }
225  DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
226  cpv.position(glogs[i], glogM, copyNumber[i], tran0, rot);
227 #ifdef EDM_ML_DEBUG
228  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << glogs[i].name() << " number "
229  << copyNumber[i] << " positioned in " << glogM.name() << " at " << tran0
230  << " with no rotation";
231 #endif
232  ++copyNumber[i];
233  zi += layerThick_[i];
234  thickTot += layerThick_[i];
235  }
236  if (std::abs(thickTot - thick_) >= tol) {
237  if (thickTot > thick_) {
238  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
239  << ": thickness of all its components **** ERROR ****";
240  } else {
241  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
242  << " of the components";
243  }
244  }
245  }
246  }
247 }
248 
249 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferPartialRotated, "hgcal:DDHGCalWaferPartialRotated");
Log< level::Info, true > LogVerbatim
std::vector< std::string > placementIndexTags_
std::vector< std::string > materials_
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
static std::vector< std::pair< double, double > > waferXY(int part, int orient, int zside, double delX, double delY, double xpos, double ypos)
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
~DDHGCalWaferPartialRotated() override=default
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)
std::vector< std::string > layerNames_
void execute(DDCompactView &cpv) override
static std::pair< int32_t, int32_t > cellOrient(int32_t placementIndex)
Definition: HGCalCell.cc:235
std::vector< std::string > tags_
T sqrt(T t)
Definition: SSEVec.h:19
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
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
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
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