Import Geant4 10.6.0.beta source tree
This commit is contained in:
@@ -68,7 +68,6 @@
|
||||
#include "G4OpticalSurface.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4SurfaceProperty.hh"
|
||||
#include "G4MaterialPropertiesTable.hh"
|
||||
|
||||
G4GDMLReadSolids::G4GDMLReadSolids() : G4GDMLReadMaterials()
|
||||
{
|
||||
@@ -2535,11 +2534,24 @@ PropertyRead(const xercesc::DOMElement* const propertyElement,
|
||||
}
|
||||
else // build the material properties vector
|
||||
{
|
||||
G4MaterialPropertyVector* propvect = new G4MaterialPropertyVector();
|
||||
for (size_t i=0; i<matrix.GetRows(); i++)
|
||||
{
|
||||
propvect->InsertValues(matrix.Get(i,0),matrix.Get(i,1));
|
||||
}
|
||||
G4MaterialPropertyVector* propvect;
|
||||
// first check if it was already built
|
||||
if ( mapOfMatPropVects.find(Strip(name)) == mapOfMatPropVects.end())
|
||||
{
|
||||
// if not create a new one
|
||||
propvect = new G4MaterialPropertyVector();
|
||||
for (size_t i=0; i<matrix.GetRows(); i++)
|
||||
{
|
||||
propvect->InsertValues(matrix.Get(i,0),matrix.Get(i,1));
|
||||
}
|
||||
// and add it to the list for potential future reuse
|
||||
mapOfMatPropVects[Strip(name)] = propvect;
|
||||
}
|
||||
else
|
||||
{
|
||||
propvect = mapOfMatPropVects[Strip(name)];
|
||||
}
|
||||
|
||||
matprop->AddProperty(Strip(name),propvect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@
|
||||
#include "G4Proton.hh"
|
||||
|
||||
#include "G4VSensitiveDetector.hh"
|
||||
#include "G4AssemblyStore.hh"
|
||||
#include "G4AssemblyVolume.hh"
|
||||
|
||||
G4int G4GDMLWriteStructure::levelNo = 0; // Counter for level being exported
|
||||
|
||||
@@ -229,6 +231,63 @@ void G4GDMLWriteStructure::ReplicavolWrite(xercesc::DOMElement* volumeElement,
|
||||
volumeElement->appendChild(replicavolElement);
|
||||
}
|
||||
|
||||
|
||||
void G4GDMLWriteStructure::AssemblyWrite(xercesc::DOMElement* volumeElement,
|
||||
const int assemblyID)
|
||||
{
|
||||
|
||||
G4AssemblyStore* assemblies = G4AssemblyStore::GetInstance();
|
||||
G4AssemblyVolume* myassembly = assemblies->GetAssembly(assemblyID);
|
||||
|
||||
xercesc::DOMElement* assemblyElement = NewElement("assembly");
|
||||
G4String name = "Assembly_" + std::to_string(assemblyID);
|
||||
|
||||
assemblyElement->setAttributeNode(NewAttribute("name",name));
|
||||
|
||||
std::vector<G4AssemblyTriplet>::iterator vit = myassembly->GetTripletsIterator();
|
||||
|
||||
int depth = 0;
|
||||
const G4String ModuleName;
|
||||
|
||||
for (size_t i5=0; i5<myassembly->TotalTriplets(); i5++)
|
||||
{
|
||||
TraverseVolumeTree((*vit).GetVolume(),depth+1);
|
||||
|
||||
const G4ThreeVector rot = GetAngles((*vit).GetRotation()->inverse());
|
||||
const G4ThreeVector pos = (*vit).GetTranslation();
|
||||
|
||||
const G4String pname = GenerateName((*vit).GetVolume()->GetName()+"_pv", &(*vit));
|
||||
|
||||
xercesc::DOMElement* physvolElement = NewElement("physvol");
|
||||
physvolElement->setAttributeNode(NewAttribute("name",pname));
|
||||
|
||||
assemblyElement->appendChild(physvolElement);
|
||||
|
||||
const G4String volumeref = GenerateName((*vit).GetVolume()->GetName(), (*vit).GetVolume());
|
||||
|
||||
xercesc::DOMElement* volumerefElement = NewElement("volumeref");
|
||||
volumerefElement->setAttributeNode(NewAttribute("ref",volumeref));
|
||||
physvolElement->appendChild(volumerefElement);
|
||||
|
||||
if (std::fabs(pos.x()) > kLinearPrecision
|
||||
|| std::fabs(pos.y()) > kLinearPrecision
|
||||
|| std::fabs(pos.z()) > kLinearPrecision)
|
||||
{
|
||||
PositionWrite(physvolElement,"Position_" + std::to_string(i5), pos);
|
||||
}
|
||||
if (std::fabs(rot.x()) > kAngularPrecision
|
||||
|| std::fabs(rot.y()) > kAngularPrecision
|
||||
|| std::fabs(rot.z()) > kAngularPrecision)
|
||||
{
|
||||
RotationWrite(physvolElement,"Rotation_" + std::to_string(i5), rot);
|
||||
}
|
||||
vit++;
|
||||
}
|
||||
|
||||
volumeElement->appendChild(assemblyElement);
|
||||
}
|
||||
|
||||
|
||||
void G4GDMLWriteStructure::
|
||||
BorderSurfaceCache(const G4LogicalBorderSurface* const bsurf)
|
||||
{
|
||||
@@ -383,6 +442,31 @@ void G4GDMLWriteStructure::StructureWrite(xercesc::DOMElement* gdmlElement)
|
||||
#ifdef G4VERBOSE
|
||||
G4cout << "G4GDML: Writing structure..." << G4endl;
|
||||
#endif
|
||||
|
||||
// filling the list of phys volumes that are parts of assemblies
|
||||
|
||||
G4AssemblyStore* assemblies = G4AssemblyStore::GetInstance();
|
||||
|
||||
for(G4AssemblyStore::iterator it=assemblies->begin(); it!=assemblies->end(); it++)
|
||||
{
|
||||
|
||||
std::vector<G4VPhysicalVolume*>::iterator vit = (*it)->GetVolumesIterator();
|
||||
|
||||
for (size_t i5=0; i5<(*it)->TotalImprintedVolumes(); i5++)
|
||||
{
|
||||
G4String pvname = (*vit)->GetName();
|
||||
std::size_t pos = pvname.find("_impr_") + 6;
|
||||
G4String impID = pvname.substr(pos);
|
||||
|
||||
pos = impID.find("_");
|
||||
impID = impID.substr(0, pos);
|
||||
|
||||
assemblyVolMap[*vit] = (*it)->GetAssemblyID();
|
||||
imprintsMap[*vit] = std::atoi(impID.c_str());
|
||||
vit++;
|
||||
}
|
||||
}
|
||||
|
||||
structureElement = NewElement("structure");
|
||||
gdmlElement->appendChild(structureElement);
|
||||
}
|
||||
@@ -480,6 +564,8 @@ TraverseVolumeTree(const G4LogicalVolume* const volumePtr, const G4int depth)
|
||||
daughterCount = 0;
|
||||
}
|
||||
|
||||
std::vector<int> addedImprints;
|
||||
|
||||
for (G4int i=0;i<daughterCount;i++) // Traverse all the children!
|
||||
{
|
||||
const G4VPhysicalVolume* const physvol = volumePtr->GetDaughter(i);
|
||||
@@ -532,16 +618,100 @@ TraverseVolumeTree(const G4LogicalVolume* const volumePtr, const G4int depth)
|
||||
}
|
||||
ReplicavolWrite(volumeElement,physvol);
|
||||
}
|
||||
else // Is it a physvol?
|
||||
else // Is it a physvol or an assembly?
|
||||
{
|
||||
G4RotationMatrix rot;
|
||||
if (physvol->GetFrameRotation() != 0)
|
||||
if(assemblyVolMap.find(physvol) != assemblyVolMap.end())
|
||||
{
|
||||
rot = *(physvol->GetFrameRotation());
|
||||
int assemblyID = assemblyVolMap[physvol];
|
||||
|
||||
G4String assemblyref = "Assembly_" + std::to_string(assemblyID);
|
||||
|
||||
// here I need to retrieve the imprint ID
|
||||
|
||||
G4int imprintID = imprintsMap[physvol];
|
||||
|
||||
// there are 2 steps:
|
||||
//
|
||||
// 1) add assembly to the structure if that has not yet been done
|
||||
// (but after the constituents volumes have been added)
|
||||
//
|
||||
|
||||
if(std::find(addedAssemblies.begin(), addedAssemblies.end(), assemblyID) == addedAssemblies.end())
|
||||
{
|
||||
AssemblyWrite(structureElement, assemblyID);
|
||||
addedAssemblies.push_back(assemblyID);
|
||||
}
|
||||
|
||||
// 2) add the assembly (as physical volume) to the mother volume (but only once),
|
||||
// using it's original position and rotation.
|
||||
//
|
||||
|
||||
// here I need a check if assembly has been already added to the mother volume
|
||||
if(std::find(addedImprints.begin(), addedImprints.end(), imprintID) == addedImprints.end())
|
||||
{
|
||||
G4String imprintname = "Imprint_" + std::to_string(imprintID);
|
||||
imprintname = GenerateName(imprintname, physvol);
|
||||
|
||||
// I need to get those two from the container of imprints from the assembly
|
||||
// I have the imprint ID, I need to get pos and rot
|
||||
//
|
||||
G4Transform3D& transf =
|
||||
G4AssemblyStore::GetInstance()->GetAssembly(assemblyID)->GetImprintTransformation(imprintID);
|
||||
|
||||
HepGeom::Scale3D scale;
|
||||
HepGeom::Rotate3D rotate;
|
||||
HepGeom::Translate3D translate;
|
||||
|
||||
transf.getDecomposition(scale,rotate,translate);
|
||||
|
||||
const G4ThreeVector scl(scale(0,0),scale(1,1),scale(2,2));
|
||||
const G4ThreeVector rot = GetAngles(rotate.getRotation().inverse());
|
||||
const G4ThreeVector pos = transf.getTranslation();
|
||||
|
||||
// here I need a normal physvol referencing to my assemblyref
|
||||
|
||||
xercesc::DOMElement* physvolElement = NewElement("physvol");
|
||||
physvolElement->setAttributeNode(NewAttribute("name",imprintname));
|
||||
|
||||
xercesc::DOMElement* volumerefElement = NewElement("volumeref");
|
||||
volumerefElement->setAttributeNode(NewAttribute("ref",assemblyref));
|
||||
physvolElement->appendChild(volumerefElement);
|
||||
|
||||
if (std::fabs(pos.x()) > kLinearPrecision
|
||||
|| std::fabs(pos.y()) > kLinearPrecision
|
||||
|| std::fabs(pos.z()) > kLinearPrecision)
|
||||
{
|
||||
PositionWrite(physvolElement,imprintname+"_pos",pos);
|
||||
}
|
||||
if (std::fabs(rot.x()) > kAngularPrecision
|
||||
|| std::fabs(rot.y()) > kAngularPrecision
|
||||
|| std::fabs(rot.z()) > kAngularPrecision)
|
||||
{
|
||||
RotationWrite(physvolElement,imprintname+"_rot",rot);
|
||||
}
|
||||
if (std::fabs(scl.x()-1.0) > kRelativePrecision
|
||||
|| std::fabs(scl.y()-1.0) > kRelativePrecision
|
||||
|| std::fabs(scl.z()-1.0) > kRelativePrecision)
|
||||
{
|
||||
ScaleWrite(physvolElement,name+"_scl",scl);
|
||||
}
|
||||
|
||||
volumeElement->appendChild(physvolElement);
|
||||
//
|
||||
addedImprints.push_back(imprintID);
|
||||
}
|
||||
}
|
||||
G4Transform3D P(rot,physvol->GetObjectTranslation());
|
||||
else // not part of assembly, so a normal physical volume
|
||||
{
|
||||
G4RotationMatrix rot;
|
||||
if (physvol->GetFrameRotation() != 0)
|
||||
{
|
||||
rot = *(physvol->GetFrameRotation());
|
||||
}
|
||||
G4Transform3D P(rot,physvol->GetObjectTranslation());
|
||||
|
||||
PhysvolWrite(volumeElement,physvol,invR*P*daughterR,ModuleName);
|
||||
PhysvolWrite(volumeElement,physvol,invR*P*daughterR,ModuleName);
|
||||
}
|
||||
}
|
||||
// BorderSurfaceCache(GetBorderSurface(physvol));
|
||||
GetBorderSurface(physvol);
|
||||
|
||||
Reference in New Issue
Block a user