From ac98d49c23f50d33b735f9856867b19918a7c4ad Mon Sep 17 00:00:00 2001
From: FU Chengdong <fucd@ihep.ac.cn>
Date: Tue, 10 Sep 2024 07:35:26 +0000
Subject: [PATCH] =?UTF-8?q?SIM=EF=BC=9Aadd=20time=20smear=20option=20for?=
 =?UTF-8?q?=20silicon?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Digitisers/SimpleDigi/src/PlanarDigiAlg.cpp | 9 +++++++--
 Digitisers/SimpleDigi/src/PlanarDigiAlg.h   | 2 ++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/Digitisers/SimpleDigi/src/PlanarDigiAlg.cpp b/Digitisers/SimpleDigi/src/PlanarDigiAlg.cpp
index 23e6b9a5..913009e1 100644
--- a/Digitisers/SimpleDigi/src/PlanarDigiAlg.cpp
+++ b/Digitisers/SimpleDigi/src/PlanarDigiAlg.cpp
@@ -232,7 +232,7 @@ StatusCode PlanarDigiAlg::execute()
             << " V[0] = "<< v_direction[0] << " V[1] = "<< v_direction[1]
             << endmsg ;
     
-    float resU(0), resV(0);
+    float resU(0), resV(0), resT(0);
 
     if (!_parameterize) {
       if( (_resU.size() > 1 && layer > _resU.size()-1) || (_resV.size() > 1 && layer > _resV.size()-1) ) {
@@ -260,6 +260,10 @@ StatusCode PlanarDigiAlg::execute()
       resV = _parV[0] + _parV[1] * y + _parV[2] * exp(-_parV[9] * y) * cos(_parV[3] * y + _parV[4])
         + _parV[5] * exp(-0.5 * pow(((y - _parV[6]) / _parV[7]), 2)) + _parV[8] * pow(y, 0.5);
     }
+    // parameterize only for position now, todo
+    resT = ( _resT.size() > 1 ? _resT.value().at(layer) : _resT.value().at(0) );
+    // from ps (input unit) to ns (record unit, Geant4)
+    resT *= CLHEP::ps/CLHEP::ns;
 
     debug() << " --- will smear hit with resU = " << resU << " and resV = " << resV << endmsg;
 
@@ -380,7 +384,8 @@ StatusCode PlanarDigiAlg::execute()
         trkHit.setType( UTIL::set_bit( trkHit.getType() , UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ) ) ;
     }
     trkHit.setEDep( SimTHit.getEDep() );
-    trkHit.setTime( SimTHit.getTime() );
+    trkHit.setTime( SimTHit.getTime() + gsl_ran_gaussian(_rng, resT) );
+
     // make the relation
     auto rel = relCol->create();
 
diff --git a/Digitisers/SimpleDigi/src/PlanarDigiAlg.h b/Digitisers/SimpleDigi/src/PlanarDigiAlg.h
index 3f9dafe5..5924338d 100644
--- a/Digitisers/SimpleDigi/src/PlanarDigiAlg.h
+++ b/Digitisers/SimpleDigi/src/PlanarDigiAlg.h
@@ -77,6 +77,8 @@ protected:
   Gaudi::Property<FloatVec> _resU{ this, "ResolutionU", {0.0040} };
   // resolution in direction of v - either one per layer or one for all layers
   Gaudi::Property<FloatVec> _resV{ this, "ResolutionV", {0.0040} };
+  // resolution of t - either one per layer or one for all layers, unit - ps
+  Gaudi::Property<FloatVec> _resT{ this, "ResolutionT", {0.} };
   // whether hits are 1D strip hits
   Gaudi::Property<bool> _isStrip{ this, "IsStrip", false };
   // whether use Planar tag for type and cov, if true, CEPCConf::TrkHitTypeBit::PLANAR bit is set as true
-- 
GitLab