aboutsummaryrefslogtreecommitdiff
path: root/Makefile
AgeCommit message (Collapse)Author
2019-10-12move sddm.tex to doc/tlatorre
2019-10-12add a section about the backgroundstlatorre
2019-10-12first draft of my thesistlatorre
2019-05-24add a script to submit jobs to the gridtlatorre
2018-09-17add top level Makefiletlatorre
2018-08-14move everything to src directorytlatorre
2018-08-14initial commit of likelihood fit for muonstlatorre
This commit contains code to fit for the energy, position, and direction of muons in the SNO detector. Currently, we read events from SNOMAN zebra files and fill an event struct containing the PMT hits and fit it with the Nelder Mead simplex algorithm from GSL. I've also added code to read in ZEBRA title bank files to read in the DQXX files for a specific run. Any problems with channels in the DQCH and DQCR banks are flagged in the event struct by masking in a bit in the flags variable and these PMT hits are not included in the likelihood calculation. The likelihood for an event is calculated by integrating along the particle track for each PMT and computing the expected number of PE. The charge likelihood is then calculated by looping over all possible number of PE and computing: P(q|n)*P(n|mu) where q is the calibrated QHS charge, n is the number of PE, and mu is the expected number of photoelectrons. The latter is calculated assuming the distribution of PE at a given PMT follows a Poisson distribution (which I think should be correct given the track, but is probably not perfect for tracks which scatter a lot). The time part of the likelihood is calculated by integrating over the track for each PMT and calculating the average time at which the PMT is hit. We then assume the PDF for the photons to arrive is approximately a delta function and compute the first order statistic for a given time to compute the probability that the first photon arrived at a given time. So far I've only tested this with single tracks but the method was designed to be easy to use when you are fitting for multiple particles.
2018-07-05refractive_index.c -> optics.ctlatorre
2018-07-05add a function to compute the energy along a muon tracktlatorre
2018-07-05add a simple test for the various muon functionstlatorre
2018-07-04add a function to compute the refractive index of water as a function of ↵tlatorre
wavelength
2018-07-04add a test of the get_solid_angle functiontlatorre
2018-07-04initial commit of a function to calculate the solid angle subtended by a ↵tlatorre
circular disk
2018-05-01update makefile to compile with -O4tlatorre
2018-05-01start working on the code to numerically integrate to find the event ratetlatorre
2018-05-01initial committlatorre
b0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
Building
========

First you have to install the gsl and nlopt libraries. On Fedora you can
install these with the following command:

    $ yum install gsl gsl-devel NLopt NLopt-devel

You can also install these packages yourself. For instructions, see below
(Installing GSL and Installing NLopt).

Then, to build everything you just type:

    $ make

Some of the test programs also require plot and gnuplot which can be installed
with:

    $ yum install plotutils gnuplot

Installing GSL
==============

To install GSL in your home directory, you can run the following commands:

    $ curl -O -L ftp://ftp.gnu.org/gnu/gsl/gsl-2.5.tar.gz
    $ tar -xzvf gsl-2.5.tar.gz
    $ cd gsl-2.5
    $ mkdir $HOME/local
    $ ./configure --prefix=$HOME/local
    $ make
    $ make install

Installing NLopt
================

    $ curl -O -L https://github.com/stevengj/nlopt/archive/v2.5.0.tar.gz
    $ tar -xzvf v2.5.0.tar.gz
    $ cd nlopt-2.5.0
    $ mkdir build
    $ cd build
    $ cmake -DCMAKE_INSTALL_PREFIX=$HOME/local ..
    $ make
    $ make install

To use gsl and nlopt installed locally, you will have to edit the Makefile and
add the following to the CFLAGS and LDLIBS variables:

    CFLAGS=-I$(HOME)/local/include
    LDLIBS=-L$(HOME)/local/lib -L$(HOME)/local/lib64

and also edit the -lnopt_cxx line to just be -lnlopt.

You will also need to edit ~/.bash_profile and add the following line:

    export LD_LIBRARY_PATH=$HOME/local/lib:$HOME/local/lib64

Installing NLopt for the grid
=============================

When running the fitter on the grid, it's necessary to compile NLopt as a
static library.

    $ curl -O -L https://github.com/stevengj/nlopt/archive/v2.6.1.tar.gz
    $ tar -xzvf v2.6.1.tar.gz
    $ cd nlopt-2.6.1
    $ mkdir build
    $ cd build
    $ cmake -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ -DCMAKE_INSTALL_PREFIX=$HOME/local -DBUILD_SHARED_LIBS=OFF ..
    $ make
    $ make install

and then you have to edit the Makefile to add:

    CFLAGS=-fdiagnostics-color -O2 -Wall -g -DSWAP_BYTES -I/home/tlatorre/local/include
    LDLIBS=-fdiagnostics-color -lm -L/home/tlatorre/local/lib64 -l:libnlopt.a -L/home/tlatorre/local/lib -l:libgsl.a -l:libgslcblas.a -lstdc++

Fitting Events
==============

You can fit events from SNOMAN data structure files by running the following
command:

    $ ./src/fit [input file] -o [output file]

and then plot the fit results by using the plot script:

    $ ./utils/plot.py [output file]

The plot script relies on the MC information in the SNOMAN file, so make sure
that SNOMAN is set up to output MC info when you simulate events (see the next
section).

Simulating Events with SNOMAN
=============================

Since the fitter reads in SNOMAN data structures it is necessary to use a
command file which correctly specifies the output file format. To benchmark the
fit results it is also necessary to save the initial MC vertex information.

I have created a template command file in macros/mc_run_10000.cmd which
simulates run 10000 from the D2O phase. You can create a proper command file to
run SNOMAN with by running the snogen program which uses a simple templating
system to fill in some variables in this template. For example to simulate 100
1 GeV muons uniformly distributed throughout the AV and with isotropic
directions you can run:

    $ ./macros/snogen -p mu_minus -e 1000.0 -n 100 | /path/to/snoman.exe

See the comment at the top of ./macros/snogen for more information.

Debugging
=========

To debug memory issues you can compile everything with an address sanitizer.
Edit the Makefile and add the following flags:

    CFLAGS=-fsanitize=address
    LDLIBS=-fsanitize=address

Then, recompile:

    $ make clean
    $ make

and run the fitter. It should crash if there is a buffer overflow or use after
free bug.

You can also run the fitter with valgrind to search for memory leaks:

    $ valgrind --leak-check=full ./src/fit [input file]

Profiling
=========

To profile the code, you can use the linux perf command along with Brendan
Gregg's flamegraph software to produce a flame graph.

First run the fitter:

    $ ./src/fit [input file]

Then, identify the PID of the fit program and run:

    $ sudo perf record -F 99 -p [PID] --call-graph dwarf sleep 10

Then, to create the flame graph:

    $ sudo chown [username]:[username] perf.data
    $ perf script > out.perf
    $ stack-collapse.pl out.perf > out.folded
    $ flamegraph.pl out.folded > kernel.svg