From cde957e109f4903c0542f5cde1141ef830ad8e24 Mon Sep 17 00:00:00 2001
From: John Derek Chapman <chapman@hep.phy.cam.ac.uk>
Date: Wed, 25 Mar 2020 13:04:16 +0000
Subject: [PATCH] Merge branch 'introduceErrorParametrizationForCentroid' into
 '21.3'

Adding error parametrization for MM simple clustering

See merge request atlas/athena!31452

(cherry picked from commit f19ab7322248bb41b1d335a2a858f2a1ed941384)

791cd9d4  adding parametrization of error of MM simple clustering; adding job option to switch it on or off
c75843ec fixing error for one strip clusters
---
 .../src/SimpleMMClusterBuilderTool.cxx              | 13 +++++++++++--
 .../src/SimpleMMClusterBuilderTool.h                |  2 ++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MMClusterization/src/SimpleMMClusterBuilderTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MMClusterization/src/SimpleMMClusterBuilderTool.cxx
index b583d97411bb..13e84b367a21 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MMClusterization/src/SimpleMMClusterBuilderTool.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MMClusterization/src/SimpleMMClusterBuilderTool.cxx
@@ -17,6 +17,7 @@ Muon::SimpleMMClusterBuilderTool::SimpleMMClusterBuilderTool(const std::string&
   m_mmIdHelper(nullptr)
 {
   declareInterface<IMMClusterBuilderTool>(this);
+  declareProperty("useErrorParametrization",m_useErrorParametrization=false);
 
 }
 
@@ -165,6 +166,7 @@ StatusCode Muon::SimpleMMClusterBuilderTool::getClusters(std::vector<Muon::MMPre
     double weightedPosX = 0.0;
     double posY = 0.0;
     double totalCharge = 0.0;
+    double theta = 0.0;
     if ( mergeStrips.size() > 0 ) { 
       /// get the Y local position from the first strip ( it's the same for all strips in the cluster)
       posY = MMprds[mergeIndices[0]].localPosition().y();
@@ -173,9 +175,11 @@ StatusCode Muon::SimpleMMClusterBuilderTool::getClusters(std::vector<Muon::MMPre
 	double charge = MMprds[mergeIndices[k]].charge();
 	weightedPosX += posX*charge;
 	totalCharge += charge;
+  theta += std::atan(MMprds[mergeIndices[k]].globalPosition().perp()/std::abs(MMprds[mergeIndices[k]].globalPosition().z()))*charge;
 	ATH_MSG_VERBOSE("Adding a strip to the centroid calculation: charge=" << charge);
       } 
       weightedPosX = weightedPosX/totalCharge;
+      theta /= totalCharge;
     }
 
     
@@ -188,8 +192,13 @@ StatusCode Muon::SimpleMMClusterBuilderTool::getClusters(std::vector<Muon::MMPre
     ///
     Amg::MatrixX* covN = new Amg::MatrixX(1,1);
     covN->setIdentity();
-    (*covN)(0,0) = 6.*(nmerge + 1.)*covX;
-    if(nmerge<=1) (*covN)(0,0) = covX;
+    if(!m_useErrorParametrization) {
+      (*covN)(0,0) = 6.*(nmerge + 1.)*covX;
+      if(nmerge<=1) (*covN)(0,0) = covX;
+    } else {
+      double localUncertainty = 0.074+0.66*theta-0.15*theta*theta;
+      (*covN)(0,0) = localUncertainty * localUncertainty;
+    }
     ATH_MSG_VERBOSE(" make merged prepData at strip " << m_mmIdHelper->channel(MMprds[j].identify()) << " nmerge " << nmerge << " sqrt covX " << sqrt((*covN)(0,0)));
     
     ///
diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MMClusterization/src/SimpleMMClusterBuilderTool.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MMClusterization/src/SimpleMMClusterBuilderTool.h
index a5c2164b7216..a32cacefcfd7 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MMClusterization/src/SimpleMMClusterBuilderTool.h
+++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MMClusterization/src/SimpleMMClusterBuilderTool.h
@@ -44,6 +44,8 @@ namespace Muon
     /// Muon Detector Descriptor
     const MuonGM::MuonDetectorManager* m_muonMgr;
     const MmIdHelper* m_mmIdHelper;
+
+    bool m_useErrorParametrization;
     
 };
 
-- 
GitLab