ATLAS Offline Software
TauPVRefitTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TauPVRefitTool.cxx
7 // Author: Evelina Bouhova-Thacker (e.bouhova@cern.ch)
8 //
10 
13 #include "xAODTracking/Vertex.h"
14 
15 namespace DerivationFramework {
16 
17  TauPVRefitTool::TauPVRefitTool(const std::string& t, const std::string& n, const IInterface* p) :
18  AthAlgTool(t,n,p),
19  m_linkName("PVLink"),
20  m_reflinkName("TauRefittedPVLink"),
21  m_pvrefContainerName("TauRefittedPrimaryVertices"),
22  m_pvContainerName("PrimaryVertices"),
23  m_tauTrkContainerName("TauPVTracks"),
24  m_pvrefitter("Analysis::PrimaryVertexRefitter")
25  {
26  declareInterface<DerivationFramework::IAugmentationTool>(this);
27  declareProperty("PVLinkName", m_linkName);
28  declareProperty("RefittedLinkName", m_reflinkName);
29  declareProperty("PVRefContainerName", m_pvrefContainerName);
30  declareProperty("PVContainerName", m_pvContainerName);
31  declareProperty("TauTrkContainerName", m_tauTrkContainerName);
32  declareProperty("PrimaryVertexRefitterTool", m_pvrefitter);
33  }
34 
36  {
37  if (m_pvrefContainerName=="") {
38  ATH_MSG_ERROR("No SG name provided for the output of the tau PV refitter tool!");
39  return StatusCode::FAILURE;
40  }
41  CHECK( m_pvrefitter.retrieve() );
42  return StatusCode::SUCCESS;
43  }
44 
46  {
47  return StatusCode::SUCCESS;
48  }
49 
51  {
52  // check that container we want to write in SG does not yet exist
53  if (evtStore()->contains<std::vector<float> >(m_pvrefContainerName)) {
54  ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << m_pvrefContainerName << " which already exists. Please use a different key");
55  return StatusCode::FAILURE;
56  }
57 
58  xAOD::VertexContainer* TauRefittedPrimaryVertices(0);
59  xAOD::VertexAuxContainer* TauRefittedPrimaryVerticesAux(0);
60 
61  CHECK(refit(TauRefittedPrimaryVertices,TauRefittedPrimaryVerticesAux));
62  ATH_MSG_DEBUG ("number of refitted PVs " << TauRefittedPrimaryVertices->size());
63 
64  if (!evtStore()->contains<xAOD::VertexContainer>(m_pvrefContainerName))
65  CHECK(evtStore()->record(TauRefittedPrimaryVertices, m_pvrefContainerName));
66  if (!evtStore()->contains<xAOD::VertexAuxContainer>(m_pvrefContainerName+"Aux."))
67  CHECK(evtStore()->record(TauRefittedPrimaryVerticesAux, m_pvrefContainerName+"Aux."));
68 
69  return StatusCode::SUCCESS;
70  }
71 
72  StatusCode TauPVRefitTool::refit(xAOD::VertexContainer*& TauRefittedPrimaryVertices, xAOD::VertexAuxContainer*& TauRefittedPrimaryVerticesAux) const
73  {
74  TauRefittedPrimaryVertices = new xAOD::VertexContainer;
75  TauRefittedPrimaryVerticesAux = new xAOD::VertexAuxContainer;
76  TauRefittedPrimaryVertices->setStore(TauRefittedPrimaryVerticesAux);
77 
78  // Get PV collection from StoreGate
79  const xAOD::VertexContainer* pv_cont = evtStore()->retrieve< const xAOD::VertexContainer >( m_pvContainerName );
80  if (pv_cont == 0) return StatusCode::SUCCESS;
81  ATH_MSG_DEBUG ("number of PVs " << pv_cont->size());
82 
83  // Get selected tau tracks
84  std::vector<const xAOD::TrackParticle*> tps; tps.clear();
86  for (auto trk: *trk_cont) tps.push_back(trk);
87  ATH_MSG_DEBUG ("tps size " << tps.size());
88 
89  std::vector<unsigned int> pv_index; pv_index.clear();
90  unsigned int ipv = 0, ipv2 = 0;
91  // loop over PV container and refit
92  for (auto pv: *pv_cont ) {
93  xAOD::Vertex* pv_ref = m_pvrefitter->refitVertex(pv,tps);
94  if (pv_ref) {
95  if (pv_ref->nTrackParticles() < pv->nTrackParticles()) {
96  TauRefittedPrimaryVertices->push_back(pv_ref);
97  pv_index.push_back(ipv);
98  } else {
99  delete pv_ref;
100  }
101  } else {
102  delete pv_ref;
103  }
104  ipv++;
105  }
106 
107  // loop over PV container and set links
108  for (auto pv: *pv_cont ) {
113  if (TauRefittedPrimaryVertices->size() == 0) mDecor_pvLink(*pv) = pvLink;
114  unsigned int irpv = 0;
115  for (auto rpv: *TauRefittedPrimaryVertices ) {
116  if (ipv2 == pv_index[irpv]) {
117  ATH_MSG_DEBUG (" pv x " << pv->x() << " y " << pv->y() << " z " << pv->z() << " ntrks " << pv->nTrackParticles() << " ndf " << pv->numberDoF() << " chi2 " << pv->chiSquared());
118  ATH_MSG_DEBUG ("ref pv x " << rpv->x() << " y " << rpv->y() << " z " << rpv->z() << " ntrks " << rpv->nTrackParticles() << " ndf " << rpv->numberDoF() << " chi2 " << rpv->chiSquared());
119  pvLink.setElement(rpv);
120  pvLink.setStorableObject(*TauRefittedPrimaryVertices);
121  mDecor_pvLink(*pv) = pvLink;
122 
123  ref_pvLink.setElement(pv);
124  ref_pvLink.setStorableObject(*pv_cont);
125  mDecor_ref_pvLink(*rpv) = ref_pvLink;
126  } else {
127  mDecor_pvLink(*pv) = pvLink;
128  }
129  irpv++;
130  }
131  ipv2++;
132  }
133 
134  return StatusCode::SUCCESS;
135  }
136 }
DerivationFramework::TauPVRefitTool::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: TauPVRefitTool.cxx:50
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
xAOD::VertexAuxContainer_v1
Temporary container used until we have I/O for AuxStoreInternal.
Definition: VertexAuxContainer_v1.h:32
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
DerivationFramework::TauPVRefitTool::finalize
StatusCode finalize()
Definition: TauPVRefitTool.cxx:45
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::TauPVRefitTool::refit
StatusCode refit(xAOD::VertexContainer *&TauRefittedPrimaryVertices, xAOD::VertexAuxContainer *&TauRefittedPrimaryVerticesAux) const
Definition: TauPVRefitTool.cxx:72
TauPVRefitTool.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
PrimaryVertexRefitter.h
xAOD::VertexContainer
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Definition: VertexContainer.h:14
DerivationFramework::TauPVRefitTool::m_linkName
std::string m_linkName
Definition: TauPVRefitTool.h:41
DerivationFramework::TauPVRefitTool::m_reflinkName
std::string m_reflinkName
Definition: TauPVRefitTool.h:42
DerivationFramework::TauPVRefitTool::TauPVRefitTool
TauPVRefitTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: TauPVRefitTool.cxx:17
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
xAOD::VertexAuxContainer
VertexAuxContainer_v1 VertexAuxContainer
Definition of the current jet auxiliary container.
Definition: VertexAuxContainer.h:19
beamspotman.n
n
Definition: beamspotman.py:731
DerivationFramework::TauPVRefitTool::initialize
StatusCode initialize()
Definition: TauPVRefitTool.cxx:35
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DerivationFramework::TauPVRefitTool::m_pvrefitter
ToolHandle< Analysis::PrimaryVertexRefitter > m_pvrefitter
Definition: TauPVRefitTool.h:47
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Vertex.h
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DerivationFramework::TauPVRefitTool::m_pvContainerName
std::string m_pvContainerName
Definition: TauPVRefitTool.h:44
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
python.changerun.pv
pv
Definition: changerun.py:81
DerivationFramework::TauPVRefitTool::m_pvrefContainerName
std::string m_pvrefContainerName
Definition: TauPVRefitTool.h:43
AthAlgTool
Definition: AthAlgTool.h:26
DerivationFramework::TauPVRefitTool::m_tauTrkContainerName
std::string m_tauTrkContainerName
Definition: TauPVRefitTool.h:45
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.