From b3eb5a431eda7f06517fc24b991053424f07c902 Mon Sep 17 00:00:00 2001
From: hallc-online <hallc-online@jlab.org>
Date: Tue, 4 Apr 2017 12:43:09 -0400
Subject: [PATCH] Fix mistake in THcShowerArray and make the threshold a
 parameter

THcShowerArray
1) in ProcessHits methodfFixed mistake in index of fThresh
   was using padnum instead of padnum-1
2) add parameter pcal_arr_AdcThreshold so that threshold
   can be set by a parameter. Default is zero which gives
   the best resolution.

THcShowerPlane
1) Added the parameter cal_AdcNegThreshold and cal_AdcPosThreshold
   so that the threshold can be set through a parameter
   Previously it was hardcoded.
---
 src/THcShowerArray.cxx |  4 +++-
 src/THcShowerArray.h   |  1 +
 src/THcShowerPlane.cxx | 13 ++++++++-----
 src/THcShowerPlane.h   |  2 ++
 4 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/THcShowerArray.cxx b/src/THcShowerArray.cxx
index 63e5357..6473d6f 100644
--- a/src/THcShowerArray.cxx
+++ b/src/THcShowerArray.cxx
@@ -128,6 +128,7 @@ Int_t THcShowerArray::ReadDatabase( const TDatime& date )
     {"cal_arr_ADCMode", &fADCMode, kInt, 0, 1},
     {"cal_arr_AdcTimeWindowMin", &fAdcTimeWindowMin, kDouble, 0, 1},
     {"cal_arr_AdcTimeWindowMax", &fAdcTimeWindowMax, kDouble, 0, 1},
+    {"cal_arr_AdcThreshold", &fAdcThreshold, kDouble, 0, 1},
     {"cal_ped_sample_low", &fPedSampLow, kInt, 0, 1},
     {"cal_ped_sample_high", &fPedSampHigh, kInt, 0, 1},
     {"cal_data_sample_low", &fDataSampLow, kInt, 0, 1},
@@ -138,6 +139,7 @@ Int_t THcShowerArray::ReadDatabase( const TDatime& date )
   fADCMode=kADCDynamicPedestal;
   fAdcTimeWindowMin=0;
   fAdcTimeWindowMax=10000;
+  fAdcThreshold=0.;
   fNelem = fNRows*fNColumns;
 
   fXPos = new Double_t* [fNRows];
@@ -791,7 +793,7 @@ Int_t THcShowerArray::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
     //
     for (UInt_t thit=0; thit<rawAdcHit.GetNPulses(); ++thit) {
       ((THcSignalHit*) frAdcPedRaw->ConstructedAt(nrAdcHits))->Set(padnum, rawAdcHit.GetPedRaw());
-        fThresh[padnum]=rawAdcHit.GetPedRaw()*rawAdcHit.GetF250_PeakPedestalRatio()+250.;
+        fThresh[padnum-1]=rawAdcHit.GetPedRaw()*rawAdcHit.GetF250_PeakPedestalRatio()+fAdcThreshold;
      ((THcSignalHit*) frAdcPed->ConstructedAt(nrAdcHits))->Set(padnum, rawAdcHit.GetPed());
 
       ((THcSignalHit*) frAdcPulseIntRaw->ConstructedAt(nrAdcHits))->Set(padnum, rawAdcHit.GetPulseIntRaw(thit));
diff --git a/src/THcShowerArray.h b/src/THcShowerArray.h
index 4b178cb..9206f77 100644
--- a/src/THcShowerArray.h
+++ b/src/THcShowerArray.h
@@ -113,6 +113,7 @@ protected:
   static const Int_t kADCSampIntDynPed=3;
   Double_t fAdcTimeWindowMin ;
   Double_t fAdcTimeWindowMax ;
+  Double_t fAdcThreshold ;
 Int_t fPedSampLow;		// Sample range for
   Int_t fPedSampHigh;		// dynamic pedestal
   Int_t fDataSampLow;		// Sample range for
diff --git a/src/THcShowerPlane.cxx b/src/THcShowerPlane.cxx
index 0a9452d..2553ee1 100644
--- a/src/THcShowerPlane.cxx
+++ b/src/THcShowerPlane.cxx
@@ -134,13 +134,15 @@ Int_t THcShowerPlane::ReadDatabase( const TDatime& date )
   char prefix[2];
   prefix[0]=tolower(GetParent()->GetPrefix()[0]);
   prefix[1]='\0';
-  fUsingFADC=0;
   fPedSampLow=0;
   fPedSampHigh=9;
   fDataSampLow=23;
   fDataSampHigh=49;
+    fAdcNegThreshold=0.;
+    fAdcPosThreshold=0.;
   DBRequest list[]={
-    {"cal_using_fadc", &fUsingFADC, kInt, 0, 1},
+    {"cal_AdcNegThreshold", &fAdcNegThreshold, kDouble, 0, 1},
+    {"cal_AdcPosThreshold", &fAdcPosThreshold, kDouble, 0, 1},
     {"cal_ped_sample_low", &fPedSampLow, kInt, 0, 1},
     {"cal_ped_sample_high", &fPedSampHigh, kInt, 0, 1},
     {"cal_data_sample_low", &fDataSampLow, kInt, 0, 1},
@@ -431,7 +433,8 @@ Int_t THcShowerPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
     THcRawAdcHit& rawPosAdcHit = hit->GetRawAdcHitPos();
     for (UInt_t thit=0; thit<rawPosAdcHit.GetNPulses(); ++thit) {
       ((THcSignalHit*) frPosAdcPedRaw->ConstructedAt(nrPosAdcHits))->Set(padnum, rawPosAdcHit.GetPedRaw());
-       fPosThresh[hit->fCounter -1]=rawPosAdcHit.GetPedRaw()*rawPosAdcHit.GetF250_PeakPedestalRatio()+250.;
+       fPosThresh[hit->fCounter -1]=rawPosAdcHit.GetPedRaw()*rawPosAdcHit.GetF250_PeakPedestalRatio()+fAdcPosThreshold;
+       
       ((THcSignalHit*) frPosAdcPed->ConstructedAt(nrPosAdcHits))->Set(padnum, rawPosAdcHit.GetPed());
 
       ((THcSignalHit*) frPosAdcPulseIntRaw->ConstructedAt(nrPosAdcHits))->Set(padnum, rawPosAdcHit.GetPulseIntRaw(thit));
@@ -451,7 +454,7 @@ Int_t THcShowerPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
     THcRawAdcHit& rawNegAdcHit = hit->GetRawAdcHitNeg();
     for (UInt_t thit=0; thit<rawNegAdcHit.GetNPulses(); ++thit) {
       ((THcSignalHit*) frNegAdcPedRaw->ConstructedAt(nrNegAdcHits))->Set(padnum, rawNegAdcHit.GetPedRaw());
-       fNegThresh[hit->fCounter -1]=rawNegAdcHit.GetPedRaw()*rawNegAdcHit.GetF250_PeakPedestalRatio()+250.;
+       fNegThresh[hit->fCounter -1]=rawNegAdcHit.GetPedRaw()*rawNegAdcHit.GetF250_PeakPedestalRatio()+fAdcNegThreshold;
       ((THcSignalHit*) frNegAdcPed->ConstructedAt(nrNegAdcHits))->Set(padnum, rawNegAdcHit.GetPed());
 
       ((THcSignalHit*) frNegAdcPulseIntRaw->ConstructedAt(nrNegAdcHits))->Set(padnum, rawNegAdcHit.GetPulseIntRaw(thit));
@@ -564,7 +567,7 @@ void THcShowerPlane::FillADC_Standard()
     Int_t npad = ((THcSignalHit*) frPosAdcPulseIntRaw->ConstructedAt(ielem))->GetPaddleNumber() - 1;
     Double_t pulseIntRaw = ((THcSignalHit*) frPosAdcPulseIntRaw->ConstructedAt(ielem))->GetData();
       fA_Pos[npad] =pulseIntRaw;
-      if(fA_Pos[npad] >  fPosThresh[npad]) {
+      if(fA_Pos[npad] > fPosThresh[npad]) {
        fA_Pos_p[npad] =pulseIntRaw-fPosPed[npad] ;
        fEpos[npad] = fA_Pos_p[npad]*fParent->GetGain(npad,fLayerNum-1,0);
        fEmean[npad] += fEpos[npad];
diff --git a/src/THcShowerPlane.h b/src/THcShowerPlane.h
index fe00766..1c84d1a 100644
--- a/src/THcShowerPlane.h
+++ b/src/THcShowerPlane.h
@@ -122,6 +122,8 @@ protected:
   Int_t fPedSampHigh;		// dynamic pedestal
   Int_t fDataSampLow;		// Sample range for
   Int_t fDataSampHigh;		// sample integration
+  Double_t fAdcNegThreshold;		// 
+  Double_t fAdcPosThreshold;		// 
 
   Double_t*   fA_Pos;         // [fNelem] ADC amplitudes of blocks
   Double_t*   fA_Neg;         // [fNelem] ADC amplitudes of blocks
-- 
GitLab