% Hall C Howto Template
% Rename this file to "something.tex" where something is a unique
% filename.
% To process this document, you also need the files:
%    chowto.cls
%    chowto.bib
%    chowto.bst
%
% If you refer to publications not in chowto.bib, then create a file with the
% same name as this with the ``.tex'' changed to ``.bib'' and put the
% references into that file in BibTeX format.
%
% Instructions for downloading and using this template can be found at
%
%           http://www.jlab.org/~saw/howto/
% 
\documentclass{chowto}

\title{Time of Flight Scintillator Hodoscope Calibration}
\howtotype{user} % ``expert'', ``user'', ``reference''
%\experiment{Name of experiment} % Optional
\author{Peter Bosted}
\category{hms} % Subject area of this document
        % Allowed choices are
        %
        % hms             HMS detectors and other HMS stuff (eg rotation)
        % sos             SOS detectors and other SOS stuff i(eg doors)
        % magnet          SOS/HMS or other magnet systems
        % beamline        Beamline instrumentation
        % daq             Data Acuisition and Analysis
        % electronics     
        % target   
        % general         All other subjects

%\maintainer{Name of person maintaining document} % Optional
\date{\today} % Can use \today as the argument

\begin{document}

\begin{abstract}
This document describes how to optimize the scintillator hodoscope
parameters to obtain the most accurate possible timing information.
This in turn leads to the best determination of the time-of-flight
between S1 and S2, which can be used to distinguish between
particles of different mass (electrons, pions, kaons, and protons).
\end{abstract}

\section{Introduction}
The scintillators in the HMS and SOS spectrometers come in two
sets: S1 and S2. In each set, there are horizontal and vertical
bars, labeled X and Y. Each bar has a photo-multiplier tybe (PMT)
 at each end. The PMT
outputs go through a splitter: one output goes to an Analog to Digital
Converter (ADC) and one
to a discriminator, then to a multi-hit Time to Digital 
Converter (TDC). To determine the
time at which a particle passed through a scintillator, relative
to the time in one of the paddles (used as the reference paddle),
one needs to correct the TDC values (which measure time relative
to the trigger time) for three effects:
\begin{itemize}
\item
The average time delay between when light hits the photo-cathode
of the PMT, and when a pulse emerges from the anode (there are
variations from PMT to PMT, and the offset also depends on the
HV). Thus new calibrations are needed every time the HV is changed.
Also, the length of cable for each PMT is slightly different going
from the PMT eventually to the TDC: this is also taken into
account by an overall time offset for each PMT.
\item
The time it takes for light produced in the paddle to get to the
PMT. To first order, this is proportional to the distance from
where the particle hit the paddle to the PMT, which requires
information from the tracking code. If the photons went straight
to the PMT, then the time just depends on the speed of light
in plastic. In practice, the light bounces around, so takes about
40% longer to reach the PMT that one might expect. This can
depend on the PMT geometry (i.e. how thick it is), and how much
is has aged. So we can fit an effective velocity of light for
each paddle. 
\item
The TDC value depends on the time at which the pulse crosses the
discriminator threshold, hence it depends on the pulse height.
Since pulses are attenuated in the plastic, there is a correlation
of pulse height with distance from the PMT, so it is hard to
distinguish this correction from the effective velocity one. 
Several forms have been tried (no ADC correction, correction
proportional to $\sqrt{ADC}$, to $1./\sqrt{ADC}$, and to
ignoring the ADC but using a path length squared correction.
The fitting code can easily be changed to accommodate all of
these cases, but the current version uses $1./\sqrt{ADC}$
\end{itemize}

The goal of the TOF calibration is to find the above three
correction factors for each PMT, such that the corrected
times are all in as perfect agreement with each other as possible.
The average time difference between S1 and S2 can then be
used to find the velocity of the particle in question, and
distinguish between electrons, pions, kaons, and protons (and
even deuterons and tritons).

\section{Step by step Instructions}
Pick a run to analyze that has mostly one particle type making
triggers, and singles rates that aren't too high ($<$100 kHz). Then
\begin{itemize}
\item Type ``newgrp c-inclusive'' (or whichever group you 
analyzing data in) if this is not your default group, so that
other in the group can collaborate with you.
\item
Include the text  'hdumptof=1'' on the command line that you
use to replay the run (next to ``grun=12345'', etc.). 
(for SOS, uses ``sdumptof=1''.
These variables can be more permantly changed in the
file  `hdebug.param'' in PARAM directory. 
(or something like PARAM/online07 directory) 
\item
Run the analyzer for the run you have chosen.
\item
Copy the output file fort.37 (fort.38 for SOS) to a file you will
cal ``tofcal.inp'' in the directory where you will do the calibration.
\item
Copy the source code:
/group/hallc/packages/tof\_calibration/tofcal.f to your directory.
Also copy the ``Make file''
/group/hallc/packages/tof\_calibration/Maketof to your directory.
Log on to a Linux machine and ``Make'' (compile and link) the
code by typing ``Maketof tofcal''
\item
Run the code by typing ``tofcal''
\item
The new tof parameters will be found in the file ``tofcal.param''. 
See if the results make sense. The offsets, velocities, ADC corrections,
and sigmas will be set to 0, 50., 0., and 100. respectively for
PMTs where their weren't enough hits (100 minimum) within the
starting time window. Note that each parameter is listed in four
columns and 16 rows. The columns correspond to S1X, S1Y, S2X, and S2y,
and the rows correspond to the paddle numbers. Since some arrays
don't have 16 paddles, one expects the last 1, 7, 0, and 7 rows
of columns 1, 2, 3, 4 to not have hits. (For SOS, this would be
last 8, 8, 1, and 7 rows). Also, quite often there are not enough
hits in the first row. If any other paddles don't have enough hits,
trying running more events. Also, check that the online histograms
show normal-looking ADC and TDC spectra for that PMT.  This can
also be checked in the text-formatted histograms that are dumped
out, called ``tofcal.adchist'' and ``tofcal.tdchist'' (see tofcal.f
for format). 
\item
Check that values for parameters seem reasonable.
 Normal values of invadc\_offset are between -50 and 50,
 normal values of invadc\_velocity are between 12 and 17 (again, 50 is
 default if not enough data for the fit), and normal values of
 hhodo\_pos\_invadc\_adc are 20 to 50. If not reasonable, investigate.
\item
If all is working well, the values of ``sigma'' should be below 0.5
(units are nsec). These are the widths of the differences of
the time for each paddle with the averaged time for all paddles. 
With the new PMTs in the HMS, we should strive for 0.25 nsec. 
\item
Once happy with the new values, insert the contents of
``tofcal.param'' into the end of the file ``hhodo.param\_xxxxx'' in the
``PARAM'' directory, where xxxxx is the run number you used
for the calibration. You can then point to this file in the
master setup file ??? to use the new calibrations.
\item 
Re-analyze the run with the new parameters and make sure the
spectra of ``beta'' and ``mass'' are now narrower than before. 

\end{itemize}



\end{document}
