ATLAS Offline Software
Loading...
Searching...
No Matches
Reco_Vertex.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6// Reco_Vertex.cxx
8// Author: Daniel Scheirich <daniel.scheirich@cern.ch>
9// Based on the Integrated Simulation Framework
10//
11// Basic Jpsi->mu mu derivation example
12
13#include "Reco_Vertex.h"
14#include "BPhysPVTools.h"
18
19namespace DerivationFramework {
20
21 Reco_Vertex::Reco_Vertex(const std::string& t,
22 const std::string& n,
23 const IInterface* p) :
24 base_class(t,n,p),
25 m_v0Tools("Trk::V0Tools", this),
26 m_SearchTool("",this),
27 m_pvRefitter("Analysis::PrimaryVertexRefitter", this)
28 {
29
30 // Declare tools
31 declareProperty("V0Tools" , m_v0Tools);
32 declareProperty("VertexSearchTool", m_SearchTool);
33 declareProperty("PVRefitter", m_pvRefitter);
34
35 // Declare user-defined properties
36 declareProperty("OutputVtxContainerName", m_outputVtxContainerName = "OniaCandidates");
37 declareProperty("PVContainerName" , m_pvContainerName = "PrimaryVertices");
38 declareProperty("RefPVContainerName" , m_refPVContainerName = "RefittedPrimaryVertices");
39 declareProperty("RefitPV" , m_refitPV = false);
40 declareProperty("MaxPVrefit" , m_PV_max = 1000);
41 declareProperty("DoVertexType" , m_DoVertexType = 7);
42 // minimum number of tracks for PV to be considered for PV association
43 declareProperty("MinNTracksInPV" , m_PV_minNTracks = 0);
44 declareProperty("Do3d" , m_do3d = false);
45 declareProperty("CheckCollections" , m_checkCollections = false);
46 declareProperty("CheckVertexContainers" , m_CollectionsToCheck);
47 }
48
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
50
52 {
53
54 ATH_MSG_DEBUG("in initialize()");
55
56 // retrieve V0 tools
57 CHECK( m_v0Tools.retrieve() );
58
59 // get the Search tool
60 CHECK( m_SearchTool.retrieve() );
61
62 // get the PrimaryVertexRefitter tool
63 CHECK( m_pvRefitter.retrieve() );
64
65 // Get the beam spot service
66 ATH_CHECK(m_eventInfo_key.initialize());
67
68
70 ATH_CHECK(m_pvContainerName.initialize());
71 ATH_CHECK(m_refPVContainerName.initialize());
72 ATH_CHECK(m_RelinkContainers.initialize());
73 ATH_CHECK(m_RelinkMuons.initialize());
75 return StatusCode::SUCCESS;
76
77 }
78
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
80
81 StatusCode Reco_Vertex::addBranches(const EventContext& ctx) const
82 {
83 bool callTool = true;
85 for(const auto &str : m_CollectionsToCheck){
87 ATH_CHECK(handle.isValid());
88 if(handle->size() == 0) {
89 callTool = false;
90 ATH_MSG_DEBUG("Container VertexContainer (" << str << ") is empty");
91 break;//No point checking other containers
92 }
93 }
94 }
95
96 // Vertex container and its auxilliary store
97 std::unique_ptr<xAOD::VertexContainer> vtxContainer = std::make_unique<xAOD::VertexContainer>();
98 std::unique_ptr<xAOD::VertexAuxContainer> vtxAuxContainer = std::make_unique<xAOD::VertexAuxContainer>();
99 vtxContainer->setStore(vtxAuxContainer.get());
100
101 if(callTool) {
102 //----------------------------------------------------
103 // call Tool
104 //----------------------------------------------------
105 if( !m_SearchTool->performSearch(ctx,*vtxContainer).isSuccess() ) {
106 ATH_MSG_FATAL("Tool (" << m_SearchTool << ") failed.");
107 return StatusCode::FAILURE;
108 }
109
110 //----------------------------------------------------
111 // retrieve primary vertices
112 //----------------------------------------------------
114
115 //----------------------------------------------------
116 // Try to retrieve refitted primary vertices
117 //----------------------------------------------------
118 std::unique_ptr<xAOD::VertexContainer> refPvContainer;
119 std::unique_ptr<xAOD::VertexAuxContainer> refPvAuxContainer;
120 if(m_refitPV) {
121 // refitted PV container does not exist. Create a new one.
122 refPvContainer = std::make_unique<xAOD::VertexContainer>();
123 refPvAuxContainer = std::make_unique<xAOD::VertexAuxContainer>();
124 refPvContainer->setStore(refPvAuxContainer.get());
125 }
126
127 // Give the helper class the ptr to v0tools and beamSpotsSvc to use
129 if(not evt.isValid()) ATH_MSG_ERROR("Cannot Retrieve " << evt.key() );
130 BPhysPVTools helper(&(*m_v0Tools), evt.cptr());
131 helper.SetMinNTracksInPV(m_PV_minNTracks);
132 helper.SetSave3d(m_do3d);
133
134 if(m_refitPV){
135 if(vtxContainer->size() >0){
136 if(vtxContainer->size() > 10000){
137 ATH_MSG_WARNING("Number of candidates is very high N=" << vtxContainer->size() << " this may crash the sharedwriter");
138 }
139 StatusCode SC = helper.FillCandwithRefittedVertices(vtxContainer.get(), pvContainer.cptr(), refPvContainer.get(), &(*m_pvRefitter) , m_PV_max, m_DoVertexType);
140 if(SC.isFailure()){
141 ATH_MSG_FATAL("refitting failed - check the vertices you passed");
142 return SC;
143 }
144 if(refPvContainer->size() > 10000){
145 ATH_MSG_WARNING("Number of refitted vertices is very high N=" << refPvContainer->size() << " this may crash the sharedwriter");
146 }
147 }
148 }else{
149 if(vtxContainer->size() >0)CHECK(helper.FillCandExistingVertices(vtxContainer.get(), pvContainer.cptr(), m_DoVertexType));
150 }
151
153
154 std::vector<const xAOD::TrackParticleContainer*> trackCols;
155 for(const auto &str : m_RelinkContainers){
157 trackCols.push_back(handle.cptr());
158 }
159 if(not trackCols.empty()){
160 for(xAOD::Vertex* vtx : *vtxContainer.get()){
161 try{
163 }catch(std::runtime_error const& e){
164 ATH_MSG_ERROR(e.what());
165 return StatusCode::FAILURE;
166 }
167 }
168 }
169 std::vector<const xAOD::MuonContainer*> muCols;
170 for(const auto &str : m_RelinkMuons){
172 muCols.push_back(handle.cptr());
173 }
174 if(not muCols.empty()){
175 for(xAOD::Vertex* vtx : *vtxContainer.get()){
176 try{
178 }catch(std::runtime_error const& e){
179 ATH_MSG_ERROR(e.what());
180 return StatusCode::FAILURE;
181 }
182 }
183 }
184 //----------------------------------------------------
185 // save in the StoreGate
186 //----------------------------------------------------
188 ATH_CHECK(handle.record(std::move(vtxContainer), std::move(vtxAuxContainer)));
189
190 if(m_refitPV) {
192 ATH_CHECK(handle.record(std::move(refPvContainer), std::move(refPvAuxContainer)));
193 }
194 }
195
196 if (!callTool) { //Fill with empty containers
198 ATH_CHECK(handle.record(std::unique_ptr<xAOD::VertexContainer>(new xAOD::VertexContainer ),
199 std::unique_ptr<xAOD::VertexAuxContainer>(new xAOD::VertexAuxContainer )));
200 }
201
202 return StatusCode::SUCCESS;
203 }
204
205
206
207}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
static void RelinkVertexMuons(const std::vector< const xAOD::MuonContainer * > &muoncols, xAOD::Vertex *vtx)
static void RelinkVertexTracks(const std::vector< const xAOD::TrackParticleContainer * > &trkcols, xAOD::Vertex *vtx)
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo_key
Definition Reco_Vertex.h:39
ToolHandle< Analysis::ICandidateSearch > m_SearchTool
Definition Reco_Vertex.h:37
SG::WriteHandleKey< xAOD::VertexContainer > m_refPVContainerName
Definition Reco_Vertex.h:44
ToolHandle< Trk::V0Tools > m_v0Tools
tools
Definition Reco_Vertex.h:36
SG::ReadHandleKey< xAOD::VertexContainer > m_pvContainerName
Definition Reco_Vertex.h:43
ToolHandle< Analysis::PrimaryVertexRefitter > m_pvRefitter
Definition Reco_Vertex.h:38
SG::ReadHandleKeyArray< xAOD::TrackParticleContainer > m_RelinkContainers
Definition Reco_Vertex.h:52
SG::ReadHandleKeyArray< xAOD::MuonContainer > m_RelinkMuons
Definition Reco_Vertex.h:53
SG::WriteHandleKey< xAOD::VertexContainer > m_outputVtxContainerName
job options
Definition Reco_Vertex.h:42
Reco_Vertex(const std::string &t, const std::string &n, const IInterface *p)
SG::ReadHandleKeyArray< xAOD::VertexContainer > m_CollectionsToCheck
Definition Reco_Vertex.h:51
virtual StatusCode initialize()
virtual StatusCode addBranches(const EventContext &ctx) const
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
THE reconstruction tool.
VertexAuxContainer_v1 VertexAuxContainer
Definition of the current jet auxiliary container.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.