  ========== Preliminaries, probably already OK ===========
  Install things if needed. Example is for a brand-new Ubuntu 20.04 system; on
  a more complete system for scientific use, most of this is already there.

  Compilers etc:

sudo apt install gcc g++ gfortran make cmake

  Code management clients:

sudo apt install subversion git cvs

  System tools:

sudo apt install mlocate gawk 

  ========= End of preliminaries =========

  ========= Root and LCIO, if not already available =======

  Root: If you already have root up and running, skip this:

  If

which root

  doesn't give output, either (if you're sure that you have root), find and
  source your thisroot.sh, or install root. On Ubuntu/Debian there is
  no package file, so you must do:

cd ~
sudo apt-get install dpkg-dev binutils libx11-dev libxpm-dev libxft-dev libxext-dev python libssl-dev
wget https://root.cern/download/root_v6.24.02.Linux-ubuntu20-x86_64-gcc9.3.tar.gz
tar -xzvf root_v6.24.02.Linux-ubuntu20-x86_64-gcc9.3.tar.gz
.  root/bin/thisroot.sh

  (This is for Ubuntu 20.04, look at the root download page ( https://root.cern/install/ )to get
  the right tar-ball or package file for other installations)

  LCIO:  If you already have LCIO up and running, skip this. Note that to actually build it
  takes quite some time!!!

cd ~
git clone https://github.com/iLCSoft/LCIO.git
cd LCIO/
git checkout v02-16-01
mkdir build ; cd build

  here do "root-config --cflags" to check which standard your root was compiled with.
  for the Ubuntu 20.04  installation, you'll find " -std=c++14 ", so 14 is the one you should tell
  LCIO to use.

cmake -DBUILD_ROOTDICT=ON -D CMAKE_CXX_STANDARD=14 ..
make -j 4 install
cd ..
. ./setup.sh
cd ~


  ==========  Now actually in business !!!!

  First check for the linear algebra packages. Do:

locate liblapack

  If that gives no output, install:

    sudo apt install liblapack-dev libblas-dev

  You can also make sure that you have pandoc installed ("which pandoc", if no output "sudo apt  install pandoc").
  Likewise for "texlive" and "texlive-latex-extra". They are not essential, having them allows you to get your free
  copy of the User's Guide during install.

  If your default shell is not bash, now is the time to do

bash

  and work in that window !!!


  Now - finally :

cd ~
git clone https://berggren@gitlab.desy.de/mikael.berggren/sgv.git sgv/
cd sgv
git checkout -b mysgv
less -iX README

  Read it!!!

  Install pythia6 and stdhep, if you don't already have them:

cd samples/
bash install-stdhep ../
. ./install-stdhep ../ "" env
bash install-pythia ../
. ./install-pythia ../ "" env
cd ..

  (If you already *do* have pythia6 and/or stdhep installed, the install script will try to
   find them, but might fail to do so: pay attention to the messages !)

  All set! Now do

. ./install

  and take the defaults for all questions.

  ========= Fun starts here !

  The main reference:
  
    https://desy.de/~berggren/sgv_ug/
    
  If you had pandoc, you will also have the pdf sgv_ug.pdf in your sgv directory by now.
  The contents is the same as the web-page.

  Also: always check the READMEs in various sub-directories you might be curious about.

  Example 1:

cd tests
cresgvexe merge sgvuser
./sgvass.sh basic
root -b sgv_ex.C
./sgvuser.exe

  And look at your first SGV results:

root -l  basic_sgv.root
.ls
id1->Draw()
// etc. ....
.q

  Example 2:

  Create and view some detector performance study. It is described in samples/README , but
  here are the steps;

cd ..
mkdir myscan
cd samples
  # copy scripts, macros, and code
cp  all-scans-in-one  scan-template.steer  scan.F95  p5_plots_onegeo_reduced.C \
    sgvass-scan.sh all-to-one-in-100 one-in-100.f  ../myscan
cd ../myscan
  # compile and link
cresgvexe merge scan "-DSCAN"
  # get a detector geometry description to study:
cp ../sgv_geo3_ex.inp .
  # scan in momentum at a few fixed angles, then in angle at a few fixed momenta
bash all-scans-in-one sgv_geo3_ex
  # condense the output for faster plotting:
gfortran -o one-in-100.exe one-in-100.f
cd sgv_geo3_ex-all
bash ../all-to-one-in-100

  Now look at it with root. First do

for red in *red ; do echo -n "\"$red\"," ;done ; echo

  to get a list of files to look at in a form ready to cut'n'paste (don't include the
  trailing comma in the cut !). Then

root -l
.x ../p5_plots_onegeo_reduced.C( { --- cut'n'paste goes here ---- } )
// .... draw D(pt) vs. pt a different theta, all in the same plot, with colour coding ....
null(0.1, 250., 1.0e-5, 1.0e-2) ; c1->SetLogy(); c1->SetLogx();
graph(sgv_geo[3].pt,sgv_geo[3].dpt,2)->Draw("SAME")
graph(sgv_geo[2].pt,sgv_geo[2].dpt,4)->Draw("SAME")
graph(sgv_geo[1].pt,sgv_geo[1].dpt,1)->Draw("SAME")
graph(sgv_geo[0].pt,sgv_geo[0].dpt,6)->Draw("SAME")
.q

  Look in  ../p5_plots_onegeo_reduced.C to see in detail what p5_plots_onegeo_reduced(), frame() and
  graph() does.

  Example 3: 

  Create a root column-wise ntuple, and also output the generated events.

cd ../..
cd tests/
cp ../samples/sgvopt.F95 .
cp ../samples/sgv_pythia.steer .
sgvass.sh sgvopt
rm sgv.steer ; ln -s sgv_pythia.steer sgv.steer
cresgvexe merge sgvopt

  Now edit sgv_pythia.steer, and look for GENERATOR_OUTPUT_TYPE . Change the value to 'STDH'. Run.

./sgvopt.exe
mv fort.90 fort.90.stdhep
mv sgvopt_sgv.root sgvopt_sgv_1.root

  Look at the ntuple:

root -l sgvopt_sgv_1.root
.ls
SGV_NTUPLE->StartViewer()
// .... click around ....
// .... look at eg. Impact parameter/over its error , if that's less than 15:
SGV_NTUPLE->Draw("IPRF/SIPRF","fabs(IPRF/SIPRF)<15")
// .... Or the energy of all true e+-
SGV_NTUPLE->Draw("ES","abs(IDT[TTRA])==11")
// .... and so on
.q

  Now edit sgv_pythia.steer again, but change GENERATOR_OUTPUT_TYPE to 'LCIO' instead. Run.

./sgvopt.exe

  (Don't need to rename fort.90 in this case - the output is already set to fort.90.slcio)

Example 4:

  Read generated events from external file.

cp ../samples/sgv_extread.steer .
sgvass.sh extreadstdh
rm sgv.steer ; ln -s sgv_extread.steer sgv.steer
cresgvexe merge sgvuser "-DEXTREAD"

  (Note the  "-DEXTREAD" !)

  Edit sgv_extread.steer. Change CWN to .FALSE. and look for INPUT_FILENAMES . uncomment it and set it
  to 'fort.90.stdhep'. GENERATOR_INPUT_TYPE should be 'STDH'. Run:

root -b sgv_ex.C
./sgvuser.exe

  (look at the histos in root if you want).
  Edit sgv_extread.steer again, and change the INPUT_FILENAMES to 'fort.90.slcio', and change
  GENERATOR_INPUT_TYPE to 'LCIO'. Run again.

sgvass.sh extreadlcio
root -b sgv_ex.C
./sgvuser.exe

  Example 5:

  Make an LCIO dst as output. Details in samples/lcio/00_README

cd ../samples/lcio/
cp usesgvlcio.F95 sgv_ild_lcio.steer ../../tests/
cd ../../tests/
sgvass.sh lciotest
rm sgv.steer ; ln -s sgv_ild_lcio.steer sgv.steer
cresgvexe merge usesgvlcio

  and run

./usesgvlcio.exe

  look at the output:

dumpevent  sgvout.slcio 1 | less -iX

  If your LCIO was compiled to generate the root-dictionary, you can look at the lcio file
  in root. See https://github.com/ILDAnaSoft/miniDST ("Reading LCIO in ROOT") on what is needed
  for that to work!

  Also: Look at the geo-files, the steer files and zauser (in sgvuser and sgvopt).
