EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicCadWizardCylinder.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicCadWizardCylinder.cxx
1 
2 
3 #include <gp_Cylinder.hxx>
4 
5 #include <BRepPrimAPI_MakeCylinder.hxx>
6 
7 #include <TGeoTube.h>
8 
9 #include <EicCadWizardCylinder.h>
10 
11 // =======================================================================================
12 
13 EicCadWizardCylinder::EicCadWizardCylinder(const gp_Cylinder &cylinder, const gp_Pnt *bcenter, double bradius)
14 {
15  double r = cylinder.Radius();
16 
17  gp_Ax1 ax1 = cylinder.Axis();
18  gp_Dir dir = ax1.Direction();
19  gp_Ax2 ax2 = cylinder.Position().Ax2();
20  gp_Pnt x0 = cylinder.Location();
21  double dist_to_sphere = cylinder.Location().Distance(*bcenter);
22  double safe_dimension = dist_to_sphere + bradius;
23  double t = safe_dimension;
24  gp_Pnt x1(x0.X() - t*dir.X(), x0.Y()- t*dir.Y(), x0.Z()- t*dir.Z());
25  ax2.SetLocation(x1);
26  ax2.SetDirection(dir);
27  mSolid = new TopoDS_Shape(BRepPrimAPI_MakeCylinder(ax2, r, 2 * safe_dimension).Solid());
28 
29  mCylinder = new gp_Cylinder(gp_Ax3(ax2), r);
30  mDimension = safe_dimension;
31 } // EicCadWizardCylinder::EicCadWizardCylinder()
32 
33 // ---------------------------------------------------------------------------------------
34 
36 {
37  // Check object type first;
38  const EicCadWizardCylinder *other = dynamic_cast<const EicCadWizardCylinder*>(cut);
39  if (!other) return false;
40 
41  const gp_Cylinder *cyl = mCylinder, *cyr = other->mCylinder;
42 
43  // Do not need to check length (assume cylinders are "infinitely" long);
44  if (!cyl->Axis().Direction().IsParallel(cyr->Axis().Direction(), _ANGULAR_TOLERANCE_))
45  return false;
46 
47  // Radius match;
48  if (fabs(cyl->Radius() - cyr->Radius()) > _SPATIAL_TOLERANCE_) return false;
49 
50  {
51  gp_XYZ diff(cyl->Location().X() - cyr->Location().X(),
52  cyl->Location().Y() - cyr->Location().Y(),
53  cyl->Location().Z() - cyr->Location().Z());
54 
55  // Check transverse component only (it can be, that two origins are sitting
56  // on the same axis);
57  gp_XYZ axis(cyl->Axis().Direction().X(),
58  cyl->Axis().Direction().Y(),
59  cyl->Axis().Direction().Z());
60  double pro = diff.Dot(axis);
61  gp_XYZ vpro = pro*axis, vnorm = diff - vpro;
62 
63  if (vnorm.Modulus() > _SPATIAL_TOLERANCE_) return false;
64  }
65 
66  return true;
67 } // EicCadWizardCylinder::IsEqual()
68 
69 // ---------------------------------------------------------------------------------------
70 
71 TGeoCombiTrans *EicCadWizardCylinder::BuildRootVolume(const char *vname, const char *tname)
72 {
73  new TGeoTube(vname, 0.0, mCylinder->Radius(), mDimension);
74 
75  return Ax3ToCombiTrans(tname, mCylinder->Position(), mDimension);
76 
77  //printf("CY (%s) x0[]: %f %f %f, r = %f\n", facets[fc].first ? "-" : "*",
78  // mCylinder->Location().X(),
79  // mCylinder->Location().Y(), mCylinder->Location().Z(), mCylinder->Radius());
80  //break;
81 } // EicCadWizardCylinder::BuildRootVolume()
82 
83 // =======================================================================================