File indexing completed on 2026-09-15 08:29:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "BoundedBrownianAction.hh"
0030
0031 #include "G4DNABoundingBox.hh"
0032 #include "G4Molecule.hh"
0033 #include "G4Track.hh"
0034
0035
0036
0037 BoundedBrownianAction::BoundedBrownianAction() : G4VUserBrownianAction() {}
0038
0039
0040 G4double BoundedBrownianAction::GetDistanceToBoundary(const G4Track& track)
0041 {
0042 if (!fpBoundingBox->contains(track.GetPosition())) {
0043 G4ExceptionDescription errMsg;
0044 errMsg << "Point is out of box : " << *fpBoundingBox
0045 << " of particle : " << GetIT(track)->GetName() << "(" << track.GetTrackID()
0046 << ") : " << track.GetPosition();
0047 G4Exception(
0048 "BoundedBrownianAction::GetDistanceToBoundary"
0049 "BoundedBrownianAction",
0050 "BoundedBrownianAction", FatalErrorInArgument, errMsg);
0051 }
0052
0053 auto dx = std::min(track.GetPosition().getX() - fpBoundingBox->Getxlo(),
0054 fpBoundingBox->Getxhi() - track.GetPosition().getX());
0055 auto dy = std::min(track.GetPosition().getY() - fpBoundingBox->Getylo(),
0056 fpBoundingBox->Getyhi() - track.GetPosition().getY());
0057 auto dz = std::min(track.GetPosition().getZ() - fpBoundingBox->Getzlo(),
0058 fpBoundingBox->Getzhi() - track.GetPosition().getZ());
0059 return std::min({dx, dy, dz});
0060 }
0061
0062
0063
0064 void BoundedBrownianAction::Transport(G4ThreeVector& nextposition, G4Track*)
0065 {
0066 BouncingAction(nextposition);
0067 }
0068
0069
0070
0071 void BoundedBrownianAction::BouncingAction(G4ThreeVector& nextposition) const
0072 {
0073
0074
0075 G4double RxM = fpBoundingBox->Getxhi();
0076 G4double RyM = fpBoundingBox->Getyhi();
0077 G4double RzM = fpBoundingBox->Getzhi();
0078
0079 G4double Rxm = fpBoundingBox->Getxlo();
0080 G4double Rym = fpBoundingBox->Getylo();
0081 G4double Rzm = fpBoundingBox->Getzlo();
0082 G4double Lx = RxM - Rxm;
0083 G4double Ly = RyM - Rym;
0084 G4double Lz = RzM - Rzm;
0085 G4double trunx = trunc(std::abs(nextposition.getX() - Rxm) / Lx);
0086 G4double truny = trunc(std::abs(nextposition.getY() - Rym) / Ly);
0087 G4double trunz = trunc(std::abs(nextposition.getZ() - Rzm) / Lz);
0088 G4double hx = std::fmod(trunx, 2);
0089 G4double hy = std::fmod(truny, 2);
0090 G4double hz = std::fmod(trunz, 2);
0091 G4double x = Rxm + hx * Lx + (1 - 2 * hx) * std::abs(std::fmod(nextposition.getX() - Rxm, Lx));
0092 G4double y = Rym + hy * Ly + (1 - 2 * hy) * std::abs(std::fmod(nextposition.getY() - Rym, Ly));
0093 G4double z = Rzm + hz * Lz + (1 - 2 * hz) * std::abs(std::fmod(nextposition.getZ() - Rzm, Lz));
0094 nextposition.set(x, y, z);
0095 }
0096
0097