ATLAS Offline Software
SurfaceToSoNode.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Implementation of class SurfaceToSoNode //
8 // //
9 // Author: Andreas Salzburger <Andreas.Salzburger@cern.ch> (primary) //
10 // Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
11 // //
12 // Initial VP1 version: June 2007 //
13 // //
15 
18 
19 #include <Inventor/C/errors/debugerror.h>
20 //#include <Inventor/nodes/SoNode.h>
21 #include <Inventor/nodes/SoSeparator.h>
22 #include <Inventor/nodes/SoTransform.h>
23 #include <Inventor/nodes/SoVertexProperty.h>
24 #include <Inventor/nodes/SoLineSet.h>
26 #include "VP1HEPVis/nodes/SoTubs.h"
28 #include "VP1HEPVis/SbPolyhedron.h"
29 
30 #include "TrkSurfaces/Surface.h"
37 #include "TrkSurfaces/DiscBounds.h"
43 #include "TrkSurfaces/NoBounds.h"
44 
45 #include "GeoModelKernel/GeoSimplePolygonBrep.h"
46 
47 const double SurfaceToSoNode::surfaceThickness = 0.1;
48 
50 {
53 }
54 
56 
57 SoNode* SurfaceToSoNode::translateSurface(const Trk::Surface& sf, const bool& simple) const
58 {
59 
60  SoNode* sono =0;
61  const Trk::CylinderSurface* ccsf = dynamic_cast<const Trk::CylinderSurface*>(&sf);
62  if (ccsf) sono = this->translateCylinderSurface(*ccsf);
63 
64  const Trk::DiscSurface* cdsf = sono ? 0 : dynamic_cast<const Trk::DiscSurface*>(&sf);
65  if (cdsf) sono = this->translateDiscSurface(*cdsf);
66 
67  const Trk::PlaneSurface* cpsf = sono ? 0 : dynamic_cast<const Trk::PlaneSurface*>(&sf);
68  if (cpsf) sono = this->translatePlaneSurface(*cpsf);
69 
70  const Trk::StraightLineSurface* cssf = sono ? 0 : dynamic_cast<const Trk::StraightLineSurface*>(&sf);
71  if (cssf) sono = this->translateStraightLineSurface(*cssf, simple);
72 
73  const Trk::PerigeeSurface* cpersf = sono ? 0 : dynamic_cast<const Trk::PerigeeSurface*>(&sf);
74  if (cpersf) sono = this->translatePerigeeSurface(*cpersf);
75 
76  if (!sono) {
77  std::cout<<"ERROR! Surface unknown!"<<std::endl;
78  return 0;
79  }
80 
81  // place and transform them
82  SoSeparator* sosep = new SoSeparator();
83 
84  // Horrible hack for ITK annulus bounds. What should really happen is we draw the surface where the bounds are. But this was never done before.
85  Amg::Transform3D transform = sf.transform();
86  if (cpsf) {
87  const Trk::AnnulusBounds* cannulus = dynamic_cast<const Trk::AnnulusBounds*>(&(cpsf->bounds()));
88  if (cannulus){
89  Amg::Vector3D vec(0.0,0.5*(cannulus->maxR()+cannulus->minR()),0.0);
90  transform.translate(vec);
91  }
92  }
93 
94  SoTransform* sotra = VP1LinAlgUtils::toSoTransform(transform);
95  sosep->addChild(sotra);
96  sosep->addChild(sono);
97 
98  return sosep;
99 }
100 
102 {
103  const Trk::RectangleBounds* crecbo = dynamic_cast<const Trk::RectangleBounds*>(&(psf.bounds()));
104  if (crecbo){
105  SoGenericBox * gb = new SoGenericBox;
107  gb->drawEdgeLines.setValue(true);
108  return gb;
109  }
110 
111  const Trk::TrapezoidBounds* ctrabo = dynamic_cast<const Trk::TrapezoidBounds*>(&(psf.bounds()));
112  if (ctrabo){
113  SoGenericBox * gb = new SoGenericBox;
114  const double hminphi = ctrabo->minHalflengthPhi();
115  const double hmaxphi = ctrabo->maxHalflengthPhi();
116  const double heta = ctrabo->halflengthEta();
117  gb->setParametersForTrapezoid( 0.5*surfaceThickness/*dz*/, 0/*theta*/, 0/*phi*/, heta/*dy1*/,
118  hminphi/*dx1*/, hmaxphi/*dx2*/, heta/*dy2*/, hminphi/*dx3*/,
119  hmaxphi/*dx4*/, 0/*alp1*/, 0/*alp2*/ );
120  gb->drawEdgeLines.setValue(true);
121  return gb;
122  }
123  const Trk::RotatedTrapezoidBounds* crottrabo = dynamic_cast<const Trk::RotatedTrapezoidBounds*>(&(psf.bounds()));
124  if (crottrabo){
125  SoGenericBox * gb = new SoGenericBox;
126  const double hminphi = crottrabo->minHalflengthY();
127  const double hmaxphi = crottrabo->maxHalflengthY();
128  const double heta = crottrabo->halflengthX();
129  gb->setParametersForTrapezoid( 0.5*surfaceThickness/*dz*/, 0/*theta*/, 0/*phi*/, heta/*dy1*/,
130  hminphi/*dx1*/, hmaxphi/*dx2*/, heta/*dy2*/, hminphi/*dx3*/,
131  hmaxphi/*dx4*/, 0/*alp1*/, 0/*alp2*/ );
132  gb->drawEdgeLines.setValue(true);
133  return gb;
134  }
135  const Trk::DiamondBounds* cdiabo = dynamic_cast<const Trk::DiamondBounds*>(&(psf.bounds()));
136  if (cdiabo){
137  double dz=0.25;
138  std::vector<double> x,y;
139  x.push_back(cdiabo->minHalflengthX());y.push_back( -2*cdiabo->halflengthY1());
140  x.push_back(cdiabo->medHalflengthX());y.push_back( 0.);
141  if (cdiabo->halflengthY2()>0.) {
142  x.push_back(cdiabo->maxHalflengthX()); y.push_back( 2*cdiabo->halflengthY2());
143  x.push_back(-cdiabo->maxHalflengthX());y.push_back( 2*cdiabo->halflengthY2());
144  }
145  x.push_back(-cdiabo->medHalflengthX());y.push_back( 0.);
146  x.push_back(-cdiabo->minHalflengthX());y.push_back( -2*cdiabo->halflengthY1());
147 
148  SbPolyhedronPolygonXSect sbPoly(x,y,dz);
149  return new SoPolyhedron(sbPoly);
150  }
151 
152  const Trk::AnnulusBounds* cannulus = dynamic_cast<const Trk::AnnulusBounds*>(&(psf.bounds()));
153  if (cannulus){
154  SoGenericBox * gb = new SoGenericBox;
155  const double hminphi = 0.5*cannulus->minR()*cannulus->phi();
156  const double hmaxphi = 0.5*cannulus->maxR()*cannulus->phi();
157  const double heta = 0.5 * (cannulus->maxR() - cannulus->minR());
158  gb->setParametersForTrapezoid( 0.5*surfaceThickness/*dz*/, 0/*theta*/, 0/*phi*/, heta/*dy1*/,
159  hminphi/*dx1*/, hmaxphi/*dx2*/, heta/*dy2*/, hminphi/*dx3*/,
160  hmaxphi/*dx4*/, 0/*alp1*/, 0/*alp2*/ );
161  gb->drawEdgeLines.setValue(true);
162  return gb;
163  }
164  const Trk::NoBounds* nobo = dynamic_cast<const Trk::NoBounds*>(&(psf.bounds()));
165  if (nobo){
166  SoGenericBox * gb = new SoGenericBox;
167  gb->setParametersForBox(50.0,50.0,0.5*surfaceThickness);
168  gb->drawEdgeLines.setValue(false);
169  return gb;
170  }
171 
172  return 0;
173 }
174 
176 {
177  //std::cout<<"translateCylinderSurface"<<std::endl;
178 
179  double radius = csf.bounds().r();
180  double hlength = csf.bounds().halflengthZ();
181 
182  SoTubs* cylinderSurface = new SoTubs();
183  (*cylinderSurface).pRMin = radius-0.25;
184  (*cylinderSurface).pRMax = radius+0.25;
185  (*cylinderSurface).pDz = hlength;
186 
187  return cylinderSurface;
188 
189 }
190 
192 {
193  //std::cout<<"translateDiscSurface"<<std::endl;
194  const Trk::DiscBounds* cdbo = dynamic_cast<const Trk::DiscBounds*>(&(dsf.bounds()));
195  if (cdbo){
196  double iradius = cdbo->rMin();
197  double oradius = cdbo->rMax();
198  double halfphisec = cdbo->halfPhiSector();
199 
200  SoTubs* discSurface = new SoTubs();
201  (*discSurface).pRMin = iradius;
202  (*discSurface).pRMax = oradius;
203  (*discSurface).pDz = 0.25;
204 
205  if (fabs(halfphisec-M_PI)>10e-5){
206  // sweep back the rotation as the sweepangle starts from x-axis
207  (*discSurface).pSPhi = -halfphisec;
208  (*discSurface).pDPhi = 2.* halfphisec;
209  }
210 
211  return discSurface;
212  }
213  return 0;
214 }
215 
216 SoNode* SurfaceToSoNode::translateStraightLineSurface(const Trk::StraightLineSurface& slsf, const bool& simple ) const
217 {
218  //std::cout<<"translateStraightLineSurface"<<std::endl;
219  const Trk::CylinderBounds* ccbo = dynamic_cast<const Trk::CylinderBounds*>(&(slsf.bounds()));
220  if (ccbo){
221  double hlength = ccbo->halflengthZ();
222  if ( simple )
223  {
224  SoVertexProperty * scatVtxProperty = new SoVertexProperty();
225  scatVtxProperty->vertex.set1Value(0, 0.0,0.0,-hlength);
226  scatVtxProperty->vertex.set1Value(1, 0.0,0.0, hlength);
227  SoLineSet * lineSurface = new SoLineSet();
228  lineSurface->numVertices = 2;
229  lineSurface->vertexProperty = scatVtxProperty;
230  return lineSurface;
231  }
232 
233  double radius = ccbo->r();
234  SoTubs* lineSurface = new SoTubs();
235  (*lineSurface).pRMin = 0.;
236  (*lineSurface).pRMax = radius;
237  (*lineSurface).pDz = hlength;
238  return lineSurface;
239  }
240  return 0;
241 }
242 
244 {
245  //TK: Why do we need depend on the input???? FIXME
246  //std::cout<<"translatePerigeeSurface"<<std::endl;
247  SoTubs* perigeeSurface = new SoTubs();
248  (*perigeeSurface).pRMin = 0.;
249  (*perigeeSurface).pRMax = 5.;
250  (*perigeeSurface).pDz = 4000.;
251  return perigeeSurface;
252 }
TrapezoidBounds.h
Trk::RectangleBounds
Definition: RectangleBounds.h:38
SoGenericBox::setParametersForTrapezoid
void setParametersForTrapezoid(float dz, float theta, float phi, float dy1, float dx1, float dx2, float dy2, float dx3, float dx4, float alp1, float alp2)
Definition: SoGenericBox.cxx:293
Trk::DiamondBounds::halflengthY2
double halflengthY2() const
Trk::StraightLineSurface::bounds
virtual const SurfaceBounds & bounds() const override final
This method returns the bounds of the Surface by reference.
StraightLineSurface.h
DiscBounds.h
PerigeeSurface.h
RectangleBounds.h
Surface.h
Trk::AnnulusBounds::maxR
double maxR() const
This method returns the bigger radius.
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
SoTubs
SoTubs - Inventor version of the G4Tubs Geant Geometry entity.
Definition: SoTubs.h:50
SurfaceToSoNode::translateStraightLineSurface
SoNode * translateStraightLineSurface(const Trk::StraightLineSurface &slsf, const bool &simple=false) const
Definition: SurfaceToSoNode.cxx:216
Trk::RotatedTrapezoidBounds
Definition: RotatedTrapezoidBounds.h:45
Trk::DiamondBounds::minHalflengthX
double minHalflengthX() const
This method returns the halflength in X at minimal Y (first coordinate of local surface frame)
Trk::AnnulusBounds
Definition: AnnulusBounds.h:45
Trk::DiscBounds::halfPhiSector
double halfPhiSector() const
This method returns the halfPhiSector which is covered by the disc.
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Trk::CylinderSurface::bounds
virtual const CylinderBounds & bounds() const override final
This method returns the CylinderBounds by reference (NoBounds is not possible for cylinder)
Trk::AnnulusBounds::phi
double phi() const
This method returns the opening angle.
Trk::DiscSurface
Definition: DiscSurface.h:54
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
x
#define x
Trk::RotatedTrapezoidBounds::halflengthX
double halflengthX() const
This method returns the minimal halflength in X (first coordinate of local surface frame)
Trk::TrapezoidBounds::minHalflengthPhi
double minHalflengthPhi() const
This method returns the minimal halflength in phi (first coordinate of local surface frame)
Trk::DiscBounds::rMax
double rMax() const
This method returns outer radius.
SurfaceToSoNode::translatePerigeeSurface
SoNode * translatePerigeeSurface(const Trk::PerigeeSurface &persf) const
Definition: SurfaceToSoNode.cxx:243
SurfaceToSoNode::~SurfaceToSoNode
virtual ~SurfaceToSoNode()
Definition: SurfaceToSoNode.cxx:55
Trk::RectangleBounds::halflengthEta
double halflengthEta() const
This method returns the halflength in Eta (second coordinate of local surface frame)
VP1LinAlgUtils.h
Trk::DiamondBounds::medHalflengthX
double medHalflengthX() const
This method returns the (maximal) halflength in X (first coordinate of local surface frame)
DiamondBounds.h
SoGenericBox::initClass
static void initClass()
Definition: SoGenericBox.cxx:62
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
SoPolyhedron.h
Trk::DiscBounds::rMin
double rMin() const
This method returns inner radius.
Trk::DiamondBounds
Definition: DiamondBounds.h:37
AnnulusBounds.h
Trk::RectangleBounds::halflengthPhi
double halflengthPhi() const
This method returns the halflength in phi (first coordinate of local surface frame)
Trk::CylinderSurface
Definition: CylinderSurface.h:55
Trk::CylinderBounds
Definition: CylinderBounds.h:46
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Trk::DiscSurface::bounds
const SurfaceBounds & bounds() const override final
This method returns the bounds by reference.
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
CylinderSurface.h
SurfaceToSoNode::translateSurface
SoNode * translateSurface(const Trk::Surface &sf, const bool &simple=false) const
Definition: SurfaceToSoNode.cxx:57
Trk::AnnulusBounds::minR
double minR() const
This method returns the smaller radius.
SurfaceToSoNode::SurfaceToSoNode
SurfaceToSoNode()
Definition: SurfaceToSoNode.cxx:49
SoTubs::initClass
static void initClass()
Class Initializer, required.
Definition: SoTubs.cxx:68
SoGenericBox::setParametersForBox
void setParametersForBox(float dx, float dy, float dz, float xcenter=0.0, float ycenter=0.0, float zcenter=0.0)
Definition: SoGenericBox.cxx:179
Trk::RotatedTrapezoidBounds::maxHalflengthY
double maxHalflengthY() const
This method returns the halflength in Y (second coordinate of local surface frame)
SurfaceToSoNode::surfaceThickness
static const double surfaceThickness
Definition: SurfaceToSoNode.h:55
Trk::TrapezoidBounds::halflengthEta
double halflengthEta() const
This method returns the halflength in eta (second coordinate of local surface frame)
SurfaceToSoNode::translateDiscSurface
SoNode * translateDiscSurface(const Trk::DiscSurface &dsf) const
Definition: SurfaceToSoNode.cxx:191
Trk::RotatedTrapezoidBounds::minHalflengthY
double minHalflengthY() const
This method returns the maximal halflength in X (first coordinate of local surface frame)
Trk::DiamondBounds::maxHalflengthX
double maxHalflengthX() const
This method returns the halflength in X at maximal Y (first coordinate of local surface frame)
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
Trk::TrapezoidBounds
Definition: TrapezoidBounds.h:43
SoGenericBox::drawEdgeLines
SoSFBool drawEdgeLines
Definition: SoGenericBox.h:33
Trk::NoBounds
Definition: NoBounds.h:30
CylinderBounds.h
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
y
#define y
Trk::DiamondBounds::halflengthY1
double halflengthY1() const
This method returns the halflength in Y of trapezoid at negative/positive Y (second coordinate)
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
Trk::TrapezoidBounds::maxHalflengthPhi
double maxHalflengthPhi() const
This method returns the maximal halflength in phi (first coordinate of local surface frame)
Trk::PlaneSurface
Definition: PlaneSurface.h:64
PlaneSurface.h
Trk::PlaneSurface::bounds
virtual const SurfaceBounds & bounds() const override final
This method returns the bounds by reference, static NoBounds in case of no boundaries.
SoGenericBox
Definition: SoGenericBox.h:26
SoTubs.h
DiscSurface.h
SurfaceToSoNode.h
SoPolyhedron
SoPolyhedron is an Inventor encapsulation of the HepPolyedron class written by E.Chernyaev.
Definition: SoPolyhedron.h:47
RotatedTrapezoidBounds.h
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
SurfaceToSoNode::translatePlaneSurface
SoNode * translatePlaneSurface(const Trk::PlaneSurface &psf) const
Definition: SurfaceToSoNode.cxx:101
SurfaceToSoNode::translateCylinderSurface
SoNode * translateCylinderSurface(const Trk::CylinderSurface &csf) const
Definition: SurfaceToSoNode.cxx:175
VP1LinAlgUtils::toSoTransform
static SoTransform * toSoTransform(const HepGeom::Transform3D &, SoTransform *t=0)
Definition: VP1LinAlgUtils.cxx:40
SbPolyhedron.h
SoGenericBox.h
NoBounds.h
Trk::StraightLineSurface
Definition: StraightLineSurface.h:51
Trk::DiscBounds
Definition: DiscBounds.h:44
Trk::CylinderBounds::halflengthZ
double halflengthZ() const
This method returns the halflengthZ.
Trk::CylinderBounds::r
virtual double r() const override final
This method returns the radius.
SbPolyhedronPolygonXSect
Definition: SbPolyhedron.h:534