Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
28  ISvcLocator* pSvcLocator)
29  : AthAlgorithm(name, pSvcLocator), m_thistSvc("THistSvc/THistSvc", name) {}
30 
31 // Athena hook:
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 
65  Gaudi::Hive::currentContext()};
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 
beamspotman.r
def r
Definition: beamspotman.py:676
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AtlasFieldCacheCondObj
Definition: AtlasFieldCacheCondObj.h:19
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
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
M_PI
#define M_PI
Definition: ActiveFraction.h:11
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
MagField::SolenoidTest::SolenoidTest
SolenoidTest(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SolenoidTest.cxx:27
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SolenoidTest.h
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
MagField::SolenoidTest::execute
virtual StatusCode execute() override final
Definition: SolenoidTest.cxx:63
dumpFileToPlots.treeName
string treeName
Definition: dumpFileToPlots.py:20
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MagField::SolenoidTest::initialize
virtual StatusCode initialize() override final
Definition: SolenoidTest.cxx:32
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
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
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
makeComparison.deltaZ
int deltaZ
Definition: makeComparison.py:46
makeComparison.deltaR
float deltaR
Definition: makeComparison.py:36
fitman.k
k
Definition: fitman.py:528