ATLAS Offline Software
GlobalFieldManagerTool.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 // Local package include
10 
11 // Geant4 includes
12 #include "G4ChordFinder.hh"
13 #include "G4FieldManager.hh"
14 #include "G4MagIntegratorStepper.hh"
15 #include "G4MagneticField.hh"
16 #include "G4PropagatorInField.hh"
17 #include "G4TransportationManager.hh"
18 #include "G4Version.hh"
19 #include "G4VIntegrationDriver.hh"
20 
21 //-----------------------------------------------------------------------------
22 // Tool constructor
23 //-----------------------------------------------------------------------------
25  const std::string& name,
26  const IInterface* parent)
28 {
29 }
30 
31 //-----------------------------------------------------------------------------
32 // Initialize a field manager
33 //-----------------------------------------------------------------------------
35 {
36  ATH_MSG_DEBUG("initializeField");
37 
38  if (m_fieldOn) {
39 
40  // Retrieve the G4MagneticField
41  G4MagneticField* field = m_fieldSvc->getField();
42 
43  // Retrieve the global field manager
44  auto transpManager = G4TransportationManager::GetTransportationManager();
45  G4FieldManager* fieldMgr(nullptr);
47  // In the case of tight stepping we need to make our own global field manager
48  // If field manager already exists for current thread, error.
49  // There is no foreseen use-case for this situation.
50  if(m_fieldMgrHolder.get()) {
51  ATH_MSG_ERROR("GlobalFieldManagerTool::initializeField() - " <<
52  "Field manager already exists!");
53  return StatusCode::FAILURE;
54  }
55  // Create a new field manager
56  fieldMgr = new TightMuonSteppingFieldManager();
57 
58  // Save it in the TL holder
59  m_fieldMgrHolder.set(fieldMgr);
60 
61  // Assign it to the global field manager
62  transpManager->SetFieldManager(fieldMgr);
63  } else {
64  // Otherwise get the default from the transportation manager
65  fieldMgr = transpManager->GetFieldManager();
66  }
67 
68  // Configure the field manager
69  fieldMgr->SetDetectorField(field);
70  ATH_CHECK( setFieldParameters(fieldMgr) );
71 
72  // Create and configure the ChordFinder
73  fieldMgr->CreateChordFinder(field);
74 
75 #if G4VERSION_NUMBER < 1040
76  ATH_MSG_DEBUG("Old style stepper setting");
77  G4MagIntegratorStepper* stepper = getStepper(m_integratorStepper, field);
78  G4MagInt_Driver* magDriver = fieldMgr->GetChordFinder()->GetIntegrationDriver();
79  magDriver->RenewStepperAndAdjust(stepper);
80 #else
81  ATH_MSG_DEBUG("New style stepper setting");
82  G4VIntegrationDriver* driver = createDriverAndStepper(m_integratorStepper, field);
83  G4ChordFinder* chordFinder = fieldMgr->GetChordFinder();
84  chordFinder->SetIntegrationDriver(driver);
85 #endif
86 
87  // Configure the propagator
88  G4PropagatorInField* propagator = transpManager->GetPropagatorInField();
89  if (m_maxStep>0) propagator->SetLargestAcceptableStep(m_maxStep);
90 
91  }
92 
93  return StatusCode::SUCCESS;
94 }
G4FieldManagerToolBase::setFieldParameters
StatusCode setFieldParameters(G4FieldManager *fieldMgr) const
Common method to apply configuredfield parameters.
Definition: G4FieldManagerToolBase.cxx:239
G4FieldManagerToolBase::m_integratorStepper
Gaudi::Property< std::string > m_integratorStepper
The type of stepper to use.
Definition: G4FieldManagerToolBase.h:71
TightMuonSteppingFieldManager.h
G4FieldManagerToolBase::m_maxStep
Gaudi::Property< double > m_maxStep
Definition: G4FieldManagerToolBase.h:84
G4FieldManagerToolBase
Definition: G4FieldManagerToolBase.h:34
G4FieldManagerToolBase::m_fieldOn
Gaudi::Property< bool > m_fieldOn
Definition: G4FieldManagerToolBase.h:68
G4FieldManagerToolBase::m_fieldSvc
ServiceHandle< IG4FieldSvc > m_fieldSvc
Handle to the G4 field service.
Definition: G4FieldManagerToolBase.h:65
GlobalFieldManagerTool::GlobalFieldManagerTool
GlobalFieldManagerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: GlobalFieldManagerTool.cxx:24
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
FullCPAlgorithmsTest_eljob.driver
driver
Definition: FullCPAlgorithmsTest_eljob.py:171
thread_utils::ThreadLocalHolder::set
void set(T *obj)
Assign the object of the current thread.
Definition: ThreadLocalHolder.h:67
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
thread_utils::ThreadLocalHolder::get
T * get()
Get the object of the current thread.
Definition: ThreadLocalHolder.h:60
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
GlobalFieldManagerTool::m_useTightMuonStepping
Gaudi::Property< bool > m_useTightMuonStepping
Tight muon stepping parameters via the field manager's configure for track.
Definition: GlobalFieldManagerTool.h:38
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
GlobalFieldManagerTool::m_fieldMgrHolder
thread_utils::ThreadLocalOwner< G4FieldManager > m_fieldMgrHolder
My field manager – populated only in the case that we use tight muon stepping.
Definition: GlobalFieldManagerTool.h:42
GlobalFieldManagerTool.h
GlobalFieldManagerTool::initializeField
StatusCode initializeField() override final
Initialize a field manager.
Definition: GlobalFieldManagerTool.cxx:34
TightMuonSteppingFieldManager
G4FieldManager that sets tight stepping for muons; caches global values for other particles.
Definition: TightMuonSteppingFieldManager.h:24
G4FieldManagerToolBase::getStepper
G4MagIntegratorStepper * getStepper(const std::string &stepperType, G4MagneticField *field) const
Common method to construct a stepper of requested type.
Definition: G4FieldManagerToolBase.cxx:190