From 71e27664b7859695a5237bd4b50a754ed1997452 Mon Sep 17 00:00:00 2001
From: Zafar <ahmed24z@uregina.ca>
Date: Thu, 25 Sep 2014 23:07:46 -0400
Subject: [PATCH] Golden track using prune:       Selection of golden track
 using prune method is added.       A bug is also fixed in THcHodoscope class 
      Number of pmts hits, focal plane time, good time for plane 4       and
 good time for plane 3 are set to the tracks in       THcHodoscope class.

---
 src/THcHallCSpectrometer.cxx | 297 ++++++++++++++++++++++++++++++++++-
 src/THcHallCSpectrometer.h   |  19 ++-
 src/THcHodoscope.cxx         |  61 +++----
 src/THcHodoscope.h           |   6 +-
 4 files changed, 343 insertions(+), 40 deletions(-)

diff --git a/src/THcHallCSpectrometer.cxx b/src/THcHallCSpectrometer.cxx
index 532c13d..9001464 100644
--- a/src/THcHallCSpectrometer.cxx
+++ b/src/THcHallCSpectrometer.cxx
@@ -53,6 +53,13 @@
 //      additional cuts on the tracks. These cuts are on dedx, beta 
 //      and on energy.
 //
+//  Golden track using prune. Zafar Ahmed. September 23 2014
+//      Selection of golden track using prune method is added.
+//      A bug is also fixed in THcHodoscope class
+//      Number of pmts hits, focal plane time, good time for plane 4 
+//      and good time for plane 3 are set to the tracks in 
+//      THcHodoscope class.
+//
 //////////////////////////////////////////////////////////////////////////
 
 #include "THcHallCSpectrometer.h"
@@ -203,7 +210,9 @@ Int_t THcHallCSpectrometer::ReadDatabase( const TDatime& date )
     {"pcentral_offset",       &fPCentralOffset,        kDouble               },
     {"pcentral",              &fPCentral,              kDouble               },
     {"theta_lab",             &fTheta_lab,             kDouble               },
+    {"partmass",              &fPartMass,              kDouble               },
     {"sel_using_scin",        &fSelUsingScin,          kInt,            0,  1},
+    {"sel_using_prune",       &fSelUsingPrune,         kInt,            0,  1},
     {"sel_ndegreesmin",       &fSelNDegreesMin,        kDouble,         0,  1},
     {"sel_dedx1min",          &fSeldEdX1Min,           kDouble,         0,  1},
     {"sel_dedx1max",          &fSeldEdX1Max,           kDouble,         0,  1},
@@ -216,14 +225,36 @@ Int_t THcHallCSpectrometer::ReadDatabase( const TDatime& date )
     {"scin_2x_dzpos",         &fScin2XdZpos,           kDouble,         0,  1},
     {"scin_2y_zpos",          &fScin2YZpos,            kDouble,         0,  1},
     {"scin_2y_dzpos",         &fScin2YdZpos,           kDouble,         0,  1},
+    {"prune_xp",              &fPruneXp,               kDouble,         0,  1},
+    {"prune_yp",              &fPruneYp,               kDouble,         0,  1},
+    {"prune_ytar",            &fPruneYtar,             kDouble,         0,  1},
+    {"prune_delta",           &fPruneDelta,            kDouble,         0,  1},
+    {"prune_beta",            &fPruneBeta,             kDouble,         0,  1},
+    {"prune_df",              &fPruneDf,               kDouble,         0,  1},
+    {"prune_chibeta",         &fPruneChiBeta,          kDouble,         0,  1},
+    {"prune_npmt",            &fPruneNPMT,           kDouble,         0,  1},
+    {"prune_fptime",          &fPruneFpTime,             kDouble,         0,  1},
     {0}
   };
   gHcParms->LoadParmValues((DBRequest*)&list,prefix);
   //
 
-  cout << "\n\n\nhodo planes = " << fNPlanes << endl;
-  cout << " fPcentral = " <<  fPCentral << " " <<fPCentralOffset << endl; 
-  cout << " fThate_lab = " <<  fTheta_lab << " " <<fThetaCentralOffset << endl; 
+
+  cout <<  "\n\n\nhodo planes = " << fNPlanes << endl;
+  cout <<  "sel using scin = "    << fSelUsingScin << endl;
+  cout <<  "fPruneXp = "          <<  fPruneXp << endl; 
+  cout <<  "fPruneYp = "          <<  fPruneYp << endl; 
+  cout <<  "fPruneYtar = "        <<  fPruneYtar << endl; 
+  cout <<  "fPruneDelta = "       <<  fPruneDelta << endl; 
+  cout <<  "fPruneBeta = "        <<  fPruneBeta << endl; 
+  cout <<  "fPruneDf = "          <<  fPruneDf << endl; 
+  cout <<  "fPruneChiBeta = "     <<  fPruneChiBeta << endl; 
+  cout <<  "fPruneFpTime = "      <<  fPruneFpTime << endl; 
+  cout <<  "fPruneNPMT = "        <<  fPruneNPMT << endl; 
+  cout <<  "sel using prune = "   <<  fSelUsingPrune << endl;
+  cout <<  "fPartMass = "         <<  fPartMass << endl;
+  cout <<  "fPcentral = "         <<  fPCentral << " " <<fPCentralOffset << endl; 
+  cout <<  "fThate_lab = "        <<  fTheta_lab << " " <<fThetaCentralOffset << endl; 
   fPCentral= fPCentral*(1.+fPCentralOffset/100.);
   // Check that these offsets are in radians
   fTheta_lab=fTheta_lab + fThetaCentralOffset*TMath::RadToDeg();
@@ -354,6 +385,7 @@ Int_t THcHallCSpectrometer::FindVertices( TClonesArray& tracks )
     // There is an hpcentral_offset that needs to be applied somewhere.
     // (happly_offs)
     track->SetMomentum(fPCentral*(1+track->GetDp()/100.0));
+
   }
 
 
@@ -394,7 +426,7 @@ Int_t THcHallCSpectrometer::FindVertices( TClonesArray& tracks )
 Int_t THcHallCSpectrometer::TrackCalc()
 {
 
-  if ( fSelUsingScin == 0 ) {
+  if ( ( fSelUsingScin == 0 ) && ( fSelUsingPrune == 0 ) ) {
     
     if( GetTrSorting() )
       fTracks->Sort();
@@ -585,14 +617,265 @@ Int_t THcHallCSpectrometer::TrackCalc()
 	  }
 	} // loop over trakcs
 	
-      } // Condition for fNtrack > 0
+      } 
 
-    } else //  condtion fSelUsingScin == 1
+    } else // Condition for fNtrack > 0
       fGoldenTrack = NULL;
     
-  }
+  } //  condtion fSelUsingScin == 1 
 
+  //-------------------------------------------------------------------------------------
+  //-------------------------------------------------------------------------------------
+  //-------------------------------------------------------------------------------------
+  //-------------------------------------------------------------------------------------
+
+  if ( fSelUsingPrune == 1 ){
+    
+    fPruneXp      = TMath::Max( 0.08, fPruneXp); 
+    fPruneYp      = TMath::Max( 0.04, fPruneYp); 
+    fPruneYtar    = TMath::Max( 4.0,  fPruneYtar); 
+    fPruneDelta   = TMath::Max( 13.0, fPruneDelta); 
+    fPruneBeta    = TMath::Max( 0.1,  fPruneBeta); 
+    fPruneDf      = TMath::Max( 1.0,  fPruneDf); 
+    fPruneChiBeta = TMath::Max( 2.0,  fPruneChiBeta); 
+    fPruneFpTime  = TMath::Max( 5.0,  fPruneFpTime); 
+    fPruneNPMT    = TMath::Max( 6.0,  fPruneNPMT); 
     
+    Int_t ptrack = 0, fNGood;
+    Double_t fP = 0., fBetaP = 0.; // , fPartMass = 0.00051099; // 5.10989979E-04 Fix it
+
+    if ( fNtracks > 0 ) {
+      fChi2Min   = 10000000000.0;
+      fGoodTrack = 0;    
+      fKeep      = new Bool_t [fNtracks];  
+      fReject    = new Int_t  [fNtracks];  
+
+      THaTrack *testTracks[fNtracks];
+
+      // ! Initialize all tracks to be good
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){
+	fKeep[ptrack] = kTRUE;
+	fReject[ptrack] = 0;
+	testTracks[ptrack] = static_cast<THaTrack*>( fTracks->At(ptrack) );      
+        if (!testTracks[ptrack]) return -1;	
+      }      
+      
+      // ! Prune on xptar
+      fNGood = 0;
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){
+	if ( ( TMath::Abs( testTracks[ptrack]->GetTTheta() ) < fPruneXp ) && ( fKeep[ptrack] ) ){	  
+	  fNGood ++;
+	}	
+      }
+      if ( fNGood > 0 ) {
+	for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){
+	  if ( TMath::Abs( testTracks[ptrack]->GetTTheta() ) >= fPruneXp ){
+	    fKeep[ptrack] = kFALSE;
+	    fReject[ptrack] = fReject[ptrack] + 1;
+	  }
+	}
+      }
+      
+      // ! Prune on yptar
+      fNGood = 0;
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){
+	if ( ( TMath::Abs( testTracks[ptrack]->GetTPhi() ) < fPruneYp ) && ( fKeep[ptrack] ) ){
+	  fNGood ++; 
+	}
+      }
+      if (fNGood > 0 ) {
+	for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){
+	  if ( TMath::Abs( testTracks[ptrack]->GetTPhi() ) >= fPruneYp ){
+	    fKeep[ptrack] = kFALSE;
+	    fReject[ptrack] = fReject[ptrack] + 2;
+	    
+	  }		
+	}
+      }
+      
+      // !     Prune on ytar
+      fNGood = 0;
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	
+	if ( ( TMath::Abs( testTracks[ptrack]->GetTY() ) < fPruneYtar ) && ( fKeep[ptrack] ) ){
+	  fNGood ++; 
+	}	
+      }      
+      if (fNGood > 0 ) {
+	for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){
+	  if ( TMath::Abs( testTracks[ptrack]->GetTY() ) >= fPruneYtar ){
+	    fKeep[ptrack] = kFALSE;
+	    fReject[ptrack] = fReject[ptrack] + 10;
+	  }
+	}
+      }
+      
+      // !     Prune on delta
+      fNGood = 0;
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	
+	if ( ( TMath::Abs( testTracks[ptrack]->GetDp() ) < fPruneDelta ) && ( fKeep[ptrack] ) ){
+	  fNGood ++; 
+	}	
+      }            
+      if (fNGood > 0 ) {
+	for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){
+	  if ( TMath::Abs( testTracks[ptrack]->GetDp() ) >= fPruneDelta ){
+	    fKeep[ptrack] = kFALSE;
+	    fReject[ptrack] = fReject[ptrack] + 20;
+	  }
+	}
+      }      
+            
+      // !     Prune on beta
+      fNGood = 0;
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      
+	fP = testTracks[ptrack]->GetP();
+	fBetaP = fP / TMath::Sqrt( fP * fP + fPartMass * fPartMass );       
+	if ( ( TMath::Abs( testTracks[ptrack]->GetBeta() - fBetaP ) < fPruneBeta ) && ( fKeep[ptrack] ) ){
+	  fNGood ++; 
+	}	
+      }
+      if (fNGood > 0 ) {
+	for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      
+	  fP = testTracks[ptrack]->GetP();
+	  fBetaP = fP / TMath::Sqrt( fP * fP + fPartMass * fPartMass );       
+	  if ( TMath::Abs( testTracks[ptrack]->GetBeta() - fBetaP ) >= fPruneBeta ) {	    
+	    fKeep[ptrack] = kFALSE;
+	    fReject[ptrack] = fReject[ptrack] + 100;	          
+	  }	  
+	}	
+      }
+      
+      // !     Prune on deg. freedom for track chisq
+      fNGood = 0;
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      	
+	if ( ( testTracks[ptrack]->GetNDoF() >= fPruneDf ) && ( fKeep[ptrack] ) ){
+	  fNGood ++; 	  
+	}		
+      }          
+      if (fNGood > 0 ) {
+	for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      
+	  if ( testTracks[ptrack]->GetNDoF() < fPruneDf ){	  
+	    fKeep[ptrack] = kFALSE;
+	    fReject[ptrack] = fReject[ptrack] + 200;
+	  }
+	}
+      }
+
+      //!     Prune on num pmt hits
+      fNGood = 0;
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      	
+	if ( ( testTracks[ptrack]->GetNPMT() >= fPruneNPMT ) && ( fKeep[ptrack] ) ){
+	  fNGood ++; 	  
+	}	        		
+      }
+      if (fNGood > 0 ) {
+	for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      
+	  if ( testTracks[ptrack]->GetNPMT() < fPruneNPMT ){
+	    fKeep[ptrack] = kFALSE;
+	    fReject[ptrack] = fReject[ptrack] + 100000;
+	  }
+	}
+      }
+
+      // !     Prune on beta chisqr
+      fNGood = 0;
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      	
+	if ( ( testTracks[ptrack]->GetBetaChi2() < fPruneChiBeta ) && 
+	     ( testTracks[ptrack]->GetBetaChi2() > 0.01 )          &&   ( fKeep[ptrack] ) ){
+	  fNGood ++; 	  
+	}	        			
+      }
+      if (fNGood > 0 ) {
+	for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      
+	  if ( ( testTracks[ptrack]->GetBetaChi2() >= fPruneChiBeta ) || 
+	       ( testTracks[ptrack]->GetBetaChi2() <= 0.01          ) ){
+	    fKeep[ptrack] = kFALSE;
+	    fReject[ptrack] = fReject[ptrack] + 1000;
+	  }	  	  
+	}
+      }
+
+      // !     Prune on fptime
+      fNGood = 0;
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      	
+	if ( ( TMath::Abs( testTracks[ptrack]->GetFPTime() - fHodo->GetStartTimeCenter() ) < fPruneFpTime )  &&   
+	     ( fKeep[ptrack] ) ){
+	  fNGood ++; 	  
+	}	        			
+      }
+      if (fNGood > 0 ) {
+	for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      
+	  if ( TMath::Abs( testTracks[ptrack]->GetFPTime() - fHodo->GetStartTimeCenter() ) >= fPruneFpTime ) {
+	    fKeep[ptrack] = kFALSE;
+	    fReject[ptrack] = fReject[ptrack] + 2000;	    	    
+	  }
+	}
+      }
+      
+      // !     Prune on Y2 being hit
+      fNGood = 0;
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      	
+	if ( ( testTracks[ptrack]->GetGoodPlane4() == 1 )  &&  fKeep[ptrack] ) {
+	  fNGood ++; 	  	  
+	}	        			
+      }
+      if (fNGood > 0 ) {
+	for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      
+	  if ( testTracks[ptrack]->GetGoodPlane4() != 1 ) {
+	    fKeep[ptrack] = kFALSE;
+	    fReject[ptrack] = fReject[ptrack] + 10000;	    	    
+	  }
+	}
+      }      
+      
+      // !     Prune on X2 being hit
+      fNGood = 0;
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      	
+	if ( ( testTracks[ptrack]->GetGoodPlane3() == 1 )  &&  fKeep[ptrack] ) {
+	  fNGood ++; 	  	  
+	}	        			
+      }
+      if (fNGood > 0 ) {
+	for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      
+	  if ( testTracks[ptrack]->GetGoodPlane3() != 1 ) {
+	    fKeep[ptrack] = kFALSE;
+	    fReject[ptrack] = fReject[ptrack] + 20000;	    	    	    	    
+	  }
+	}
+      }      
+      
+      // !     Pick track with best chisq if more than one track passed prune tests
+      Double_t fChi2PerDeg = 0.;
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	      	
+
+	fChi2PerDeg =  testTracks[ptrack]->GetChi2() / testTracks[ptrack]->GetNDoF();
+
+	if ( ( fChi2PerDeg < fChi2Min ) && ( fKeep[ptrack] ) ){
+	  fGoodTrack = ptrack;
+	  fChi2Min = fChi2PerDeg;
+	}	
+      }      
+
+      fGoldenTrack = static_cast<THaTrack*>( fTracks->At(fGoodTrack) );
+      fTrkIfo      = *fGoldenTrack;
+      fTrk         = fGoldenTrack;
+      
+      delete [] fKeep;             fKeep = NULL;        
+      delete [] fReject;           fKeep = NULL;        
+      for ( ptrack = 0; ptrack < fNtracks; ptrack++ ){	
+	testTracks[ptrack] = NULL;
+	delete 	testTracks[ptrack];
+      }	      
+      
+    } else // Condition for fNtrack > 0
+      fGoldenTrack = NULL;
+  } // if prune
+  
+  //-------------------------------------------------------------------------------------
+  //-------------------------------------------------------------------------------------
+  //-------------------------------------------------------------------------------------
+  //-------------------------------------------------------------------------------------
+  //  cout << endl;
   return TrackTimes( fTracks );
 }
 
diff --git a/src/THcHallCSpectrometer.h b/src/THcHallCSpectrometer.h
index 5e89dfd..56bce13 100644
--- a/src/THcHallCSpectrometer.h
+++ b/src/THcHallCSpectrometer.h
@@ -55,13 +55,28 @@ protected:
 
   Int_t        MAXHODHITS;
 
+  Bool_t*      fKeep;
+  Int_t*       fReject;
+
+  Double_t     fPartMass;
+  Double_t     fPruneXp;
+  Double_t     fPruneYp;
+  Double_t     fPruneYtar;
+  Double_t     fPruneDelta;
+  Double_t     fPruneBeta;
+  Double_t     fPruneDf;
+  Double_t     fPruneChiBeta;
+  Double_t     fPruneFpTime;
+  Double_t     fPruneNPMT;
+
   Int_t        fGoodTrack;
   Int_t        fSelUsingScin;
+  Int_t        fSelUsingPrune;
   Int_t        fNPlanes;
   Int_t        fNtracks;
 
-  Int_t*    f2XHits;
-  Int_t*    f2YHits;
+  Int_t*       f2XHits;
+  Int_t*       f2YHits;
 
   Double_t*    fX2D;
   Double_t*    fY2D;
diff --git a/src/THcHodoscope.cxx b/src/THcHodoscope.cxx
index 5c3a186..218e6eb 100644
--- a/src/THcHodoscope.cxx
+++ b/src/THcHodoscope.cxx
@@ -715,7 +715,7 @@ Int_t THcHodoscope::Decode( const THaEvData& evdata )
   // if (evdata.GetEvNum()>1000) 
   //   cout <<"\nhcana_event " << evdata.GetEvNum()<<endl;
   
-  fCheckEvent = evdata.GetEvNum();
+  //  fCheckEvent = evdata.GetEvNum();
 
   if(gHaCuts->Result("Pedestal_event")) {
     Int_t nexthit = 0;
@@ -809,9 +809,9 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 
   Int_t Ntracks = tracks.GetLast()+1; // Number of reconstructed tracks
   Int_t fPaddle = 0, fIndex, k, fJMax, fMaxHit, ip, ihit, itrack;
-  Int_t fNfpTime, fSumfpTime, fRawIndex = -1; //, fNScinHits[fNPlanes]; 
-  Double_t fScinTrnsCoord, fScinLongCoord, fScinCenter;
-  Double_t fP, fBetaP, fXcoord, fYcoord, fTMin;
+  Int_t fRawIndex = -1; //, fNScinHits[fNPlanes]; 
+  Double_t fScinTrnsCoord, fScinLongCoord, fScinCenter, fSumfpTime;
+  Double_t fP, fBetaP, fXcoord, fYcoord, fTMin, fNfpTime;
 
   // -------------------------------------------------
 
@@ -823,6 +823,7 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
       fdEdX[m][k] = 0.;
     }
 
+    fNPmtHit[m] = 0;
     fGoodRawPad[m] = 0;
     fScinSigma[m] = 0.;
     fHitPaddle[m] = 0.;
@@ -835,7 +836,6 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
     fTimeNeg[m] = 0.;
     fScinTimefp[m] = 0.; 
     fGoodScinTime[m] = kFALSE;
-    //    fScinGoodTime[m] = kFALSE;
     
     fGoodTDCPos[m] = kFALSE;
     fGoodTDCNeg[m] = kFALSE;
@@ -856,8 +856,8 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	fGoodPlaneTime[ip] = kFALSE; 
 	fNScinHits[ip] = 0;
       }
-      
-      fNfpTime = 0;
+
+      fNfpTime = 0.;
       fBetaChisq[itrack] = -3;
       fTimeAtFP[itrack] = 0.;
       fSumfpTime = 0.; // Line 138
@@ -890,6 +890,8 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
       // Loop over scintillator planes.
       // In ENGINE, its loop over good scintillator hits.
       
+      for ( k = 0; k < MAXHODHITS; k++ ){ fGoodScinTime[k] = kFALSE; }
+
       fGoodTimeIndex = -1;
       for( ip = 0; ip < fNPlanes; ip++ ) {
 	
@@ -1008,12 +1010,10 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	  }
 	} // fJMax > 0 condition
 	
-	// fScinPosTime = new Double_t [MAXHODHITS];
-	// fScinNegTime = new Double_t [MAXHODHITS];
-
 	for ( k = 0; k < MAXHODHITS; k++ ){
 	  fScinPosTime[k] = 0;
 	  fScinNegTime[k] = 0;
+	  //	  fGoodScinTime[k] = kFALSE;
 	}
 
 	//---------------------------------------------------------------------------------------------	
@@ -1101,20 +1101,19 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	    } // check for good neg TDC condition
 	    
 	    // ** Calculate ave time for scin and error.
+
 	    if ( fGoodTDCPos[fGoodTimeIndex] ){
 	      if ( fGoodTDCNeg[fGoodTimeIndex] ){	
 		fScinTime[fGoodTimeIndex]  = ( fScinPosTime[ihit] + fScinNegTime[ihit] ) / 2.;
 		fScinSigma[fGoodTimeIndex] = TMath::Sqrt( fHodoPosSigma[fIndex] * fHodoPosSigma[fIndex] + 
 							  fHodoNegSigma[fIndex] * fHodoNegSigma[fIndex] )/2.;
 		fGoodScinTime[fGoodTimeIndex] = kTRUE;
-		//		fScinGoodTime[fGoodTimeIndex] = kTRUE;
 		//		fNtofPairs ++;
 	      }
 	      else{
 		fScinTime[fGoodTimeIndex] = fScinPosTime[ihit];
 		fScinSigma[fGoodTimeIndex] = fHodoPosSigma[fIndex];
 		fGoodScinTime[fGoodTimeIndex] = kTRUE;
-		//		fScinGoodTime[fGoodTimeIndex] = kTRUE;
 	      }
 	    }
 	    else {
@@ -1122,7 +1121,6 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 		fScinTime[fGoodTimeIndex] = fScinNegTime[ihit];
 		fScinSigma[fGoodTimeIndex] = fHodoNegSigma[fIndex];
 		fGoodScinTime[fGoodTimeIndex] = kTRUE;
-		//	fScinGoodTime[fGoodTimeIndex] = kTRUE;
 	      }
 	    } // In h_tof.f this includes the following if condition for time at focal plane
 	    // // because it is written in FORTRAN code
@@ -1142,8 +1140,8 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	      // Right now we do not need this code for beta and chisquare
 	      //
 	      //
-	      // fSumfpTime = fSumfpTime + fScinTimefp[ihit];
-	      // fNfpTime ++;
+	      fSumfpTime = fSumfpTime + fScinTimefp[ihit];
+	      fNfpTime ++;
 	      //
 	      // ---------------------------------------------------------------------------
 
@@ -1157,12 +1155,12 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	      // Date: July 8 2014
 	      // This counts the pmt hits. Right now we don't need it so it is commentd off
 	      //
-	      // if ( ( fGoodTDCPos[fGoodTimeIndex] ) && ( fGoodTDCNeg[fGoodTimeIndex] ) ){
-	      // 	fNPmtHit[itrack] = fNPmtHit[itrack] + 2;
-	      // }
-	      // else {
-	      // 	fNPmtHit[itrack] = fNPmtHit[itrack] + 1;
-	      // }
+	      if ( ( fGoodTDCPos[fGoodTimeIndex] ) && ( fGoodTDCNeg[fGoodTimeIndex] ) ){
+	       	fNPmtHit[itrack] = fNPmtHit[itrack] + 2;
+	      }
+	      else {
+	       	fNPmtHit[itrack] = fNPmtHit[itrack] + 1;
+	      }	      
 	      // ---------------------------------------------------------------------------
 
 
@@ -1204,7 +1202,13 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	  if ( fGoodScinTime[fGoodTimeIndex] ){
 	    fGoodPlaneTime[ip] = kTRUE;
 	  }
-	  	  
+	  
+	  if ( fGoodPlaneTime[2]  )	theTrack->SetGoodPlane3( 1 );
+	  if ( !fGoodPlaneTime[2] )	theTrack->SetGoodPlane3( 0 );
+	  
+	  if ( fGoodPlaneTime[3]  )	theTrack->SetGoodPlane4( 1 );
+	  if ( !fGoodPlaneTime[3] )	theTrack->SetGoodPlane4( 0 );
+	  
 	} // Second loop over hits of a scintillator plane ends here
       } // Loop over scintillator planes ends here
 
@@ -1217,6 +1221,7 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
       //------------------------------------------------------------------------------
       //------------------------------------------------------------------------------
 
+
       // * * Fit beta if there are enough time measurements (one upper, one lower)
       if ( ( ( fGoodPlaneTime[0] ) || ( fGoodPlaneTime[1] ) ) && 
 	   ( ( fGoodPlaneTime[2] ) || ( fGoodPlaneTime[3] ) ) ){	
@@ -1285,9 +1290,6 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
 	  pathNorm = TMath::Sqrt( 1. + theTrack->GetTheta() * theTrack->GetTheta() + theTrack->GetPhi() * theTrack->GetPhi() );
 	  fBeta[itrack] = fBeta[itrack] / pathNorm;
 	  fBeta[itrack] = fBeta[itrack] / 29.979;    // velocity / c
-	  
-	  // cout << "track = " << itrack + 1 
-	  //      << "   beta = " << fBeta[itrack] << endl;
 
 
 	}  // condition for tmpDenom	
@@ -1318,9 +1320,9 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
       //
       // Right now we do not need this code for beta and chisquare
       //
-      // if ( fNfpTime != 0 ){
-      // 	// fTimeAtFP[itrack] = ( fSumfpTime / fNfpTime ); 
-      // }
+      if ( fNfpTime != 0 ){
+	fTimeAtFP[itrack] = ( fSumfpTime / fNfpTime ); 
+      }
       //
       // ---------------------------------------------------------------------------
       
@@ -1341,6 +1343,9 @@ Int_t THcHodoscope::FineProcess( TClonesArray& tracks )
       theTrack->SetDedx(fdEdX[itrack][0]);
       theTrack->SetBeta(fBeta[itrack]);
       theTrack->SetBetaChi2( fBetaChisq[itrack] );
+      theTrack->SetNPMT( fNPmtHit[itrack] );
+      theTrack->SetFPTime( fTimeAtFP[itrack] );
+
 
     } // Main loop over tracks ends here.         
    
diff --git a/src/THcHodoscope.h b/src/THcHodoscope.h
index 2189bd4..48da162 100644
--- a/src/THcHodoscope.h
+++ b/src/THcHodoscope.h
@@ -81,7 +81,7 @@ public:
   //  Int_t GetEvent(){ return fCheckEvent;}
 
   Double_t GetHodoPosSigma(Int_t iii) const {return fHodoPosSigma[iii];}
-  Double_t GetHodoNegSigma(Int_t iii) const {return fHodoNegSigma[iii];}
+  Double_t GetHodoNegSigma(Int_t iii) const {return fNPmtHit[iii];}
 
 
   const TClonesArray* GetTrackHits() const { return fTrackProj; }
@@ -146,11 +146,11 @@ protected:
 
   THcShower* fShower;
 
-  Int_t        fCheckEvent;
+  //  Int_t        fCheckEvent;
 
   Int_t        fGoodTrack;
   Int_t        MAXHODHITS;
-  //  Int_t        fSelUsingScin;
+
   Int_t        fSelNDegreesMin;
   Double_t     fSeldEdX1Min;
   Double_t     fSeldEdX1Max;
-- 
GitLab