11 #include "AthLinks/ElementLink.h"
26 BuildTruthTaus::BuildTruthTaus(
const std::string&
name )
27 : AsgMetadataTool(
name)
28 , m_tMCTruthClassifier(
"MCTruthClassifier", this)
30 declareProperty(
"WriteInvisibleFourMomentum", m_bWriteInvisibleFourMomentum =
false);
31 declareProperty(
"WriteVisibleChargedFourMomentum", m_bWriteVisibleChargedFourMomentum =
false);
32 declareProperty(
"WriteVisibleNeutralFourMomentum", m_bWriteVisibleNeutralFourMomentum =
false);
33 declareProperty(
"WriteDecayModeVector", m_bWriteDecayModeVector =
true);
64 return StatusCode::SUCCESS;
82 const EventContext& ctx = Gaudi::Hive::currentContext();
86 if (!truthElectronsHandle.
isValid()) {
88 return StatusCode::FAILURE;
90 truthTausEvent.m_xTruthElectronContainerConst = truthElectronsHandle.
cptr();
93 ATH_MSG_WARNING(
"Truth electron container is not available, won't perform matching to truth electrons");
98 if (!truthMuonsHandle.
isValid()) {
100 return StatusCode::FAILURE;
102 truthTausEvent.m_xTruthMuonContainerConst = truthMuonsHandle.
cptr();
105 ATH_MSG_WARNING(
"Truth muon container is not available, won't perform matching to truth muons");
110 if (!truthJetsHandle.
isValid()) {
112 return StatusCode::FAILURE;
114 truthTausEvent.m_xTruthJetContainerConst = truthJetsHandle.
cptr();
117 ATH_MSG_WARNING(
"Truth jet container is not available, won't perform matching to truth jets");
123 if (!truthTausHandle.
isValid()) {
125 return StatusCode::FAILURE;
127 truthTausEvent.m_xTruthTauContainerConst = truthTausHandle.
cptr();
131 if (!truthParticlesHandle.
isValid()) {
133 return StatusCode::FAILURE;
135 truthTausEvent.m_xTruthParticleContainer = truthParticlesHandle.
cptr();
137 auto truthTausOutput = std::make_unique<xAOD::TruthParticleContainer>();
138 auto truthTausOutputAux = std::make_unique<xAOD::TruthParticleAuxContainer>();
139 truthTausOutput->setStore(truthTausOutputAux.get());
140 truthTausEvent.m_xTruthTauContainer = truthTausOutput.get();
145 ATH_CHECK(writeHandle.record(std::move(truthTausOutput), std::move(truthTausOutputAux)));
148 return StatusCode::SUCCESS;
157 for (
auto xTruthParticle : *truthTausEvent.m_xTruthParticleContainer)
159 if ( xTruthParticle->isTau() )
174 decClassifierParticleType(*xTruthTau) = pClassification.first;
175 decClassifierParticleOrigin(*xTruthTau) = pClassification.second;
180 accOriginalTruthParticle(*xTruthTau) = lTruthParticleLink;
182 truthTausEvent.m_xTruthTauContainer->push_back(xTruthTau);
185 return StatusCode::SUCCESS;
193 return StatusCode::FAILURE;
200 if (xDecayVertex ==
nullptr)
201 return StatusCode::FAILURE;
202 for (
size_t iOutgoingParticle = 0; iOutgoingParticle < xDecayVertex->
nOutgoingParticles(); ++iOutgoingParticle )
205 if (xTruthDaughter ==
nullptr)
207 ATH_MSG_ERROR(
"Truth daughter of tau decay was not found in "<<
m_truthParticleContainer.
key() <<
" container. Please ensure that this container has the full tau decay information or produce the TruthTaus container in AtlasDerivation.");
208 return StatusCode::FAILURE;
212 if ( xTruthDaughter->
isTau() )
215 return StatusCode::FAILURE;
256 TLorentzVector vTruthInvisTLV = xTruthParticle.
p4() - truthInfo.
m_vTruthVisTLV;
261 decPtInvis(xTruthParticle) = vTruthInvisTLV.Pt();
262 decEtaInvis(xTruthParticle) = vTruthInvisTLV.Eta();
263 decPhiInvis(xTruthParticle) = vTruthInvisTLV.Phi();
264 decMInvis(xTruthParticle) = vTruthInvisTLV.M();
294 decDecayModeVector(xTruthParticle) = truthInfo.
m_vDecayMode;
313 decProdVertexX(xTruthParticle) = truthInfo.
m_vProdVertex.X();
314 decProdVertexY(xTruthParticle) = truthInfo.
m_vProdVertex.Y();
315 decProdVertexZ(xTruthParticle) = truthInfo.
m_vProdVertex.Z();
318 return StatusCode::SUCCESS;
328 return StatusCode::SUCCESS;
330 truthInfo.
m_vDecayVertex.SetXYZ(xDecayVertex->
x(),xDecayVertex->
y(),xDecayVertex->
z());
334 truthInfo.
m_vProdVertex.SetXYZ(xProdVertex->
x(),xProdVertex->
y(),xProdVertex->
z());
339 for (
size_t iOutgoingParticle = 0; iOutgoingParticle < xDecayVertex->
nOutgoingParticles(); ++iOutgoingParticle )
342 if (xTruthDaughter ==
nullptr)
344 ATH_MSG_ERROR(
"Truth daughter of tau decay was not found in "<<
m_truthParticleContainer.
key() <<
" container. Please ensure that this container has the full tau decay information or produce the TruthTaus container in AtlasDerivation.");
345 return StatusCode::FAILURE;
348 int iAbsPdgId = xTruthDaughter->
absPdgId();
349 int iPdgId = xTruthDaughter->
pdgId();
354 if ( iAbsPdgId != 111 && iAbsPdgId != 311 && iAbsPdgId != 310 && iAbsPdgId != 130 )
406 return StatusCode::SUCCESS;
414 if (xDecayVertex ==
nullptr)
417 for (
size_t iOutgoingParticle = 0; iOutgoingParticle < xDecayVertex->
nOutgoingParticles(); ++iOutgoingParticle )
420 if (xTruthDaughter ==
nullptr)
422 ATH_MSG_WARNING(
"Truth daughter of tau decay was not found in "<<
m_truthParticleContainer.
key() <<
" container. Please ensure that this container has the full tau decay information or produce the TruthTaus container in AtlasDerivation.");
426 <<
" e "<<xTruthDaughter->
e()
427 <<
" eta "<<xTruthDaughter->
p4().Eta()
428 <<
" phi "<<xTruthDaughter->
p4().Phi()
429 <<
" pdgid "<<xTruthDaughter->
pdgId()
430 <<
" status "<<xTruthDaughter->
status()