---
# System prepended metadata

title: WCT Tutorial on Sim/SigProc

---

# WCT Tutorial on Sim/SigProc

- Video and slides: https://indico.bnl.gov/event/15006/

## Run current SBND sim/sigproc
Setup the sbnd umbrella package and check `wirecell` and `larwirecell`
```
source /cvmfs/sbnd.opensciencegrid.org/products/sbnd/setup_sbnd.sh
setup sbndcode v09_43_00 -q e20:prof
```

Check current `$WIRECELL_PATH` and find there are missing stuff.
```
$echo $WIRECELL_PATH 
/cvmfs/larsoft.opensciencegrid.org/products/wirecell/v0_17_1/Linux64bit+3.10-2.17-e20-prof/share/wirecell
```

Add more cfg and data to `$WIRECELL_PATH`
**WCT uses this env var to search for configurations or data files**
```
export TUTORIAL=<path-to-tutoiral>
mkdir $TUTORIAL
cd $TUTORIAL
git clone https://github.com/WireCell/wire-cell-toolkit.git
git clone https://github.com/WireCell/wire-cell-data.git
```

Use this version for now
```
cd wire-cell-toolkit
git checkout -b tutorial remotes/origin/0.17.1-tutorial-20220302
```

Add cfg and data to ``$WIRECELL_PATH`
```
export WIRECELL_PATH=$TUTORIAL/wire-cell-toolkit/cfg:$WIRECELL_PATH
export WIRECELL_PATH=$TUTORIAL/wire-cell-data:$WIRECELL_PATH
```

### run
Copy all fcl files here `$TUTORIAL/wire-cell-toolkit/cfg/pgrapher/experiment/sbnd/fhicl` to your test location, then follow the [run.sh](https://github.com/WireCell/wire-cell-toolkit/blob/0.17.1-tutorial-20220302/cfg/pgrapher/experiment/sbnd/fhicl/run.sh)
<!-- **note: do this first `rm standard_g4_sbnd.fcl` to use newer g4 sim fcl here `sbndcode/*/fcl`** -->
```
mkdir $TUTORIAL/test
cd $TUTORIAL/test
cp $TUTORIAL/wire-cell-toolkit/cfg/pgrapher/experiment/sbnd/fhicl/*.fcl .

lar -n1 -c singlegen_muon.fcl -o gen.root
lar -n1 -c standard_g4_sbnd.fcl gen.root -o g4.root
lar -n1 -c standard_detsim_sbnd.fcl g4.root -o detsim.root
lar -n1 -c wcls-sp.fcl detsim.root -o reco.root
```

## Visualize a WCT graph

Need to install wire-cell-python first to use `wirecell-pgraph`
```
cd $TUTORIAL
git clone https://github.com/WireCell/wire-cell-python.git
python3 -m venv wcpy
source wcpy/bin/activate
pip install numpy vtk shapely
cd wire-cell-python
python setup.py develop # first time deployment, can ignore next time
```
jsonnet -> json
```
jsonnet \
--ext-code DL=4.0 \
--ext-code DT=8.8 \
--ext-code lifetime=10.4 \
--ext-code driftSpeed=1.565 \
-J $TUTORIAL/wire-cell-toolkit/cfg \
$TUTORIAL/wire-cell-toolkit/cfg/pgrapher/experiment/sbnd/wcls-sim-drift-simchannel.jsonnet \
-o wcls-sim-drift-simchannel.json
```
json -> pdf
```
wirecell-pgraph dotify --jpath -1 --no-params \
wcls-sim-drift-simchannel.json \
wcls-sim-drift-simchannel.pdf
```

Examples: https://www.phy.bnl.gov/~hyu/tutorial-sbnd/

## Re-compile WCT
```
cd $TUTORIAL/wire-cell-toolkit

./wcb configure \
--with-tbb="$TBBROOT" \
--with-jsoncpp="$JSONCPP_FQ_DIR" \
--with-jsonnet-include="$GOJSONNET_FQ_DIR/include" \
--with-jsonnet-lib="$GOJSONNET_FQ_DIR/lib" \
--with-eigen-include="$EIGEN_DIR/include/eigen3/" \
--with-root="$ROOTSYS" \
--with-fftw="$FFTW_FQ_DIR" \
--with-fftw-include="$FFTW_INC" \
--with-fftw-lib="$FFTW_LIBRARY" \
--with-fftwthreads="$FFTW_FQ_DIR" \
--boost-includes="$BOOST_INC" \
--boost-libs="$BOOST_LIB" \
--boost-mt \
--with-hdf5="$HDF5_FQ_DIR" \
--with-h5cpp="$H5CPP_DIR" \
--with-spdlog-include="$SPDLOG_INC" \
--with-spdlog-lib="$SPDLOG_LIB" \
--prefix=$TUTORIAL/opt
```
```
./wcb -p --notests install
```

## WCT user package

```
cd $TUTORIAL
git clone https://github.com/WireCell/example-analysis-package.git
git checkout -b tutorial 0.17.1-tutorial-20220302
```

compiling
```
cd $TUTORIAL/example-analysis-package

./wcb configure --prefix=$TUTORIAL/opt \
--with-spdlog-include="$SPDLOG_INC" \
--with-spdlog-lib="$SPDLOG_LIB" \
--with-jsoncpp="$JSONCPP_FQ_DIR" \
--with-jsonnet-include="$GOJSONNET_FQ_DIR/include" \
--with-jsonnet-lib="$GOJSONNET_FQ_DIR/lib" \
--with-eigen-include="$EIGEN_DIR/include/eigen3" \
--with-root="$ROOTSYS" \
--with-fftw="$FFTW_FQ_DIR" \
--with-fftw-include="$FFTW_INC" \
--with-fftw-lib="$FFTW_LIBRARY" \
--with-fftwthreads="$FFTW_FQ_DIR" \
--boost-includes="$BOOST_INC" \
--boost-libs="$BOOST_LIB" \
--boost-mt \
--with-wct=$WIRECELL_FQ_DIR/ \
--with-wct-lib=$WIRECELL_LIB
```
```
./wcb -p --notests install
```
```
export LD_LIBRARY_PATH=$TUTORIAL/opt/lib64:$LD_LIBRARY_PATH
```


## Useful commands

### Translate wire geom txt to json.bz2 format and make a pdf for checking
```
wirecell-util convert-multitpc-wire --no-duoface input.txt output.json.bz2
wirecell-util plot-wires output.json.bz2 output.pdf
```

## References

 - [Xin - Brief Review of WCP Algorithm](https://indico.bnl.gov/event/12908/)
 - [BV - Modern C++](https://indico.bnl.gov/event/13236/)
 - [BV - WCT Architecture and Design Philosophy](https://indico.bnl.gov/event/13058/)
 - [BV - Wire-Cell Toolkit Configuration](https://indico.bnl.gov/event/13480/)