ATLAS Offline Software
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 
27 JetHypoExerciserCompareAlg::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";
69  if(!(sc == StatusCode::SUCCESS)){return sc;}
70 
71  logname = m_logname + "_config1.log";
72  return initialize_(m_helper1, logname);
73 }
74 
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
76 
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 
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 
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 
lineSplitter.h
JetHypoExerciserCompareAlg::m_differ
std::size_t m_differ
Definition: JetHypoExerciserCompareAlg.h:50
JetHypoExerciserCompareAlg::initialize_
StatusCode initialize_(const ToolHandle< ITrigJetHypoToolHelper > &, const std::string &)
Definition: JetHypoExerciserCompareAlg.cxx:27
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TLorentzVectorFactory.h
DebugInfoCollector::toString
virtual std::string toString() const override
Definition: DebugInfoCollector.cxx:70
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
xAODJetCollector::hypoJets
HypoJetVector hypoJets() const
Definition: xAODJetCollector.cxx:44
JetHypoExerciserCompareAlg::execute
StatusCode execute()
Definition: JetHypoExerciserCompareAlg.cxx:136
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
JetHypoExerciserCompareAlg::m_agree_true
std::size_t m_agree_true
Definition: JetHypoExerciserCompareAlg.h:48
HypoJetDefs.h
JetHypoExerciserCompareAlg::execute_
StatusCode execute_(ToolHandle< ITrigJetHypoToolHelper > &, HypoJetVector &, const std::string &collectorName, xAODJetCollector &jetCollector, const std::string &logname, bool &pass)
Definition: JetHypoExerciserCompareAlg.cxx:78
lineSplitter
std::vector< std::string > lineSplitter(const std::string &s, char delimiter)
Definition: lineSplitter.cxx:8
TLorentzVectorAsIJet.h
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
JetHypoExerciserCompareAlg::m_generator
ToolHandle< IHypoJetVectorGenerator > m_generator
Definition: JetHypoExerciserCompareAlg.h:36
JetHypoExerciserCompareAlg::m_differ_jets
std::size_t m_differ_jets
Definition: JetHypoExerciserCompareAlg.h:52
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
JetHypoExerciserCompareAlg::initialize
StatusCode initialize()
Definition: JetHypoExerciserCompareAlg.cxx:64
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
plotBeamSpotCompare.pass1
bool pass1
Definition: plotBeamSpotCompare.py:231
lumiFormat.i
int i
Definition: lumiFormat.py:85
JetHypoExerciserCompareAlg::finalize
StatusCode finalize()
Definition: JetHypoExerciserCompareAlg.cxx:244
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
JetHypoExerciserCompareAlg::m_visitDebug
Gaudi::Property< bool > m_visitDebug
Definition: JetHypoExerciserCompareAlg.h:41
DebugInfoCollector.h
DebugInfoCollector
Definition: DebugInfoCollector.h:13
xAODJetCollector.h
JetHypoExerciserCompareAlg::m_agree_jets
std::size_t m_agree_jets
Definition: JetHypoExerciserCompareAlg.h:51
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
JetHypoExerciserCompareAlg::m_ncall
std::size_t m_ncall
Definition: JetHypoExerciserCompareAlg.h:46
HypoJetVector
std::vector< pHypoJet > HypoJetVector
Definition: HypoJetDefs.h:27
JetHypoExerciserCompareAlg::m_logname
Gaudi::Property< std::string > m_logname
Definition: JetHypoExerciserCompareAlg.h:44
AthAlgorithm
Definition: AthAlgorithm.h:47
JetHypoExerciserCompareAlg::m_helper0
ToolHandle< ITrigJetHypoToolHelper > m_helper0
Definition: JetHypoExerciserCompareAlg.h:30
JetTrigTimer
Definition: JetTrigTimer.h:13
ITrigJetHypoToolHelper.h
JetTrigTimer.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
xAODJetCollector
Definition: xAODJetCollector.h:20
Trig::FeatureAccessImpl::collect
void collect(const HLT::TriggerElement *te, std::vector< Trig::Feature< T > > &data, const std::string &label, unsigned int condition, const std::string &teName, const HLT::TrigNavStructure *navstructure)
actual feature acceess implementation It has (thanks to the ClassTraits) functionality to flatten con...
Definition: FeatureCollectAthena.h:299
JetHypoExerciserCompareAlg::JetHypoExerciserCompareAlg
JetHypoExerciserCompareAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: JetHypoExerciserCompareAlg.cxx:18
ITrigJetHypoInfoCollector::toString
virtual std::string toString() const =0
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42
JetHypoExerciserCompareAlg.h
JetHypoExerciserCompareAlg::m_agree_false
std::size_t m_agree_false
Definition: JetHypoExerciserCompareAlg.h:49
MakeSliceSet.logname
logname
Definition: MakeSliceSet.py:34
JetHypoExerciserCompareAlg::m_helper1
ToolHandle< ITrigJetHypoToolHelper > m_helper1
Definition: JetHypoExerciserCompareAlg.h:33
JetHypoExerciserCompareAlg::~JetHypoExerciserCompareAlg
virtual ~JetHypoExerciserCompareAlg()
Definition: JetHypoExerciserCompareAlg.cxx:23