NEXT Analysis Quickstart Guide

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

NEXT Software Quickstart Guide

Assembled at NEXT-Ton Workshop 03/18/19

Setting yo’self up for IC analysis:


1) Get accounts and permissions
- Get an account on neutrinos.ific.uv.es. If you need a new account or password
reset, email Jose Carrion:
jocarbur@ific.uv.es.
- If you don’t have a GitHub account, sign up for one:
www.github.com
- Get permissions for gitLab, by emailing Jose Maria:
jmbenlloch@ific.uv.es

2) Log in via SSH. To do this type:


> ssh -Y [username]@neutrinos1.ific.uv.es

2) Add these lines to your ~/.bashrc file on neutrinos1:


export HDF5_USE_FILE_LOCKING=FALSE
export PATH=$PATH:/data4/NEXT/sw/git-2.9.5/bin
. /home/${USER}/miniconda/etc/profile.d/conda.sh
alias IC_setup='cd ~; export ICTDIR=$PWD/IC/; export ICDIR=$ICTDIR/invisible_cities;
export PATH=“ICTDIR/bin:$PATH”; export PYTHONPATH=$ICTDIR:$PYTHONPATH;
conda activate IC-3.7-2018-11-14'

3) Make a directory for yourself on /data4/NEXT/users


mkdir /data4/NEXT/users/${USER}

4) Make a fork of the Invisible Cities repository


- Log into your account on GitHub
- Go to this repository: https://github.com/nextic/IC
- Fork a copy to your local GitHub by clicking “Fork”, top right

5) Clone the IC directory


- SSH into neutrios1 as above
- Go to the directory where you want to install IC
- Activate lfs for git with ``git lfs install``
- Clone the IC code like this:
> git clone https://github.com/[your_github_account]/IC.git

6) Build it
- cd into the IC directory
- source manage.sh work_in_python_version 3.7
-
Setting yerself up for nexus analysis:
Warning: nexus and IC don’t play well together. If you have set up your environment for one of
them, you will need to open a new terminal to set it up for the other one. Don’t try to cofigure
both in one terminal.

Do (1) and (2) above if you didn’t already.

Add this alias to your bash profile:


alias nexus_setup='cd /data4/NEXT/users/$USER; source
/data4/NEXT/sw/Releases/NEXT_v1_05_02/setup.sh'

Make a fork of the Nexus repository


Go to https://next.ific.uv.es:8888/nextsw/nexus and hit “fork”.
Log into gitlab account and for a copy to your own area

On neutrinos, check out the repository


> git clone https://[user]@next.ific.uv.es:8888/[user]/nexus.git
(you can copy the above url from the gitlab page)

To build nexus:
Execute your new alias:
(This presumes you’ve got Geant4 available to you, as is true on the ific
nodes. However, on yer laptop download G4, build using
cmake -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_OPENGL_X11=ON
-DCMAKE_INSTALL_PREFIX=$GEANT4_DIR $GEANT4_DIR;
make; … get a sandwich, make install, then set it up, then proceed...)
> nexus_setup
Go to the directory nexus is in, then run scons to build it
> scons
Watch the compiler output fly!

To run a rest job:


Run this macro, it should work!
> ./nexus -n [NumOfEvents] macros/NEW_fullKr.init.mac
(Note: for some scripts you may need to modify this macro to
ensure it writes hdf5, by adding the line to the config:
/nexus/persistency/hdf5 true.
Another note: the above is a full simulation job, it will take a while.
Start with a small number of events, like N=1)
Looking at the output of your Nexus job using IC
Open a new terminal and set up the IC environment (above)

Setup IC and open a notebook


- If you are running IC on neutrinos, set up a forwarded jupyter notebook
(see below).
- If you are running IC on your own computer, copy the data file made with
nexus from neutrinos to your computer, and open a local jupyter notebook.

At the top of the jupyter notebook, import these packages:


%matplotlib inline
import numpy as np
import pylab
from invisible_cities.io.mcinfo_io import load_mcparticles

Load the MC from the file:


data = load_mcparticles("[File].h5")

You can look at the MC particle data just by running:


data

To access event number N:


data[N]

To access the Mth particle in event number N:


data[N][M]

Live a little! Take a look at a Kypton track!


eventNumber=0
particleNumber=1

hitpositions=[]
for h in data[eventNumber][particleNumber].hits:
hitpositions.append(h.pos)
hitpositions=np.array(hitpositions)

pylab.figure(figsize=(5,5),dpi=200)
pylab.plot(hitpositions[:,0],hitpositions[:,2],'o--')
pylab.xlabel("X position / mm")
pylab.ylabel("Z position / mm")
Running Invisible Cities to look at Waveforms
Make sure IC is built (see above), and that city is in your path:
> cd IC/bin
> export PATH=$PATH:$PWD

Now you have access to the “city” executable. Run a city, for example,
diomira, like this:
> city [cityname] [configfile]

In this case:
> cd invisible_cities/config
> city diomira diomira.conf

The action of any city is documented (theoretically) in its python file:


> cat ../cities/diomira.py
“This city simulates the response of the different sensors within the
detector, namely, PMTs and SiPMs…”

To look at the city output, open a python notebook using one of the
methods described. Use these imports:
import numpy as np
import pylab
import tables as tb
%matplotlib inline

You can open the h5 file using PyTables, like this:


dat=tb.open_file("./electrons_40keV_z250_test_RWF.h5")

Check out pytables tutorials and docs online to understand the details of
its functionality. But as a quick tour, we can see what tables are in the file
like this:
Dat.root
… Outputs this:
children := ['Filters' (Group), 'MC' (Group), 'RD' (Group), 'Run' (Group)]
The Raw Data waveforms are in table RD:
dat.root.RD
… Outputs this:
children := ['pmtblr' (EArray), 'pmtrwf' (EArray), 'sipmrwf' (EArray)]

For example, to look at PMT waveform M in event N:


dat.root.RD.pmtrwf[M][N]

Make a plot!
M=1
N=1
waveform=dat.root.RD.pmtrwf[M][N]

pylab.figure(figsize=(5,3),dpi=200)
pylab.plot(waveform)
pylab.xlabel("Tick")
pylab.ylabel("PMT Pulse Height (ADC)")
Try these Life-Hacks to make your world lazier:

Passwordless login
To log in without having to type your password every time, you can set up an ssh RSA
key. On a Mac, that involves typing these commands from your home directory:

ssh-keygen -t rsa
ssh [username]@neutrinos1.ific.uv.es mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh [username]@neutrinos1.ific.uv.es 'cat >>
.ssh/authorized_keys'

Then you can login without a password:


ssh -Y [username]@neutrinos1.ific.uv.es

jupyter notebook forwarding

You can run jupyter notebooks on neutrinos1 and forward the output to your local
browser like this:

From your computer:


ssh -Y -L[port]:localhost:[port] [username]@neutrinos1.ific.uv.es

For [port] pick a 4 digit number, and pick a unique one from all your friends.

Then from neutrinos1, launch the notebook with forwarding:


jupyter notebook --no-browser --port [port]

The terminal will give you a link to copy, something like:


http://localhost:8734/?token=1cd62afcec28c9da5b70fda3f58edee178c7d4b1e16cd2a0

Paste it into your browser, and you should be forwarding the notebook.
Aliases Commented [1]: This is a good document
If you are too lazy to type out the full ssh command, add these to your ~/.bash_profile on
your local computer:

alias sshuvpy="ssh -Y -L [port]:localhost:[port] [username]@neutrinos1.ific.uv.es"


alias sshuv="ssh -Y [username]@neutrinos1.ific.uv.es"

Restart the terminal.

From then on, you can log in using:


sshuv
For a normal shell or:
sshuvpy
For an ipython notebook forwarding shell.

You might also like