How to do sphere voxelation

Hi
I am using geant4 10.06.p02.

i want to divide a sphere into several shells with different radius.

i have used replica and G4VNestedParameterisation like i had used for Box before and it worked good.

this is my DetectorConstruction’s construct method :

G4NistManager* nist = G4NistManager::Instance();

G4Material* _world_mat = nist->FindOrBuildMaterial(“G4_Galactic”);

G4Material* _phantom_mat = nist->FindOrBuildMaterial(“G4_WATER”);

auto world_solid = new G4Box(“WORLD”,1m,1m,1*m);

auto world_logic = new G4LogicalVolume(world_solid,_world_mat,“World_logic”);

auto world_phy = new G4PVPlacement(0,G4ThreeVector(),world_logic,“World_PHYSI”,0,false,0,true);

auto sphere_solid = new G4Sphere(“sphere solid”,0,60cm,0deg,360deg,0deg,180*deg);

auto sphere_logic= new G4LogicalVolume(sphere_solid,_phantom_mat,“sphere logic”);

new G4PVPlacement(0,G4ThreeVector(0,0,0),sphere_logic,“sphere solid”,world_logic,false,0,true);

auto repSolidPhi = new G4Sphere("_SOLID",0,60cm,0deg,36deg,0deg,180*deg);

auto repLogicPhi= new G4LogicalVolume(repSolidPhi,_phantom_mat,"_LOGIC");

new G4PVReplica(“repZ”,repLogicPhi,sphere_logic,kPhi,10,36*deg);

auto repSolidR = new G4Sphere("_SOLID",0,6cm,0deg,36deg,0deg,180*deg);

auto repLogicR= new G4LogicalVolume(repSolidR,_phantom_mat,"_LOGIC");

std::vector<G4Material*> mat(2,_phantom_mat);

G4double dr=6*cm;

G4double dphi=36*deg;

G4double dtheta=180*deg;

Parameterisation* voxelpara = new Parameterisation(G4ThreeVector(dr,dphi,dtheta),(G4int)10,mat);

new G4PVParameterised(“voxel1”,repLogicR,repLogicPhi,kUndefined,(G4int)10,voxelpara);

and this is parameterization class :

Parameterisation::Parameterisation(const G4ThreeVector& voxelsize_sphere,G4int NZ_SPHERE,std::vector<G4Material*>& Mat):
G4VNestedParameterisation(),dr(voxelsize_sphere.x()),dphi(voxelsize_sphere.y()),dtheta(voxelsize_sphere.z()),nz_sphere(NZ_SPHERE),mat(Mat)
{
pz_cart.clear();
pz_sphere.clear();

G4double z_sphere;

for(G4int i=0;i<nz_sphere;i++)
{
z_sphere=i*dr;
pz_sphere.push_back(z_sphere);

}

}

Parameterisation::~Parameterisation(){pz_sphere.clear();pz_cart.clear();}

void Parameterisation::ComputeTransformation(const G4int copyNo,G4VPhysicalVolume* pv) const
{
G4ThreeVector origin(0,0,0/pz_cart[copyNo]/);
pv->SetTranslation(origin);
pv->SetRotation(0);
}
void Parameterisation::ComputeDimensions (G4Sphere& sphere,const G4int copyNo, const G4VPhysicalVolume*) const
{
sphere.SetInnerRadius(pz_sphere[copyNo]);
sphere.SetOuterRadius(pz_sphere[copyNo]+dr);
sphere.SetStartPhiAngle(0deg);
sphere.SetDeltaPhiAngle(dphi);
sphere.SetStartThetaAngle(0
deg);
sphere.SetDeltaThetaAngle(dtheta);
}

i get this warning and it takes too long.


What is the problem?
is there any another way to divide a sphere into several shell for scoring ?

I want to create a shell detector

Like this topic

Using nestedparameterization and replica dose not work correctly

Is there a way to do this?

Thanks,

Hi, could you please check if you have the same problem running the simulation with the sphere WITHOUT the voxelisation?

cheers
Susanna

1 Like

Hi guatelli
Thank you for your reply

As you said, i ran it without voxelisation it worked correctly and there was no problem

could you try to use Parameterised volumes instead of nested ones?

1 Like

I used parameterisation instead of nested, and the warning did not appear, but it toke so time to simulate less than 100 thousand primary photons.
it just was simulating photon passing through a 10 cm sphere with 10 shells 1 cm thickness and nothing were not being scored.

i had used a box with 1 million voxel 1x1x1 mm and it ran much more faster.

Is there any problem with using sphere or it is normal?

is there any example for sphere voxelisation in geant4 examples?

is there a instruction in geant4 user manual or something else?

Hi keyvantabaei,

Can you explain what pz_cart refers to? I see it invoked twice to be cleared, but then it is also used to set the origin of each sphere. I’m not sure how this works because I assume that vector is empty.

Could you also possibly include an illustration of what your parameterisation is trying to achieve? It looks like you are trying to move a spherical shell every time the copy number changes, but you are also trying to change the radius of that spherical shell every time you move its position. If you included the header file of your parameterisation class this would be helpful as well to see your variable definitions.

Joseph

1 Like

hi JDecunha,

thank you for your reply,

I am trying to create spherical shell detectors for calculating dose kernel by Monte Carlo simulation.
dividing a sphere into shells with a different radius for calculating the dose kernel in each shell.
like these pictures :

Screenshot from 2021-05-13 17-37-32
Screenshot from 2021-05-13 17-37-10

pz_chart referred to a vector that keeps cubic voxel z locations for box voxelisation. it does not use here I commended it (/* … */)(I edited classes that I used for box voxelisation, because this is the first time that i am trying to do sphere voxelisation i tried to do something like box voxelisation)

I attach my last files that I am using them.

Keyvan Tabaei

Parameterisation.cc (1.1 KB)
Parameterisation.hh (2.6 KB)

Hi keyvantabaei,

I believe your issue comes from trying to place a parameterised volume inside of a replicated volume. Is the G4PVReplica functionality a necessary part of your code?

The constructor you are invoking for G4PVParameterised is:

G4PVParameterised::G4PVParameterised ( const G4String & pName,
G4LogicalVolume * pLogical,
G4LogicalVolume * pMotherLogical,
const EAxis pAxis,
const G4int nReplicas,
G4VPVParameterisation * pParam,
G4bool pSurfChk = false)

Where your pMotherLogical is a logical volume that has been placed many times by your replication. I don’t think that using the replicated volume as the mother volume of your parameterisation will work. I would advise you use sphere_logic as your logical mother volume of your Parameterisation and remove the lines regarding G4PVReplica. Is there a reason that that G4PVReplica is required for this application?

Joseph

1 Like

hi JDecunha,

thank you for your reply,

as you said, I replaced sphere_logic instead of replicated sphere logic but nothing did not change, running time is so long for simulating a few primary photons.

G4PVReplica is not a necessary part of my code,I used it because I tried to do something like RE02 Box parameterization.

I am wondering why these classes and instruction is worked for G4Box very fast and very good but for sphere does not, maybe there is a mistake in my application.

I searched in G4 examples for creating spherical shell voxels but did not find any example.

I also searched in User’s Guide: For Application Developers and just find instructions for creating box and cylindrical voxels.

I have seen that the sphere shell detector is used by Gate in some papers and I thought I could do this by Geant4 like RE02 example.

maybe I should create sphere shell logic as much as I need instead of divide a sphere into shells, and track particles in each of them.

Fond regards

Keyvan

Hi Keyvan,

Have you removed the G4PVReplica parts of your code as well? because in your current configuration your parameterisation and your replica will be colliding, which will violate the condition that only 1 volume can inhabit a single location in a mother volume.

How were you using G4Box previously, with a G4Replica? The simulation speed will always decrease when working with curved surfaces compared to flat ones because of the increased complexity of those solids. Though, you only have 10 voxels in your spherical paramaterisation right now, so I would not expect the speed of your simulation to be changed very much.

An additional step you can take, beyond removing the G4PVReplica is to ensure there is a small amount of spacing between the radial edges of your spherical shells. When I have worked with cylindrical and spherical parameterisations in the past, I have found there is a small amount of overlap between the shells unless I force there to be some space between. You could do so like this:

sphere.SetInnerRadius(pz_sphere[copyNo]);
//Leave 1% of space between the radial shells
sphere.SetOuterRadius(pz_sphere[copyNo]+(dr*0.99));

I hope this is helpful. Are you still seeing the errors that you shared above? or is your only issue now that the code is running slowly.

Joseph

1 Like

hi JDecunha,

thank you for your reply,

I removed the line which invoked G4Replica and used sphere logic as *pMotherLogical of G4PVParameterised.

Yes,I did G4Box NestedParameterization with G4Replica it worked well and fast.
No, that error does not appear anymore, just the running time is so long.

I set 10 voxels but it would be increased, I just set it 10 for testing application.

as you said I left %1 between the radial shell but it was running like before.

I defined 100 spherical shells, tracked particles by identifying each volume in every step, and scored some data. it worked well and fast. so why using parameterization did not work?

have you done spherical parameterizations by using NestedParameterisation?was it running normally?

I appreciate your response to this issue

found regards,

Keyvan

I would ask to Makoto Asai (asai@slac.stanford.edu) if the Nested Param works for voxelisation of spheres in spherical shells. I am not sure Nested Param can handle it. I would ask to Makoto as he is the developer of that functionality.

Cheers

1 Like