From c706ae5c49ca8cc827441e45a21a3bafe5c6298a Mon Sep 17 00:00:00 2001
From: Tobias Boeckh <tobias.boeckh@cern.ch>
Date: Mon, 24 Jan 2022 09:26:35 +0100
Subject: [PATCH] smear true measurements

---
 .../FaserActsKalmanFilter/TruthTrackFinderTool.h    |  4 ++++
 .../python/FaserActsKalmanFilterConfig.py           | 13 +++++++------
 .../src/TruthTrackFinderTool.cxx                    | 13 ++++++++++---
 3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/Tracking/Acts/FaserActsKalmanFilter/FaserActsKalmanFilter/TruthTrackFinderTool.h b/Tracking/Acts/FaserActsKalmanFilter/FaserActsKalmanFilter/TruthTrackFinderTool.h
index 078fbc58f..3753c62f4 100644
--- a/Tracking/Acts/FaserActsKalmanFilter/FaserActsKalmanFilter/TruthTrackFinderTool.h
+++ b/Tracking/Acts/FaserActsKalmanFilter/FaserActsKalmanFilter/TruthTrackFinderTool.h
@@ -58,6 +58,10 @@ private:
   ToolHandle<IFaserActsTrackingGeometryTool> m_trackingGeometryTool {
     this, "TrackingGeometryTool", "FaserActsTrackingGeometryTool"};
 
+  // smearing of measurements
+  Gaudi::Property<double> m_sigma0 {this, "sigma0", 0.02};
+  Gaudi::Property<double> m_sigma1 {this, "sigma1", 0.02};
+
   // covariance of the measurements
   Gaudi::Property<double> m_covMeasLoc0 {this, "covMeasLoc0", 0.01};
   Gaudi::Property<double> m_covMeasLoc1 {this, "covMeasLoc1", 0.01};
diff --git a/Tracking/Acts/FaserActsKalmanFilter/python/FaserActsKalmanFilterConfig.py b/Tracking/Acts/FaserActsKalmanFilter/python/FaserActsKalmanFilterConfig.py
index cd1470325..2ad993a09 100644
--- a/Tracking/Acts/FaserActsKalmanFilter/python/FaserActsKalmanFilterConfig.py
+++ b/Tracking/Acts/FaserActsKalmanFilter/python/FaserActsKalmanFilterConfig.py
@@ -54,12 +54,13 @@ def FaserActsKalmanFilterCfg(flags, **kwargs):
     acc = ComponentAccumulator()
     trajectory_writer_tool = CompFactory.TrajectoryWriterTool()
     trajectory_writer_tool.FilePath = "KalmanFilterTrajectories.root"
-    track_finder_tool = CompFactory.TruthSeededTrackFinderTool()
-    track_finder_tool.covLoc0 = 1e-3
-    track_finder_tool.covLoc1 = 1e-3
-    track_finder_tool.covPhi = 1e-3
-    track_finder_tool.covTheta = 1e-3
-    track_finder_tool.covQOverP = 1e-3
+    track_finder_tool = CompFactory.TruthTrackFinderTool()
+    # track_finder_tool = CompFactory.TruthSeededTrackFinderTool()
+    # track_finder_tool.covLoc0 = 1e-1
+    # track_finder_tool.covLoc1 = 1e-1
+    # track_finder_tool.covPhi = 1e-1
+    # track_finder_tool.covTheta = 1e-1
+    # track_finder_tool.covQOverP = 1e-1
     kalman_filter = CompFactory.FaserActsKalmanFilterAlg(**kwargs)
     kalman_filter.OutputTool = trajectory_writer_tool
     kalman_filter.TrackFinderTool = track_finder_tool
diff --git a/Tracking/Acts/FaserActsKalmanFilter/src/TruthTrackFinderTool.cxx b/Tracking/Acts/FaserActsKalmanFilter/src/TruthTrackFinderTool.cxx
index 98f684502..920cce2dc 100644
--- a/Tracking/Acts/FaserActsKalmanFilter/src/TruthTrackFinderTool.cxx
+++ b/Tracking/Acts/FaserActsKalmanFilter/src/TruthTrackFinderTool.cxx
@@ -13,6 +13,7 @@
 #include "TrackerReadoutGeometry/SCT_DetectorManager.h"
 #include "TrackerReadoutGeometry/SiDetectorElement.h"
 #include <array>
+#include <random>
 
 
 TruthTrackFinderTool::TruthTrackFinderTool(const std::string& type, const std::string& name, const IInterface* parent)
@@ -99,12 +100,18 @@ StatusCode TruthTrackFinderTool::run() {
         ATH_MSG_FATAL("Could not construct bound parameters");
         return StatusCode::FAILURE;
       }
-      const auto &boundParams = boundParamsRes.value();
+      const ParametersVector &boundParams = boundParamsRes.value();
       ATH_MSG_DEBUG(boundParams[0] << ", " << boundParams[1]);
 
+      std::random_device rd;
+      std::default_random_engine rng {rd()};
+      std::normal_distribution<> norm;
+
+      ParametersVector smearedBoundParams = {boundParams[0] * norm(rng) * m_sigma0, boundParams[1] * norm(rng) * m_sigma1};
+
       ParametersVector par = ParametersVector::Zero();
-      par[0] = boundParams[0];
-      par[1] = boundParams[1];
+      par[0] = smearedBoundParams[0];
+      par[1] = smearedBoundParams[1];
 
       CovarianceMatrix cov = CovarianceMatrix::Zero();
       cov(0, 0) = m_covMeasLoc0;
-- 
GitLab