ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Atlas
G4AtlasTools
src
DetectorFieldManagerTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// Main header
6
#include "
G4AtlasTools/DetectorFieldManagerTool.h
"
7
8
// From this package
9
#include "
TightMuonElseNoFieldManager.h
"
10
#include "
SwitchingFieldManager.h
"
11
12
// Geant4 includes
13
#include "G4ChordFinder.hh"
14
#include "G4FieldManager.hh"
15
#include "G4LogicalVolumeStore.hh"
16
#include "G4PhysicalVolumeStore.hh"
17
#include "G4MagIntegratorStepper.hh"
18
#include "G4MagneticField.hh"
19
#include "G4Version.hh"
20
#include "G4VIntegrationDriver.hh"
21
22
//-----------------------------------------------------------------------------
23
// Tool constructor
24
//-----------------------------------------------------------------------------
25
DetectorFieldManagerTool::DetectorFieldManagerTool
(
const
std::string&
type
,
26
const
std::string& name,
27
const
IInterface* parent)
28
:
G4FieldManagerToolBase
(
type
, name, parent)
29
{
30
}
31
32
//-----------------------------------------------------------------------------
33
// Initialize a field manager
34
//-----------------------------------------------------------------------------
35
StatusCode
DetectorFieldManagerTool::initializeField
()
36
{
37
ATH_MSG_DEBUG
(
"initializeField"
);
38
39
if
(
m_fieldOn
) {
40
41
// If field manager already exists for current thread, error.
42
// There is no foreseen use-case for this situation.
43
44
// Retrieve the G4MagneticField
45
G4MagneticField* field =
m_fieldSvc
->getField();
46
47
// Create a new field manager
48
G4FieldManager* field_manager =
m_muonOnlyField
?
new
SwitchingFieldManager
(field) :
new
G4FieldManager();
49
50
// Configure the field manager
51
field_manager->SetDetectorField(field);
52
field_manager->CreateChordFinder(field);
53
ATH_CHECK
(
setFieldParameters
(field_manager) );
54
55
// Create and configure the ChordFinder
56
field_manager->CreateChordFinder(field);
57
58
#if G4VERSION_NUMBER < 1040
59
ATH_MSG_DEBUG
(
"Old style stepper setting"
);
60
G4MagIntegratorStepper* stepper =
getStepper
(
m_integratorStepper
, field);
61
G4MagInt_Driver* magDriver = field_manager->GetChordFinder()->GetIntegrationDriver();
62
magDriver->RenewStepperAndAdjust(stepper);
63
#else
64
ATH_MSG_DEBUG
(
"New style stepper setting"
);
65
G4VIntegrationDriver* driver = createDriverAndStepper(
m_integratorStepper
, field);
66
G4ChordFinder* chordFinder = field_manager->GetChordFinder();
67
chordFinder->SetIntegrationDriver(driver);
68
#endif
69
70
// Assign the field manager to volumes
71
if
(!
m_logVolumeList
.empty()) {
72
auto
logVolStore = G4LogicalVolumeStore::GetInstance();
73
for
(
const
auto
& volume:
m_logVolumeList
) {
74
G4LogicalVolume* logicalVolume = logVolStore->GetVolume(volume);
75
if
(logicalVolume !=
nullptr
) logicalVolume->SetFieldManager(field_manager,
true
);
76
else
77
ATH_MSG_WARNING
(
"No volume called "
<< volume <<
" was found in the G4LogicalVolumeStore! Skipping this volume."
);
78
}
79
}
80
else
if
(!
m_physVolumeList
.empty()) {
81
auto
physVolStore = G4PhysicalVolumeStore::GetInstance();
82
for
(
const
auto
& volume:
m_physVolumeList
) {
83
G4VPhysicalVolume* physicalVolume = physVolStore->GetVolume(volume);
84
if
(physicalVolume !=
nullptr
) physicalVolume->GetLogicalVolume()->SetFieldManager(field_manager,
true
);
85
else
86
ATH_MSG_WARNING
(
"No volume called "
<< volume <<
" was found in the G4PhysicalVolumeStore! Skipping this volume."
);
87
}
88
}
89
else
90
ATH_MSG_WARNING
(
"No volumes are provided. Field manager is NOT assigned."
);
91
}
92
93
return
StatusCode::SUCCESS;
94
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
DetectorFieldManagerTool.h
SwitchingFieldManager.h
TightMuonElseNoFieldManager.h
DetectorFieldManagerTool::m_physVolumeList
Gaudi::Property< std::vector< std::string > > m_physVolumeList
Definition
DetectorFieldManagerTool.h:37
DetectorFieldManagerTool::m_logVolumeList
Gaudi::Property< std::vector< std::string > > m_logVolumeList
List of volumes to assign this field configuration to.
Definition
DetectorFieldManagerTool.h:36
DetectorFieldManagerTool::DetectorFieldManagerTool
DetectorFieldManagerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition
DetectorFieldManagerTool.cxx:25
DetectorFieldManagerTool::initializeField
StatusCode initializeField() override final
Initialize a field manager.
Definition
DetectorFieldManagerTool.cxx:35
DetectorFieldManagerTool::m_muonOnlyField
Gaudi::Property< bool > m_muonOnlyField
Option for muons feeling the B-field only.
Definition
DetectorFieldManagerTool.h:40
G4FieldManagerToolBase::setFieldParameters
StatusCode setFieldParameters(G4FieldManager *fieldMgr) const
Common method to apply configuredfield parameters.
Definition
G4FieldManagerToolBase.cxx:239
G4FieldManagerToolBase::getStepper
G4MagIntegratorStepper * getStepper(const std::string &stepperType, G4MagneticField *field) const
Common method to construct a stepper of requested type.
Definition
G4FieldManagerToolBase.cxx:190
G4FieldManagerToolBase::m_fieldSvc
ServiceHandle< IG4FieldSvc > m_fieldSvc
Handle to the G4 field service.
Definition
G4FieldManagerToolBase.h:65
G4FieldManagerToolBase::m_fieldOn
Gaudi::Property< bool > m_fieldOn
Definition
G4FieldManagerToolBase.h:68
G4FieldManagerToolBase::G4FieldManagerToolBase
G4FieldManagerToolBase(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition
G4FieldManagerToolBase.cxx:52
G4FieldManagerToolBase::m_integratorStepper
Gaudi::Property< std::string > m_integratorStepper
The type of stepper to use.
Definition
G4FieldManagerToolBase.h:71
SwitchingFieldManager
G4FieldManager that sets tight stepping for muons; disables magnetic field for other particles.
Definition
SwitchingFieldManager.h:20
type
Generated on
for ATLAS Offline Software by
1.17.0