14 #include "AthLinks/ElementLink.h"
29 DiTauTruthMatchingTool::DiTauTruthMatchingTool(
const std::string&
name )
31 , m_accPtVis(
"pt_vis")
32 , m_accEtaVis(
"eta_vis")
33 , m_accPhiVis(
"phi_vis")
40 DiTauTruthMatchingTool::~DiTauTruthMatchingTool( )
51 DiTauTruthMatchingTool::BuildTruthTaus::setTruthMatchingMode();
56 return StatusCode::FAILURE;
58 return StatusCode::SUCCESS;
64 if (retrieveTruthTaus().isFailure())
67 if (findTruthTau(xDiTau).isFailure())
68 ATH_MSG_WARNING(
"There was a failure in finding the matched truth tau");
76 for (
auto xDiTau : vDiTaus)
90 if (!m_bIsTruthMatchedAvailable.isValid()) {
92 m_bIsTruthMatchedAvailable.set (accIsTruthMatched.
isAvailable(xDiTau));
94 if (*m_bIsTruthMatchedAvailable.ptr())
95 return StatusCode::SUCCESS;
97 if (m_bTruthTauAvailable)
98 return checkTruthMatch(xDiTau, *m_truthTausEvent.m_xTruthTauContainerConst);
100 return checkTruthMatch(xDiTau, *m_truthTausEvent.m_xTruthTauContainer);
106 std::vector<const xAOD::TruthParticle*> vTruthMatch;
107 std::vector<TruthMatchedParticleType> vTruthMatchedParticleType;
119 for (
int i = 0;
i < accNSubjets(xDiTau); ++
i)
124 vTruthMatch.push_back(xTruthMatch);
125 vTruthMatchedParticleType.push_back(eTruthMatchedParticleType);
129 for (
int i = 0;
i < accNSubjets(xDiTau); ++
i)
131 TLorentzVector vSubjetTLV;
132 vSubjetTLV.SetPtEtaPhiE(xDiTau.
subjetPt(
i),
136 if ( truthMatch(vSubjetTLV,
139 vTruthMatchedParticleType.at(
i)).isFailure() )
141 ATH_MSG_WARNING(
"There was a failure in matching truth taus with subjet " <<
i);
142 return StatusCode::FAILURE;
147 xRemainingTruthTaus.
end(),
148 vTruthMatch.at(
i)) );
152 bool bTruthMatched =
true;
155 std::vector< ElementLink < xAOD::TruthParticleContainer > > vTruthLinks;
156 for (
int i = 0;
i < accNSubjets(xDiTau); ++
i)
165 vTruthLinks.push_back(lTruthParticleLink);
167 else if (eTruthMatchedParticleType ==
TruthMuon)
170 vTruthLinks.push_back(lTruthParticleLink);
175 vTruthLinks.push_back(lTruthParticleLink);
181 vTruthLinks.push_back(lTruthParticleLink);
184 if (
i == 0 ||
i == 1) bTruthMatched =
false;
189 decTruthParticleLinks (
"truthParticleLinks");
190 decTruthParticleLinks(xDiTau) = vTruthLinks;
191 if (!m_bTruthTauAvailable)
194 decTruthTaus (
"TruthTaus");
195 decTruthTaus(xDiTau) = vTruthLinks;
210 ATH_MSG_ERROR(
"Links to reco electron and reco muon available for one ditau candidate.");
215 mcTruthType = accTruthType(*pElectron);
216 mcTruthOrigin = accTruthOrigin(*pElectron);
218 lTruthLeptonLink = checkTruthLepton(pElectron);
224 mcTruthType = accTruthType(*pMuon);
225 mcTruthOrigin = accTruthOrigin(*pMuon);
227 lTruthLeptonLink = checkTruthLepton(pMuon);
232 decClassifierParticleType(xDiTau) = mcTruthType;
233 decClassifierParticleOrigin(xDiTau) = mcTruthOrigin;
234 decTruthLeptonLink(xDiTau) = lTruthLeptonLink;
248 if ( accNSubjets(xDiTau) < 2) {
249 decIsTruthMatched(xDiTau) = (
char)
false;
250 decIsTruthHadronic(xDiTau) = (
char)
false;
251 decTruthLeadPt(xDiTau) = -1234.;
252 decTruthLeadEta(xDiTau) = -1234.;
253 decTruthLeadPhi(xDiTau) = -1234.;
254 decTruthLeadM(xDiTau) = -1234.;
255 decTruthSubleadPt(xDiTau) = -1234.;
256 decTruthSubleadEta(xDiTau) = -1234.;
257 decTruthSubleadPhi(xDiTau) = -1234.;
258 decTruthSubleadM(xDiTau) = -1234.;
259 decTruthDeltaR(xDiTau) = -1234.;
260 decTruthMass(xDiTau) = -1234.;
261 return StatusCode::SUCCESS;
264 decIsTruthMatched(xDiTau) = (
char)bTruthMatched;
272 decIsTruthHadronic(xDiTau) = (
char)
false;
274 if (accIsTruthHadronic(xDiTau))
276 TLorentzVector tlvTruthTau1;
277 TLorentzVector tlvTruthTau2;
278 tlvTruthTau1.SetPtEtaPhiM(m_accPtVis(*(*vTruthLinks.at(0))),
279 m_accEtaVis(*(*vTruthLinks.at(0))),
280 m_accPhiVis(*(*vTruthLinks.at(0))),
281 m_accMVis(*(*vTruthLinks.at(0))));
282 tlvTruthTau2.SetPtEtaPhiM(m_accPtVis(*(*vTruthLinks.at(1))),
283 m_accEtaVis(*(*vTruthLinks.at(1))),
284 m_accPhiVis(*(*vTruthLinks.at(1))),
285 m_accMVis(*(*vTruthLinks.at(1))));
287 decTruthLeadPt(xDiTau) =
std::max(tlvTruthTau1.Pt(), tlvTruthTau2.Pt());
288 decTruthLeadEta(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau1.Eta() : tlvTruthTau2.Eta();
289 decTruthLeadPhi(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau1.Phi() : tlvTruthTau2.Phi();
290 decTruthLeadM(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau1.M() : tlvTruthTau2.M();
291 decTruthSubleadPt(xDiTau) =
std::min(tlvTruthTau1.Pt(), tlvTruthTau2.Pt());
292 decTruthSubleadEta(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau2.Eta() : tlvTruthTau1.Eta();
293 decTruthSubleadPhi(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau2.Phi() : tlvTruthTau1.Phi();
294 decTruthSubleadM(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau2.M() : tlvTruthTau1.M();
295 decTruthDeltaR(xDiTau) = tlvTruthTau1.DeltaR(tlvTruthTau2);
296 decTruthMass(xDiTau) = (tlvTruthTau1 + tlvTruthTau2).M();
300 decTruthLeadPt(xDiTau) = -1234.;
301 decTruthLeadEta(xDiTau) = -1234.;
302 decTruthLeadPhi(xDiTau) = -1234.;
303 decTruthLeadM(xDiTau) = -1234.;
304 decTruthSubleadPt(xDiTau) = -1234.;
305 decTruthSubleadEta(xDiTau) = -1234.;
306 decTruthSubleadPhi(xDiTau) = -1234.;
307 decTruthSubleadM(xDiTau) = -1234.;
308 decTruthDeltaR(xDiTau) = -1234.;
309 decTruthMass(xDiTau) = -1234.;
312 return StatusCode::SUCCESS;
320 return truthParticleLink;
322 truthParticleLink = accTruthParticleLink(*pLepton);
323 return truthParticleLink;
327 StatusCode DiTauTruthMatchingTool::truthMatch(
const TLorentzVector& vSubjetTLV,
332 for (
auto xTruthTauIt : xTruthTauContainer)
334 TLorentzVector vTruthVisTLV;
335 vTruthVisTLV.SetPtEtaPhiM(m_accPtVis(*xTruthTauIt),
336 m_accEtaVis(*xTruthTauIt),
337 m_accPhiVis(*xTruthTauIt),
338 m_accMVis(*xTruthTauIt));
339 if (vSubjetTLV.DeltaR(vTruthVisTLV) <= m_dMaxDeltaR)
342 if ((
bool)accIsHadronicTau(*xTruthTauIt))
347 xTruthMatch = xTruthTauIt;
352 if (!xTruthMatch and m_truthTausEvent.m_xTruthMuonContainerConst)
355 for (
auto xTruthMuonIt : *m_truthTausEvent.m_xTruthMuonContainerConst)
357 if (vSubjetTLV.DeltaR(xTruthMuonIt->p4()) <= m_dMaxDeltaR)
359 if (xTruthMuonIt->pt()<dPtMax)
363 xTruthMatch = xTruthMuonIt;
364 dPtMax = xTruthMuonIt->
pt();
369 if (!xTruthMatch and m_truthTausEvent.m_xTruthElectronContainerConst)
372 for (
auto xTruthElectronIt : *m_truthTausEvent.m_xTruthElectronContainerConst)
374 if (vSubjetTLV.DeltaR(xTruthElectronIt->p4()) <= m_dMaxDeltaR)
376 if (xTruthElectronIt->pt()<dPtMax)
379 xTruthMatch = xTruthElectronIt;
380 dPtMax = xTruthElectronIt->
pt();
385 return StatusCode::SUCCESS;