ATLAS Offline Software
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
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. More...
 
 ~StandardFieldSvc ()=default
 Empty destructor. More...
 
StatusCode initialize () override final
 Athena method. called at initialization time, being customized here. More...
 
G4MagneticField * getField () override final
 Retrieve a G4 magnetic field object. More...
 

Protected Member Functions

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

Protected Attributes

thread_utils::ThreadLocalOwner< G4MagneticField > m_fieldHolder
 Thread-local field object. More...
 

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. More...
 
Gaudi::Property< std::string > m_fullMapFilename
 map file names More...
 
Gaudi::Property< std::string > m_soleMapFilename
 
Gaudi::Property< std::string > m_toroMapFilename
 
Gaudi::Property< double > m_mapSoleCurrent
 nominal current for the maps More...
 
Gaudi::Property< double > m_mapToroCurrent
 
Gaudi::Property< double > m_useSoleCurrent
 configurable current for map scaling More...
 
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 {}

◆ ~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 "
94  << m_useSoleCurrent << "," << m_useToroCurrent );
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 }

◆ 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 29 of file G4MagFieldSvcBase.cxx.

30 {
31  ATH_MSG_DEBUG("G4MagFieldSvcBase::getField");
32 
33  // Check if we already have a field setup for current thread
34  auto field = m_fieldHolder.get();
35  // If not, we create one
36  if(!field) {
37  field = makeField();
39  }
40 
41  return field;
42 }

◆ 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 }

◆ 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 }

◆ 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_fieldHolder

thread_utils::ThreadLocalOwner<G4MagneticField> G4MagFieldSvcBase::m_fieldHolder
protectedinherited

Thread-local field object.

Definition at line 48 of file G4MagFieldSvcBase.h.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.


The documentation for this class was generated from the following files:
G4MagFieldSvcBase::makeField
virtual G4MagneticField * makeField()=0
This method must be overridden by concrete tools to create a new field.
StandardFieldSvc::toroidOn
bool toroidOn()
Definition: StandardFieldSvc.h:105
StandardFieldSvc::m_toroMapFilename
Gaudi::Property< std::string > m_toroMapFilename
Definition: StandardFieldSvc.h:114
StandardFieldSvc::m_magFieldSvc
ServiceHandle< MagField::IMagFieldSvc > m_magFieldSvc
Handle to the the Forward ATLAS magnetic field service.
Definition: StandardFieldSvc.h:99
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
StandardFieldSvc::m_useMagFieldSvc
Gaudi::Property< bool > m_useMagFieldSvc
Definition: StandardFieldSvc.h:95
tree
TChain * tree
Definition: tile_monitor.h:30
StandardFieldSvc::m_mapSoleCurrent
Gaudi::Property< double > m_mapSoleCurrent
nominal current for the maps
Definition: StandardFieldSvc.h:118
StandardFieldSvc::m_fieldMap
std::unique_ptr< MagField::AtlasFieldMap > m_fieldMap
Definition: StandardFieldSvc.h:129
StandardFieldSvc::m_mapToroCurrent
Gaudi::Property< double > m_mapToroCurrent
Definition: StandardFieldSvc.h:120
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
LArCalib_HVScale2NtupleConfig.rootfile
string rootfile
Definition: LArCalib_HVScale2NtupleConfig.py:74
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
AtlasField
G4 wrapper around the main ATLAS magnetic field cache or field svc for forward field.
Definition: StandardFieldSvc.h:32
StandardFieldSvc::m_useToroCurrent
Gaudi::Property< double > m_useToroCurrent
Definition: StandardFieldSvc.h:125
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
StandardFieldSvc::m_fullMapFilename
Gaudi::Property< std::string > m_fullMapFilename
map file names
Definition: StandardFieldSvc.h:108
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
StandardFieldSvc::solenoidOn
bool solenoidOn()
Definition: StandardFieldSvc.h:104
StandardFieldSvc::createFieldMap
StatusCode createFieldMap()
Definition: StandardFieldSvc.cxx:76
G4MagFieldSvcBase::G4MagFieldSvcBase
G4MagFieldSvcBase(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.
Definition: G4MagFieldSvcBase.cxx:20
StandardFieldSvc::m_soleMapFilename
Gaudi::Property< std::string > m_soleMapFilename
Definition: StandardFieldSvc.h:111
G4MagFieldSvcBase::m_fieldHolder
thread_utils::ThreadLocalOwner< G4MagneticField > m_fieldHolder
Thread-local field object.
Definition: G4MagFieldSvcBase.h:48
StandardFieldSvc::m_useSoleCurrent
Gaudi::Property< double > m_useSoleCurrent
configurable current for map scaling
Definition: StandardFieldSvc.h:123