ATLAS Offline Software
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 
10 namespace {
11 
12 bool 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
41 const 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 }
grepfile.info
info
Definition: grepfile.py:38
InDetVertexTruthMatchUtils::LOWPU
@ LOWPU
Definition: InDetVertexTruthMatchUtils.h:32
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
get_generator_info.result
result
Definition: get_generator_info.py:21
InDetVertexTruthMatchUtils::bestHardScatterMatch
const xAOD::Vertex * bestHardScatterMatch(const xAOD::VertexContainer &vxContainer)
Definition: InDetVertexTruthMatchUtils.cxx:20
xAOD::TruthEvent
TruthEvent_v1 TruthEvent
Typedef to implementation.
Definition: TruthEvent.h:17
skel.it
it
Definition: skel.GENtoEVGEN.py:396
InDetVertexTruthMatchUtils::classifyHardScatter
HardScatterType classifyHardScatter(const xAOD::VertexContainer &vxContainer)
Definition: InDetVertexTruthMatchUtils.cxx:70
InDetVertexTruthMatchUtils::MATCHED
@ MATCHED
Definition: InDetVertexTruthMatchUtils.h:21
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
InDetVertexTruthMatchUtils::CLEAN
@ CLEAN
Definition: InDetVertexTruthMatchUtils.h:31
InDetVertexTruthMatchUtils::HSSPLIT
@ HSSPLIT
Definition: InDetVertexTruthMatchUtils.h:34
InDetVertexTruthMatchUtils.h
SG::ExcBadAuxVar
Exception — Attempt to retrieve nonexistent aux data item.
Definition: Control/AthContainers/AthContainers/exceptions.h:59
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
lumiFormat.i
int i
Definition: lumiFormat.py:85
InDetVertexTruthMatchUtils::HIGHPU
@ HIGHPU
Definition: InDetVertexTruthMatchUtils.h:33
python.utils.best
def best(iterable, priorities=[3, 2, 1, -1, 0])
Definition: DataQuality/DQUtils/python/utils.py:50
InDetVertexTruthMatchUtils::VertexMatchType
VertexMatchType
Definition: InDetVertexTruthMatchUtils.h:20
InDetVertexTruthMatchUtils::NONE
@ NONE
Definition: InDetVertexTruthMatchUtils.h:35
InDetVertexTruthMatchUtils
Definition: InDetVertexTruthMatchUtils.h:11
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
InDetVertexTruthMatchUtils::MERGED
@ MERGED
Definition: InDetVertexTruthMatchUtils.h:22
InDetVertexTruthMatchUtils::HardScatterType
HardScatterType
Definition: InDetVertexTruthMatchUtils.h:30
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:536
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
InDetVertexTruthMatchUtils::hardScatterMatches
const std::vector< std::pair< const xAOD::Vertex *, size_t > > hardScatterMatches(const xAOD::VertexContainer &vxContainer)
Definition: InDetVertexTruthMatchUtils.cxx:41