35 template<
class Map>
void printMap(
const Map&
m) {
36 std::cout<<
"printMap(): [";
37 for (
typename Map::const_iterator
i=
m.begin();
i!=
m.end(); ++
i) {
38 std::cout<<
"("<<
i->first<<
","<<
i->second<<
"), ";
40 std::cout<<
"]"<<std::endl;
47 SubDetPRDs& operator+=(SubDetPRDs&
a,
const SubDetPRDs&
b) {
49 const std::set<Identifier>& bset =
b.subDetHits[
i];
50 for (std::set<Identifier>::const_iterator
pb=bset.begin();
pb!=bset.end(); ++
pb) {
51 a.subDetHits[
i].insert(*
pb);
66 class Sprout :
public std::list<HepMC::ConstGenParticlePtr> {
82 return StatusCode::SUCCESS;
89 const std::vector<const PRD_MultiTruthCollection*>& prdTruth,
90 const EventContext& ctx)
const
92 ATH_MSG_VERBOSE(
"DetailedTrackTruthBuilder::buildDetailedTrackTruth() ");
94 if (!output) {
return; }
103 if (prdTruthColl->empty()) {
110 orderedPRD_Truth[subdet] = prdTruthColl;
121 for (
unsigned itrack=0; itrack<tracks.
size(); ++itrack) {
123 addTrack(output, ptrack, orderedPRD_Truth, inverseTruth, ctx);
129 " Entries with TruthTrajectories of more then one particle shown at the DEBUG level.\n"
130 " Use VERBOSE level for complete dump.");
132 for (DetailedTrackTruthCollection::const_iterator
i=output->begin();
i!=output->end(); ++
i) {
133 bool interesting = (
i->second.trajectory().size() > 1);
136 <<
"out: trk="<<
i->first.index()<<
" => "<<
i->second<<
endmsg;
141 for (
unsigned k=0;
k<
t.size(); ++
k) {
185 class ExtendedEventIndex {
192 m_eventIndex =
source.getEventPositionInCollection(
proxy);
209 const std::vector<const PRD_MultiTruthCollection*>& orderedPRD_Truth,
211 const EventContext& ctx)
const
215 std::map<HepMcParticleLink,SubDetPRDs> pairStat;
247 if (!orderedPRD_Truth[subdet]) {
254 using iprdt = PRD_MultiTruthCollection::const_iterator;
255 std::pair<iprdt, iprdt>
range = orderedPRD_Truth[subdet]->equal_range(
id);
265 if (!
i->second.isValid()) {
266 ATH_MSG_WARNING(
"Unexpected invalid HepMcParticleLink in PRD_MultiTruthCollection");
269 pairStat[
i->second].subDetHits[subdet].insert(
id);
271 ATH_MSG_VERBOSE(
"PRD-ID:"<<
id<<
" subdet:"<<subdet<<
" number:"<<
n<<
" particle link:"<<
i->second);
274 ATH_MSG_VERBOSE(
"--> no link, noise ? PRD-ID:"<<
id<<
" subdet:"<<subdet);
285 for (std::map<HepMcParticleLink,SubDetPRDs>::const_iterator
i=pairStat.begin();
i!=pairStat.end(); ++
i) {
296 std::set<HepMcParticleLink> seeds;
297 for (std::map<HepMcParticleLink,SubDetPRDs>::const_iterator
i=pairStat.begin();
i!=pairStat.end(); ++
i) {
298 if (
i->first.isValid()) {
299 seeds.insert(
i->first);
305 traj.push_back(
i->first);
306 ATH_MSG_VERBOSE(
"addTrack(): add id 0 hits (noise ?) to DetailedTrackTruthCollection.");
314 output->insert(std::make_pair(trackLink,
323 using SproutMap = std::map<HepMcParticleLink, Sprout>;
325 while (!seeds.empty() ) {
328 Sprout current_sprout;
329 std::queue<HepMC::ConstGenParticlePtr>
tmp;
335 unsigned nAncestor{0};
340 if (!nAncestor && !seeds.count(curlink)) {
341 ATH_MSG_WARNING(
"The first link should always point to the object itself.\nHowever "<<
342 link<<
"=="<<curlink<<
"\n evaluates to " <<(curlink==link)<<
", getTruthSuppressionType: "
344 <<
", id:"<<(curlink.
id() == link.
id())
351 seeds.erase(curlink);
355 if (p_old != sprouts.end()) {
357 current_sprout.splice(current_sprout.end(), p_old->second);
358 current_sprout.stat += p_old->second.stat;
360 sprouts.erase(p_old);
369 current_sprout.push_back(
current);
372 if (p_newstat != pairStat.end()) {
373 current_sprout.stat += p_newstat->second;
380 sprouts.insert(std::make_pair(link, current_sprout));
409 for (Sprout::const_iterator ppart=
s->second.begin(); ppart!=
s->second.end(); ++ppart) {
417 output->insert(std::make_pair(trackLink,
419 makeSubDetHitStatistics(
s->second.stat),
425 ATH_MSG_VERBOSE(
"addTrack(): #sprouts = "<<sprouts.size()<<
", output->size() = "<<output->size());
433 for (
const auto&
i : rec2truth ) {
436 auto pa =
i.second.cptr();
446 result.insert(std::make_pair(
i.second,
i.first));
459 for (TruthTrajectory::const_iterator
p = traj.begin();
p != traj.end(); ++
p) {
465 ATH_MSG_WARNING(
"HepMcParticleLink " << *
p <<
" in truth trajectory does not point to a valid GenParticle.");
469 using iter = PRD_InverseTruth::const_iterator;
470 std::pair<iter,iter>
range = inverseTruth.equal_range(*
p);
478 return makeSubDetHitStatistics(prds);