From f42cba7c96e9a03f5231db289af937908c15008b Mon Sep 17 00:00:00 2001
From: "Stephen A. Wood" <saw@jlab.org>
Date: Thu, 10 Nov 2016 12:10:08 -0500
Subject: [PATCH] Make raster derived position/angles, with offsets available
 to Beamline

---
 src/THcRaster.cxx | 33 ++++++++++++++++++++++++++++++---
 src/THcRaster.h   | 11 +++++++++--
 2 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/src/THcRaster.cxx b/src/THcRaster.cxx
index 3358f75..ca66490 100644
--- a/src/THcRaster.cxx
+++ b/src/THcRaster.cxx
@@ -8,6 +8,8 @@
 \author Buddhini Waidyawansa
 
 */
+#include "TMath.h"
+
 #include "THcRaster.h"
 #include "THaEvData.h"
 #include "THaDetMap.h"
@@ -17,7 +19,6 @@
 #include "THcGlobals.h"
 #include "THaGlobals.h"
 
-
 //#include "THcHitList.h"
 
 #include <cstring>
@@ -84,11 +85,24 @@ Int_t THcRaster::ReadDatabase( const TDatime& date )
     {"frx_adcpercm",&fFrXADCperCM, kDouble},
     {"fry_adcpercm",&fFrYADCperCM, kDouble},
     {"pbeam",&fgpbeam, kDouble},
+    {"frx_dist", &fgfrx_dist, kDouble},
+    {"fry_dist", &fgfry_dist, kDouble},
+    {"beam_x", &fgbeam_xoff, kDouble,0,1},
+    {"beam_xp", &fgbeam_xpoff, kDouble,0,1},
+    {"beam_y", &fgbeam_yoff, kDouble,0,1},
+    {"beam_yp", &fgbeam_ypoff, kDouble,0,1},
+    {"usefr", &fgusefr, kInt,0,1},
     {0}
   };
 
+  // Default offsets to zero
+  fgbeam_xoff = 0.0;
+  fgbeam_xpoff = 0.0;
+  fgbeam_yoff = 0.0;
+  fgbeam_ypoff = 0.0;
+  fgusefr = 0;
   // get the calibration factors from gbeam.param file
-   gHcParms->LoadParmValues((DBRequest*)&list,prefix);
+  gHcParms->LoadParmValues((DBRequest*)&list,prefix);
 
   return kOK;
 
@@ -298,8 +312,21 @@ Int_t THcRaster::Process( ){
 
   // std::cout<<" X = "<<fXpos<<" Y = "<<fYpos<<std::endl;
   
-  fDirection.SetXYZ(0.0,0.0,1.0); // Set arbitrarily to avoid run time warnings
 
+  Double_t tt;
+  Double_t tp;
+  if(fgusefr != 0) {
+    fPosition[1].SetXYZ(fXpos+fgbeam_xoff, fYpos+fgbeam_yoff, 0.0);
+    tt = fXpos/fgfrx_dist+fgbeam_xpoff;
+    tp = fYpos/fgfry_dist+fgbeam_ypoff;
+  } else {			// Just use fixed beam position and angle
+    fPosition[0].SetXYZ(fgbeam_xoff, fgbeam_yoff, 0.0);
+    tt = fgbeam_xpoff;
+    tp = fgbeam_ypoff;
+  }
+  fDirection.SetXYZ(tt, tp ,1.0); // Set arbitrarily to avoid run time warnings
+  fDirection *= 1.0/TMath::Sqrt(1.0+tt*tt+tp*tp);
+    
   return 0;
 }
 
diff --git a/src/THcRaster.h b/src/THcRaster.h
index 29d3f08..e71ec6f 100644
--- a/src/THcRaster.h
+++ b/src/THcRaster.h
@@ -28,8 +28,8 @@ class THcRaster : public THaBeamDet, public THcHitList {
   Int_t      Process();
 
   //  TVector3 GetPosition()  const { return fPosition[2]; }
-  TVector3 GetPosition()  const { return fPosition[0]; }
-  TVector3 GetDirection() const { return fDirection; } // Hall C we don't use raster direction yet.
+  TVector3 GetPosition()  const { return fPosition[1]; }
+  TVector3 GetDirection() const { return fDirection; }
 
   Double_t GetCurrentX() { return fRawPos[0]; }
   Double_t GetCurrentY() { return fRawPos[1]; }
@@ -41,6 +41,13 @@ class THcRaster : public THaBeamDet, public THcHitList {
   Int_t DefineVariables( EMode mode );
 
   Double_t       fgpbeam;   //beam momentum
+  Double_t       fgfrx_dist;     //Distance of raster to target
+  Double_t       fgfry_dist;
+  Double_t       fgbeam_xoff; // Beam offsets
+  Double_t       fgbeam_xpoff; // Beam offsets
+  Double_t       fgbeam_yoff; // Beam offsets
+  Double_t       fgbeam_ypoff; // Beam offsets
+  Int_t          fgusefr;   /* Use Raster for beam position */
 
   Double_t       fRawXADC;  // X raw ADC
   Double_t       fRawYADC;  // Y raw ADC
-- 
GitLab