#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 test_DistFromInside() { gSystem->Load("libGeom"); TGeoManager *mgr = new TGeoManager( "box" , "Simple geometry" ); TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0); TGeoMedium *med = new TGeoMedium("Vacuum",1, matVacuum); TGeoVolume *top = mgr->MakeBox( "top" , med , 100 , 100 , 100 ); mgr->SetTopVolume( top ); TGeoVolume *boxvol = mgr->MakeBox("box", med, 20, 20, 20); boxvol->SetLineColor( kRed ); boxvol->SetTransparency( 80 ); top->AddNode( boxvol, 0); TGeoBBox * box = boxvol->GetShape(); mgr->CloseGeometry(); TEveManager::Create(); TGeoNode* node = gGeoManager->GetTopNode(); TEveGeoTopNode* en = new TEveGeoTopNode(gGeoManager, node); en->SetVisLevel(4); en->GetNode()->GetVolume()->SetVisibility(kFALSE); gEve->AddGlobalElement(en); Double_t pt[3] = { 0. , 0. , -20.}; double theta = 45./180*3.14; double phi = 45./180*3.14; Double_t dir[3] = { sin(theta)*cos(phi) , sin(theta)*sin(phi), cos(theta)}; Double_t opposite_dir[3] = { -dir[0], -dir[1], -dir[2]}; double dist1 = box->DistFromInside( pt , dir , 1); double dist2 = box->DistFromInside( pt , opposite_dir , 1); cout << "positive dir: " << dist1 << " negative dir: " << dist2 << endl; gEve->Redraw3D(kTRUE); en->ExpandIntoListTreesRecursively(); }