From eeae921bee20d6d288c71de21b5a4db6832a01af Mon Sep 17 00:00:00 2001
From: "Stephen A. Wood" <saw@jlab.org>
Date: Mon, 19 Nov 2018 11:15:13 -0500
Subject: [PATCH] Change threshold for helicity signals.   For KaonLT, the
 kPulsePedestal values being returned for   the helicity signal channels was 0
 and 16380.  For SIDIS, the   values for off and on are ~2000 and ~1400.  Made
 the default   threshold 8000 instead of 1000.  Also added an optional
 parameter,   "helicity_fadcthreshold" so that this threshold can be changed  
 at run time.

---
 src/THcHelicityReader.cxx | 27 +++++++++++++++++++--------
 src/THcHelicityReader.h   |  2 ++
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/THcHelicityReader.cxx b/src/THcHelicityReader.cxx
index e956fd1..6681430 100644
--- a/src/THcHelicityReader.cxx
+++ b/src/THcHelicityReader.cxx
@@ -8,6 +8,8 @@
 
 #include "THcHelicityReader.h"
 #include "THaEvData.h"
+#include "THcGlobals.h"
+#include "THcParmList.h"
 #include "TMath.h"
 #include "TError.h"
 #include "VarDef.h"
@@ -59,6 +61,15 @@ Int_t THcHelicityReader::ReadDatabase( const char* /*dbfilename*/,
   SetROCinfo(kMPS,2,14,10);
   SetROCinfo(kQrt,2,14,7);
   SetROCinfo(kTime,2,21,2);
+  
+  fADCThreshold = 8000;
+  
+  DBRequest list[] = {
+    {"helicity_adcthreshold",&fADCThreshold, kInt, 0, 1},
+    {0}
+  };
+
+  gHcParms->LoadParmValues(list, "");
 
   return THaAnalysisObject::kOK;
 }
@@ -124,27 +135,27 @@ Int_t THcHelicityReader::ReadData( const THaEvData& evdata )
   // Get the helicity control signals.  These are from the pedestals
   // acquired by FADC channels.
 
-  UInt_t helpraw = evdata.GetData(Decoder::kPulsePedestal,
+  Int_t helpraw = evdata.GetData(Decoder::kPulsePedestal,
 				  fROCinfo[kHel].roc,
 				  fROCinfo[kHel].slot,
 				  fROCinfo[kHel].index, 0);
-  UInt_t helmraw = evdata.GetData(Decoder::kPulsePedestal,
+  Int_t helmraw = evdata.GetData(Decoder::kPulsePedestal,
 				  fROCinfo[kHelm].roc,
 				  fROCinfo[kHelm].slot,
 				  fROCinfo[kHelm].index, 0);
-  UInt_t mpsraw = evdata.GetData(Decoder::kPulsePedestal,
+  Int_t mpsraw = evdata.GetData(Decoder::kPulsePedestal,
 				  fROCinfo[kMPS].roc,
 				  fROCinfo[kMPS].slot,
 				  fROCinfo[kMPS].index, 0);
-  UInt_t qrtraw = evdata.GetData(Decoder::kPulsePedestal,
+  Int_t qrtraw = evdata.GetData(Decoder::kPulsePedestal,
 				  fROCinfo[kQrt].roc,
 				  fROCinfo[kQrt].slot,
 				  fROCinfo[kQrt].index, 0);
 
-  fIsQrt = qrtraw > 1000;
-  fIsMPS = mpsraw > 1000;
-  fIsHelp = helpraw > 1000;
-  fIsHelm = helmraw > 1000;
+  fIsQrt = qrtraw > fADCThreshold;
+  fIsMPS = mpsraw > fADCThreshold;
+  fIsHelp = helpraw > fADCThreshold;
+  fIsHelm = helmraw > fADCThreshold;
 
   return 0;
 }
diff --git a/src/THcHelicityReader.h b/src/THcHelicityReader.h
index a65ad13..c594628 100644
--- a/src/THcHelicityReader.h
+++ b/src/THcHelicityReader.h
@@ -52,6 +52,8 @@ protected:
   Bool_t fIsHelp;
   Bool_t fIsHelm;
 
+  Int_t fADCThreshold;		// Threshold for On/Off of helicity signals
+
   ROCinfo  fROCinfo[kCount];
 
   Int_t    fQWEAKDebug;          // Debug level
-- 
GitLab