All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | List of all members
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.

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

Definition at line 27 of file OpDetLookup.cxx.

28  {
29  fTheTopOpDet=0;
30  }

Member Function Documentation

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

Definition at line 96 of file OpDetLookup.cxx.

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

Definition at line 57 of file OpDetLookup.cxx.

58  {
59  art::ServiceHandle<geo::Geometry const> geom;
60  int OpDetCount = 0;
61 
62  double MinDistance = UINT_MAX;
63  int ClosestOpDet = -1;
64 
65  for(size_t o=0; o!=geom->NOpDets(); o++) {
66  double xyz[3];
67  geom->OpDetGeoFromOpDet(o).GetCenter(xyz);
68 
69  CLHEP::Hep3Vector DetPos(xyz[0],xyz[1],xyz[2]);
70  CLHEP::Hep3Vector ThisVolPos = vol->GetTranslation();
71 
72  ThisVolPos/=CLHEP::cm;
73 
74  // std::cout<<"Det: " << xyz[0]<< " " <<xyz[1]<< " " << xyz[2]<<std::endl;
75  // std::cout<<"Vol: " << ThisVolPos.x()<< " " <<ThisVolPos.y() << " " <<ThisVolPos.z()<<std::endl;
76 
77  double Distance = (DetPos-ThisVolPos).mag();
78  if(Distance < MinDistance)
79  {
80  MinDistance = Distance;
81  ClosestOpDet = o;
82  }
83  OpDetCount++;
84  }
85  if(ClosestOpDet<0)
86  {
87  throw cet::exception("OpDetLookup Error") << "No nearby OpDet found!\n";
88  }
89 
90  distance = MinDistance;
91  return ClosestOpDet;
92  }
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
int larg4::OpDetLookup::GetN ( )

Definition at line 118 of file OpDetLookup.cxx.

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

Definition at line 48 of file OpDetLookup.cxx.

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

Definition at line 42 of file OpDetLookup.cxx.

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

Definition at line 33 of file OpDetLookup.cxx.

34  {
35  if(!TheOpDetLookup){
37  }
38  return TheOpDetLookup;
39  }
OpDetLookup * TheOpDetLookup
Definition: OpDetLookup.cxx:24

Member Data Documentation

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

Definition at line 60 of file OpDetLookup.h.

int larg4::OpDetLookup::fTheTopOpDet
private

Definition at line 61 of file OpDetLookup.h.


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