15 #include "Geant4/G4VPhysicalVolume.hh" 33 if (!TheOpDetLookup) { TheOpDetLookup =
new OpDetLookup; }
46 return GetOpDet(TheVolume->GetName());
56 double MinDistance = UINT_MAX;
57 int ClosestOpDet = -1;
59 for (
size_t o = 0; o != geom->
NOpDets(); o++) {
62 CLHEP::Hep3Vector DetPos(xyz.X(), xyz.Y(), xyz.Z());
63 CLHEP::Hep3Vector ThisVolPos = vol->GetTranslation();
65 ThisVolPos /= CLHEP::cm;
67 double Distance = (DetPos - ThisVolPos).
mag();
68 if (Distance < MinDistance) {
69 MinDistance = Distance;
74 if (ClosestOpDet < 0) {
75 throw cet::exception(
"OpDetLookup Error") <<
"No nearby OpDet found!\n";
78 distance = MinDistance;
85 std::stringstream VolName(
"");
91 VolName << volume->GetName() <<
"_" << NearestOpDet;
92 volume->SetName(VolName.str().c_str());
OpDetGeo const & OpDetGeoFromOpDet(unsigned int OpDet) const
Returns the geo::OpDetGeo object for the given detector number.
std::map< std::string, int > fTheOpDetMap
int GetOpDet(G4VPhysicalVolume const *)
void AddPhysicalVolume(G4VPhysicalVolume *)
static OpDetLookup * Instance()
int FindClosestOpDet(G4VPhysicalVolume *vol, double &Distance)
unsigned int NOpDets() const
Number of OpDets in the whole detector.
OpDetLookup * TheOpDetLookup
Encapsulate the geometry of an optical detector.
geo::Point_t const & GetCenter() const
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception