Need advice how to create Hexagonal prism

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.


I try to triangulate the bottom plane and then using triangular facets. And this is the result:

But I wonder if there is any other elegant way to do this? (the bottom is actually a plane, the point inside the bottom plane can be removed)

You did everything right. The only advice I can give is to subdivide the bottom plane into quadrilaterals instead of triangles.

BTW, lateral planes also can be subdivided into quadrilaterals.

For the lateral planes, I do want to subdivide into quadrilaterals :joy: . but the results gives me the triangles:

for(auto iter = convexHull.begin(); iter != convexHull.end() - 1; iter++){
        mountain->AddFacet((G4VFacet *)new G4QuadrangularFacet(*iter, 
                                                               G4ThreeVector(iter->x(), iter->y(), 0.0),
                                                               G4ThreeVector((iter + 1)->x(), (iter + 1)->y(), 0.0),
                                                               *(iter+1),
                                                               ABSOLUTE));
    }

convexHull is the sorted points on the convex hull of my point set and it is in counterclockwise.

Strange, I have no reasonable explanation. The code looks OK for me.

Thank you very much!

Hi, evc. I try to run with newer version Geant4 (10.05 to 10.07). the triangles in the lateral planes disappeared.

Sorry to all. This warning is a bug in my code. the vertices order of the triangles in my bottom plane is clockwise (it should be counter-clockwise).

Hello Evc,

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

Thank you,
Helen

Hello Helen,

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.

Hello Evc,

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?

Thank you again
Helen

For Instance I would like to do sth like this:

The picture is from another conversation in the forum.
Thank you again

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.

Hello evc,

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.

Do I have to include more packages?

Thank you a lot.

I hope this is my last question.

Best
Helen

It looks that you placed this function inside another function.

Ok so I removed the function and I define the variables outside.
But I do not see any hexagons.
Do I have to do G4bool?

  G4double d;
  G4double xc;
  G4int nhex;
  bool checkOverlaps = true;
  for (G4int i=0; i<nhex; ++i) 
   {G4ThreeVector pos(xc, d*(i - (nhex-1)*0.5), 0.);
    new G4PVPlacement(0,              // no rotation                                                                    
                      pos,            // position                                                                       
                      logicHexagon,     // logical volume                                                                 
                      "hexa",      // its name                                                                       
                      detectorLV,      // its mother  volume                                                             
                      false,          // no boolean operation                                                           
                      0,              // copy number                                                                    
                      checkOverlaps);} //overlaps checking                                                               

Thank you again
Helen

nhex will be zero if you don’t assign a value to it, so your loop counts from 0 to 0 → no hexagons to admire

edit: note this is the case for d and xc as well…

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:

void PlaceHexagons(double d, double xc, int nhex, G4LogicalVolume,  G4LogicalVolume)
{
  bool checkOverlaps = true;
  for (int i=0; i<nhex; ++i) {
    G4ThreeVector pos(xc, d*(i - (nhex-1)*0.5), 0.);
                                                                 
  }
}

and then call it while I create the logical volumes?
i.e. here:

auto detectorLV
    = new G4LogicalVolume(
			  detectorS,
			  Material,
			  "Detector");

and here

G4LogicalVolume* logicHexagon =                         
     new G4LogicalVolume  (Hexagon,
			                   Material,
			                   "hexa_log");

?
Or I define these logical volumes normally and then I place the hexagonal prisms inside them calling the function?
Thank you
Helen

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

  1. Create a solid for Box; Create a logical volume detectorLV; Create a physical volume detectorPV.
  2. Create a solid for Hexagon.
  3. Create a logical volume logicHexagon.
  4. 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); 

Good morning,

Thank you for your answer yesterday I finally manage to use the function and I placed the function where you told me.

But I guess now I have to create another function and change the y coordinate in order to have this shape?

Otherwise I think I will get only this?

Thank you
Helen

combining

with

→ one way would be an extra y-offset yc:

void PlaceHexagons(double d, double xc, double yc, int nhex, G4LogicalVolume* logHexagon,  G4LogicalVolume* logMother)
{
  bool checkOverlaps = true;
  for (int i=0; i<nhex; ++i) {
    G4ThreeVector pos(xc, yc + 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                                                               
  }
}