CMS 3D CMS Logo

DDShapes.cc
Go to the documentation of this file.
6 
7 #include "DD4hep/Shapes.h"
8 #include <TGeoBBox.h>
9 
10 using namespace cms;
11 using namespace cms::dd;
12 using namespace angle_units::operators;
13 
14 template <class T>
16  return (static_cast<int>(val + 0.5) != 0);
17 }
18 
20  if (fview.isABox())
21  return (DDSolidShape::ddbox);
22 
23  if (fview.isAConeSeg())
24  return (DDSolidShape::ddcons);
25 
26  if (fview.isATrapezoid())
27  return (DDSolidShape::ddtrap);
28 
29  if (fview.isATubeSeg())
30  return (DDSolidShape::ddtubs);
31 
32  if (fview.isATruncTube())
34 
35  if (fview.isAPseudoTrap()) // Rarely used -- put it last
37 
39 }
40 
41 // ** DDBox
43  if (valid) {
44  const TGeoBBox *box = fv.getShapePtr<TGeoBBox>();
45  dx_ = box->GetDX();
46  dy_ = box->GetDY();
47  dz_ = box->GetDZ();
48  }
49 }
50 
51 // ** end DDBox
52 
53 // ** DDCons
54 
56  if (valid) {
57  const TGeoConeSeg *coneSeg = fv.getShapePtr<TGeoConeSeg>();
58  dz_ = coneSeg->GetDZ();
59  phi1_ = convertDegToRad(coneSeg->GetPhi1());
60  phi2_ = convertDegToRad(coneSeg->GetPhi2()) - phi1_;
61 
62  // Limit to range -pi to pi
64  rmin1_ = coneSeg->GetRmin1();
65  rmin2_ = coneSeg->GetRmin2();
66  rmax1_ = coneSeg->GetRmax1();
67  rmax2_ = coneSeg->GetRmax2();
68  }
69 }
70 
71 // ** end of DDCons
72 
73 // ** DDPseudoTrap
74 // No longer used -- this code does not work right
75 /*
76 DDPseudoTrap::DDPseudoTrap(const DDFilteredView &fv) : valid{fv.isAPseudoTrap()} {
77  if (valid) {
78  auto trap = fv.solid();
79  std::vector<double> params = trap.dimensions();
80  minusX_ = params[0];
81  plusX_ = params[1];
82  minusY_ = params[2];
83  plusY_ = params[3];
84  dz_ = params[4];
85  rmax_ = params[5];
86  minusZSide_ = convFpToBool(params[6]);
87  }
88 }
89 */
90 // ** end of DDPseudoTrap
91 
92 // *** DDTrap
93 
95  if (valid) {
96  const TGeoTrap *trap = fv.getShapePtr<TGeoTrap>();
97  halfZ_ = trap->GetDz();
98  theta_ = convertDegToRad(trap->GetTheta());
99  phi_ = convertDegToRad(trap->GetPhi());
100  x1_ = trap->GetBl1(); // Along x, low y, low z
101  x2_ = trap->GetTl1(); // Along x, high y, low z
102  y1_ = trap->GetH1(); // Along y, low z
103  y2_ = trap->GetH2(); // Along y, high z
104  x3_ = trap->GetBl2(); // Along x, low y, high z
105  x4_ = trap->GetTl2(); // Along x, high y, high z
106  alpha1_ = convertDegToRad(trap->GetAlpha1());
107  alpha2_ = convertDegToRad(trap->GetAlpha2());
108  }
109 }
110 
111 // *** end of DDTrap
112 
113 // ** DDTubs
114 
116  if (valid) {
117  const TGeoTubeSeg *tube = fv.getShapePtr<TGeoTubeSeg>();
118  zHalf_ = tube->GetDz();
119  rIn_ = tube->GetRmin();
120  rOut_ = tube->GetRmax();
121  startPhi_ = convertDegToRad(tube->GetPhi1());
122  deltaPhi_ = convertDegToRad(tube->GetPhi2()) - startPhi_;
123 
124  // Limit to range -pi to pi
126  }
127 }
128 
129 // *** end of DDTubs
130 
131 // ** DDTruncTubs
132 
134  if (valid) {
135  auto tube = fv.solid();
136  std::vector<double> params = tube.dimensions();
137  if (params.size() < 16) {
138  edm::LogError("DDShapes DDTruncTubs") << "Truncated tube parameters list too small";
139  return;
140  }
141  for (unsigned int index = 0; index < params.size(); ++index) {
142  edm::LogVerbatim("DDShapes DDTruncTubs") << "DDTruncTubs param " << index << " = " << params[index];
143  }
144  rIn_ = params[1];
145  rOut_ = params[2];
146  zHalf_ = params[3];
147  startPhi_ = convertDegToRad(params[4]);
148  deltaPhi_ = convertDegToRad(params[5]) - startPhi_;
149  // Limit to range -pi to pi
151 
152  dd4hep::Rotation3D cutRotation(
153  params[6], params[7], params[8], params[9], params[10], params[11], params[12], params[13], params[14]);
154  double translation = params[15];
155  DD3Vector xUnitVec(1., 0., 0.);
156  DD3Vector rotatedVec = cutRotation(xUnitVec);
157  double cosAlpha = xUnitVec.Dot(rotatedVec);
158  double sinAlpha = sqrt(1. - cosAlpha * cosAlpha);
159  if (sinAlpha == 0.)
160  sinAlpha = 1.; // Prevent divide by 0
161  cutInside_ = true;
162  cutAtStart_ = translation + (rOut_ / sinAlpha);
163  if (cutAtStart_ > rOut_ || cutAtStart_ < 0.) {
164  cutAtStart_ = translation - (rOut_ / sinAlpha);
165  cutInside_ = false;
166  }
167  double alpha = std::acos(cosAlpha);
168  if (std::abs(deltaPhi_) != 1._pi)
169  cutAtDelta_ = cutAtStart_ * (sinAlpha / std::sin(deltaPhi_ + alpha));
170 
171  /*
172  * If we need to check the parameters in the TGeoCompositeShape
173  const TGeoCompositeShape *compShape = fv.getShapePtr<TGeoCompositeShape>();
174  const TGeoBoolNode *boolNode = compShape->GetBoolNode();
175  const TGeoMatrix *lmatrix = boolNode->GetLeftMatrix();
176  auto showMats = [] (const TGeoMatrix *matrix) -> void {
177  const Double_t *rotMatrix = matrix->GetRotationMatrix();
178  const Double_t *translat = matrix->GetTranslation();
179  edm::LogVerbatim("DDShapes DDTruncTubs") << "translation (" << translat[0] << ", "
180  << translat[1] << ", " << translat[2] << ")\n";
181  edm::LogVerbatim("DDShapes DDTruncTubs") << "rotation 1 (" << rotMatrix[0] << ", "
182  << rotMatrix[1] << ", " << rotMatrix[2] << ")\n";
183  edm::LogVerbatim("DDShapes DDTruncTubs") << "rotation 2 (" << rotMatrix[3] << ", "
184  << rotMatrix[4] << ", " << rotMatrix[2] << ")\n";
185  edm::LogVerbatim("DDShapes DDTruncTubs") << "rotation 3 (" << rotMatrix[6] << ", "
186  << rotMatrix[7] << ", " << rotMatrix[8] << ")\n";
187  };
188  edm::LogVerbatim("DDShapes DDTruncTubs") << "Left matrix";
189  showMats(lmatrix);
190  const TGeoMatrix *rmatrix = boolNode->GetRightMatrix();
191  edm::LogVerbatim("DDShapes DDTruncTubs") << "Right matrix";
192  showMats(rmatrix);
193  */
194  }
195 }
196 
197 // *** end of DDTruncTubs
double startPhi_
Definition: DDShapes.h:47
double zHalf_
Definition: DDShapes.h:44
double alpha2_
Definition: DDShapes.h:129
DDSolidShape getCurrentShape(const cms::DDFilteredView &fview)
Definition: DDShapes.cc:19
constexpr long double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
const bool valid
Definition: DDShapes.h:41
const bool valid
Definition: DDShapes.h:116
double rIn_
Definition: DDShapes.h:45
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
double dx_
Definition: DDShapes.h:26
double rmin2_
Definition: DDShapes.h:71
DDTrap(void)=delete
double theta_
Definition: DDShapes.h:120
bool isAConeSeg() const
DDBox(void)=delete
bool isAPseudoTrap() const
double rOut_
Definition: DDShapes.h:46
bool convFpToBool(T val)
Definition: DDShapes.cc:15
double dz_
Definition: DDShapes.h:68
double alpha1_
Definition: DDShapes.h:128
const bool valid
Definition: DDShapes.h:23
double phi1_
Definition: DDShapes.h:73
T sqrt(T t)
Definition: SSEVec.h:19
double dy_
Definition: DDShapes.h:26
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const bool valid
Definition: DDShapes.h:206
double dz_
Definition: DDShapes.h:26
double rmax1_
Definition: DDShapes.h:70
const bool valid
Definition: DDShapes.h:65
double rmax2_
Definition: DDShapes.h:72
double rmin1_
Definition: DDShapes.h:69
Namespace of DDCMS conversion namespace.
double halfZ_
Definition: DDShapes.h:119
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >> DD3Vector
bool isABox() const
DDTruncTubs(void)=delete
bool isATruncTube() const
DDCons(void)=delete
DDTubs(void)=delete
bool isATubeSeg() const
double phi2_
Definition: DDShapes.h:74
alpha
zGenParticlesMatch = cms.InputTag(""),
double deltaPhi_
Definition: DDShapes.h:48
long double T
bool isATrapezoid() const
DDSolidShape
Definition: DDSolidShapes.h:62