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