owned this note
owned this note
Published
Linked with GitHub
# Repository
https://github.com/effofex/madanalysis5_WSL
# What Will I Learn?
[MadAnalysis5](https://launchpad.net/madanalysis5) is a suite of software used to generate c/c++ code to analyze particle collider data. It was developed for Linux systems, but, with some tweaks can be run using the [Windows Subsystem for Linux](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux) (WSL, a.k.a. Bash on Ubuntu on Windows) available in Windows 10.
- You will learn how to install MadAnalysis5 and its core dependencies under the WSL
- You will learn how to generate and run the equivalent of 'hello world' to test the installation.
# Requirements
- An current installation (build 16215 or later) of Windows 10
- Approximately 1 to 2 gigabytes of drive space, mainly for the WSL installation
- An activated WSL with Ubuntu installed
- Installing WSL itself is beyond the scope of this tutorial, as there are already details [installation instructions](https://docs.microsoft.com/en-us/windows/wsl/install-win10) from Microsoft and from [third parties](https://www.computerhope.com/issues/ch001879.htm)
- This tutorial was specifically tested using ``Ubuntu 16.04.4 LTS``, the user may check their version by typing `lsb_release -a` in the console.
# Difficulty
- **Intermediate**. The user does not need to be an expert using the command line, but must not be intimidated by it.
# Tutorial Contents
There are three components to successfully run MadAnalysis5 using a fresh WSL:
1. Installing relevant development tools
1. Installing the software and its dependencies
1. Testing the installation using the equivalent of 'Hello, world!' to analyze some Large Hadron Collider (LHC) data.
All of these steps will be performed within the Bash shell, which is available from the start menu or can be found by pressing the Windows key and searching for 'ubuntu'.
## Preparing the WSL environment for development
A base install of Ubuntu under WSL will not include the necessary development tools for c/c++ (*e.g.* `gcc` and `make`). The simplest way to install these is to use `build-essential` [metapackage](https://superuser.com/questions/151557/what-are-build-essential-build-dep). The following three commands will update your [package manager](https://www.digitalocean.com/community/tutorials/how-to-manage-packages-in-ubuntu-and-debian-with-apt-get-apt-cache) and install `build-essential`:
```bash
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
```
## Installing MadAnalysis5 and its dependencies
Althought MadAnalysis5 has the ability to install some of its dependencies, that route does not always work under WSL. It is advisable to follow the order of installation listed here.
## Python **2.7**
As installed under the WSL, Ubuntu does not have Python, which MadAnalysis5 depends on. You must first install Python itself and then set up the environment so that MadAnalysis5 can find it.
```bash
sudo apt install python2.7
sudo ln -s /usr/bin/python2.7 /usr/bin/python
```
*Note:* This method assumes that a custom WSL instance is being set up for MadAnalysis5. Although creating a symbolic link to python2.7 is the simplest solution, it can cause issues in environments where other projects requiring Python3 are being run. Setting up a Python `virtualenv` is probably a workable solution in that case, but is beyond the scope of this tutorial.
### Installing the `ROOT` dependency
In this section, `ROOT` doe *not* refer to the Unix term, but rather the [CERN particle physics data analysis package](https://root.cern.ch/).
Although other versions of ROOT are likely to work, this tutorial was developed using [release 6.10.08](https://root.cern.ch/content/release-61008). The binary release for the appropriate Ubuntu version (here, 16.xx) can be installed using the following commands:
```bash
cd ~
curl https://root.cern.ch/download/root_v6.10.08.Linux-ubuntu16-x86_64-gcc5.4.tar.gz | tar xvz
cd root/bin/
source thisroot.sh
cd ~
```
**Note:** To avoid having to `source thisroot.sh` for every new WSL instance, the user is advised to [update their `.bashrc`](https://unix.stackexchange.com/questions/129143/what-is-the-purpose-of-bashrc-and-how-does-it-work) to do so.
### Installing madanalysis5
MadAnalysis5 can be installed similarly to `ROOT`:
```bash
wget https://launchpad.net/madanalysis5/trunk/v1.6/+download/ma5_v1.6.tgz
tar -xvzf ma5_v1.6.tgz
```
After unarchiving, run `./bin/ma5`.
<center>
![ma5_install.png](https://ipfs.busy.org/ipfs/QmXVBA4vttWehRFwhJLMgLJNaqbKiBddzRcwfHyMbygExY)
</center>
The screen displayed should be similar to above and list mostly disabled dependencies, but indicate that `ROOT` has been found. There should be a prompt asking the number of cores to be configured for. Choose the default number of cores and let the program run. It should list the component number and total number of components it is preparing, as below:
<center>
![ma5_cores.png](https://ipfs.busy.org/ipfs/QmYgECSPKoPmGC8E5PTFaoCe2px8NGHxV4zuZCkgf4Ni5f)
</center>
### Installing delphes
This is *one of the major installation steps which differs* from installing MadAnalysis5 under a dedicated Linux environment. Instead of using the MadAnalysis5 prompt to 'install delphes', the user should clone the delphes git repository into the appropraite location and build from source:
From the madanalysis5 directory
```bash
cd tools
git clone https://github.com/delphes/delphes.git
cd delphes
make
```
Compilation should take approximately 30 to 60 minutes on a contemporary computer (*e.g.* an i7-3xxx with 8 gb RAM was sufficient for this tutorial).
MadAnalysis5 should be run again (`~/madanalysis/bin/ma5`) to check that `delphes` was found and to reconfigure the components.
## Generating the equivalent of 'Hello, world!' to test the installation.
MadAnalysis5 serves as a code generator to create programs for specific analyses of data. The code resulting from this section of tutorial serves as both a test of the installation and as a completed [Task 1a](https://steemit.com/utopian-io/@lemouth/particle-physics-utopian-detecting-particles-at-colliders-and-implementing-this-on-a-computer) for the associated Utopian project. The user is advised to work through the example themselves, but a working version is [available on github](https://github.com/effofex/madanalysis5_WSL).
### Code generation
As in the associated task, the first step is to tell MadAnalysis5 where to create the skeleton code:
```bash
./bin/ma5 -E test_folder test_analysis
```
For the generated code to compile under the WSL ***an additional step is needed***. This is because the environment variables referenced in the generated `Build/setup.sh` script, when expanded, contain spaces as as result of Windows naming conventions, and the conditionals used in the script cannot handle them, as written.
To fix the script, edit `Build/setup.sh` in in `vim` or your text editor of choice, and surround all environment variables in conditional statements with double quotes .
For example, `if [[ $MA5_BASE && $PATH && $LD_LIBRARY_PATH ]]; then` should become `if [[ "$MA5_BASE" && "$PATH" && "$LD_LIBRARY_PATH" ]]; then`
(GUI users will need to [setup their system to use X](https://virtualizationreview.com/articles/2018/01/30/hands-on-with-wsl-graphical-apps.aspx) should they wish to use an editor like `gedit`).
### Downloading example data
It is generally best to treat the WSL file system and the host windows file system as two separate entities. The best way to download the example data file is then to use wget, such as we did with the `ROOT` binaries. This is also a good time to create the input file read by the generated program.
```bash
cd test_folder\test_analysis\Input
wget http://madanalysis.irmp.ucl.ac.be/raw-attachment/wiki/MA5PublicSandBox/tth_aa.root
realpath tth_aa.root > tth_aa.list
```
### Running the software
The generated code, after the modifications above, will run, but will not produce the output required by Task 1a. The user is encouraged to figure out how to modify `test_folder/Build/SampleAnalyzer/User/Analyzer/test_analysis.cpp` to produce the desired output. However, one approach is published at the [github repository](https://github.com/effofex/madanalysis5_WSL) associated with this tutorial, should they become stuck.
For completeness, the rest of the build process is the same as under native Ubuntu and should not take more than a few minutes.
```bash
cd test_folder/Build
source setup.sh
make
./MadAnalysis5job ../Input/tth_aa.list
```
The expected output will differ slightly, based on how the user chose to display the output, but should appear similar to below:
<center>
![ma5_run.png](https://ipfs.busy.org/ipfs/QmTPtZ1gsq3JmN1GNazteVnjcWhSF1QENCPif84X4uQrMX)
</center>
# Proof of Work Done
The modified generated code used in this tutorial is available at https://github.com/effofex/madanalysis5_WSL