Hexagonal lattice geometry

Hi,

I am new to geant4 and I am using geant4 to conduct a simulation which requires a geometry with hexagonal lattice placement. The geometry consists of a hexagonal placement of smaller sub-geometry (small spheres). I used for loops to place spheres into a larger lattice sphere. However, the program encounters segmentation fault when the amount of small sphere is large. I was wondering if there is any way to solve this or another way to construct such geometry.

Thanks in advance.:slight_smile:

the code is pasted here:
latticeS = new G4MultiUnion(“MOFLatticeSolid”);
G4double limit = round((flattice_radius-frmax_mof)/fdistance);

for (G4double i=-limit; i<=limit; i++) //2*limit is the total number along the axis
{
    for (G4double j=-limit; j<=limit; j++)
    {
        for (G4double k=-limit; k<=limit; k++)
        {
            G4double x1=i*fdistance;
            G4double x2=(0.5+i)*fdistance;
            
            G4double y1=j*fdistance;
            G4double y2=(0.5+j)*fdistance;
            G4double y3=(0.25+j)*fdistance;
            G4double y4=(j-0.25)*fdistance;
            
            G4double z1=2*k*sin(60*deg)*fdistance;
            G4double z2=(2*k+1)*sin(60*deg)*fdistance;

            G4ThreeVector position1 = G4ThreeVector(x1, y1, z1);
            G4ThreeVector position2 = G4ThreeVector(x2, y2, z1);
            G4ThreeVector position3 = G4ThreeVector(x1, y3, z2);
            G4ThreeVector position4 = G4ThreeVector(x2, y4, z2);
            
            G4RotationMatrix rotm  = G4RotationMatrix(); //no rotation
            
            G4Transform3D transform1 = G4Transform3D(rotm,position1);
            G4Transform3D transform2 = G4Transform3D(rotm,position2);
            G4Transform3D transform3 = G4Transform3D(rotm,position3);
            G4Transform3D transform4 = G4Transform3D(rotm,position4);
            
            if (containerS->Inside(position1)==kInside){
                latticeS->AddNode(*mofS,transform1);} //to see whether the point is in a container sphere
            if (containerS->Inside(position2)==kInside){
                latticeS->AddNode(*mofS,transform2);}
            if (containerS->Inside(position3)==kInside){
                latticeS->AddNode(*mofS,transform3);}
            if (containerS->Inside(position4)==kInside){
                latticeS->AddNode(*mofS,transform4);}
        }
    }
}

//close the solid structure

latticeS->Voxelize();

Hello Kkarl-uc,
Please I’m also very new to Geant4 and I’m also working on something with the geometries of collimators.
I also have difficulty simulating the source code for hexagon and other geometries.
Please, if you have resolved it, could you help me with it.
My email: roq4eva@yahoo.com
Thanks.