Spin patterns and polarization direction

The STAR spin database is using the CDEV information from the polarized proton source.

You can check the spin pattern at a specific time with:
StRoot/StSpinPool/StSpinDbMaker/api/spinDbAPI -p beamV0/V124 -t "2015-06-16 18:00:00"

The information is given per RF bucket (0-360). Only every third bucket is filled, i.e. 120 bunches per beam.
The listed format is usually called the "8-spin bits."
The first four bits are for the blue beam, the last four bits are for the yellow beam.
They translate as follows:
0000: empty
0001: filled
0011: polarization up
0101: polarization down
1001: not polarized

(Note: 0001 is never used, although it is somewhat redundant with 1001.)

Bunch crossings have to be calculated from the single bunch patterns with the crossing shift (the first line in the output list, usually 240 buckets). This is the shift between the yellow bucket number and the blue bucket number. (The abort gaps are aligned at 2 and 8 o'clock.)

In the analysis code, the StSpinDbMaker translates the 8-spin bits into a 4-spin bit for the bunch crossing. Here, the first two bits are for the blue bunch, the last two bits are for the yellow bunch.
These translate as:
0101 =  5: B+ Y+
0110 =  6: B+ Y-
1001 =  9: B- Y+
1010 = 10: B- Y-
(Note: Bunches can also be unpolarized, i.e. other possible values for the 4-spin bits are 1, 2, 4, and 8.)

This information is still the "spin direction" from the source. During acceleration through the AGS and RHIC the polarization vector changes direction repeatedly and the final beam polarization (at 200 and 510 GeV) at STAR is opposite to the polarization direction from the source. Analyzers should either use a negative value for the beam polarization OR reverse the interpretation of the 4-spin bits in their code, as was done in the W AL analysis (STAR note PSN 0702):
enum { ka=10,  /* STAR pol B+ Y +  */
       kb=9,   /* STAR pol B+ Y -  */
       kc=6,   /* STAR pol B- Y +  */
       kd=5,   /* STAR pol B- Y -  */ };


How to use StSpinDbMaker


In the macro, run_StYourAnalysisMaker.C, add an instance of StSpinDbMaker:
St_db_Maker *dbMk = new St_db_Maker("db","MySQL:StarDb","$STAR/StarDb");
StSpinDbMaker* spindb = new StSpinDbMaker("spinDb");
In the header, StYourAnalysisMaker.h:
class StSpinDbMaker;
protected:
StSpinDbMaker *mStSpinDbMaker;
In the analysis source code, StYourAnalysisMaker.cxx:
#include "StSpinPool/StSpinDbMaker/StSpinDbMaker.h"
Int_t StYourAnlaysisMaker::Init() {
  mH1_PolBlue   = new TH1F("pol_Blue",   "blue beam polarization",   120, -0.5, 119.5);
  mH1_PolYellow = new TH1F("pol_Yellow", "yellow beam polarization", 120, -0.5, 119.5);

Int_t StYourAnalysisMaker::InitRun(int runNo) {
  // Reading the polarization pattern
  mStSpinDbMaker = static_cast<StSpinDbMaker*>(GetMaker("spinDb"));
  mStSpinDbMaker->print();

  for( int i=0; i<120; i++ ) {
    int bunch = mStSpinDbMaker->BXstarUsingBX48(i);
    int spin4 = mStSpinDbMaker->spin4usingBX48(i);

    int bpol = 0;
    int ypol = 0;
    if( spin4 & 0x1 ) ypol = +1;
    if( spin4 & 0x2 ) ypol = -1;
    if( spin4 & 0x4 ) bpol = +1;
    if( spin4 & 0x8 ) bpol = -1;

    mH1_PolBlue->SetBinContent( bunch+1, bpol);
    mH1_PolYellow->SetBinContent( bunch+1, ypol);
  }
}