Public Member Functions | Private Member Functions | Private Attributes | List of all members
larg4::OpDetReadoutGeometry Class Reference

#include <OpDetReadoutGeometry.h>

Inheritance diagram for larg4::OpDetReadoutGeometry:

Public Member Functions

 OpDetReadoutGeometry (G4String OpDetSensitiveName, const G4String name="OpDetReadoutGeometry", bool useLitePhotons=false)
 
virtual ~OpDetReadoutGeometry ()
 
virtual void Construct ()
 

Private Member Functions

void FindVolumes (G4VPhysicalVolume *, G4String, std::vector< G4Transform3D >, std::vector< G4LogicalVolume * > &, std::vector< G4Transform3D > &)
 

Private Attributes

std::vector< G4LogicalVolume * > fOpDetVolumes
 
std::vector< G4Transform3D > fOpDetTransformations
 
bool const fUseLitePhotons
 Pass-through option for sensitive detector. More...
 
G4String fOpDetSensitiveName
 

Detailed Description

Definition at line 37 of file OpDetReadoutGeometry.h.

Constructor & Destructor Documentation

larg4::OpDetReadoutGeometry::OpDetReadoutGeometry ( G4String  OpDetSensitiveName,
const G4String  name = "OpDetReadoutGeometry",
bool  useLitePhotons = false 
)

Definition at line 32 of file OpDetReadoutGeometry.cxx.

35  : G4VUserParallelWorld(name), fUseLitePhotons(useLitePhotons)
36  {
37  fOpDetSensitiveName = OpDetSensitiveName;
38  }
static QCString name
Definition: declinfo.cpp:673
bool const fUseLitePhotons
Pass-through option for sensitive detector.
larg4::OpDetReadoutGeometry::~OpDetReadoutGeometry ( )
virtual

Definition at line 40 of file OpDetReadoutGeometry.cxx.

40 {}

Member Function Documentation

void larg4::OpDetReadoutGeometry::Construct ( )
virtual

Definition at line 43 of file OpDetReadoutGeometry.cxx.

44  {
45  mf::LogInfo("OpDetReadoutGeometry")
46  << "constructing parallel world, looking for " << fOpDetSensitiveName;
47 
48  // Get an empty parallel world volume
49  G4VPhysicalVolume* ParallelWorld = GetWorld();
50 
51  // Start with empty vectors
52  std::vector<G4LogicalVolume*> OpDetVolumes;
53  std::vector<G4Transform3D> OpDetTransformations;
54 
55  // Get the primary world volume
56  G4VPhysicalVolume* WorldPhysical = g4b::DetectorConstruction::GetWorld();
57 
58  // Find the OpDet volumes
59  std::vector<G4Transform3D> EmptyVector;
60  EmptyVector.clear();
62  WorldPhysical, fOpDetSensitiveName, EmptyVector, OpDetVolumes, OpDetTransformations);
63 
64  fOpDetVolumes = OpDetVolumes;
65  fOpDetTransformations = OpDetTransformations;
66 
67  // Get the OpDet Lookup Table
68  OpDetLookup* TheOpDetLookup = OpDetLookup::Instance();
69 
70  // Create sensitive detector
71  OpDetSensitiveDetector* TheSD =
72  new OpDetSensitiveDetector("OpDetSensitiveDetector", fUseLitePhotons);
73 
74  if (OpDetVolumes.size() > 0) {
75 
76  // Make placements
77  for (unsigned int i = 0; i != OpDetVolumes.size(); i++) {
78  std::stringstream VolumeName;
79  VolumeName.flush();
80  VolumeName.str("OpDetVolume_");
81  VolumeName << i;
82 
83  G4Transform3D TheTransform = OpDetTransformations.at(i);
84 
85  G4VSolid* TheSolid = OpDetVolumes.at(i)->GetSolid();
86  G4Material* TheMaterial = OpDetVolumes.at(i)->GetMaterial();
87  G4LogicalVolume* TheLogVolume =
88  new G4LogicalVolume(TheSolid, TheMaterial, VolumeName.str().c_str());
89 
90  TheLogVolume->SetSensitiveDetector(TheSD);
91 
92  G4PVPlacement* ThePlacement = new G4PVPlacement(
93  TheTransform, VolumeName.str().c_str(), TheLogVolume, ParallelWorld, false, 0);
94 
95  // CLHEP::Hep3Vector trans = ThePlacement->GetTranslation();
96 
97  TheOpDetLookup->AddPhysicalVolume(ThePlacement);
98  }
99  }
100 
101  // Now add any optically parameterized volumes
102 
103  std::vector<G4LogicalVolume*> OpParamVolumesFound;
104  std::vector<G4Transform3D> OpParamTransformationsFound;
105 
107 
108  std::vector<std::string> OpParamModels = lgp->OpticalParamModels();
109  std::vector<std::string> OpParamVolumes = lgp->OpticalParamVolumes();
110  std::vector<int> OpParamOrientations = lgp->OpticalParamOrientations();
111  ;
112  std::vector<std::vector<std::vector<double>>> OpParamParameters = lgp->OpticalParamParameters();
113 
114  if ((OpParamModels.size() != OpParamVolumes.size()) ||
115  (OpParamModels.size() != OpParamOrientations.size()) ||
116  (OpParamModels.size() != OpParamParameters.size())) {
117  throw cet::exception("OpDetReadoutGeometry")
118  << "sizes of OpParam specification vectors do not match\n";
119  }
120 
121  for (size_t imodel = 0; imodel != OpParamVolumes.size(); ++imodel) {
122  EmptyVector.clear();
123  FindVolumes(WorldPhysical,
124  OpParamVolumes.at(imodel),
125  EmptyVector,
126  OpParamVolumesFound,
127  OpParamTransformationsFound);
128  mf::LogInfo("OpDetReadoutGeometry")
129  << "Found " << OpParamVolumesFound.size() << " volumes of name "
130  << OpParamVolumes.at(imodel) << " to attach optical parameterization "
131  << OpParamModels.at(imodel) << std::endl;
132 
133  // Since the same named model may be instantiated more than once with
134  // different parameters, create a unique sensitive detector name for this
135  // instance
136 
137  std::stringstream SDName("");
138  SDName << OpParamModels.at(imodel) << "_" << imodel;
139 
140  OpParamSD* ParamSD = new OpParamSD(SDName.str().c_str(),
141  OpParamModels.at(imodel),
142  OpParamOrientations.at(imodel),
143  OpParamParameters.at(imodel));
144 
145  if (OpParamVolumesFound.size() > 0) {
146  for (unsigned int ivol = 0; ivol != OpParamVolumes.size(); ivol++) {
147  std::stringstream VolumeName;
148  VolumeName.flush();
149  VolumeName.str("OpParamVolume_");
150  VolumeName << ivol;
151 
152  G4Transform3D TheTransform = OpParamTransformationsFound.at(ivol);
153 
154  G4VSolid* TheSolid = OpParamVolumesFound.at(ivol)->GetSolid();
155  G4Material* TheMaterial = OpParamVolumesFound.at(ivol)->GetMaterial();
156  G4LogicalVolume* TheLogVolume =
157  new G4LogicalVolume(TheSolid, TheMaterial, VolumeName.str().c_str());
158 
159  G4PVPlacement* ThePlacement = new G4PVPlacement(
160  TheTransform, VolumeName.str().c_str(), TheLogVolume, ParallelWorld, false, 0);
161 
162  TheLogVolume->SetSensitiveDetector(ParamSD);
163 
164  // This line just suppressed a compiler warning
165  ThePlacement->GetTranslation();
166  }
167  }
168  }
169  }
void FindVolumes(G4VPhysicalVolume *, G4String, std::vector< G4Transform3D >, std::vector< G4LogicalVolume * > &, std::vector< G4Transform3D > &)
const std::vector< std::vector< std::vector< double > > > & OpticalParamParameters() const
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::vector< G4Transform3D > fOpDetTransformations
const std::vector< std::string > & OpticalParamVolumes() const
bool const fUseLitePhotons
Pass-through option for sensitive detector.
std::vector< G4LogicalVolume * > fOpDetVolumes
const std::vector< std::string > & OpticalParamModels() const
const std::vector< int > & OpticalParamOrientations() const
static OpDetLookup * Instance()
Definition: OpDetLookup.cxx:33
OpDetLookup * TheOpDetLookup
Definition: OpDetLookup.cxx:24
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
void larg4::OpDetReadoutGeometry::FindVolumes ( G4VPhysicalVolume *  PhysicalVolume,
G4String  OpDetName,
std::vector< G4Transform3D >  TransformSoFar,
std::vector< G4LogicalVolume * > &  OpDetVolumes,
std::vector< G4Transform3D > &  OpDetTransformations 
)
private

Definition at line 172 of file OpDetReadoutGeometry.cxx.

177  {
178 
179  // Add the next layer of transformation to the vector
180  G4ThreeVector Translation = PhysicalVolume->GetObjectTranslation();
181  G4RotationMatrix Rotation = PhysicalVolume->GetObjectRotationValue();
182  G4Transform3D NextTransform(Rotation, Translation);
183 
184  TransformSoFar.push_back(NextTransform);
185 
186  // Check if this volume is a OpDet
187  G4String OpDetNameUnderscore = OpDetName + "_";
188  G4String VolumeName = PhysicalVolume->GetName();
189  if ((VolumeName == OpDetName) ||
190  (VolumeName.find(OpDetNameUnderscore, 0, OpDetNameUnderscore.length()) == 0)) {
191 
192  // We found a OpDet! Store its volume and global transformation
193  G4ThreeVector Trans(0, 0, 0);
194  G4RotationMatrix Rot(0, 0, 0);
195  G4Transform3D TotalTransform(Rot, Trans);
196  //for ( std::vector<G4Transform3D>::reverse_iterator it = TransformSoFar.rbegin();
197  // it != TransformSoFar.rend(); ++it )
198 
199  for (std::vector<G4Transform3D>::iterator it = TransformSoFar.begin();
200  it != TransformSoFar.end();
201  ++it) {
202  CLHEP::Hep3Vector trans = (*it).getTranslation();
203  CLHEP::HepRotation rot = (*it).getRotation();
204  TotalTransform = TotalTransform * (*it);
205  }
206 
207  OpDetVolumes.push_back(PhysicalVolume->GetLogicalVolume());
208  OpDetTransformations.push_back(TotalTransform);
209  }
210  else {
211  // We did not find a OpDet. Keep looking through daughters.
212  G4LogicalVolume* LogicalVolume = PhysicalVolume->GetLogicalVolume();
213 
214  // Loop through the daughters of the volume
215  G4int NumberDaughters = LogicalVolume->GetNoDaughters();
216  for (G4int i = 0; i != NumberDaughters; ++i) {
217  // Get the ith daughter volume
218  G4VPhysicalVolume* Daughter = LogicalVolume->GetDaughter(i);
219 
220  // Recursively step into this volume
221  FindVolumes(Daughter, OpDetName, TransformSoFar, OpDetVolumes, OpDetTransformations);
222  }
223  }
224  }
void FindVolumes(G4VPhysicalVolume *, G4String, std::vector< G4Transform3D >, std::vector< G4LogicalVolume * > &, std::vector< G4Transform3D > &)
intermediate_table::iterator iterator

Member Data Documentation

G4String larg4::OpDetReadoutGeometry::fOpDetSensitiveName
private

Definition at line 55 of file OpDetReadoutGeometry.h.

std::vector<G4Transform3D> larg4::OpDetReadoutGeometry::fOpDetTransformations
private

Definition at line 53 of file OpDetReadoutGeometry.h.

std::vector<G4LogicalVolume*> larg4::OpDetReadoutGeometry::fOpDetVolumes
private

Definition at line 52 of file OpDetReadoutGeometry.h.

bool const larg4::OpDetReadoutGeometry::fUseLitePhotons
private

Pass-through option for sensitive detector.

Definition at line 54 of file OpDetReadoutGeometry.h.


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