From 8a544af749b0b5a6bda70f51c89027b45ff40fc2 Mon Sep 17 00:00:00 2001
From: "Stephen A. Wood" <saw@jlab.org>
Date: Mon, 28 Jan 2013 16:51:58 -0500
Subject: [PATCH] Pass a start time computed in THcHodoscope to
 THcDriftChamberPlane. A dummy value for the start time is used until the
 Hodoscope code actually computes the start time.

---
 src/THcDriftChamberPlane.cxx | 17 ++++++++++++++++-
 src/THcDriftChamberPlane.h   |  3 +++
 src/THcHodoscope.cxx         |  2 ++
 src/THcHodoscope.h           |  4 +++-
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/THcDriftChamberPlane.cxx b/src/THcDriftChamberPlane.cxx
index 5408b4f..f836582 100644
--- a/src/THcDriftChamberPlane.cxx
+++ b/src/THcDriftChamberPlane.cxx
@@ -15,6 +15,7 @@
 #include "THcParmList.h"
 #include "THcHitList.h"
 #include "THcDriftChamber.h"
+#include "THcHodoscope.h"
 #include "TClass.h"
 
 #include <cstring>
@@ -115,6 +116,14 @@ Int_t THcDriftChamberPlane::ReadDatabase( const TDatime& date )
     //if( something < 0 ) wire->SetFlag(1);
   }
 
+  THaApparatus* app = GetApparatus();
+  const char* nm = "hod";
+  if(  !app || 
+      !(fglHod = dynamic_cast<THcHodoscope*>(app->GetDetector(nm))) ) {
+    Warning(Here(here),"Hodoscope \"%s\" not found. "
+	    "Event-by-event time offsets will NOT be used!!",nm);
+  }
+
   return kOK;
 }
 //_____________________________________________________________________________
@@ -175,6 +184,12 @@ Int_t THcDriftChamberPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
   // Assumes that the hit list is sorted by plane, so we stop when the
   // plane doesn't agree and return the index for the next hit.
 
+  Double_t StartTime = 0.0;
+  // Would be nice to have a way to determine that the hodoscope decode was
+  // actually called for this event.
+  if( fglHod ) StartTime = fglHod->GetStartTime();
+  cout << "Start time " << StartTime << endl;
+
   //Int_t nTDCHits=0;
   fHits->Clear();
 
@@ -206,7 +221,7 @@ Int_t THcDriftChamberPlane::ProcessHits(TClonesArray* rawhits, Int_t nexthit)
 	  // Are we choose the same hit that ENGINE chooses?
 	  // cout << "Extra hit " << fPlaneNum << " " << wireNum << " " << rawtdc << endl;
 	} else {
-	  Double_t time = // -hstart_time (comes from h_trans_scin
+	  Double_t time = -StartTime   // (comes from h_trans_scin
 	    - rawtdc*fNSperChan + fPlaneTimeZero;
 	  // How do we get this start time from the hodoscope to here
 	  // (or at least have it ready by coarse process)
diff --git a/src/THcDriftChamberPlane.h b/src/THcDriftChamberPlane.h
index 152796d..7307a4a 100644
--- a/src/THcDriftChamberPlane.h
+++ b/src/THcDriftChamberPlane.h
@@ -20,6 +20,7 @@ class THaEvData;
 class THcDCWire;
 class THcDCHit;
 class THcDCTimeToDistConv;
+class THcHodoscope;
 
 /*class THaSignalHit;*/
 
@@ -73,6 +74,8 @@ class THcDriftChamberPlane : public THaSubDetector {
 
   THcDCTimeToDistConv* fTTDConv;  // Time-to-distance converter for this plane's wires
 
+  THcHodoscope* fglHod;		// Hodoscope to get start time
+
   ClassDef(THcDriftChamberPlane,0)
 };
 #endif
diff --git a/src/THcHodoscope.cxx b/src/THcHodoscope.cxx
index a56dbb8..6868124 100644
--- a/src/THcHodoscope.cxx
+++ b/src/THcHodoscope.cxx
@@ -575,6 +575,8 @@ Int_t THcHodoscope::Decode( const THaEvData& evdata )
   cout << endl;
 #endif
 
+  fStartTime = 500;		// Drift Chamber will need this
+
   return nhits;
 }
 
diff --git a/src/THcHodoscope.h b/src/THcHodoscope.h
index 609b8ed..2f3577d 100644
--- a/src/THcHodoscope.h
+++ b/src/THcHodoscope.h
@@ -32,6 +32,7 @@ public:
   virtual Int_t      ApplyCorrections( void );
 
   //  Int_t GetNHits() const { return fNhit; }
+  Double_t GetStartTime() const { return fStartTime; }
   Int_t GetScinIndex(Int_t nPlane, Int_t nPaddle);
   Int_t GetScinIndex(Int_t nSide, Int_t nPlane, Int_t nPaddle);
   Double_t GetPathLengthCentral();
@@ -50,7 +51,8 @@ protected:
 
   // Per-event data
 
-
+  Double_t fStartTime;
+  
   // Potential Hall C parameters.  Mostly here for demonstration
   Int_t fNPlanes,fMaxScinPerPlane,fMaxHodoScin; // number of planes; max number of scin/plane; product of the first two 
   Double_t fStartTimeCenter, fStartTimeSlop, fScinTdcToTime;
-- 
GitLab