ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Atlas
G4AtlasServices
src
StandardFieldSvc.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
StandardFieldSvc.h
"
6
#include "
StoreGate/ReadCondHandle.h
"
7
8
// Field map
9
#include "
MagFieldElements/AtlasFieldMap.h
"
10
11
// PathResolver
12
#include "
PathResolver/PathResolver.h
"
13
14
// ROOT
15
#include "TFile.h"
16
#include "TTree.h"
17
18
19
//-----------------------------------------------------------------------------
20
// Constructor for the StandardFieldSvc
21
//-----------------------------------------------------------------------------
22
StandardFieldSvc::StandardFieldSvc
(
const
std::string& name,
23
ISvcLocator* pSvcLocator)
24
:
G4MagFieldSvcBase
(name, pSvcLocator)
25
{}
26
27
28
//-----------------------------------------------------------------------------
29
// Initialize the service
30
//-----------------------------------------------------------------------------
31
StatusCode
StandardFieldSvc::initialize
()
32
{
33
ATH_MSG_INFO
(
"Initializing "
<< name() );
34
35
// Either initialize the field map - used for solenoid and toroid, or the field service for the forward field
36
if
(
m_useMagFieldSvc
) {
37
ATH_CHECK
(
m_magFieldSvc
.retrieve() );
38
ATH_MSG_INFO
(
"initialize: using field service "
<<
m_magFieldSvc
.name() );
39
}
40
else
{
41
// Create field map
42
ATH_CHECK
(
createFieldMap
() );
43
ATH_MSG_INFO
(
"initialize: using created map for field cache "
);
44
}
45
46
return
StatusCode::SUCCESS;
47
}
48
49
//-----------------------------------------------------------------------------
50
// Create and retrieve the magnetic field
51
//-----------------------------------------------------------------------------
52
G4MagneticField*
StandardFieldSvc::makeField
()
53
{
54
ATH_MSG_INFO
(
"StandardFieldSvc::makeField"
);
55
56
AtlasField
* af{
nullptr
};
57
58
// Either initialize the field map - used for solenoid and toroid, or the field service for the forward field
59
if
(
m_useMagFieldSvc
) {
60
af =
new
AtlasField
( &*
m_magFieldSvc
);
61
}
62
else
{
63
const
double
scaleSolenoid =
m_mapSoleCurrent
>0 ?
m_useSoleCurrent
/
m_mapSoleCurrent
: 1. ;
64
const
double
scaleToroid =
m_mapToroCurrent
>0 ?
m_useToroCurrent
/
m_mapToroCurrent
: 1. ;
65
af =
new
AtlasField
(scaleSolenoid, scaleToroid,
m_fieldMap
.get());
66
}
67
68
return
(af);
69
}
70
71
72
//-----------------------------------------------------------------------------
73
// Create field map
74
//-----------------------------------------------------------------------------
75
StatusCode
StandardFieldSvc::createFieldMap
()
76
{
77
ATH_MSG_INFO
(
"StandardFieldSvc::createFieldMap"
);
78
79
80
// Select map file according to the value of the currents which indicate which map is 'on'
81
82
// determine the map to load
83
std::string mapFile;
84
if
(
solenoidOn
() &&
toroidOn
() ) mapFile =
m_fullMapFilename
;
85
else
if
(
solenoidOn
() ) mapFile =
m_soleMapFilename
;
86
else
if
(
toroidOn
() ) mapFile =
m_toroMapFilename
;
87
else
{
88
// all magnets OFF. no need to read map
89
return
StatusCode::SUCCESS;
90
}
91
92
ATH_MSG_INFO
(
"StandardFieldSvc::createFieldMap: Set map currents from FieldSvc: solenoid/toroid "
93
<<
m_useSoleCurrent
<<
","
<<
m_useToroCurrent
);
94
ATH_MSG_INFO
(
"StandardFieldSvc::createFieldMap: Use map file "
<< mapFile);
95
96
// find the path to the map file
97
std::string resolvedMapFile =
PathResolver::find_file
( mapFile,
"DATAPATH"
);
98
if
( resolvedMapFile.empty() ) {
99
ATH_MSG_ERROR
(
"StandardFieldSvc::createFieldMap: Field map file "
<< mapFile <<
" not found"
);
100
return
StatusCode::FAILURE;
101
}
102
// Do checks and extract root file to initialize the map
103
if
( resolvedMapFile.find(
".root"
) == std::string::npos ) {
104
ATH_MSG_ERROR
(
"StandardFieldSvc::createFieldMap: input file name '"
<< resolvedMapFile <<
"' does not end with .root"
);
105
return
StatusCode::FAILURE;
106
}
107
108
std::unique_ptr<TFile>
rootfile
= std::make_unique<TFile>(resolvedMapFile.c_str(),
"OLD"
);
109
if
( !
rootfile
.get() ) {
110
ATH_MSG_ERROR
(
"StandardFieldSvc::createFieldMap: failed to open "
<< resolvedMapFile);
111
return
StatusCode::FAILURE;
112
}
113
if
( !
rootfile
->cd() ) {
114
// could not make it current directory
115
ATH_MSG_ERROR
(
"StandardFieldSvc::createFieldMap: unable to cd() into the ROOT field map TFile"
);
116
rootfile
->Close();
117
return
StatusCode::FAILURE;
118
}
119
// open the tree
120
TTree*
tree
= (TTree*)
rootfile
->Get(
"BFieldMap"
);
121
if
(
tree
==
nullptr
) {
122
// no tree
123
ATH_MSG_ERROR
(
"StandardFieldSvc::createFieldMap: TTree 'BFieldMap' does not exist in ROOT field map"
);
124
rootfile
->Close();
125
return
StatusCode::FAILURE;
126
}
127
128
// create map
129
m_fieldMap
= std::make_unique<MagField::AtlasFieldMap>();
130
131
// initialize map
132
if
(!
m_fieldMap
->initializeMap(
rootfile
.get(),
m_useSoleCurrent
,
m_useToroCurrent
) ) {
133
// failed to initialize the map
134
ATH_MSG_ERROR
(
"StandardFieldSvc::createFieldMap: unable to initialize the map for AtlasFieldMap for file "
<< resolvedMapFile);
135
rootfile
->Close();
136
return
StatusCode::FAILURE;
137
}
138
139
rootfile
->Close();
140
141
ATH_MSG_INFO
(
"StandardFieldSvc::createFieldMap: Initialized the field map from "
<< resolvedMapFile );
142
return
StatusCode::SUCCESS;
143
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
AtlasFieldMap.h
PathResolver.h
ReadCondHandle.h
StandardFieldSvc.h
AtlasField
G4 wrapper around the main ATLAS magnetic field cache or field svc for forward field.
Definition
StandardFieldSvc.h:32
G4MagFieldSvcBase::G4MagFieldSvcBase
G4MagFieldSvcBase(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.
Definition
G4MagFieldSvcBase.cxx:22
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Definition
PathResolver.cxx:220
StandardFieldSvc::StandardFieldSvc
StandardFieldSvc(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.
Definition
StandardFieldSvc.cxx:22
StandardFieldSvc::m_useSoleCurrent
Gaudi::Property< double > m_useSoleCurrent
configurable current for map scaling
Definition
StandardFieldSvc.h:123
StandardFieldSvc::toroidOn
bool toroidOn()
Definition
StandardFieldSvc.h:105
StandardFieldSvc::m_mapSoleCurrent
Gaudi::Property< double > m_mapSoleCurrent
nominal current for the maps
Definition
StandardFieldSvc.h:118
StandardFieldSvc::m_fullMapFilename
Gaudi::Property< std::string > m_fullMapFilename
map file names
Definition
StandardFieldSvc.h:108
StandardFieldSvc::m_fieldMap
std::unique_ptr< MagField::AtlasFieldMap > m_fieldMap
Definition
StandardFieldSvc.h:129
StandardFieldSvc::solenoidOn
bool solenoidOn()
Definition
StandardFieldSvc.h:104
StandardFieldSvc::m_useToroCurrent
Gaudi::Property< double > m_useToroCurrent
Definition
StandardFieldSvc.h:125
StandardFieldSvc::initialize
StatusCode initialize() override final
Athena method. called at initialization time, being customized here.
Definition
StandardFieldSvc.cxx:31
StandardFieldSvc::m_magFieldSvc
ServiceHandle< MagField::IMagFieldSvc > m_magFieldSvc
Handle to the the Forward ATLAS magnetic field service.
Definition
StandardFieldSvc.h:99
StandardFieldSvc::m_toroMapFilename
Gaudi::Property< std::string > m_toroMapFilename
Definition
StandardFieldSvc.h:114
StandardFieldSvc::m_soleMapFilename
Gaudi::Property< std::string > m_soleMapFilename
Definition
StandardFieldSvc.h:111
StandardFieldSvc::createFieldMap
StatusCode createFieldMap()
Definition
StandardFieldSvc.cxx:75
StandardFieldSvc::m_mapToroCurrent
Gaudi::Property< double > m_mapToroCurrent
Definition
StandardFieldSvc.h:120
StandardFieldSvc::makeField
G4MagneticField * makeField() override final
Create/retrieve the AtlasField object.
Definition
StandardFieldSvc.cxx:52
StandardFieldSvc::m_useMagFieldSvc
Gaudi::Property< bool > m_useMagFieldSvc
Definition
StandardFieldSvc.h:95
rootfile
static std::vector< std::string > rootfile
Definition
iLumiCalc.h:30
tree
TChain * tree
Definition
tile_monitor.h:30
Generated on
for ATLAS Offline Software by
1.17.0