EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicCadWizardCone.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicCadWizardCone.cxx
1 
2 #include <gp_Cone.hxx>
3 
4 #include <BRepPrimAPI_MakeCone.hxx>
5 
6 #include <EicCadWizardCone.h>
7 
8 #include <TGeoCone.h>
9 
10 // =======================================================================================
11 
12 EicCadWizardCone::EicCadWizardCone(const gp_Cone &cone, const gp_Pnt *bcenter, double bradius)
13 {
14  //gp_Cone cone = es->Cone();
15  gp_Pnt apex = cone.Apex();
16  gp_Ax1 axis = cone.Axis();
17  gp_Ax2 ax2(apex, axis.Direction());
18 
19  double dist_to_sphere = apex.Distance(*bcenter);
20  // This should suffice in all cases;
21  double safe_dimension = dist_to_sphere + bradius;
22  double semiAngle = cone.SemiAngle(), r0 = 0.0, r1 = safe_dimension*tan(semiAngle);
23 
24  mCone = new gp_Cone(gp_Ax3(ax2), semiAngle, r0);
25  mDimension = safe_dimension;
26  mSolid = new TopoDS_Shape(BRepPrimAPI_MakeCone(ax2, r0, r1, safe_dimension).Solid());
27 } // EicCadWizardCone::EicCadWizardCone()
28 
29 // ---------------------------------------------------------------------------------------
30 
32 {
33  // Check object type first;
34  const EicCadWizardCone *other = dynamic_cast<const EicCadWizardCone*>(cut);
35  if (!other) return false;
36 
37  const gp_Cone *col = mCone, *cor = other->mCone;
38 
39  // Axis direction;
40  if (!col->Axis().Direction().IsParallel(cor->Axis().Direction(), _ANGULAR_TOLERANCE_))
41  return false;
42 
43  // Opening angle;
44  if (fabs(col->SemiAngle() - cor->SemiAngle()) > _ANGULAR_TOLERANCE_) return false;
45 
46  // Apex;
47  {
48  double dc = sqrt(SQR(col->Location().X() - cor->Location().X()) +
49  SQR(col->Location().Y() - cor->Location().Y()) +
50  SQR(col->Location().Z() - cor->Location().Z()));
51 
52  if (dc > _SPATIAL_TOLERANCE_) return false;
53  }
54 
55  return true;
56 } // EicCadWizardCone::IsEqual()
57 
58 // ---------------------------------------------------------------------------------------
59 
60 TGeoCombiTrans *EicCadWizardCone::BuildRootVolume(const char *vname, const char *tname)
61 {
62  new TGeoCone(vname, mDimension/2.,
63  0.0, 0.0,
64  0.0, mDimension*tan(mCone->SemiAngle()));
65 
66  return Ax3ToCombiTrans(tname, mCone->Position(), mDimension/2.);
67 
68  //printf("CO (%s) x0[]: %f %f %f\n", facets[fc].first ? "-" : "*",
69  // cone->Location().X(), cone->Location().Y(), cone->Location().Z());
70 } // EicCadWizardCone::BuildRootVolume()
71 
72 // =======================================================================================