ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MagneticField
MagFieldUtils
src
SolenoidTest.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
/*
6
* Masahiro Morii, Harvard University
7
*/
8
9
// class include
10
#include "
SolenoidTest.h
"
11
12
// root
13
#include "TFile.h"
14
#include "TRandom3.h"
15
#include "TTree.h"
16
17
//
18
#include <cmath>
19
#include <vector>
20
22
// Public methods:
24
25
// Constructor
27
MagField::SolenoidTest::SolenoidTest
(
const
std::string& name,
28
ISvcLocator* pSvcLocator)
29
:
AthAlgorithm
(name, pSvcLocator),
m_thistSvc
(
"THistSvc/THistSvc"
, name) {}
30
31
// Athena hook:
32
StatusCode
MagField::SolenoidTest::initialize
() {
33
ATH_CHECK
(
m_fieldCacheKey
.initialize());
34
// retrieve the histogram service
35
if
(
m_thistSvc
.retrieve().isFailure()) {
36
ATH_MSG_ERROR
(
"Unable to retrieve HistogramSvc"
);
37
return
StatusCode::FAILURE;
38
}
39
// Create the prefix of histogram names for the THistSvc
40
std::string prefix =
"/"
+
m_histStream
+
"/"
;
41
42
std::string treeName =
m_treeName
.value();
43
// the ROOT tree
44
m_tree
=
new
TTree(treeName.c_str(),
"Magnetic field in the solenoid"
);
45
m_tree
->Branch(
"pos"
, &
m_xyzt
,
"x/D:y/D:z/D"
);
46
m_tree
->Branch(
"fieldFull"
, &
m_field
,
"Bx/D:By/D:Bz/D"
);
47
m_tree
->Branch(
"deriv"
, &
m_deriv
,
48
"dBxdx/D:dBxdy/D:dBxdz/D:dBydx/D:dBydy/D:dBydz/"
49
"D:dBzdx/D:dBzdy/D:dBzdz/D"
);
50
m_tree
->Branch(
"fieldFast"
, &
m_fieldZR
,
"Bx2/D:By2/D:Bz2/D"
);
51
m_tree
->Branch(
"derivZR"
, &
m_derivZR
,
52
"dBxdx2/D:dBxdy2/D:dBxdz2/D:dBydx2/D:dBydy2/D:dBydz2/"
53
"D:dBzdx2/D:dBzdy2/D:dBzdz2/D"
);
54
// register this ROOT TTree to the THistSvc
55
if
(
m_thistSvc
->regTree(prefix + treeName,
m_tree
).isFailure()) {
56
ATH_MSG_ERROR
(
"Unable to register TTree to THistSvc"
);
57
return
StatusCode::FAILURE;
58
}
59
60
return
StatusCode::SUCCESS;
61
}
62
63
StatusCode
MagField::SolenoidTest::execute
(
const
EventContext& ctx) {
64
SG::ReadCondHandle<AtlasFieldCacheCondObj>
rh{
m_fieldCacheKey
,
65
ctx};
66
const
AtlasFieldCacheCondObj
* fieldCondObj{*rh};
67
if
(fieldCondObj ==
nullptr
) {
68
ATH_MSG_ERROR
(
"Failed to retrieve AtlasFieldCacheCondObj with key "
69
<<
m_fieldCacheKey
.key());
70
return
StatusCode::FAILURE;
71
}
72
73
MagField::AtlasFieldCache
fieldCache;
74
fieldCondObj->
getInitializedCache
(fieldCache);
75
76
if
(
m_eventsSeen
==
m_event
) {
77
78
double
deltaZ = (
m_maxZ
-
m_minZ
) / (
m_stepsZ
- 1);
79
double
deltaR
= (
m_maxR
-
m_minR
) /
m_stepsR
- 1;
80
double
deltaPhi
= (2 *
M_PI
) / (
m_stepsPhi
- 1);
81
82
for
(
int
k = 0; k <
m_stepsPhi
; k++) {
// loop over phi
83
double
phi
=
deltaPhi
* k;
84
for
(
int
j = 0; j <
m_stepsZ
; j++) {
// loop over Z
85
m_xyzt
[2] =
m_minZ
+ deltaZ * j;
86
for
(
int
i = 0; i <
m_stepsR
; i++) {
// loop over R
87
double
r
=
m_minR
+
deltaR
* i;
88
m_xyzt
[0] =
r
* cos(
phi
);
89
m_xyzt
[1] =
r
* sin(
phi
);
90
91
fieldCache.
getField
(
m_xyzt
,
m_field
,
m_deriv
);
92
fieldCache.
getFieldZR
(
m_xyzt
,
m_fieldZR
,
nullptr
);
93
ATH_MSG_INFO
(
"Field at r,phi "
<<
r
<<
", "
<<
phi
<<
", "
94
<<
" with xyz: "
<<
m_xyzt
[0] <<
", "
95
<<
m_xyzt
[1] <<
", "
<<
m_xyzt
[2]
96
<<
" with value "
<<
m_field
[0] <<
", "
97
<<
m_field
[1] <<
", "
<<
m_field
[2]);
98
99
m_tree
->Fill();
100
}
101
}
102
}
103
}
104
m_eventsSeen
++;
105
return
StatusCode::SUCCESS;
106
}
107
M_PI
#define M_PI
Definition
ActiveFraction.h:14
deltaPhi
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
Definition
AmgMatrixBasePlugin.h:112
deltaR
Scalar deltaR(const MatrixBase< Derived > &vec) const
Definition
AmgMatrixBasePlugin.h:105
phi
Scalar phi() const
phi method
Definition
AmgMatrixBasePlugin.h:67
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
SolenoidTest.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AtlasFieldCacheCondObj
Definition
AtlasFieldCacheCondObj.h:19
AtlasFieldCacheCondObj::getInitializedCache
void getInitializedCache(MagField::AtlasFieldCache &cache) const
get B field cache for evaluation as a function of 2-d or 3-d position.
Definition
AtlasFieldCacheCondObj.h:32
MagField::AtlasFieldCache
Local cache for magnetic field (based on MagFieldServices/AtlasFieldSvcTLS.h).
Definition
AtlasFieldCache.h:43
MagField::AtlasFieldCache::getField
void getField(const double *ATH_RESTRICT xyz, double *ATH_RESTRICT bxyz, double *ATH_RESTRICT deriv=nullptr)
get B field value at given position xyz[3] is in mm, bxyz[3] is in kT if deriv[9] is given,...
Definition
AtlasFieldCache.cxx:42
MagField::AtlasFieldCache::getFieldZR
void getFieldZR(const double *ATH_RESTRICT xyz, double *ATH_RESTRICT bxyz, double *ATH_RESTRICT deriv=nullptr)
get B field valaue on the z-r plane at given position works only inside the solenoid.
Definition
AtlasFieldCache.cxx:86
MagField::SolenoidTest::initialize
virtual StatusCode initialize() override final
Definition
SolenoidTest.cxx:32
MagField::SolenoidTest::execute
virtual StatusCode execute(const EventContext &ctx) override final
Execute method.
Definition
SolenoidTest.cxx:63
MagField::SolenoidTest::m_minR
Gaudi::Property< double > m_minR
Definition
SolenoidTest.h:61
MagField::SolenoidTest::m_tree
TTree * m_tree
the ROOT tree containing the output
Definition
SolenoidTest.h:53
MagField::SolenoidTest::m_stepsZ
Gaudi::Property< int > m_stepsZ
Definition
SolenoidTest.h:67
MagField::SolenoidTest::m_minZ
Gaudi::Property< double > m_minZ
Definition
SolenoidTest.h:63
MagField::SolenoidTest::SolenoidTest
SolenoidTest(const std::string &name, ISvcLocator *pSvcLocator)
Definition
SolenoidTest.cxx:27
MagField::SolenoidTest::m_eventsSeen
std::atomic< long int > m_eventsSeen
event counter
Definition
SolenoidTest.h:73
MagField::SolenoidTest::m_derivZR
double m_derivZR[9]
stores derivatives
Definition
SolenoidTest.h:51
MagField::SolenoidTest::m_xyzt
double m_xyzt[4]
Variable to write out.
Definition
SolenoidTest.h:47
MagField::SolenoidTest::m_event
Gaudi::Property< int > m_event
Definition
SolenoidTest.h:71
MagField::SolenoidTest::m_maxZ
Gaudi::Property< double > m_maxZ
Definition
SolenoidTest.h:64
MagField::SolenoidTest::m_treeName
Gaudi::Property< std::string > m_treeName
Definition
SolenoidTest.h:58
MagField::SolenoidTest::m_maxR
Gaudi::Property< double > m_maxR
Definition
SolenoidTest.h:62
MagField::SolenoidTest::m_deriv
double m_deriv[9]
stores derivatives
Definition
SolenoidTest.h:50
MagField::SolenoidTest::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Histogram Service.
Definition
SolenoidTest.h:45
MagField::SolenoidTest::m_histStream
Gaudi::Property< std::string > m_histStream
Definition
SolenoidTest.h:55
MagField::SolenoidTest::m_stepsR
Gaudi::Property< int > m_stepsR
Definition
SolenoidTest.h:65
MagField::SolenoidTest::m_stepsPhi
Gaudi::Property< int > m_stepsPhi
Definition
SolenoidTest.h:69
MagField::SolenoidTest::m_field
double m_field[3]
stores the field components
Definition
SolenoidTest.h:48
MagField::SolenoidTest::m_fieldZR
double m_fieldZR[3]
stores the 2d field components
Definition
SolenoidTest.h:49
MagField::SolenoidTest::m_fieldCacheKey
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCacheKey
Definition
SolenoidTest.h:40
SG::ReadCondHandle
Definition
ReadCondHandle.h:40
r
int r
Definition
globals.cxx:22
Generated on
for ATLAS Offline Software by
1.17.0