ATLAS Offline Software
PromptUtils.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef PROMPT_PROMPTUTILS_H
6 #define PROMPT_PROMPTUTILS_H
7 
8 /**********************************************************************************
9  * @Package: LeptonTaggers
10  * @Class : PromptUtils
11  * @Author : Rustem Ospanov
12  * @Author : Rhys Roberts
13  *
14  * @Brief :
15  *
16  * Helper functions
17  *
18  **********************************************************************************/
19 
20 // Local
21 #include "VarHolder.h"
22 
23 // Athena
25 #include "GaudiKernel/MsgStream.h"
27 #include "xAODTracking/Vertex.h"
28 
29 // ROOT
30 #include "TStopwatch.h"
31 #include "TH1.h"
32 
33 // C/C++
34 #include <string>
35 
36 namespace Prompt
37 {
38  //=============================================================================
39  double getVertexFitProb(const xAOD::Vertex *vtx);
40 
41  std::string vtxAsStr(const xAOD::Vertex *vtx, bool print_tracks=false);
42  std::string trkAsStr(const xAOD::TrackParticle *trk);
43 
44  std::string truthAsStr(const xAOD::IParticle &particle);
45 
46  double getDistance(const xAOD::Vertex *vtx1, const xAOD::Vertex *vtx2);
47  double getDistance(const Amg::Vector3D &vtx1, const Amg::Vector3D &vtx2);
48 
49  double getNormDist(const Amg::Vector3D &PrimVtx, const Amg::Vector3D &SecVtx, const std::vector<float> &ErrorMatrix, MsgStream &msg);
50 
51  void fillTH1(TH1 *h, double val, double weight = 1.0);
52 
53  std::string printPromptVertexAsStr(const xAOD::Vertex *vtx, MsgStream &msg);
54 
55  //=============================================================================
56  struct SortByIDTrackPt
57  {
58  bool operator()(const xAOD::TrackParticle *lhs, const xAOD::TrackParticle *rhs) { return lhs->pt() > rhs->pt(); }
59  };
60 
61  //=============================================================================
62  template<class T1, class T2> bool getVar(T1 &obj, T2 &value, const std::string &var_name)
63  {
64  if (!obj) {
65  std::cerr << "getVar - received a null object" << std::endl;
66  return false;
67  }
68 
69  //
70  // get the int aux-variable
71  //
73 
74  if(!acc.isAvailable(*obj)) {
75  return false;
76  }
77 
78  value = acc(*obj);
79  return true;
80  }
81 
82  //=============================================================================
83  template<class T1, class T2> bool GetAuxVar(const T1 &obj, T2 &value, const std::string &var_name)
84  {
85  //
86  // get the int aux-variable
87  //
89 
90  if(!acc.isAvailable(obj)) {
91  return false;
92  }
93 
94  value = acc(obj);
95  return true;
96  }
97 
98  //=============================================================================
99  std::string PrintResetStopWatch(TStopwatch &watch);
100 
101  class TimerScopeHelper
102  {
103  public:
104 
105  explicit TimerScopeHelper(TStopwatch &timer)
106  :m_fTimer(timer) { m_fTimer.Start(false); }
107  ~TimerScopeHelper() { m_fTimer.Stop(); }
108 
109  private:
110 
111  TStopwatch &m_fTimer;
112  };
113 
114 
115  //======================================================================================================
116  struct SortObjectByVar
117  {
118  explicit SortObjectByVar(const unsigned v, MsgStream &m, bool inverse=false):m_var(v), m_inv(inverse), m_msg(m) {}
119 
120  template<class T> bool operator()(const T &lhs, const T &rhs)
121  {
122  double val_rhs = 0.0;
123  double val_lhs = 0.0;
124 
125  if(!lhs.getVar(m_var, val_lhs) || !rhs.getVar(m_var, val_rhs)) {
126  m_msg << MSG::WARNING << "SortObjectByVar - missing var" << std::endl;
127  }
128 
129  if(m_inv) {
130  return val_lhs > val_rhs;
131  }
132 
133  return val_lhs < val_rhs;
134  }
135 
136  private:
137 
138  SortObjectByVar();
139 
140  unsigned m_var;
141  bool m_inv;
142  MsgStream &m_msg;
143 
144  };
145 }
146 
147 #endif //PROMPT_PROMPTUTILS_H
Prompt::TimerScopeHelper::TimerScopeHelper
TimerScopeHelper(TStopwatch &timer)
Definition: PromptUtils.h:115
xAOD::TrackParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TrackParticle_v1.cxx:73
Prompt
Definition: DecoratePLIT.h:28
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
Prompt::GetAuxVar
bool GetAuxVar(const T1 &obj, T2 &value, const std::string &var_name)
Definition: PromptUtils.h:93
Prompt::getVertexFitProb
double getVertexFitProb(const xAOD::Vertex *vtx)
Definition: PromptUtils.cxx:21
Prompt::TimerScopeHelper::~TimerScopeHelper
~TimerScopeHelper()
Definition: PromptUtils.h:117
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
CheckAppliedSFs.var_name
var_name
Definition: CheckAppliedSFs.py:241
Prompt::getVar
bool getVar(T1 &obj, T2 &value, const std::string &var_name)
Definition: PromptUtils.h:72
Prompt::trkAsStr
std::string trkAsStr(const xAOD::TrackParticle *trk)
Definition: PromptUtils.cxx:228
athena.value
value
Definition: athena.py:124
Prompt::vtxAsStr
std::string vtxAsStr(const xAOD::Vertex *vtx, bool print_tracks=false)
Definition: PromptUtils.cxx:172
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
Prompt::PrintResetStopWatch
std::string PrintResetStopWatch(TStopwatch &watch)
Definition: PromptUtils.cxx:244
Prompt::SortObjectByVar::SortObjectByVar
SortObjectByVar()
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
Prompt::SortObjectByVar::operator()
bool operator()(const T &lhs, const T &rhs)
Definition: PromptUtils.h:130
Prompt::getNormDist
double getNormDist(const Amg::Vector3D &PrimVtx, const Amg::Vector3D &SecVtx, const std::vector< float > &ErrorMatrix, MsgStream &msg)
Definition: PromptUtils.cxx:57
Prompt::SortObjectByVar::m_inv
bool m_inv
Definition: PromptUtils.h:151
Prompt::getDistance
double getDistance(const xAOD::Vertex *vtx1, const xAOD::Vertex *vtx2)
Definition: PromptUtils.cxx:41
xAOD::VxType::SecVtx
@ SecVtx
Secondary vertex.
Definition: TrackingPrimitives.h:572
MuonR4::inverse
CalibratedSpacePoint::Covariance_t inverse(const CalibratedSpacePoint::Covariance_t &mat)
Inverts the parsed matrix.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/UtilFunctions.cxx:65
Prompt::printPromptVertexAsStr
std::string printPromptVertexAsStr(const xAOD::Vertex *vtx, MsgStream &msg)
Definition: PromptUtils.cxx:127
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
Vertex.h
Prompt::SortObjectByVar::m_var
unsigned m_var
Definition: PromptUtils.h:150
Prompt::truthAsStr
std::string truthAsStr(const xAOD::IParticle &particle)
Definition: PromptUtils.cxx:213
Prompt::SortObjectByVar
Definition: PromptUtils.h:127
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
VarHolder.h
TrackParticle.h
python.PyAthena.v
v
Definition: PyAthena.py:154
h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
Prompt::fillTH1
void fillTH1(TH1 *h, double val, double weight=1.0)
Definition: PromptUtils.cxx:104
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
Prompt::TimerScopeHelper::m_fTimer
TStopwatch & m_fTimer
Definition: PromptUtils.h:121
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
Prompt::SortObjectByVar::m_msg
MsgStream & m_msg
Definition: PromptUtils.h:152
python.PyAthena.obj
obj
Definition: PyAthena.py:132
Prompt::SortByIDTrackPt::operator()
bool operator()(const xAOD::TrackParticle *lhs, const xAOD::TrackParticle *rhs)
Definition: PromptUtils.h:68
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
AuxElement.h
Base class for elements of a container that can have aux data.