Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TrajectoryDrawerUtils Namespace Reference

Enumerations

enum  TimesValidity { InvalidTimes , ValidTimes }

Functions

void GetPoints (const G4VTrajectory &traj, G4Polyline &trajectoryLine, G4Polymarker &auxiliaryPoints, G4Polymarker &stepPoints)
void DrawLineAndPoints (const G4VTrajectory &traj, const G4VisTrajContext &)
TimesValidity GetPointsAndTimes (const G4VTrajectory &traj, const G4VisTrajContext &context, G4Polyline &trajectoryLine, G4Polymarker &auxiliaryPoints, G4Polymarker &stepPoints, std::vector< G4double > &trajectoryLineTimes, std::vector< G4double > &auxiliaryPointTimes, std::vector< G4double > &stepPointTimes)

Enumeration Type Documentation

◆ TimesValidity

Function Documentation

◆ DrawLineAndPoints()

void G4TrajectoryDrawerUtils::DrawLineAndPoints ( const G4VTrajectory & traj,
const G4VisTrajContext & context )

Definition at line 322 of file G4TrajectoryDrawerUtils.cc.

323{
324 // Return if don't need to do anything
325 if (!context.GetDrawLine() && !context.GetDrawAuxPts() && !context.GetDrawStepPts()) return;
326
327 // Get points and times (times are returned only if time-slicing
328 // is requested).
329 G4Polyline trajectoryLine;
330 G4Polymarker stepPoints;
331 G4Polymarker auxiliaryPoints;
332 std::vector<G4double> trajectoryLineTimes;
333 std::vector<G4double> stepPointTimes;
334 std::vector<G4double> auxiliaryPointTimes;
335
336 TimesValidity validity =
337 GetPointsAndTimes(traj, context, trajectoryLine, auxiliaryPoints, stepPoints,
338 trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes);
339
340 if (validity == ValidTimes) {
341 SliceLine(context.GetTimeSliceInterval(), trajectoryLine, trajectoryLineTimes);
342
343 DrawWithTime(context, trajectoryLine, auxiliaryPoints, stepPoints, trajectoryLineTimes,
344 auxiliaryPointTimes, stepPointTimes);
345 }
346 else {
347 DrawWithoutTime(context, trajectoryLine, auxiliaryPoints, stepPoints);
348 }
349}
G4bool GetDrawAuxPts() const
G4double GetTimeSliceInterval() const
G4bool GetDrawLine() const
G4bool GetDrawStepPts() const
TimesValidity GetPointsAndTimes(const G4VTrajectory &traj, const G4VisTrajContext &context, G4Polyline &trajectoryLine, G4Polymarker &auxiliaryPoints, G4Polymarker &stepPoints, std::vector< G4double > &trajectoryLineTimes, std::vector< G4double > &auxiliaryPointTimes, std::vector< G4double > &stepPointTimes)

Referenced by G4TrajectoryDrawByAttribute::Draw(), G4TrajectoryDrawByCharge::Draw(), G4TrajectoryDrawByEncounteredVolume::Draw(), G4TrajectoryDrawByOriginVolume::Draw(), G4TrajectoryDrawByParticleID::Draw(), and G4TrajectoryGenericDrawer::Draw().

◆ GetPoints()

void G4TrajectoryDrawerUtils::GetPoints ( const G4VTrajectory & traj,
G4Polyline & trajectoryLine,
G4Polymarker & auxiliaryPoints,
G4Polymarker & stepPoints )

◆ GetPointsAndTimes()

TimesValidity G4TrajectoryDrawerUtils::GetPointsAndTimes ( const G4VTrajectory & traj,
const G4VisTrajContext & context,
G4Polyline & trajectoryLine,
G4Polymarker & auxiliaryPoints,
G4Polymarker & stepPoints,
std::vector< G4double > & trajectoryLineTimes,
std::vector< G4double > & auxiliaryPointTimes,
std::vector< G4double > & stepPointTimes )

Definition at line 58 of file G4TrajectoryDrawerUtils.cc.

64{
65 TimesValidity validity = InvalidTimes;
66 if (context.GetTimeSliceInterval()) validity = ValidTimes;
67
68 // Memory for last trajectory point position for auxiliary point
69 // time interpolation algorithm. There are no auxiliary points
70 // for the first trajectory point, so its initial value is
71 // immaterial.
72 G4ThreeVector lastTrajectoryPointPosition;
73
74 // Keep positions. Don't store unless first or different.
75 std::vector<G4ThreeVector> positions;
76
77 for (G4int iPoint = 0; iPoint < traj.GetPointEntries(); iPoint++) {
78 G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(iPoint);
79 const G4ThreeVector& trajectoryPointPosition = aTrajectoryPoint->GetPosition();
80
81 // Only store if first or if different
82 if (positions.size() == 0 || trajectoryPointPosition != positions[positions.size() - 1]) {
83 // Pre- and Post-Point times from the trajectory point...
84 G4double trajectoryPointPreTime = -std::numeric_limits<double>::max();
85 G4double trajectoryPointPostTime = std::numeric_limits<double>::max();
86
87 if (context.GetTimeSliceInterval() && validity == ValidTimes) {
88
89 const auto richTrajectoryPoint = dynamic_cast<G4RichTrajectoryPoint*>(aTrajectoryPoint);
90 if (richTrajectoryPoint) {
91 trajectoryPointPreTime = richTrajectoryPoint->GetPreStepPointGlobalTime();
92 trajectoryPointPostTime = richTrajectoryPoint->GetPostStepPointGlobalTime();
93 if (trajectoryPointPostTime > 1000000. * context.GetTimeSliceInterval()) {
94 static G4bool warnedTimeExceeded = false;
95 if (!warnedTimeExceeded) {
96 G4Exception("G4TrajectoryUtils::GetPointsAndTimes", "modeling0128", JustWarning,
97 "Trajectory point times exceed limit (>1000000 time slice)."
98 "\nNormal trajectory will be drawn.");
99 warnedTimeExceeded = true;
100 }
101 validity = InvalidTimes;
102 }
103 } else {
104 static G4bool warnedNoAttValues = false;
105 if (!warnedNoAttValues) {
106 G4Exception("G4TrajectoryUtils::GetPointsAndTimes", "modeling0127", JustWarning,
107 "Trajectory point times not found. Use G4RichTrajectory:"
108 "\n /vis/scene/add/trajectories rich");
109 warnedNoAttValues = true;
110 }
111 validity = InvalidTimes;
112 }
113 }
114
115 const std::vector<G4ThreeVector>* auxiliaries = aTrajectoryPoint->GetAuxiliaryPoints();
116 if (0 != auxiliaries) {
117 for (size_t iAux = 0; iAux < auxiliaries->size(); ++iAux) {
118 const G4ThreeVector& auxPointPosition = (*auxiliaries)[iAux];
119 if (positions.size() == 0 || auxPointPosition != positions[positions.size() - 1]) {
120 // Only store if first or if different
121 positions.push_back(trajectoryPointPosition);
122 trajectoryLine.push_back(auxPointPosition);
123 auxiliaryPoints.push_back(auxPointPosition);
124 if (validity == ValidTimes) {
125 // Interpolate time for auxiliary points...
126 G4double s1 = (auxPointPosition - lastTrajectoryPointPosition).mag();
127 G4double s2 = (trajectoryPointPosition - auxPointPosition).mag();
128 G4double t = trajectoryPointPreTime
129 + (trajectoryPointPostTime - trajectoryPointPreTime) * (s1 / (s1 + s2));
130 trajectoryLineTimes.push_back(t);
131 auxiliaryPointTimes.push_back(t);
132 }
133 }
134 }
135 }
136
137 positions.push_back(trajectoryPointPosition);
138 trajectoryLine.push_back(trajectoryPointPosition);
139 stepPoints.push_back(trajectoryPointPosition);
140 if (validity == ValidTimes) {
141 trajectoryLineTimes.push_back(trajectoryPointPostTime);
142 stepPointTimes.push_back(trajectoryPointPostTime);
143 }
144 lastTrajectoryPointPosition = trajectoryPointPosition;
145 }
146 }
147 return validity;
148}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
virtual const std::vector< G4ThreeVector > * GetAuxiliaryPoints() const
virtual const G4ThreeVector GetPosition() const =0
virtual G4VTrajectoryPoint * GetPoint(G4int i) const =0
virtual G4int GetPointEntries() const =0

Referenced by DrawLineAndPoints().