110 {
111
112
115 assert(tMgr);
117 assert(navigator);
118
120 const G4Field* globalField = 0;
121 const G4String intro =
"G4VFieldModel::DescribeYourselfTo: ";
122 if (globalFieldMgr) {
125 if (!globalField) {
126 static G4bool warned =
false;
127 if (!warned) {
128 G4warn << intro <<
"Null global field pointer." <<
G4endl;
129 warned = true;
130 }
131 }
132 }
133 } else {
134 static G4bool warned =
false;
135 if (!warned) {
136 G4warn << intro <<
"No global field manager." <<
G4endl;
137 warned = true;
138 }
139 }
140
144 } else {
145 extent = fExtentForField;
146 }
153 const G4double xHalfScene = 0.5 * (xMax - xMin);
154 const G4double yHalfScene = 0.5 * (yMax - yMin);
155 const G4double zHalfScene = 0.5 * (zMax - zMin);
156 const G4double xSceneCentre = 0.5 * (xMax + xMin);
157 const G4double ySceneCentre = 0.5 * (yMax + yMin);
158 const G4double zSceneCentre = 0.5 * (zMax + zMin);
160 std::max(xHalfScene,std::max(yHalfScene,zHalfScene));
161 if (maxHalfScene <= 0.) {
163 return;
164 }
165
166
167 const G4double interval = maxHalfScene / fNDataPointsPerMaxHalfExtent;
168 const G4int nDataPointsPerXHalfScene =
G4int(xHalfScene / interval);
169 const G4int nDataPointsPerYHalfScene =
G4int(yHalfScene / interval);
170 const G4int nDataPointsPerZHalfScene =
G4int(zHalfScene / interval);
171 const G4int nXSamples = 2 * nDataPointsPerXHalfScene + 1;
172 const G4int nYSamples = 2 * nDataPointsPerYHalfScene + 1;
173 const G4int nZSamples = 2 * nDataPointsPerZHalfScene + 1;
174 const G4int nSamples = nXSamples * nYSamples * nZSamples;
175 const G4double arrowLengthMax = 0.8 * interval;
176
177
178 std::vector<G4Point3D> Field(nSamples);
179 std::vector<G4Point3D> xyz(nSamples);
180 G4double FieldMagnitudeMax = -std::numeric_limits<G4double>::max();
181
182
183 for (
G4int i = 0; i < nXSamples; i++) {
184 G4double x = xSceneCentre + (i - nDataPointsPerXHalfScene) * interval;
185
186 for (
G4int j = 0; j < nYSamples; j++) {
187 G4double y = ySceneCentre + (j - nDataPointsPerYHalfScene) * interval;
188
189 for (
G4int k = 0; k < nZSamples; k++) {
190 G4double z = zSceneCentre + (k - nDataPointsPerZHalfScene) * interval;
191
192
193 const G4int ijk = i * nYSamples * nZSamples + j * nZSamples + k;
194 xyz[ijk].set(x,y,z);
195
197
198
199 if (!fPVFindings.empty()) {
201 for (const auto& findings: fPVFindings) {
203 G4int copyNo = findings.fFoundPVCopyNo;
206 if (pvParam) {
208 solid = param->ComputeSolid(copyNo,pvParam);
210 }
211
212 const auto& transform = findings.fFoundObjectTransformation;
213 auto rotation = transform.getRotation();
214 auto translation = transform.getTranslation();
217 isInPV = true;
218 break;
219 }
220 }
221 if (!isInPV) continue;
222 }
223
224
225
228 const G4Field* field = globalField;
229 if (pPV) {
230
232 if (pLV) {
233
235 if (pRegion) {
237 if (pRegionFieldMgr) {
239
240 }
241 }
242
244 if (pLVFieldMgr) {
246
247 }
248 }
249 }
250
252
253
255
257 if (mag > FieldMagnitudeMax) FieldMagnitudeMax = mag;
258 }
259 }
260 }
261
262 if (FieldMagnitudeMax <= 0.) {
263 G4warn <<
"No " << fTypeOfField <<
" field in this extent." <<
G4endl;
264 return;
265 }
266
267 for (
G4int i = 0; i < nSamples; i++) {
268 const G4double Fmag = Field[i].mag();
269 const G4double f = Fmag / FieldMagnitudeMax;
270 if (f <= 0.) continue;
271
273 if (f < 0.5) {
274 green = 2. * f;
275 red = 2. * (0.5 - f);
276 } else {
277 blue = 2. * (f - 0.5);
278 green = 2. * (1.0 - f);
279 }
280 const G4Colour arrowColour(red,green,blue,alpha);
281
282
283 G4bool drawAsLine =
false;
284 switch (fRepresentation) {
286 if (f < 0.1) {
287 drawAsLine = true;
288 }
289 break;
291 drawAsLine = true;
292 break;
293 default:
294 break;
295 }
296
297
298 G4double arrowLength = arrowLengthMax * f;
299
300 if (f < 0.01) arrowLength = arrowLengthMax * 0.01;
301 const G4Point3D head = xyz[i] + arrowLength*Field[i]/Fmag;
302
303 if (drawAsLine) {
306 va.SetLineWidth(2.);
308 FArrowLite.push_back(xyz[i]);
309 FArrowLite.push_back(head);
313 } else {
315 head.
x(), head.
y(), head.
z(),
316 arrowLength/5, arrowColour,
317 fArrowPrefix+"Field",
318 fArrow3DLineSegmentsPerCircle);
319 FArrow.DescribeYourselfTo(sceneHandler);
320 }
321 }
322}
Hep3Vector & transform(const HepRotation &)
const G4Field * GetDetectorField() const
G4bool DoesFieldExist() const
G4VSolid * GetSolid() const
G4Region * GetRegion() const
G4FieldManager * GetFieldManager() const
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=nullptr, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
G4VPVParameterisation * GetParameterisation() const override
G4FieldManager * GetFieldManager() const
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
G4FieldManager * GetFieldManager() const
virtual void GetFieldAtLocation(const G4Field *field, const G4Point3D &position, G4double time, G4Point3D &result) const =0
virtual void BeginPrimitives(const G4Transform3D &objectTransformation=G4Transform3D())=0
virtual void AddPrimitive(const G4Polyline &)=0
virtual const G4VisExtent & GetExtent() const
virtual void EndPrimitives()=0
G4LogicalVolume * GetLogicalVolume() const
virtual EInside Inside(const G4ThreeVector &p) const =0
virtual void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
void SetVisAttributes(const G4VisAttributes *)