---
# System prepended metadata

title: Alignment Monitoring and Evaluation

---

# Alignment Monitoring and Evaluation

## Data locations

### 2016 Physics
#### Data
##### 10% new data ntuples
`/fs/ddn/sdf/group/hps/data/physrun2016/BLPass4c/`
- corresponding lcio files
`/fs/ddn/sdf/group/hps/users/alspellm/projects/THESIS/data/2016/20230724_sample0/rerecon_files`
#### MC:
`/fs/ddn/sdf/group/hps/users/alspellm/projects/THESIS/analysis/data_mc_comparisons/update_20230112/smearing_20231129/final_hadd_ecalSmearingUpdate_tritrig_beam_ana.root`

### 2019 Physics
#### Data
##### run 10031
- recon: `/fs/ddn/sdf/group/hps/users/sgaiser/data/recon_jeo2024/2019/ttb/10031/HPS_ShimShoSurvey_M1M2tu_TZFix_iter26/`
- input: `/fs/ddn/sdf/group/hps/data/physrun2019/hps_010031/`
##### run 10105
- recon: `/fs/ddn/sdf/group/hps/users/sgaiser/data/recon_jeo2024/2019/ttb/10105/HPS_ShimShoSurvey_M1M2tu_TZFix_iter26/`
- input: `/fs/ddn/sdf/group/hps/data/physrun2019/hps_010676/`
##### run 10676
- recon: `/fs/ddn/sdf/group/hps/users/sgaiser/data/recon_jeo2024/2019/ttb/10676/HPS_ShimShoSurvey_M1M2tu_TZFix_iter26/`
- input: `/fs/ddn/sdf/group/hps/data/physrun2019/hps_010105/`

#### MC
- 2019 tritrig+beam MC sample, generated with `HPS_IDEAL_iter0`: `/fs/ddn/sdf/group/hps/mc/tritrig_beam/4pt55/HPS_IDEAL_iter0/`
    - run number: 1194550
    - stats too low for analysis
    - readout + reconstruction output: `/fs/ddn/sdf/group/hps/users/sgaiser/data/recon_jeo2024/2019/MC/ttb/4pt55/20um/HPS_IDEAL_iter0/`
- old 2019 tritrig+beam MC sample (generated 2021), generated with `HPS_PhysicsRun2019-v2-FEE-Pass0`:
`/sdf/group/hps/mc/4pt55GeV/tritrig/20um120nA/tritrig_beam/HPS_PhysicsRun2019-v2-FEE-Pass0/idealCond`
    - run number: 1194550
    - reconstructed using `HPS_PhysicsRun2019-v2-FEE-Pass0` (bug version):
`/fs/ddn/sdf/group/hps/users/sgaiser/data/recon_jeo2024/2019/MC/ttb/4pt55/20um/HPS_PhysicsRun2019-v2-FEE-Pass0/missingL7t/`

### 2019 FEE
#### Data
##### run 10104: 
- recon: `/fs/ddn/sdf/group/hps/users/sgaiser/data/recon_jeo2024/2019/fee/10104/HPS_ShimShoSurvey_M1M2tu_TZFix_iter26/rerecon/`
- input: `/fs/ddn/sdf/group/hps/data/physrun2019/hps_010104_slcio_pf/`
#### MC
- recon: `/fs/ddn/sdf/group/hps/users/sgaiser/data/recon_jeo2024/2019/MC/fee/4pt55/20um/HPS_IDEAL_iter0/missingL7t`
- 2019 beam MC sample, generated with `HPS_IDEAL_iter0`:
`/fs/ddn/sdf/group/hps/mc/beam/slic/4pt55/HPS_IDEAL_iter0/20um`
    - using run number: 1194550

### 2021 Physics
#### Data: 
`/fs/ddn/sdf/group/hps/users/bravo/run/run14168/output/hps_014770/HPS_Run2021Pass1_v4_ironMPgblslot`
- `HPS_Run2021Pass1_v4_ironMPgblslot` is equivalent to `HPS_Run2021Pass1_v5`
- new ntuples: `/fs/ddn/sdf/group/hps/users/sgaiser/data/recon_jeo2024/2021/ttb/HPS_Run2021Pass1_v5/root/`

#### MC:
`/fs/ddn/sdf/group/hps/users/pbutti/sw/hpstr/run_jeopardy/jeopardyNtuples_MC_2021_ttb/`
- newer, low stats sample generated with `HPS_Run2021Pass0_v0`:
`/fs/ddn/sdf/group/hps/mc/tritrig_beam/3pt74/HPS_Run2021Pass0_v0`
    - run number: 1194550
- old sample (generated 2022), generated with `HPS_Run2021Pass2FEE`:
`/fs/ddn/sdf/group/hps/mc/3pt7GeV/HPS_Run2021Pass2FEE/tritrig_beam_13_singles23/recon/`
    - run number: 14166

### 2021 FEE
#### Data:
- later detector with later run (matches ttb): `/fs/ddn/sdf/group/hps/users/bravo/run/ali21/output/feeSkim/HPS_Run2021Pass1_v4_ironMPgblslot/hps_14770_sarah.root`
- prefer to use this one because it has better mom distribution (is different detector from ttb sample, v4 vs v5): `/fs/ddn/sdf/group/hps/users/bravo/run/ali21/output/HPS_Run2021Pass1_v4/hps_14168_sarah.root`
- using later detector for earlier data set (mismatch, do not use for analysis): `/fs/ddn/sdf/group/hps/users/sgaiser/data/recon_jeo2024/2021/fee/3pt74/HPS_Run2021Pass1_v5/rerecon`

#### MC: 
`/fs/ddn/sdf/group/hps/users/sgaiser/data/recon_jeo2024/2021/MC/fee/3pt74/HPS_Run2021Pass0_v0/`
- 2021 beam MC sample, generated with HPS_Run2021Pass0_v0:
`/fs/ddn/sdf/group/hps/mc/beam/slic/3pt74/HPS_Run2021Pass0_v0`
    - run number: 1194550

## Workflow

### Running reconstruction on s3df
example for 2019 data
- go to `/sdf/group/hps/user-data/sgaiser/run/recon_jeo2024/2019/ttb`
- copy and adjust subArray as follows:
    ```bash
    #!/bin/bash
    #SBATCH --ntasks=1
    #SBATCH --time=08:00:00
    #SBATCH --mem=1500M
    #SBATCH --array=1-30
    #SBATCH --account=HPS:hps-prod

    source $HPSMC/install/bin/hps-mc-env.sh
    export LD_LIBRARY_PATH=/fs/ddn/sdf/group/hps/users/bravo/src/gsl-2.6/install/lib:$LD_LIBRARY_PATH

    export FIRST_ID=20
    export JOB_ID=$(($SLURM_ARRAY_TASK_ID+$FIRST_ID))
    export JOBDIR=/sdf/group/hps/user-data/sgaiser/run/recon_jeo2024/2019/ttb
    export RUNDIR=/fs/ddn/sdf/scratch/<YOUR SCRATCH>/$JOB_ID

    mkdir -p $RUNDIR
    cd $RUNDIR

    /bin/python3 $HPSMC_DIR/lib/python/hpsmc/job.py run -d $RUNDIR -c $JOBDIR/.hpsmc -i ${JOB_ID} $JOBDIR/data_cnv_job.py $JOBDIR/jobs_conv_<RUN NBR OF INTEREST>.json > $RUNDIR/../logs/job.${JOB_ID}.log
    ```
- Make sure that `fs/ddn/sdf/scratch/<YOUR SCRATCH>/logs` exists
- submit this via `sbatch subArray`


### Hpstr plotting from hpstr ntuples
From the object-ntuples we should be forming plots
We can use local processing (if easier / faster than sending to the grid):
```
python3 ../scripts/run_jobPool.py -c ../processors/config/anaVtxTuple_cfg.py --outDir ./jeopardyHistos/ --fileList ./hps_sarah_10031.txt --isData 1 -e "-y 2019"
```
Where fileList is the usual list of input files


### Plotting tools in hps-align
Find the branch with new plotting tools here:
 https://github.com/JeffersonLab/hps-align/tree/vtxana_monitoring

#### Example config file
```json
{
    "inputFiles": [
        "/path/to/fee_MC_gblplots_2021.root",
        "/path/to/fee_data_gblplots_2021.root",
        "/path/to/fee_MC_gblplots_2019.root",
        "/path/to/fee_data_gblplots_2019.root"
    ],
    "vtxana_inputFiles": [
        "/path/to/ttb_MC_ana_2021.root",
        "/path/to/physics_ana_2021.root",
        "/path/to/ttb_MC_ana_2019.root",
    	"/path/to/physics_ana_2019.root"
    ],
    "additional_inputFiles": [
	    "/path/to/ttb_MC_ana_2016.root",
	    "/path/to/physics_ana_2016.root"
    ],
    "outdir": "out",
    "legend": ["MC   2021", "data 2021", "MC   2019", "data 2019", "MC 2016", "data 2016"],
    "do_HTML": false,
    "oFext": ".png",
    "year": [2021, 2021, 2019, 2019]
}
```

#### Run hps-align
```bash
python3 -m hps_align plot --config your_config.json tracks.eop vtxana.vtx_z vtxana.momentum vtxana.chi2 vtxana.eop
```

## Problems
- EoP plots look okay for samples reconstructed from readout.
    - single cluster w energy above 3GeV (example in hpstr config for fee smearing)
    - **PF:: The solution to have the correct energy in re-reco is to switch `applyClusterCorrections` to true in the ReconParticleDriver. It seems to me that otherwise the energy of clusters associated to the particles won't be correct otherwise.** - Checking with Maurik if this is the right way to do it.
    - A working steering file for particles based trajectories as well as correct E/p is here: `/fs/ddn/sdf/group/hps/users/pbutti/run/alignmentDriver_gblplots_particles_fee_maps.lcsim`
- old 2019 MC has really bad $\chi^2$ after reconstruction(`/fs/ddn/sdf/group/hps/mc/4pt55GeV/tritrig/20um120nA/HPS_PhysicsRun2019-v2-FEE-Pass0/idealCond/`) 
    - Even after reintroducing the geometry bug in hps-java this problem persists.
    - **NOTES ON USING OLD MC**: The existing 2019 ttb MC has been generated with hps-java before the geometry bug fix. It is possible to manually reintroduce the bug to get the 'correct' results.
    - An example can be found here: https://github.com/sarahgaiser/hps-java/tree/alignment_workspace
- `VertexAnaProcessor` and `NewVertexAnaProcessor` -- issues with reconstructed momentum
    - When using `NewVertexAnaProcessor`: The wrong magnetic field seems to be used when generating the reco ntuples?


## Detectors

### 2019 detectors
#### Current for data:
`/fs/ddn/sdf/group/hps/users/pbutti/sw/hps-java/detector-data/detectors/HPS_ShimShoSurvey_M1M2tu_TZFix_iter26`

### 2021 detectors
#### Current for data:
`/fs/ddn/sdf/group/hps/users/bravo/src/hps-java/detector-data/detectors/HPS_Run2021Pass1_v5`


## Other useful notes

### Skip sensor in rerecon
```xml
<driver name="SensorSetup" type="org.hps.recon.tracking.SensorSetup" >
          <readoutCollections>SVTRawTrackerHits</readoutCollections>
          <fittedHitCollection>SVTFittedRawTrackerHits</fittedHitCollection>
          <skipSensors>module_L7t</skipSensors>
</driver>
```

### Run dir PF
`/fs/ddn/sdf/group/hps/users/pbutti/run`
`/fs/ddn/sdf/group/hps/users/pbutti/sw/hpstr/run_jeopardy`
### Run dir Sarah
`/sdf/group/hps/user-data/sgaiser/run/recon_jeo2024/2019/`

### Things shared by Matt
Data tuples (that's all I have, I think):
`/fs/ddn/sdf/group/hps/data/physrun2021/pass1b/HPS_Run2021Pass1_v4/hps_014185/`
Monte Carlo:
slcio:
`/fs/ddn/sdf/group/hps/mc/3pt7GeV/HPS_Run2021Pass2FEE/tritrig_beam_13_singles23/recon/`
`/fs/ddn/sdf/group/hps/mc/3pt7GeV/HPS_Run2021Pass2FEE/wab_beam_31_singles23/recon/`
root tuples (not guaranteed to work with your analysis!) :
`/fs/ddn/sdf/group/hps/users/mgraham/Tridents20XX/physrun2021/mctuples-tritrigbeam`
`/fs/ddn/sdf/group/hps/users/mgraham/Tridents20XX/physrun2021/mctuples-wabbeam`

### 2019 MC sample
- I tried to make the old 2019 MC work with different versions of hps-java (before the geometry bug fix, current status but without the geometry bug fix commit, current status but manually fixing the geometry in the compact) and all of them give us the same stats in the tight selection. As you said @PF: this MC is dead. The only option would be to generate more (or to also include the low lumi but that will only be factor x2 of total stats so not really worth it).
    - NOTE for future: We need to generate a new 2019 ttb MC sample with the fixed version of hps-java