From 8be65bf038438a3889f8e02cfb4f2aa081a336c7 Mon Sep 17 00:00:00 2001
From: Vadim Kostyukhin <vadim.kostyukhin@cern.ch>
Date: Wed, 17 Mar 2021 11:13:56 +0100
Subject: [PATCH] Add Z reco-truth histograms for identified Primary Vertex

---
 .../share/InDetPVMPlotDefCommon.xml                  |  8 ++++++++
 .../src/InDetPerfPlot_VertexTruthMatching.cxx        | 12 +++++++++++-
 .../src/InDetPerfPlot_VertexTruthMatching.h          |  4 +++-
 .../InDetPhysValMonitoring/src/InDetRttPlots.cxx     |  3 ++-
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/InnerDetector/InDetValidation/InDetPhysValMonitoring/share/InDetPVMPlotDefCommon.xml b/InnerDetector/InDetValidation/InDetPhysValMonitoring/share/InDetPVMPlotDefCommon.xml
index 91db4d14cd2d..3734b95fc86d 100644
--- a/InnerDetector/InDetValidation/InDetPhysValMonitoring/share/InDetPVMPlotDefCommon.xml
+++ b/InnerDetector/InDetValidation/InDetPhysValMonitoring/share/InDetPVMPlotDefCommon.xml
@@ -756,6 +756,14 @@
   <x title="Vertex Truth-Matched type" n="5" lo="-0.5" hi="4.5"/>
   <y title="Entries"/>
 </h>
+<h id="vx_z_diff" type="TH1F" title="PV selected-truth Z difference">
+  <x title="Vertex Truth-Matched type" n="100" lo="-0.5" hi="0.5"/>
+  <y title="Entries"/>
+</h>
+<h id="vx_z_diff_pull" type="TH1F" title="PV selected-truth Z difference pull">
+  <x title="Vertex Truth-Matched type" n="100" lo="-5.0" hi="5.0"/>
+  <y title="Entries"/>
+</h>
 <h id="vx_hs_classification" type="TH1F" title="Event hardscatter vertex classification">
   <x title="Hardscatter classification" n="5" lo="-0.5" hi="4.5"/>
   <y title="Entries"/>
diff --git a/InnerDetector/InDetValidation/InDetPhysValMonitoring/src/InDetPerfPlot_VertexTruthMatching.cxx b/InnerDetector/InDetValidation/InDetPhysValMonitoring/src/InDetPerfPlot_VertexTruthMatching.cxx
index 5b1ff7314bb9..b0a4d3b19efd 100644
--- a/InnerDetector/InDetValidation/InDetPhysValMonitoring/src/InDetPerfPlot_VertexTruthMatching.cxx
+++ b/InnerDetector/InDetValidation/InDetPhysValMonitoring/src/InDetPerfPlot_VertexTruthMatching.cxx
@@ -81,6 +81,8 @@ InDetPerfPlot_VertexTruthMatching::InDetPerfPlot_VertexTruthMatching(InDetPlotBa
 void InDetPerfPlot_VertexTruthMatching::initializePlots() {
 
     book(m_vx_type_truth,"vx_type_truth");
+    book(m_vx_z_diff,"vx_z_diff");
+    book(m_vx_z_diff_pull,"vx_z_diff_pull");
     if (m_iDetailLevel >= 200) {
         book(m_vx_hs_classification,"vx_hs_classification");
         book(m_vx_nReco_vs_nTruth_inclusive,"vx_nReco_vs_nTruth_inclusive");
@@ -314,7 +316,15 @@ const xAOD::TruthVertex* InDetPerfPlot_VertexTruthMatching::getTruthVertex(const
     return truthVtx;
 }
 
-void InDetPerfPlot_VertexTruthMatching::fill(const xAOD::Vertex& vertex) {
+void InDetPerfPlot_VertexTruthMatching::fill(const xAOD::Vertex& vertex, const xAOD::TruthVertex * tvrt) {
+
+    if(tvrt){
+      float diff_z=vertex.z()-tvrt->z();
+      const AmgSymMatrix(3)& covariance = vertex.covariancePosition();
+      float err_z = fabs(Amg::error(covariance, 2)) > 1e-7 ? Amg::error(covariance, 2) : 1000.;
+      fillHisto(m_vx_z_diff,diff_z);
+      fillHisto(m_vx_z_diff_pull,diff_z/err_z);
+    }
 
     // Get the match type info for each vertex:
     const static xAOD::Vertex::Decorator<InDetVertexTruthMatchUtils::VertexMatchType> recoVtxMatchTypeInfo("VertexMatchType");
diff --git a/InnerDetector/InDetValidation/InDetPhysValMonitoring/src/InDetPerfPlot_VertexTruthMatching.h b/InnerDetector/InDetValidation/InDetPhysValMonitoring/src/InDetPerfPlot_VertexTruthMatching.h
index 31574711c13c..6ac0364c84b3 100644
--- a/InnerDetector/InDetValidation/InDetPhysValMonitoring/src/InDetPerfPlot_VertexTruthMatching.h
+++ b/InnerDetector/InDetValidation/InDetPhysValMonitoring/src/InDetPerfPlot_VertexTruthMatching.h
@@ -41,13 +41,15 @@
 class InDetPerfPlot_VertexTruthMatching: public InDetPlotBase {
 public:
     InDetPerfPlot_VertexTruthMatching(InDetPlotBase* pParent, const std::string& dirName, const int iDetailLevel = 10);
-    void fill(const xAOD::Vertex& vertex);
+    void fill(const xAOD::Vertex& vertex, const xAOD::TruthVertex * tvrt =0);
     void fill(const xAOD::VertexContainer& vertexContainer, const std::vector<const xAOD::TruthVertex*>& truthHSVertices, const std::vector<const xAOD::TruthVertex*>& truthPUVertices);
 private:
     int m_iDetailLevel;
     float m_cutMinTruthRecoRadialDiff = 0.1;
     ///truth type
     TH1* m_vx_type_truth;
+    TH1* m_vx_z_diff;
+    TH1* m_vx_z_diff_pull;
     ///hardscatter classification
     TH1* m_vx_hs_classification;
     ///vertex reco efficiency
diff --git a/InnerDetector/InDetValidation/InDetPhysValMonitoring/src/InDetRttPlots.cxx b/InnerDetector/InDetValidation/InDetPhysValMonitoring/src/InDetRttPlots.cxx
index 40e248f9add5..99983a58236f 100644
--- a/InnerDetector/InDetValidation/InDetPhysValMonitoring/src/InDetRttPlots.cxx
+++ b/InnerDetector/InDetValidation/InDetPhysValMonitoring/src/InDetRttPlots.cxx
@@ -316,7 +316,8 @@ InDetRttPlots::fill(const xAOD::VertexContainer& vertexContainer, const std::vec
     ATH_MSG_DEBUG("IN InDetRttPlots::fill, filling for all vertices");
     if (vtx->vertexType() == xAOD::VxType::PriVtx) {
       m_hardScatterVertexPlots.fill(*vtx);
-      m_hardScatterVertexTruthMatchingPlots.fill(*vtx);
+      if(truthHSVertices.size()>0)m_hardScatterVertexTruthMatchingPlots.fill(*vtx,truthHSVertices[0]);
+      else m_hardScatterVertexTruthMatchingPlots.fill(*vtx);
       ATH_MSG_DEBUG("IN InDetRttPlots::fill, filling for all HS vertex");
     }
   }
-- 
GitLab