From 17f3b5591509b031b8fab38b75332121ccff6dab Mon Sep 17 00:00:00 2001
From: Vardan Tadevosyan <tadevosn@jlab.org>
Date: Thu, 14 Aug 2014 10:58:38 -0400
Subject: [PATCH] Move energy to track assignment from THcHallCSpectrometer to
 the shower counter's FineProcess.

       Remove THcHallCSpectrometer::TrackEnergies method.
       Add GetShEnergy call for each tack in THcShower::fineProcess.
---
 examples/PARAM/hdebug.param  |  2 +-
 src/THcHallCSpectrometer.cxx | 39 ------------------------------------
 src/THcHallCSpectrometer.h   |  1 -
 src/THcShower.cxx            | 33 ++++++++++++++++++++++++------
 4 files changed, 28 insertions(+), 47 deletions(-)

diff --git a/examples/PARAM/hdebug.param b/examples/PARAM/hdebug.param
index 950b1f6..2f7dc21 100644
--- a/examples/PARAM/hdebug.param
+++ b/examples/PARAM/hdebug.param
@@ -65,7 +65,7 @@
 ;  hdbg_clusters_cal   call h_prt_cal_clusters
    hdbg_clusters_cal = 0
 ;  hdbg_tracks_cal     call h_prt_cal_tracks
-   hdbg_tracks_cal = 0
+   hdbg_tracks_cal = 1
 ;  hdbg_tests_cal      call h_prt_cal_tests    HMS_TRACK_TESTS
    hdbg_tests_cal = 0
 ;
diff --git a/src/THcHallCSpectrometer.cxx b/src/THcHallCSpectrometer.cxx
index dc5bfc5..7ce0bfc 100644
--- a/src/THcHallCSpectrometer.cxx
+++ b/src/THcHallCSpectrometer.cxx
@@ -313,48 +313,9 @@ Int_t THcHallCSpectrometer::TrackCalc()
 {
   // Additioal track calculations. At present, we only calculate beta here.
 
-  // cout << "THcHallCSpectrometer::TrackCalc is called xxxxxxxxxxxxxxxxx\n";
-
-  TrackEnergies(fTracks);
-
   return TrackTimes( fTracks );
 }
 
-//_____________________________________________________________________________
-Int_t THcHallCSpectrometer::TrackEnergies( TClonesArray* Tracks ) {
-
-  // Example code for track energy assignments from shower counter.
-
-  //  cout << "THcHallCSpectrometer::TrackEnergies called -----------------\n" ;
-  
-  if ( !Tracks ) return -1;
-  
-  THaTrack *track=0;
-  Int_t ntrack = GetNTracks();
-
-  //  cout << "     number of tracks " << ntrack << endl;
-
-  for ( Int_t itrk=0; itrk < ntrack; itrk++ ) {
-
-    Double_t energy = kBig;
-
-    track = static_cast<THaTrack*>(Tracks->At(itrk));
-
-    TIter nextDet( fNonTrackingDetectors );
-    THaNonTrackingDetector *det;
-    while ((det = static_cast<THaNonTrackingDetector*>(nextDet()))) {
-      
-      THcShower *sh = dynamic_cast<THcShower*>(det);
-      if ( sh ) energy = sh->GetShEnergy(track);
-    }
-
-    track->SetEnergy(energy);
-    // cout << "track " << itrk << "   energy = " << track->GetEnergy() << endl;
-  }
-
-  return ntrack;
-}
-
 //_____________________________________________________________________________
 Int_t THcHallCSpectrometer::TrackTimes( TClonesArray* Tracks ) {
   // Do the actual track-timing (beta) calculation.
diff --git a/src/THcHallCSpectrometer.h b/src/THcHallCSpectrometer.h
index 90e1be5..f906546 100644
--- a/src/THcHallCSpectrometer.h
+++ b/src/THcHallCSpectrometer.h
@@ -21,7 +21,6 @@ public:
   virtual Int_t   FindVertices( TClonesArray& tracks );
   virtual Int_t   TrackCalc();
   virtual Int_t   TrackTimes( TClonesArray* tracks );
-  Int_t TrackEnergies( TClonesArray* tracks );
 
   virtual Int_t   ReadRunDatabase( const TDatime& date );
 
diff --git a/src/THcShower.cxx b/src/THcShower.cxx
index 8cd56bc..060d120 100644
--- a/src/THcShower.cxx
+++ b/src/THcShower.cxx
@@ -996,14 +996,35 @@ Float_t THcShower::GetShEnergy(THaTrack* Track) {
 //_____________________________________________________________________________
 Int_t THcShower::FineProcess( TClonesArray& tracks )
 {
-  // Reconstruct coordinates of particle track cross point with shower
-  // plane, and copy the data into the following local data structure:
+
+  // Shower energy assignment to the spectrometer tracks.
   //
-  // Units of measurements are meters.
 
-  // Calculation of coordinates of particle track cross point with shower
-  // plane in the detector coordinate system. For this, parameters of track 
-  // reconstructed in THaVDC::FineTrack() are used.
+  Int_t Ntracks = tracks.GetLast()+1;   // Number of reconstructed tracks
+
+  if (fdbg_tracks_cal) {
+    cout << endl;
+    cout << "THcShower::FineProcess: Number of tracks = " << Ntracks << endl;
+  }
+
+  for (Int_t itrk=0; itrk<Ntracks; itrk++) {
+
+    THaTrack* theTrack = static_cast<THaTrack*>( tracks[itrk] );
+
+    Float_t energy = GetShEnergy(theTrack);
+    theTrack->SetEnergy(energy);
+
+    if (fdbg_tracks_cal) {
+      cout << "THcShower::FineProcess, Track " << itrk << ": "
+	   << "  X = " << theTrack->GetX()
+	   << "  Y = " << theTrack->GetY()
+	   << "  Theta = " << theTrack->GetTheta()
+	   << "  Phi = " << theTrack->GetPhi()
+	   << "  Enegy = " << energy << endl;
+    }
+
+
+  }       //over tracks
 
   return 0;
 }
-- 
GitLab