From e4b97c402fd635b7a142a34bd7cc005cdcb0399c Mon Sep 17 00:00:00 2001
From: xiaozhon Huang <xiaozhong.huang@cern.ch>
Date: Fri, 30 Oct 2020 13:09:09 +0000
Subject: [PATCH] tauRecTools: workaround for buggy constituent p4
 (ATLJETMET-1280)

The constituent p4 is buggy for EMPFlow seed jets, but the p4 of the
rawConstituent is OK. As a workaround, we now use the rawConstituent
p4.
---
 .../tauRecTools/Root/HelperFunctions.cxx      | 23 +++++++++++++++++++
 .../tauRecTools/src/TauAxisSetter.cxx         |  6 ++---
 .../tauRecTools/tauRecTools/HelperFunctions.h |  2 ++
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/Reconstruction/tauRecTools/Root/HelperFunctions.cxx b/Reconstruction/tauRecTools/Root/HelperFunctions.cxx
index b77abacca75..d364dd756bd 100644
--- a/Reconstruction/tauRecTools/Root/HelperFunctions.cxx
+++ b/Reconstruction/tauRecTools/Root/HelperFunctions.cxx
@@ -148,6 +148,29 @@ std::unique_ptr<MVAUtils::BDT> tauRecTools::configureMVABDT(std::vector<TString>
 
 
 
+TLorentzVector tauRecTools::GetConstituentP4(const xAOD::JetConstituent& constituent) {
+  using namespace tauRecTools::msgHelperFunction;
+
+  TLorentzVector constituentP4;
+
+  if( constituent->type() == xAOD::Type::CaloCluster ) {
+    const xAOD::CaloCluster* cluster = static_cast<const xAOD::CaloCluster*>( constituent->rawConstituent() );
+    constituentP4 = cluster->p4();
+  }
+  else if ( constituent->type() == xAOD::Type::ParticleFlow ) {
+    const xAOD::PFO* pfo = static_cast<const xAOD::PFO*>( constituent->rawConstituent() );
+    constituentP4 = pfo->p4();
+  }
+  else {
+    ANA_MSG_ERROR("GetJetConstCluster: Seed jet constituent type not supported!");
+    constituentP4.SetPtEtaPhiE(constituent.pt(), constituent.eta(), constituent.phi(), constituent.e());
+  }
+
+  return constituentP4;
+}
+
+
+
 const StatusCode tauRecTools::GetJetClusterList(const xAOD::Jet* jet, std::vector<const xAOD::CaloCluster*> &clusterList, bool useSubtractedCluster) {
   using namespace tauRecTools::msgHelperFunction;
 
diff --git a/Reconstruction/tauRecTools/src/TauAxisSetter.cxx b/Reconstruction/tauRecTools/src/TauAxisSetter.cxx
index 582a0ab44e5..ad87dbd4f4f 100644
--- a/Reconstruction/tauRecTools/src/TauAxisSetter.cxx
+++ b/Reconstruction/tauRecTools/src/TauAxisSetter.cxx
@@ -41,8 +41,7 @@ StatusCode TauAxisSetter::execute(xAOD::TauJet& pTau) const {
   
   xAOD::JetConstituentVector constituents = jetSeed->getConstituents();
   for (const xAOD::JetConstituent* constituent : constituents) {
-    TLorentzVector constituentP4;
-    constituentP4.SetPtEtaPhiE(constituent->pt(), constituent->eta(), constituent->phi(), constituent->e());
+    TLorentzVector constituentP4 = tauRecTools::GetConstituentP4(*constituent);
     baryCenter += constituentP4;
   }
   
@@ -53,8 +52,7 @@ StatusCode TauAxisSetter::execute(xAOD::TauJet& pTau) const {
   int nConstituents = 0;
 
   for (const xAOD::JetConstituent* constituent : constituents) {
-    TLorentzVector constituentP4;
-    constituentP4.SetPtEtaPhiE(constituent->pt(), constituent->eta(), constituent->phi(), constituent->e());
+    TLorentzVector constituentP4 = tauRecTools::GetConstituentP4(*constituent);
     
     double dR = baryCenter.DeltaR(constituentP4);
     if (dR > m_clusterCone) continue;
diff --git a/Reconstruction/tauRecTools/tauRecTools/HelperFunctions.h b/Reconstruction/tauRecTools/tauRecTools/HelperFunctions.h
index 67abf144f38..28122100371 100644
--- a/Reconstruction/tauRecTools/tauRecTools/HelperFunctions.h
+++ b/Reconstruction/tauRecTools/tauRecTools/HelperFunctions.h
@@ -24,6 +24,8 @@ namespace tauRecTools
 {
   ANA_MSG_HEADER(msgHelperFunction)
 
+  TLorentzVector GetConstituentP4(const xAOD::JetConstituent& constituent);
+
   const StatusCode GetJetClusterList(const xAOD::Jet* jet, std::vector<const xAOD::CaloCluster*> &clusterList, bool useSubtractedCluster);
 
   xAOD::TauTrack::TrackFlagType isolateClassifiedBits(xAOD::TauTrack::TrackFlagType flag);
-- 
GitLab