CMS 3D CMS Logo

DDHCalTBCableAlgo.cc
Go to the documentation of this file.
1 // File: DDHCalTBCableAlgo.cc
3 // Description: Cable mockup between barrel and endcap gap
5 
6 #include <cmath>
7 #include <algorithm>
8 #include <map>
9 #include <string>
10 #include <vector>
11 
23 
24 //#define EDM_ML_DEBUG
25 using namespace angle_units::operators;
26 
27 class DDHCalTBCableAlgo : public DDAlgorithm {
28 public:
29  //Constructor and Destructor
30  DDHCalTBCableAlgo(); //const std::string & name);
31  ~DDHCalTBCableAlgo() override;
32 
33  void initialize(const DDNumericArguments& nArgs,
34  const DDVectorArguments& vArgs,
35  const DDMapArguments& mArgs,
36  const DDStringArguments& sArgs,
37  const DDStringVectorArguments& vsArgs) override;
38 
39  void execute(DDCompactView& cpv) override;
40 
41 private:
42  std::string genMat; //General material
43  int nsectors; //Number of potenital straight edges
44  int nsectortot; //Number of straight edges (actual)
45  int nhalf; //Number of half modules
46  double rin; //(see Figure of hcalbarrel)
47  std::vector<double> theta; // .... (in degrees)
48  std::vector<double> rmax; // ....
49  std::vector<double> zoff; // ....
50  std::string absMat; //Absorber material
51  double thick; //Thickness of absorber
52  double width1, length1; //Width, length of absorber type 1
53  double width2, length2; //Width, length of absorber type 2
54  double gap2; //Gap between abosrbers of type 2
55 
56  std::string idName; //Name of the "parent" volume.
57  std::string idNameSpace; //Namespace of this and ALL sub-parts
58  std::string rotns; //Namespace for rotation matrix
59 };
60 
61 DDHCalTBCableAlgo::DDHCalTBCableAlgo() : theta(0), rmax(0), zoff(0) {
62 #ifdef EDM_ML_DEBUG
63  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating an instance";
64 #endif
65 }
66 
68 
70  const DDVectorArguments& vArgs,
71  const DDMapArguments&,
72  const DDStringArguments& sArgs,
73  const DDStringVectorArguments&) {
74  genMat = sArgs["MaterialName"];
75  nsectors = int(nArgs["NSector"]);
76  nsectortot = int(nArgs["NSectorTot"]);
77  nhalf = int(nArgs["NHalf"]);
78  rin = nArgs["RIn"];
79  theta = vArgs["Theta"];
80  rmax = vArgs["RMax"];
81  zoff = vArgs["ZOff"];
82 
83  absMat = sArgs["AbsMatName"];
84  thick = nArgs["Thickness"];
85  width1 = nArgs["Width1"];
86  length1 = nArgs["Length1"];
87  width2 = nArgs["Width2"];
88  length2 = nArgs["Length2"];
89  gap2 = nArgs["Gap2"];
90 
91 #ifdef EDM_ML_DEBUG
92  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: General material " << genMat << "\tSectors " << nsectors << ", "
93  << nsectortot << "\tHalves " << nhalf << "\tRin " << rin;
94  for (unsigned int i = 0; i < theta.size(); i++)
95  edm::LogVerbatim("HCalGeom") << "\t" << i << " Theta " << theta[i] << " rmax " << rmax[i] << " zoff " << zoff[i];
96  edm::LogVerbatim("HCalGeom") << "\tCable mockup made of " << absMat << "\tThick " << thick << "\tLength and width "
97  << length1 << ", " << width1 << " and " << length2 << ", " << width2 << " Gap " << gap2;
98 #endif
99  idName = sArgs["MotherName"];
101  rotns = sArgs["RotNameSpace"];
102 #ifdef EDM_ML_DEBUG
103  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Parent " << parent().name() << " idName " << idName
104  << " NameSpace " << idNameSpace << " for solids etc. and " << rotns << " for rotations";
105 #endif
106 }
107 
109 #ifdef EDM_ML_DEBUG
110  edm::LogVerbatim("HCalGeom") << "==>> Constructing DDHCalTBCableAlgo...";
111 #endif
112 
113  double alpha = 1._pi / nsectors;
114  double dphi = nsectortot * 2._pi / nsectors;
115 
116  double zstep0 = zoff[1] + rmax[1] * tan(theta[1]) + (rin - rmax[1]) * tan(theta[2]);
117  double zstep1 = zstep0 + thick / cos(theta[2]);
118  double zstep2 = zoff[3];
119 
120  double rstep0 = rin + (zstep2 - zstep1) / tan(theta[2]);
121  double rstep1 = rin + (zstep1 - zstep0) / tan(theta[2]);
122 
123  std::vector<double> pgonZ = {zstep0, zstep1, zstep2, zstep2 + thick / cos(theta[2])};
124 
125  std::vector<double> pgonRmin = {rin, rin, rstep0, rmax[2]};
126  std::vector<double> pgonRmax = {rin, rstep1, rmax[2], rmax[2]};
127 
128  std::string name("Null");
129  DDSolid solid;
130  solid = DDSolidFactory::polyhedra(DDName(idName, idNameSpace), nsectortot, -alpha, dphi, pgonZ, pgonRmin, pgonRmax);
131 #ifdef EDM_ML_DEBUG
132  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << DDName(idName, idNameSpace) << " Polyhedra made of "
133  << genMat << " with " << nsectortot << " sectors from " << convertRadToDeg(-alpha)
134  << " to " << convertRadToDeg(-alpha + dphi) << " and with " << pgonZ.size()
135  << " sections";
136  for (unsigned int i = 0; i < pgonZ.size(); i++)
137  edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[i] << "\tRmin = " << pgonRmin[i] << "\tRmax = " << pgonRmax[i];
138 #endif
140  DDMaterial matter(matname);
141  DDLogicalPart genlogic(solid.ddname(), matter, solid);
142 
143  DDName parentName = parent().name();
144  DDTranslation r0(0.0, 0.0, 0.0);
145  DDRotation rot;
146  cpv.position(DDName(idName, idNameSpace), parentName, 1, r0, rot);
147 #ifdef EDM_ML_DEBUG
148  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << DDName(idName, idNameSpace) << " number 1 positioned in "
149  << parentName << " at " << r0 << " with " << rot;
150 #endif
151  if (nhalf != 1) {
152  rot = DDRotation(DDName("180D", rotns));
153  cpv.position(DDName(idName, idNameSpace), parentName, 2, r0, rot);
154 #ifdef EDM_ML_DEBUG
155  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << DDName(idName, idNameSpace) << " number 2 positioned in "
156  << parentName << " at " << r0 << " with " << rot;
157 #endif
158  }
159 
160  //Construct sector (from -alpha to +alpha)
161  name = idName + "Module";
162 #ifdef EDM_ML_DEBUG
163  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << DDName(name, idNameSpace) << " Polyhedra made of " << genMat
164  << " with 1 sector from " << convertRadToDeg(-alpha) << " to " << convertRadToDeg(alpha)
165  << " and with " << pgonZ.size() << " sections";
166  for (unsigned int i = 0; i < pgonZ.size(); i++)
167  edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[i] << "\tRmin = " << pgonRmin[i] << "\tRmax = " << pgonRmax[i];
168 #endif
169  solid = DDSolidFactory::polyhedra(DDName(name, idNameSpace), 1, -alpha, 2 * alpha, pgonZ, pgonRmin, pgonRmax);
170  DDLogicalPart seclogic(solid.ddname(), matter, solid);
171 
172  for (int ii = 0; ii < nsectortot; ii++) {
173  double phi = ii * 2 * alpha;
175  std::string rotstr("NULL");
176  if (phi != 0) {
177  rotstr = "R" + formatAsDegreesInInteger(phi);
178  rotation = DDRotation(DDName(rotstr, rotns));
179  if (!rotation) {
180 #ifdef EDM_ML_DEBUG
181  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a new "
182  << "rotation " << rotstr << "\t90," << convertRadToDeg(phi) << ",90,"
183  << (90 + convertRadToDeg(phi)) << ", 0, 0";
184 #endif
185  rotation = DDrot(DDName(rotstr, idNameSpace), 90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
186  }
187  }
188 
189  cpv.position(seclogic, genlogic, ii + 1, DDTranslation(0.0, 0.0, 0.0), rotation);
190 #ifdef EDM_ML_DEBUG
191  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << seclogic.name() << " number " << ii + 1
192  << " positioned in " << genlogic.name() << " at (0,0,0) with " << rotation;
193 #endif
194  }
195 
196  //Now a trapezoid of air
197  double rinl = pgonRmin[0] + thick * sin(theta[2]);
198  double routl = pgonRmax[2] - thick * sin(theta[2]);
199  double dx1 = rinl * tan(alpha);
200  double dx2 = 0.90 * routl * tan(alpha);
201  double dy = 0.50 * thick;
202  double dz = 0.50 * (routl - rinl);
203  name = idName + "Trap";
204  solid = DDSolidFactory::trap(DDName(name, idNameSpace), dz, 0, 0, dy, dx1, dx1, 0, dy, dx2, dx2, 0);
205 #ifdef EDM_ML_DEBUG
206  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Trap made of " << genMat
207  << " of dimensions " << dz << ", 0, 0, " << dy << ", " << dx1 << ", " << dx1 << ", 0, "
208  << dy << ", " << dx2 << ", " << dx2 << ", 0";
209 #endif
210  DDLogicalPart glog(solid.ddname(), matter, solid);
211 
212  std::string rotstr = name;
213 #ifdef EDM_ML_DEBUG
214  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation: " << rotstr << "\t90, 270, "
215  << (180 - convertRadToDeg(theta[2])) << ", 0, " << (90 - convertRadToDeg(theta[2]))
216  << ", 0";
217 #endif
218  rot = DDrot(DDName(rotstr, idNameSpace), 90._deg, 270._deg, (180._deg - theta[2]), 0, (90._deg - theta[2]), 0);
219  DDTranslation r1(0.5 * (rinl + routl), 0, 0.5 * (pgonZ[1] + pgonZ[2]));
220  cpv.position(glog, seclogic, 1, r1, rot);
221 #ifdef EDM_ML_DEBUG
222  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << glog.name() << " number 1 positioned in " << seclogic.name()
223  << " at " << r1 << " with " << rot;
224 #endif
225  //Now the cable of type 1
226  name = idName + "Cable1";
227  double phi = atan((dx2 - dx1) / (2 * dz));
228  double xmid = 0.5 * (dx1 + dx2) - 1.0;
229  solid = DDSolidFactory::box(DDName(name, idNameSpace), 0.5 * width1, 0.5 * thick, 0.5 * length1);
230 #ifdef EDM_ML_DEBUG
231  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Box made of " << absMat << " of dimension "
232  << 0.5 * width1 << ", " << 0.5 * thick << ", " << 0.5 * length1;
233 #endif
235  DDMaterial absmatter(absname);
236  DDLogicalPart cablog1(solid.ddname(), absmatter, solid);
237 
238  rotstr = idName + "Left";
239 #ifdef EDM_ML_DEBUG
240  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation " << rotstr << "\t"
241  << (90 + convertRadToDeg(phi)) << ", 0, 90, 90, " << convertRadToDeg(phi) << ", 0";
242 #endif
243  DDRotation rot2 = DDrot(DDName(rotstr, idNameSpace), (90._deg + phi), 0.0, 90._deg, 90._deg, phi, 0.0);
244  DDTranslation r2((xmid - 0.5 * width1 * cos(phi)), 0, 0);
245  cpv.position(cablog1, glog, 1, r2, rot2);
246 #ifdef EDM_ML_DEBUG
247  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog1.name() << " number 1 positioned in " << glog.name()
248  << " at " << r2 << " with " << rot2;
249 #endif
250  rotstr = idName + "Right";
251 #ifdef EDM_ML_DEBUG
252  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation " << rotstr << "\t"
253  << (90 - convertRadToDeg(phi)) << ", 0, 90, 90, " << convertRadToDeg(-phi) << ", 0";
254 #endif
255  DDRotation rot3 = DDrot(DDName(rotstr, idNameSpace), (90._deg - phi), 0, 90._deg, 90._deg, -phi, 0);
256  DDTranslation r3(-(xmid - 0.5 * width1 * cos(phi)), 0, 0);
257  cpv.position(cablog1, glog, 2, r3, rot3);
258 #ifdef EDM_ML_DEBUG
259  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog1.name() << " number 2 positioned in " << glog.name()
260  << " at " << r3 << " with " << rot3;
261 #endif
262  //Now the cable of type 2
263  name = idName + "Cable2";
264  solid = DDSolidFactory::box(DDName(name, idNameSpace), 0.5 * width2, 0.5 * thick, 0.5 * length2);
265 #ifdef EDM_ML_DEBUG
266  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Box made of " << absMat << " of dimension "
267  << 0.5 * width2 << ", " << 0.5 * thick << ", " << 0.5 * length2;
268 #endif
269  DDLogicalPart cablog2(solid.ddname(), absmatter, solid);
270 
271  double xpos = 0.5 * (width2 + gap2);
272  cpv.position(cablog2, glog, 1, DDTranslation(xpos, 0.0, 0.0), DDRotation());
273 #ifdef EDM_ML_DEBUG
274  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog2.name() << " number 1 positioned in " << glog.name()
275  << " at (" << xpos << ", 0, 0) with no "
276  << "rotation";
277 #endif
278  cpv.position(cablog2, glog, 2, DDTranslation(-xpos, 0.0, 0.0), DDRotation());
279 #ifdef EDM_ML_DEBUG
280  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog2.name() << " number 2 positioned in " << glog.name()
281  << " at (" << -xpos << ", 0, 0) with no "
282  << "rotation";
283 
284  edm::LogVerbatim("HCalGeom") << "<<== End of DDHCalTBCableAlgo construction";
285 #endif
286 }
287 
288 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalTBCableAlgo, "hcal:DDHCalTBCableAlgo");
std::vector< double > theta
Log< level::Info, true > LogVerbatim
static AlgebraicMatrix initialize()
std::vector< double > rmax
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
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
std::string formatAsDegreesInInteger(double radianVal)
Definition: DDTypes.cc:79
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)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
DDRotation DDrot(const DDName &name, std::unique_ptr< DDRotationMatrix > rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:67
void execute(DDCompactView &cpv) override
static DDSolid trap(const DDName &name, double pDz, double pTheta, double pPhi, double pDy1, double pDx1, double pDx2, double pAlp1, double pDy2, double pDx3, double pDx4, double pAlp2)
Definition: DDSolid.cc:609
static DDSolid box(const DDName &name, double xHalf, double yHalf, double zHalf)
Creates a box with side length 2*xHalf, 2*yHalf, 2*zHalf.
Definition: DDSolid.cc:547
ii
Definition: cuy.py:589
const N & name() const
Definition: DDBase.h:59
const N & ddname() const
Definition: DDBase.h:61
~DDHCalTBCableAlgo() override
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
std::vector< double > zoff
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
Geom::Theta< T > theta() const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
static DDSolid polyhedra(const DDName &name, int sides, double startPhi, double deltaPhi, const std::vector< double > &z, const std::vector< double > &rmin, const std::vector< double > &rmax)
Creates a polyhedra (refere to Geant3 or Geant4 documentation)
Definition: DDSolid.cc:565