From d85d0117b43e4a1fa2bd4431bd3052b08f630889 Mon Sep 17 00:00:00 2001
From: "Stephen A. Wood" <saw@jlab.org>
Date: Mon, 25 Mar 2013 14:49:30 -0400
Subject: [PATCH] Add variables for Aerogel raw and ped subracted ADCs and raw
 TDCs.

---
 src/THcAerogel.cxx | 50 +++++++++++++++++++++++++++++++++++++++++++---
 src/THcAerogel.h   | 14 ++++++++++---
 2 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/src/THcAerogel.cxx b/src/THcAerogel.cxx
index 5dba213..1cb9ca2 100644
--- a/src/THcAerogel.cxx
+++ b/src/THcAerogel.cxx
@@ -55,6 +55,24 @@ THcAerogel::THcAerogel( ) :
   // Constructor
 }
 
+//_____________________________________________________________________________
+THcAerogel::~THcAerogel()
+{
+  // Destructor
+  delete [] fA_Pos;
+  delete [] fA_Neg;
+  delete [] fA_Pos_p;
+  delete [] fA_Neg_p;
+  delete [] fT_Pos;
+  delete [] fT_Neg;
+  delete [] fPosGain;
+  delete [] fNegGain;
+  delete [] fPosPedLimit;
+  delete [] fNegPedLimit;
+  delete [] fPosPedMean;
+  delete [] fNegPedMean;
+}
+
 //_____________________________________________________________________________
 THaAnalysisObject::EStatus THcAerogel::Init( const TDatime& date )
 {
@@ -101,6 +119,13 @@ Int_t THcAerogel::ReadDatabase( const TDatime& date )
   fNelem = 8;			// Default if not defined
   gHcParms->LoadParmValues((DBRequest*)&listextra,prefix);
 
+  fA_Pos = new Float_t[fNelem];
+  fA_Neg = new Float_t[fNelem];
+  fA_Pos_p = new Float_t[fNelem];
+  fA_Neg_p = new Float_t[fNelem];
+  fT_Pos = new Float_t[fNelem];
+  fT_Neg = new Float_t[fNelem];
+
   fPosGain = new Double_t[fNelem];
   fNegGain = new Double_t[fNelem];
   fPosPedLimit = new Int_t[fNelem];
@@ -151,8 +176,14 @@ Int_t THcAerogel::DefineVariables( EMode mode )
      "fPosADCHits.THcSignalHit.GetPaddleNumber()"},
     {"negadchits", "List of Negative ADC hits", 
      "fNegADCHits.THcSignalHit.GetPaddleNumber()"},
+    {"apos",  "Raw Positive ADC Amplitudes",   "fA_Pos"},
+    {"aneg",  "Raw Negative ADC Amplitudes",   "fA_Neg"},
+    {"apos_p",  "Ped-subtracted Positive ADC Amplitudes",   "fA_Pos_p"},
+    {"aneg_p",  "Ped-subtracted Negative ADC Amplitudes",   "fA_Neg_p"},
+    {"tpos",  "Raw Positive TDC",   "fT_Pos"},
+    {"tneg",  "Raw Negative TDC",   "fT_Neg"},
     {"pos_npe","PEs Positive Tube","fPosNpe"},
-    {"neg_npe","PEs PE Negative Tube","fNegNpe"},
+    {"neg_npe","PEs Negative Tube","fNegNpe"},
     {"pos_npe_sum", "Total Positive Tube PEs", "fPosNpeSum"},
     {"neg_npe_sum", "Total Negative Tube PEs", "fNegNpeSum"},
     {"npe_sum", "Total PEs", "fNpeSum"},
@@ -190,6 +221,12 @@ void THcAerogel::Clear(Option_t* opt)
   fNTDCNegHits = 0;
 
   for(Int_t itube = 0;itube < fNelem;itube++) {
+    fA_Pos[itube] = 0;
+    fA_Neg[itube] = 0;
+    fA_Pos_p[itube] = 0;
+    fA_Neg_p[itube] = 0;
+    fT_Pos[itube] = 0;
+    fT_Neg[itube] = 0;
     fPosNpe[itube] = 0.0;
     fNegNpe[itube] = 0.0;
   }
@@ -278,15 +315,22 @@ Int_t THcAerogel::CoarseProcess( TClonesArray&  ) //tracks
     // be assigned NPE = 100.0.
 
     Int_t npmt = hit->fCounter - 1;
+    // Should probably check that npmt is in range
+    fA_Pos[npmt] = hit->fADC_pos;
+    fA_Neg[npmt] = hit->fADC_neg;
+    fA_Pos_p[npmt] = hit->fADC_pos - fPosPedMean[npmt];
+    fA_Neg_p[npmt] = hit->fADC_neg - fNegPedMean[npmt];
+    fT_Pos[npmt] = hit->fTDC_pos;
+    fT_Neg[npmt] = hit->fTDC_neg;
 
     if(hit->fADC_pos < 8000) {
-      fPosNpe[npmt] = fPosGain[npmt]*(hit->fADC_pos - fPosPedMean[npmt]);
+      fPosNpe[npmt] = fPosGain[npmt]*fA_Pos_p[npmt];
     } else {
       fPosNpe[npmt] = 100.0;
     }
 
     if(hit->fADC_neg < 8000) {
-      fNegNpe[npmt] = fNegGain[npmt]*(hit->fADC_neg - fNegPedMean[npmt]);
+      fNegNpe[npmt] = fNegGain[npmt]*fA_Neg_p[npmt];
     } else {
       fNegNpe[npmt] = 100.0;
     }
diff --git a/src/THcAerogel.h b/src/THcAerogel.h
index 5ed1b3e..abb7e4a 100644
--- a/src/THcAerogel.h
+++ b/src/THcAerogel.h
@@ -17,7 +17,7 @@ class THcAerogel : public THaNonTrackingDetector, public THcHitList {
  public:
   THcAerogel( const char* name, const char* description = "",
 		THaApparatus* a = NULL );
-  virtual ~THcAerogel() {};
+  virtual ~THcAerogel();
   
   virtual void 	     Clear( Option_t* opt="" );
   virtual Int_t      Decode( const THaEvData& );
@@ -44,6 +44,14 @@ class THcAerogel : public THaNonTrackingDetector, public THcHitList {
 
   // Event information
   Int_t fNhits;
+
+  Float_t*   fA_Pos;         // [fNelem] Array of ADC amplitudes
+  Float_t*   fA_Neg;         // [fNelem] Array of ADC amplitudes
+  Float_t*   fA_Pos_p;	     // [fNelem] Array of ped-subtracted ADC amplitudes
+  Float_t*   fA_Neg_p;	     // [fNelem] Array of ped-subtracted ADC amplitudes
+  Float_t*   fT_Pos;         // [fNelem] Array of TDCs
+  Float_t*   fT_Neg;         // [fNelem] Array of TDCs
+
   Double_t fPosNpeSum;
   Double_t fNegNpeSum;
   Double_t fNpeSum;
@@ -53,8 +61,8 @@ class THcAerogel : public THaNonTrackingDetector, public THcHitList {
   Int_t fNTDCPosHits;
   Int_t fNTDCNegHits;
 
-  Double_t* fPosNpe;
-  Double_t* fNegNpe;
+  Double_t* fPosNpe;		// [fNelem] # Photoelectrons per positive tube
+  Double_t* fNegNpe;		// [fNelem] # Photoelectrons per negative tube
 
   // Hits
   TClonesArray* fPosTDCHits;
-- 
GitLab