ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigHypothesis
TrigHLTJetHypoUnitTests
exerciser
JetHypoExerciserCompareAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
TrigHLTJetHypoUnitTests/JetHypoExerciserCompareAlg.h
"
6
#include "
TrigHLTJetHypo/ITrigJetHypoToolHelper.h
"
7
#include "
TrigHLTJetHypo/TrigHLTJetHypoUtils/HypoJetDefs.h
"
8
#include "
TrigHLTJetHypoUnitTests/../src/TLorentzVectorFactory.h
"
9
#include "
TrigHLTJetHypoUnitTests/../src/TLorentzVectorAsIJet.h
"
10
#include "
TrigHLTJetHypo/../src/DebugInfoCollector.h
"
11
#include "
TrigHLTJetHypo/../src/xAODJetCollector.h
"
12
#include "
TrigHLTJetHypo/../src/JetTrigTimer.h
"
13
#include "
TrigHLTJetHypo/TrigHLTJetHypoUtils/lineSplitter.h
"
14
15
#include <fstream>
16
#include <sstream>
17
18
JetHypoExerciserCompareAlg::JetHypoExerciserCompareAlg
(
const
std::string& name,
19
ISvcLocator* pSvcLocator) :
20
AthAlgorithm
(name, pSvcLocator){
21
}
22
23
JetHypoExerciserCompareAlg::~JetHypoExerciserCompareAlg
(){}
24
25
26
StatusCode
27
JetHypoExerciserCompareAlg::initialize_
(
const
ToolHandle<ITrigJetHypoToolHelper>& helper,
28
const
std::string& logname) {
29
30
ATH_MSG_INFO
(
"initialize_()"
);
31
32
ATH_MSG_INFO
33
(
" "
<< helper.propertyName()
34
<<
" = "
<< helper.type());
35
36
if
( helper.retrieve().isFailure() ) {
37
ATH_MSG_FATAL
38
(helper.propertyName() <<
": Failed to retrieve tool "
39
<< helper.type());
40
return
StatusCode::FAILURE;
41
}
else
{
42
ATH_MSG_INFO
43
(helper.propertyName() <<
": Retrieved tool "
44
<< helper.type());
45
}
46
DebugInfoCollector
collector(name());
47
CHECK
(helper->getDescription(collector));
48
auto
s = collector.
toString
();
49
s +=
'\n'
+
m_generator
->toString();
50
51
for
(
const
auto
& l :
lineSplitter
(s)){
52
ATH_MSG_INFO
(l);
53
}
54
55
if
(
m_visitDebug
){
56
std::ofstream outfile;
57
outfile.open(logname);
58
outfile << s;
59
}
60
61
return
StatusCode::SUCCESS;
62
}
63
64
StatusCode
JetHypoExerciserCompareAlg::initialize
() {
65
66
ATH_MSG_INFO
(
"initialize()"
);
67
auto
logname =
m_logname
+
"_config0.log"
;
68
auto
sc
=
initialize_
(
m_helper0
, logname);
69
if
(!(
sc
== StatusCode::SUCCESS)){
return
sc
;}
70
71
logname =
m_logname
+
"_config1.log"
;
72
return
initialize_
(
m_helper1
, logname);
73
}
74
75
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
76
77
StatusCode
78
JetHypoExerciserCompareAlg::execute_
(ToolHandle<ITrigJetHypoToolHelper>& helper,
79
HypoJetVector
& jv,
80
const
std::string& collectorName,
81
xAODJetCollector
& jetCollector,
82
const
std::string& logname,
83
bool
& pass) {
84
85
// make a HypoJet, add to vector and send to helper tool
86
87
std::unique_ptr<ITrigJetHypoInfoCollector> debugInfoCollector(
nullptr
);
88
if
(
m_visitDebug
){
89
debugInfoCollector.reset(
new
DebugInfoCollector
(collectorName));
90
}
91
92
if
(debugInfoCollector){
93
std::stringstream ss0;
94
ss0 <<
"n jets "
<< jv.size() <<
'\n'
;
95
debugInfoCollector-> collect(
"JetHypoExerciserCompareAlg"
, ss0.str());
96
97
98
std::stringstream ss1;
99
ss1 <<
'\n'
;
100
for
(
const
auto
& j : jv){
101
ss1 <<
"e: "
<< j->e() <<
" et "
<< j->et() <<
" eta "
<< j->eta()
102
<<
'\n'
;
103
}
104
debugInfoCollector-> collect(
"JetHypoExerciserCompareAlg"
, ss1.str());
105
}
106
107
108
pass = helper->pass(jv, jetCollector, debugInfoCollector);
109
110
std::stringstream
ss
;
111
ss
<<
"========= ncall: "
<<
m_ncall
<<
"==========\n"
;
112
if
(debugInfoCollector){
113
std::stringstream ss1;
114
ss1 <<
'\n'
;
115
for
(
const
auto
& j : jetCollector.
hypoJets
()){
116
ss1 <<
"e: "
<< j->e() <<
" et "
<< j->et() <<
" eta "
<< j->eta()
117
<<
'\n'
;
118
}
119
debugInfoCollector-> collect(
"JetHypoExerciserCompareAlg"
, ss1.str());
120
debugInfoCollector-> collect(
"JetHypoExerciserCompareAlg collectedJets"
,
121
ss1.str());
122
123
ss
<< debugInfoCollector->toString() +
'\n'
;
124
}
125
auto
s =
ss
.str();
126
std::ofstream outfile;
127
// outfile.open(logname, std::ios_base::app);
128
outfile.open(logname);
129
outfile << s;
130
outfile.close();
131
return
StatusCode::SUCCESS;
132
}
133
134
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
135
136
StatusCode
JetHypoExerciserCompareAlg::execute
(
const
EventContext&
/*ctx*/
) {
137
138
// Part 1: print where you are
139
ATH_MSG_INFO
(
"execute()"
);
140
++
m_ncall
;
141
142
// make a HypoJet, add to vector and send to helper tool
143
144
HypoJetVector
jv =
m_generator
->get();
145
146
auto
timer =
JetTrigTimer
();
147
std::string collectorName = name() +
"debugInfoCollector0"
;
148
std::string logname =
m_logname
+
"_ev_"
+ std::to_string(
m_ncall
) +
"tool0"
;
149
bool
pass0{
false
};
150
151
xAODJetCollector
jetCollector0;
152
153
timer.start();
154
ATH_CHECK
(
execute_
(
m_helper0
, jv, collectorName, jetCollector0, logname, pass0));
155
timer.update();
156
157
if
(!
m_visitDebug
){
158
std::stringstream
ss
;
159
ss
<< timer.elapsed_to_update()
160
<<
" tool0 "
<< std::boolalpha << pass0 <<
'\n'
;
161
timer.reset();
162
std::ofstream outfile;
163
outfile.open(logname);
164
outfile <<
ss
.str();
165
outfile.close();
166
}
167
168
collectorName = name() +
"debugInfoCollector1"
;
169
logname =
m_logname
+
"_ev_"
+ std::to_string(
m_ncall
) +
"tool1"
;
170
bool
pass1{
false
};
171
xAODJetCollector
jetCollector1;
172
173
174
timer.start();
175
176
ATH_CHECK
(
execute_
(
m_helper1
, jv, collectorName, jetCollector1, logname, pass1));
177
timer.update();
178
179
if
(!
m_visitDebug
){
180
std::stringstream
ss
;
181
ss
<< timer.elapsed_to_update()
182
<<
" tool1 "
<< std::boolalpha << pass1 <<
'\n'
;
183
timer.reset();
184
std::ofstream outfile;
185
outfile.open(logname);
186
outfile <<
ss
.str();
187
outfile.close();
188
}
189
190
191
std::string spass0 = (pass0 ?
"True"
:
"False"
);
192
std::string spass1 = (pass1 ?
"True"
:
"False"
);
193
if
(pass0 != pass1){
194
++
m_differ
;
195
ATH_MSG_INFO
(
"hypo helper tools DISAGREE: "
196
<<
"pass 0 "
<< spass0 <<
" pass 1 "
<< spass1);
197
}
else
{
198
if
(pass0){
199
200
++
m_agree_true
;
201
}
else
{
202
++
m_agree_false
;
203
}
204
ATH_MSG_INFO
(
"hypo helper tools agree on result which is: "
<< spass0);
205
}
206
207
HypoJetVector
collected0 = jetCollector0.
hypoJets
();
208
HypoJetVector
collected1 = jetCollector1.
hypoJets
();
209
std::size_t njets = collected0.size();
210
211
if
(njets == collected1.size()) {
212
std::sort
(collected0.begin(), collected0.end());
213
std::sort
(collected1.begin(), collected1.end());
214
215
bool
jagree{
true
};
216
for
(std::size_t i = 0; i < njets; i++) {
217
ATH_MSG_INFO
(
" jet 0 : "
<<
static_cast<
const
void
*
>
(collected0.at(i).get()) <<
218
" jet 1 : "
<<
static_cast<
const
void
*
>
(collected1.at(i).get()));
219
220
if
(collected0.at(i) != collected1.at(i)) {
221
ATH_MSG_INFO
(
" jets above differ "
);
222
jagree =
false
;
223
break
;
224
}
225
}
226
if
(jagree) {
227
++
m_agree_jets
;
228
}
else
{
229
++
m_differ_jets
;
230
}
231
}
else
{
232
++
m_differ_jets
;
233
ATH_MSG_INFO
(
" no of jets 0 : "
<< collected0.size() <<
" "
234
" no of jets 1 : "
<< collected1.size() <<
" "
235
" no of jets differ "
);
236
237
}
238
239
return
StatusCode::SUCCESS;
240
}
241
242
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
243
244
StatusCode
JetHypoExerciserCompareAlg::finalize
() {
245
246
// Part 1: print where you are
247
ATH_MSG_INFO
(
"finalize()"
);
248
ATH_MSG_INFO
(
"agree and false: "
<<
m_agree_false
<<
249
" agree and true: "
<<
m_agree_true
<<
250
" differ: "
<<
m_differ
<<
251
" jets agree: "
<<
m_agree_jets
<<
252
" jets differ: "
<<
m_differ_jets
253
);
254
255
return
StatusCode::SUCCESS;
256
}
257
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DebugInfoCollector.h
HypoJetDefs.h
HypoJetVector
std::vector< pHypoJet > HypoJetVector
Definition
HypoJetDefs.h:27
ITrigJetHypoToolHelper.h
JetHypoExerciserCompareAlg.h
JetTrigTimer.h
ss
static Double_t ss
Definition
LArPhysWaveHECTool.cxx:37
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
TLorentzVectorAsIJet.h
TLorentzVectorFactory.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
DebugInfoCollector
Definition
DebugInfoCollector.h:13
DebugInfoCollector::toString
virtual std::string toString() const override
Definition
DebugInfoCollector.cxx:70
JetHypoExerciserCompareAlg::m_agree_true
std::size_t m_agree_true
Definition
JetHypoExerciserCompareAlg.h:48
JetHypoExerciserCompareAlg::~JetHypoExerciserCompareAlg
virtual ~JetHypoExerciserCompareAlg()
Definition
JetHypoExerciserCompareAlg.cxx:23
JetHypoExerciserCompareAlg::m_differ_jets
std::size_t m_differ_jets
Definition
JetHypoExerciserCompareAlg.h:52
JetHypoExerciserCompareAlg::m_helper0
ToolHandle< ITrigJetHypoToolHelper > m_helper0
Definition
JetHypoExerciserCompareAlg.h:30
JetHypoExerciserCompareAlg::m_helper1
ToolHandle< ITrigJetHypoToolHelper > m_helper1
Definition
JetHypoExerciserCompareAlg.h:33
JetHypoExerciserCompareAlg::JetHypoExerciserCompareAlg
JetHypoExerciserCompareAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
JetHypoExerciserCompareAlg.cxx:18
JetHypoExerciserCompareAlg::m_visitDebug
Gaudi::Property< bool > m_visitDebug
Definition
JetHypoExerciserCompareAlg.h:41
JetHypoExerciserCompareAlg::m_differ
std::size_t m_differ
Definition
JetHypoExerciserCompareAlg.h:50
JetHypoExerciserCompareAlg::initialize
StatusCode initialize()
Definition
JetHypoExerciserCompareAlg.cxx:64
JetHypoExerciserCompareAlg::execute
StatusCode execute(const EventContext &ctx)
Execute method.
Definition
JetHypoExerciserCompareAlg.cxx:136
JetHypoExerciserCompareAlg::m_agree_jets
std::size_t m_agree_jets
Definition
JetHypoExerciserCompareAlg.h:51
JetHypoExerciserCompareAlg::finalize
StatusCode finalize()
Definition
JetHypoExerciserCompareAlg.cxx:244
JetHypoExerciserCompareAlg::execute_
StatusCode execute_(ToolHandle< ITrigJetHypoToolHelper > &, HypoJetVector &, const std::string &collectorName, xAODJetCollector &jetCollector, const std::string &logname, bool &pass)
Definition
JetHypoExerciserCompareAlg.cxx:78
JetHypoExerciserCompareAlg::m_logname
Gaudi::Property< std::string > m_logname
Definition
JetHypoExerciserCompareAlg.h:44
JetHypoExerciserCompareAlg::m_generator
ToolHandle< IHypoJetVectorGenerator > m_generator
Definition
JetHypoExerciserCompareAlg.h:36
JetHypoExerciserCompareAlg::m_agree_false
std::size_t m_agree_false
Definition
JetHypoExerciserCompareAlg.h:49
JetHypoExerciserCompareAlg::m_ncall
std::size_t m_ncall
Definition
JetHypoExerciserCompareAlg.h:46
JetHypoExerciserCompareAlg::initialize_
StatusCode initialize_(const ToolHandle< ITrigJetHypoToolHelper > &, const std::string &)
Definition
JetHypoExerciserCompareAlg.cxx:27
JetTrigTimer
Definition
JetTrigTimer.h:13
xAODJetCollector
Definition
xAODJetCollector.h:20
xAODJetCollector::hypoJets
HypoJetVector hypoJets() const
Definition
xAODJetCollector.cxx:44
lineSplitter
std::vector< std::string > lineSplitter(const std::string &s, char delimiter)
Definition
lineSplitter.cxx:8
lineSplitter.h
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
xAODJetCollector.h
Generated on
for ATLAS Offline Software by
1.17.0