14 #include "art/Framework/Services/Registry/ServiceHandle.h"
16 #include "Geant4/G4VPhysicalVolume.hh"
50 std::string TheName = TheVolume->GetName();
59 art::ServiceHandle<geo::Geometry const> geom;
62 double MinDistance = UINT_MAX;
63 int ClosestOpDet = -1;
65 for(
size_t o=0; o!=geom->NOpDets(); o++) {
67 geom->OpDetGeoFromOpDet(o).GetCenter(xyz);
69 CLHEP::Hep3Vector DetPos(xyz[0],xyz[1],xyz[2]);
70 CLHEP::Hep3Vector ThisVolPos = vol->GetTranslation();
72 ThisVolPos/=CLHEP::cm;
77 double Distance = (DetPos-ThisVolPos).mag();
78 if(Distance < MinDistance)
80 MinDistance = Distance;
87 throw cet::exception(
"OpDetLookup Error") <<
"No nearby OpDet found!\n";
90 distance = MinDistance;
101 std::stringstream VolName(
"");
107 VolName << volume->GetName() <<
"_" << NearestOpDet;
108 volume->SetName(VolName.str().c_str());
std::map< std::string, int > fTheOpDetMap
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
void AddPhysicalVolume(G4VPhysicalVolume *)
static OpDetLookup * Instance()
int FindClosestOpDet(G4VPhysicalVolume *vol, double &Distance)
OpDetLookup * TheOpDetLookup
Encapsulate the geometry of an optical detector.
int GetOpDet(G4VPhysicalVolume *)
art framework interface to geometry description