ATLAS Offline Software
Loading...
Searching...
No Matches
MuonSpectrometer/MuonValidation/MuonVertexValidation/util/Utils.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "Utils.h"
6#include <numeric>
7
8
10
11
12// Detector region: Separation into barrel and endcaps
13bool inBarrel(double eta){
14 return std::abs(eta) <= fidVol_barrel_etaCut;
15}
16
17
18bool inBarrel(const Amg::Vector3D &vtx){
19 return inBarrel(vtx.eta());
20}
21
22
23bool inEndcaps(double eta){
24 return (std::abs(eta) > fidVol_endcaps_etaCut_low && std::abs(eta) < fidVol_endcaps_etaCut_up);
25}
26
27
28bool inEndcaps(const Amg::Vector3D &vtx){
29 return inEndcaps(vtx.eta());
30}
31
32
34 return inBarrel(vtx) || inEndcaps(vtx);
35}
36
37
38int getNvtxBarrel(const std::vector<Amg::Vector3D> &vertices){
39 // find the number of vertices in the barrel region
40 return std::accumulate(vertices.begin(), vertices.end(), 0, [](unsigned int N, const Amg::Vector3D& vtx){return N+inBarrel(vtx);});
41}
42
43
44int getNvtxEndcaps(const std::vector<Amg::Vector3D> &vertices){
45 // find the number of vertices in the endcap region
46 return std::accumulate(vertices.begin(), vertices.end(), 0, [](unsigned int N, const Amg::Vector3D& vtx){return N+inEndcaps(vtx);});
47}
48
49
50int getNvtxDetectorRegion(const std::vector<Amg::Vector3D> &vertices){
51 // find the number of vertices in the either the barrel or endcaps
52 return getNvtxBarrel(vertices) + getNvtxEndcaps(vertices);
53}
54// --- //
55
56
57// Muon spectrometer displaced vertex search fiducial region //
59 bool eta = inBarrel(vtx);
60 bool Lxy = vtx.perp() > fidVol_Lxy_low && vtx.perp() < fidVol_Lxy_up;
61 return eta && Lxy;
62}
63
64
66 bool eta = inEndcaps(vtx);
67 bool Lxy = vtx.perp() < fidVol_endcaps_Lxy_up;
68 bool z = std::abs(vtx.z()) > fidVol_z_low && std::abs(vtx.z()) < fidVol_z_up;
69 return eta && Lxy && z;
70}
71
72
74 return inFiducialVolBarrel(vtx) || inFiducialVolEndcaps(vtx);
75}
76
77
78int NvtxFiducialVol(const std::vector<Amg::Vector3D> &vertices){
79 // find the number ofvertices in the fiducial volume
80 unsigned int N = 0;
81 for (const Amg::Vector3D &vtx : vertices) if (inFiducialVol(vtx)) ++N;
82 return N;
83}
84
85
86bool isGoodVtx(const Amg::Vector3D &vtx){
87 // add further conditions for a vertex to be considered in efficiency calculations here
88 bool is_good = true;
89 if (!inFiducialVol(vtx)) is_good = false;
90 return is_good;
91}
92// --- //
93
94
95// matching of vertices
96double getMatchMetric(const Amg::Vector3D &vtx1, const Amg::Vector3D &vtx2){
97 // Computes the metric on which matches are made between two vertices
98 return xAOD::P4Helpers::deltaR(vtx1.eta(), vtx1.phi(), vtx2.eta(), vtx2.phi());
99}
100
101
102Amg::Vector3D findBestMatch(const Amg::Vector3D &vtx, const std::vector<Amg::Vector3D> &candidates){
103 // finds the best match for vtx among candidates
104 // The match metric is assumed to decreases for better matches. If no match could be found, a zero vector is returned
105 Amg::Vector3D best{Amg::Vector3D::Zero()}; // initialised with zeros
106 double aux(0), min(999);
107
108 for (unsigned int i=0; i<candidates.size(); ++i){
109 aux = getMatchMetric(vtx, candidates[i]);
110 if (aux > match_max) continue;
111 if (aux < min){
112 min = aux;
113 best = candidates[i];
114 }
115 }
116
117 return best;
118}
119
120
121bool isValidMatch(const Amg::Vector3D &match_candidate){
122 return match_candidate.mag() > 0.001;
123}
124
125
126bool hasMatch(const Amg::Vector3D &vtx1, const std::vector<Amg::Vector3D> &vtx2_vec){
127 // Checks if vtx1 has a match in vtx2_vec
128 Amg::Vector3D candidate = findBestMatch(vtx1, vtx2_vec);
129 return isValidMatch(candidate);
130}
131
132
133std::vector<Amg::Vector3D> getVertexPos(const std::vector<double> &vtx_x, const std::vector<double> &vtx_y, const std::vector<double> &vtx_z){
134 std::vector<Amg::Vector3D> vertices;
135 for (unsigned int i=0; i<vtx_x.size(); ++i){
136 Amg::Vector3D vtx_pos(vtx_x[i], vtx_y[i], vtx_z[i]);
137 vertices.push_back(vtx_pos);
138 }
139
140 return vertices;
141}
142
143
144std::vector<std::vector<Amg::Vector3D>> getConstituentPos(int Nvtx, const std::vector<int> &obj_vtx_link,
145 const std::vector<double> &obj_x, const std::vector<double> &obj_y, const std::vector<double> &obj_z){
146 // returns the constituent position vectors for each reconstructed vertex
147 std::vector<std::vector<Amg::Vector3D>> consti_vec;
148 for (int j=0; j<Nvtx; ++j){
149 std::vector<Amg::Vector3D> consti;
150 for (unsigned int k=0; k<obj_x.size(); ++k){
151 if (obj_vtx_link[k] == j){consti.push_back(Amg::Vector3D(obj_x[k], obj_y[k], obj_z[k]));}
152 }
153 consti_vec.push_back(consti);
154 }
155
156 return consti_vec;
157}
158
159} // namespace MuonVertexValidationMacroUtils
Scalar eta() const
pseudorapidity method
#define z
#define min(a, b)
Definition cfImp.cxx:40
Eigen::Matrix< double, 3, 1 > Vector3D
int getNvtxDetectorRegion(const std::vector< Amg::Vector3D > &vertices)
double getMatchMetric(const Amg::Vector3D &vtx1, const Amg::Vector3D &vtx2)
bool hasMatch(const Amg::Vector3D &vtx1, const std::vector< Amg::Vector3D > &vtx2_vec)
std::vector< Amg::Vector3D > getVertexPos(const std::vector< double > &vtx_x, const std::vector< double > &vtx_y, const std::vector< double > &vtx_z)
Amg::Vector3D findBestMatch(const Amg::Vector3D &vtx, const std::vector< Amg::Vector3D > &candidates)
std::vector< std::vector< Amg::Vector3D > > getConstituentPos(int Nvtx, const std::vector< int > &obj_vtx_link, const std::vector< double > &obj_x, const std::vector< double > &obj_y, const std::vector< double > &obj_z)
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi