20 constexpr
unsigned int dummy_unsigned = 999;
21 constexpr
int com_bit = (1<<xAOD::Muon::Author::Commissioning);
22 void increment_unsigned(
unsigned&
val) {
23 if (
val == dummy_unsigned)
64 return StatusCode::SUCCESS;
70 if (!muonTruthContainer.
isValid()) {
72 return StatusCode::FAILURE;
74 std::unique_ptr<SG::WriteDecorHandle<xAOD::TruthParticleContainer, ElementLink<xAOD::MuonContainer>>> muonTruthParticleRecoLink{};
76 muonTruthParticleRecoLink = std::make_unique<SG::WriteDecorHandle<xAOD::TruthParticleContainer, ElementLink<xAOD::MuonContainer>>>(
m_muonTruthRecoLink, ctx);
81 if (!muonTruthParticleLink.isValid()) {
83 return StatusCode::FAILURE;
93 bool saw_staco =
false;
94 bool decor_staco =
false;
104 tp =
muon->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
106 tp =
muon->primaryTrackParticle();
109 bool foundTruth{
false}, setOrigin{
false};
114 if (acc_origin.isAvailable(*
tp) && acc_origin(*
tp) != 0) {
115 muonTruthParticleOrigin(*
muon) = acc_origin(*
tp);
116 muonTruthParticleType(*
muon) = acc_type(*
tp);
121 if (acc_link.isAvailable(*
tp)) {
122 truthLink = acc_link(*
tp);
124 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());
142 truthParticle->
index(),
144 muonTruthLink.toPersistent();
145 muonTruthParticleLink(*
muon) = muonTruthLink;
147 muonTruthParticleOrigin(*
muon) = acc_origin(*
tp);
148 muonTruthParticleType(*
muon) = acc_type(*
tp);
152 if (muonTruthParticleRecoLink && muonTruthParticleRecoLink->operator()(*truthParticle).isValid()){
153 const xAOD::Muon* decor_muon = *muonTruthParticleRecoLink->operator()(*truthParticle);
154 ATH_MSG_VERBOSE(
"Truth particle is already decorated with reco muon "<<decor_muon->
pt()*1.e-3
155 <<
" eta: "<<decor_muon->
eta()<<
" phi: "<<decor_muon->
phi()<<
" charge: "<<
156 decor_muon->
charge()<<
" author: "<<decor_muon->
author()<<
" all authors: "<<
161 ATH_MSG_DEBUG(
"Author of the decorated muon is better than the one of the new candidate");
165 const int com_score = (
muon->allAuthors() & com_bit) - (decor_muon->
allAuthors() &com_bit);
167 ATH_MSG_DEBUG(
"Found two muons reconstructed by an equivalent author. But this one is from the commissioning chain");
187 tp->track(), nprecHitsPerChamberLayer, nphiHitsPerChamberLayer, ntrigEtaHitsPerChamberLayer);
189 muonTruthParticleNPrecMatched(*
muon) = nprecHitsPerChamberLayer;
190 muonTruthParticleNPhiMatched(*
muon) = nphiHitsPerChamberLayer;
191 muonTruthParticleNTrigEtaMatched(*
muon) = ntrigEtaHitsPerChamberLayer;
193 if (muonTruthParticleRecoLink) (*muonTruthParticleRecoLink)(*truthParticle) = muonLink;
200 ATH_MSG_WARNING(
"Could not find the appropiate track particle for muon with pT: " <<
muon->pt() * 1.e-3 <<
" GeV, eta: "
201 <<
muon->eta() <<
", phi: " <<
muon->phi()
202 <<
" author: " <<
muon->author());
206 muonTruthParticleOrigin(*
muon) = 0;
207 muonTruthParticleType(*
muon) = 0;
212 muonTruthParticleNPrecMatched(*
muon) = std::vector<unsigned int>{};
213 muonTruthParticleNPhiMatched(*
muon) = std::vector<unsigned int>{};
214 muonTruthParticleNTrigEtaMatched(*
muon) = std::vector<unsigned int>{};
226 decor_staco = !dec_origin.isAvailable (*cmb_trk);
229 dec_origin(*cmb_trk) = acc_origin(*
muon);
230 dec_type(*cmb_trk) = acc_type(*
muon);
231 dec_link(*cmb_trk) = acc_link(*
muon);
237 if (muonTruthParticleRecoLink && !muonTruthParticleRecoLink->isAvailable()) {
244 return StatusCode::SUCCESS;
248 std::vector<unsigned int>& nprecHitsPerChamberLayer,
249 std::vector<unsigned int>& nphiHitsPerChamberLayer,
250 std::vector<unsigned int>& ntrigEtaHitsPerChamberLayer)
const {
252 if (!truthParticle || !truthMdtHitsAcc.
isAvailable(*truthParticle)) {
253 ATH_MSG_DEBUG(
"muon has no truth hits vector in the truth association alg");
254 nprecHitsPerChamberLayer.clear();
255 nphiHitsPerChamberLayer.clear();
256 ntrigEtaHitsPerChamberLayer.clear();
259 const std::vector<unsigned long long>& mdtTruth = truthMdtHitsAcc(*truthParticle);
260 std::vector<unsigned long long> cscTruth;
262 truthCscHitsAcc(
"truthCscHits");
264 truthRpcHitsAcc(
"truthRpcHits");
266 truthTgcHitsAcc(
"truthTgcHits");
267 if (
m_idHelperSvc->hasCSC()) cscTruth = truthCscHitsAcc(*truthParticle);
268 const std::vector<unsigned long long>& rpcTruth = truthRpcHitsAcc(*truthParticle);
269 const std::vector<unsigned long long>& tgcTruth = truthTgcHitsAcc(*truthParticle);
272 if (!tsit || !tsit->trackParameters() || !tsit->measurementOnTrack())
continue;
288 for (
unsigned int i = 0;
i < mdtTruth.size(); ++
i) {
289 if (
id == mdtTruth[
i]) {
291 increment_unsigned(nprecHitsPerChamberLayer.at(chIndex));
297 for (
unsigned int i = 0;
i < cscTruth.size(); ++
i) {
298 if (
id != cscTruth[
i])
continue;
302 increment_unsigned(nphiHitsPerChamberLayer.at(
index));
306 increment_unsigned(nprecHitsPerChamberLayer.at(chIndex));
312 for (
unsigned int i = 0;
i < rpcTruth.size(); ++
i) {
313 if (
id != rpcTruth[
i]) {
continue; }
317 increment_unsigned(nphiHitsPerChamberLayer.at(
index));
319 increment_unsigned(ntrigEtaHitsPerChamberLayer.at(
index));
325 for (
unsigned int i = 0;
i < tgcTruth.size(); ++
i) {
326 if (
id != tgcTruth[
i]) {
continue; }
330 increment_unsigned(nphiHitsPerChamberLayer.at(
index));
332 increment_unsigned(ntrigEtaHitsPerChamberLayer.at(
index));
356 for (
unsigned int i = 0;
i <
vec.size(); ++
i) {
357 if (
vec[
i] != dummy_unsigned)
continue;
358 for (
unsigned j = 0; j <
identifiers.size(); ++j) {