From 7878074b5c3617fb170129c62072caac05592f2a Mon Sep 17 00:00:00 2001
From: Jure Bericic <bericic@jlab.org>
Date: Fri, 24 Feb 2017 10:30:46 -0500
Subject: [PATCH] Added capability to set F250 parameters from PSE125.

PSE125 holds information about setting of F250 modules. Now this
information is used to set `fNPedestalSamples` and `fNPeakSamples`
parameters of `THcRawAdcHit`.

This is done through `THcHitList`, since it has information about
which crate and module each channel is in. Currently, the information
is set for each event, because of the hitlist and analyzer design.

I added the neccessary support for these changes to all raw hit
classes.
---
 src/THcHitList.cxx      | 19 +++++++++++++++++++
 src/THcHitList.h        |  3 +++
 src/THcRawAdcHit.cxx    | 15 +++++++++++++++
 src/THcRawAdcHit.h      |  2 ++
 src/THcRawHit.h         |  2 ++
 src/THcRawHodoHit.cxx   |  7 +++++++
 src/THcRawHodoHit.h     |  2 ++
 src/THcRawShowerHit.cxx |  7 +++++++
 src/THcRawShowerHit.h   |  2 ++
 src/THcTrigRawHit.cxx   | 12 ++++++++++++
 src/THcTrigRawHit.h     |  2 ++
 11 files changed, 73 insertions(+)

diff --git a/src/THcHitList.cxx b/src/THcHitList.cxx
index 0697618..4569782 100644
--- a/src/THcHitList.cxx
+++ b/src/THcHitList.cxx
@@ -10,6 +10,10 @@
 #include "TError.h"
 #include "TClass.h"
 
+#include "THcConfigEvtHandler.h"
+#include "THaGlobals.h"
+#include "TList.h"
+
 using namespace std;
 
 THcHitList::THcHitList()
@@ -17,6 +21,7 @@ THcHitList::THcHitList()
   // Normal constructor.
 
   fRawHitList = NULL;
+  fPSE125 = NULL;
 
 }
 
@@ -101,6 +106,10 @@ void THcHitList::InitHitList(THaDetMap* detmap,
     }
   }
 
+  fPSE125 = static_cast<THcConfigEvtHandler*>(gHaEvtHandlers->FindObject("HC"));
+  if (!fPSE125) {
+    cout << "THcHitList::InitHitList : Prestart event 125 not found." << endl;
+  }
 }
 
 Int_t THcHitList::DecodeToHitList( const THaEvData& evdata ) {
@@ -112,6 +121,7 @@ Int_t THcHitList::DecodeToHitList( const THaEvData& evdata ) {
   // hits for multihit tdcs.
   // The hit list is sorted (by plane, counter) after filling.
 
+
   // cout << " Clearing TClonesArray " << endl;
   fRawHitList->Clear( );
   fNRawHits = 0;
@@ -212,6 +222,15 @@ Int_t THcHitList::DecodeToHitList( const THaEvData& evdata ) {
 	  }
 	}
       } else {			// This is a Flash ADC
+
+        if (fPSE125) {  // Set F250 parameters.
+          rawhit->SetF250Params(
+            fPSE125->GetNSA(d->crate),
+            fPSE125->GetNSB(d->crate),
+            fPSE125->GetNPED(d->crate)
+          );
+        }
+
 	// Copy the samples
 	Int_t nsamples=evdata.GetNumEvents(Decoder::kSampleADC, d->crate, d->slot, chan);
 
diff --git a/src/THcHitList.h b/src/THcHitList.h
index 8f3bc81..9ab0722 100644
--- a/src/THcHitList.h
+++ b/src/THcHitList.h
@@ -18,6 +18,7 @@ using namespace std;
 //////////////////////////////////////////////////////////////////////////
 
 //class THaDetMap;
+class THcConfigEvtHandler;
 
 class THcHitList {
 
@@ -58,6 +59,8 @@ protected:
   UInt_t fNSignals;
   THcRawHit::ESignalType *fSignalTypes;
 
+  THcConfigEvtHandler* fPSE125;
+
   ClassDef(THcHitList,0);  // List of raw hits sorted by plane, counter
 };
 #endif
diff --git a/src/THcRawAdcHit.cxx b/src/THcRawAdcHit.cxx
index e35c5f5..508b39b 100644
--- a/src/THcRawAdcHit.cxx
+++ b/src/THcRawAdcHit.cxx
@@ -167,6 +167,14 @@ Returns 0 if no signal pedestal is set.
 \brief Gets pedestal subtracted integral of samples. In channels.
 */
 
+/**
+\fn void THcRawAdcHit::SetF250Params(Int_t NSA, Int_t NSB, Int_t NPED)
+\brief Sets F250 parameters used for pedestal subtraction.
+\param [in] NSA NSA parameter of F250 modules.
+\param [in] NSB NSB parameter of F250 modules.
+\param [in] NPED NPED parameter of F250 modules.
+*/
+
 // TODO: Disallow using both SetData and SetDataTimePedestalPeak.
 
 
@@ -450,4 +458,11 @@ Double_t THcRawAdcHit::GetSampleInt() const {
 }
 
 
+void THcRawAdcHit::SetF250Params(Int_t NSA, Int_t NSB, Int_t NPED) {
+  fNPedestalSamples = NPED;
+  fNPeakSamples = NSA + NSB;
+  fPeakPedestalRatio = 1.0*fNPeakSamples/fNPedestalSamples;
+}
+
+
 ClassImp(THcRawAdcHit)
diff --git a/src/THcRawAdcHit.h b/src/THcRawAdcHit.h
index 210dfbc..82a1922 100644
--- a/src/THcRawAdcHit.h
+++ b/src/THcRawAdcHit.h
@@ -46,6 +46,8 @@ class THcRawAdcHit : public TObject {
     Int_t GetSampleIntRaw() const;
     Double_t GetSampleInt() const;
 
+    void SetF250Params(Int_t NSA, Int_t NSB, Int_t NPED);
+
   protected:
     static const UInt_t fMaxNPulses = 4;
     static const UInt_t fMaxNSamples = 511;
diff --git a/src/THcRawHit.h b/src/THcRawHit.h
index 9406e25..e56674f 100644
--- a/src/THcRawHit.h
+++ b/src/THcRawHit.h
@@ -42,6 +42,8 @@ public:
   virtual Bool_t HasReference(Int_t signal) {return kFALSE;};
   virtual Int_t GetReference(Int_t signal) {return 0;};
 
+  virtual void SetF250Params(Int_t NSA, Int_t NSB, Int_t NPED) {};
+
   // Derived objects must be sortable and supply Compare method
   //  virtual Bool_t  IsSortable () const {return kFALSE; }
   //  virtual Int_t   Compare(const TObject* obj) const {return 0;}
diff --git a/src/THcRawHodoHit.cxx b/src/THcRawHodoHit.cxx
index fa1407e..db2d487 100644
--- a/src/THcRawHodoHit.cxx
+++ b/src/THcRawHodoHit.cxx
@@ -198,4 +198,11 @@ THcRawTdcHit& THcRawHodoHit::GetRawTdcHitNeg() {
 }
 
 
+void THcRawHodoHit::SetF250Params(Int_t NSA, Int_t NSB, Int_t NPED) {
+  for (Int_t iAdcSig=0; iAdcSig<fNAdcSignals; ++iAdcSig) {
+    fAdcHits[iAdcSig].SetF250Params(NSA, NSB, NPED);
+  }
+}
+
+
 ClassImp(THcRawHodoHit)
diff --git a/src/THcRawHodoHit.h b/src/THcRawHodoHit.h
index 679d36f..dc2528f 100644
--- a/src/THcRawHodoHit.h
+++ b/src/THcRawHodoHit.h
@@ -39,6 +39,8 @@ class THcRawHodoHit : public THcRawHit {
     THcRawTdcHit& GetRawTdcHitPos();
     THcRawTdcHit& GetRawTdcHitNeg();
 
+    void SetF250Params(Int_t NSA, Int_t NSB, Int_t NPED);
+
   protected:
     static const Int_t fNAdcSignals = 2;
     static const Int_t fNTdcSignals = 2;
diff --git a/src/THcRawShowerHit.cxx b/src/THcRawShowerHit.cxx
index 165a749..982266f 100644
--- a/src/THcRawShowerHit.cxx
+++ b/src/THcRawShowerHit.cxx
@@ -142,4 +142,11 @@ THcRawAdcHit& THcRawShowerHit::GetRawAdcHitNeg() {
 }
 
 
+void THcRawShowerHit::SetF250Params(Int_t NSA, Int_t NSB, Int_t NPED) {
+  for (Int_t iAdcSig=0; iAdcSig<fNAdcSignals; ++iAdcSig) {
+    fAdcHits[iAdcSig].SetF250Params(NSA, NSB, NPED);
+  }
+}
+
+
 ClassImp(THcRawShowerHit)
diff --git a/src/THcRawShowerHit.h b/src/THcRawShowerHit.h
index a70af83..9008831 100644
--- a/src/THcRawShowerHit.h
+++ b/src/THcRawShowerHit.h
@@ -31,6 +31,8 @@ class THcRawShowerHit : public THcRawHit {
     THcRawAdcHit& GetRawAdcHitPos();
     THcRawAdcHit& GetRawAdcHitNeg();
 
+    void SetF250Params(Int_t NSA, Int_t NSB, Int_t NPED);
+
   protected:
     static const Int_t fNAdcSignals = 2;
 
diff --git a/src/THcTrigRawHit.cxx b/src/THcTrigRawHit.cxx
index d0dbd47..60e3b60 100644
--- a/src/THcTrigRawHit.cxx
+++ b/src/THcTrigRawHit.cxx
@@ -121,6 +121,11 @@ It supports rich data from flash 250 ADC modules.
 \brief Gets reference to THcRawTdcHit.
 */
 
+/**
+\fn void THcTrigRawHit::SetF250Params(Int_t NSA, Int_t NSB, Int_t NPED)
+\brief See THcRawAdcHit::SetF250Params.
+*/
+
 // TODO: Check if signal matches plane.
 
 #include "THcTrigRawHit.h"
@@ -307,4 +312,11 @@ THcRawTdcHit& THcTrigRawHit::GetRawTdcHit() {
 }
 
 
+void THcTrigRawHit::SetF250Params(Int_t NSA, Int_t NSB, Int_t NPED) {
+  for (Int_t iAdcSig=0; iAdcSig<fNAdcSignals; ++iAdcSig) {
+    fAdcHits[iAdcSig].SetF250Params(NSA, NSB, NPED);
+  }
+}
+
+
 ClassImp(THcTrigRawHit)
diff --git a/src/THcTrigRawHit.h b/src/THcTrigRawHit.h
index 762cac7..345e3d0 100644
--- a/src/THcTrigRawHit.h
+++ b/src/THcTrigRawHit.h
@@ -33,6 +33,8 @@ class THcTrigRawHit : public THcRawHit {
     THcRawAdcHit& GetRawAdcHit();
     THcRawTdcHit& GetRawTdcHit();
 
+    void SetF250Params(Int_t NSA, Int_t NSB, Int_t NPED);
+
   protected:
     static const Int_t fNAdcSignals = 1;
     static const Int_t fNTdcSignals = 1;
-- 
GitLab