From 7fad2089e987d358a4c56e78b86fd867bac189c6 Mon Sep 17 00:00:00 2001
From: Vardan Tadevosyan <tadevosn@jlab.org>
Date: Mon, 23 Nov 2015 13:22:42 +0400
Subject: [PATCH] Fill ShowerArray::CalculatePedestals method.

---
 src/THcShowerArray.cxx | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/THcShowerArray.cxx b/src/THcShowerArray.cxx
index ef36896..d333161 100644
--- a/src/THcShowerArray.cxx
+++ b/src/THcShowerArray.cxx
@@ -310,7 +310,8 @@ Int_t THcShowerArray::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
 //_____________________________________________________________________________
 Int_t THcShowerArray::AccumulatePedestals(TClonesArray* rawhits, Int_t nexthit)
 {
-  // Doesn't do anything yet except skip over hits
+  // Extract data for this plane from hit list and accumulate in
+  // arrays for subsequent pedestal calculations.
 
   Int_t nrawhits = rawhits->GetLast()+1;
 
@@ -376,8 +377,37 @@ Int_t THcShowerArray::AccumulatePedestals(TClonesArray* rawhits, Int_t nexthit)
 //_____________________________________________________________________________
 void THcShowerArray::CalculatePedestals( )
 {
-  // Doesn't do anything yet
+  // Use the accumulated pedestal data to calculate pedestals.
+
+  for(Int_t i=0; i<fNelem;i++) {
+    
+    fPed[i] = ((Float_t) fPedSum[i]) / TMath::Max(1, fPedCount[i]);
+    fSig[i] = sqrt(((Float_t)fPedSum2[i])/TMath::Max(1, fPedCount[i])
+		   - fPed[i]*fPed[i]);
+    fThresh[i] = fPed[i] + TMath::Min(50., TMath::Max(10., 3.*fSig[i]));
+
+  }
+
+  // Debug output.
+
+  if ( ((THcShower*) GetParent())->fdbg_raw_cal ) {
 
+    cout << "---------------------------------------------------------------\n";
+    cout << "Debug output from THcShowerArray::CalculatePedestals for"
+    	 << GetParent()->GetPrefix() << ":" << endl;
+
+    cout << "  ADC pedestals and thresholds for calorimeter plane "
+	 << GetName() << endl;
+    for(Int_t i=0; i<fNelem;i++) {
+      cout << "  element " << i << ": "
+	   << "  Pedestal = " << fPed[i]
+	   << "  /threshold = " << fThresh[i]
+	   << endl;
+    }
+    cout << "---------------------------------------------------------------\n";
+
+  }
+  
 }
 //_____________________________________________________________________________
 void THcShowerArray::InitializePedestals( )
-- 
GitLab