From c4736336586a924a2bda71475ad5677f080157e4 Mon Sep 17 00:00:00 2001
From: Vardan Tadevosyan <tadevosn@jlab.org>
Date: Mon, 20 Oct 2014 09:22:46 -0400
Subject: [PATCH] Make association of hit clusters to tracks in the HMS more
 consistent with Engine.

	   Reverse order of cycling through clusters in THcShower::MatchCluster.
---
 src/THcShower.cxx | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/src/THcShower.cxx b/src/THcShower.cxx
index 531def6..23cd933 100644
--- a/src/THcShower.cxx
+++ b/src/THcShower.cxx
@@ -697,18 +697,19 @@ Int_t THcShower::CoarseProcess( TClonesArray& tracks)
 
       THcShowerCluster* cluster = (*fClusterList).ListedCluster(i);
 
-      //cout << "Cluster #" << i 
-	   //<<":  E=" << (*cluster).clE() 
-	   //<< "  Epr=" << (*cluster).clEpr()
-	   //<< "  X=" << (*cluster).clX()
-	   //<< "  Z=" << (*cluster).clZ()
-	   //<< "  size=" << (*cluster).clSize()
-	   //<< endl;
+      cout << "Cluster #" << i 
+	   <<":  E=" << (*cluster).clE() 
+	   << "  Epr=" << (*cluster).clEpr()
+	   << "  X=" << (*cluster).clX()
+	   << "  Z=" << (*cluster).clZ()
+	   << "  size=" << (*cluster).clSize()
+	   << endl;
 
       for (UInt_t j=0; j!=(*cluster).clSize(); j++) {
-       	//THcShowerHit* hit = (*cluster).ClusteredHit(j);
-       	//cout << "  hit #" << j << ":  "; (*hit).show();
+       	THcShowerHit* hit = (*cluster).ClusteredHit(j);
+       	cout << "  hit #" << j << ":  "; (*hit).show();
       }
+      //      cout << endl;
 
     }
   }
@@ -920,10 +921,10 @@ Int_t THcShower::MatchCluster(THaTrack* Track,
 	   << "  Pathl = " << pathl
 	   << endl;
 
-    inFidVol = (XTrFront < fvXmax) && (XTrFront > fvXmin) &&
-               (YTrFront < fvYmax) && (YTrFront > fvYmin) &&
-               (XTrBack < fvXmax) && (XTrBack > fvXmin) &&
-               (YTrBack < fvYmax) && (YTrBack > fvYmin);
+    inFidVol = (XTrFront <= fvXmax) && (XTrFront >= fvXmin) &&
+               (YTrFront <= fvYmax) && (YTrFront >= fvYmin) &&
+               (XTrBack <= fvXmax) && (XTrBack >= fvXmin) &&
+               (YTrBack <= fvYmax) && (YTrBack >= fvYmin);
 
     if (fdbg_tracks_cal) 
       cout << "  Fiducial volume test: inFidVol = " << inFidVol << endl;
@@ -936,7 +937,12 @@ Int_t THcShower::MatchCluster(THaTrack* Track,
 
   if (inFidVol) {
 
-    for (Int_t i=0; i<fNclust; i++) {
+    //    for (Int_t i=0; i<fNclust; i++) {
+
+    // Since hits and clusters are in reverse order (with respect to Engine),
+    // search backwards to be consistent with Engine.
+    //
+    for (Int_t i=fNclust-1; i>-1; i--) {
 
       THcShowerCluster* cluster = (*fClusterList).ListedCluster(i);
 
@@ -944,7 +950,7 @@ Int_t THcShower::MatchCluster(THaTrack* Track,
 
       if (dx <= (0.5*BlockThick[0] + fSlop)) {
 	fNtracks++;  // number of shower tracks (Consistent with engine)
-	if (dx <= deltaX) {
+	if (dx < deltaX) {
 	  mclust = i;
 	  deltaX = dx;
 	}
-- 
GitLab