Tac Offset Files for EPD

The EPD tac offsets need to be determined after the timing is set, and the bias voltages are set. 

Order of operations:
QT LUT (TAC Offset/ADC Pedestal Subtraction)
Slew Corrections
QT Channel Masks

First Step:
You need to be able to log into the startrg machine as staruser.   (You also need to be able to log in as trg as well.)  If you do not have permission, follow the instructions at:
www.star.bnl.gov/starkeyw

Logging In:
ssh -A -Y you@ssh.sdcc.bnl.gov
ssh -t -A -Y stargw.starp.bnl.gov
ssh staruser@startrg.starp.bnl.gov

The location that the star system looks for the tac offset (and slew correction files) is: /home/startrg/trg/cal/qt
Use ls -l to see the softlinks.  For the epd there are 3 tac offset files for the 3 crates, and 3 slew correction files for the 3 crates (eq1_slew_corr.txt, eq1_tac.dat, etc)

Checking the System
Before doing any tac offset analysis, make sure that both the slew correction and tac offset files are pointing to their zero files.  This is always done via softlink.  You must always be logged in as trg to make these changes (from stargw):
 ssh trg@startrg.starp.bnl.gov

(It is best to work as staruser unless you are planning to change the system)

You will be making soft links, which are created like this:
ln -s file1 link1

For example, this would create a soft link named link1 to a file named file1, both in the current directory

ln -s /home/startrg/staruser/eq1_tac_zeroed.dat /home/startrg/trg/cal/qt/eq1_tac.dat
And so on for all files.

In order for any changes to be picked up, the shift crew has to take a pedestal rhic clock clean.  Do not do this with beam in the machine.

Recording the data

 To take the files for the EPD tac offset, the EPD can not be used in the trigger decision.  So the run needs to be a dedicated run with just the bbc, vpd, zdc acting as trigger detectors.  Ideally the file would have 100k events in it, but probably 50k would be sufficient.

After the data is taken it takes some time to analyze so if there are already tac offset files (i.e. you are trying to improve upon things) you should return the EPD back to the old files before going further.

The histograms needed come from the *.dat files in the usual way: drupal.star.bnl.gov/STAR/blog/rjreed/procedure-make-histograms-various-scans
 
TAC Analysis
Using the mapped histogram file from above, you should run the following code: drupal.star.bnl.gov/STAR/system/files/MakeTacOffset2023.C.txt

The old code (jic) is: drupal.star.bnl.gov/STAR/system/files/MakeTacOffset.txt

This code will produce 6 files.  The 3 text files which will be the new tac offsets.  A *.png which shows the means of the tac offsets, a root file of the same histogram and a pdf that shows the ADC vs TAC for all the channels.  Note: The location of the boards in this macro are hard coded in.  If they were ever to be changed in the crate, this would need to change.  Also, the LUT is created by numbering the boards in a given crate regardless of their address.  So the addresses listed in the text files are to help the reader, but aren't copied in in any way.

A couple of details about how the code operates.  The issue is that low signals will come in with low TAC values (i.e. slow TAC values).  This is even apparent as you even look at ADC ~1 mip.  You would have to go to fairly high values of ADC before it levels off.  There are also beam satellites which can have a very high TAC (i.e. fast).  Unfortunately the statistics there are minimal and so we would need to take far more data than possible to get this precision.  We also can only subtract a value for the tac offset, so one needs to find the channel with the lowest mean TAC (i.e. the fastest channel) and use that as the baseline.  This can be done by running the code once with taccorval set to a high value and seeing what the mean is of the fast channel as it will record all channels with a mean less than the taccorval.  Then change the taccorval to that mean - this will set all the other channels means to this value.

The mean is calculated by projecting the ADC vs TAC distribution along the TAC axis, and then finding the mean from TAC values between 300 and 2800.  This remove most of the outliers due to out-of-time/dark current, very low signals and those that start to come in from the beam satellite.  These numbers are at the top of the macro and can be changed if needed.  Once this is completed, the text files are ready for upload.

Run 20 tac offset files are: drupal.star.bnl.gov/STAR/system/files/tacoffsets1.txt drupal.star.bnl.gov/STAR/system/files/tacoffsets2.txt drupal.star.bnl.gov/STAR/system/files/tacoffsets3.txt
 
Uploading the Files
It is slightly complicated to get files onto the system from your laptop.  First copy the files to rcf:
scp thefiles you@rftpexp.rhic.bnl.gov:

Then you can log into the trigger system as star user:
ssh -A -Y you@ssh.sdcc.bnl.gov
ssh -t -A -Y stargw.starp.bnl.gov
ssh staruser@startrg.starp.bnl.gov

You should be in the folder /home/startrg/staruser/
Next copy the files to this directory, making sure that you don't erase any existing files:
scp you@rftpexp.rhic.bnl.gov:thefiles .

Then you need to log in as trg so:
exit
ssh trg@startrg.starp.bnl.gov
ln -s /home/startrg/staruser/thefirstfile.dat /home/startrg/trg/cal/qt/eq1_tac.dat

Now the files are uploaded and will be applied the next time the shift crew runs a pedestal for the EPD.