ATLAS Offline Software
Loading...
Searching...
No Matches
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
7
8// From this package
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//-----------------------------------------------------------------------------
26 const std::string& name,
27 const IInterface* parent)
28 : G4FieldManagerToolBase(type, name, parent)
29{
30}
31
32//-----------------------------------------------------------------------------
33// Initialize a field manager
34//-----------------------------------------------------------------------------
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Property< std::vector< std::string > > m_physVolumeList
Gaudi::Property< std::vector< std::string > > m_logVolumeList
List of volumes to assign this field configuration to.
DetectorFieldManagerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
StatusCode initializeField() override final
Initialize a field manager.
Gaudi::Property< bool > m_muonOnlyField
Option for muons feeling the B-field only.
StatusCode setFieldParameters(G4FieldManager *fieldMgr) const
Common method to apply configuredfield parameters.
G4MagIntegratorStepper * getStepper(const std::string &stepperType, G4MagneticField *field) const
Common method to construct a stepper of requested type.
ServiceHandle< IG4FieldSvc > m_fieldSvc
Handle to the G4 field service.
Gaudi::Property< bool > m_fieldOn
G4FieldManagerToolBase(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Gaudi::Property< std::string > m_integratorStepper
The type of stepper to use.
G4FieldManager that sets tight stepping for muons; disables magnetic field for other particles.