10 #include "GaudiKernel/ITHistSvc.h"
21 m_incidentSvc(
"IncidentSvc",
n),
28 declareInterface<IMuonTruthSummaryTool>(
this);
50 std::string treePathAndName(
"/");
52 treePathAndName +=
"/";
61 ATH_MSG_WARNING(
"SelectedPdgId should be positive, taking the absolute value");
69 return StatusCode::SUCCESS;
73 ATH_MSG_INFO(
"Of " << m_truthHitsTotal <<
" truth hits in total...");
75 return StatusCode::SUCCESS;
82 m_truthDataPerLevel.clear();
89 if (!
col.isValid() || !
col.isPresent())
continue;
91 PRD_MultiTruthCollection::const_iterator
it =
col->begin();
92 PRD_MultiTruthCollection::const_iterator it_end =
col->end();
93 for (;
it != it_end; ++
it) {
97 m_truthHits[
it->first] = bc;
98 m_pdgIdLookupFromBarcode[bc] = link.
cptr()->pdg_id();
104 ATH_MSG_DEBUG(
" Total collected muon truth hits " << m_truthHits.size());
110 std::scoped_lock lock(
m_mutex);
111 auto pos = m_pdgIdLookupFromBarcode.find(
barcode);
112 if (
pos == m_pdgIdLookupFromBarcode.end())
return 0;
118 std::scoped_lock lock(
m_mutex);
119 auto pos = m_truthHits.find(
id);
120 if (
pos == m_truthHits.end())
return -1;
126 std::scoped_lock lock(
m_mutex);
127 if (m_truthHits.count(
id)) m_truthDataPerLevel[
level].insert(
id);
133 std::scoped_lock lock(
m_mutex);
139 std::scoped_lock lock(
m_mutex);
140 for (std::vector<const Trk::MeasurementBase*>::const_iterator
it = measurements.begin();
it != measurements.end(); ++
it) {
147 std::scoped_lock lock(
m_mutex);
148 if (m_truthHits.empty())
return "Event without truth hits";
149 if (m_truthDataPerLevel.empty())
return "No hits added";
150 std::ostringstream sout;
151 sout <<
"Have " << m_truthHits.size() <<
" truth hits and " << m_truthDataPerLevel.size() <<
" levels filled." << std::endl;
153 std::unordered_set<Identifier, IdentifierHash> truthHits;
154 for (
auto it = m_truthHits.begin();
it != m_truthHits.end(); ++
it) truthHits.insert(
it->first);
156 m_truthHitsTotal += truthHits.size();
157 sout <<
" Summarizing: truth hits " << truthHits.size() <<
" levels filled " << m_truthDataPerLevel.size() << std::endl;
158 for (
auto& pair : m_truthDataPerLevel) {
161 sout <<
" Comparing truth to level " <<
m_level << std::endl <<
printSummary(truthHits, pair.second);
165 std::cout <<
"About to try to fill try tree " <<
m_tree->GetName() << std::endl;
174 const std::unordered_set<Identifier, MuonTruthSummaryTool::IdentifierHash>&
found) {
175 std::scoped_lock lock(
m_mutex);
176 std::ostringstream sout;
177 if (truth.size() !=
found.size()) {
178 sout <<
" Some truth hits not found: truth " << truth.size() <<
" found " <<
found.size() << std::endl;
179 std::set<Identifier> truthset(truth.begin(), truth.end());
180 std::set<Identifier> foundset(
found.begin(),
found.end());
181 std::vector<Identifier>
result(truth.size() -
found.size());
183 std::set_difference(truthset.begin(), truthset.end(), foundset.begin(), foundset.end(),
result.begin());
186 std::map<Identifier, unsigned int> chambers;
187 unsigned int hitNum = 0;
189 sout << hitNum++ <<
":\t" <<
m_idHelperSvc->toString(*
it) << std::endl;
193 if (nmm > 4) sout <<
" possible missing MM segment : " << nmm << std::endl;
195 sout << std::endl <<
"++++ Chamber summaries:" << std::endl;
196 for (
auto chamber : chambers) {
202 sout <<
" All hits found: truth " << truth.size() <<
" found " <<
found.size() << std::endl;
208 std::scoped_lock lock(
m_mutex);
210 ATH_MSG_WARNING(
"Trying to write ntuple, but tree is zero. Setting WriteNtuple to False");
237 std::string leafThing =
name + std::string(
"/i");
262 std::scoped_lock lock(
m_mutex);
277 std::scoped_lock lock(
m_mutex);
279 <<
" numMissedHits=" << numMissedHits);
292 if (inc.type() ==
"EndEvent") {