8 #include "cetlib_except/exception.h" 15 #include "Geant4/G4PVPlacement.hh" 16 #include "Geant4/G4VSolid.hh" 17 #include "Geant4/G4SDManager.hh" 25 G4VUserParallelWorld(name)
35 mf::LogInfo(
"OpDetReadoutGeometry") <<
"constructing parallel world, looking for " 39 G4VPhysicalVolume * ParallelWorld = GetWorld();
42 std::vector<G4LogicalVolume*> OpDetVolumes;
43 std::vector<G4Transform3D> OpDetTransformations;
49 std::vector<G4Transform3D> EmptyVector;
63 if(OpDetVolumes.size()>0)
69 for(
unsigned int i=0; i!=OpDetVolumes.size(); i++)
71 std::stringstream VolumeName;
73 VolumeName.str(
"OpDetVolume_");
76 G4Transform3D TheTransform = OpDetTransformations.at(i);
78 G4VSolid * TheSolid = OpDetVolumes.at(i)->GetSolid();
79 G4Material * TheMaterial = OpDetVolumes.at(i)->GetMaterial();
80 G4LogicalVolume * TheLogVolume =
new G4LogicalVolume(TheSolid,TheMaterial,VolumeName.str().c_str());
82 TheLogVolume->SetSensitiveDetector(TheSD );
85 G4PVPlacement * ThePlacement
86 =
new G4PVPlacement( TheTransform,
87 VolumeName.str().c_str(),
103 std::vector<G4LogicalVolume*> OpParamVolumesFound;
104 std::vector<G4Transform3D> OpParamTransformationsFound;
113 if((OpParamModels.size()!=OpParamVolumes.size())||
114 (OpParamModels.size()!=OpParamOrientations.size())||
115 (OpParamModels.size()!=OpParamParameters.size()))
117 throw cet::exception(
"OpDetReadoutGeometry")<<
"sizes of OpParam specification vectors do not match\n";
120 for(
size_t imodel=0; imodel!=OpParamVolumes.size(); ++imodel)
123 FindVolumes(WorldPhysical, OpParamVolumes.at(imodel), EmptyVector, OpParamVolumesFound, OpParamTransformationsFound );
124 mf::LogInfo(
"OpDetReadoutGeometry")<<
"Found " << OpParamVolumesFound.size()<<
" volumes of name " << OpParamVolumes.at(imodel)<<
" to attach optical parameterization " << OpParamModels.at(imodel)<<std::endl;
131 std::stringstream SDName(
"");
132 SDName<<OpParamModels.at(imodel)<<
"_"<<imodel;
134 OpParamSD * ParamSD =
new OpParamSD(SDName.str().c_str(), OpParamModels.at(imodel), OpParamOrientations.at(imodel), OpParamParameters.at(imodel));
137 if(OpParamVolumesFound.size()>0)
139 for(
unsigned int ivol=0; ivol!=OpParamVolumes.size(); ivol++)
141 std::stringstream VolumeName;
143 VolumeName.str(
"OpParamVolume_");
146 G4Transform3D TheTransform = OpParamTransformationsFound.at(ivol);
148 G4VSolid * TheSolid = OpParamVolumesFound.at(ivol)->GetSolid();
149 G4Material * TheMaterial = OpParamVolumesFound.at(ivol)->GetMaterial();
150 G4LogicalVolume * TheLogVolume =
new G4LogicalVolume(TheSolid,TheMaterial,VolumeName.str().c_str());
153 G4PVPlacement * ThePlacement
154 =
new G4PVPlacement( TheTransform,
155 VolumeName.str().c_str(),
161 TheLogVolume->SetSensitiveDetector(ParamSD );
165 ThePlacement->GetTranslation();
176 void OpDetReadoutGeometry::FindVolumes(G4VPhysicalVolume * PhysicalVolume,
G4String OpDetName, std::vector<G4Transform3D> TransformSoFar, std::vector<G4LogicalVolume*>& OpDetVolumes, std::vector<G4Transform3D>& OpDetTransformations)
180 G4ThreeVector Translation = PhysicalVolume->GetObjectTranslation();
181 G4RotationMatrix Rotation = PhysicalVolume->GetObjectRotationValue();
182 G4Transform3D NextTransform( Rotation, Translation );
184 TransformSoFar.push_back(NextTransform);
188 G4String OpDetNameUnderscore = OpDetName+
"_";
189 G4String VolumeName = PhysicalVolume->GetName();
190 if( ( VolumeName == OpDetName ) ||
191 ( VolumeName.find( OpDetNameUnderscore,0,OpDetNameUnderscore.length() )==0 )
196 G4ThreeVector Trans(0,0,0);
197 G4RotationMatrix Rot(0,0,0);
198 G4Transform3D TotalTransform(Rot,Trans);
205 it != TransformSoFar.end(); ++it )
207 CLHEP::Hep3Vector trans = (*it).getTranslation();
208 CLHEP::HepRotation rot = (*it).getRotation();
209 TotalTransform = TotalTransform * (*it);
212 OpDetVolumes.push_back(PhysicalVolume->GetLogicalVolume());
213 OpDetTransformations.push_back(TotalTransform);
219 G4LogicalVolume * LogicalVolume = PhysicalVolume->GetLogicalVolume();
222 G4int NumberDaughters = LogicalVolume->GetNoDaughters();
223 for(G4int i=0; i!=NumberDaughters; ++i)
226 G4VPhysicalVolume * Daughter = LogicalVolume->GetDaughter(i);
229 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.
G4String fOpDetSensitiveName
const std::vector< int > OpticalParamOrientations() const
const std::vector< std::string > OpticalParamModels() const
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
static G4VPhysicalVolume * GetWorld()
std::vector< G4Transform3D > fOpDetTransformations
std::vector< G4LogicalVolume * > fOpDetVolumes
virtual ~OpDetReadoutGeometry()
const std::vector< std::vector< std::vector< double > > > OpticalParamParameters() const
void AddPhysicalVolume(G4VPhysicalVolume *)
static OpDetLookup * Instance()
OpDetLookup * TheOpDetLookup
const std::vector< std::string > OpticalParamVolumes() const
OpDetReadoutGeometry(G4String OpDetSensitiveName, const G4String name="OpDetReadoutGeometry")
cet::coded_exception< error, detail::translate > exception