From 56f982b2b41d2cab9cb1aa670dbe355d4f15ac55 Mon Sep 17 00:00:00 2001
From: Tamara Vazquez Schroeder <tamara.vazquez.schroeder@cern.ch>
Date: Tue, 14 Nov 2017 16:13:51 +0000
Subject: [PATCH] Merge branch '21.0-AFPToF_pulseLength' into '21.0'

Add pulse length information to AFP time-of-flight

See merge request !6504

(cherry picked from commit 6cf4e1db798426fe9c2ae929fa39715001bb915e [formerly 97a75554d63fa9a5ee4952bae5e8fe0947db2a58])

02271e02 AFPSOFT-25 Add information about pulse length in AFP time-of-flight detector
494d17df Updated documentation about pulse length of AFP time-of-flight detector.

Former-commit-id: 5ffccec9dbce89246105f993f8f8187e225f864f
---
 .../xAODForward/xAODForward/versions/AFPToFHit_v1.h   |  6 ++++--
 .../src/AFP_ByteStream2RawCnv.cxx                     |  1 +
 .../AFP/AFP_Raw2Digi/src/AFP_Raw2DigiTool.cxx         |  2 +-
 .../AFP/AFP_Raw2Digi/src/AFP_Raw2DigiTool.h           |  5 +++++
 .../AFP/AFP_RawEv/AFP_RawEv/AFP_ToFRawData.h          | 11 +++++++++++
 5 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/Event/xAOD/xAODForward/xAODForward/versions/AFPToFHit_v1.h b/Event/xAOD/xAODForward/xAODForward/versions/AFPToFHit_v1.h
index ba6dd59fca7..bbbbc3f7b01 100644
--- a/Event/xAOD/xAODForward/xAODForward/versions/AFPToFHit_v1.h
+++ b/Event/xAOD/xAODForward/xAODForward/versions/AFPToFHit_v1.h
@@ -64,8 +64,10 @@ namespace xAOD {
     /// @brief Lenght of the signal pulse which is proportional to the signal
     /// amplitude
     ///
-    /// The returned value is roughly lenght of the signal above
-    /// threshold expressed in nanoseconds.
+    /// The returned value is lenght of the signal above
+    /// threshold expressed in nanoseconds. Available values should be
+    /// multiples of 0.521. Pulse lenght of 1 nanosecond corresponds
+    /// roughtly to signal of about 67 mV.
     float pulseLength() const;
 
     void setPulseLength(float pulseLength);
diff --git a/ForwardDetectors/AFP/AFP_ByteStream2RawCnv/src/AFP_ByteStream2RawCnv.cxx b/ForwardDetectors/AFP/AFP_ByteStream2RawCnv/src/AFP_ByteStream2RawCnv.cxx
index fa1a4566fca..815d4b04cb1 100644
--- a/ForwardDetectors/AFP/AFP_ByteStream2RawCnv/src/AFP_ByteStream2RawCnv.cxx
+++ b/ForwardDetectors/AFP/AFP_ByteStream2RawCnv/src/AFP_ByteStream2RawCnv.cxx
@@ -159,6 +159,7 @@ StatusCode AFP_ByteStream2RawCnv::fillCollection(const OFFLINE_FRAGMENTS_NAMESPA
 	ToFData.setHeader( m_wordReadout.getBits (23, 21) );
 	ToFData.setEdge( m_wordReadout.getBits (20, 20) );
 	ToFData.setChannel( m_wordReadout.getBits (19, 16) );
+	ToFData.setPulseLength( m_wordReadout.getBits (15, 10) );
 	ToFData.setTime( m_wordReadout.getBits (9, 0) );
 
 	setDataHeader (&ToFData);
diff --git a/ForwardDetectors/AFP/AFP_Raw2Digi/src/AFP_Raw2DigiTool.cxx b/ForwardDetectors/AFP/AFP_Raw2Digi/src/AFP_Raw2DigiTool.cxx
index 165cfde9bc5..d846794909e 100644
--- a/ForwardDetectors/AFP/AFP_Raw2Digi/src/AFP_Raw2DigiTool.cxx
+++ b/ForwardDetectors/AFP/AFP_Raw2Digi/src/AFP_Raw2DigiTool.cxx
@@ -119,7 +119,7 @@ void AFP_Raw2DigiTool::newXAODHitToF (xAOD::AFPToFHitContainer* tofHitContainer,
   const uint32_t hitLink = data.link();
   const unsigned int robID = collection.robId();
   xAODToFHit->setTime(data.time()*s_timeConversionFactor);
-  xAODToFHit->setPulseLength(0); // currently there is no information in raw data about pulse length
+  xAODToFHit->setPulseLength(data.pulseLength()*s_pulseLengthFactor); 
   xAODToFHit->setHptdcChannel(data.channel());
 
   // set station ID
diff --git a/ForwardDetectors/AFP/AFP_Raw2Digi/src/AFP_Raw2DigiTool.h b/ForwardDetectors/AFP/AFP_Raw2Digi/src/AFP_Raw2DigiTool.h
index 5ed5aa478e5..9c6a8a4e35b 100644
--- a/ForwardDetectors/AFP/AFP_Raw2Digi/src/AFP_Raw2DigiTool.h
+++ b/ForwardDetectors/AFP/AFP_Raw2Digi/src/AFP_Raw2DigiTool.h
@@ -52,6 +52,11 @@ protected:
   /// The value of the factor is 25/1024 nanoseconds
   static constexpr double s_timeConversionFactor = 25./1024.;
 
+  /// @brief Factor converting pulse length to time
+  ///
+  /// The value of the factor is 0.521 nanoseconds
+  static constexpr double s_pulseLengthFactor = 0.521;
+
   /// @brief Function that transforms time-over-threshold to charge
   ///
   /// Transformation function can be set in steering cards
diff --git a/ForwardDetectors/AFP/AFP_RawEv/AFP_RawEv/AFP_ToFRawData.h b/ForwardDetectors/AFP/AFP_RawEv/AFP_RawEv/AFP_ToFRawData.h
index 043a403740f..597417720d0 100644
--- a/ForwardDetectors/AFP/AFP_RawEv/AFP_RawEv/AFP_ToFRawData.h
+++ b/ForwardDetectors/AFP/AFP_RawEv/AFP_RawEv/AFP_ToFRawData.h
@@ -32,6 +32,10 @@ public:
   uint32_t time() const {return m_time;}
   void setTime(const uint32_t time) {m_time = time;}
 
+  /// @copydoc AFP_ToFRawData::m_pulseLength
+  uint32_t pulseLength() const {return m_pulseLength;}
+  void setPulseLength(const uint32_t pulseLength) {m_pulseLength = pulseLength;}
+
 private:
   /// @brief Value of 9-11 most significant bits
   ///
@@ -61,5 +65,12 @@ private:
   /// In the following record: `xxxx xxxx xxxx xxxx xxxx xxtt tttt tttt`
   /// it means bits marked with `t`. Contains information about time.
   uint32_t m_time;
+
+  /// @brief Value of 11-16 least significant bits
+  ///
+  /// In the following record: `xxxx xxxx xxxx xxxx LLLL LLxx xxxx xxxx`
+  /// it means bits marked with `L`. Contains information how long
+  /// signal from the bar was above threshold.
+  uint32_t m_pulseLength;
 };
 #endif
-- 
GitLab