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() ");
133 if (!output) {
return; }
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++) {
163 addTrack(output, ptrack, orderedPRD_Truth, inverseTruth);
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);
182 msg(MSG::VERBOSE) <<
"Particles on the trajectory:\n";
183 for (
unsigned k = 0; k < t.size(); ++k) {
msg(MSG::VERBOSE) << t[k] <<
"\n"; }
193 const std::vector<const PRD_MultiTruthCollection*>& prdTruth) {
194 ATH_MSG_VERBOSE(
"DetailedMuonPatternTruthBuilder::buildDetailedTrackTruth() ");
196 if (!output) {
return; }
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);
302 for (iprdt i = range.first; i != range.second; ++i) {
303 if (!i->second.isValid()) {
304 ATH_MSG_WARNING(
"Unexpected invalid HepMcParticleLink in PRD_MultiTruthCollection");
306 pairStat[i->second].subDetHits[subdet].insert(
id);
308 ATH_MSG_VERBOSE(
"PRD-ID:" <<
id <<
" subdet:" << subdet <<
" number:" << n
309 <<
" particle link:" << i->second);
313 ATH_MSG_VERBOSE(
"--> no link, noise ? PRD-ID:" <<
id <<
" subdet:" << subdet);
315 unsigned int ID(0), EV(0);
323 if (
msgLvl(MSG::VERBOSE)) {
324 msg(MSG::VERBOSE) <<
"PRD truth particles = ";
325 for (std::map<HepMcParticleLink, SubDetPRDs>::const_iterator i = pairStat.begin(); i != pairStat.end(); ++i) {
326 msg(MSG::VERBOSE) << i->first <<
",";
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);
351 output->insert(std::make_pair(MuPatternCombo,
DetailedTrackTruth(traj, noiseStat, trackStat, noiseStat)));
356 typedef std::map<HepMcParticleLink, Sprout> SproutMap;
359 while (!seeds.empty()) {
362 Sprout current_sprout;
363 std::queue<HepMC::ConstGenParticlePtr> tmp;
364 unsigned eventIndex = link.eventIndex();
370 seeds.erase(curlink);
373 SproutMap::iterator p_old = sprouts.find(curlink);
374 if (p_old != sprouts.end()) {
376 current_sprout.splice(current_sprout.end(), p_old->second);
377 current_sprout.stat += p_old->second.stat;
379 sprouts.erase(p_old);
387 current_sprout.push_back(current);
389 std::map<HepMcParticleLink, SubDetPRDs>::iterator p_newstat = pairStat.find(curlink);
390 if (p_newstat != pairStat.end()) { current_sprout.stat += p_newstat->second; }
395 sprouts.insert(std::make_pair(link, current_sprout));
409 for (SproutMap::iterator s = sprouts.begin(); s != sprouts.end(); ++s) {
415 while ((current =
m_truthTrackBuilder->getDaughter(current))) { s->second.push_front(current); }
421 for (Sprout::const_iterator ppart = s->second.begin(); ppart != s->second.end(); ++ppart) {
426 std::set<Muon::MuonStationIndex::ChIndex> tempSet;
431 std::make_pair(MuPatternCombo,
DetailedTrackTruth(traj, makeSubDetHitStatistics(s->second.stat), trackStat, truthStat)));
434 ATH_MSG_VERBOSE(
"addTrack(): #sprouts = " << sprouts.size() <<
", output->size() = " << output->size());
439 std::set<Muon::MuonStationIndex::ChIndex> chIndices) {
444 for (TruthTrajectory::const_iterator p = traj.begin(); p != traj.end(); ++p) {
445 typedef PRD_InverseTruth::const_iterator iter;
446 std::pair<iter, iter> range = inverseTruth.equal_range(*p);
447 for (iter i = range.first; i != range.second; ++i) {
448 if (chIndices.find(
m_idHelperSvc->chamberIndex(i->second)) != chIndices.end()) {
451 prds.subDetHits[subdet].insert(i->second);
456 return makeSubDetHitStatistics(prds);
461 std::list<HepMC::ConstGenParticlePtr> genPartList,
int truthPos,
462 std::set<Muon::MuonStationIndex::ChIndex> chIndices) {
463 double minPos = 2e8, maxPos = 0;
466 if (genPartList.empty()) {
467 ATH_MSG_WARNING(
"No GenParticles associated to this PRD_TruthTrajectory. Exiting segment creation.");
472 if (!mdtSimDataMap) {
484 if (!stgcSimDataMap) {
491 std::map<Muon::MuonStationIndex::StIndex, DetectorLayer> hitsPerLayer;
492 std::map<const Trk::TrkDetElementBase*, std::pair<std::list<const Trk::PrepRawData*>, std::list<const Trk::PrepRawData*> > >
507 if (chIndices.find(
m_idHelperSvc->chamberIndex(
id)) == chIndices.end()) {
508 ATH_MSG_DEBUG(
"Muon station doesn't match segment. Continuing");
516 stIndex = Muon::MuonStationIndex::StIndex::EI;
521 stIndex = Muon::MuonStationIndex::StIndex::EI;
538 for (
auto it = genPartList.begin(); it != genPartList.end() && !deposit; ++it) {
539 deposit =
getDeposit(*mdtSimDataMap, *it,
id);
546 Amg::Vector2D lp(deposit->second.firstEntry(), deposit->second.secondEntry());
549 double val = isEndcap ? fabs(gpos.z()) : gpos.perp();
552 if (val < detLayer.
minPos) {
559 }
else if (val > detLayer.
maxPos) {
565 if (maxPos < -1e8 && minPos < 1e8) {
571 }
else if (val > maxPos) {
585 << deposit->second.firstEntry() <<
" pull " << pull);
587 detLayer.
meas.push_back(mdt);
595 for (
auto it = genPartList.begin(); it != genPartList.end() && !deposit; ++it) {
603 Amg::Vector2D lp(deposit->second.firstEntry(), deposit->second.secondEntry());
608 double val = fabs(gpos.z());
610 if (val < detLayer.
minPos) {
617 }
else if (val > detLayer.
maxPos) {
623 if (maxPos < -1e8 && detLayer.
minPos < 1e8) {
629 }
else if (val > maxPos) {
642 <<
" pull " << pull);
643 detLayer.
meas.push_back(rot);
655 for (
auto it = genPartList.begin(); it != genPartList.end() && !deposit; ++it) {
656 deposit =
getDeposit(*stgcSimDataMap, *it,
id);
663 Amg::Vector2D lp(deposit->second.firstEntry(), deposit->second.secondEntry());
668 double val = fabs(gpos.z());
670 if (val < detLayer.
minPos) {
677 }
else if (val > detLayer.
maxPos) {
683 if (maxPos < -1e8 && minPos < 1e8) {
689 }
else if (val > maxPos) {
702 <<
" pull " << pull);
703 detLayer.
meas.push_back(rot);
710 if (minPos == 2e8 || maxPos == 0) {
711 ATH_MSG_WARNING(
"Min and max positions not found. Filling with meaningless position");
716 return (first3D + last3D) / 2;
719 return (last3D - first3D);
726 const std::vector<const PRD_MultiTruthCollection*>& orderedPRD_Truth,
729 std::map<HepMcParticleLink, SubDetPRDs> pairStat;
732 const std::vector<Muon::MuonPatternChamberIntersect>& MPCIV = pattern.chamberData();
733 for (
unsigned int i_MPCI = 0; i_MPCI < MPCIV.size(); i_MPCI++) {
734 if (MPCIV.empty())
continue;
737 std::vector<const Trk::PrepRawData*> PRDV = MPCIV.at(i_MPCI).prepRawDataVec();
740 for (
unsigned int j_PRD = 0; j_PRD < PRDV.size(); j_PRD++) {
741 if (PRDV.empty())
continue;
748 if (orderedPRD_Truth[subdet]) {
751 typedef PRD_MultiTruthCollection::const_iterator iprdt;
752 std::pair<iprdt, iprdt> range = orderedPRD_Truth[subdet]->equal_range(
id);
756 for (iprdt i = range.first; i != range.second; ++i) {
757 if (!i->second.isValid()) {
758 ATH_MSG_WARNING(
"Unexpected invalid HepMcParticleLink in PRD_MultiTruthCollection");
760 pairStat[i->second].subDetHits[subdet].insert(
id);
762 ATH_MSG_VERBOSE(
"PRD-ID:" <<
id <<
" subdet:" << subdet <<
" number:" << n
763 <<
" particle link:" << i->second);
767 ATH_MSG_VERBOSE(
"--> no link, noise ? PRD-ID:" <<
id <<
" subdet:" << subdet);
769 unsigned int ID(0), EV(0);
777 if (
msgLvl(MSG::VERBOSE)) {
778 msg(MSG::VERBOSE) <<
"PRD truth particles = ";
779 for (std::map<HepMcParticleLink, SubDetPRDs>::const_iterator i = pairStat.begin(); i != pairStat.end(); ++i) {
780 msg(MSG::VERBOSE) << i->first <<
",";
789 std::set<HepMcParticleLink> seeds;
790 for (std::map<HepMcParticleLink, SubDetPRDs>::const_iterator i = pairStat.begin(); i != pairStat.end(); ++i) {
791 if (i->first.isValid()) {
792 seeds.insert(i->first);
797 traj.push_back(i->first);
811 typedef std::map<HepMcParticleLink, Sprout> SproutMap;
814 while (!seeds.empty()) {
817 Sprout current_sprout;
818 std::queue<HepMC::ConstGenParticlePtr> tmp;
819 unsigned eventIndex = link.eventIndex();
825 seeds.erase(curlink);
828 SproutMap::iterator p_old = sprouts.find(curlink);
829 if (p_old != sprouts.end()) {
831 current_sprout.splice(current_sprout.end(), p_old->second);
832 current_sprout.stat += p_old->second.stat;
834 sprouts.erase(p_old);
842 current_sprout.push_back(current);
844 std::map<HepMcParticleLink, SubDetPRDs>::iterator p_newstat = pairStat.find(curlink);
845 if (p_newstat != pairStat.end()) { current_sprout.stat += p_newstat->second; }
850 sprouts.insert(std::make_pair(link, current_sprout));
863 for (SproutMap::iterator s = sprouts.begin(); s != sprouts.end(); ++s) {
869 while ((current =
m_truthTrackBuilder->getDaughter(current))) { s->second.push_front(current); }
875 for (Sprout::const_iterator ppart = s->second.begin(); ppart != s->second.end(); ++ppart) {
880 std::set<Muon::MuonStationIndex::ChIndex> tempSet;
884 output->push_back(
DetailedTrackTruth(traj, makeSubDetHitStatistics(s->second.stat), trackStat, truthStat));
887 ATH_MSG_VERBOSE(
"addTrack(): #sprouts = " << sprouts.size() <<
", output->size() = " << output->size());
892 const std::vector<const PRD_MultiTruthCollection*>& prdTruth) {
893 ATH_MSG_VERBOSE(
"DetailedMuonPatternTruthBuilder::buildDetailedTrackTruthFromSegments() ");
895 if (!output) {
return; }
903 for (std::vector<const PRD_MultiTruthCollection*>::const_iterator i = prdTruth.begin(); i != prdTruth.end(); ++i) {
905 if (!(*i)->empty()) {
909 orderedPRD_Truth[subdet] = *i;
927 "Dumping output collection.\n"
928 " Entries with TruthTrajectories of more then one particle shown at the DEBUG level.\n"
929 " Use VERBOSE level for complete dump.");
935 const std::vector<const PRD_MultiTruthCollection*>& orderedPRD_Truth,
const PRD_InverseTruth& inverseTruth) {
937 std::map<HepMcParticleLink, SubDetPRDs> pairStat;
939 std::set<Muon::MuonStationIndex::ChIndex> chIndices;
955 if (orderedPRD_Truth[subdet]) {
958 typedef PRD_MultiTruthCollection::const_iterator iprdt;
959 std::pair<iprdt, iprdt> range = orderedPRD_Truth[subdet]->equal_range(
id);
963 for (iprdt i = range.first; i != range.second; ++i) {
964 if (!i->second.isValid()) {
965 ATH_MSG_WARNING(
"Unexpected invalid HepMcParticleLink in PRD_MultiTruthCollection");
967 pairStat[i->second].subDetHits[subdet].insert(
id);
969 ATH_MSG_VERBOSE(
"PRD-ID:" <<
id <<
" subdet:" << subdet <<
" number:" << n <<
" particle link:" << i->second);
973 ATH_MSG_VERBOSE(
"--> no link, noise ? PRD-ID:" <<
id <<
" subdet:" << subdet);
975 unsigned int ID(0), EV(0);
982 if (
msgLvl(MSG::VERBOSE)) {
983 msg(MSG::VERBOSE) <<
"PRD truth particles = ";
984 for (std::map<HepMcParticleLink, SubDetPRDs>::const_iterator i = pairStat.begin(); i != pairStat.end(); ++i) {
985 msg(MSG::VERBOSE) << i->first <<
",";
994 std::set<HepMcParticleLink> seeds;
995 for (std::map<HepMcParticleLink, SubDetPRDs>::const_iterator i = pairStat.begin(); i != pairStat.end(); ++i) {
996 if (i->first.isValid()) {
997 seeds.insert(i->first);
1002 traj.push_back(i->first);
1017 typedef std::map<HepMcParticleLink, Sprout> SproutMap;
1020 while (!seeds.empty()) {
1023 Sprout current_sprout;
1024 std::queue<HepMC::ConstGenParticlePtr> tmp;
1025 unsigned eventIndex = link.eventIndex();
1032 seeds.erase(curlink);
1035 SproutMap::iterator p_old = sprouts.find(curlink);
1036 if (p_old != sprouts.end()) {
1038 current_sprout.splice(current_sprout.end(), p_old->second);
1039 current_sprout.stat += p_old->second.stat;
1041 sprouts.erase(p_old);
1049 current_sprout.push_back(current);
1051 std::map<HepMcParticleLink, SubDetPRDs>::iterator p_newstat = pairStat.find(curlink);
1052 if (p_newstat != pairStat.end()) { current_sprout.stat += p_newstat->second; }
1057 sprouts.insert(std::make_pair(link, current_sprout));
1070 for (SproutMap::iterator s = sprouts.begin(); s != sprouts.end(); ++s) {
1076 while ((current =
m_truthTrackBuilder->getDaughter(current))) { s->second.push_front(current); }
1082 for (Sprout::const_iterator ppart = s->second.begin(); ppart != s->second.end(); ++ppart) {
1092 output->push_back(
DetailedSegmentTruth(traj, makeSubDetHitStatistics(s->second.stat), trackStat, truthStat, pos, dir));
1095 ATH_MSG_VERBOSE(
"addTrack(): #sprouts = " << sprouts.size() <<
", output->size() = " << output->size());
1101 MuonSimDataCollection::const_iterator it = simCol.find(
id);
1102 if (it == simCol.end()) {
1109 std::vector<MuonSimData::Deposit>::const_iterator dit =
simData.getdeposits().begin();
1110 std::vector<MuonSimData::Deposit>::const_iterator dit_end =
simData.getdeposits().end();
1111 for (; dit != dit_end; ++dit) {
1113 if (gp == genPart) {
1127 if (!
evtStore()->retrieve(truthCol, colName).isSuccess()) {
1128 ATH_MSG_VERBOSE(
"Could NOT find the MuonSimDataMap map key = " << colName);
1130 ATH_MSG_VERBOSE(
"Retrieved MuonSimDataCollection for key = " << colName);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
An STL vector of pointers that by default owns its pointed-to elements.
std::pair< std::vector< unsigned int >, bool > res
DataVector< Muon::MuonPatternCombination > MuonPatternCombinationCollection
This typedef represents a collection of MuonPatternCombination objects.
size_t size() const
Number of registered mappings.
ServiceHandle< StoreGateSvc > & evtStore()
bool msgLvl(const MSG::Level lvl) const
ElementLink implementation for ROOT usage.
a link optimized in size for a GenParticle in a McEventCollection
std::pair< HepMcParticleLink, MuonMCData > Deposit
Class to represent MM measurements.
This class represents the corrected MDT measurements, where the corrections include the effects of wi...
double driftRadius() const
Returns the value of the drift radius.
Class to represent measurements from the Monitored Drift Tubes.
Base class for Muon cluster RIO_OnTracks.
The MuonPatternCombination class provides the means to store the output of the initial global pattern...
This is the common class for 3D segments used in the muon spectrometer.
const Trk::RIO_OnTrack * rioOnTrack(unsigned int) const
returns the RIO_OnTrack (also known as ROT) objects depending on the integer
unsigned int numberOfContainedROTs() const
number of RIO_OnTracks
Class to represent sTgc measurements.
virtual StatusCode initialize()
virtual void buildDetailedMuonPatternTruth(DetailedMuonPatternTruthCollection *output, const MuonPatternCombinationCollection &tracks, const std::vector< const PRD_MultiTruthCollection * > &prdTruth)
See description for IDetailedMuonPatternTruthBuilder::buildDetailedTrackTruth().
InverseMultiMap< PRD_MultiTruthCollection > PRD_InverseTruth
const MuonSimDataCollection * retrieveTruthCollection(const std::string &colName)
SubDetHitStatistics::SubDetType findSubDetType(Identifier id)
void addDetailedTrackTruth(std::vector< DetailedTrackTruth > *output, const Muon::MuonPatternCombination &pattern, const std::vector< const PRD_MultiTruthCollection * > &orderedPRD_Truth, const PRD_InverseTruth &inverseTruth)
Amg::Vector3D getPRDTruthPosition(const Muon::MuonSegment &segment, std::list< HepMC::ConstGenParticlePtr > genPartList, int truthPos, std::set< Muon::MuonStationIndex::ChIndex > chIndices)
void addTrack(DetailedMuonPatternTruthCollection *output, const ElementLink< DataVector< Muon::MuonPatternCombination > > &track, const std::vector< const PRD_MultiTruthCollection * > &orderedPRD_Truth, const PRD_InverseTruth &inverseTruth)
void buildDetailedTrackTruthFromSegments(std::vector< DetailedSegmentTruth > *output, const Muon::MuonSegment &segment, const std::vector< const PRD_MultiTruthCollection * > &prdTruth)
ToolHandle< Muon::IMuonClusterOnTrackCreator > m_muonClusterCreator
SubDetHitStatistics countPRDsOnTruth(const TruthTrajectory &traj, const PRD_InverseTruth &inverseTruth, std::set< Muon::MuonStationIndex::ChIndex > chIndices)
ToolHandle< Trk::ITruthTrajectoryBuilder > m_truthTrackBuilder
void addDetailedTrackTruthFromSegment(std::vector< DetailedSegmentTruth > *output, const Muon::MuonSegment &segment, const std::vector< const PRD_MultiTruthCollection * > &orderedPRD_Truth, const PRD_InverseTruth &inverseTruth)
DetailedMuonPatternTruthBuilder(const std::string &type, const std::string &name, const IInterface *parent)
virtual void buildDetailedTrackTruth(std::vector< DetailedTrackTruth > *output, const Muon::MuonPatternCombination &pattern, const std::vector< const PRD_MultiTruthCollection * > &prdTruth)
ToolHandle< Muon::IMdtDriftCircleOnTrackCreator > m_mdtCreator
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
const MuonSimData::Deposit * getDeposit(const MuonSimDataCollection &simCol, const HepMC::ConstGenParticlePtr &genPart, const Identifier &id)
double get(ParamDefs par) const
Retrieve specified parameter (const version).
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
virtual const TrkDetElementBase * detectorElement() const =0
return the detector element corresponding to this PRD The pointer will be zero if the det el is not d...
Identifier identify() const
return the identifier
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
virtual void localToGlobal(const Amg::Vector2D &locp, const Amg::Vector3D &mom, Amg::Vector3D &glob) const =0
Specified by each surface type: LocalToGlobal method without dynamic memory allocation.
virtual const Surface & surface() const =0
Return surface associated with this detector element.
A TruthTrajectory is a chain of charged MC particles connected through the mother-daughter relationsh...
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
std::vector< std::string > patterns
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
StIndex
enum to classify the different station layers in the muon spectrometer
Ensure that the ATLAS eigen extensions are properly loaded.
DriftCircleSide
Enumerates the 'side' of the wire on which the tracks passed (i.e.
@ RIGHT
the drift radius is positive (see Trk::AtaStraightLine)
@ LEFT
the drift radius is negative (see Trk::AtaStraightLine)
void addToInverseMultiMap(InverseMultiMap< OrigMap, CmpT > *result, const OrigMap &rec2truth)
std::vector< const Trk::MeasurementBase * > meas
Muon::MuonStationIndex::StIndex stIndex