HFT simulation--Hijing + HF simulation

 Instructions from Yifei Zhang:
https://drupal.star.bnl.gov/STAR/blog/yfzhang/instruction-hft-simulation

1. inserted Ds+/Ds- 

code position: RCF
           /star/u/xlchen/work/lbl/hft/Run14/Ds_Simu/HijinSimu

first : read README

1.1 makeFZ/------------in 1 e) of Yifei's

 scripts to produce fz files for hijing simulations with embedded HF decays.

  - starsim.hijing.D0.C:
    -Line 63:  Set embedded particle, find names to use in:" emacs $STAR/pams/sim/gstar/gstar_part.g " currently set to D0
    -Line 181: Change HF particle pT distribution
    -Line 185: Change HF particle y distribution

If need add in new defined particles, one need check out local pams/sim/gstar/gstar_part.g to local and modify this file accordingly
And also the decay channel

>run.sh [index]
or
>submit.sh [index_begin] [index_end]

Reference class: StarPrimaryMaker. 
http://www.star.bnl.gov/webdata/dox/html/classStarPrimaryMaker.html#a065785692580b6725e1a6190a40c389e
example: primary->SetSigma(0.01,0.01,2.0,0);

void StarPrimaryMaker::SetSigma ( Double_t  sx,
    Double_t  sy,
    Double_t  sz,
    Double_t  rho = 0  
  )     [inline]

Set the smearing in the x, y and z vertex positions.

Parameters:
  sx  is the smearing in x
  sy  is the smearing in y
  sz  is the smearing in z
  rho  is the correlation between x and y

particle list:vim $ROOTSYS/etc/pdg_table.txt
class:  StarParticleData provides an interface to the data provided in the TDatabasePDG class from ROOT. We extend the available list of particles,                                      
including some standard heavy ions which are lacking in the ROOT table, and provide the capability to alias names to individual particles.

1.2 Reco/
- Reco: Contains two directories:
     -StRoot_sti15: Standard simulation library. Only contains StPxlSimMaker required to load Pile Up

     -StRoot_detEFF_SC: Sti15 tracking library plus corrections accounting for detector (PXL+IST)
      detector efficiency plus TPC space charge effect.

If you want to use StRoot_detEFF_SC, you need copy this folder to StRoot.
Then you can compile the code with command 'cons'. (Note: cons can only compile the file named StRoot)

See the BigFullChain: 
vim $STAR/StRoot/StBFChain/BigFullChain.h 
fzin: read gstar fz-file
in: In put tree --root file
Know how many events in the input file (.fzd, .root), define the same 
events loop number --in runPUReco.csh -- chain->EventLoop($start,$end);

Test  the code and submit jobs by 

Test:   
>./runPUReco.csh [FZfile_index] [pileup_index]
submit:
>./submitPUReco.csh [FZfile_index_begin] [FZfile_index_end]

The FZfile_index should be consistent with the file produced in 1.1
pileup_index can select one in /star/u/xlchen/work/lbl/hft/Run14/Ds_Simu/HijinSimu/pileup

Clear the useless file

>./clear.sh

When you want to use the new Star Library, you just need starver new star library, then compile by cons.
for example, this time I use:

>starver SL15e
>cons

But, maybe some errors occure, because some functions may be different at different versions.

Pay attention to load correct parameters and hit errors by checking log files.
e.g. 

1)The suggested setting
 ---------------------------------------------------------------------------------------
 bfc/.make/db/.const/StarDb/Calibrations/tracker/.DefaultTrackingParameters/DefaultTrackingParameters  Allocated rows: 1         Used rows: 1    Row size: 32 bytes
 Table: TrackingParameters_st        [0] :
 ======================================================================================
double  minSearch            0.1 : Minimum Search Window
double  maxSearch              3 : Maximum Search Window
double  scaling                    5 : Search Window Scaling
double  maxChi2               20 : Max Chi2
---------------------------------------------------------------------------------------

2)To check if the pileup hits are loaded, one need find in log file:

StPxlSimMaker:INFO  - StPxlPileupAdder: adding 13504 pileup hits.
Number of hits before adding...159
 
Number of hits after adding...13663
This reasonably indicates that pileup hits are correctly added.

3)To check if the detector geometry and are included and activated, one can check:

  1 - makepulls = 1
  2 - activesst = 1
  3 - usesst = 1
  4 - activeist = 1
  5 - useist = 1
  6 - activepixel = 1
  7 - usepixel = 1
  8 - usesvt = 0
  9 - alignment = 0
 10 - usevertexfinder = 1
 11 - usetracker = 1
 12 - useeventfiller = 1
 13 - usessd = 1
 14 - usesvt = 1
 15 - activetpc = 1
 
 16 - usetpc = 1
This means IST, PXL, SSD are correctly included.

4) hit errors 

---------------------------------------------------------------------------------------
 bfc/.make/db/.const/StarDb/Calibrations/tracker/.PixelHitError/PixelHitError  Allocated rows: 1         Used rows: 1    Row size: 48 bytes
 Table: HitError_st          [0] :
 ======================================================================================
double  coeff[0]        1.44e-06 : *
             [1]               0 :
             [2]               0 :
             [3]        1.44e-06 :
             [4]               0 :
             [5]               0 :
 
---------------------------------------------------------------------------------------
This is a correct example that PXL hits errors are 12 micron in x and 12 micron in z.  e.g. sqrt(1.44e-06).


---------------------------------------------------------------------------------------
 bfc/.make/db/.const/StarDb/Calibrations/tracker/.ist1HitError/ist1HitError  Allocated rows: 1   Used rows: 1    Row size: 48 bytes
 Table: HitError_st          [0] :
 ======================================================================================
double  coeff[0]        0.00029241 : *
             [1]               0 :
             [2]               0 :
             [3]        0.032797 :
             [4]               0 :
             [5]               0 :
 
---------------------------------------------------------------------------------------
 IST hits errors are 170 micron in x and 1700 micron in z. 

others

---------------------------------------------------------------------------------------
 bfc/.make/db/.const/StarDb/Calibrations/tracker/.tpcInnerHitError/tpcInnerHitError  Allocated rows: 1   Used rows: 1    Row size: 48 bytes
 Table: HitError_st          [0] :
 ======================================================================================
double  coeff[0]          0.0004 : *
             [1]        0.0017853 :
             [2]        0.037184 :
             [3]          0.0004 :
             [4]        0.0054884 :
             [5]        0.021818 :
 
---------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------
 bfc/.make/db/.const/StarDb/Calibrations/tracker/.tpcOuterHitError/tpcOuterHitError  Allocated rows: 1   Used rows: 1    Row size: 48 bytes
 Table: HitError_st          [0] :
 ======================================================================================
double  coeff[0]        0.00087904 : *
             [1]        0.00083214 :
             [2]        0.059281 :
             [3]        0.0057825 :
             [4]        3.4195e-05 :
             [5]        0.047681 :
 
---------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------
 bfc/.make/db/.const/StarDb/Calibrations/tracker/.ssdHitError/ssdHitError  Allocated rows: 1     Used rows: 1    Row size: 48 bytes
 Table: HitError_st          [0] :
 ======================================================================================
double  coeff[0]         9e-06 : *
             [1]               0 :
             [2]               0 :
             [3]        0.0073469 :
             [4]               0 :
             [5]               0 :
 
---------------------------------------------------------------------------------------

1.3 ReadMuDst-----deal with the *.MuDst.root from Reco

- ReadMuDst:

  -lMuDst.C: Loads MuDSt's

  -RecoSimGlobal.C: Contains sample code to load RC and MC information from MuDst. Contains example on associating mc and rc tracks,

    and sample loops, etc.

1)Test

>./Test.sh [index]
[index] is the number from Reco

 2)Submit jobs:ReadMuDst/submit

>cd submit
>./getlist.sh
>./SubmitJobs.sh

3)merge the output root file by hadd.sh: Reco/submit

>./hadd.sh [$1] [$2] [$3] [$4] [$5]
the number of parameters can be 0-5

int myhadd(TString WorkPath,Int_t TESTMODE=1,TString SourceDir="out",TString DestinationDir="Hist",const Int_t Nfilesperjob=10,TString options="")
                          pwd                            $1                       $2                                    $3                                             $4                                $5
$1: 1---test mode, default value, test if the macro can be runned right; 0------run mode
$2: source root files directory
$3: out put root file directory
$4: every $4 root files to merge one root file
$5: Options : please look at hadd options. see:  hadd --help
                                    
4)ReadMuDst/ana

>./RunMySelector.sh $1
$1: dir/name.root  or  name.root-->current direction
to produce *.mini.root in dir/
>./plots.sh $1 $2
$1: dir/name.mini.root
$2: decay mode
       0--D_{s}#rightarrow#phi(1020)#pi
            D_{s}#rightarrowk#bar{k^{*0}}(892)
       1--D_{s}#rightarrow#phi(1020)#pi
       2--D_{s}#rightarrowk#bar{k^{*0}}(892)

2. D0

Similar to Ds

3. Supplyment

3.1 Mc particle id, mass, life time, etc

To see the star simulation particle characters, by printing the list of particles available in STARSIM:

>starsim
starsim>make sim/gstar
starsim>gprint part

StMuMcTrack *mcTrack;
mcTrack->GePid();

3.2 Particle name used in starsim function (makefz) and decay channel, pid, etc

>vim $ROOTSYS/etc/pdg_table.txt

3.3 Add new particle(makefz/)
If need add in new defined particles, one need check out pams/sim/gstar/gstar_part.g to local and modify this file accordingly. 
Like _phi_to_KK, code=99, pdg=333, you can also define the particle K*bar0(code=892,pdg=-313), and reconstruction the
decay channel Ds+ --> K*bar0 k+ --> k- pi+ k+