Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic surface sampler #226

Merged
merged 28 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8dd3883
implement generic surface sampling
tdixon97 Jan 9, 2025
8b0fa2e
[tests] add some basic tests for surface generator
tdixon97 Jan 11, 2025
2072046
[tests] add a more sophisticated test - but ... it fails for the unions
tdixon97 Jan 13, 2025
7d9151e
[docs] add new macro commands
tdixon97 Jan 13, 2025
de50cb9
[tests] try to fix the tests in CI
tdixon97 Jan 13, 2025
81c5d9b
some formatting fixes
tdixon97 Jan 13, 2025
443dbb3
[fix] adjust sampling sphere to have the correct center
tdixon97 Jan 13, 2025
3478a24
formatting
tdixon97 Jan 13, 2025
12bb478
[tests] fix the test of the bounding sphere
tdixon97 Jan 14, 2025
f459e8d
fix linking
tdixon97 Jan 14, 2025
577a391
style: pre-commit fixes
pre-commit-ci[bot] Jan 14, 2025
3e18805
[tests] a bit of reformatting
tdixon97 Jan 14, 2025
257ac05
add some more comments
tdixon97 Jan 14, 2025
b613494
[docs] adding docstrings for some functions
tdixon97 Jan 14, 2025
3eed479
[docs] add some docstrings for generic surface sampling objects
tdixon97 Jan 14, 2025
5a41343
fix merge from pre-commit changes
tdixon97 Jan 14, 2025
8cd6965
fix cmake
tdixon97 Jan 14, 2025
913bba7
more fixes to cmake
tdixon97 Jan 14, 2025
ce8b2d8
Update tests/confinement/CMakeLists.txt
tdixon97 Jan 14, 2025
a795ac3
[docs] adding more documentation
tdixon97 Jan 14, 2025
887eb72
Merge branch 'main' of github.com:tdixon97/remage into main
tdixon97 Jan 14, 2025
5678c73
[docs] small changes
tdixon97 Jan 14, 2025
2751f06
[tests] first attempt to organise all the test outputs into a LaTeX d…
tdixon97 Jan 15, 2025
7a2a1d7
update github actions to save the .tex
tdixon97 Jan 15, 2025
458c621
[tests] update plot formats
tdixon97 Jan 16, 2025
d8677d1
cleanup
tdixon97 Jan 16, 2025
13d2dc5
cleanup and removing the tex
tdixon97 Jan 16, 2025
5dfe307
[docs] update the macro commands file
tdixon97 Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/rmg-commands.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 74 additions & 3 deletions include/RMGVertexConfinement.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class RMGVertexConfinement : public RMGVVertexGenerator {
kGeometrical,
kUnset,
};


RMGVertexConfinement();

void BeginOfRunAction(const G4Run* run) override;
Expand Down Expand Up @@ -96,20 +98,88 @@ class RMGVertexConfinement : public RMGVVertexGenerator {
SampleableObject() = default;
SampleableObject(const SampleableObject&) = default;
SampleableObject(G4VPhysicalVolume* v, G4RotationMatrix r, G4ThreeVector t, G4VSolid* s,
tdixon97 marked this conversation as resolved.
Show resolved Hide resolved
bool cc = true);
bool ns = false, bool ss = false);
// NOTE: G4 volume/solid pointers should be fully owned by G4, avoid trying to delete them
~SampleableObject() = default;
[[nodiscard]] bool IsInside(const G4ThreeVector& vertex) const;
[[nodiscard]] bool Sample(G4ThreeVector& vertex, int max_attempts, bool sample_on_surface,

/**
* @brief Generate a sample from the solid.
*
* @details Depending on if the solid is a basic one either sample natively,
* or using rejection sampling. Either samples the volume or the surface depending
* on the @c surface_sample member.
*
* @param vertex The sampled vertex.
* @param max_attempts The maximum number of candidate vertices for rejection sampling.
* @param force_containment_check Whether to force a check on where the point is
* inside the solid.
* @param n_trials The total number of trials performed.
*
*/
[[nodiscard]] bool Sample(G4ThreeVector& vertex, int max_attempts,
bool force_containment_check, long int& n_trials) const;


/**
* @brief Generate a point on the surface of the solid.
*
* @details This follows the algorithm from https://arxiv.org/abs/0802.2960.
* - Produce a direction vector corresponding to a uniform flux in a bounding sphere.
* - Find the intersections of this line with the solid.
* - Pick one intersection, or repeat.
*
* @param vertex The sampled vertex,
* @param max_samples The maximum number of attempts to find a valid vertex.
* @param n_max The maximum number of intersections possible for the solid,
* can be an overestimate.
*
*/
[[nodiscard]] bool GenerateSurfacePoint(G4ThreeVector& vertex, int max_samples,
int n_max) const;

// methods for the generic surface sampling
/**
* @brief Get the number of intersections between the solid and the line starting at @c
* start with direction @c dir.
*
* @details This is used in the generic surface sampling algorithm. This function makes use
* of the methods @c GetDistanceToIn(p,v) and @c GetDistanceToOut(p,v) of @c G4VSolid .
* It continually looks for the distance to the next boundary (along the line)
* until this becomes zero indicating there are no more intersections.
*
* @param start The starting vector of the line, note this should be outside the solid.
* @param dir The direction vector.
*
* @returns A vector of the points of intersection.
*/
std::vector<G4ThreeVector> GetIntersections(const G4ThreeVector start,
const G4ThreeVector dir) const;


tdixon97 marked this conversation as resolved.
Show resolved Hide resolved
/**
* @brief Get a position and direction for the generic surface sampling algorithm.
*
* @details This generates a point on a bounding sphere, then shifts by some impact
* parameter, following the algorithm from https://arxiv.org/abs/0802.2960. This produces a
* uniform and isotropic flux inside the bounding sphere.
*
* @param dir The direction vector for the point.
* @param pos The initial position for the point.
*
*/
void GetDirection(G4ThreeVector& dir, G4ThreeVector& pos) const;


G4VPhysicalVolume* physical_volume = nullptr;
G4VSolid* sampling_solid = nullptr;
G4RotationMatrix rotation;
G4ThreeVector translation;
double volume = -1;
double surface = -1;
bool containment_check = true;
bool surface_sample = false;
bool native_sample = false;
int max_num_intersections = -1;
};

struct SampleableObjectCollection {
Expand Down Expand Up @@ -179,6 +249,7 @@ class RMGVertexConfinement : public RMGVVertexGenerator {
bool fOnSurface = false;
bool fForceContainmentCheck = false;
bool fLastSolidExcluded = false;
int fMaxNumIntersections = -1;
tdixon97 marked this conversation as resolved.
Show resolved Hide resolved
// counters used for the current run.
long fTrials = 0;
std::chrono::nanoseconds fVertexGenerationTime;
Expand Down
Loading
Loading