ATLAS Offline Software
Loading...
Searching...
No Matches
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
14
15#include <fstream>
16#include <sstream>
17
19 ISvcLocator* pSvcLocator) :
20 AthAlgorithm(name, pSvcLocator){
21}
22
24
25
26StatusCode
27JetHypoExerciserCompareAlg::initialize_(const ToolHandle<ITrigJetHypoToolHelper>& helper,
28 const std::string& logname) {
29
30 ATH_MSG_INFO ("initialize_()");
31
33 (" " << helper.propertyName()
34 << " = " << helper.type());
35
36 if ( helper.retrieve().isFailure() ) {
38 (helper.propertyName() << ": Failed to retrieve tool "
39 << helper.type());
40 return StatusCode::FAILURE;
41 } else {
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
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
77StatusCode
78JetHypoExerciserCompareAlg::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
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 {
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 {
230 }
231 } else {
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
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define CHECK(...)
Evaluate an expression and check for errors.
std::vector< pHypoJet > HypoJetVector
Definition HypoJetDefs.h:27
static Double_t ss
static Double_t sc
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
virtual std::string toString() const override
ToolHandle< ITrigJetHypoToolHelper > m_helper0
ToolHandle< ITrigJetHypoToolHelper > m_helper1
JetHypoExerciserCompareAlg(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode execute_(ToolHandle< ITrigJetHypoToolHelper > &, HypoJetVector &, const std::string &collectorName, xAODJetCollector &jetCollector, const std::string &logname, bool &pass)
Gaudi::Property< std::string > m_logname
ToolHandle< IHypoJetVectorGenerator > m_generator
StatusCode initialize_(const ToolHandle< ITrigJetHypoToolHelper > &, const std::string &)
HypoJetVector hypoJets() const
std::vector< std::string > lineSplitter(const std::string &s, char delimiter)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.