LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
larg4::OpDetLookup Class Reference

#include "OpDetLookup.h"

Public Member Functions

void AddPhysicalVolume (G4VPhysicalVolume *)
 
int GetOpDet (G4VPhysicalVolume const *)
 
int GetOpDet (std::string const &)
 
int GetN () const
 
int FindClosestOpDet (G4VPhysicalVolume *vol, double &Distance)
 

Static Public Member Functions

static OpDetLookupInstance ()
 

Private Member Functions

 OpDetLookup ()
 

Private Attributes

std::map< std::string, int > fTheOpDetMap
 
int fTheTopOpDet
 

Detailed Description

Definition at line 44 of file OpDetLookup.h.

Constructor & Destructor Documentation

larg4::OpDetLookup::OpDetLookup ( )
private

Definition at line 25 of file OpDetLookup.cxx.

References fTheTopOpDet.

Referenced by Instance().

26  {
27  fTheTopOpDet = 0;
28  }

Member Function Documentation

void larg4::OpDetLookup::AddPhysicalVolume ( G4VPhysicalVolume *  volume)

Definition at line 83 of file OpDetLookup.cxx.

References FindClosestOpDet(), and fTheOpDetMap.

Referenced by larg4::OpDetReadoutGeometry::Construct().

84  {
85  std::stringstream VolName("");
86  double Distance = 0;
87 
88  int NearestOpDet = FindClosestOpDet(volume, Distance);
89 
90  VolName.flush();
91  VolName << volume->GetName() << "_" << NearestOpDet;
92  volume->SetName(VolName.str().c_str());
93 
94  fTheOpDetMap[VolName.str()] = NearestOpDet;
95  }
std::map< std::string, int > fTheOpDetMap
Definition: OpDetLookup.h:57
int FindClosestOpDet(G4VPhysicalVolume *vol, double &Distance)
Definition: OpDetLookup.cxx:51
int larg4::OpDetLookup::FindClosestOpDet ( G4VPhysicalVolume *  vol,
double &  Distance 
)

Definition at line 51 of file OpDetLookup.cxx.

References geo::OpDetGeo::GetCenter(), geo::GeometryCore::NOpDets(), and geo::GeometryCore::OpDetGeoFromOpDet().

Referenced by AddPhysicalVolume().

52  {
54  int OpDetCount = 0;
55 
56  double MinDistance = UINT_MAX;
57  int ClosestOpDet = -1;
58 
59  for (size_t o = 0; o != geom->NOpDets(); o++) {
60  auto const xyz = geom->OpDetGeoFromOpDet(o).GetCenter();
61 
62  CLHEP::Hep3Vector DetPos(xyz.X(), xyz.Y(), xyz.Z());
63  CLHEP::Hep3Vector ThisVolPos = vol->GetTranslation();
64 
65  ThisVolPos /= CLHEP::cm;
66 
67  double Distance = (DetPos - ThisVolPos).mag();
68  if (Distance < MinDistance) {
69  MinDistance = Distance;
70  ClosestOpDet = o;
71  }
72  OpDetCount++;
73  }
74  if (ClosestOpDet < 0) {
75  throw cet::exception("OpDetLookup Error") << "No nearby OpDet found!\n";
76  }
77 
78  distance = MinDistance;
79  return ClosestOpDet;
80  }
OpDetGeo const & OpDetGeoFromOpDet(unsigned int OpDet) const
Returns the geo::OpDetGeo object for the given detector number.
unsigned int NOpDets() const
Number of OpDets in the whole detector.
geo::Point_t const & GetCenter() const
Definition: OpDetGeo.h:72
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
int larg4::OpDetLookup::GetN ( ) const

Definition at line 98 of file OpDetLookup.cxx.

References fTheTopOpDet.

99  {
100  return fTheTopOpDet;
101  }
int larg4::OpDetLookup::GetOpDet ( G4VPhysicalVolume const *  TheVolume)

Definition at line 44 of file OpDetLookup.cxx.

Referenced by larg4::OpDetSensitiveDetector::ProcessHits().

45  {
46  return GetOpDet(TheVolume->GetName());
47  }
int GetOpDet(G4VPhysicalVolume const *)
Definition: OpDetLookup.cxx:44
int larg4::OpDetLookup::GetOpDet ( std::string const &  TheName)

Definition at line 38 of file OpDetLookup.cxx.

References fTheOpDetMap.

39  {
40  return fTheOpDetMap[TheName];
41  }
std::map< std::string, int > fTheOpDetMap
Definition: OpDetLookup.h:57
OpDetLookup * larg4::OpDetLookup::Instance ( )
static

Member Data Documentation

std::map<std::string, int> larg4::OpDetLookup::fTheOpDetMap
private

Definition at line 57 of file OpDetLookup.h.

Referenced by AddPhysicalVolume(), and GetOpDet().

int larg4::OpDetLookup::fTheTopOpDet
private

Definition at line 58 of file OpDetLookup.h.

Referenced by GetN(), and OpDetLookup().


The documentation for this class was generated from the following files: