ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigSteer
DecisionHandling
src
TestRecoAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include <fstream>
6
#include <
xAODTrigger/TrigCompositeAuxContainer.h
>
7
#include <
TrigSteeringEvent/TrigRoiDescriptorCollection.h
>
8
#include <
TrigCompositeUtils/TrigCompositeUtils.h
>
9
#include "
TestRecoAlg.h
"
10
11
12
13
namespace
HLTTest
{
14
15
TestRecoAlg::TestRecoAlg
(
const
std::string& name,
16
ISvcLocator* pSvcLocator ) :
17
::
AthAlgorithm
( name, pSvcLocator )
18
{}
19
20
21
TestRecoAlg::~TestRecoAlg
() {}
22
23
void
split
(
const
std::string& src,
char
delim, std::vector<std::string>& result) {
24
std::istringstream i(src);
25
std::string element;
26
while
( getline(i, element, delim) ) {
27
result.push_back(element);
28
}
29
}
30
std::string
trim
(
const
std::string&
str
) {
31
size_t
firstNonSpace =
str
.find_first_not_of(
' '
);
32
size_t
lastNonSpace =
str
.find_last_not_of(
' '
);
33
return
str
.substr( firstNonSpace, lastNonSpace-firstNonSpace+1 );
34
}
35
36
StatusCode
TestRecoAlg::initialize
() {
37
ATH_MSG_INFO
(
"Initializing "
<< name() <<
" reading input file "
<<
m_fileName
);
38
39
40
CHECK
(
m_output
.initialize() );
41
CHECK
(
m_input
.initialize( not
m_input
.key().empty() ) );
42
std::ifstream inputFile(
m_fileName
);
43
std::string line;
44
typedef
std::vector<std::string> Split_t;
45
46
while
( getline(inputFile, line) ) {
47
if
( line[0] ==
'#'
)
continue
;
48
Split_t objects;
49
Event_t
event;
50
split
( line,
';'
, objects );
51
for
(
const
auto
& obj: objects ) {
52
Obj_t
object;
53
Split_t properties;
54
split
( obj,
','
, properties );
55
for
(
const
auto
& prop: properties ) {
56
Split_t keyval;
57
split
( prop,
':'
, keyval );
58
if
( keyval.size() != 2 ) {
59
ATH_MSG_ERROR
(
"Pnput format error, property specification invalid, should be a:b "
<< prop );
60
return
StatusCode::FAILURE;
61
}
62
object
.push_back( std::make_pair(
trim
( keyval[0] ), std::stof(keyval[1]) ) );
63
}
64
if
(
object
.
size
() != 0 )
65
event
.push_back(std::move(
object
));
66
}
67
m_data
.push_back(std::move(event));
68
}
69
ATH_MSG_DEBUG
(
"Loaded "
<<
m_data
.size() <<
" pseudo events"
);
70
if
(
m_data
.size() == 0 ) {
71
ATH_MSG_ERROR
(
"Can not run with zero pseudo events"
);
72
return
StatusCode::FAILURE;
73
}
74
return
StatusCode::SUCCESS;
75
}
76
77
StatusCode
TestRecoAlg::finalize
() {
78
ATH_MSG_INFO
(
"Finalizing "
<< name() <<
"..."
);
79
return
StatusCode::SUCCESS;
80
}
81
82
StatusCode
TestRecoAlg::execute
(
const
EventContext& ctx) {
83
using namespace
TrigCompositeUtils
;
84
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"..."
);
85
86
const
EventContext& context = ctx;
87
const
size_t
eventNo = context.evt() %
m_data
.size();
88
auto
objects=
m_data
[eventNo];
89
90
auto
output = std::make_unique<xAOD::TrigCompositeContainer>();
91
auto
aux = std::make_unique<xAOD::TrigCompositeAuxContainer>();
92
output->setStore( aux.get() );
93
94
95
auto
inputHandle =
SG::makeHandle
(
m_input
, ctx);
96
ATH_MSG_DEBUG
(
"Input "
<<
m_input
.key() <<
" has "
<<inputHandle->size() <<
" elements, scanning it"
);
97
for
(
auto
i: *inputHandle.cptr() ) {
98
auto
featureInfo =
TrigCompositeUtils::findLink<TrigRoiDescriptorCollection>
( ctx, i,
"initialRoI"
);
99
auto
roiLink = featureInfo.link;
100
CHECK
( roiLink.isValid() );
101
if
( roiLink.isValid() ) {
102
auto
roiPtr(roiLink.cptr());
103
ATH_MSG_DEBUG
(
"RoI"
<< **roiPtr );
104
bool
foundObject =
false
;
105
// create new outpu objects and add the properties
106
if
(objects.size() > output->size()) {
107
// attaching the correct object form input data:
108
for
(
const
auto
&
object
: objects){
109
auto
eta
=
object
[0].second;
110
auto
phi
=
object
[1].second;
111
// check eta and phi
112
if
(std::abs(
eta
- (*roiPtr)->eta()) <0.01 && std::abs(
phi
- (*roiPtr)->phi())< 0.01){
113
foundObject =
true
;
114
ATH_MSG_DEBUG
(
"Found object: "
<<
object
[0].first <<
" : "
<<
object
[0].second <<
" , "
<<
object
[1].first <<
" : "
<<
object
[1].second );
115
auto
xobj =
new
xAOD::TrigComposite
;
116
output->push_back( xobj );
117
// maintain link to previous collections
118
xobj->setObjectLink(
"initialRoI"
, roiLink );
// this is used by the HypoAlg
119
for
(
const
auto
& prop :
object
) {
120
xobj->setDetail( prop.first, prop.second );
121
ATH_MSG_DEBUG
(
" "
<< prop.first <<
" : "
<< prop.second );
122
}
123
}
124
}
125
if
(!foundObject) {
126
ATH_MSG_ERROR
(
"No reco object found in eta and phi range: this might be an error"
);
127
}
128
}
129
else
{
130
ATH_MSG_DEBUG
(
"No reco object created for this RoI because it's not found in the event"
);
131
}
132
}
else
{
133
ATH_MSG_DEBUG
(
"RoI information missing"
);
134
}
135
}
136
137
138
ATH_MSG_DEBUG
(
"Reconstructed "
<<output->size() <<
" objects"
);
139
140
auto
handle =
SG::makeHandle
(
m_output
, ctx);
141
CHECK
( handle.record( std::move(output), std::move(aux) ) );
142
143
return
StatusCode::SUCCESS;
144
}
145
146
}
//> end namespace HLTTest
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
phi
Scalar phi() const
phi method
Definition
AmgMatrixBasePlugin.h:67
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:422
size
size_t size() const
Number of registered mappings.
TestRecoAlg.h
TrigCompositeAuxContainer.h
TrigCompositeUtils.h
TrigRoiDescriptorCollection.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
HLTTest::TestRecoAlg::m_fileName
StringProperty m_fileName
Definition
TestRecoAlg.h:44
HLTTest::TestRecoAlg::initialize
StatusCode initialize() override
Definition
TestRecoAlg.cxx:36
HLTTest::TestRecoAlg::TestRecoAlg
TestRecoAlg()
HLTTest::TestRecoAlg::~TestRecoAlg
virtual ~TestRecoAlg()
Definition
TestRecoAlg.cxx:21
HLTTest::TestRecoAlg::m_data
std::vector< Event_t > m_data
Definition
TestRecoAlg.h:43
HLTTest::TestRecoAlg::m_output
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_output
Definition
TestRecoAlg.h:46
HLTTest::TestRecoAlg::execute
StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
TestRecoAlg.cxx:82
HLTTest::TestRecoAlg::m_input
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_input
Definition
TestRecoAlg.h:47
HLTTest::TestRecoAlg::finalize
StatusCode finalize() override
Definition
TestRecoAlg.cxx:77
HLTTest::TestRecoAlg::Obj_t
std::vector< Prop_t > Obj_t
Definition
TestRecoAlg.h:41
HLTTest::TestRecoAlg::Event_t
std::vector< Obj_t > Event_t
Definition
TestRecoAlg.h:42
HLTTest
Definition
ITestHypoTool.cxx:9
HLTTest::split
void split(const std::string &src, char delim, std::vector< std::string > &result)
Definition
TestRecoAlg.cxx:23
HLTTest::trim
std::string trim(const std::string &str)
Definition
TestRecoAlg.cxx:30
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition
ReadCondHandle.h:269
TrigCompositeUtils
Definition
TrigComposite.h:19
TrigCompositeUtils::findLink
LinkInfo< T > findLink(const EventContext &ctx, const Decision *start, const std::string &linkName, const bool suppressMultipleLinksWarning=false)
Perform a recursive search for ElementLinks of type T and name 'linkName', starting from Decision obj...
str
Definition
BTagTrackIpAccessor.cxx:11
xAOD::TrigComposite
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
Definition
TrigComposite.h:16
Generated on
for ATLAS Offline Software by
1.17.0