From 295c4620a9d5e9dc93ad66d266fda501fb8b165d Mon Sep 17 00:00:00 2001
From: "Stephen A. Wood" <saw@jlab.org>
Date: Mon, 6 Apr 2015 16:27:00 -0400
Subject: [PATCH] More hodoscope cleanup.  Replace arras with THcHodoHit clones
 array    Don't repeat comparisons of tdc values    with fScinTdcMin and
 fScinTdcMax because hits only get added to    fHodoHits (and previously
 fPosTDCHits, fNegTDCHits, ...) if    the times are within these ranges.   In
 THcHodoscop, remove members of fTOFPInfo that are just used    locally.

---
 Makefile                     |   2 +-
 SConscript.py                |   3 +-
 src/HallC_LinkDef.h          |   1 +
 src/THcHodoHit.cxx           |  37 ++++++++
 src/THcHodoHit.h             |  54 +++++++++++
 src/THcHodoscope.cxx         | 152 +++++++++++++------------------
 src/THcHodoscope.h           |   6 +-
 src/THcRawHodoHit.h          |   1 +
 src/THcScintillatorPlane.cxx | 168 ++++++++++++++---------------------
 src/THcScintillatorPlane.h   |  10 +--
 10 files changed, 228 insertions(+), 206 deletions(-)
 create mode 100644 src/THcHodoHit.cxx
 create mode 100644 src/THcHodoHit.h

diff --git a/Makefile b/Makefile
index 056ecb8..ac36479 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ SRC  =  src/THcInterface.cxx src/THcParmList.cxx src/THcAnalyzer.cxx \
 	src/THcRawHit.cxx src/THcHitList.cxx \
 	src/THcSignalHit.cxx \
 	src/THcHodoscope.cxx src/THcScintillatorPlane.cxx \
-	src/THcRawHodoHit.cxx \
+	src/THcRawHodoHit.cxx src/THcHodoHit.cxx \
 	src/THcDC.cxx src/THcDriftChamberPlane.cxx \
 	src/THcDriftChamber.cxx \
 	src/THcRawDCHit.cxx src/THcDCHit.cxx \
diff --git a/SConscript.py b/SConscript.py
index c94403f..3d54796 100644
--- a/SConscript.py
+++ b/SConscript.py
@@ -13,7 +13,8 @@ roothcobj = pbaseenv.subst('$HC_SRC')+'/HallCDict.so'
 hcheaders = Split("""
 	src/THcInterface.h src/THcParmList.h src/THcAnalyzer.h src/THcHallCSpectrometer.h 
 	src/THcDetectorMap.h src/THcRawHit.h src/THcHitList.h src/THcSignalHit.h src/THcHodoscope.h 
-	src/THcScintillatorPlane.h src/THcRawHodoHit.h src/THcDC.h src/THcDriftChamberPlane.h 
+	src/THcScintillatorPlane.h src/THcRawHodoHit.h src/THcHodoHit.h
+        src/THcDC.h src/THcDriftChamberPlane.h 
 	src/THcDriftChamber.h src/THcRawDCHit.h src/THcDCHit.h src/THcDCWire.h src/THcSpacePoint.h 
 	src/THcDCLookupTTDConv.h src/THcDCTimeToDistConv.h src/THcShower.h src/THcShowerPlane.h 
 	src/THcRawShowerHit.h src/THcAerogel.h src/THcAerogelHit.h src/THcCherenkov.h src/THcCherenkovHit.h
diff --git a/src/HallC_LinkDef.h b/src/HallC_LinkDef.h
index 21d28e1..d421883 100644
--- a/src/HallC_LinkDef.h
+++ b/src/HallC_LinkDef.h
@@ -30,6 +30,7 @@
 #pragma link C++ class THcHodoscope+;
 #pragma link C++ class THcScintillatorPlane+;
 #pragma link C++ class THcRawHodoHit+;
+#pragma link C++ class THcHodoHit+;
 #pragma link C++ class THcDC+;
 #pragma link C++ class THcDriftChamber+;
 #pragma link C++ class THcDriftChamberPlane+;
diff --git a/src/THcHodoHit.cxx b/src/THcHodoHit.cxx
new file mode 100644
index 0000000..bd3aa24
--- /dev/null
+++ b/src/THcHodoHit.cxx
@@ -0,0 +1,37 @@
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// THcHodoHit                                                                //
+//                                                                           //
+// Class representing a single hit for the Hodoscopes                        //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#include "THcHodoHit.h"
+
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+ClassImp(THcHodoHit)
+
+THcHodoHit::THcHodoHit( THcRawHodoHit *hit=NULL, Double_t posPed=0.0, 
+			     Double_t negPed=0.0, THcScintillatorPlane* sp=NULL)
+{
+  if(hit) {
+    fPosTDC = hit->fTDC_pos;
+    fNegTDC = hit->fTDC_neg;
+    fPosADC_Ped = hit->fADC_pos - posPed;
+    fNegADC_Ped = hit->fADC_neg - negPed;
+    fPaddleNumber = hit->fCounter;
+  } else {
+    fPosTDC = -1;
+    fNegTDC = -1;
+    fPosADC_Ped = -1000.0;
+    fNegADC_Ped = -1000.0;
+    fPaddleNumber = -1;
+  }
+  fPlane = sp;
+}
+
+////////////////////////////////////////////////////////////////////////////////
diff --git a/src/THcHodoHit.h b/src/THcHodoHit.h
new file mode 100644
index 0000000..03c538c
--- /dev/null
+++ b/src/THcHodoHit.h
@@ -0,0 +1,54 @@
+#ifndef ROOT_THcHodoHit
+#define ROOT_THcHodoHit
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// THcHodoHit                                                                 //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#include "TObject.h"
+#include "THcScintillatorPlane.h"
+//#include "THcDriftChamber.h"
+#include "THcRawHodoHit.h"
+#include <cstdio>
+
+class THcHodoHit : public TObject {
+
+public:
+  THcHodoHit( THcRawHodoHit* hit, Double_t posPed, 
+	      Double_t negPed, THcScintillatorPlane* sp);
+      
+  virtual ~THcHodoHit() {}
+
+  Bool_t IsSortable () const { return kFALSE; }
+  
+  // Get and Set Functions
+  Double_t GetPosADC() const { return fPosADC_Ped; }
+  Double_t GetNegADC() const { return fNegADC_Ped; }
+  Int_t GetPosTDC() const { return fPosTDC; }
+  Int_t GetNegTDC() const { return fNegTDC; }
+  Int_t GetPaddleNumber() const { return fPaddleNumber; }
+
+protected:
+  static const Double_t kBig;  //!
+
+  Int_t fPaddleNumber;
+  Int_t fPosTDC;
+  Int_t fNegTDC;
+  Double_t fPosADC_Ped;		// Pedestal subtracted ADC
+  Double_t fNegADC_Ped;		// Pedestal subtracted ADC
+
+  THcScintillatorPlane* fPlane;	// Pointer to parent scintillator plane
+  
+  
+private:
+  THcHodoHit( const THcHodoHit& );
+  THcHodoHit& operator=( const THcHodoHit& );
+  
+  ClassDef(THcHodoHit,0)             // Drift Chamber Hit
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+#endif
diff --git a/src/THcHodoscope.cxx b/src/THcHodoscope.cxx
index b992702..bb0e341 100644
--- a/src/THcHodoscope.cxx
+++ b/src/THcHodoscope.cxx
@@ -15,6 +15,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "THcSignalHit.h"
+#include "THcHodoHit.h"
 #include "THcShower.h"
 #include "THcCherenkov.h"
 #include "THcHallCSpectrometer.h"
@@ -805,10 +806,7 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
       for(Int_t ip = 0; ip < fNPlanes; ip++ ) {
 	
 	fNScinHits[ip] = fPlanes[ip]->GetNScinHits();
-	TClonesArray* scinPosADC = fPlanes[ip]->GetPosADC();
-	TClonesArray* scinNegADC = fPlanes[ip]->GetNegADC();
-	TClonesArray* scinPosTDC = fPlanes[ip]->GetPosTDC();
-	TClonesArray* scinNegTDC = fPlanes[ip]->GetNegTDC();  
+	TClonesArray* hodoHits = fPlanes[ip]->GetHits();
 
 	// first loop over hits with in a single plane
 	fTOFPInfo.clear();
@@ -824,7 +822,7 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	  fTOFPInfo[iphit].scin_pos_time = 0.0;
 	  fTOFPInfo[iphit].scin_neg_time = 0.0;
 	  
-	  Int_t paddle = ((THcSignalHit*)scinPosTDC->At(iphit))->GetPaddleNumber()-1;
+	  Int_t paddle = ((THcHodoHit*)hodoHits->At(iphit))->GetPaddleNumber()-1;
 	  
 	  Double_t xHitCoord = theTrack->GetX() + theTrack->GetTheta() *
 	    ( fPlanes[ip]->GetZpos() +
@@ -855,57 +853,44 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	  if ( TMath::Abs( scinCenter - scinTrnsCoord ) <
 	       ( fPlanes[ip]->GetSize() * 0.5 + fPlanes[ip]->GetHodoSlop() ) ){ // Line 293
 	    
-	    if ( ( ((THcSignalHit*)scinPosTDC->At(iphit))->GetData() > fScinTdcMin ) &&
-		 ( ((THcSignalHit*)scinPosTDC->At(iphit))->GetData() < fScinTdcMax ) ) { // Line 199
+	    Double_t adcPhp = ((THcHodoHit*)hodoHits->At(iphit))->GetPosADC();
+	    Double_t pathp = fPlanes[ip]->GetPosLeft() - scinLongCoord;
+	    Double_t timep = ((THcHodoHit*)hodoHits->At(iphit))->GetPosTDC() * fScinTdcToTime;
+	    timep = timep - fHodoPosPhcCoeff[fPIndex] *
+	      TMath::Sqrt( TMath::Max( 0., ( ( adcPhp / fHodoPosMinPh[fPIndex] ) - 1 ) ) );
+	    timep = timep - ( pathp / fHodoVelLight[fPIndex] ) - ( fPlanes[ip]->GetZpos() +  
+								( paddle % 2 ) * fPlanes[ip]->GetDzpos() ) / ( 29.979 * betaP ) *
+	      TMath::Sqrt( 1. + theTrack->GetTheta() * theTrack->GetTheta() +
+			   theTrack->GetPhi() * theTrack->GetPhi() );
+	    timep = timep - fHodoPosTimeOffset[fPIndex];
+	    fTOFPInfo[iphit].time_pos = timep;
 	      
-	      Double_t adcPh = ((THcSignalHit*)scinPosADC->At(iphit))->GetData();
-	      fTOFPInfo[iphit].adcPh = adcPh;
-	      Double_t path = fPlanes[ip]->GetPosLeft() - scinLongCoord;
-	      fTOFPInfo[iphit].path = path;
-	      Double_t time = ((THcSignalHit*)scinPosTDC->At(iphit))->GetData() * fScinTdcToTime;
-	      time = time - fHodoPosPhcCoeff[fPIndex] *
-		TMath::Sqrt( TMath::Max( 0., ( ( adcPh / fHodoPosMinPh[fPIndex] ) - 1 ) ) );
-	      time = time - ( path / fHodoVelLight[fPIndex] ) - ( fPlanes[ip]->GetZpos() +  
-			    ( paddle % 2 ) * fPlanes[ip]->GetDzpos() ) / ( 29.979 * betaP ) *
-		            TMath::Sqrt( 1. + theTrack->GetTheta() * theTrack->GetTheta() +
-			    theTrack->GetPhi() * theTrack->GetPhi() );
-	      fTOFPInfo[iphit].time = time;
-	      fTOFPInfo[iphit].time_pos = time - fHodoPosTimeOffset[fPIndex];
-	      
-	      for ( Int_t k = 0; k < 200; k++ ){ // Line 211
-		Double_t tmin = 0.5 * ( k + 1 ) ;
-		if ( ( fTOFPInfo[iphit].time_pos > tmin ) && ( fTOFPInfo[iphit].time_pos < ( tmin + fTofTolerance ) ) )
-		  timehist[k] ++;
-	      }
-	    } // TDC pos hit condition
-	    
+	    for ( Int_t k = 0; k < 200; k++ ){ // Line 211
+	      Double_t tmin = 0.5 * ( k + 1 ) ;
+	      if ( ( timep > tmin ) && ( timep < ( tmin + fTofTolerance ) ) )
+		timehist[k] ++;
+	    }
 	    
-	    if ( ( ((THcSignalHit*)scinNegTDC->At(iphit))->GetData() > fScinTdcMin ) &&
-		 ( ((THcSignalHit*)scinNegTDC->At(iphit))->GetData() < fScinTdcMax ) ) { // Line 218
-	      
-	      Double_t adcPh = ((THcSignalHit*)scinNegADC->At(iphit))->GetData();
-	      fTOFPInfo[iphit].adcPh = adcPh;
-	      Double_t path =  scinLongCoord - fPlanes[ip]->GetPosRight();
-	      fTOFPInfo[iphit].path = path;
-	      Double_t time = ((THcSignalHit*)scinNegTDC->At(iphit))->GetData() * fScinTdcToTime;
-	      time =time - fHodoNegPhcCoeff[fPIndex] * 
-		TMath::Sqrt( TMath::Max( 0., ( ( adcPh / fHodoNegMinPh[fPIndex] ) - 1 ) ) );
-	      time = time - ( path / fHodoVelLight[fPIndex] ) - ( fPlanes[ip]->GetZpos() +
-			      ( paddle % 2 ) * fPlanes[ip]->GetDzpos() ) / ( 29.979 * betaP ) *
-		TMath::Sqrt( 1. + theTrack->GetTheta() * theTrack->GetTheta() +
-			     theTrack->GetPhi() * theTrack->GetPhi() );
-	      fTOFPInfo[iphit].time = time;
-	      fTOFPInfo[iphit].time_neg = time - fHodoNegTimeOffset[fPIndex];
+	    Double_t adcPhn = ((THcHodoHit*)hodoHits->At(iphit))->GetNegADC();
+	    Double_t pathn =  scinLongCoord - fPlanes[ip]->GetPosRight();
+	    Double_t timen = ((THcHodoHit*)hodoHits->At(iphit))->GetNegTDC() * fScinTdcToTime;
+	    timen =timen - fHodoNegPhcCoeff[fPIndex] * 
+	      TMath::Sqrt( TMath::Max( 0., ( ( adcPhn / fHodoNegMinPh[fPIndex] ) - 1 ) ) );
+	    timen = timen - ( pathn / fHodoVelLight[fPIndex] ) - ( fPlanes[ip]->GetZpos() +
+								( paddle % 2 ) * fPlanes[ip]->GetDzpos() ) / ( 29.979 * betaP ) *
+	      TMath::Sqrt( 1. + theTrack->GetTheta() * theTrack->GetTheta() +
+			   theTrack->GetPhi() * theTrack->GetPhi() );
+	    timen = timen - fHodoNegTimeOffset[fPIndex];
+	    fTOFPInfo[iphit].time_neg = timen;
 	      
-	      for ( Int_t k = 0; k < 200; k++ ){ // Line 230
-		Double_t tmin = 0.5 * ( k + 1 );
-		if ( ( fTOFPInfo[iphit].time_neg > tmin ) && ( fTOFPInfo[iphit].time_neg < ( tmin + fTofTolerance ) ) )
-		  timehist[k] ++;
-	      }
-	    } // TDC neg hit condition
+	    for ( Int_t k = 0; k < 200; k++ ){ // Line 230
+	      Double_t tmin = 0.5 * ( k + 1 );
+	      if ( ( timen > tmin ) && ( timen < ( tmin + fTofTolerance ) ) )
+		timehist[k] ++;
+	    }
 	  } // condition for cenetr on a paddle
 	} // First loop over hits in a plane <---------
-
+	
 	//-----------------------------------------------------------------------------------------------
 	//------------- First large loop over scintillator hits in a plane ends here --------------------
 	//-----------------------------------------------------------------------------------------------
@@ -921,16 +906,15 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	}
 	
 
-	  Double_t tmin = 0.5 * jmax;
-	  for(Int_t iphit = 0; iphit < fNScinHits[ip]; iphit++) { // Loop over sinc. hits. in plane
-	    if ( ( fTOFPInfo[iphit].time_pos > tmin ) && ( fTOFPInfo[iphit].time_pos < ( tmin + fTofTolerance ) ) ) {
-	      fTOFPInfo[iphit].keep_pos=kTRUE;
-	    }	
-	    if ( ( fTOFPInfo[iphit].time_neg > tmin ) && ( fTOFPInfo[iphit].time_neg < ( tmin + fTofTolerance ) ) ){
-	      fTOFPInfo[iphit].keep_neg=kTRUE;
-	    }	
-	  }
-
+	Double_t tmin = 0.5 * jmax;
+	for(Int_t iphit = 0; iphit < fNScinHits[ip]; iphit++) { // Loop over sinc. hits. in plane
+	  if ( ( fTOFPInfo[iphit].time_pos > tmin ) && ( fTOFPInfo[iphit].time_pos < ( tmin + fTofTolerance ) ) ) {
+	    fTOFPInfo[iphit].keep_pos=kTRUE;
+	  }	
+	  if ( ( fTOFPInfo[iphit].time_neg > tmin ) && ( fTOFPInfo[iphit].time_neg < ( tmin + fTofTolerance ) ) ){
+	    fTOFPInfo[iphit].keep_neg=kTRUE;
+	  }	
+	}
 	
 	//---------------------------------------------------------------------------------------------	
 	// ---------------------- Scond loop over scint. hits in a plane ------------------------------
@@ -950,7 +934,7 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	  //	  fRawIndex ++;   // Is fRawIndex ever different from ihhit
 	  Int_t rawindex = ihhit;
 
-	  Int_t paddle = ((THcSignalHit*)scinPosTDC->At(iphit))->GetPaddleNumber()-1;
+	  Int_t paddle = ((THcHodoHit*)hodoHits->At(iphit))->GetPaddleNumber()-1;
 	  fTOFCalc[ihhit].hit_paddle = paddle;
 	  fTOFCalc[rawindex].good_raw_pad = paddle;
 	  
@@ -978,50 +962,38 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	       ( fPlanes[ip]->GetSize() * 0.5 + fPlanes[ip]->GetHodoSlop() ) ){ // Line 293
 	  }
 	  else{	    
-	    // * * Check for good TDC
-	    if ( ( ((THcSignalHit*)scinPosTDC->At(iphit))->GetData() > fScinTdcMin ) &&
-		 ( ((THcSignalHit*)scinPosTDC->At(iphit))->GetData() < fScinTdcMax ) &&
-		 ( fTOFPInfo[iphit].keep_pos ) ) { // 301
+	    if ( fTOFPInfo[iphit].keep_pos ) { // 301
 	      
 	      // ** Calculate time for each tube with a good tdc. 'pos' side first.
 	      fTOFCalc[ihhit].good_tdc_pos = kTRUE;
-	      Double_t adcPh = ((THcSignalHit*)scinPosADC->At(iphit))->GetData();
-	      fTOFPInfo[iphit].adcPh = adcPh;
+	      Double_t adcPh = ((THcHodoHit*)hodoHits->At(iphit))->GetPosADC();
 	      Double_t path = fPlanes[ip]->GetPosLeft() - scinLongCoord;
-	      fTOFPInfo[iphit].path = path;
 	      
 	      // * Convert TDC value to time, do pulse height correction, correction for
 	      // * propogation of light thru scintillator, and offset.	      
-	      Double_t time = ((THcSignalHit*)scinPosTDC->At(iphit))->GetData() * fScinTdcToTime;
+	      Double_t time = ((THcHodoHit*)hodoHits->At(iphit))->GetPosTDC() * fScinTdcToTime;
 	      time = time - ( fHodoPosPhcCoeff[fPIndex] * TMath::Sqrt( TMath::Max( 0. , 
 					( ( adcPh / fHodoPosMinPh[fPIndex] ) - 1 ) ) ) );
 	      time = time - ( path / fHodoVelLight[fPIndex] );
-	      fTOFPInfo[iphit].time = time;
 	      fTOFPInfo[iphit].scin_pos_time = time - fHodoPosTimeOffset[fPIndex];
 	      
 	    } // check for good pos TDC condition
 	    
-	    // ** Repeat for pmts on 'negative' side
-	    if ( ( ((THcSignalHit*)scinNegTDC->At(iphit))->GetData() > fScinTdcMin ) &&
-		 ( ((THcSignalHit*)scinNegTDC->At(iphit))->GetData() < fScinTdcMax ) &&
-		 ( fTOFPInfo[iphit].keep_neg ) ) { //
+	    if ( fTOFPInfo[iphit].keep_neg ) { //
 	      
 	      // ** Calculate time for each tube with a good tdc. 'pos' side first.
 	      fTOFCalc[ihhit].good_tdc_neg = kTRUE;
 	      //	      fNtof ++;
-	      Double_t adcPh = ((THcSignalHit*)scinNegADC->At(iphit))->GetData();
-	      fTOFPInfo[iphit].adcPh = adcPh;
+	      Double_t adcPh = ((THcHodoHit*)hodoHits->At(iphit))->GetNegADC();
 	      //	      Double_t path = fPlanes[ip]->GetPosRight() - scinLongCoord;
 	      Double_t path = scinLongCoord - fPlanes[ip]->GetPosRight();
-	      fTOFPInfo[iphit].path = path;
 	      
 	      // * Convert TDC value to time, do pulse height correction, correction for
 	      // * propogation of light thru scintillator, and offset.
-	      Double_t time = ((THcSignalHit*)scinNegTDC->At(iphit))->GetData() * fScinTdcToTime;
+	      Double_t time = ((THcHodoHit*)hodoHits->At(iphit))->GetNegTDC() * fScinTdcToTime;
 	      time = time - ( fHodoNegPhcCoeff[fPIndex] *
 			   TMath::Sqrt( TMath::Max( 0. , ( ( adcPh / fHodoNegMinPh[fPIndex] ) - 1 ) ) ) );
 	      time = time - ( path / fHodoVelLight[fPIndex] );
-	      fTOFPInfo[iphit].time = time;
 	      fTOFPInfo[iphit].scin_neg_time = time - fHodoNegTimeOffset[fPIndex];
       
 	    } // check for good neg TDC condition
@@ -1080,18 +1052,18 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	      if ( fTOFCalc[ihhit].good_tdc_pos ){
 		if ( fTOFCalc[ihhit].good_tdc_neg ){
 		  fdEdX[itrack][fNScinHit[itrack]-1]=
-		    TMath::Sqrt( TMath::Max( 0., ((THcSignalHit*)scinPosADC->At(iphit))->GetData() *
-                                                 ((THcSignalHit*)scinNegADC->At(iphit))->GetData() ) );
+		    TMath::Sqrt( TMath::Max( 0., ((THcHodoHit*)hodoHits->At(iphit))->GetPosADC() *
+                                                 ((THcHodoHit*)hodoHits->At(iphit))->GetNegADC() ) );
 		}
 		else{
 		  fdEdX[itrack][fNScinHit[itrack]-1]=
-		    TMath::Max( 0., ((THcSignalHit*)scinPosADC->At(iphit))->GetData() );
+		    TMath::Max( 0., ((THcHodoHit*)hodoHits->At(iphit))->GetPosADC() );
 	       	}
 	      }
 	      else{
 		if ( fTOFCalc[ihhit].good_tdc_neg ){
 		  fdEdX[itrack][fNScinHit[itrack]-1]=
-		    TMath::Max( 0., ((THcSignalHit*)scinNegADC->At(iphit))->GetData() );
+		    TMath::Max( 0., ((THcHodoHit*)hodoHits->At(iphit))->GetNegADC() );
 		}
 		else{
 		  fdEdX[itrack][fNScinHit[itrack]-1]=0.0;
@@ -1280,17 +1252,15 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
     if (!fPlanes[ip])
       return -1;
 
-    TClonesArray* scinPosTDC = fPlanes[ip]->GetPosTDC();
-    TClonesArray* scinNegTDC = fPlanes[ip]->GetNegTDC();
+    TClonesArray* hodoHits = fPlanes[ip]->GetHits();
+    //    TClonesArray* scinPosTDC = fPlanes[ip]->GetPosTDC();
+    //    TClonesArray* scinNegTDC = fPlanes[ip]->GetNegTDC();
 
     fNScinHits[ip] = fPlanes[ip]->GetNScinHits();
     for (Int_t iphit = 0; iphit < fNScinHits[ip]; iphit++ ){
-      Int_t paddlePos = ((THcSignalHit*)scinPosTDC->At(iphit))->GetPaddleNumber()-1;
-      Int_t paddleNeg = ((THcSignalHit*)scinNegTDC->At(iphit))->GetPaddleNumber()-1;
-      if ( paddlePos != paddleNeg )
-	return -1;
+      Int_t paddle = ((THcHodoHit*)hodoHits->At(iphit))->GetPaddleNumber()-1;
       
-      fScinHitPaddle[ip][paddlePos] = 1;
+      fScinHitPaddle[ip][paddle] = 1;
     }
   }
 
diff --git a/src/THcHodoscope.h b/src/THcHodoscope.h
index 4617fa1..a72b32e 100644
--- a/src/THcHodoscope.h
+++ b/src/THcHodoscope.h
@@ -229,9 +229,9 @@ protected:
     Double_t time_neg;
     Bool_t keep_pos;
     Bool_t keep_neg;
-    Double_t adcPh;
-    Double_t path;
-    Double_t time;
+    //    Double_t adcPh;
+    //    Double_t path;
+    //    Double_t time;
     Double_t scin_pos_time;
     Double_t scin_neg_time;
     TOFPInfo () : time_pos(-99.0), time_neg(-99.0), keep_pos(kFALSE),
diff --git a/src/THcRawHodoHit.h b/src/THcRawHodoHit.h
index b4d3702..7e5614b 100644
--- a/src/THcRawHodoHit.h
+++ b/src/THcRawHodoHit.h
@@ -8,6 +8,7 @@ class THcRawHodoHit : public THcRawHit {
  public:
   friend class THcScintillatorPlane;
   friend class THcHodoscope;
+  friend class THcHodoHit;
 
   THcRawHodoHit(Int_t plane=0, Int_t counter=0) : THcRawHit(plane, counter), 
     fADC_pos(-1), fADC_neg(-1),
diff --git a/src/THcScintillatorPlane.cxx b/src/THcScintillatorPlane.cxx
index 64aa1dd..9556cbe 100644
--- a/src/THcScintillatorPlane.cxx
+++ b/src/THcScintillatorPlane.cxx
@@ -9,6 +9,7 @@
 #include "THcScintillatorPlane.h"
 #include "TClonesArray.h"
 #include "THcSignalHit.h"
+#include "THcHodoHit.h"
 #include "THcGlobals.h"
 #include "THcParmList.h"
 #include "THcHitList.h"
@@ -32,10 +33,7 @@ THcScintillatorPlane::THcScintillatorPlane( const char* name,
   : THaSubDetector(name,description,parent)
 {
   // Normal constructor with name and description
-  fPosTDCHits = new TClonesArray("THcSignalHit",16);
-  fNegTDCHits = new TClonesArray("THcSignalHit",16);
-  fPosADCHits = new TClonesArray("THcSignalHit",16);
-  fNegADCHits = new TClonesArray("THcSignalHit",16);
+  fHodoHits = new TClonesArray("THcHodoHit",16);
   frPosTDCHits = new TClonesArray("THcSignalHit",16);
   frNegTDCHits = new TClonesArray("THcSignalHit",16);
   frPosADCHits = new TClonesArray("THcSignalHit",16);
@@ -57,10 +55,7 @@ THcScintillatorPlane::THcScintillatorPlane( const char* name,
 THcScintillatorPlane::~THcScintillatorPlane()
 {
   // Destructor
-  delete fPosTDCHits;
-  delete fNegTDCHits;
-  delete fPosADCHits;
-  delete fNegADCHits;
+  delete fHodoHits;
   delete frPosTDCHits;
   delete frNegTDCHits;
   delete frPosADCHits;
@@ -248,10 +243,7 @@ void THcScintillatorPlane::Clear( Option_t* )
 {
   //cout << " Calling THcScintillatorPlane::Clear " << GetName() << endl;
   // Clears the hit lists
-  fPosTDCHits->Clear();
-  fNegTDCHits->Clear();
-  fPosADCHits->Clear();
-  fNegADCHits->Clear();
+  fHodoHits->Clear();
   frPosTDCHits->Clear();
   frNegTDCHits->Clear();
   frPosADCHits->Clear();
@@ -307,15 +299,8 @@ Int_t THcScintillatorPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
   frPosADCHits->Clear();
   frNegADCHits->Clear();
   //stripped
-  Int_t nPosTDCHits=0;
-  Int_t nNegTDCHits=0;
-  Int_t nPosADCHits=0;
-  Int_t nNegADCHits=0;
   fNScinHits=0;
-  fPosTDCHits->Clear();
-  fNegTDCHits->Clear();
-  fPosADCHits->Clear();
-  fNegADCHits->Clear();
+  fHodoHits->Clear();
   Int_t nrawhits = rawhits->GetLast()+1;
   // cout << "THcScintillatorPlane::ProcessHits " << fPlaneNum << " " << nexthit << "/" << nrawhits << endl;
   Int_t ihit = nexthit;
@@ -342,19 +327,8 @@ Int_t THcScintillatorPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
     if (((hit->fTDC_pos >= fScinTdcMin) && (hit->fTDC_pos <= fScinTdcMax)) ||
 	((hit->fTDC_neg >= fScinTdcMin) && (hit->fTDC_neg <= fScinTdcMax))) {
 
-      //TDC positive hit
-      THcSignalHit *sighit = (THcSignalHit*) fPosTDCHits->ConstructedAt(nPosTDCHits++);
-      sighit->Set(padnum, hit->fTDC_pos);
-      // TDC negative hit
-      THcSignalHit *sighit2 = (THcSignalHit*) fNegTDCHits->ConstructedAt(nNegTDCHits++);
-      sighit2->Set(padnum, hit->fTDC_neg);
-      // ADC positive hit
-      THcSignalHit *sighit3 = (THcSignalHit*) fPosADCHits->ConstructedAt(nPosADCHits++);
-      sighit3->Set(padnum, hit->fADC_pos-fPosPed[index]);
-      // ADC negative hit
-      THcSignalHit *sighit4 = (THcSignalHit*) fNegADCHits->ConstructedAt(nNegADCHits++);
-      sighit4->Set(padnum, hit->fADC_neg-fNegPed[index]);      
-      fNScinHits++;
+      // If TDC values are all good, transfer the raw hit to the HodoHit list
+      new( (*fHodoHits)[fNScinHits++]) THcHodoHit(hit, fPosPed[index], fNegPed[index], this);
     }
     else {
     }
@@ -406,47 +380,42 @@ Int_t THcScintillatorPlane::PulseHeightCorrection()
 
   fpTime=-1e5;
   for (Int_t i=0;i<fNScinHits;i++) {
-    if ((((THcSignalHit*) fPosTDCHits->At(i))->GetData()>=fScinTdcMin) &&
-	(((THcSignalHit*) fPosTDCHits->At(i))->GetData()<=fScinTdcMax) &&
-	(((THcSignalHit*) fNegTDCHits->At(i))->GetData()>=fScinTdcMin) &&
-	(((THcSignalHit*) fNegTDCHits->At(i))->GetData()<=fScinTdcMax)) {
-	  pos_ph[i]=((THcSignalHit*) fPosADCHits->At(i))->GetData();
-	  postime[i]=((THcSignalHit*) fPosTDCHits->At(i))->GetData()*fScinTdcToTime;
-	  Int_t jpos=((THcSignalHit*)fPosTDCHits->At(i))->GetPaddleNumber()-1;
-	  postime[i]=postime[i]-fHodoPosPhcCoeff[jpos]*
-	    TMath::Sqrt(TMath::Max(0.,(pos_ph[i]/fHodoPosMinPh[jpos]-1)));
-	  postime[i]=postime[i]-fHodoPosTimeOffset[jpos];
-
-	  neg_ph[i]=((THcSignalHit*) fNegADCHits->At(i))->GetData();
-	  negtime[i]=((THcSignalHit*) fNegTDCHits->At(i))->GetData()*fScinTdcToTime;
-	  Int_t jneg=((THcSignalHit*)fNegTDCHits->At(i))->GetPaddleNumber()-1;
-	  assert(jpos==jneg);
-	  negtime[i]=negtime[i]-fHodoNegPhcCoeff[jneg]*
-	    TMath::Sqrt(TMath::Max(0.,(neg_ph[i]/fHodoNegMinPh[jneg]-1)));
-	  negtime[i]=negtime[i]-fHodoNegTimeOffset[jneg];
-
-	  // Find hit position.  If postime larger, then hit was nearer negative side.
-	  dist_from_center=0.5*(negtime[i]-postime[i])*fHodoVelLight[jpos];
-	  scint_center=0.5*(fPosLeft+fPosRight);
-	  hit_position=scint_center+dist_from_center;
-	  hit_position=TMath::Min(hit_position,fPosLeft);
-	  hit_position=TMath::Max(hit_position,fPosRight);
-	  postime[i]=postime[i]-(fPosLeft-hit_position)/fHodoVelLight[jpos];
-	  negtime[i]=negtime[i]-(hit_position-fPosRight)/fHodoVelLight[jpos];
-
-	  time_pos[i]=postime[i]-(fZpos+(jpos%2)*fDzpos)/(29.979*fBetaNominal);
-	  time_neg[i]=negtime[i]-(fZpos+(jpos%2)*fDzpos)/(29.979*fBetaNominal);
-	  //	  nfound++;
-	  for (Int_t k=0;k<200;k++) {
-	    Double_t tmin=0.5*(k+1);
-	    if ((time_pos[i]> tmin) && (time_pos[i] < tmin+fTofTolerance)) {
-	      timehist[k]++;
-	    }
-	    if ((time_neg[i]> tmin) && (time_neg[i] < tmin+fTofTolerance)) {
-	      timehist[k]++;
-	    }
-	  }
+    // Perhaps these calculations should be done in the THcHodoHit class so
+    // that they don't get repeated
+    Int_t index=((THcHodoHit*)fHodoHits->At(i))->GetPaddleNumber()-1;
+
+    pos_ph[i]=((THcHodoHit*) fHodoHits->At(i))->GetPosADC();
+    postime[i]=((THcHodoHit*) fHodoHits->At(i))->GetPosTDC()*fScinTdcToTime;
+    postime[i]=postime[i]-fHodoPosPhcCoeff[index]*
+      TMath::Sqrt(TMath::Max(0.,(pos_ph[i]/fHodoPosMinPh[index]-1)));
+    postime[i]=postime[i]-fHodoPosTimeOffset[index];
+
+    neg_ph[i]=((THcHodoHit*) fHodoHits->At(i))->GetNegADC();
+    negtime[i]=((THcHodoHit*) fHodoHits->At(i))->GetNegTDC()*fScinTdcToTime;
+    negtime[i]=negtime[i]-fHodoNegPhcCoeff[index]*
+      TMath::Sqrt(TMath::Max(0.,(neg_ph[i]/fHodoNegMinPh[index]-1)));
+    negtime[i]=negtime[i]-fHodoNegTimeOffset[index];
+	  
+    // Find hit position.  If postime larger, then hit was nearer negative side.
+    dist_from_center=0.5*(negtime[i]-postime[i])*fHodoVelLight[index];
+    scint_center=0.5*(fPosLeft+fPosRight);
+    hit_position=scint_center+dist_from_center;
+    hit_position=TMath::Min(hit_position,fPosLeft);
+    hit_position=TMath::Max(hit_position,fPosRight);
+    postime[i]=postime[i]-(fPosLeft-hit_position)/fHodoVelLight[index];
+    negtime[i]=negtime[i]-(hit_position-fPosRight)/fHodoVelLight[index];
+
+    time_pos[i]=postime[i]-(fZpos+(index%2)*fDzpos)/(29.979*fBetaNominal);
+    time_neg[i]=negtime[i]-(fZpos+(index%2)*fDzpos)/(29.979*fBetaNominal);
 	  //	  nfound++;
+    for (Int_t k=0;k<200;k++) {
+      Double_t tmin=0.5*(k+1);
+      if ((time_pos[i]> tmin) && (time_pos[i] < tmin+fTofTolerance)) {
+	timehist[k]++;
+      }
+      if ((time_neg[i]> tmin) && (time_neg[i] < tmin+fTofTolerance)) {
+	timehist[k]++;
+      }
     }
   }
   // Find the bin with most hits
@@ -463,45 +432,40 @@ Int_t THcScintillatorPlane::PulseHeightCorrection()
   // Resume regular tof code, now using time filer(?) from above
   // Check for TWO good TDC hits
   for (Int_t i=0;i<fNScinHits;i++) {
-    if ((((THcSignalHit*) fPosTDCHits->At(i))->GetData()>=fScinTdcMin) &&
-	(((THcSignalHit*) fPosTDCHits->At(i))->GetData()<=fScinTdcMax) &&
-	(((THcSignalHit*) fNegTDCHits->At(i))->GetData()>=fScinTdcMin) &&
-	(((THcSignalHit*) fNegTDCHits->At(i))->GetData()<=fScinTdcMax)) {
-	Double_t tmin = 0.5*jmax;
-	if ((time_pos[i]>tmin) && (time_pos[i]<tmin+fTofTolerance) &&
-	    (time_neg[i]>tmin) && (time_neg[i]<tmin+fTofTolerance))
-	  two_good_times[i]=kTRUE;
-    }
+    Double_t tmin = 0.5*jmax;
+    if ((time_pos[i]>tmin) && (time_pos[i]<tmin+fTofTolerance) &&
+	(time_neg[i]>tmin) && (time_neg[i]<tmin+fTofTolerance))
+      two_good_times[i]=kTRUE;
   } // end of loop that finds tube setting time
   for (Int_t i=0;i<fNScinHits;i++) {
     if (two_good_times[i]) { // both tubes fired
       // correct time for everything except veloc. correction in order
       // to find hit location from difference in TDC.
-      pos_ph[i]=((THcSignalHit*) fPosADCHits->At(i))->GetData();
-      postime[i]=((THcSignalHit*) fPosTDCHits->At(i))->GetData()*fScinTdcToTime;
-      Int_t jpos=((THcSignalHit*)fPosTDCHits->At(i))->GetPaddleNumber()-1;
-      postime[i]=postime[i]-fHodoPosPhcCoeff[jpos]*
-	TMath::Sqrt(TMath::Max(0.,(pos_ph[i]/fHodoPosMinPh[jpos]-1)));
-      postime[i]=postime[i]-fHodoPosTimeOffset[jpos];
-      //
-      neg_ph[i]=((THcSignalHit*) fNegADCHits->At(i))->GetData();
-      negtime[i]=((THcSignalHit*) fNegTDCHits->At(i))->GetData()*fScinTdcToTime;
-      Int_t jneg=((THcSignalHit*)fNegTDCHits->At(i))->GetPaddleNumber()-1;
-      assert(jpos==jneg);
-      negtime[i]=negtime[i]-fHodoNegPhcCoeff[jneg]*
-	TMath::Sqrt(TMath::Max(0.,(neg_ph[i]/fHodoNegMinPh[jneg]-1)));
-      negtime[i]=negtime[i]-fHodoNegTimeOffset[jneg];
+      // We are repeating some stuff here.  Should save it all in the hit
+      // class so it doesn't have to be recalculated.  (Avoid mistakes too)
+      Int_t index=((THcHodoHit*)fHodoHits->At(i))->GetPaddleNumber()-1;
+      pos_ph[i]=((THcHodoHit*) fHodoHits->At(i))->GetPosADC();
+      postime[i]=((THcHodoHit*) fHodoHits->At(i))->GetPosTDC()*fScinTdcToTime;
+      postime[i]=postime[i]-fHodoPosPhcCoeff[index]*
+	TMath::Sqrt(TMath::Max(0.,(pos_ph[i]/fHodoPosMinPh[index]-1)));
+      postime[i]=postime[i]-fHodoPosTimeOffset[index];
+
+      neg_ph[i]=((THcHodoHit*) fHodoHits->At(i))->GetNegADC();
+      negtime[i]=((THcHodoHit*) fHodoHits->At(i))->GetNegTDC()*fScinTdcToTime;
+      negtime[i]=negtime[i]-fHodoNegPhcCoeff[index]*
+	TMath::Sqrt(TMath::Max(0.,(neg_ph[i]/fHodoNegMinPh[index]-1)));
+      negtime[i]=negtime[i]-fHodoNegTimeOffset[index];
+
       // find hit position. If postime larger, then hit was nearer negative side
-      dist_from_center=0.5*(negtime[i]-postime[i])*fHodoVelLight[jpos];
+      dist_from_center=0.5*(negtime[i]-postime[i])*fHodoVelLight[index];
       scint_center=0.5*(fPosLeft+fPosRight);
       hit_position=scint_center+dist_from_center;
       hit_position=TMath::Min(hit_position,fPosLeft);
       hit_position=TMath::Max(hit_position,fPosRight);
-      postime[i]=postime[i]-(fPosLeft-hit_position)/fHodoVelLight[jpos];
-      negtime[i]=negtime[i]-(hit_position-fPosRight)/fHodoVelLight[jpos];
+      postime[i]=postime[i]-(fPosLeft-hit_position)/fHodoVelLight[index];
+      negtime[i]=negtime[i]-(hit_position-fPosRight)/fHodoVelLight[index];
       scin_corrected_time[i]=0.5*(postime[i]+negtime[i]);
-    }
-    else { // only one tube fired
+    } else { // only one tube fired
       scin_corrected_time[i]=0.0; // not a very good "flag" but there is the logical two_good_hits...
       // no fpTimes for U!
     }
@@ -511,7 +475,7 @@ Int_t THcScintillatorPlane::PulseHeightCorrection()
 
   fNScinGoodHits=0;
   for (Int_t i=0;i<fNScinHits;i++) {
-    Int_t j=((THcSignalHit*)fNegTDCHits->At(i))->GetPaddleNumber()-1;  
+    Int_t j=((THcHodoHit*)fHodoHits->At(i))->GetPaddleNumber()-1;  
     if (two_good_times[i]) { // both tubes fired
       fpTimes[fNScinGoodHits]=scin_corrected_time[i]-(fZpos+(j%2)*fDzpos)/(29.979*fBetaNominal);
       fScinTime[fNScinGoodHits]=scin_corrected_time[i];
diff --git a/src/THcScintillatorPlane.h b/src/THcScintillatorPlane.h
index f619a2b..70db898 100644
--- a/src/THcScintillatorPlane.h
+++ b/src/THcScintillatorPlane.h
@@ -61,10 +61,7 @@ class THcScintillatorPlane : public THaSubDetector {
 
   TClonesArray* fParentHitList;
 
-  TClonesArray* GetPosADC() { return fPosADCHits;};  // Ahmed
-  TClonesArray* GetNegADC() { return fNegADCHits;};  // Ahmed
-  TClonesArray* GetPosTDC() { return fPosTDCHits;};  // Ahmed
-  TClonesArray* GetNegTDC() { return fNegTDCHits;};  // Ahmed
+  TClonesArray* GetHits() { return fHodoHits;};
 
  protected:
 
@@ -72,10 +69,7 @@ class THcScintillatorPlane : public THaSubDetector {
   TClonesArray* frNegTDCHits;
   TClonesArray* frPosADCHits;
   TClonesArray* frNegADCHits;
-  TClonesArray* fPosTDCHits;
-  TClonesArray* fNegTDCHits;
-  TClonesArray* fPosADCHits;
-  TClonesArray* fNegADCHits;
+  TClonesArray* fHodoHits;
 
   Int_t fPlaneNum;		/* Which plane am I 1-4 */
   UInt_t fTotPlanes;            /* so we can read variables that are not indexed by plane id */
-- 
GitLab