From 619277fb59ef14070b374b93824e5c1dbc16bcc4 Mon Sep 17 00:00:00 2001
From: cdelitzs <chris.malena.delitzsch@cern.ch>
Date: Tue, 10 Nov 2020 12:08:36 +0100
Subject: [PATCH] Add protection for four-vector retrieval

---
 .../JetMonitoring/Root/JetKinematicHistos.cxx | 39 ++++++++++---------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/Reconstruction/Jet/JetMonitoring/Root/JetKinematicHistos.cxx b/Reconstruction/Jet/JetMonitoring/Root/JetKinematicHistos.cxx
index 9e0b766c914..7ea1e32dee6 100644
--- a/Reconstruction/Jet/JetMonitoring/Root/JetKinematicHistos.cxx
+++ b/Reconstruction/Jet/JetMonitoring/Root/JetKinematicHistos.cxx
@@ -107,26 +107,27 @@ int JetKinematicHistos::fillHistosFromContainer(const xAOD::JetContainer & cont)
 
 int JetKinematicHistos::fillHistosFromJet(const xAOD::Jet &j){
 
-  // m_jetScale is a property of the base tool
-  const xAOD::JetFourMom_t p4 = j.jetP4( (xAOD::JetScale) m_jetScale);
-  m_pt->Fill( p4.Pt()*toGeV );
-  m_eta->Fill( p4.Eta() );
-  m_phi->Fill( p4.Phi() );
-  if (p4.Pt()*toGeV > 200.0){ // high eta 
-                         m_pt_high->Fill( p4.Pt()*toGeV );
-                         m_eta_high->Fill( p4.Eta() );
-                         if(m_doE) m_e_high->Fill( p4.E()*toGeV );
-                         if(m_doM) m_m_high->Fill( p4.M()*toGeV );
-                         if(m_doNConstit) m_nConstit_high->Fill( j.numConstituents() );
-                      }
-
-
-  if(m_doE) m_e->Fill( p4.E()*toGeV );
-  if(m_doM) m_m->Fill( p4.M()*toGeV );
+  if(j.isAvailable<float>((m_jetScale)+"_pt")){
+    // m_jetScale is a property of the base tool
+    const xAOD::JetFourMom_t p4 = j.jetP4( (xAOD::JetScale) m_jetScale);
+    m_pt->Fill( p4.Pt()*toGeV );
+    m_eta->Fill( p4.Eta() );
+    m_phi->Fill( p4.Phi() );
+    if (p4.Pt()*toGeV > 200.0){ // high eta
+      m_pt_high->Fill( p4.Pt()*toGeV );
+      m_eta_high->Fill( p4.Eta() );
+      if(m_doE) m_e_high->Fill( p4.E()*toGeV );
+      if(m_doM) m_m_high->Fill( p4.M()*toGeV );
+      if(m_doNConstit) m_nConstit_high->Fill( j.numConstituents() );
+    }
+
+    if(m_doE) m_e->Fill( p4.E()*toGeV );
+    if(m_doM) m_m->Fill( p4.M()*toGeV );
   
-  if(m_doOccupancy) m_occupancyEtaPhi->Fill( p4.Eta(), p4.Phi() );
-  if(m_doAveragePt) m_averagePtEtaPhi->Fill( p4.Eta(), p4.Phi() , p4.Pt()*toGeV);
-  if(m_doAverageE) m_averageE_EtaPhi->Fill( p4.Eta(), p4.Phi() , p4.E()*toGeV);
+    if(m_doOccupancy) m_occupancyEtaPhi->Fill( p4.Eta(), p4.Phi() );
+    if(m_doAveragePt) m_averagePtEtaPhi->Fill( p4.Eta(), p4.Phi() , p4.Pt()*toGeV);
+    if(m_doAverageE) m_averageE_EtaPhi->Fill( p4.Eta(), p4.Phi() , p4.E()*toGeV);
+  }
 
   if(m_doNConstit) m_nConstit->Fill( j.numConstituents() );
   return 0;
-- 
GitLab