ATLAS Offline Software
Loading...
Searching...
No Matches
InDetVertexTruthMatchUtils.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
7
9
10namespace {
11
12bool isHardScatterEvent( const ElementLink<xAOD::TruthEventBaseContainer>& evlink ) {
13 //good link of type "TruthEvent" (not truthpileupevent) and the first one in the collection
14 return ( evlink.isValid() && (*evlink)->type() == xAOD::Type::TruthEvent && evlink.index() == 0 );
15}
16
17}
18
19//find vertex with largest amount of hard-scatter tracks
21 //accessors for decorations
22 xAOD::Vertex::ConstAccessor<int> nHSTrkDecor("nHSTrk");
23
24 std::vector<std::pair<const xAOD::Vertex*, size_t> > allMatches = hardScatterMatches( vxContainer );
25
26 int bestNHSTrk = 0;
27 const xAOD::Vertex * best = nullptr;
28 for ( auto it : allMatches ) {
29 int nHSTrk = nHSTrkDecor( *(it.first) );
30 if( nHSTrk > bestNHSTrk ){
31 bestNHSTrk = nHSTrk;
32 best = it.first;
33 }
34 }
35
36 //if didn't find any matches will return 0
37 return best;
38}
39
40//Find all hard scatter matches
41const std::vector<std::pair<const xAOD::Vertex*, size_t> > hardScatterMatches( const xAOD::VertexContainer & vxContainer ) {
42 //accessors for decorations
43 xAOD::Vertex::ConstAccessor<std::vector<VertexTruthMatchInfo> > matchInfoDecor("TruthEventMatchingInfos");
44
45 //return vector
46 std::vector<std::pair<const xAOD::Vertex*, size_t> > result;
47
48 //loop and look
49 for ( auto vxit : vxContainer ) {
50 try{
51 const std::vector<VertexTruthMatchInfo> & info = matchInfoDecor( *vxit );
52 if (!matchInfoDecor.isAvailable(*vxit)){
53 return result;
54 }
55 for ( size_t i = 0; i < info.size(); ++i ) {
56 if ( isHardScatterEvent( std::get<0>(info[i]) ) ) {
57 result.emplace_back(vxit, i );
58 break;
59 }
60 }
61 }
62 catch (SG::ExcBadAuxVar &){
63 return result;
64 }
65
66 }
67 return result;
68}
69
71
72 // return a vector of reco vertices with contributions from the hard-scatter
73 // if the second element in the pair is zero, it means tracks from the hard-scatter
74 // contribute more weight to that reco vertex than any other interaction
75 std::vector<std::pair<const xAOD::Vertex*, size_t> > matches = hardScatterMatches( vxContainer );
76
77 // information indicating whether a given reco vertex is:
78 // MATCHED, MERGED, SPLIT or FAKE
79 xAOD::Vertex::Decorator<VertexMatchType> matchTypeDecor("VertexMatchType");
80
81 if ( matches.empty() ) {
82 // No reco vertices with tracks from hard-scatter
83 return NONE;
84 } else if ( matches.size() == 1 ) {
85 // A single reco vertex has tracks from hard-scatter
86 const VertexMatchType & type = matchTypeDecor( *(matches[0].first) );
87 //check if the index in the matching info for HS is first, then can assign clean/lowpu based on match/merge
88 if ( matches[0].second == 0 && type == MATCHED ) {
89 // HS made largest contribution and vertex matched
90 return CLEAN;
91 } else if ( matches[0].second == 0 && type == MERGED ) {
92 // HS made largest contribution and vertex merged
93 return LOWPU;
94 } else {
95 // HS did not make largest contribution or vertex is fake or vertex is part of non-HS split pair
96 return HIGHPU;
97 }
98
99 } else {
100 // multiple reco vertices have tracks from hard-scatter
101 // count how many have hard-scatter tracks as largest contribution
102 int num_main = 0;
103 const xAOD::Vertex* mainVtx = nullptr;
104 for ( auto it : matches ) {
105 if ( it.second == 0 ) // is hard-scatter the largest contribution?
106 {
107 num_main++;
108 mainVtx = it.first;
109 }
110 }
111 if (num_main == 0 ) {
112 return HIGHPU;
113 } else if (num_main == 1 ) {
114 const VertexMatchType& type = matchTypeDecor(*mainVtx);
115 if (type == MATCHED)
116 return CLEAN;
117 else if (type == MERGED)
118 return LOWPU;
119 else
120 return HIGHPU;
121 } else {
122 return HSSPLIT;
123 }
124 }
125
126 return NONE;
127}
128
129}
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
SG::Decorator< T, ALLOC > Decorator
class to provide type-safe access to aux data.
Definition AuxElement.h:135
SG::ConstAccessor< T, ALLOC > ConstAccessor
Helper class to provide type-safe access to aux data.
Definition AuxElement.h:131
Exception — Attempt to retrieve nonexistent aux data item.
const std::vector< std::pair< const xAOD::Vertex *, size_t > > hardScatterMatches(const xAOD::VertexContainer &vxContainer)
const xAOD::Vertex * bestHardScatterMatch(const xAOD::VertexContainer &vxContainer)
HardScatterType classifyHardScatter(const xAOD::VertexContainer &vxContainer)
@ TruthEvent
The object is a truth event.
Definition ObjectType.h:69
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.