20 m_incidentSvc(
"IncidentSvc",
n),
24 m_thistSvc(
"THistSvc",
n),
27 declareInterface<IMuonTruthSummaryTool>(
this);
49 std::string treePathAndName(
"/");
51 treePathAndName +=
"/";
60 ATH_MSG_WARNING(
"SelectedPdgId should be positive, taking the absolute value");
68 return StatusCode::SUCCESS;
72 ATH_MSG_INFO(
"Of " << m_truthHitsTotal <<
" truth hits in total...");
74 return StatusCode::SUCCESS;
81 m_truthDataPerLevel.clear();
88 if (!
col.isValid() || !
col.isPresent())
continue;
90 PRD_MultiTruthCollection::const_iterator
it =
col->begin();
91 PRD_MultiTruthCollection::const_iterator it_end =
col->end();
92 for (;
it != it_end; ++
it) {
96 m_truthHits[
it->first] = bc;
97 m_pdgIdLookupFromBarcode[bc] = link.
cptr()->pdg_id();
103 ATH_MSG_DEBUG(
" Total collected muon truth hits " << m_truthHits.size());
109 std::scoped_lock lock(
m_mutex);
110 auto pos = m_pdgIdLookupFromBarcode.find(
barcode);
111 if (
pos == m_pdgIdLookupFromBarcode.end())
return 0;
117 std::scoped_lock lock(
m_mutex);
118 auto pos = m_truthHits.find(
id);
119 if (
pos == m_truthHits.end())
return -1;
125 std::scoped_lock lock(
m_mutex);
126 if (m_truthHits.count(
id)) m_truthDataPerLevel[
level].insert(
id);
132 std::scoped_lock lock(
m_mutex);
138 std::scoped_lock lock(
m_mutex);
139 for (std::vector<const Trk::MeasurementBase*>::const_iterator
it = measurements.begin();
it != measurements.end(); ++
it) {
146 std::scoped_lock lock(
m_mutex);
147 if (m_truthHits.empty())
return "Event without truth hits";
148 if (m_truthDataPerLevel.empty())
return "No hits added";
149 std::ostringstream sout;
150 sout <<
"Have " << m_truthHits.size() <<
" truth hits and " << m_truthDataPerLevel.size() <<
" levels filled." << std::endl;
152 std::unordered_set<Identifier, IdentifierHash> truthHits;
153 for (
auto it = m_truthHits.begin();
it != m_truthHits.end(); ++
it) truthHits.insert(
it->first);
155 m_truthHitsTotal += truthHits.size();
156 sout <<
" Summarizing: truth hits " << truthHits.size() <<
" levels filled " << m_truthDataPerLevel.size() << std::endl;
157 for (
auto& pair : m_truthDataPerLevel) {
160 sout <<
" Comparing truth to level " <<
m_level << std::endl <<
printSummary(truthHits, pair.second);
164 std::cout <<
"About to try to fill try tree " <<
m_tree->GetName() << std::endl;
173 const std::unordered_set<Identifier, MuonTruthSummaryTool::IdentifierHash>&
found) {
174 std::scoped_lock lock(
m_mutex);
175 std::ostringstream sout;
176 if (truth.size() !=
found.size()) {
177 sout <<
" Some truth hits not found: truth " << truth.size() <<
" found " <<
found.size() << std::endl;
178 std::set<Identifier> truthset(truth.begin(), truth.end());
179 std::set<Identifier> foundset(
found.begin(),
found.end());
180 std::vector<Identifier>
result(truth.size() -
found.size());
182 std::set_difference(truthset.begin(), truthset.end(), foundset.begin(), foundset.end(),
result.begin());
185 std::map<Identifier, unsigned int> chambers;
186 unsigned int hitNum = 0;
188 sout << hitNum++ <<
":\t" <<
m_idHelperSvc->toString(*
it) << std::endl;
192 if (nmm > 4) sout <<
" possible missing MM segment : " << nmm << std::endl;
194 sout << std::endl <<
"++++ Chamber summaries:" << std::endl;
195 for (
auto chamber : chambers) {
201 sout <<
" All hits found: truth " << truth.size() <<
" found " <<
found.size() << std::endl;
207 std::scoped_lock lock(
m_mutex);
209 ATH_MSG_WARNING(
"Trying to write ntuple, but tree is zero. Setting WriteNtuple to False");
236 std::string leafThing =
name + std::string(
"/i");
261 std::scoped_lock lock(
m_mutex);
276 std::scoped_lock lock(
m_mutex);
278 <<
" numMissedHits=" << numMissedHits);
291 if (inc.type() ==
"EndEvent") {