70 std::vector<const Trk::MeasurementBase*>
meas;
75 template <
class Map>
void printMap(
const Map&
m) {
76 std::cout <<
"printMap(): [";
77 for (
typename Map::const_iterator
i =
m.begin();
i !=
m.end(); ++
i) { std::cout <<
"(" <<
i->first <<
"," <<
i->second <<
"), "; }
78 std::cout <<
"]" << std::endl;
85 SubDetPRDs& operator+=(SubDetPRDs&
a,
const SubDetPRDs&
b) {
87 const std::set<Identifier>& bset =
b.subDetHits[
i];
88 for (std::set<Identifier>::const_iterator
pb = bset.begin();
pb != bset.end(); ++
pb) {
a.subDetHits[
i].insert(*
pb); }
102 class Sprout :
public std::list<HepMC::ConstGenParticlePtr> {
113 const IInterface*
parent) :
115 declareInterface<IDetailedMuonPatternTruthBuilder>(
this);
124 return StatusCode::SUCCESS;
130 const std::vector<const PRD_MultiTruthCollection*>& prdTruth) {
131 ATH_MSG_VERBOSE(
"DetailedMuonPatternTruthBuilder::buildDetailedMuonPatternTruth() ");
141 for (std::vector<const PRD_MultiTruthCollection*>::const_iterator
i = prdTruth.begin();
i != prdTruth.end(); ++
i) {
143 if (!(*i)->empty()) {
147 orderedPRD_Truth[subdet] = *
i;
161 for (
unsigned itrack = 0; itrack <
patterns.size(); itrack++) {
169 "Dumping output collection.\n"
170 " Entries with TruthTrajectories of more then one particle shown at the DEBUG level.\n"
171 " Use VERBOSE level for complete dump.");
173 for (DetailedMuonPatternTruthCollection::const_iterator
i =
output->begin();
i !=
output->end(); ++
i) {
174 bool interesting = (
i->second.trajectory().size() > 1);
193 const std::vector<const PRD_MultiTruthCollection*>& prdTruth) {
194 ATH_MSG_VERBOSE(
"DetailedMuonPatternTruthBuilder::buildDetailedTrackTruth() ");
204 for (std::vector<const PRD_MultiTruthCollection*>::const_iterator
i = prdTruth.begin();
i != prdTruth.end(); ++
i) {
206 if (!(*i)->empty()) {
210 orderedPRD_Truth[subdet] = *
i;
228 "Dumping output collection.\n"
229 " Entries with TruthTrajectories of more then one particle shown at the DEBUG level.\n"
230 " Use VERBOSE level for complete dump.");
272 const std::vector<const PRD_MultiTruthCollection*>& orderedPRD_Truth,
275 std::map<HepMcParticleLink, SubDetPRDs> pairStat;
278 const std::vector<Muon::MuonPatternChamberIntersect>& MPCIV = (*MuPatternCombo)->chamberData();
279 for (
unsigned int i_MPCI = 0; i_MPCI < MPCIV.size(); i_MPCI++) {
280 if (MPCIV.empty())
continue;
283 std::vector<const Trk::PrepRawData*> PRDV = MPCIV.at(i_MPCI).prepRawDataVec();
286 for (
unsigned int j_PRD = 0; j_PRD < PRDV.size(); j_PRD++) {
287 if (PRDV.empty())
continue;
294 if (orderedPRD_Truth[subdet]) {
297 typedef PRD_MultiTruthCollection::const_iterator iprdt;
298 std::pair<iprdt, iprdt>
range = orderedPRD_Truth[subdet]->equal_range(
id);
303 if (!
i->second.isValid()) {
304 ATH_MSG_WARNING(
"Unexpected invalid HepMcParticleLink in PRD_MultiTruthCollection");
306 pairStat[
i->second].subDetHits[subdet].insert(
id);
309 <<
" particle link:" <<
i->second);
313 ATH_MSG_VERBOSE(
"--> no link, noise ? PRD-ID:" <<
id <<
" subdet:" << subdet);
315 unsigned int BC(0), EV(0);
325 for (std::map<HepMcParticleLink, SubDetPRDs>::const_iterator
i = pairStat.begin();
i != pairStat.end(); ++
i) {
334 std::set<HepMcParticleLink> seeds;
335 for (std::map<HepMcParticleLink, SubDetPRDs>::const_iterator
i = pairStat.begin();
i != pairStat.end(); ++
i) {
336 if (
i->first.isValid()) {
337 seeds.insert(
i->first);
342 traj.push_back(
i->first);
356 typedef std::map<HepMcParticleLink, Sprout> SproutMap;
359 while (!seeds.empty()) {
362 Sprout current_sprout;
363 std::queue<HepMC::ConstGenParticlePtr>
tmp;
375 seeds.erase(curlink);
379 if (p_old != sprouts.end()) {
381 current_sprout.splice(current_sprout.end(), p_old->second);
382 current_sprout.stat += p_old->second.stat;
384 sprouts.erase(p_old);
392 current_sprout.push_back(
current);
395 if (p_newstat != pairStat.end()) { current_sprout.stat += p_newstat->second; }
400 sprouts.insert(std::make_pair(link, current_sprout));
426 for (Sprout::const_iterator ppart =
s->second.begin(); ppart !=
s->second.end(); ++ppart) {
431 std::set<Muon::MuonStationIndex::ChIndex> tempSet;
436 std::make_pair(MuPatternCombo,
DetailedTrackTruth(traj, makeSubDetHitStatistics(
s->second.stat), trackStat, truthStat)));
439 ATH_MSG_VERBOSE(
"addTrack(): #sprouts = " << sprouts.size() <<
", output->size() = " <<
output->size());
444 std::set<Muon::MuonStationIndex::ChIndex> chIndices) {
449 for (TruthTrajectory::const_iterator
p = traj.begin();
p != traj.end(); ++
p) {
450 typedef PRD_InverseTruth::const_iterator iter;
451 std::pair<iter, iter>
range = inverseTruth.equal_range(*
p);
453 if (chIndices.find(
m_idHelperSvc->chamberIndex(
i->second)) != chIndices.end()) {
456 prds.subDetHits[subdet].insert(
i->second);
461 return makeSubDetHitStatistics(prds);
466 std::list<HepMC::ConstGenParticlePtr> genPartList,
int truthPos,
467 std::set<Muon::MuonStationIndex::ChIndex> chIndices) {
468 double minPos = 2e8, maxPos = 0;
471 if (genPartList.empty()) {
472 ATH_MSG_WARNING(
"No GenParticles associated to this PRD_TruthTrajectory. Exiting segment creation.");
477 if (!mdtSimDataMap) {
489 if (!stgcSimDataMap) {
496 std::map<Muon::MuonStationIndex::StIndex, DetectorLayer> hitsPerLayer;
497 std::map<const Trk::TrkDetElementBase*, std::pair<std::list<const Trk::PrepRawData*>, std::list<const Trk::PrepRawData*> > >
501 for (
unsigned int i_cROTv = 0; i_cROTv <
segment.numberOfContainedROTs(); i_cROTv++) {
512 if (chIndices.find(
m_idHelperSvc->chamberIndex(
id)) == chIndices.end()) {
513 ATH_MSG_DEBUG(
"Muon station doesn't match segment. Continuing");
543 for (
auto it = genPartList.begin();
it != genPartList.end() && !deposit; ++
it) {
551 Amg::Vector2D lp(deposit->second.firstEntry(), deposit->second.secondEntry());
554 double val = isEndcap ? fabs(gpos.z()) : gpos.perp();
570 if (maxPos < -1e8 && minPos < 1e8) {
576 }
else if (
val > maxPos) {
590 << deposit->second.firstEntry() <<
" pull " <<
pull);
592 detLayer.
meas.push_back(mdt);
600 for (
auto it = genPartList.begin();
it != genPartList.end() && !deposit; ++
it) {
608 Amg::Vector2D lp(deposit->second.firstEntry(), deposit->second.secondEntry());
613 double val = fabs(gpos.z());
628 if (maxPos < -1e8 && detLayer.
minPos < 1e8) {
634 }
else if (
val > maxPos) {
647 <<
" pull " <<
pull);
648 detLayer.
meas.push_back(rot);
660 for (
auto it = genPartList.begin();
it != genPartList.end() && !deposit; ++
it) {
668 Amg::Vector2D lp(deposit->second.firstEntry(), deposit->second.secondEntry());
673 double val = fabs(gpos.z());
688 if (maxPos < -1e8 && minPos < 1e8) {
694 }
else if (
val > maxPos) {
707 <<
" pull " <<
pull);
708 detLayer.
meas.push_back(rot);
715 if (minPos == 2e8 || maxPos == 0) {
716 ATH_MSG_WARNING(
"Min and max positions not found. Filling with meaningless position");
721 return (first3D + last3D) / 2;
724 return (last3D - first3D);
731 const std::vector<const PRD_MultiTruthCollection*>& orderedPRD_Truth,
734 std::map<HepMcParticleLink, SubDetPRDs> pairStat;
737 const std::vector<Muon::MuonPatternChamberIntersect>& MPCIV =
pattern.chamberData();
738 for (
unsigned int i_MPCI = 0; i_MPCI < MPCIV.size(); i_MPCI++) {
739 if (MPCIV.empty())
continue;
742 std::vector<const Trk::PrepRawData*> PRDV = MPCIV.at(i_MPCI).prepRawDataVec();
745 for (
unsigned int j_PRD = 0; j_PRD < PRDV.size(); j_PRD++) {
746 if (PRDV.empty())
continue;
753 if (orderedPRD_Truth[subdet]) {
756 typedef PRD_MultiTruthCollection::const_iterator iprdt;
757 std::pair<iprdt, iprdt>
range = orderedPRD_Truth[subdet]->equal_range(
id);
762 if (!
i->second.isValid()) {
763 ATH_MSG_WARNING(
"Unexpected invalid HepMcParticleLink in PRD_MultiTruthCollection");
765 pairStat[
i->second].subDetHits[subdet].insert(
id);
768 <<
" particle link:" <<
i->second);
772 ATH_MSG_VERBOSE(
"--> no link, noise ? PRD-ID:" <<
id <<
" subdet:" << subdet);
774 unsigned int BC(0), EV(0);
784 for (std::map<HepMcParticleLink, SubDetPRDs>::const_iterator
i = pairStat.begin();
i != pairStat.end(); ++
i) {
794 std::set<HepMcParticleLink> seeds;
795 for (std::map<HepMcParticleLink, SubDetPRDs>::const_iterator
i = pairStat.begin();
i != pairStat.end(); ++
i) {
796 if (
i->first.isValid()) {
797 seeds.insert(
i->first);
802 traj.push_back(
i->first);
816 typedef std::map<HepMcParticleLink, Sprout> SproutMap;
819 while (!seeds.empty()) {
822 Sprout current_sprout;
823 std::queue<HepMC::ConstGenParticlePtr>
tmp;
835 seeds.erase(curlink);
839 if (p_old != sprouts.end()) {
841 current_sprout.splice(current_sprout.end(), p_old->second);
842 current_sprout.stat += p_old->second.stat;
844 sprouts.erase(p_old);
852 current_sprout.push_back(
current);
855 if (p_newstat != pairStat.end()) { current_sprout.stat += p_newstat->second; }
860 sprouts.insert(std::make_pair(link, current_sprout));
885 for (Sprout::const_iterator ppart =
s->second.begin(); ppart !=
s->second.end(); ++ppart) {
890 std::set<Muon::MuonStationIndex::ChIndex> tempSet;
897 ATH_MSG_VERBOSE(
"addTrack(): #sprouts = " << sprouts.size() <<
", output->size() = " <<
output->size());
902 const std::vector<const PRD_MultiTruthCollection*>& prdTruth) {
903 ATH_MSG_VERBOSE(
"DetailedMuonPatternTruthBuilder::buildDetailedTrackTruthFromSegments() ");
913 for (std::vector<const PRD_MultiTruthCollection*>::const_iterator
i = prdTruth.begin();
i != prdTruth.end(); ++
i) {
915 if (!(*i)->empty()) {
919 orderedPRD_Truth[subdet] = *
i;
937 "Dumping output collection.\n"
938 " Entries with TruthTrajectories of more then one particle shown at the DEBUG level.\n"
939 " Use VERBOSE level for complete dump.");
945 const std::vector<const PRD_MultiTruthCollection*>& orderedPRD_Truth,
const PRD_InverseTruth& inverseTruth) {
947 std::map<HepMcParticleLink, SubDetPRDs> pairStat;
949 std::set<Muon::MuonStationIndex::ChIndex> chIndices;
952 for (
unsigned int i_cROTv = 0; i_cROTv <
segment.numberOfContainedROTs(); i_cROTv++) {
965 if (orderedPRD_Truth[subdet]) {
968 typedef PRD_MultiTruthCollection::const_iterator iprdt;
969 std::pair<iprdt, iprdt>
range = orderedPRD_Truth[subdet]->equal_range(
id);
974 if (!
i->second.isValid()) {
975 ATH_MSG_WARNING(
"Unexpected invalid HepMcParticleLink in PRD_MultiTruthCollection");
977 pairStat[
i->second].subDetHits[subdet].insert(
id);
979 ATH_MSG_VERBOSE(
"PRD-ID:" <<
id <<
" subdet:" << subdet <<
" number:" <<
n <<
" particle link:" <<
i->second);
983 ATH_MSG_VERBOSE(
"--> no link, noise ? PRD-ID:" <<
id <<
" subdet:" << subdet);
985 unsigned int BC(0), EV(0);
994 for (std::map<HepMcParticleLink, SubDetPRDs>::const_iterator
i = pairStat.begin();
i != pairStat.end(); ++
i) {
1004 std::set<HepMcParticleLink> seeds;
1005 for (std::map<HepMcParticleLink, SubDetPRDs>::const_iterator
i = pairStat.begin();
i != pairStat.end(); ++
i) {
1006 if (
i->first.isValid()) {
1007 seeds.insert(
i->first);
1012 traj.push_back(
i->first);
1027 typedef std::map<HepMcParticleLink, Sprout> SproutMap;
1030 while (!seeds.empty()) {
1033 Sprout current_sprout;
1034 std::queue<HepMC::ConstGenParticlePtr>
tmp;
1046 seeds.erase(curlink);
1050 if (p_old != sprouts.end()) {
1052 current_sprout.splice(current_sprout.end(), p_old->second);
1053 current_sprout.stat += p_old->second.stat;
1055 sprouts.erase(p_old);
1063 current_sprout.push_back(
current);
1066 if (p_newstat != pairStat.end()) { current_sprout.stat += p_newstat->second; }
1071 sprouts.insert(std::make_pair(link, current_sprout));
1096 for (Sprout::const_iterator ppart =
s->second.begin(); ppart !=
s->second.end(); ++ppart) {
1109 ATH_MSG_VERBOSE(
"addTrack(): #sprouts = " << sprouts.size() <<
", output->size() = " <<
output->size());
1115 MuonSimDataCollection::const_iterator
it = simCol.find(
id);
1116 if (
it == simCol.end()) {
1123 std::vector<MuonSimData::Deposit>::const_iterator dit =
simData.getdeposits().begin();
1124 std::vector<MuonSimData::Deposit>::const_iterator dit_end =
simData.getdeposits().end();
1125 for (; dit != dit_end; ++dit) {
1131 if (gp == genPart) {
1142 if (!
evtStore()->contains<MuonSimDataCollection>(colName))
return nullptr;
1146 ATH_MSG_VERBOSE(
"Could NOT find the MuonSimDataMap map key = " << colName);
1148 ATH_MSG_VERBOSE(
"Retrieved MuonSimDataCollection for key = " << colName);