ATLAS Offline Software
Loading...
Searching...
No Matches
AFP_VertexRecoTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7using namespace std;
8
10 const std::string &name,
11 const IInterface *parent)
12 : base_class(type, name, parent)
13{
14 ATH_MSG_DEBUG("in AFP_VertexRecoTool constructor");
15}
16
17
19{
20 ATH_MSG_DEBUG("in AFP_VertexRecoTool::initialize()");
21
22 // vertex reconstruction tools
23 if(m_recoToolsList.empty())
24 {
25 ATH_MSG_ERROR("No vertex reconstruction tools set, check settings in AFP_VertexReco/AFP_VertexReco.py. Aborting.");
26 return StatusCode::FAILURE;
27 }
28 else
29 {
30 ATH_MSG_DEBUG("There are these tools in m_recoToolsList: "<<m_recoToolsList<<", will retrieve");
31 CHECK( m_recoToolsList.retrieve() );
32 }
33
34 // output containers for the vertex reconstruction tools
35 if(m_arrayOfWriteHandleKeys.empty())
36 {
37 ATH_MSG_ERROR("No output vertex containers provided, check settings in AFP_VertexReco/AFP_VertexReco.py. Aborting.");
38 return StatusCode::FAILURE;
39 }
40 else
41 {
42 ATH_MSG_DEBUG("There are these write handle keys in m_arrayOfWriteHandleKeys: "<<m_arrayOfWriteHandleKeys<<", will initialize");
43 CHECK( m_arrayOfWriteHandleKeys.initialize() );
44 }
45
46
47 // the code in execute relies on the facts that (a) the keys in WriteHandleKeyArray are unique; (b) all output container names from vertex reco tools are also in WriteHandleKeyArray; and moreover (c) that there are no extra WriteHandleKeys that are not present in any vertex reco tools
48 // case (c) wouldn't necessarily break things but it's not a sign of a good configuration and thus it's forbidden as well
49 // first, get names from write handle keys
50 std::vector<std::string> listOfWHKeys;
51 for(const auto &whk : m_arrayOfWriteHandleKeys)
52 {
53 ATH_MSG_DEBUG("have WHKey "<<whk.key());
54 listOfWHKeys.push_back(whk.key());
55 }
56 unsigned int all_WHkeys=listOfWHKeys.size();
57 // remove duplicities, there shouldn't be any
58 std::sort(listOfWHKeys.begin(), listOfWHKeys.end());
59 listOfWHKeys.erase(std::unique(listOfWHKeys.begin(),listOfWHKeys.end()), listOfWHKeys.end());
60 if(listOfWHKeys.size() != all_WHkeys)
61 {
62 ATH_MSG_ERROR("It seems write handle keys do not have unique values, check settings in AFP_VertexReco/AFP_VertexReco.py. Aborting.");
63 return StatusCode::FAILURE;
64 }
65 // get names from vertex reco tools
66 std::vector<std::string> listOfOutputContainers;
67 for(const auto &recoTool : m_recoToolsList)
68 {
69 ATH_MSG_DEBUG("have ouput container "<<recoTool->outputContainerName());
70 listOfOutputContainers.push_back(recoTool->outputContainerName());
71 }
72 // remove duplicities, they are allowed
73 std::sort(listOfOutputContainers.begin(), listOfOutputContainers.end());
74 listOfOutputContainers.erase(std::unique(listOfOutputContainers.begin(),listOfOutputContainers.end()), listOfOutputContainers.end());
75 // write handle keys and names from vertex reco tools should have the same size
76 if(listOfWHKeys.size() != listOfOutputContainers.size())
77 {
78 ATH_MSG_ERROR("There is different number of unique write handle keys ("<<listOfWHKeys.size()<<") and unique output containers ("<<listOfOutputContainers.size()<<"). Aborting");
79 return StatusCode::FAILURE;
80 }
81 // check they are the same; one of these loops are not strictly neccessary, but they will print outstanding names
82 bool doAbort=false;
83 for(const auto &trkOutCont : listOfOutputContainers)
84 {
85 if(std::find(listOfWHKeys.begin(),listOfWHKeys.end(),trkOutCont) == listOfWHKeys.end())
86 {
87 ATH_MSG_ERROR("Cannot find vertex reconstruction output container "<<trkOutCont<<" in write handle keys. Aborting");
88 doAbort=true;
89 }
90 }
91 for(const auto &whk : listOfWHKeys)
92 {
93 if(std::find(listOfOutputContainers.begin(),listOfOutputContainers.end(),whk) == listOfOutputContainers.end())
94 {
95 ATH_MSG_ERROR("Cannot find write handle key "<<whk<<" in vertex reconstruction output containers. Aborting");
96 doAbort=true;
97 }
98 }
99 if(doAbort) return StatusCode::FAILURE;
100 // Now, we are sure it's setup correctly
101
102
103// monitoring tool to be added soon
104 // monitoring
105// if (!(m_monTool.name().empty())) {
106// CHECK( m_monTool.retrieve() );
107// ATH_MSG_DEBUG("m_monTool name: " << m_monTool);
108// }
109
110 return StatusCode::SUCCESS;
111}
112
113StatusCode AFP_VertexRecoTool::execute(const EventContext& ctx) const
114{
115 ATH_MSG_DEBUG("in AFP_VertexRecoTool::execute()");
116
117
118 for(const auto &whk : m_arrayOfWriteHandleKeys)
119 {
120 // reconstruct vertices
121 auto afpVertex=std::make_unique<xAOD::AFPVertexContainer>();
122 auto afpVertexAux=std::make_unique<xAOD::AFPVertexAuxContainer>();
123 afpVertex->setStore(afpVertexAux.get());
124
125 for(const auto &recoTool : m_recoToolsList)
126 {
127 if(recoTool->outputContainerName() != whk.key()) continue;
128
129 if( recoTool->doVertexReco(afpVertex, ctx).isFailure() )
130 {
131 ATH_MSG_WARNING ("Failed to reconstruct vertices with algorithm = "<<recoTool->name());
132 }
133 }
134
135 ATH_MSG_DEBUG("write handle key "<<whk<<", have "<<afpVertex->size()<<" reconstructed vertices");
136
137
138 SG::WriteHandle<xAOD::AFPVertexContainer> vertexContainer(whk, ctx);
139 ATH_CHECK( vertexContainer.record(std::move(afpVertex), std::move(afpVertexAux)) );
140 }
141
142 return StatusCode::SUCCESS;
143}
144
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
virtual StatusCode execute(const EventContext &ctx) const override
Run vertex reco tool.
SG::WriteHandleKeyArray< xAOD::AFPVertexContainer > m_arrayOfWriteHandleKeys
Array of unique write handle keys for vertex output container.
ToolHandleArray< IAFP_TimeRecoTool > m_recoToolsList
Vector of tool handles to be used for vertex reconstruction.
virtual StatusCode initialize() override
AFP_VertexRecoTool(const std::string &type, const std::string &name, const IInterface *parent)
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
STL namespace.
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.