CMS 3D CMS Logo

DDHGCalPassivePartial.cc
Go to the documentation of this file.
14 
15 #include <string>
16 #include <vector>
17 #include <sstream>
18 
19 //#define EDM_ML_DEBUG
20 
21 class DDHGCalPassivePartial : public DDAlgorithm {
22 public:
23  // Constructor and Destructor
24  DDHGCalPassivePartial() = default;
25  ~DDHGCalPassivePartial() override = default;
26 
27  void initialize(const DDNumericArguments& nArgs,
28  const DDVectorArguments& vArgs,
29  const DDMapArguments& mArgs,
30  const DDStringArguments& sArgs,
31  const DDStringVectorArguments& vsArgs) override;
32  void execute(DDCompactView& cpv) override;
33 
34 private:
35  std::string material_; // Material name for module with gap
36  double thick_; // Module thickness
37  double waferSize_; // Wafer size
38  double waferSepar_; // Sensor separation
39  std::vector<std::string> tags_; // Tags to be added to each name
40  std::vector<int> partialTypes_; // Type of partial wafer
41  std::vector<int> placementIndex_;
42  std::vector<std::string> placementIndexTags_; // Plaement index of the wafers
43  std::vector<std::string> layerNames_; // Names of the layers
44  std::vector<std::string> materials_; // Materials of the layers
45  std::vector<double> layerThick_; // Thickness of layers
46  std::vector<int> layerType_; // Types of layers
47 };
48 
50  const DDVectorArguments& vArgs,
51  const DDMapArguments&,
52  const DDStringArguments& sArgs,
53  const DDStringVectorArguments& vsArgs) {
54  material_ = sArgs["ModuleMaterial"];
55  thick_ = nArgs["ModuleThickness"];
56  waferSize_ = nArgs["WaferSize"];
57 #ifdef EDM_ML_DEBUG
58  waferSepar_ = nArgs["SensorSeparation"];
59  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: Module " << parent().name() << " made of " << material_
60  << " T " << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_;
61 #endif
62  tags_ = vsArgs["Tags"];
63  partialTypes_ = dbl_to_int(vArgs["PartialTypes"]);
64  placementIndex_ = dbl_to_int(vArgs["PlacementIndex"]);
65  placementIndexTags_ = vsArgs["PlacementIndexTags"];
66 #ifdef EDM_ML_DEBUG
67  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << tags_.size() << " variations of wafer types";
68  for (unsigned int k = 0; k < tags_.size(); ++k) {
69  for (unsigned int m = 0; m < placementIndex_.size(); ++m) {
70  edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags_[k] << " Partial " << partialTypes_[k]
71  << " Placement Index " << placementIndex_[m] << " Tag " << placementIndexTags_[m];
72  }
73  }
74 #endif
75  layerNames_ = vsArgs["LayerNames"];
76  materials_ = vsArgs["LayerMaterials"];
77  layerThick_ = vArgs["LayerThickness"];
78 #ifdef EDM_ML_DEBUG
79  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << layerNames_.size() << " types of volumes";
80  for (unsigned int i = 0; i < layerNames_.size(); ++i)
81  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
82  << " filled with " << materials_[i];
83 #endif
84  layerType_ = dbl_to_int(vArgs["LayerType"]);
85 #ifdef EDM_ML_DEBUG
86  std::ostringstream st1;
87  for (unsigned int i = 0; i < layerType_.size(); ++i)
88  st1 << " [" << i << "] " << layerType_[i];
89  edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " blocks" << st1.str();
90 #endif
91 }
92 
94 #ifdef EDM_ML_DEBUG
95  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassivePartial...";
96 #endif
97 
98  static constexpr double tol = 0.00001;
99  std::string parentName = parent().name().name();
100 
101  // Loop over all types
102  for (unsigned int k = 0; k < tags_.size(); ++k) {
103  for (unsigned int m = 0; m < placementIndex_.size(); ++m) {
104  // First the mother
105  std::string mother = parentName + placementIndexTags_[m] + tags_[k];
106  std::vector<std::pair<double, double> > wxy =
108  std::vector<double> xM, yM;
109  for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
110  xM.emplace_back(wxy[i].first);
111  yM.emplace_back(wxy[i].second);
112  }
113  std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
114  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
115  DDSolid solid = DDSolidFactory::extrudedpolygon(mother, xM, yM, zw, zx, zy, scale);
117  DDMaterial matter(matName);
118  DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
119 #ifdef EDM_ML_DEBUG
120  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << solid.name() << " extruded polygon made of "
121  << matName << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
122  << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
123  << scale[1] << " partial " << partialTypes_[k] << " placement index "
124  << placementIndex_[m] << " and " << xM.size() << " edges";
125  for (unsigned int j = 0; j < xM.size(); ++j)
126  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xM[j] << ":" << yM[j];
127 #endif
128 
129  // Then the layers
130  std::vector<DDLogicalPart> glogs(materials_.size());
131  std::vector<int> copyNumber(materials_.size(), 1);
132  double zi(-0.5 * thick_), thickTot(0.0);
133  for (unsigned int l = 0; l < layerType_.size(); l++) {
134  unsigned int i = layerType_[l];
136  std::vector<double> xL, yL;
137  for (unsigned int i0 = 0; i0 < (wxy.size() - 1); ++i0) {
138  xL.emplace_back(wxy[i0].first);
139  yL.emplace_back(wxy[i0].second);
140  }
141 #ifdef EDM_ML_DEBUG
142  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial:Layer " << l << ":" << i << " T " << layerThick_[i]
143  << " Copy " << copyNumber[i] << " Partial type " << partialTypes_[k];
144 #endif
145  DDRotation rot;
146  if (copyNumber[i] == 1) {
147  zw[0] = -0.5 * layerThick_[i];
148  zw[1] = 0.5 * layerThick_[i];
149  std::string lname = mother + layerNames_[i];
150  solid = DDSolidFactory::extrudedpolygon(lname, xL, yL, zw, zx, zy, scale);
152  DDMaterial matter(matN);
153  glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
154 #ifdef EDM_ML_DEBUG
155  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << solid.name() << " extruded polygon made of "
156  << matN << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
157  << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
158  << scale[1] << " partial " << partialTypes_[k] << " placement index "
159  << placementIndex_[m] << " and " << xL.size() << " edges";
160  for (unsigned int j = 0; j < xL.size(); ++j)
161  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xL[j] << ":" << yL[j];
162 #endif
163  }
164  DDTranslation tran(0, 0, (zi + 0.5 * layerThick_[i]));
165  cpv.position(glogs[i], glogM, copyNumber[i], tran, rot);
166 #ifdef EDM_ML_DEBUG
167  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << glogs[i].name() << " number " << copyNumber[i]
168  << " positioned in " << glogM.name() << " at " << tran << " with no rotation";
169 #endif
170  ++copyNumber[i];
171  zi += layerThick_[i];
172  thickTot += layerThick_[i];
173  }
174  if ((std::abs(thickTot - thick_) >= tol) && (!layerType_.empty())) {
175  if (thickTot > thick_) {
176  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
177  << ": thickness of all its components **** ERROR ****";
178  } else {
179  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
180  << " of the components";
181  }
182  }
183  }
184  }
185 }
186 
187 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalPassivePartial, "hgcal:DDHGCalPassivePartial");
Log< level::Info, true > LogVerbatim
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
~DDHGCalPassivePartial() override=default
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
Log< level::Error, false > LogError
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
static std::vector< std::pair< double, double > > waferXY(int part, int orient, int zside, double waferSize, double offset, double xpos, double ypos)
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< int > layerType_
std::vector< std::string > placementIndexTags_
DDHGCalPassivePartial()=default
std::vector< std::string > materials_
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 > partialTypes_
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::vector< double > layerThick_
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< int > placementIndex_
auto zw(V v) -> Vec2< typename std::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:71
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< std::string > layerNames_
void execute(DDCompactView &cpv) override
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
std::vector< std::string > tags_
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override