CMS 3D CMS Logo

DDHGCalWaferP.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 DDHGCalWaferP : public DDAlgorithm {
22 public:
23  // Constructor and Destructor
25  ~DDHGCalWaferP() 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  double waferThick_; // Wafer thickness
40  std::vector<std::string> tags_; // Tags to be added to each name
41  std::vector<int> partialTypes_; // Type of partial wafer
42  std::vector<int> orientations_; // Orientations 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_; // Layer types
47  std::vector<int> layers_; // Number of layers in a section
48  std::string senseName_; // Name of the sensitive layer
49  double senseT_; // Thickness of sensitive layer
50  int senseType_; // Cell Type (0,1,2: Fine, Course 2/3)
51  int posSense_; // Position depleted layer
52  std::string nameSpace_; // Namespace to be used
53 };
54 
56  const DDVectorArguments& vArgs,
57  const DDMapArguments&,
58  const DDStringArguments& sArgs,
59  const DDStringVectorArguments& vsArgs) {
60  material_ = sArgs["ModuleMaterial"];
61  thick_ = nArgs["ModuleThickness"];
62  waferSize_ = nArgs["WaferSize"];
63  waferThick_ = nArgs["WaferThickness"];
64 #ifdef EDM_ML_DEBUG
65  waferSepar_ = nArgs["SensorSeparation"];
66  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: Module " << parent().name() << " made of " << material_ << " T "
67  << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_ << " T "
68  << waferThick_;
69 #endif
70  tags_ = vsArgs["Tags"];
71  partialTypes_ = dbl_to_int(vArgs["PartialTypes"]);
72  orientations_ = dbl_to_int(vArgs["Orientations"]);
73 #ifdef EDM_ML_DEBUG
74  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << tags_.size() << " variations of wafer types";
75  for (unsigned int k = 0; k < tags_.size(); ++k)
76  edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags_[k] << " Partial " << partialTypes_[k]
77  << " Orientation " << orientations_[k];
78 #endif
79  layerNames_ = vsArgs["LayerNames"];
80  materials_ = vsArgs["LayerMaterials"];
81  layerThick_ = vArgs["LayerThickness"];
82  layerType_ = dbl_to_int(vArgs["LayerTypes"]);
83 #ifdef EDM_ML_DEBUG
84  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << layerNames_.size() << " types of volumes";
85  for (unsigned int i = 0; i < layerNames_.size(); ++i)
86  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
87  << " filled with " << materials_[i] << " type " << layerType_[i];
88 #endif
89  layers_ = dbl_to_int(vArgs["Layers"]);
90 #ifdef EDM_ML_DEBUG
91  std::ostringstream st1;
92  for (unsigned int i = 0; i < layers_.size(); ++i)
93  st1 << " [" << i << "] " << layers_[i];
94  edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks" << st1.str();
95 #endif
96  senseName_ = sArgs["SenseName"];
97  senseT_ = nArgs["SenseThick"];
98  senseType_ = static_cast<int>(nArgs["SenseType"]);
99  posSense_ = static_cast<int>(nArgs["PosSensitive"]);
101 #ifdef EDM_ML_DEBUG
102  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: NameSpace " << nameSpace_ << ": Sensitive Layer Name " << senseName_
103  << " Thickness " << senseT_ << " Type " << senseType_ << " Position " << posSense_;
104 #endif
105 }
106 
108  static constexpr double tol = 0.00001;
109  static const double sqrt3 = std::sqrt(3.0);
110  double r = 0.5 * waferSize_;
111  double R = 2.0 * r / sqrt3;
112  std::string parentName = parent().name().name();
113 
114  // Loop over all types
115  for (unsigned int k = 0; k < tags_.size(); ++k) {
116  // First the mother
117  std::string mother = parentName + tags_[k];
118  std::vector<std::pair<double, double> > wxy =
120  std::vector<double> xM, yM;
121  for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
122  xM.emplace_back(wxy[i].first);
123  yM.emplace_back(wxy[i].second);
124  }
125  std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
126  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
127  DDSolid solid = DDSolidFactory::extrudedpolygon(mother, xM, yM, zw, zx, zy, scale);
129  DDMaterial matter(matName);
130  DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
131 #ifdef EDM_ML_DEBUG
132  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of " << matName
133  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
134  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
135  << " partial " << partialTypes_[k] << " orientation " << orientations_[k] << " and "
136  << xM.size() << " edges";
137  for (unsigned int j = 0; j < xM.size(); ++j)
138  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xM[j] << ":" << yM[j];
139 #endif
140 
141  // Then the layers
142  wxy = HGCalWaferMask::waferXY(partialTypes_[k], orientations_[k], 1, r, R, 0.0, 0.0);
143  std::vector<double> xL, yL;
144  for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
145  xL.emplace_back(wxy[i].first);
146  yL.emplace_back(wxy[i].second);
147  }
148  std::vector<DDLogicalPart> glogs(materials_.size());
149  std::vector<int> copyNumber(materials_.size(), 1);
150  double zi(-0.5 * thick_), thickTot(0.0);
151  for (unsigned int l = 0; l < layers_.size(); l++) {
152  unsigned int i = layers_[l];
153 #ifdef EDM_ML_DEBUG
154  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP:Layer " << l << ":" << i << " T " << layerThick_[i] << " Copy "
155  << copyNumber[i];
156 #endif
157  DDRotation rot;
158  if (copyNumber[i] == 1) {
159  if (layerType_[i] > 0) {
160  zw[0] = -0.5 * waferThick_;
161  zw[1] = 0.5 * waferThick_;
162  } else {
163  zw[0] = -0.5 * layerThick_[i];
164  zw[1] = 0.5 * layerThick_[i];
165  }
166  std::string lname = layerNames_[i] + tags_[k];
167  solid = DDSolidFactory::extrudedpolygon(lname, xL, yL, zw, zx, zy, scale);
169  DDMaterial matter(matN);
170  glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
171 #ifdef EDM_ML_DEBUG
172  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of " << matN
173  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
174  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
175  << " partial " << partialTypes_[k] << " orientation " << orientations_[k]
176  << " and " << xL.size() << " edges";
177  for (unsigned int j = 0; j < xL.size(); ++j)
178  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xL[j] << ":" << yL[j];
179 #endif
180  if (layerType_[i] > 0) {
181  std::string sname = senseName_ + tags_[k];
182  zw[0] = -0.5 * senseT_;
183  zw[1] = 0.5 * senseT_;
184  solid = DDSolidFactory::extrudedpolygon(sname, xL, yL, zw, zx, zy, scale);
185  DDLogicalPart glog = DDLogicalPart(solid.ddname(), matter, solid);
186 #ifdef EDM_ML_DEBUG
187  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of " << matN
188  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
189  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
190  << " partial " << partialTypes_[k] << " orientation " << orientations_[k]
191  << " and " << xL.size() << " edges";
192  for (unsigned int j = 0; j < xL.size(); ++j)
193  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xL[j] << ":" << yL[j];
194 #endif
195  double zpos = (posSense_ == 0) ? -0.5 * (waferThick_ - senseT_) : 0.5 * (waferThick_ - senseT_);
196  DDTranslation tran(0, 0, zpos);
197  int copy = 10 + senseType_;
198  cpv.position(glog, glogs[i], copy, tran, rot);
199 #ifdef EDM_ML_DEBUG
200  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << glog.name() << " number " << copy << " positioned in "
201  << glogs[i].name() << " at " << tran << " with no rotation";
202 #endif
203  }
204  }
205  DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
206  cpv.position(glogs[i], glogM, copyNumber[i], tran0, rot);
207 #ifdef EDM_ML_DEBUG
208  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << glogs[i].name() << " number " << copyNumber[i]
209  << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
210 #endif
211  ++copyNumber[i];
212  zi += layerThick_[i];
213  thickTot += layerThick_[i];
214  }
215  if (std::abs(thickTot - thick_) >= tol) {
216  if (thickTot > thick_) {
217  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
218  << ": thickness of all its components **** ERROR ****";
219  } else {
220  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
221  << " of the components";
222  }
223  }
224  }
225 }
226 
227 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferP, "hgcal:DDHGCalWaferP");
Log< level::Info, true > LogVerbatim
std::vector< int > orientations_
double waferSepar_
std::vector< int > layerType_
std::vector< int > partialTypes_
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
std::vector< std::string > tags_
std::vector< std::string > layerNames_
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
void execute(DDCompactView &cpv) override
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
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 > materials_
std::vector< int > layers_
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
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
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< double > layerThick_
std::string material_
double waferThick_
std::string nameSpace_
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
~DDHGCalWaferP() override=default
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 senseName_