41 {
42
43 SG::WriteDecorHandle<xAOD::MuonSegmentContainer, ElementLink<xAOD::MuonSegmentContainer> > muonTruthSegments(
46 ctx);
47 if (!muonTruthSegments.isPresent()) {
49 return StatusCode::SUCCESS;
50 }
51 if (!segments.isPresent()) {
53 return StatusCode::SUCCESS;
54 }
55 if (!muonTruthSegments.isValid()) {
57 return StatusCode::FAILURE;
58 }
59 if (!segments.isValid()) {
61 return StatusCode::FAILURE;
62 }
63 SG::ReadHandle<TrackRecordCollection> truthTrackCol(
m_trackRecord, ctx);
64 if (!truthTrackCol.isValid()) {
66 return StatusCode::FAILURE;
67 }
68 if (truthTrackCol->empty()) {
70 return StatusCode::SUCCESS;
71 }
72
74 auto ppos = truthSegmentContainerName.find('.');
75 truthSegmentContainerName.resize(std::min(ppos,truthSegmentContainerName.size()));
77 ppos = segmentCollectionName.find('.');
78 segmentCollectionName.resize(std::min(ppos,segmentCollectionName.size()));
79
80 std::vector<const Muon::MuonSegment*> muonSegments;
81 typedef std::map<const Muon::MuonSegment*, ElementLink<xAOD::MuonSegmentContainer> > MuonSegmentLinkMap;
82 MuonSegmentLinkMap muonSegmentLinkMap;
83 unsigned int segIndex = 0;
84 muonSegments.reserve(segments->size());
85 for (const auto *const seg : *segments) {
86 segments(*seg) = ElementLink<xAOD::MuonSegmentContainer>();
87 if (seg->muonSegment().isValid()) {
88 const Muon::MuonSegment* mseg = dynamic_cast<const Muon::MuonSegment*>(*seg->muonSegment());
89 if (mseg) {
91 muonSegments.push_back(mseg);
92 muonSegmentLinkMap[mseg] = ElementLink<xAOD::MuonSegmentContainer>(segmentCollectionName, segIndex);
93 }
94 }
95 ++segIndex;
96 }
97
98 SG::ReadHandle<McEventCollection> mcEventCollection(
m_mcEventColl, ctx);
99 std::vector<const MuonSimDataCollection*> muonSimData;
100 for (SG::ReadHandle<MuonSimDataCollection>& simDataMap :
m_muonSimData.makeHandles(ctx)) {
101 if (!simDataMap.isValid()) {
103 continue;
104 }
105 if (!simDataMap.isPresent()) continue;
106 muonSimData.push_back(simDataMap.cptr());
107 }
110 SG::ReadHandle<CscSimDataCollection> cscSimDataMap(
m_cscSimData, ctx);
111 if (!cscSimDataMap.isValid()) {
114 } else {
116 cscSimDataMap.cptr());
117 }
118 } else {
120 }
121 ATH_MSG_DEBUG(
"Matching reconstructed segments " << muonSegments.size());
123
124
125 std::map<Muon::MuonStationIndex::ChIndex, std::vector<ElementLink<xAOD::MuonSegmentContainer> > > chamberTruthSegmentLinks;
126 segIndex = 0;
127 for (const auto *const truthSegment : *muonTruthSegments) {
128 muonTruthSegments(*truthSegment) = ElementLink<xAOD::MuonSegmentContainer>();
129 std::vector<ElementLink<xAOD::MuonSegmentContainer> >& linkVec = chamberTruthSegmentLinks[truthSegment->chamberIndex()];
130 linkVec.emplace_back(truthSegmentContainerName, segIndex);
132 << " nlinks " << linkVec.size() << " link " << *linkVec.back());
133 ++segIndex;
134 }
135
136
138 std::set<Muon::MuonStationIndex::ChIndex> chambers;
139 std::vector<std::pair<Muon::MuonStationIndex::ChIndex, const TrackRecord*> > chamberTruthVec;
140 for (const auto& result : segmentMatchResult) {
141
143 if (!
result.second.truthTrack)
continue;
145
146
148 if (!
result.second.mdts.matchedHits.empty())
id = *
result.second.mdts.matchedHits.begin();
149 if (!
result.second.cscs.matchedHits.empty())
id = *
result.second.cscs.matchedHits.begin();
150 if (!
result.second.stgcs.matchedHits.empty())
id = *
result.second.stgcs.matchedHits.begin();
151 if (!
result.second.mms.matchedHits.empty())
id = *
result.second.mms.matchedHits.begin();
152 if (!id.is_valid()) continue;
153
156
159
160 for (const auto& index : chamberTruthVec) {
161
165 break;
166 }
167 }
169 }
170
171 std::pair<Muon::MuonStationIndex::ChIndex, const TrackRecord*> chPair;
173 chPair.second =
result.second.truthTrack;
174 chamberTruthVec.push_back(chPair);
175
176
177 auto segPos = muonSegmentLinkMap.find(
result.first);
178 if (segPos == muonSegmentLinkMap.end()) {
180 continue;
181 }
182 ElementLink<xAOD::MuonSegmentContainer> recoLink = segPos->second;
184 if (!recoLink) {
186 continue;
187 }
189
190 auto truthPos = chamberTruthSegmentLinks.find(
chIndex);
191 if (truthPos == chamberTruthSegmentLinks.end()) continue;
193 << truthPos->second.size());
194
195 for (auto& truthSegLink : truthPos->second) {
196
197 truthSegLink.toPersistent();
199 if (!truthSegment) {
201 continue;
202 }
204 static const SG::ConstAccessor<ElementLink<xAOD::TruthParticleContainer> >
205 truthParticleLinkAcc("truthParticleLink");
206 if (!truthParticleLinkAcc.isAvailable(*truthSegment)) {
208 continue;
209 }
210 ElementLink<xAOD::TruthParticleContainer> truthLink =
211 truthParticleLinkAcc(*truthSegment);
213 if (!truthParticle) {
215 continue;
216 }
217
219 ATH_MSG_DEBUG(
"Matched reconstructed segment: barcode " << barcode <<
" layer "
223 muonTruthSegments(*truthSegment) = recoLink;
224 segments(*recoSegment) = truthSegLink;
225 } else {
227 }
228 }
229 }
230 return StatusCode::SUCCESS;
231 }
#define ATH_MSG_WARNING(x)
bool toPersistent()
Dummy function provinding the offline interface.
ToolHandle< Muon::IMuonTrackTruthTool > m_muonTrackTruthTool
SG::WriteDecorHandleKey< xAOD::MuonSegmentContainer > m_muonSegmentCollectionName
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::ReadHandleKeyArray< MuonSimDataCollection > m_muonSimData
PublicToolHandle< Muon::MuonEDMPrinterTool > m_printer
SG::ReadHandleKey< McEventCollection > m_mcEventColl
SG::ReadHandleKey< CscSimDataCollection > m_cscSimData
SG::WriteDecorHandleKey< xAOD::MuonSegmentContainer > m_muonTruthSegmentContainerName
SG::ReadHandleKey< TrackRecordCollection > m_trackRecord
bool is_sim_descendant(const T1 &p1, const T2 &p2)
Method to check if the first particle is a descendant of the second in the simulation,...
ChIndex chIndex(const std::string &index)
convert ChIndex name string to enum
const std::string & chName(ChIndex index)
convert ChIndex into a string
ChIndex
enum to classify the different chamber layers in the muon spectrometer
TruthParticle_v1 TruthParticle
Typedef to implementation.
MuonSegment_v1 MuonSegment
Reference the current persistent version: