ATLAS Offline Software
Loading...
Searching...
No Matches
StandardFieldSvc Class Referencefinal

Athena service for constructing the AtlasField object. More...

#include <StandardFieldSvc.h>

Inheritance diagram for StandardFieldSvc:
Collaboration diagram for StandardFieldSvc:

Public Member Functions

 StandardFieldSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Standard constructor.
 ~StandardFieldSvc ()=default
 Empty destructor.
StatusCode initialize () override final
 Athena method. called at initialization time, being customized here.
G4MagneticField * getField () override final
 Retrieve a G4 magnetic field object.

Protected Member Functions

G4MagneticField * makeField () override final
 Create/retrieve the AtlasField object.

Private Member Functions

StatusCode createFieldMap ()
bool solenoidOn ()
bool toroidOn ()

Private Attributes

Gaudi::Property< bool > m_useMagFieldSvc
ServiceHandle< MagField::IMagFieldSvcm_magFieldSvc {this, "MagneticFieldSvc", ""}
 Handle to the the Forward ATLAS magnetic field service.
Gaudi::Property< std::string > m_fullMapFilename
 map file names
Gaudi::Property< std::string > m_soleMapFilename
Gaudi::Property< std::string > m_toroMapFilename
Gaudi::Property< double > m_mapSoleCurrent
 nominal current for the maps
Gaudi::Property< double > m_mapToroCurrent
Gaudi::Property< double > m_useSoleCurrent
 configurable current for map scaling
Gaudi::Property< double > m_useToroCurrent
std::unique_ptr< MagField::AtlasFieldMapm_fieldMap

Detailed Description

Athena service for constructing the AtlasField object.

Definition at line 67 of file StandardFieldSvc.h.

Constructor & Destructor Documentation

◆ StandardFieldSvc()

StandardFieldSvc::StandardFieldSvc ( const std::string & name,
ISvcLocator * pSvcLocator )

Standard constructor.

Definition at line 23 of file StandardFieldSvc.cxx.

25 : G4MagFieldSvcBase(name, pSvcLocator)
26{}
G4MagFieldSvcBase(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.

◆ ~StandardFieldSvc()

StandardFieldSvc::~StandardFieldSvc ( )
default

Empty destructor.

Member Function Documentation

◆ createFieldMap()

StatusCode StandardFieldSvc::createFieldMap ( )
private

Definition at line 76 of file StandardFieldSvc.cxx.

77{
78 ATH_MSG_INFO( "StandardFieldSvc::createFieldMap" );
79
80
81 // Select map file according to the value of the currents which indicate which map is 'on'
82
83 // determine the map to load
84 std::string mapFile;
85 if ( solenoidOn() && toroidOn() ) mapFile = m_fullMapFilename;
86 else if ( solenoidOn() ) mapFile = m_soleMapFilename;
87 else if ( toroidOn() ) mapFile = m_toroMapFilename;
88 else {
89 // all magnets OFF. no need to read map
90 return StatusCode::SUCCESS;
91 }
92
93 ATH_MSG_INFO ( "StandardFieldSvc::createFieldMap: Set map currents from FieldSvc: solenoid/toroid "
95 ATH_MSG_INFO ( "StandardFieldSvc::createFieldMap: Use map file " << mapFile);
96
97 // find the path to the map file
98 std::string resolvedMapFile = PathResolver::find_file( mapFile, "DATAPATH" );
99 if ( resolvedMapFile.empty() ) {
100 ATH_MSG_ERROR( "StandardFieldSvc::createFieldMap: Field map file " << mapFile << " not found" );
101 return StatusCode::FAILURE;
102 }
103 // Do checks and extract root file to initialize the map
104 if ( resolvedMapFile.find(".root") == std::string::npos ) {
105 ATH_MSG_ERROR("StandardFieldSvc::createFieldMap: input file name '" << resolvedMapFile << "' does not end with .root");
106 return StatusCode::FAILURE;
107 }
108
109 std::unique_ptr<TFile> rootfile = std::make_unique<TFile>(resolvedMapFile.c_str(), "OLD");
110 if ( ! rootfile.get() ) {
111 ATH_MSG_ERROR("StandardFieldSvc::createFieldMap: failed to open " << resolvedMapFile);
112 return StatusCode::FAILURE;
113 }
114 if ( !rootfile->cd() ) {
115 // could not make it current directory
116 ATH_MSG_ERROR("StandardFieldSvc::createFieldMap: unable to cd() into the ROOT field map TFile");
117 rootfile->Close();
118 return StatusCode::FAILURE;
119 }
120 // open the tree
121 TTree* tree = (TTree*)rootfile->Get("BFieldMap");
122 if ( tree == nullptr ) {
123 // no tree
124 ATH_MSG_ERROR("StandardFieldSvc::createFieldMap: TTree 'BFieldMap' does not exist in ROOT field map");
125 rootfile->Close();
126 return StatusCode::FAILURE;
127 }
128
129 // create map
130 m_fieldMap = std::make_unique<MagField::AtlasFieldMap>();
131
132 // initialize map
133 if (!m_fieldMap->initializeMap( rootfile.get(), m_useSoleCurrent , m_useToroCurrent) ) {
134 // failed to initialize the map
135 ATH_MSG_ERROR("StandardFieldSvc::createFieldMap: unable to initialize the map for AtlasFieldMap for file " << resolvedMapFile);
136 rootfile->Close();
137 return StatusCode::FAILURE;
138 }
139
140 rootfile->Close();
141
142 ATH_MSG_INFO( "StandardFieldSvc::createFieldMap: Initialized the field map from " << resolvedMapFile );
143 return StatusCode::SUCCESS;
144}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Gaudi::Property< double > m_useSoleCurrent
configurable current for map scaling
Gaudi::Property< std::string > m_fullMapFilename
map file names
std::unique_ptr< MagField::AtlasFieldMap > m_fieldMap
Gaudi::Property< double > m_useToroCurrent
Gaudi::Property< std::string > m_toroMapFilename
Gaudi::Property< std::string > m_soleMapFilename
static std::vector< std::string > rootfile
Definition iLumiCalc.h:30
TChain * tree

◆ getField()

G4MagneticField * G4MagFieldSvcBase::getField ( )
finaloverrideinherited

Retrieve a G4 magnetic field object.

If one doesn't yet exist in the current thread, it will be created.

Definition at line 31 of file G4MagFieldSvcBase.cxx.

32{
33 ATH_MSG_DEBUG("G4MagFieldSvcBase::getField");
34
35 // create a thread-local magnetic field instance
36 static thread_local std::unique_ptr<G4MagneticField> field{makeField()};
37
38 return field.get();
39}
#define ATH_MSG_DEBUG(x)
virtual G4MagneticField * makeField()=0
This method must be overridden by concrete tools to create a new field.

◆ initialize()

StatusCode StandardFieldSvc::initialize ( )
finaloverride

Athena method. called at initialization time, being customized here.

Definition at line 32 of file StandardFieldSvc.cxx.

33{
34 ATH_MSG_INFO( "Initializing " << name() );
35
36 // Either initialize the field map - used for solenoid and toroid, or the field service for the forward field
37 if (m_useMagFieldSvc) {
38 ATH_CHECK( m_magFieldSvc.retrieve() );
39 ATH_MSG_INFO( "initialize: using field service " << m_magFieldSvc.name() );
40 }
41 else {
42 // Create field map
44 ATH_MSG_INFO( "initialize: using created map for field cache ");
45 }
46
47 return StatusCode::SUCCESS;
48}
#define ATH_CHECK
Evaluate an expression and check for errors.
ServiceHandle< MagField::IMagFieldSvc > m_magFieldSvc
Handle to the the Forward ATLAS magnetic field service.
StatusCode createFieldMap()
Gaudi::Property< bool > m_useMagFieldSvc

◆ makeField()

G4MagneticField * StandardFieldSvc::makeField ( )
finaloverrideprotectedvirtual

Create/retrieve the AtlasField object.

Implements G4MagFieldSvcBase.

Definition at line 53 of file StandardFieldSvc.cxx.

54{
55 ATH_MSG_INFO( "StandardFieldSvc::makeField" );
56
57 AtlasField* af{nullptr};
58
59 // Either initialize the field map - used for solenoid and toroid, or the field service for the forward field
60 if (m_useMagFieldSvc) {
61 af = new AtlasField( &*m_magFieldSvc );
62 }
63 else {
64 const double scaleSolenoid = m_mapSoleCurrent>0 ? m_useSoleCurrent / m_mapSoleCurrent : 1. ;
65 const double scaleToroid = m_mapToroCurrent>0 ? m_useToroCurrent / m_mapToroCurrent : 1. ;
66 af = new AtlasField(scaleSolenoid, scaleToroid, m_fieldMap.get());
67 }
68
69 return (af);
70}
Gaudi::Property< double > m_mapSoleCurrent
nominal current for the maps
Gaudi::Property< double > m_mapToroCurrent

◆ solenoidOn()

bool StandardFieldSvc::solenoidOn ( )
inlineprivate

Definition at line 104 of file StandardFieldSvc.h.

104{ return (m_mapSoleCurrent > 0.0); }

◆ toroidOn()

bool StandardFieldSvc::toroidOn ( )
inlineprivate

Definition at line 105 of file StandardFieldSvc.h.

105{ return (m_mapToroCurrent > 0.0); }

Member Data Documentation

◆ m_fieldMap

std::unique_ptr<MagField::AtlasFieldMap> StandardFieldSvc::m_fieldMap
private

Definition at line 129 of file StandardFieldSvc.h.

◆ m_fullMapFilename

Gaudi::Property<std::string> StandardFieldSvc::m_fullMapFilename
private
Initial value:
{this,
"FullMapFile", "MagneticFieldMaps/bfieldmap_7730_20400_14m.root",
"File storing the full magnetic field map"}

map file names

Definition at line 108 of file StandardFieldSvc.h.

108 {this,
109 "FullMapFile", "MagneticFieldMaps/bfieldmap_7730_20400_14m.root",
110 "File storing the full magnetic field map"};

◆ m_magFieldSvc

ServiceHandle<MagField::IMagFieldSvc> StandardFieldSvc::m_magFieldSvc {this, "MagneticFieldSvc", ""}
private

Handle to the the Forward ATLAS magnetic field service.

Definition at line 99 of file StandardFieldSvc.h.

99{this, "MagneticFieldSvc", ""};

◆ m_mapSoleCurrent

Gaudi::Property<double> StandardFieldSvc::m_mapSoleCurrent
private
Initial value:
{this,
"MapSoleCurrent", 7730., "Nominal solenoid current (A)"}

nominal current for the maps

Definition at line 118 of file StandardFieldSvc.h.

118 {this,
119 "MapSoleCurrent", 7730., "Nominal solenoid current (A)"};

◆ m_mapToroCurrent

Gaudi::Property<double> StandardFieldSvc::m_mapToroCurrent
private
Initial value:
{this,
"MapToroCurrent", 20400., "Nominal toroid current (A)"}

Definition at line 120 of file StandardFieldSvc.h.

120 {this,
121 "MapToroCurrent", 20400., "Nominal toroid current (A)"};

◆ m_soleMapFilename

Gaudi::Property<std::string> StandardFieldSvc::m_soleMapFilename
private
Initial value:
{this,
"SoleMapFile", "MagneticFieldMaps/bfieldmap_7730_0_14m.root",
"File storing the solenoid-only magnetic field map"}

Definition at line 111 of file StandardFieldSvc.h.

111 {this,
112 "SoleMapFile", "MagneticFieldMaps/bfieldmap_7730_0_14m.root",
113 "File storing the solenoid-only magnetic field map"};

◆ m_toroMapFilename

Gaudi::Property<std::string> StandardFieldSvc::m_toroMapFilename
private
Initial value:
{this,
"ToroMapFile", "MagneticFieldMaps/bfieldmap_0_20400_14m.root",
"File storing the toroid-only magnetic field map"}

Definition at line 114 of file StandardFieldSvc.h.

114 {this,
115 "ToroMapFile", "MagneticFieldMaps/bfieldmap_0_20400_14m.root",
116 "File storing the toroid-only magnetic field map"};

◆ m_useMagFieldSvc

Gaudi::Property<bool> StandardFieldSvc::m_useMagFieldSvc
private
Initial value:
{this,
"UseMagFieldSvc", false, "Use magnetic field service - Should ONLY be used for ForwardRegionFieldSvc"}

Definition at line 95 of file StandardFieldSvc.h.

95 {this,
96 "UseMagFieldSvc", false, "Use magnetic field service - Should ONLY be used for ForwardRegionFieldSvc"};

◆ m_useSoleCurrent

Gaudi::Property<double> StandardFieldSvc::m_useSoleCurrent
private
Initial value:
{this,
"UseSoleCurrent", 7730., "Configured solenoid current (A)"}

configurable current for map scaling

Definition at line 123 of file StandardFieldSvc.h.

123 {this,
124 "UseSoleCurrent", 7730., "Configured solenoid current (A)"};

◆ m_useToroCurrent

Gaudi::Property<double> StandardFieldSvc::m_useToroCurrent
private
Initial value:
{this,
"UseToroCurrent", 20400., "Configured toroid current (A)"}

Definition at line 125 of file StandardFieldSvc.h.

125 {this,
126 "UseToroCurrent", 20400., "Configured toroid current (A)"};

The documentation for this class was generated from the following files: