Patch for STACO muons: Copy the truth information from the muon back to the combined track to avoid file corruptions reported in ATLASRECTS-6454
one more thing: need to have muonlink set for all truth particles to avoid ELReset errors
91 {
94 std::unique_ptr<SG::WriteDecorHandle<xAOD::TruthParticleContainer, ElementLink<xAOD::MuonContainer>>> muonTruthParticleRecoLink{};
96 muonTruthParticleRecoLink = std::make_unique<SG::WriteDecorHandle<xAOD::TruthParticleContainer, ElementLink<xAOD::MuonContainer>>>(
m_muonTruthRecoLink, ctx);
97 }
98
99 SG::WriteDecorHandle<xAOD::MuonContainer, ElementLink<xAOD::TruthParticleContainer> > muonTruthParticleLink(
m_muonTruthParticleLink,
100 ctx);
101 if (!muonTruthParticleLink.isValid()) {
103 return StatusCode::FAILURE;
104 }
109 ctx);
112
113
114 bool saw_staco = false;
115 bool decor_staco = false;
116
117
118 for (
const xAOD::Muon* muon : *muonTruthParticleLink) {
119
120
125
126 using enum xAOD::Muon::TrackParticleType;
127 tp =
muon->trackParticle(useID ?InnerDetectorTrackParticle : Primary);
128
129 bool foundTruth{false}, setOrigin{false};
130 if (tp) {
131
132
133
134 if (acc_origin.isAvailable(*tp) && acc_origin(*tp) != 0) {
135 muonTruthParticleOrigin(*muon) = acc_origin(*tp);
136 muonTruthParticleType(*muon) = acc_type(*tp);
137 muonTruthParticleClassification(*muon) = acc_classification(*tp);
138 setOrigin = true;
139 }
140
141 ElementLink<xAOD::TruthParticleContainer> truthLink;
142 if (acc_link.isAvailable(*tp)) {
143 truthLink = acc_link(*tp);
144 } else {
145 ATH_MSG_DEBUG(
"Could not find any truth link associated with track having pt:"<<tp->
pt()<<
" MeV, eta: "<<tp->
eta()<<
", phi: "<<tp->
phi()<<
", charge: "<<tp->
charge()<<
". d0:"<<tp->
d0()<<
", z0: "<<tp->
z0());
146 }
147
150
157 continue;
158 }
160 foundTruth = true;
162 ElementLink<xAOD::TruthParticleContainer> muonTruthLink{*muonTruthContainer,
163 truthParticle->index(),
164 ctx};
166 muonTruthParticleLink(*muon) = muonTruthLink;
167 if (!setOrigin) {
168 muonTruthParticleOrigin(*muon) = acc_origin(*tp);
169 muonTruthParticleType(*muon) = acc_type(*tp);
170 muonTruthParticleClassification(*muon) = acc_classification(*tp);
171 setOrigin = true;
172 }
174 if (muonTruthParticleRecoLink && muonTruthParticleRecoLink->operator()(*truthParticle).isValid()){
175 const xAOD::Muon* decor_muon = *muonTruthParticleRecoLink->operator()(*truthParticle);
176 ATH_MSG_VERBOSE(
"Truth particle is already decorated with reco muon "<<decor_muon->
pt()*1.e-3
177 <<
" eta: "<<decor_muon->
eta()<<
" phi: "<<decor_muon->
phi()<<
" charge: "<<
178 decor_muon->
charge()<<
" author: "<<decor_muon->
author()<<
" all authors: "<<
180
181
183 ATH_MSG_DEBUG(
"Author of the decorated muon is better than the one of the new candidate");
184 continue;
185 }
187 if (
deltaR2(muon,truthParticle) >=
deltaR2(muon, decor_muon))
continue;
188 }
189
190
191 ElementLink<xAOD::MuonContainer> muonLink{
muon, *muonTruthParticleLink, ctx};
192
194 std::vector<unsigned int> nprecHitsPerChamberLayer(
toInt(ChIndex::ChIndexMax), dummy_unsigned);
195 std::vector<unsigned int> nphiHitsPerChamberLayer(
toInt(PhiIndex::PhiIndexMax), dummy_unsigned);
196 std::vector<unsigned int> ntrigEtaHitsPerChamberLayer(
toInt(PhiIndex::PhiIndexMax), dummy_unsigned);
197
198 constexpr std::array<xAOD::Muon::Author, 3> author_sel{xAOD::Muon::Author::MuidCo,
199 xAOD::Muon::Author::MuidSA,
200 xAOD::Muon::Author::MuGirl};
202 ? truthParticle
203 : nullptr,
204 tp->
track(), nprecHitsPerChamberLayer, nphiHitsPerChamberLayer, ntrigEtaHitsPerChamberLayer);
206 muonTruthParticleNPrecMatched(*muon) = nprecHitsPerChamberLayer;
207 muonTruthParticleNPhiMatched(*muon) = nphiHitsPerChamberLayer;
208 muonTruthParticleNTrigEtaMatched(*muon) = ntrigEtaHitsPerChamberLayer;
209
210 if (muonTruthParticleRecoLink) (*muonTruthParticleRecoLink)(*truthParticle) = muonLink;
211 break;
212 }
213 } else {
215 }
216 } else {
217 ATH_MSG_WARNING(
"Could not find the appropiate track particle for muon with pT: " <<
muon->pt() * 1.e-3 <<
" GeV, eta: "
218 <<
muon->eta() <<
", phi: " <<
muon->phi()
219 <<
" author: " <<
muon->author());
220 }
221
222 if (!setOrigin) {
223 muonTruthParticleOrigin(*muon) = 0;
224 muonTruthParticleType(*muon) = 0;
225 muonTruthParticleClassification(*muon) = 0;
226 }
227 if (!foundTruth) {
228 muonTruthParticleLink(*muon) = ElementLink<xAOD::TruthParticleContainer>();
229
230 muonTruthParticleNPrecMatched(*muon) = std::vector<unsigned int>{};
231 muonTruthParticleNPhiMatched(*muon) = std::vector<unsigned int>{};
232 muonTruthParticleNTrigEtaMatched(*muon) = std::vector<unsigned int>{};
233 }
236 if (
muon->author() == xAOD::Muon::Author::STACO) {
238 if (!cmb_trk){
240 continue;
241 } else {
242 if (!saw_staco) {
243 saw_staco = true;
244 decor_staco = !dec_origin.isAvailable (*cmb_trk);
245 }
246 if (decor_staco) {
247 dec_origin(*cmb_trk) = acc_origin(*muon);
248 dec_classification(*cmb_trk) = acc_classification(*muon);
249 dec_type(*cmb_trk) = acc_type(*muon);
250 dec_link(*cmb_trk) = acc_link(*muon);
251 }
252 }
253 }
254 }
256 if (muonTruthParticleRecoLink && !muonTruthParticleRecoLink->isAvailable()) {
259 (*muonTruthParticleRecoLink)(*truthParticle) = ElementLink<xAOD::MuonContainer>();
260 }
261 }
262
263 return StatusCode::SUCCESS;
264}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
bool toPersistent()
Dummy function provinding the offline interface.
bool isValid() const
Check if the element can be found.
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleOrigin
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleNPhiMatched
Gaudi::Property< bool > m_associateWithInDetTP
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_muonTruthRecoLink
Decorations for the filtered muon truth particles.
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleClassification
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleType
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleLink
Decorations for the reconstructed muon particles.
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleNTrigEtaMatched
void count_chamber_layers(const xAOD::IParticle *truth_particle, const Trk::Track *ptrk, std::vector< unsigned int > &nprecHitsPerChamberLayer, std::vector< unsigned int > &nphiHitsPerChamberLayer, std::vector< unsigned int > &ntrigEtaHitsPerChamberLayer) const
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthMuKey
Key to the filtered muon truth particles.
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_muonTruthParticleNPrecMatched
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
virtual double pt() const
The transverse momentum ( ) of the particle.
uint16_t allAuthors() const
Get all the authors of this Muon.
float z0() const
Returns the parameter.
const Trk::Track * track() const
Returns a pointer (which can be NULL) to the Trk::Track which was used to make this TrackParticle.
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .).
float d0() const
Returns the parameter.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
float charge() const
Returns the charge.
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,...
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
int authorRank(const xAOD::Muon::Author a)
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.
Muon_v1 Muon
Reference the current persistent version:
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.