# Imported .stl files creating stuck tracks

**URL:** <https://geant4-forum.web.cern.ch/t/imported-stl-files-creating-stuck-tracks/10184>\
**Category:** Geometry, Fields and Transportation\
**Created:** [March 8, 2023, 6:52am UTC](https://geant4-forum.web.cern.ch/t/imported-stl-files-creating-stuck-tracks/10184 "2023-03-08T06:52:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![james.pollock](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/j/e47774/32.png) [@james.pollock](https://geant4-forum.web.cern.ch/u/james.pollock)\
**Post date:** [March 8, 2023, 6:52am UTC](https://geant4-forum.web.cern.ch/t/imported-stl-files-creating-stuck-tracks/10184/1 "2023-03-08T06:52:32Z")

</div>

Hello all,

Hopefully this description wont be too vague but I’m not really sure how to narrow down this problem. I am currently attempting to make a geant4 program for measuring the x-ray dose imparted to an object during a CT scan. I am doing this based of example b1 and have been making fast progress until it came to switching the detector geometry to reflect my experimental data.  
I use dragonfly to segment my images and convert them to a contour mesh, saving as an stl file which i then import into geant4 using the CADMesh package. I am able to visualise these files in opengl perfectly but when it comes to running an event I experience stuck tracks. Initially I thought this may be related to overlap and mesh hole warnings I was getting so I remade the meshes without decimation/smoothing (using a lower sampling instead) and found this got rid of all the warnings and stuck tracks (yay). Except I have found it still occurs on some of the segmentations despite them giving no warnings.

I have tried using freeCAD to clean up images but it just confirmed that the stl files have no errors or holes. Given my program works for some stls and not others I feel like it must be something to do with the files but I don’t know what. My world volume is much bigger than the bounds of the stl files so that shouldn’t be an issue and I check for overlaps upon placement of the solids but it doesn’t give any warnings.  
Can anyone with experience importing stl files into geant4 give any insight into what may be happening? Or otherwise point me in the direction of software that can be reliably used to make stl files from pixelated data volumes?

The error I get is

 ![image](https://geant4-forum.web.cern.ch/uploads/default/original/2X/d/d10a4b9d1dc1c60f32820a8cbac120e84a0d657c.png)

The current physics model I am using is QBBC which I am not sure is fully valid for energies as low as 45keV but my assumption is that if that was creating this problem it would happen consistently.

Thanks in advance for the help

---

<div class="post-metadata">

**Author:** ![weller](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/weller/32/3357_2.png) [@weller](https://geant4-forum.web.cern.ch/u/weller)\
**Post date:** [March 8, 2023, 7:24am UTC](https://geant4-forum.web.cern.ch/t/imported-stl-files-creating-stuck-tracks/10184/2 "2023-03-08T07:24:14Z")

</div>

Do you have in your non-working stl some triangles with very/extremely small aspect ratio?

---

<div class="post-metadata">

**Author:** ![james.pollock](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/j/e47774/32.png) [@james.pollock](https://geant4-forum.web.cern.ch/u/james.pollock)\
**Post date:** [March 9, 2023, 5:10am UTC](https://geant4-forum.web.cern.ch/t/imported-stl-files-creating-stuck-tracks/10184/3 "2023-03-09T05:10:17Z")

</div>

Thank you for the response!  
It could be the case, do you know of a program I could use to check this or revaluate the mesh with more regular triangles?

Out of curiosity though how could oddly shaped triangles create issues with geant4?

---

<div class="post-metadata">

**Author:** ![weller](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/weller/32/3357_2.png) [@weller](https://geant4-forum.web.cern.ch/u/weller)\
**Post date:** [March 9, 2023, 8:54am UTC](https://geant4-forum.web.cern.ch/t/imported-stl-files-creating-stuck-tracks/10184/4 "2023-03-09T08:54:17Z")

</div>

> [@james.pollock](#):
>
> Out of curiosity though how could oddly shaped triangles create issues with geant4?

could be some algorithms to calculate distances/directions. I had a similar issue:

> [@Cadmesh: Sample point is not on the surface](https://geant4-forum.web.cern.ch/t/cadmesh-sample-point-is-not-on-the-surface/5748/4):
>
> The reason of the issue is the calculation error of the algorithm for calculation of a distance from a point to 3D triangle. In your case the error very often was bigger than the thickness of the surface, it resulted in incorrect return value from Inside(). To fix the issue you can change the code for the region 0 in G4TriangularFacet::Distance(p) (line 346) to the following: // // We are in region 0. // G4double dist = fSurfaceNormal.dot(D); fSqrDist = dist\*dist…

> [@james.pollock](#):
>
> It could be the case, do you know of a program I could use to check this or revaluate the mesh with more regular triangles?

I would try MeshLab and use the filter “Remeshing: Isotropic Explicit Remeshing”. You will have to play with the parameters to get the best results…

---

<div class="post-metadata">

**Author:** ![james.pollock](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/j/e47774/32.png) [@james.pollock](https://geant4-forum.web.cern.ch/u/james.pollock)\
**Post date:** [March 13, 2023, 3:50am UTC](https://geant4-forum.web.cern.ch/t/imported-stl-files-creating-stuck-tracks/10184/5 "2023-03-13T03:50:13Z")

</div>

That worked perfectly, thank you!

---

<div class="post-metadata">

**Author:** ![system](https://geant4-forum.web.cern.ch/uploads/default/original/1X/ce519a43ebdf7ac48a98a03c6ad6eea013b68c46.png) [@system](https://geant4-forum.web.cern.ch/u/system)\
**Post date:** [March 20, 2023, 3:50am UTC](https://geant4-forum.web.cern.ch/t/imported-stl-files-creating-stuck-tracks/10184/6 "2023-03-20T03:50:47Z")

</div>

Closed on March 20, 2023, 3:50am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
