\documentclass[]{article}
\usepackage{graphicx}
%opening
\title{Beam in HCANA}
\begin{document}
\maketitle
\tableofcontents
\section{Introduction}
For most purposes in Hall C data analysis, the beam apparatus that is used is
THcRasteredBeam and the beam detector is THcRaster. A sample in the replay script
is :
\begin{verbatim}
THaApparatus* beam = new THcRasteredBeam("H.rb", "Rastered Beamline")
\end{verbatim}
This is for when the HallCSpectrometer is defined as "H" ( for SHMS it is custom
to be defined as "P") . The beam object is given the name "H.rb" and
can be used later in physics modules:
\begin{verbatim}
THcReactionPoint* hrp = new THcReactionPoint("H.react", "", "H", "H.rb");
THcExtTarCor* hext = new THcExtTarCor("H.extcor", "", "H", "H.react");
THcPrimaryKine* hkin = new THcPrimaryKine("H.kin", "", "H", "H.rb");
\end{verbatim}
Methods for getting the information on the beam positions and direction that are calculated in {\it THcRaster.cxx} .
\section{Raster and EPICS BPMs}
The Hall C raster consists of two sets of X and Y coils which are labeled in the code as "A" and "B". For each event, the raster voltage for all four coils is sampled in a FADC250. This voltage is proportional to the magnetic
field in the raster coils which is directly related to the deflection of the
beam at the target. The two X (Y) coils are in sync and give enough deflection
so, for 11 GeV beam, the maxiumum deflection at the maximum voltage in the supplies is about 5x5mm ( 5mm is the full width, 2.5mm is the half-width). The
raster voltage only gives the relative deflection compared to the average beam position.
In Hall C, there is presently no measure of the beam position on an
event-by-event basis. The EPICS data is used to give the average beam position with the assumption that the average beam position has a small variation over the course of a run.
The EPICS data is in units of mm and the coordinate system has +X pointing beam right
and +Y pointing up.
The {\it THcRaster.cxx} reads in the raster current data. The {\it Init}
method sets {\it THcTHcRasterRawHit} based on the detector map:
\begin{verbatim}
! HRASTER_ID=18 :: ADC
DETECTOR=18
ROC=1
SLOT=18
12, 1, 1, 0 ! FR-YA
13, 1, 2, 0 ! FR-XA
14, 1, 3, 0 ! FR-YB
15, 1, 4, 0 ! FR-XA
\end{verbatim}
with a similar setup for the SHMS detector map.
The {\it Decode} method reads in the raw ADC values for each event.
The internal variable names
and the names in the output tree are given in Table~\ref{tab:rawname}.
\begin{table} [h]
\begin{center}
\begin{tabular}[]{|c|c|c|} \hline\hline
Variable Name & Tree name & Comment \\ \hline
frxaRawAdc & FRXA\_rawadc & \\ \hline
frxbRawAdc & FRXB\_rawadc & \\ \hline
fryaRawAdc & FRYA\_rawadc & \\ \hline
frybRawAdc & FRYB\_rawadc & \\ \hline
\end{tabular}
\caption{Raster Raw ADC variables}
\label{tab:rawname}
\end{center}
\end{table}
If the EPICS handler is initialized in the replay script, then the "RAW" EPICS X-Y position data for the three BPMS along the girder before the target is read to the variables: BPMXA\_raw, BPMXB\_raw, BPMXC\_raw, BPMXA\_raw, BPMXB\_raw and BPMXC\_raw.
The raw variables are not available in the output tree. One could get them from the EPICS tree if the definition file is setup properly.
The {\it Process} method converts the raw raster ADC and EPICS BPM data into calibrated positions.
The variable raster ADC (listed in Table~\ref{tab:adcname}) is calculated by subtracting an offset from the raw raster ADC. The offsets are parameters : gfrxa\_adc\_zero\_offset, gfrxb\_adc\_zero\_offset, gfrya\_adc\_zero\_offset, gfryb\_adc\_zero\_offset.
\begin{table} [h]
\begin{center}
\begin{tabular}[]{|c|c|c|} \hline\hline
Variable Name & Tree name & Comment \\ \hline
frxaRawAdc & FRXA\_rawadc & \\ \hline
frxbRawAdc & FRXB\_rawadc & \\ \hline
fryaRawAdc & FRYA\_rawadc & \\ \hline
frybRawAdc & FRYB\_rawadc & \\ \hline
\end{tabular}
\caption{Raster ADC variables}
\label{tab:adcname}
\end{center}
\end{table}
The relative raster position is calculated as:
\begin{equation}
\mbox{fXA\_pos} = \frac{\mbox{fXA\_ADC}}{\mbox{fFrXA\_ADCperCM}}*\frac{\mbox{fFrCalMom}}{\mbox{fgpbeam}}
\end{equation}
The parameters are explained in Table~\ref{tab:adcparam}.
\begin{table} [h]
\begin{center}
\begin{tabular}[]{|c|c|c|} \hline\hline
Variable Name & Parameter name & Comment \\ \hline
fFrXA\_ADCperCM & gfrxa\_adcpercm & Scale factor Counts per cm\\ \hline
fFrXB\_ADCperCM & gfrxb\_adcpercm & Scale factor Counts per cm\\ \hline
fFrYA\_ADCperCM & gfrya\_adcpercm & Scale factor Counts per cm\\ \hline
fFrYB\_ADCperCM & gfryb\_adcpercm & Scale factor Counts per cm\\ \hline
fFrCalMom & gfr\_cal\_mom & Beam energy that calibration was done\\ \hline
fgpbeam & gpbeam & Beam energy in kinematics file \\ \hline
\end{tabular}
\caption{Raster Parameters}
\label{tab:adcparam}
\end{center}
\end{table}
The desire was to have the raster position is the EPICS coordinate system (+X beam right
and +Y up). To achieve this the positions for the Y variables had to be multiplied by -1.
Calibration of the raster positions is done by looking at the raster raw ADC histograms.
The lower and upper edges of the raster raw ADC can be found for each raster coil.
The offset is the average of the edges and the scale factor is the difference of the
edges divided by the expected full width of the raster. The size can be checked by comparison
to the carbon hole size which has a diameter of 2mm.
The BPMs positions at the target can be set as parameters which are the average over the entire run or determined from the EPICS data
throughout the run. The parameters are shown in Table~\ref{tab:bpmparam}. It is optional that the parameters are read in. If the code reads in the any of parameters, then the BPM target positions and angles will be all set to the parameter ( if it happens that only some of the parameters are read in then the others are set to zero.). If you are
using the parameter option to set the target BPM position, then it is best to do it in the
{\it standard.kinematics} file since it can change run-to-run. A script has to be
written to calculate the average target positions from the EPICS data.
\begin{table} [h]
\begin{center}
\begin{tabular}[]{|c|c|c|} \hline\hline
Parameter name & Variable Name & Comment \\ \hline
gbeam\_x & fgbeam\_x & Average target X position from EPICS BPMs (+X beam right)\\ \hline
gbeam\_y& fgbeam\_y & Average target Y position from EPICS BPMs (+Y beam up)\\ \hline
gbeam\_xp& fgbeam\_xp & Average target X angle from EPICS BPMs \\ \hline
gbeam\_yp& fgbeam\_yp & Average target Y angle from EPICS BPMs\\ \hline
\end{tabular}
\caption{BPM Parameters}
\label{tab:bpmparam}
\end{center}
\end{table}
The BPMs are calibrated relative to the HARPs. A script has been developed to fit a group
of HARP scans to determine the calibration constants. The script and instructions are
in the CALIBRATION/bpm\_calib subdirectory of hallc\_replay git repository. The HARP coordinate system has +X pointing beam left and +Y up. The BPM position in the HARP
coordinate system is given by
\begin{equation}
\mbox{BPMXA\_pos} = 0.1*(\mbox{fgbpmxa\_slope}*\mbox{BPMXA\_raw} + \mbox{fgbpmxa\_off})
\end{equation}
The 0.1 is to convert the calibration to units of cm. One note is that the slopes for all
the BPMX should be negative to convert the EPICS raw value to the HARP coordinate system. The BPM calibration parameters are given in Table~\ref{tab:bpmcalparam}.
\begin{table} [h]
\begin{center}
\begin{tabular}[]{|c|c|c|} \hline\hline
Parameter name & Variable Name & Comment \\ \hline
gbpmxa\_slope & fgbpmxa\_slope & Slope of HARP fit to BPMXA data\\ \hline
gbpmxb\_slope & fgbpmxb\_slope & Slope of HARP fit to BPMXB data\\ \hline
gbpmya\_slope & fgbpmya\_slope & Slope of HARP fit to BPMYA data\\ \hline
gbpmyb\_slope & fgbpmyb\_slope & Slope of HARP fit to BPMYB data\\ \hline
gbpmxa\_off & fgbpmxa\_off & Intercept of HARP fit to BPMXA data\\ \hline
gbpmxb\_off & fgbpmxb\_off & Intercept of HARP fit to BPMXB data\\ \hline
gbpmya\_off & fgbpmya\_off & Intercept of HARP fit to BPMYA data\\ \hline
gbpmyb\_off & fgbpmyb\_off & Intercept of HARP fit to BPMYB data\\ \hline
\end{tabular}
\caption{BPM Calibration Parameters}
\label{tab:bpmcalparam}
\end{center}
\end{table}
The X and Y BPM position and angles at the target (in the HARP coordinate system) are calculated using the BPMA\_pos and BPMC\_pos positions.
In the code ,these are called xbeam and ybeam and fXbpm\_tar = -xbeam and fYbpm\_tar=ybeam to put it in the EPICs coordinate system. If the parameters gbeam\_x and gbeam\_y are read-in then fXbpm\_tar = gbeam\_x and fYbpm\_tar = gbeam\_y.
The tree names of the BPM positions in the EPICS coordinate system are listed in Table~\ref{tab:bpmtree}.
\begin{table} [h]
\begin{center}
\begin{tabular}[]{|c|c|c|} \hline\hline
Variable name & Tree Name & Comment \\ \hline
fXbpm\_A & fr\_xbpmA & \\ \hline
fYbpm\_A & fr\_ybpmA & \\ \hline
fXbpm\_B & fr\_xbpmB & \\ \hline
fYbpm\_B & fr\_ybpmB & \\ \hline
fXbpm\_C & fr\_xbpmC & \\ \hline
fYbpm\_C & fr\_ybpmC & \\ \hline
fXbpm\_tar & fr\_xbpm\_tar & \\ \hline
fYbpm\_tar & fr\_ybpm\_tar & \\ \hline
\end{tabular}
\caption{BPM positions variables and tree names}
\label{tab:bpmtree}
\end{center}
\end{table}
\section{Target positions}
The predicted Y target position ($Y_{pred}$) measured by the spectrometer depends on the target position along the beam line ($Z_H$),
the horizontal beam position ($X_{H}$), the horizontal mispointing of the spectrometer ($Y_{mis}$), the central angle of the
spectrometer ($\theta_c$) and the scattering angle of the particle relative to the spectrometer coordinate system ($Y'$).
\begin{equation}
Y_{pred} = X_H*(\cos\theta_c-Y'*\sin\theta_c)-Z_H*(\sin\theta_c+Y'*\cos\theta_c)-Y_{mis}
\end{equation}
For scattering into the HMS then $\theta_c$ should have a negative sign. The $X_{H}$ is equal to the negative of P.rb.raster.fr\_xbpm\_tar.
$Y_{mis}$ is taken from spectrometer survey. For the SHMS, $Y_{mis} = -0.06$~cm. For the HMS,
\begin{equation}
Y_{mis} = 0.052 - 0.0012*abs(\theta_c) + 0.0002*\theta_c^2
\end{equation}
where $\theta_c$ is in degrees and $Y_{mis}$ in cm. $+Z_H$ is defined to be pointing beam downstream.
\end{document}