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 
17 
18 //#define EDM_ML_DEBUG
19 using namespace geant_units::operators;
20 
22 #ifdef EDM_ML_DEBUG
23  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating an instance";
24 #endif
25 }
26 
28 
29 
31  const DDVectorArguments & vArgs,
32  const DDMapArguments & ,
33  const DDStringArguments & sArgs,
34  const DDStringVectorArguments & ) {
35 
36  genMat = sArgs["MaterialName"];
37  nsectors = int (nArgs["NSector"]);
38  nsectortot = int (nArgs["NSectorTot"]);
39  nhalf = int (nArgs["NHalf"]);
40  rin = nArgs["RIn"];
41  theta = vArgs["Theta"];
42  rmax = vArgs["RMax"];
43  zoff = vArgs["ZOff"];
44 
45  absMat = sArgs["AbsMatName"];
46  thick = nArgs["Thickness"];
47  width1 = nArgs["Width1"];
48  length1 = nArgs["Length1"];
49  width2 = nArgs["Width2"];
50  length2 = nArgs["Length2"];
51  gap2 = nArgs["Gap2"];
52 
53 #ifdef EDM_ML_DEBUG
54  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: General material "
55  << genMat << "\tSectors " << nsectors << ", "
56  << nsectortot << "\tHalves " << nhalf
57  << "\tRin " << rin;
58  for (unsigned int i = 0; i < theta.size(); i++)
59  edm::LogVerbatim("HCalGeom") << "\t" << i << " Theta " << theta[i]
60  << " rmax " << rmax[i] << " zoff " << zoff[i];
61  edm::LogVerbatim("HCalGeom") << "\tCable mockup made of " << absMat
62  << "\tThick " << thick << "\tLength and width "
63  << length1 << ", " << width1 <<" and "
64  << length2 << ", " << width2 << " Gap " << gap2;
65 #endif
66  idName = sArgs["MotherName"];
68  rotns = sArgs["RotNameSpace"];
69 #ifdef EDM_ML_DEBUG
70  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Parent "
71  << parent().name() << " idName " << idName
72  << " NameSpace " << idNameSpace
73  << " for solids etc. and " << rotns
74  << " for rotations";
75 #endif
76 }
77 
79 
80 #ifdef EDM_ML_DEBUG
81  edm::LogVerbatim("HCalGeom") << "==>> Constructing DDHCalTBCableAlgo...";
82 #endif
83 
84  double alpha = 1._pi/nsectors;
85  double dphi = nsectortot*2._pi/nsectors;
86 
87  double zstep0 = zoff[1]+rmax[1]*tan(theta[1])+(rin-rmax[1])*tan(theta[2]);
88  double zstep1 = zstep0+thick/cos(theta[2]);
89  double zstep2 = zoff[3];
90 
91  double rstep0 = rin + (zstep2-zstep1)/tan(theta[2]);
92  double rstep1 = rin + (zstep1-zstep0)/tan(theta[2]);
93 
94  std::vector<double> pgonZ = {zstep0, zstep1, zstep2,
95  zstep2+thick/cos(theta[2])};
96 
97  std::vector<double> pgonRmin = {rin, rin, rstep0, rmax[2]};
98  std::vector<double> pgonRmax = {rin, rstep1, rmax[2], rmax[2]};
99 
100  std::string name("Null");
101  DDSolid solid;
103  nsectortot, -alpha, dphi, pgonZ,
104  pgonRmin, pgonRmax);
105 #ifdef EDM_ML_DEBUG
106  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: "
108  << " Polyhedra made of " << genMat << " with "
109  << nsectortot << " sectors from "
110  << convertRadToDeg(-alpha) << " to "
111  << convertRadToDeg(-alpha+dphi) << " and with "
112  << pgonZ.size() << " sections";
113  for (unsigned int i = 0; i <pgonZ.size(); i++)
114  edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[i] << "\tRmin = "
115  << pgonRmin[i] << "\tRmax = " << pgonRmax[i];
116 #endif
118  DDMaterial matter(matname);
119  DDLogicalPart genlogic(solid.ddname(), matter, solid);
120 
121  DDName parentName = parent().name();
122  DDTranslation r0(0.0, 0.0, 0.0);
123  DDRotation rot;
124  cpv.position(DDName(idName, idNameSpace), parentName, 1, r0, rot);
125 #ifdef EDM_ML_DEBUG
126  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: "
128  << " number 1 positioned in " << parentName
129  << " at " << r0 << " with "<<rot;
130 #endif
131  if (nhalf != 1) {
132  rot = DDRotation(DDName("180D", rotns));
133  cpv.position(DDName(idName, idNameSpace), parentName, 2, r0, rot);
134 #ifdef EDM_ML_DEBUG
135  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: "
137  <<" number 2 positioned in " << parentName
138  << " at " << r0 << " with " << rot;
139 #endif
140  }
141 
142  //Construct sector (from -alpha to +alpha)
143  name = idName + "Module";
144 #ifdef EDM_ML_DEBUG
145  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: "
146  << DDName(name,idNameSpace)
147  << " Polyhedra made of " << genMat
148  << " with 1 sector from "
149  << convertRadToDeg(-alpha) << " to "
150  << convertRadToDeg(alpha) << " and with "
151  << pgonZ.size() << " sections";
152  for (unsigned int i = 0; i < pgonZ.size(); i++)
153  edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[i] << "\tRmin = "
154  << pgonRmin[i] << "\tRmax = " << pgonRmax[i];
155 #endif
157  1, -alpha, 2*alpha, pgonZ,
158  pgonRmin, pgonRmax);
159  DDLogicalPart seclogic(solid.ddname(), matter, solid);
160 
161  for (int ii=0; ii<nsectortot; ii++) {
162  double phi = ii*2*alpha;
164  std::string rotstr("NULL");
165  if (phi != 0) {
166  rotstr = "R" + formatAsDegreesInInteger(phi);
167  rotation = DDRotation(DDName(rotstr, rotns));
168  if (!rotation) {
169 #ifdef EDM_ML_DEBUG
170  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a new "
171  << "rotation " << rotstr << "\t90,"
172  << convertRadToDeg(phi) << ",90,"
173  << (90+convertRadToDeg(phi)) << ", 0, 0";
174 #endif
175  rotation = DDrot(DDName(rotstr, idNameSpace), 90._deg, phi, 90._deg,
176  (90._deg+phi), 0, 0);
177  }
178  }
179 
180  cpv.position(seclogic, genlogic, ii+1, DDTranslation(0.0, 0.0, 0.0),
181  rotation);
182 #ifdef EDM_ML_DEBUG
183  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << seclogic.name()
184  << " number " << ii+1 << " positioned in "
185  << genlogic.name() << " at (0,0,0) with "
186  << rotation;
187 #endif
188  }
189 
190  //Now a trapezoid of air
191  double rinl = pgonRmin[0] + thick * sin(theta[2]);
192  double routl = pgonRmax[2] - thick * sin(theta[2]);
193  double dx1 = rinl * tan(alpha);
194  double dx2 = 0.90 * routl * tan(alpha);
195  double dy = 0.50 * thick;
196  double dz = 0.50 * (routl -rinl);
197  name = idName + "Trap";
198  solid = DDSolidFactory::trap(DDName(name, idNameSpace), dz, 0, 0, dy, dx1,
199  dx1, 0, dy, dx2, dx2, 0);
200 #ifdef EDM_ML_DEBUG
201  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name()
202  << " Trap made of " << genMat
203  << " of dimensions " << dz << ", 0, 0, "
204  << dy << ", " << dx1 << ", " << dx1
205  << ", 0, " << dy << ", " << dx2 << ", " << dx2
206  <<", 0";
207 #endif
208  DDLogicalPart glog(solid.ddname(), matter, solid);
209 
210  std::string rotstr = name;
211 #ifdef EDM_ML_DEBUG
212  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation: "
213  << rotstr << "\t90, 270, "
214  << (180-convertRadToDeg(theta[2]))
215  << ", 0, " << (90-convertRadToDeg(theta[2]))
216  << ", 0";
217 #endif
218  rot = DDrot(DDName(rotstr, idNameSpace), 90._deg, 270._deg,
219  (180._deg-theta[2]), 0, (90._deg-theta[2]), 0);
220  DDTranslation r1(0.5*(rinl+routl), 0, 0.5*(pgonZ[1]+pgonZ[2]));
221  cpv.position(glog, seclogic, 1, r1, rot);
222 #ifdef EDM_ML_DEBUG
223  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << glog.name()
224  << " number 1 positioned in " << seclogic.name()
225  << " at " << r1 << " with " << rot;
226 #endif
227  //Now the cable of type 1
228  name = idName + "Cable1";
229  double phi = atan((dx2-dx1)/(2*dz));
230  double xmid = 0.5*(dx1+dx2)-1.0;
231  solid = DDSolidFactory::box(DDName(name, idNameSpace), 0.5*width1,
232  0.5*thick, 0.5*length1);
233 #ifdef EDM_ML_DEBUG
234  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name()
235  << " Box made of " << absMat << " of dimension "
236  << 0.5*width1 << ", " << 0.5*thick << ", "
237  << 0.5*length1;
238 #endif
239  DDName absname(DDSplit(absMat).first, DDSplit(absMat).second);
240  DDMaterial absmatter(absname);
241  DDLogicalPart cablog1(solid.ddname(), absmatter, solid);
242 
243  rotstr = idName + "Left";
244 #ifdef EDM_ML_DEBUG
245  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation "
246  << rotstr << "\t" << (90+convertRadToDeg(phi))
247  << ", 0, 90, 90, " << convertRadToDeg(phi)
248  << ", 0";
249 #endif
250  DDRotation rot2 = DDrot(DDName(rotstr, idNameSpace), (90._deg+phi), 0.0,
251  90._deg, 90._deg, phi, 0.0);
252  DDTranslation r2((xmid-0.5*width1*cos(phi)), 0, 0);
253  cpv.position(cablog1, glog, 1, r2, rot2);
254 #ifdef EDM_ML_DEBUG
255  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog1.name()
256  << " number 1 positioned in " << glog.name()
257  << " at " << r2 << " with " << rot2;
258 #endif
259  rotstr = idName + "Right";
260 #ifdef EDM_ML_DEBUG
261  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation "
262  << rotstr << "\t" << (90-convertRadToDeg(phi))
263  << ", 0, 90, 90, " << convertRadToDeg(-phi)
264  << ", 0";
265 #endif
266  DDRotation rot3 = DDrot(DDName(rotstr, idNameSpace), (90._deg-phi), 0,
267  90._deg, 90._deg, -phi, 0);
268  DDTranslation r3(-(xmid-0.5*width1*cos(phi)), 0, 0);
269  cpv.position(cablog1, glog, 2, r3, rot3);
270 #ifdef EDM_ML_DEBUG
271  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog1.name()
272  << " number 2 positioned in " << glog.name()
273  << " at " << r3 << " with " << rot3;
274 #endif
275  //Now the cable of type 2
276  name = idName + "Cable2";
277  solid = DDSolidFactory::box(DDName(name, idNameSpace), 0.5*width2,
278  0.5*thick, 0.5*length2);
279 #ifdef EDM_ML_DEBUG
280  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name()
281  << " Box made of " << absMat << " of dimension "
282  << 0.5*width2 << ", " << 0.5*thick << ", "
283  << 0.5*length2;
284 #endif
285  DDLogicalPart cablog2(solid.ddname(), absmatter, solid);
286 
287  double xpos = 0.5*(width2+gap2);
288  cpv.position(cablog2, glog, 1, DDTranslation(xpos, 0.0, 0.0), DDRotation());
289 #ifdef EDM_ML_DEBUG
290  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog2.name()
291  << " number 1 positioned in " << glog.name()
292  << " at (" << xpos << ", 0, 0) with no "
293  << "rotation";
294 #endif
295  cpv.position(cablog2, glog, 2, DDTranslation(-xpos, 0.0, 0.0), DDRotation());
296 #ifdef EDM_ML_DEBUG
297  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog2.name()
298  << " number 2 positioned in " << glog.name()
299  << " at (" <<-xpos << ", 0, 0) with no "
300  << "rotation";
301 
302  edm::LogVerbatim("HCalGeom") << "<<== End of DDHCalTBCableAlgo construction";
303 #endif
304 }
std::vector< double > theta
float alpha
Definition: AMPTWrapper.h:95
std::vector< double > rmax
const N & name() const
Definition: DDBase.h:74
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:43
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
constexpr NumType convertRadToDeg(NumType radians)
Definition: GeantUnits.h:98
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
std::string formatAsDegreesInInteger(double radianVal)
Definition: DDTypes.cc:86
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:68
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:80
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:792
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:704
ii
Definition: cuy.py:590
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
~DDHCalTBCableAlgo() override
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
std::vector< double > zoff
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
std::string idNameSpace
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:730
const N & ddname() const
Definition: DDBase.h:76