File indexing completed on 2025-02-23 09:22:01
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
0030 #include "RodChromosome.hh"
0031
0032 #include "G4PhysicalConstants.hh"
0033 #include "G4RandomDirection.hh"
0034 #include "Randomize.hh"
0035
0036 #include <utility>
0037
0038
0039
0040 const G4String RodChromosome::fShape = "rod";
0041
0042 RodChromosome::RodChromosome(const G4String& name, const G4ThreeVector& pos, const G4double& radius,
0043 const G4double& height)
0044 : VirtualChromosome(name),
0045 fCenter(pos),
0046 fRadius(radius),
0047 fHeight(height),
0048 fRotation(G4RotationMatrix())
0049 {
0050 fInverseRotation = fRotation.inverse();
0051 }
0052
0053
0054
0055 RodChromosome::RodChromosome(const G4String& name, const G4ThreeVector& pos, const G4double& radius,
0056 const G4double& height, const G4RotationMatrix& rot)
0057 : VirtualChromosome(name), fCenter(pos), fRadius(radius), fHeight(height), fRotation(rot)
0058 {
0059 fInverseRotation = fRotation.inverse();
0060 }
0061
0062
0063
0064 RodChromosome::~RodChromosome() = default;
0065
0066
0067
0068 G4bool RodChromosome::PointInChromosome(G4ThreeVector const& pos)
0069 {
0070 G4ThreeVector rpos = pos - fCenter;
0071 rpos = fInverseRotation(rpos);
0072
0073
0074 bool height_ok;
0075 bool radius_ok;
0076 G4double height;
0077 G4double rad2;
0078
0079 height = std::abs(rpos.getZ());
0080 rad2 = rpos.getX() * rpos.getX() + rpos.getY() * rpos.getY();
0081
0082 height_ok = (height < fHeight);
0083 radius_ok = (rad2 < (fRadius * fRadius));
0084
0085 G4bool in_cylinder = height_ok && radius_ok;
0086
0087 G4ThreeVector pos1 = rpos - G4ThreeVector(0, 0, height);
0088 G4bool in_sphere1 = (pos1.mag2() < (fRadius * fRadius));
0089 G4ThreeVector pos2 = rpos + G4ThreeVector(0, 0, height);
0090 G4bool in_sphere2 = (pos2.mag2() < (fRadius * fRadius));
0091
0092 return (in_cylinder || in_sphere1 || in_sphere2);
0093 }
0094
0095
0096
0097
0098 G4ThreeVector RodChromosome::RandomPointInChromosome()
0099 {
0100 G4ThreeVector point;
0101 if (G4UniformRand() < 0.5) {
0102
0103 G4double z = 2 * (G4UniformRand() - 0.5) * fHeight;
0104 G4double theta = twopi * G4UniformRand();
0105 G4double r = fRadius * std::pow(G4UniformRand(), 0.5);
0106 G4double x = r * std::cos(theta);
0107 G4double y = r * std::sin(theta);
0108 point = G4ThreeVector(x, y, z);
0109 }
0110 else {
0111
0112 point = fRadius * std::pow(G4UniformRand(), 0.5) * G4RandomDirection();
0113 if (point.getZ() < 0) {
0114
0115 point.setZ(point.getZ() - fHeight);
0116 }
0117 else {
0118
0119 point.setZ(point.getZ() + fHeight);
0120 }
0121 }
0122 return fRotation(point) + fCenter;
0123 }
0124
0125