ATLAS Offline Software
EnergyLossMonitor.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // EnergyLossMonitor.cxx, (c) ATLAS Detector software
8 
9 // InDet include
11 // Gaudi
12 #include "GaudiKernel/ISvcLocator.h"
13 #include "GaudiKernel/SmartDataPtr.h"
14 
15 
16 // constructor
17 Trk::EnergyLossMonitor::EnergyLossMonitor(const std::string& t, const std::string& n, const IInterface* p) :
18  AthAlgTool(t,n,p),
19  m_ntupleSvc("NTupleSvc", n),
20  m_outputNtuplePath("/NTUPLES/FILE1/EnergyLossMonitor/SingleTrackEnergyLoss"),
21  m_outputNtupleDescription("Output of the Trk::EnergyLossMonitor AlgTool"),
22  m_currentStep(0)
23 {
24  declareInterface<IEnergyLossMonitor>(this);
25  declareProperty("NtuplePath", m_outputNtuplePath);
26  declareProperty("NtupleDescription", m_outputNtupleDescription);
27 }
28 
29 // Athena standard methods
30 // initialize
32 {
33  // Retrieve the NTuple Service
34  ATH_CHECK( m_ntupleSvc.retrieve() );
35  NTuplePtr ntr(m_ntupleSvc.get(), m_outputNtuplePath);
36  StatusCode sc;
37  if (!ntr) {
38  ntr = m_ntupleSvc->book(m_outputNtuplePath, CLID_ColumnWiseTuple, m_outputNtupleDescription);
39  }
40  if (ntr){
41  sc = ntr->addItem("Steps", m_steps, 0, 5000);
42  // Initial paramters
43  sc = ntr->addItem("InitialP", m_initialP, 0., 1000000.);
44  sc = ntr->addItem("InitialE", m_initialE, 0., 1000000.);
45  sc = ntr->addItem("InitialEta", m_initialEta, -4., 4.);
46  sc = ntr->addItem("InitialPhi", m_initialPhi, -4., 4.);
47  // kinematics
48  sc = ntr->addItem("Eta", m_steps, m_eta);
49  sc = ntr->addItem("Phi", m_steps, m_phi);
50  // Beam Pipe
51  sc = ntr->addItem("Energy", m_steps, m_E);
52  sc = ntr->addItem("Momentum", m_steps, m_p);
53  sc = ntr->addItem("Eta", m_steps, m_eta);
54  sc = ntr->addItem("Phi", m_steps, m_phi);
55  sc = ntr->addItem("MaterialHitX", m_steps, m_hitX);
56  sc = ntr->addItem("MaterialHitY", m_steps, m_hitY);
57  sc = ntr->addItem("MaterialHitZ", m_steps, m_hitZ);
58  sc = ntr->addItem("MaterialHitR", m_steps, m_hitR);
59 
60  } else {
61  ATH_MSG_ERROR( "Ntuple booking failed!" );
62  return StatusCode::FAILURE;
63  }
64  ATH_MSG_DEBUG("initialize() successful" );
65  return sc;
66 }
67 
68 // finalize
70 {
71  ATH_MSG_DEBUG("finalize() successful");
72  return StatusCode::SUCCESS;
73 }
74 
75 
77  double E,
78  double eta,
79  double phi)
80 {
81  m_initialP = p;
82  m_initialE = E;
83  m_initialEta = eta;
84  m_initialPhi = phi;
85  m_currentStep = 0;
86 }
87 
89  const Amg::Vector3D& mom,
90  double mass)
91 {
92 
93  // Geant4 first step protection
94  if (pos.mag() > 0.01 && m_currentStep < 5000){
95  double p = mom.mag();
96  m_E[m_currentStep] = sqrt(p*p+mass*mass);
97  m_p[m_currentStep] = p;
98  m_eta[m_currentStep] = mom.eta();
99  m_phi[m_currentStep] = mom.phi();
100  m_hitX[m_currentStep] = pos.x();
101  m_hitY[m_currentStep] = pos.y();
102  m_hitZ[m_currentStep] = pos.z();
103  m_hitR[m_currentStep] = pos.perp();
104  m_currentStep++;
105  }
106 }
107 
109 {
110  m_steps = m_currentStep;
111  StatusCode sc = m_ntupleSvc->writeRecord(m_outputNtuplePath);
112  if (sc.isFailure()){
113  ATH_MSG_WARNING( "Couldn't write ntuple record!" );
114  }
115 }
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::EnergyLossMonitor::initializeTrack
virtual void initializeTrack(double p, double E, double eta, double phi)
Initialize State.
Definition: EnergyLossMonitor.cxx:76
Trk::EnergyLossMonitor::recordTrackState
virtual void recordTrackState(const Amg::Vector3D &pos, const Amg::Vector3D &mom, double mass)
Record a single TrackState.
Definition: EnergyLossMonitor.cxx:88
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Trk::EnergyLossMonitor::finalizeTrack
virtual void finalizeTrack()
Finalization State.
Definition: EnergyLossMonitor.cxx:108
Trk::EnergyLossMonitor::finalize
StatusCode finalize()
Definition: EnergyLossMonitor.cxx:69
Trk::EnergyLossMonitor::EnergyLossMonitor
EnergyLossMonitor(const std::string &, const std::string &, const IInterface *)
standard AlgTool constructor / destructor
Definition: EnergyLossMonitor.cxx:17
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Trk::EnergyLossMonitor::initialize
StatusCode initialize()
standard Athena methods
Definition: EnergyLossMonitor.cxx:31
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EnergyLossMonitor.h
Trk::EnergyLossMonitor::m_outputNtupleDescription
std::string m_outputNtupleDescription
Definition: EnergyLossMonitor.h:56
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::phi
@ phi
Definition: ParamDefs.h:75
AthAlgTool
Definition: AthAlgTool.h:26
Trk::EnergyLossMonitor::m_outputNtuplePath
std::string m_outputNtuplePath
Definition: EnergyLossMonitor.h:55