Thanks for your reply!
In my object, the bottom plane is a “polygon”. I have add all the other facets except the bottom plane. But G4TessellatedSolid requires a fully enclosed space.

Thank you a lot for your help and excuse my low level of knowledge of Geant.
I manage to create then hexagon. Thank you a lot.
But now I have some problems to make more of them inside the box.
Does replica works for the hexagon? I want the also to have specific distance between them.
Do I have to use some other function instead of replica?

new G4PVReplica(
“all”, // its name
logicHexagon, // its logical volume
detector_logical, // its mother
kYAxis, // axis of replication
2,
0.05); // witdth of replica

Do I have to use Parameterisation? and how does this work? As replica or I have to create a class?
ps: I am attaching you the hexagon

Replica allows to describe a sequence of identical volumes inside mother volume. The position of these volumes is defined by a translation on the same distance along specified axis. Replica works with any kind of solids.

As I understand in your case there will be not so many hexahedrons inside a box. If you know the position of all hexahedrons, then may be it will be easier for you to place the hexahedrons into the box by using G4PVPlacement.

Thank you a lot for your answer. Eventually first I will implement without the gap between the hexagonal prisms. So I think the best choice is replica.
Eventually the box has to be much larger, so there will be a lot of them so it would be very difficult and long to place them one by one.
My replica eventually worked but there is overlapping (not the error) between the hexagons.
I am attaching you the image. How can be side by side?
Is it because of the way the ExtrudedSolid was created?

The hexagonal cells on the images can be subdivided in vertical sets. So, I would implement a function PlaceHexagons() that places a vertical set of hexagons into its mother volume (box).

Parameters:

d - the mesh cell diameter xc - x coordinate of the set nhex - number of hexagons in the set logHexagon - logical volume of the hexagon logMother - its mother logical volume

It is easy to verify that the radius of the circumscribed circle around a cell is r=d/sqrt(3), hence the distance between two adjacent vertical sets is 1.5*r. So, xc for the sets should be equal: 0., -1.5*r, 1.5.*r, -3*r, 3.*r, ...

void PlaceHexagons(double d, double xc, int nhex, G4LogicalVolume* logHexagon, G4LogicalVolume* logMother)
{
bool checkOverlaps = true;
for (int i=0; i<nhex; ++i) {
G4ThreeVector pos(xc, d*(i - (nhex-1)*0.5), 0.);
new G4PVPlacement(0, // no rotation
pos, // position
logHexagon, // logical volume
"Hexagon", // its name
logMother, // its mother volume
false, // no boolean operation
0, // copy number
checkOverlaps); //overlaps checking
}
}

The function is similar to replica, but it is easier to understand how the hexagons are placed into the mother volume.

Thank you a lot for your answer. It really helped. But i do it and I the error: error: a function-definition is not allowed here before ‘{’ token
and i searched but I don’t know what to do. Do I have to define the variables outside of the function?
Or have G4int instead of int? I tried them but it doesnt work.

Helen, why you removed the function? Place it just after the last #include statement. To fill the box with hexagons you will need to call this function several times inside another function (DetectorConstruction (?), where you define detectorLV and logicHexagon).

Hello,
Thank you once more for your prompt answer. I know that I am not that good since I also learn c++ during this process, so I do not also understand some things.
I removed the function, In order to remove the error with the token.
And now I am a little confused, how I can use the function placehexagons which contains the logical volumes to define the logical volumes?
So you suggest to write this after my last include statement:

Function PlaceHexagons() creates nhex physical volumes. So, the skeleton of the function where you construct your detector should look like the following:

Create a solid for Box; Create a logical volume detectorLV; Create a physical volume detectorPV.

Create a solid for Hexagon.

Create a logical volume logicHexagon.

Create multiple physical volumes that will fill detectorLV.

For point 4, you should call PlaceHexagons() several times, but you can start with just one call of PlaceHexagons(), it will create one vertical set of hexagonal volumes.

PlaceHexagons() has 5 parameters. You should assign values to d, xc, nhex before to pass them to the function. As two last parameters you pass logicHexagon and detectorLV. You should have something like:

G4double d = SizeXY/10.;
G4double r = d/std::sqrt(3.);
PlaceHexagons(d, 0.*r, 10, logicHexagon, logicLV);