Geant4 11.1.1
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 316 of file G4TrajectoryDrawerUtils.cc.

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

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