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  phi0_ = convertDegToRad(nArgs["PhiStart"]);
85  dphi_ = (2._pi) / tagSector_.size();
86 #ifdef EDM_ML_DEBUG
87  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << tagLayer_.size() << " Modules with base name "
88  << parent().name() << " made of " << material_ << " T " << thick_ << " Sectors "
89  << tagSector_.size() << " Parts " << parts_ << " phi0 " << convertRadToDeg(phi0_);
90  for (unsigned int i = 0; i < tagLayer_.size(); ++i)
91  edm::LogVerbatim("HGCalGeom") << "Layer " << i << " Tag " << tagLayer_[i] << " T " << moduleThick_;
92  for (unsigned int i = 0; i < tagSector_.size(); ++i)
93  edm::LogVerbatim("HGCalGeom") << "Sector " << i << " Tag " << tagSector_[i] << " W " << convertRadToDeg(dphi_);
94 #endif
95 
96  layerNames_ = vsArgs["LayerNames"];
97  materials_ = vsArgs["LayerMaterials"];
98  layerThick_ = vArgs["LayerThickness"];
99 #ifdef EDM_ML_DEBUG
100  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << layerNames_.size() << " types of volumes";
101  for (unsigned int i = 0; i < layerNames_.size(); ++i)
102  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
103  << " filled with " << materials_[i];
104 #endif
105  layerType_ = dbl_to_int(vArgs["LayerType"]);
106 #ifdef EDM_ML_DEBUG
107  std::ostringstream st1;
108  for (unsigned int i = 0; i < layerType_.size(); ++i)
109  st1 << " [" << i << "] " << layerType_[i];
110  edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " blocks" << st1.str();
111 #endif
112 
113  shiftTop_ = nArgs["ShiftTop"];
114  shiftBot_ = nArgs["ShiftBottom"];
115 #ifdef EDM_ML_DEBUG
116  edm::LogVerbatim("HGCalGeom") << "Shifts st the top " << shiftTop_ << " and at the bottom " << shiftBot_;
117 #endif
118  slopeB_ = vArgs["SlopeBottom"];
119  zFrontB_ = vArgs["ZFrontBottom"];
120  rMinFront_ = vArgs["RMinFront"];
121  slopeT_ = vArgs["SlopeTop"];
122  zFrontT_ = vArgs["ZFrontTop"];
123  rMaxFront_ = vArgs["RMaxFront"];
124 #ifdef EDM_ML_DEBUG
125  for (unsigned int i = 0; i < slopeB_.size(); ++i)
126  edm::LogVerbatim("HGCalGeom") << "Bottom Block [" << i << "] Zmin " << zFrontB_[i] << " Rmin " << rMinFront_[i]
127  << " Slope " << slopeB_[i];
128  for (unsigned int i = 0; i < slopeT_.size(); ++i)
129  edm::LogVerbatim("HGCalGeom") << "Top Block [" << i << "] Zmin " << zFrontT_[i] << " Rmax " << rMaxFront_[i]
130  << " Slope " << slopeT_[i];
131 #endif
132 }
133 
135 #ifdef EDM_ML_DEBUG
136  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassive...";
137 #endif
138  static constexpr double tol = 0.00001;
139 
140  // Loop over Layers
141  double zim(zMinBlock_);
142  //Loop over layers
143  for (unsigned int j = 0; j < tagLayer_.size(); ++j) {
144  double routF = HGCalGeomTools::radius(zim, zFrontT_, rMaxFront_, slopeT_) - shiftTop_;
145  double zo = zim + moduleThick_;
146  double rinB = HGCalGeomTools::radius(zo, zFrontB_, rMinFront_, slopeB_) + shiftBot_;
147  zim += moduleThick_;
148  for (unsigned int k = 0; k < tagSector_.size(); ++k) {
149  std::string parentName = parent().name().name() + tagLayer_[j] + tagSector_[k];
150  double phi1 = phi0_ + k * dphi_;
151  double phi2 = phi1 + dphi_;
152  double phi0 = phi1 + 0.5 * dphi_;
153  // First the mother
154  std::vector<double> xM, yM;
155  if (parts_ == 1) {
156  xM = {rinB * cos(phi1), routF * cos(phi1), routF * cos(phi2), rinB * cos(phi2)};
157  yM = {rinB * sin(phi1), routF * sin(phi1), routF * sin(phi2), rinB * sin(phi2)};
158  } else {
159  // workaround for https://github.com/cms-sw/cmssw/issues/44931#issuecomment-2134850535
160  std::vector<double> xTmp = {rinB * cos(phi1),
161  routF * cos(phi1),
162  routF * cos(phi0),
163  routF * cos(phi2),
164  rinB * cos(phi2),
165  rinB * cos(phi0)};
166  std::vector<double> yTmp = {rinB * sin(phi1),
167  routF * sin(phi1),
168  routF * sin(phi0),
169  routF * sin(phi2),
170  rinB * sin(phi2),
171  rinB * sin(phi0)};
172  xM = std::move(xTmp);
173  yM = std::move(yTmp);
174  }
175  std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
176  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
177  DDSolid solid = DDSolidFactory::extrudedpolygon(parentName, xM, yM, zw, zx, zy, scale);
178  DDName matName(DDSplit(material_).first, DDSplit(material_).second);
179  DDMaterial matter(matName);
180  DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
181 #ifdef EDM_ML_DEBUG
182  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << solid.name() << " extruded polygon made of " << matName
183  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
184  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
185  << " and " << xM.size() << " edges";
186  for (unsigned int kk = 0; kk < xM.size(); ++kk)
187  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
188 #endif
189 
190  // Then the layers
191  std::vector<DDLogicalPart> glogs(materials_.size());
192  std::vector<int> copyNumber(materials_.size(), 1);
193  double zi(-0.5 * thick_), thickTot(0.0);
194  for (unsigned int l = 0; l < layerType_.size(); l++) {
195  unsigned int i = layerType_[l];
196  if (copyNumber[i] == 1) {
197  zw[0] = -0.5 * layerThick_[i];
198  zw[1] = 0.5 * layerThick_[i];
199  std::string layerName = parentName + layerNames_[i];
200  solid = DDSolidFactory::extrudedpolygon(layerName, xM, yM, zw, zx, zy, scale);
201  DDName matN(DDSplit(materials_[i]).first, DDSplit(materials_[i]).second);
202  DDMaterial matter(matN);
203  glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
204 #ifdef EDM_ML_DEBUG
205  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: Layer " << i << ":" << l << ":" << solid.name()
206  << " extruded polygon made of " << matN << " z|x|y|s (0) " << zw[0] << ":"
207  << zx[0] << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":"
208  << zx[1] << ":" << zy[1] << ":" << scale[1] << " and " << xM.size() << " edges";
209  for (unsigned int kk = 0; kk < xM.size(); ++kk)
210  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
211 #endif
212  }
213  DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
214  DDRotation rot;
215  cpv.position(glogs[i], glogM, copyNumber[i], tran0, rot);
216 #ifdef EDM_ML_DEBUG
217  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << glogs[i].name() << " number " << copyNumber[i]
218  << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
219 #endif
220  ++copyNumber[i];
221  zi += layerThick_[i];
222  thickTot += layerThick_[i];
223  }
224  if ((std::abs(thickTot - thick_) >= tol) && (!layerType_.empty())) {
225  if (thickTot > thick_) {
226  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
227  << ": thickness of all its components **** ERROR ****";
228  } else {
229  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
230  << " of the components";
231  }
232  }
233  }
234  }
235 }
236 
237 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: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::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
def move(src, dest)
Definition: eostools.py:511