Geant4 10.7.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 314 of file G4TrajectoryDrawerUtils.cc.

315 {
316 // Return if don't need to do anything
317 if (!context.GetDrawLine() && !context.GetDrawAuxPts() && !context.GetDrawStepPts()) return;
318
319 // Get points and times (times are returned only if time-slicing
320 // is requested).
321 G4Polyline trajectoryLine;
322 G4Polymarker stepPoints;
323 G4Polymarker auxiliaryPoints;
324 std::vector<G4double> trajectoryLineTimes;
325 std::vector<G4double> stepPointTimes;
326 std::vector<G4double> auxiliaryPointTimes;
327
329 (traj, context,
330 trajectoryLine, auxiliaryPoints, stepPoints,
331 trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes);
332
333 if (validity == ValidTimes) {
334
335 SliceLine(context.GetTimeSliceInterval(),
336 trajectoryLine, trajectoryLineTimes);
337
338 DrawWithTime(context,
339 trajectoryLine, auxiliaryPoints, stepPoints,
340 trajectoryLineTimes, auxiliaryPointTimes, stepPointTimes);
341
342 } else {
343
344 DrawWithoutTime(context, trajectoryLine, auxiliaryPoints, stepPoints);
345
346 }
347 }
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 45 of file G4TrajectoryDrawerUtils.cc.

54 {
55 TimesValidity validity = InvalidTimes;
56 if (context.GetTimeSliceInterval()) validity = ValidTimes;
57
58 // Memory for last trajectory point position for auxiliary point
59 // time interpolation algorithm. There are no auxiliary points
60 // for the first trajectory point, so its initial value is
61 // immaterial.
62 G4ThreeVector lastTrajectoryPointPosition;
63
64 // Keep positions. Don't store unless first or different.
65 std::vector<G4ThreeVector> positions;
66
67 for (G4int iPoint=0; iPoint<traj.GetPointEntries(); iPoint++) {
68
69 G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(iPoint);
70 const G4ThreeVector& trajectoryPointPosition =
71 aTrajectoryPoint->GetPosition();
72
73 // Only store if first or if different
74 if (positions.size() == 0 ||
75 trajectoryPointPosition != positions[positions.size()-1]) {
76
77 // Pre- and Post-Point times from the trajectory point...
78 G4double trajectoryPointPreTime = -std::numeric_limits<double>::max();
79 G4double trajectoryPointPostTime = std::numeric_limits<double>::max();
80
81 if (context.GetTimeSliceInterval() && validity == ValidTimes) {
82
83 std::vector<G4AttValue>* trajectoryPointAttValues =
84 aTrajectoryPoint->CreateAttValues();
85 if (!trajectoryPointAttValues) {
86 static G4bool warnedNoAttValues = false;
87 if (!warnedNoAttValues) {
88 G4cout <<
89 "*************************************************************************"
90 "\n* WARNING: G4TrajectoryDrawerUtils::GetPointsAndTimes: no att values."
91 "\n*************************************************************************"
92 << G4endl;
93 warnedNoAttValues = true;
94 }
95 validity = InvalidTimes;
96 } else {
97 G4bool foundPreTime = false, foundPostTime = false;
98 for (std::vector<G4AttValue>::iterator i =
99 trajectoryPointAttValues->begin();
100 i != trajectoryPointAttValues->end(); ++i) {
101 if (i->GetName() == "PreT") {
102 trajectoryPointPreTime =
104 foundPreTime = true;
105 }
106 if (i->GetName() == "PostT") {
107 trajectoryPointPostTime =
109 foundPostTime = true;
110 }
111 }
112 if (!foundPreTime || !foundPostTime) {
113 static G4bool warnedTimesNotFound = false;
114 if (!warnedTimesNotFound) {
115 G4cout <<
116 "*************************************************************************"
117 "\n* WARNING: G4TrajectoryDrawerUtils::GetPointsAndTimes: times not found."
118 "\n You need to specify \"/vis/scene/add/trajectories rich\""
119 "\n*************************************************************************"
120 << G4endl;
121 warnedTimesNotFound = true;
122 }
123 validity = InvalidTimes;
124 }
125 }
126 delete trajectoryPointAttValues; // (Must be deleted after use.)
127 }
128
129 const std::vector<G4ThreeVector>* auxiliaries
130 = aTrajectoryPoint->GetAuxiliaryPoints();
131 if (0 != auxiliaries) {
132 for (size_t iAux=0; iAux<auxiliaries->size(); ++iAux) {
133 const G4ThreeVector& auxPointPosition = (*auxiliaries)[iAux];
134 if (positions.size() == 0 ||
135 auxPointPosition != positions[positions.size()-1]) {
136 // Only store if first or if different
137 positions.push_back(trajectoryPointPosition);
138 trajectoryLine.push_back(auxPointPosition);
139 auxiliaryPoints.push_back(auxPointPosition);
140 if (validity == ValidTimes) {
141 // Interpolate time for auxiliary points...
142 G4double s1 =
143 (auxPointPosition - lastTrajectoryPointPosition).mag();
144 G4double s2 =
145 (trajectoryPointPosition - auxPointPosition).mag();
146 G4double t = trajectoryPointPreTime +
147 (trajectoryPointPostTime - trajectoryPointPreTime) *
148 (s1 / (s1 + s2));
149 trajectoryLineTimes.push_back(t);
150 auxiliaryPointTimes.push_back(t);
151 }
152 }
153 }
154 }
155
156 positions.push_back(trajectoryPointPosition);
157 trajectoryLine.push_back(trajectoryPointPosition);
158 stepPoints.push_back(trajectoryPointPosition);
159 if (validity == ValidTimes) {
160 trajectoryLineTimes.push_back(trajectoryPointPostTime);
161 stepPointTimes.push_back(trajectoryPointPostTime);
162 }
163 lastTrajectoryPointPosition = trajectoryPointPosition;
164 }
165 }
166 return validity;
167 }
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:570
virtual std::vector< G4AttValue > * CreateAttValues() const
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().