Loading...
Searching...
No Matches
F04ElementField.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27/// \file field/field04/src/F04ElementField.cc
28/// \brief Implementation of the F04ElementField class
29//
30
31#include "F04ElementField.hh"
32#include "F04GlobalField.hh"
33
34#include "G4TouchableHandle.hh"
35#include "G4SystemOfUnits.hh"
36
37//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
38
39G4ThreadLocal G4Navigator* F04ElementField::fNavigator = nullptr;
40
41//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
42
44 : fVolume(lv),
45 fCenter(c)
46{
48
50 fUserLimits->SetMaxAllowedStep(fMaxStep);
51 fUserLimits->SetUserMaxTrackLength(500.*m);
52 fUserLimits->SetUserMaxTime(10*ms);
53 fUserLimits->SetUserMinEkine(0.1*MeV);
54// fUserLimits->SetUserMinRange(1*mm);
55
56 fVolume->SetVisAttributes(GetVisAttribute(fColor));
57 fVolume->SetUserLimits(fUserLimits);
58}
59
60//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61
63{
64 G4Navigator* theNavigator =
65 G4TransportationManager::GetTransportationManager()->
66 GetNavigatorForTracking();
67 if (!fNavigator) {
68 fNavigator = new G4Navigator();
69 if ( theNavigator->GetWorldVolume() )
70 fNavigator->SetWorldVolume(theNavigator->GetWorldVolume());
71 }
72
73 fNavigator->LocateGlobalPointAndSetup(fCenter,nullptr,false);
74
75 G4TouchableHandle touchable = fNavigator->CreateTouchableHistoryHandle();
76
77 G4int depth = touchable->GetHistoryDepth();
78 for (G4int i = 0; i<depth; ++i) {
79 if(touchable->GetVolume()->GetLogicalVolume() == fVolume)break;
80 touchable->MoveUpHistory();
81 }
82
83 // set fGlobal2local transform
84 fGlobal2local = touchable->GetHistory()->GetTopTransform();
85
86 // set global bounding box
87 G4double local[4], global[4];
88
89 G4ThreeVector globalPosition;
90 local[3] = 0.0;
91 for (G4int i=0; i<2; ++i) {
92 local[0] = (i==0 ? -1.0 : 1.0) * GetWidth()/2.;
93 for (G4int j=0; j<2; ++j) {
94 local[1] = (j==0 ? -1.0 : 1.0) * GetHeight()/2.;
95 for (G4int k=0; k<2; ++k) {
96 local[2] = (k==0 ? -1.0 : 1.0) * GetLength()/2.;
97 G4ThreeVector localPosition(local[0],local[1],local[2]);
98 globalPosition =
99 fGlobal2local.Inverse().TransformPoint(localPosition);
100 global[0] = globalPosition.x();
101 global[1] = globalPosition.y();
102 global[2] = globalPosition.z();
103 SetGlobalPoint(global);
104 }
105 }
106 }
107}
108
109//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110
112{
113 G4VisAttributes* p = nullptr;
114 if(color.size() > 0 &&
115 (isdigit(color.c_str()[0]) || color.c_str()[0] == '.')) {
116 G4double red=0.0, green=0.0, blue=0.0;
117 if (sscanf(color.c_str(),"%lf,%lf,%lf",&red,&green,&blue) == 3) {
118 p = new G4VisAttributes(true,G4Color(red,green,blue));
119 } else {
120 G4cout << " Invalid color " << color << G4endl;
121 }
122 }
123
124 if (!p) p = new G4VisAttributes(G4VisAttributes::GetInvisible());
125 p->SetDaughtersInvisible(false);
126
127 return p;
128}
Definition of the F04ElementField class.
Definition of the F04GlobalField class.
F04ElementField(const G4ThreeVector, G4LogicalVolume *)
Constructor.
G4AffineTransform fGlobal2local
virtual G4double GetLength()=0
G4ThreeVector fCenter
static G4VisAttributes * GetVisAttribute(G4String color)
GetVisAttribute() returns the appropriate G4VisAttributes.
static G4ThreadLocal G4Navigator * fNavigator
G4LogicalVolume * fVolume
G4UserLimits * fUserLimits
void Construct()
the actual implementation constructs the F04ElementField
void SetGlobalPoint(const G4double point[4])
SetGlobalPoint() ensures that the point is within the global bounding box of this ElementField's glob...
virtual G4double GetWidth()=0
virtual G4double GetHeight()=0
static F04GlobalField * GetObject()
void AddElementField(F04ElementField *f)
AddElementField() adds the ElementField object for a single element to the global field.

Applications | User Support | Publications | Collaboration