ATLAS Offline Software
Loading...
Searching...
No Matches
JetParticleOriginVertexAssociation.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5// author: cpollard@cern.ch
6
9
10using namespace std;
11using namespace xAOD;
12
15
16 declareProperty("coneSizeFitPar1", m_coneSizeFitPar1=0);
17 declareProperty("coneSizeFitPar2", m_coneSizeFitPar2=0);
18 declareProperty("coneSizeFitPar3", m_coneSizeFitPar3=0);
19 declareProperty("dzCut", m_dzCut=10);
20 declareProperty("useMinZ0Vertex", m_useMinZ0Vertex=false);
21 return;
22 }
23
24
25const std::vector<std::vector<ElementLink<xAOD::IParticleContainer> > >*
27
28 //Get the vertex associated to each track by reading the decoration
29 const SG::AuxElement::ConstAccessor<std::vector<ElementLink<xAOD::VertexContainer>>> trkOrigin("btagIp_ByVertex_TrkOriginVtx");
30 const SG::AuxElement::ConstAccessor<std::vector<float>> z0SinTheta("btagIp_ByVertex_z0SinTheta");
31 //Create the 2d output vector
32 std::vector<std::vector<ElementLink<xAOD::IParticleContainer> > >* matchedparts =
33 new vector<std::vector<ElementLink<xAOD::IParticleContainer> > >(jets.size());
34
35 //loop through the tracks
36 for (const IParticle* part: parts) {
37
38 // Retrieve the vector of vertex ElementLinks associated with the track and the corresponding z0 vector
39 const std::vector<ElementLink<xAOD::VertexContainer>>& vertexLink_vec = trkOrigin(*part);
40 const std::vector<float>& z0SinTheta_vec = z0SinTheta(*part);
41 // check if the vectors are not empty
42 if(z0SinTheta_vec.empty()) continue;
43 // index of vertex with min(z0)
44 unsigned int selectedVertexIndex = -1;
45 if (m_useMinZ0Vertex) {
46 // Find the vertex with the minimum absolute value of z0SinTheta
47 auto minAbsIt = std::min_element(z0SinTheta_vec.begin(), z0SinTheta_vec.end(),
48 [](float a, float b) {
49 return std::abs(a) < std::abs(b);
50 });
51 // find index of the vertex with mindZ
52 if (minAbsIt != z0SinTheta_vec.end()) {
53 selectedVertexIndex = std::distance(z0SinTheta_vec.begin(), minAbsIt);
54 }
55 }
56 // loop through vertices
57 for (unsigned int iVtx=0; iVtx < z0SinTheta_vec.size(); iVtx++){
58 // if we want to do exclusive, only use the vertex with the min(z0)
59 if (m_useMinZ0Vertex && selectedVertexIndex!=iVtx) continue;
60 // retrieve vertex link
61 const ElementLink<xAOD::VertexContainer>& vertexLink = vertexLink_vec.at(iVtx);
62 // check if link is valid
63 if (!vertexLink.isValid()) {
64 ATH_MSG_WARNING("Track decoration 'btagIp_TrkOriginVertex' is missing for this track");
65 continue;
66 }
67 // if the dz(track, vertex) doesnt pass the cut then continue to next vertex
68 if (z0SinTheta_vec.at(iVtx) > m_dzCut) continue;
69
70 // Continue processing
71 //Get vertex associated with the track
72 const Vertex* vtx_to_trk = *vertexLink;
73 int matchjetidx = -1;
74 double drmin = -1.0;
75 // Loop through jets
76 for (unsigned int iJet = 0; iJet < jets.size(); iJet++) {
77 //get jet
78 const Jet* jet = jets[iJet];
79 // if origin of jet is not the same as the vertex associated to the track then continue to next jet
80 if (jet->getAssociatedObject<xAOD::Vertex>("OriginVertex") != vtx_to_trk) continue;
81
82 // do dR matching between jet and track
83 double match_dr = coneSize(jet->pt());
84 double dr = jet->p4().DeltaR(part->p4());
85 if (dr > match_dr) continue;
86 if (drmin < 0 || dr < drmin) {
87 drmin = dr;
88 matchjetidx = iJet;
89 }
90 }
91 if (matchjetidx >= 0) {
93 EL.toContainedElement(parts, part);
94 (*matchedparts)[matchjetidx].push_back(EL);
95 }
96 }
97
98 }
99
100 return matchedparts;
101
102}
#define ATH_MSG_WARNING(x)
static Double_t a
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
JetParticleAssociation(const std::string &name)
virtual const std::vector< std::vector< ElementLink< xAOD::IParticleContainer > > > * match(const xAOD::JetContainer &, const xAOD::IParticleContainer &) const override
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
Class providing the definition of the 4-vector interface.
This module defines the arguments passed from the BATCH driver to the BATCH worker.
STL namespace.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Vertex_v1 Vertex
Define the latest version of the vertex class.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.