#include "TROOT.h" #include "TClass.h" #include "TObject.h" #include "TNamed.h" #include "TMath.h" #include "TRandom.h" #include "TRandom3.h" #include "TRotation.h" #include "TVector3.h" #include "TGeoManager.h" #include "TGeoMatrix.h" #include "TGeoMedium.h" #include "TGeoVolume.h" #include "TGeoNode.h" #include "TGeoShape.h" #include "TGeoBBox.h" #include "TGeoCompositeShape.h" void create_box() { TGeoManager *mgr = new TGeoManager( "box" , "Simple geometry" ); TGeoMedium *medium = 0; TGeoVolume *top = mgr->MakeBox( "top" , medium , 100 , 100 , 100 ); mgr->SetTopVolume( top ); TGeoBBox *box1 = new TGeoBBox( "box1" , 20 , 20 , 20 ); TGeoVolume *boxvol = new TGeoVolume( "boxvol" , box1 ); boxvol->SetLineColor( kRed ); top->AddNode( boxvol , 1 ); mgr->CloseGeometry(); mgr->SetNsegments(120); //top->Raytrace(); top->Draw(); Double_t safe_dist1; Double_t *point1; point1 = &safe_dist1; Double_t safe_dist2; Double_t *point2; point2 = &safe_dist2; Double_t pos1[3] = { 0. , 0. , -30.}; Double_t pos2[3] = { 0. , -30. , -30.}; Double_t dir1[3] = { 1. , 0. , 0.}; Double_t dir2[3] = { 0. , 1. , 0.}; Double_t dir3[3] = { 0. , 0. , 1.}; Double_t dist_to_box1 = 0.; Double_t dist_to_box2 = 0.; dist_to_box1 = box1->DistFromOutside( pos1 , dir3 , 1 , 100. , point1 ); cout << "Distance point 1 to box = " << dist_to_box1 << endl; cout << "Safe distance point 1 to box = " << safe_dist1 << endl; dist_to_box2 = box1->DistFromOutside( pos2 , dir3 , 1 , 100. , point2 ); cout << "Distance point 2 to box = " << dist_to_box2 << endl; cout << "Safe distance point 2 to box = " << safe_dist2 << endl; }