ATLAS Offline Software
Loading...
Searching...
No Matches
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
36namespace 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 //=============================================================================
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 //
72 typename SG::AuxElement::Accessor<T2> acc(var_name);
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 //
88 typename SG::AuxElement::Accessor<T2> acc(var_name);
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
102 {
103 public:
104
105 explicit TimerScopeHelper(TStopwatch &timer)
106 :m_fTimer(timer) { m_fTimer.Start(false); }
108
109 private:
110
111 TStopwatch &m_fTimer;
112 };
113
114
115 //======================================================================================================
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
139
140 unsigned m_var;
141 bool m_inv;
142 MsgStream &m_msg;
143
144 };
145}
146
147#endif //PROMPT_PROMPTUTILS_H
Base class for elements of a container that can have aux data.
TimerScopeHelper(TStopwatch &timer)
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Eigen::Matrix< double, 3, 1 > Vector3D
bool GetAuxVar(const T1 &obj, T2 &value, const std::string &var_name)
Definition PromptUtils.h:83
std::string PrintResetStopWatch(TStopwatch &watch)
void fillTH1(TH1 *h, double val, double weight=1.0)
std::string trkAsStr(const xAOD::TrackParticle *trk)
std::string printPromptVertexAsStr(const xAOD::Vertex *vtx, MsgStream &msg)
double getVertexFitProb(const xAOD::Vertex *vtx)
std::string truthAsStr(const xAOD::IParticle &particle)
bool getVar(T1 &obj, T2 &value, const std::string &var_name)
Definition PromptUtils.h:62
std::string vtxAsStr(const xAOD::Vertex *vtx, bool print_tracks=false)
double getNormDist(const Amg::Vector3D &PrimVtx, const Amg::Vector3D &SecVtx, const std::vector< float > &ErrorMatrix, MsgStream &msg)
double getDistance(const xAOD::Vertex *vtx1, const xAOD::Vertex *vtx2)
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
bool operator()(const xAOD::TrackParticle *lhs, const xAOD::TrackParticle *rhs)
Definition PromptUtils.h:58
bool operator()(const T &lhs, const T &rhs)
SortObjectByVar(const unsigned v, MsgStream &m, bool inverse=false)
MsgStream & msg
Definition testRead.cxx:32