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