17 DiTauTruthMatchingTool::DiTauTruthMatchingTool(
const std::string&
name )
19 , m_accPtVis(
"pt_vis")
20 , m_accEtaVis(
"eta_vis")
21 , m_accPhiVis(
"phi_vis")
27 DiTauTruthMatchingTool::~DiTauTruthMatchingTool( )
38 DiTauTruthMatchingTool::BuildTruthTaus::setTruthMatchingMode();
43 return StatusCode::FAILURE;
45 return StatusCode::SUCCESS;
51 if (retrieveTruthTaus().isFailure())
54 if (findTruthTau(xDiTau).isFailure())
55 ATH_MSG_WARNING(
"There was a failure in finding the matched truth tau");
63 for (
auto xDiTau : vDiTaus)
77 if (!m_bIsTruthMatchedAvailable.isValid()) {
79 m_bIsTruthMatchedAvailable.set (accIsTruthMatched.
isAvailable(xDiTau));
81 if (*m_bIsTruthMatchedAvailable.ptr())
82 return StatusCode::SUCCESS;
84 if (m_bTruthTauAvailable)
85 return checkTruthMatch(xDiTau, *m_truthTausEvent.m_xTruthTauContainerConst);
87 return checkTruthMatch(xDiTau, *m_truthTausEvent.m_xTruthTauContainer);
93 std::vector<const xAOD::TruthParticle*> vTruthMatch;
94 std::vector<TruthMatchedParticleType> vTruthMatchedParticleType;
95 std::vector<const xAOD::Jet*> vTruthJetMatch;
108 while (xDiTau.
subjetPt(n_subjets) > 0. )
113 n_subjets = accNSubjets(xDiTau);
117 for (
int i = 0;
i < n_subjets; ++
i)
122 vTruthMatch.push_back(xTruthMatch);
123 vTruthMatchedParticleType.push_back(eTruthMatchedParticleType);
125 const xAOD::Jet* xTruthJetMatch =
nullptr;
126 vTruthJetMatch.push_back(xTruthJetMatch);
130 for (
int i = 0;
i < n_subjets; ++
i)
132 TLorentzVector vSubjetTLV;
133 vSubjetTLV.SetPtEtaPhiE(xDiTau.
subjetPt(
i),
137 if ( truthMatch(vSubjetTLV,
140 vTruthJetMatch.at(
i),
141 vTruthMatchedParticleType.at(
i)).isFailure() )
143 ATH_MSG_WARNING(
"There was a failure in matching truth taus with subjet " <<
i);
144 return StatusCode::FAILURE;
149 xRemainingTruthTaus.
end(),
150 vTruthMatch.at(
i)) );
155 std::vector< ElementLink < xAOD::JetContainer > > vTruthJetLinks;
156 for (
int i = 0;
i < n_subjets; ++
i)
158 const xAOD::Jet* xTruthJetMatch = vTruthJetMatch.at(
i);
161 vTruthJetLinks.push_back(lTruthParticleLink);
166 vTruthJetLinks.push_back(lTruthParticleLink);
170 decTruthJetLinks (
"truthJetLinks");
171 decTruthJetLinks(xDiTau) = std::move(vTruthJetLinks);
174 bool bTruthMatched =
true;
177 std::vector< ElementLink < xAOD::TruthParticleContainer > > vTruthLinks;
178 for (
int i = 0;
i < n_subjets; ++
i)
187 vTruthLinks.push_back(lTruthParticleLink);
189 else if (eTruthMatchedParticleType ==
TruthMuon)
192 vTruthLinks.push_back(lTruthParticleLink);
197 vTruthLinks.push_back(lTruthParticleLink);
203 vTruthLinks.push_back(lTruthParticleLink);
206 if (
i == 0 ||
i == 1) bTruthMatched =
false;
211 decTruthParticleLinks (
"truthParticleLinks");
212 decTruthParticleLinks(xDiTau) = vTruthLinks;
213 if (!m_bTruthTauAvailable)
216 decTruthTaus (
"TruthTaus");
217 decTruthTaus(xDiTau) = vTruthLinks;
234 if ( n_subjets < 2) {
235 decIsTruthMatched(xDiTau) = (
char)
false;
236 decIsTruthHadronic(xDiTau) = (
char)
false;
237 decTruthLeadPt(xDiTau) = -1234.;
238 decTruthLeadEta(xDiTau) = -1234.;
239 decTruthLeadPhi(xDiTau) = -1234.;
240 decTruthLeadM(xDiTau) = -1234.;
241 decTruthLeadPdgID(xDiTau) = -1234.;
242 decTruthSubleadPt(xDiTau) = -1234.;
243 decTruthSubleadEta(xDiTau) = -1234.;
244 decTruthSubleadPhi(xDiTau) = -1234.;
245 decTruthSubleadM(xDiTau) = -1234.;
246 decTruthSubleadPdgID(xDiTau) = -1234.;
247 decTruthDeltaR(xDiTau) = -1234.;
248 decTruthMass(xDiTau) = -1234.;
249 return StatusCode::SUCCESS;
252 decIsTruthMatched(xDiTau) = (
char)bTruthMatched;
260 decIsTruthHadronic(xDiTau) = (
char)
false;
262 if (accIsTruthHadronic(xDiTau))
264 TLorentzVector tlvTruthTau1;
265 TLorentzVector tlvTruthTau2;
266 tlvTruthTau1.SetPtEtaPhiM(m_accPtVis(*(*vTruthLinks.at(0))),
267 m_accEtaVis(*(*vTruthLinks.at(0))),
268 m_accPhiVis(*(*vTruthLinks.at(0))),
269 m_accMVis(*(*vTruthLinks.at(0))));
270 tlvTruthTau2.SetPtEtaPhiM(m_accPtVis(*(*vTruthLinks.at(1))),
271 m_accEtaVis(*(*vTruthLinks.at(1))),
272 m_accPhiVis(*(*vTruthLinks.at(1))),
273 m_accMVis(*(*vTruthLinks.at(1))));
275 decTruthLeadPt(xDiTau) =
std::max(tlvTruthTau1.Pt(), tlvTruthTau2.Pt());
276 decTruthLeadEta(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau1.Eta() : tlvTruthTau2.Eta();
277 decTruthLeadPhi(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau1.Phi() : tlvTruthTau2.Phi();
278 decTruthLeadM(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau1.M() : tlvTruthTau2.M();
279 decTruthLeadPdgID(xDiTau) = (*vTruthLinks.at(0))->
pdgId();
280 decTruthSubleadPt(xDiTau) =
std::min(tlvTruthTau1.Pt(), tlvTruthTau2.Pt());
281 decTruthSubleadEta(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau2.Eta() : tlvTruthTau1.Eta();
282 decTruthSubleadPhi(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau2.Phi() : tlvTruthTau1.Phi();
283 decTruthSubleadM(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau2.M() : tlvTruthTau1.M();
284 decTruthSubleadPdgID(xDiTau) = (*vTruthLinks.at(1))->
pdgId();
285 decTruthDeltaR(xDiTau) = tlvTruthTau1.DeltaR(tlvTruthTau2);
286 decTruthMass(xDiTau) = (tlvTruthTau1 + tlvTruthTau2).M();
290 decTruthLeadPt(xDiTau) = -1234.;
291 decTruthLeadEta(xDiTau) = -1234.;
292 decTruthLeadPhi(xDiTau) = -1234.;
293 decTruthLeadM(xDiTau) = -1234.;
294 decTruthLeadPdgID(xDiTau) = -1234.;
295 decTruthSubleadPt(xDiTau) = -1234.;
296 decTruthSubleadEta(xDiTau) = -1234.;
297 decTruthSubleadPhi(xDiTau) = -1234.;
298 decTruthSubleadM(xDiTau) = -1234.;
299 decTruthSubleadPdgID(xDiTau) = -1234.;
300 decTruthDeltaR(xDiTau) = -1234.;
301 decTruthMass(xDiTau) = -1234.;
304 return StatusCode::SUCCESS;
307 StatusCode DiTauTruthMatchingTool::truthMatch(
const TLorentzVector& vSubjetTLV,
313 for (
auto xTruthTauIt : xTruthTauContainer)
315 TLorentzVector vTruthVisTLV;
316 vTruthVisTLV.SetPtEtaPhiM(m_accPtVis(*xTruthTauIt),
317 m_accEtaVis(*xTruthTauIt),
318 m_accPhiVis(*xTruthTauIt),
319 m_accMVis(*xTruthTauIt));
320 if (vSubjetTLV.DeltaR(vTruthVisTLV) <= m_dMaxDeltaR)
323 if (
static_cast<bool>(accIsHadronicTau(*xTruthTauIt)))
328 xTruthMatch = xTruthTauIt;
333 if (!xTruthMatch and m_truthTausEvent.m_xTruthMuonContainerConst)
336 for (
auto xTruthMuonIt : *m_truthTausEvent.m_xTruthMuonContainerConst)
338 if (vSubjetTLV.DeltaR(xTruthMuonIt->p4()) <= m_dMaxDeltaR)
340 if (xTruthMuonIt->pt()<dPtMax)
344 xTruthMatch = xTruthMuonIt;
345 dPtMax = xTruthMuonIt->
pt();
350 if (!xTruthMatch and m_truthTausEvent.m_xTruthElectronContainerConst)
353 for (
auto xTruthElectronIt : *m_truthTausEvent.m_xTruthElectronContainerConst)
355 if (vSubjetTLV.DeltaR(xTruthElectronIt->p4()) <= m_dMaxDeltaR)
357 if (xTruthElectronIt->pt()<dPtMax)
360 xTruthMatch = xTruthElectronIt;
361 dPtMax = xTruthElectronIt->
pt();
366 if (m_truthTausEvent.m_xTruthJetContainerConst)
369 for (
auto xTruthJetIt : *m_truthTausEvent.m_xTruthJetContainerConst)
371 if (vSubjetTLV.DeltaR(xTruthJetIt->p4()) <= m_dMaxDeltaR)
373 if (xTruthJetIt->pt()<dPtMax)
375 xTruthJetMatch = xTruthJetIt;
376 dPtMax = xTruthJetIt->
pt();
381 return StatusCode::SUCCESS;