ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
G4GlobalMagFieldMessenger.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file G4GlobalMagFieldMessenger.cc
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
// class G4GlobalMagFieldMessenger
27
//
28
// Implementation of the G4GlobalMagFieldMessenger class
29
//
30
// Author: Ivana Hrivnacova, 28/08/2013 (ivana@ipno.in2p3.fr)
31
// --------------------------------------------------------------------
32
33
#include "
G4GlobalMagFieldMessenger.hh
"
34
#include "
G4UniformMagField.hh
"
35
#include "
G4FieldManager.hh
"
36
#include "
G4TransportationManager.hh
"
37
#include "
G4UIdirectory.hh
"
38
#include "
G4UIcmdWith3VectorAndUnit.hh
"
39
#include "
G4UIcmdWithAnInteger.hh
"
40
#include "
G4UnitsTable.hh
"
41
#include "
G4SystemOfUnits.hh
"
42
43
//______________________________________________________________________________
44
45
G4GlobalMagFieldMessenger::G4GlobalMagFieldMessenger
(
const
G4ThreeVector
&
value
)
46
:
G4UImessenger
()
47
{
48
fDirectory
=
new
G4UIdirectory
(
"/globalField/"
);
49
fDirectory
->
SetGuidance
(
"Global uniform magnetic field UI commands"
);
50
51
fSetValueCmd
=
new
G4UIcmdWith3VectorAndUnit
(
"/globalField/setValue"
,
this
);
52
fSetValueCmd
->
SetGuidance
(
"Set uniform magnetic field value."
);
53
fSetValueCmd
->
SetParameterName
(
"Bx"
,
"By"
,
"By"
,
false
);
54
fSetValueCmd
->
SetUnitCategory
(
"Magnetic flux density"
);
55
fSetValueCmd
->
AvailableForStates
(
G4State_PreInit
,
G4State_Idle
);
56
57
fSetVerboseCmd
=
new
G4UIcmdWithAnInteger
(
"/globalField/verbose"
,
this
);
58
fSetVerboseCmd
->
SetGuidance
(
"Set verbose level: "
);
59
fSetVerboseCmd
->
SetGuidance
(
" 0: no output"
);
60
fSetVerboseCmd
->
SetGuidance
(
" 1: printing new field value"
);
61
fSetVerboseCmd
->
SetParameterName
(
"globalFieldVerbose"
,
false
);
62
fSetVerboseCmd
->
SetRange
(
"globalFieldVerbose>=0"
);
63
fSetVerboseCmd
->
AvailableForStates
(
G4State_PreInit
,
G4State_Idle
);
64
65
// Create field
66
fMagField
=
new
G4UniformMagField
(value);
67
68
// Set field value (the field is not activated if value is zero)
69
SetField
(value,
"G4GlobalMagFieldMessenger::G4GlobalMagFieldMessenger"
);
70
}
71
72
//______________________________________________________________________________
73
74
G4GlobalMagFieldMessenger::~G4GlobalMagFieldMessenger
()
75
{
76
delete
fMagField
;
77
delete
fSetValueCmd
;
78
delete
fSetVerboseCmd
;
79
delete
fDirectory
;
80
}
81
82
//______________________________________________________________________________
83
84
void
G4GlobalMagFieldMessenger::SetField
(
const
G4ThreeVector
&
value
,
85
const
G4String
&
/*inFunction*/
)
86
{
87
// Get field manager (or create it if it does not yet exist)
88
G4FieldManager
* fieldManager
89
=
G4TransportationManager::GetTransportationManager
()->
GetFieldManager
();
90
91
// Inactivate field if its value is zero
92
if
( value ==
G4ThreeVector
() )
93
{
94
fieldManager->
SetDetectorField
(0);
95
fieldManager->
CreateChordFinder
(0);
96
97
if
(
fVerboseLevel
> 0 )
98
{
99
G4cout
<<
"Magnetic field is inactive, fieldValue = (0,0,0)."
<<
G4endl
;
100
}
101
}
102
else
103
{
104
fMagField
->
SetFieldValue
(value);
105
fieldManager->
SetDetectorField
(
fMagField
);
106
fieldManager->
CreateChordFinder
(
fMagField
);
107
108
if
(
fVerboseLevel
> 0 )
109
{
110
G4cout
<<
"Magnetic field is active, fieldValue = ("
111
<<
G4BestUnit
(value,
"Magnetic flux density"
)
112
<<
")."
<<
G4endl
;
113
}
114
}
115
}
116
117
//______________________________________________________________________________
118
119
void
G4GlobalMagFieldMessenger::SetNewValue
(
G4UIcommand
* command,
G4String
newValue)
120
{
121
if
( command ==
fSetValueCmd
)
122
{
123
SetField
(
fSetValueCmd
->
GetNew3VectorValue
(newValue),
124
"G4GlobalMagFieldMessenger::SetNewValue"
);
125
}
126
else
if
( command ==
fSetVerboseCmd
)
127
{
128
SetVerboseLevel
(
fSetVerboseCmd
->
GetNewIntValue
(newValue));
129
}
130
}
131
132
//______________________________________________________________________________
133
134
void
G4GlobalMagFieldMessenger::SetFieldValue
(
const
G4ThreeVector
&
value
)
135
{
136
SetField
(value,
"G4GlobalMagFieldMessenger::SetFieldValue"
);
137
}
138
139
//______________________________________________________________________________
140
141
G4ThreeVector
G4GlobalMagFieldMessenger::GetFieldValue
()
const
142
{
143
if
(
fMagField
)
return
fMagField
->
GetConstantFieldValue
();
144
145
return
G4ThreeVector
();
146
}
geant4
tree
geant4-10.6-release
source
geometry
navigation
src
G4GlobalMagFieldMessenger.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:17
using
1.8.2 with
ECCE GitHub integration