LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
larg4::OpDetLookup Class Reference

#include "OpDetLookup.h"

Public Member Functions

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

Static Public Member Functions

static OpDetLookupInstance ()
 

Protected 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 ( )
inline

Definition at line 47 of file OpDetLookup.h.

References AddPhysicalVolume(), FindClosestOpDet(), GetN(), GetOpDet(), Instance(), and OpDetLookup().

47 {}
larg4::OpDetLookup::OpDetLookup ( )
protected

Definition at line 25 of file OpDetLookup.cxx.

References fTheTopOpDet.

Referenced by Instance(), and ~OpDetLookup().

26  {
27  fTheTopOpDet=0;
28  }

Member Function Documentation

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

Definition at line 94 of file OpDetLookup.cxx.

References FindClosestOpDet(), and fTheOpDetMap.

Referenced by larg4::OpDetReadoutGeometry::Construct(), and ~OpDetLookup().

95  {
96 
97  // mf::LogInfo("Optical") <<"G4 placing sensitive opdet"<<std::endl;
98 
99  std::stringstream VolName("");
100  double Distance = 0;
101 
102  int NearestOpDet = FindClosestOpDet(volume, Distance);
103 
104  VolName.flush();
105  VolName << volume->GetName() << "_" << NearestOpDet;
106  volume->SetName(VolName.str().c_str());
107 
108  fTheOpDetMap[VolName.str()] = NearestOpDet;
109 
110  // mf::LogInfo("Optical") << "Found closest volume: " << VolName.str().c_str() << " OpDet : " << fTheOpDetMap[VolName.str()]<<" distance : " <<Distance<<std::endl;
111 
112  }
std::map< std::string, int > fTheOpDetMap
Definition: OpDetLookup.h:60
int FindClosestOpDet(G4VPhysicalVolume *vol, double &Distance)
Definition: OpDetLookup.cxx:55
int larg4::OpDetLookup::FindClosestOpDet ( G4VPhysicalVolume *  vol,
double &  Distance 
)

Definition at line 55 of file OpDetLookup.cxx.

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

Referenced by AddPhysicalVolume(), and ~OpDetLookup().

56  {
58  int OpDetCount = 0;
59 
60  double MinDistance = UINT_MAX;
61  int ClosestOpDet = -1;
62 
63  for(size_t o=0; o!=geom->NOpDets(); o++) {
64  double xyz[3];
65  geom->OpDetGeoFromOpDet(o).GetCenter(xyz);
66 
67  CLHEP::Hep3Vector DetPos(xyz[0],xyz[1],xyz[2]);
68  CLHEP::Hep3Vector ThisVolPos = vol->GetTranslation();
69 
70  ThisVolPos/=CLHEP::cm;
71 
72  // std::cout<<"Det: " << xyz[0]<< " " <<xyz[1]<< " " << xyz[2]<<std::endl;
73  // std::cout<<"Vol: " << ThisVolPos.x()<< " " <<ThisVolPos.y() << " " <<ThisVolPos.z()<<std::endl;
74 
75  double Distance = (DetPos-ThisVolPos).mag();
76  if(Distance < MinDistance)
77  {
78  MinDistance = Distance;
79  ClosestOpDet = o;
80  }
81  OpDetCount++;
82  }
83  if(ClosestOpDet<0)
84  {
85  throw cet::exception("OpDetLookup Error") << "No nearby OpDet found!\n";
86  }
87 
88  distance = MinDistance;
89  return ClosestOpDet;
90  }
OpDetGeo const & OpDetGeoFromOpDet(unsigned int OpDet) const
Number of OpDets in the whole detector.
void GetCenter(double *xyz, double localz=0.0) const
Definition: OpDetGeo.cxx:47
unsigned int NOpDets() const
Number of OpDets in the whole detector.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
int larg4::OpDetLookup::GetN ( )

Definition at line 116 of file OpDetLookup.cxx.

References fTheTopOpDet.

Referenced by ~OpDetLookup().

117  {
118  return fTheTopOpDet;
119  }
int larg4::OpDetLookup::GetOpDet ( G4VPhysicalVolume *  TheVolume)

Definition at line 46 of file OpDetLookup.cxx.

Referenced by larg4::OpDetSensitiveDetector::ProcessHits(), and ~OpDetLookup().

47  {
48  std::string TheName = TheVolume->GetName();
49  return GetOpDet(TheName);
50  }
int GetOpDet(G4VPhysicalVolume *)
Definition: OpDetLookup.cxx:46
int larg4::OpDetLookup::GetOpDet ( std::string  TheName)

Definition at line 40 of file OpDetLookup.cxx.

References fTheOpDetMap.

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

Definition at line 31 of file OpDetLookup.cxx.

References OpDetLookup(), and larg4::TheOpDetLookup.

Referenced by larg4::OpDetReadoutGeometry::Construct(), larg4::OpDetSensitiveDetector::OpDetSensitiveDetector(), and ~OpDetLookup().

32  {
33  if(!TheOpDetLookup){
35  }
36  return TheOpDetLookup;
37  }
OpDetLookup * TheOpDetLookup
Definition: OpDetLookup.cxx:22

Member Data Documentation

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

Definition at line 60 of file OpDetLookup.h.

Referenced by AddPhysicalVolume(), and GetOpDet().

int larg4::OpDetLookup::fTheTopOpDet
private

Definition at line 61 of file OpDetLookup.h.

Referenced by GetN(), and OpDetLookup().


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