CMS 3D CMS Logo

DDHGCalPassive.cc
Go to the documentation of this file.
1 // File: DDHGCalPassive.cc
3 // Description: Makes layers of passive in the size of cassette
4 // Created by Sunanda Banerjee
19 
20 #include <string>
21 #include <vector>
22 #include <sstream>
23 
24 //#define EDM_ML_DEBUG
25 
26 using namespace angle_units::operators;
27 
28 class DDHGCalPassive : public DDAlgorithm {
29 public:
30  // Constructor and Destructor
32  ~DDHGCalPassive() override = default;
33 
34  void initialize(const DDNumericArguments& nArgs,
35  const DDVectorArguments& vArgs,
36  const DDMapArguments& mArgs,
37  const DDStringArguments& sArgs,
38  const DDStringVectorArguments& vsArgs) override;
39  void execute(DDCompactView& cpv) override;
40 
41 private:
42  std::string material_; // Material name for mother volume
43  double thick_; // Thickness of the section
44  double zMinBlock_; // z-position of the first layer
45  double moduleThick_; // Thickness of the overall module
46  std::vector<std::string> tagLayer_; // Tag of the layer (to be added to name)
47  int sectors_; // Number of phi sectors (cassettes)
48  int parts_; // number of parts in units of 30 degree
49  std::vector<std::string> tagSector_; // Tag of the sector (to be added to name)
50  double phi0_; // Start phi of the first cassette
51  double dphi_; // delta phi of the cassette
52  double shiftTop_; // Tolerance at the top
53  double shiftBot_; // Tolerance at the bottom
54  std::vector<std::string> layerNames_; // Names of the layers
55  std::vector<std::string> materials_; // Materials of the layers
56  std::vector<double> layerThick_; // Thickness of layers
57  std::vector<int> layerType_; // Layer types
58  std::vector<double> slopeB_; // Slope at the lower R
59  std::vector<double> zFrontB_; // Starting Z values for the slopes
60  std::vector<double> rMinFront_; // Corresponding rMin's
61  std::vector<double> slopeT_; // Slopes at the larger R
62  std::vector<double> zFrontT_; // Starting Z values for the slopes
63  std::vector<double> rMaxFront_; // Corresponding rMax's
64 };
65 
67 #ifdef EDM_ML_DEBUG
68  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: Creating an instance";
69 #endif
70 }
71 
73  const DDVectorArguments& vArgs,
74  const DDMapArguments&,
75  const DDStringArguments& sArgs,
76  const DDStringVectorArguments& vsArgs) {
77  material_ = sArgs["ModuleMaterial"];
78  thick_ = nArgs["Thickness"];
79  zMinBlock_ = nArgs["zMinBlock"];
80  moduleThick_ = nArgs["ModuleThick"];
81  tagLayer_ = vsArgs["TagLayer"];
82  tagSector_ = vsArgs["TagSector"];
83  parts_ = static_cast<int>(nArgs["Parts"]);
84  if (parts_ < 0)
85  parts_ = 1;
86  phi0_ = convertDegToRad(nArgs["PhiStart"]);
87  dphi_ = (2._pi) / tagSector_.size();
88 #ifdef EDM_ML_DEBUG
89  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << tagLayer_.size() << " Modules with base name "
90  << parent().name() << " made of " << material_ << " T " << thick_ << " Sectors "
91  << tagSector_.size() << " Parts " << parts_ << " phi0 " << convertRadToDeg(phi0_);
92  for (unsigned int i = 0; i < tagLayer_.size(); ++i)
93  edm::LogVerbatim("HGCalGeom") << "Layer " << i << " Tag " << tagLayer_[i] << " T " << moduleThick_;
94  for (unsigned int i = 0; i < tagSector_.size(); ++i)
95  edm::LogVerbatim("HGCalGeom") << "Sector " << i << " Tag " << tagSector_[i] << " W " << convertRadToDeg(dphi_);
96 #endif
97 
98  layerNames_ = vsArgs["LayerNames"];
99  materials_ = vsArgs["LayerMaterials"];
100  layerThick_ = vArgs["LayerThickness"];
101 #ifdef EDM_ML_DEBUG
102  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << layerNames_.size() << " types of volumes";
103  for (unsigned int i = 0; i < layerNames_.size(); ++i)
104  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
105  << " filled with " << materials_[i];
106 #endif
107  layerType_ = dbl_to_int(vArgs["LayerType"]);
108 #ifdef EDM_ML_DEBUG
109  std::ostringstream st1;
110  for (unsigned int i = 0; i < layerType_.size(); ++i)
111  st1 << " [" << i << "] " << layerType_[i];
112  edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " blocks" << st1.str();
113 #endif
114 
115  shiftTop_ = nArgs["ShiftTop"];
116  shiftBot_ = nArgs["ShiftBottom"];
117 #ifdef EDM_ML_DEBUG
118  edm::LogVerbatim("HGCalGeom") << "Shifts st the top " << shiftTop_ << " and at the bottom " << shiftBot_;
119 #endif
120  slopeB_ = vArgs["SlopeBottom"];
121  zFrontB_ = vArgs["ZFrontBottom"];
122  rMinFront_ = vArgs["RMinFront"];
123  slopeT_ = vArgs["SlopeTop"];
124  zFrontT_ = vArgs["ZFrontTop"];
125  rMaxFront_ = vArgs["RMaxFront"];
126 #ifdef EDM_ML_DEBUG
127  for (unsigned int i = 0; i < slopeB_.size(); ++i)
128  edm::LogVerbatim("HGCalGeom") << "Bottom Block [" << i << "] Zmin " << zFrontB_[i] << " Rmin " << rMinFront_[i]
129  << " Slope " << slopeB_[i];
130  for (unsigned int i = 0; i < slopeT_.size(); ++i)
131  edm::LogVerbatim("HGCalGeom") << "Top Block [" << i << "] Zmin " << zFrontT_[i] << " Rmax " << rMaxFront_[i]
132  << " Slope " << slopeT_[i];
133 #endif
134 }
135 
137 #ifdef EDM_ML_DEBUG
138  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassive...";
139 #endif
140  static constexpr double tol = 0.00001;
141 
142  // Loop over Layers
143  double zim(zMinBlock_);
144  //Loop over layers
145  for (unsigned int j = 0; j < tagLayer_.size(); ++j) {
146  double routF = HGCalGeomTools::radius(zim, zFrontT_, rMaxFront_, slopeT_) - shiftTop_;
147  double zo = zim + moduleThick_;
148  double rinB = HGCalGeomTools::radius(zo, zFrontB_, rMinFront_, slopeB_) + shiftBot_;
149  zim += moduleThick_;
150  for (unsigned int k = 0; k < tagSector_.size(); ++k) {
151  std::string parentName = parent().name().name() + tagLayer_[j] + tagSector_[k];
152  double phi1 = phi0_ + k * dphi_;
153  double dphi0 = dphi_ / parts_;
154  // First the mother
155  int nsec = 2 * parts_ + 2;
156  std::vector<double> xM(nsec, 0), yM(nsec, 0);
157  for (int n = 0; n <= parts_; ++n) {
158  double phi0 = phi1 + n * dphi0;
159  if (n == 0) {
160  xM[0] = rinB * cos(phi0);
161  yM[0] = rinB * sin(phi0);
162  } else {
163  xM[nsec - n] = rinB * cos(phi0);
164  yM[nsec - n] = rinB * sin(phi0);
165  }
166  xM[n + 1] = routF * cos(phi0);
167  yM[n + 1] = routF * sin(phi0);
168  }
169  std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
170  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
171  DDSolid solid = DDSolidFactory::extrudedpolygon(parentName, xM, yM, zw, zx, zy, scale);
172  DDName matName(DDSplit(material_).first, DDSplit(material_).second);
173  DDMaterial matter(matName);
174  DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
175 #ifdef EDM_ML_DEBUG
176  double phi2 = phi1 + dphi_;
177  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << solid.name() << " extruded polygon made of " << matName
178  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
179  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
180  << " and " << xM.size() << " edges with " << parts_ << " parts between "
181  << convertRadToDeg(phi1) << " and " << convertRadToDeg(phi2);
182  for (unsigned int kk = 0; kk < xM.size(); ++kk)
183  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
184 #endif
185 
186  // Then the layers
187  std::vector<DDLogicalPart> glogs(materials_.size());
188  std::vector<int> copyNumber(materials_.size(), 1);
189  double zi(-0.5 * thick_), thickTot(0.0);
190  for (unsigned int l = 0; l < layerType_.size(); l++) {
191  unsigned int i = layerType_[l];
192  if (copyNumber[i] == 1) {
193  zw[0] = -0.5 * layerThick_[i];
194  zw[1] = 0.5 * layerThick_[i];
195  std::string layerName = parentName + layerNames_[i];
196  solid = DDSolidFactory::extrudedpolygon(layerName, xM, yM, zw, zx, zy, scale);
197  DDName matN(DDSplit(materials_[i]).first, DDSplit(materials_[i]).second);
198  DDMaterial matter(matN);
199  glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
200 #ifdef EDM_ML_DEBUG
201  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: Layer " << i << ":" << l << ":" << solid.name()
202  << " extruded polygon made of " << matN << " z|x|y|s (0) " << zw[0] << ":"
203  << zx[0] << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":"
204  << zx[1] << ":" << zy[1] << ":" << scale[1] << " and " << xM.size() << " edges";
205  for (unsigned int kk = 0; kk < xM.size(); ++kk)
206  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
207 #endif
208  }
209  DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
210  DDRotation rot;
211  cpv.position(glogs[i], glogM, copyNumber[i], tran0, rot);
212 #ifdef EDM_ML_DEBUG
213  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << glogs[i].name() << " number " << copyNumber[i]
214  << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
215 #endif
216  ++copyNumber[i];
217  zi += layerThick_[i];
218  thickTot += layerThick_[i];
219  }
220  if ((std::abs(thickTot - thick_) >= tol) && (!layerType_.empty())) {
221  if (thickTot > thick_) {
222  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
223  << ": thickness of all its components **** ERROR ****";
224  } else {
225  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
226  << " of the components";
227  }
228  }
229  }
230  }
231 }
232 
233 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalPassive, "hgcal:DDHGCalPassive");
Log< level::Info, true > LogVerbatim
static AlgebraicMatrix initialize()
static void radius(double zf, double zb, std::vector< double > const &zFront1, std::vector< double > const &rFront1, std::vector< double > const &slope1, std::vector< double > const &zFront2, std::vector< double > const &rFront2, std::vector< double > const &slope2, int flag, std::vector< double > &zz, std::vector< double > &rin, std::vector< double > &rout)
constexpr double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
std::vector< double > rMaxFront_
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
std::vector< std::string > tagSector_
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< std::string > tagLayer_
std::vector< std::string > layerNames_
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
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< double > zFrontB_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
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< double > rMinFront_
std::vector< double > layerThick_
std::vector< int > layerType_
std::vector< double > zFrontT_
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:58
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:60
std::string material_
std::vector< double > slopeB_
std::vector< double > slopeT_
auto zw(V v) -> Vec2< typename std::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:84
#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
void execute(DDCompactView &cpv) override