14 #include "AthLinks/ElementLink.h"
25 DiTauTruthMatchingTool::DiTauTruthMatchingTool(
const std::string&
name )
27 , m_accPtVis(
"pt_vis")
28 , m_accEtaVis(
"eta_vis")
29 , m_accPhiVis(
"phi_vis")
35 DiTauTruthMatchingTool::~DiTauTruthMatchingTool( )
46 DiTauTruthMatchingTool::BuildTruthTaus::setTruthMatchingMode();
51 return StatusCode::FAILURE;
53 return StatusCode::SUCCESS;
59 if (retrieveTruthTaus().isFailure())
62 if (findTruthTau(xDiTau).isFailure())
63 ATH_MSG_WARNING(
"There was a failure in finding the matched truth tau");
71 for (
auto xDiTau : vDiTaus)
85 if (!m_bIsTruthMatchedAvailable.isValid()) {
87 m_bIsTruthMatchedAvailable.set (accIsTruthMatched.
isAvailable(xDiTau));
89 if (*m_bIsTruthMatchedAvailable.ptr())
90 return StatusCode::SUCCESS;
92 if (m_bTruthTauAvailable)
93 return checkTruthMatch(xDiTau, *m_truthTausEvent.m_xTruthTauContainerConst);
95 return checkTruthMatch(xDiTau, *m_truthTausEvent.m_xTruthTauContainer);
101 std::vector<const xAOD::TruthParticle*> vTruthMatch;
102 std::vector<TruthMatchedParticleType> vTruthMatchedParticleType;
103 std::vector<const xAOD::Jet*> vTruthJetMatch;
116 while (xDiTau.
subjetPt(n_subjets) > 0. )
121 n_subjets = accNSubjets(xDiTau);
125 for (
int i = 0;
i < n_subjets; ++
i)
130 vTruthMatch.push_back(xTruthMatch);
131 vTruthMatchedParticleType.push_back(eTruthMatchedParticleType);
133 const xAOD::Jet* xTruthJetMatch =
nullptr;
134 vTruthJetMatch.push_back(xTruthJetMatch);
138 for (
int i = 0;
i < n_subjets; ++
i)
140 TLorentzVector vSubjetTLV;
141 vSubjetTLV.SetPtEtaPhiE(xDiTau.
subjetPt(
i),
145 if ( truthMatch(vSubjetTLV,
148 vTruthJetMatch.at(
i),
149 vTruthMatchedParticleType.at(
i)).isFailure() )
151 ATH_MSG_WARNING(
"There was a failure in matching truth taus with subjet " <<
i);
152 return StatusCode::FAILURE;
157 xRemainingTruthTaus.
end(),
158 vTruthMatch.at(
i)) );
163 std::vector< ElementLink < xAOD::JetContainer > > vTruthJetLinks;
164 for (
int i = 0;
i < n_subjets; ++
i)
166 const xAOD::Jet* xTruthJetMatch = vTruthJetMatch.at(
i);
169 vTruthJetLinks.push_back(lTruthParticleLink);
174 vTruthJetLinks.push_back(lTruthParticleLink);
178 decTruthJetLinks (
"truthJetLinks");
179 decTruthJetLinks(xDiTau) = std::move(vTruthJetLinks);
182 bool bTruthMatched =
true;
185 std::vector< ElementLink < xAOD::TruthParticleContainer > > vTruthLinks;
186 for (
int i = 0;
i < n_subjets; ++
i)
195 vTruthLinks.push_back(lTruthParticleLink);
197 else if (eTruthMatchedParticleType ==
TruthMuon)
200 vTruthLinks.push_back(lTruthParticleLink);
205 vTruthLinks.push_back(lTruthParticleLink);
211 vTruthLinks.push_back(lTruthParticleLink);
214 if (
i == 0 ||
i == 1) bTruthMatched =
false;
219 decTruthParticleLinks (
"truthParticleLinks");
220 decTruthParticleLinks(xDiTau) = vTruthLinks;
221 if (!m_bTruthTauAvailable)
224 decTruthTaus (
"TruthTaus");
225 decTruthTaus(xDiTau) = vTruthLinks;
242 if ( n_subjets < 2) {
243 decIsTruthMatched(xDiTau) = (
char)
false;
244 decIsTruthHadronic(xDiTau) = (
char)
false;
245 decTruthLeadPt(xDiTau) = -1234.;
246 decTruthLeadEta(xDiTau) = -1234.;
247 decTruthLeadPhi(xDiTau) = -1234.;
248 decTruthLeadM(xDiTau) = -1234.;
249 decTruthLeadPdgID(xDiTau) = -1234.;
250 decTruthSubleadPt(xDiTau) = -1234.;
251 decTruthSubleadEta(xDiTau) = -1234.;
252 decTruthSubleadPhi(xDiTau) = -1234.;
253 decTruthSubleadM(xDiTau) = -1234.;
254 decTruthSubleadPdgID(xDiTau) = -1234.;
255 decTruthDeltaR(xDiTau) = -1234.;
256 decTruthMass(xDiTau) = -1234.;
257 return StatusCode::SUCCESS;
260 decIsTruthMatched(xDiTau) = (
char)bTruthMatched;
268 decIsTruthHadronic(xDiTau) = (
char)
false;
270 if (accIsTruthHadronic(xDiTau))
272 TLorentzVector tlvTruthTau1;
273 TLorentzVector tlvTruthTau2;
274 tlvTruthTau1.SetPtEtaPhiM(m_accPtVis(*(*vTruthLinks.at(0))),
275 m_accEtaVis(*(*vTruthLinks.at(0))),
276 m_accPhiVis(*(*vTruthLinks.at(0))),
277 m_accMVis(*(*vTruthLinks.at(0))));
278 tlvTruthTau2.SetPtEtaPhiM(m_accPtVis(*(*vTruthLinks.at(1))),
279 m_accEtaVis(*(*vTruthLinks.at(1))),
280 m_accPhiVis(*(*vTruthLinks.at(1))),
281 m_accMVis(*(*vTruthLinks.at(1))));
283 decTruthLeadPt(xDiTau) =
std::max(tlvTruthTau1.Pt(), tlvTruthTau2.Pt());
284 decTruthLeadEta(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau1.Eta() : tlvTruthTau2.Eta();
285 decTruthLeadPhi(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau1.Phi() : tlvTruthTau2.Phi();
286 decTruthLeadM(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau1.M() : tlvTruthTau2.M();
287 decTruthLeadPdgID(xDiTau) = (*vTruthLinks.at(0))->
pdgId();
288 decTruthSubleadPt(xDiTau) =
std::min(tlvTruthTau1.Pt(), tlvTruthTau2.Pt());
289 decTruthSubleadEta(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau2.Eta() : tlvTruthTau1.Eta();
290 decTruthSubleadPhi(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau2.Phi() : tlvTruthTau1.Phi();
291 decTruthSubleadM(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau2.M() : tlvTruthTau1.M();
292 decTruthSubleadPdgID(xDiTau) = (*vTruthLinks.at(1))->
pdgId();
293 decTruthDeltaR(xDiTau) = tlvTruthTau1.DeltaR(tlvTruthTau2);
294 decTruthMass(xDiTau) = (tlvTruthTau1 + tlvTruthTau2).M();
298 decTruthLeadPt(xDiTau) = -1234.;
299 decTruthLeadEta(xDiTau) = -1234.;
300 decTruthLeadPhi(xDiTau) = -1234.;
301 decTruthLeadM(xDiTau) = -1234.;
302 decTruthLeadPdgID(xDiTau) = -1234.;
303 decTruthSubleadPt(xDiTau) = -1234.;
304 decTruthSubleadEta(xDiTau) = -1234.;
305 decTruthSubleadPhi(xDiTau) = -1234.;
306 decTruthSubleadM(xDiTau) = -1234.;
307 decTruthSubleadPdgID(xDiTau) = -1234.;
308 decTruthDeltaR(xDiTau) = -1234.;
309 decTruthMass(xDiTau) = -1234.;
312 return StatusCode::SUCCESS;
315 StatusCode DiTauTruthMatchingTool::truthMatch(
const TLorentzVector& vSubjetTLV,
321 for (
auto xTruthTauIt : xTruthTauContainer)
323 TLorentzVector vTruthVisTLV;
324 vTruthVisTLV.SetPtEtaPhiM(m_accPtVis(*xTruthTauIt),
325 m_accEtaVis(*xTruthTauIt),
326 m_accPhiVis(*xTruthTauIt),
327 m_accMVis(*xTruthTauIt));
328 if (vSubjetTLV.DeltaR(vTruthVisTLV) <= m_dMaxDeltaR)
331 if (
static_cast<bool>(accIsHadronicTau(*xTruthTauIt)))
336 xTruthMatch = xTruthTauIt;
341 if (!xTruthMatch and m_truthTausEvent.m_xTruthMuonContainerConst)
344 for (
auto xTruthMuonIt : *m_truthTausEvent.m_xTruthMuonContainerConst)
346 if (vSubjetTLV.DeltaR(xTruthMuonIt->p4()) <= m_dMaxDeltaR)
348 if (xTruthMuonIt->pt()<dPtMax)
352 xTruthMatch = xTruthMuonIt;
353 dPtMax = xTruthMuonIt->
pt();
358 if (!xTruthMatch and m_truthTausEvent.m_xTruthElectronContainerConst)
361 for (
auto xTruthElectronIt : *m_truthTausEvent.m_xTruthElectronContainerConst)
363 if (vSubjetTLV.DeltaR(xTruthElectronIt->p4()) <= m_dMaxDeltaR)
365 if (xTruthElectronIt->pt()<dPtMax)
368 xTruthMatch = xTruthElectronIt;
369 dPtMax = xTruthElectronIt->
pt();
374 if (m_truthTausEvent.m_xTruthJetContainerConst)
377 for (
auto xTruthJetIt : *m_truthTausEvent.m_xTruthJetContainerConst)
379 if (vSubjetTLV.DeltaR(xTruthJetIt->p4()) <= m_dMaxDeltaR)
381 if (xTruthJetIt->pt()<dPtMax)
383 xTruthJetMatch = xTruthJetIt;
384 dPtMax = xTruthJetIt->
pt();
389 return StatusCode::SUCCESS;