8 #include "CLHEP/Geometry/Transform3D.h" 9 #include "CLHEP/Vector/Rotation.h" 10 #include "CLHEP/Vector/ThreeVector.h" 11 #include "Geant4/G4LogicalVolume.hh" 12 #include "Geant4/G4PVPlacement.hh" 13 #include "Geant4/G4RotationMatrix.hh" 14 #include "Geant4/G4ThreeVector.hh" 15 #include "Geant4/G4Types.hh" 16 #include "Geant4/G4VPhysicalVolume.hh" 27 #include "cetlib_except/exception.h" 35 : G4VUserParallelWorld(name), fUseLitePhotons(useLitePhotons)
48 G4VPhysicalVolume* ParallelWorld = GetWorld();
51 std::vector<G4LogicalVolume*> OpDetVolumes;
52 std::vector<G4Transform3D> OpDetTransformations;
58 std::vector<G4Transform3D> EmptyVector;
73 if (OpDetVolumes.size() > 0) {
76 for (
unsigned int i = 0; i != OpDetVolumes.size(); i++) {
77 std::stringstream VolumeName;
79 VolumeName.str(
"OpDetVolume_");
82 G4Transform3D TheTransform = OpDetTransformations.at(i);
84 G4VSolid* TheSolid = OpDetVolumes.at(i)->GetSolid();
85 G4Material* TheMaterial = OpDetVolumes.at(i)->GetMaterial();
86 G4LogicalVolume* TheLogVolume =
87 new G4LogicalVolume(TheSolid, TheMaterial, VolumeName.str().c_str());
89 TheLogVolume->SetSensitiveDetector(TheSD);
91 G4PVPlacement* ThePlacement =
new G4PVPlacement(
92 TheTransform, VolumeName.str().c_str(), TheLogVolume, ParallelWorld,
false, 0);
102 std::vector<G4LogicalVolume*> OpParamVolumesFound;
103 std::vector<G4Transform3D> OpParamTransformationsFound;
113 if ((OpParamModels.size() != OpParamVolumes.size()) ||
114 (OpParamModels.size() != OpParamOrientations.size()) ||
115 (OpParamModels.size() != OpParamParameters.size())) {
117 <<
"sizes of OpParam specification vectors do not match\n";
120 for (
size_t imodel = 0; imodel != OpParamVolumes.size(); ++imodel) {
123 OpParamVolumes.at(imodel),
126 OpParamTransformationsFound);
128 <<
"Found " << OpParamVolumesFound.size() <<
" volumes of name " 129 << OpParamVolumes.at(imodel) <<
" to attach optical parameterization " 130 << OpParamModels.at(imodel) << std::endl;
136 std::stringstream SDName(
"");
137 SDName << OpParamModels.at(imodel) <<
"_" << imodel;
140 OpParamModels.at(imodel),
141 OpParamOrientations.at(imodel),
142 OpParamParameters.at(imodel));
144 if (OpParamVolumesFound.size() > 0) {
145 for (
unsigned int ivol = 0; ivol != OpParamVolumes.size(); ivol++) {
146 std::stringstream VolumeName;
148 VolumeName.str(
"OpParamVolume_");
151 G4Transform3D TheTransform = OpParamTransformationsFound.at(ivol);
153 G4VSolid* TheSolid = OpParamVolumesFound.at(ivol)->GetSolid();
154 G4Material* TheMaterial = OpParamVolumesFound.at(ivol)->GetMaterial();
155 G4LogicalVolume* TheLogVolume =
156 new G4LogicalVolume(TheSolid, TheMaterial, VolumeName.str().c_str());
158 G4PVPlacement* ThePlacement =
new G4PVPlacement(
159 TheTransform, VolumeName.str().c_str(), TheLogVolume, ParallelWorld,
false, 0);
161 TheLogVolume->SetSensitiveDetector(ParamSD);
164 ThePlacement->GetTranslation();
172 std::vector<G4Transform3D> TransformSoFar,
173 std::vector<G4LogicalVolume*>& OpDetVolumes,
174 std::vector<G4Transform3D>& OpDetTransformations)
178 G4ThreeVector Translation = PhysicalVolume->GetObjectTranslation();
179 G4RotationMatrix Rotation = PhysicalVolume->GetObjectRotationValue();
180 G4Transform3D NextTransform(Rotation, Translation);
182 TransformSoFar.push_back(NextTransform);
185 G4String OpDetNameUnderscore = OpDetName +
"_";
186 G4String VolumeName = PhysicalVolume->GetName();
187 if ((VolumeName == OpDetName) ||
188 (VolumeName.find(OpDetNameUnderscore, 0, OpDetNameUnderscore.length()) == 0)) {
191 G4ThreeVector Trans(0, 0, 0);
192 G4RotationMatrix Rot(0, 0, 0);
193 G4Transform3D TotalTransform(Rot, Trans);
198 it != TransformSoFar.end();
200 CLHEP::Hep3Vector trans = (*it).getTranslation();
201 CLHEP::HepRotation rot = (*it).getRotation();
202 TotalTransform = TotalTransform * (*it);
205 OpDetVolumes.push_back(PhysicalVolume->GetLogicalVolume());
206 OpDetTransformations.push_back(TotalTransform);
210 G4LogicalVolume* LogicalVolume = PhysicalVolume->GetLogicalVolume();
213 G4int NumberDaughters = LogicalVolume->GetNoDaughters();
214 for (G4int i = 0; i != NumberDaughters; ++i) {
216 G4VPhysicalVolume* Daughter = LogicalVolume->GetDaughter(i);
219 FindVolumes(Daughter, OpDetName, TransformSoFar, OpDetVolumes, OpDetTransformations);
void FindVolumes(G4VPhysicalVolume *, G4String, std::vector< G4Transform3D >, std::vector< G4LogicalVolume * > &, std::vector< G4Transform3D > &)
Build Geant4 geometry from GDML.
Store parameters for running LArG4.
const std::vector< std::vector< std::vector< double > > > & OpticalParamParameters() const
G4String fOpDetSensitiveName
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
static G4VPhysicalVolume * GetWorld()
std::vector< G4Transform3D > fOpDetTransformations
const std::vector< std::string > & OpticalParamVolumes() const
OpDetReadoutGeometry(G4String OpDetSensitiveName, const G4String name="OpDetReadoutGeometry", bool useLitePhotons=false)
bool const fUseLitePhotons
Pass-through option for sensitive detector.
std::vector< G4LogicalVolume * > fOpDetVolumes
virtual ~OpDetReadoutGeometry()
const std::vector< std::string > & OpticalParamModels() const
const std::vector< int > & OpticalParamOrientations() const
void AddPhysicalVolume(G4VPhysicalVolume *)
static OpDetLookup * Instance()
OpDetLookup * TheOpDetLookup
cet::coded_exception< error, detail::translate > exception