From 77f0c00c2f9b446807ca14f323f301263bf01b45 Mon Sep 17 00:00:00 2001 From: tlatorre Date: Sat, 16 Mar 2019 13:22:06 -0500 Subject: add GPLv3 license --- utils/analyze-genie-mc | 15 +++++++++++++++ utils/calculate_limits.py | 15 +++++++++++++++ utils/convert-genie-to-gst | 15 +++++++++++++++ utils/convert-ratdb | 15 +++++++++++++++ utils/index.py | 15 +++++++++++++++ utils/plot | 15 +++++++++++++++ utils/plot-fit-results | 15 +++++++++++++++ 7 files changed, 105 insertions(+) (limited to 'utils') diff --git a/utils/analyze-genie-mc b/utils/analyze-genie-mc index 9739c65..7fdb948 100755 --- a/utils/analyze-genie-mc +++ b/utils/analyze-genie-mc @@ -1,4 +1,19 @@ #!/usr/bin/env python3 +# Copyright (c) 2019, Anthony Latorre +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . + import ROOT import numpy as np diff --git a/utils/calculate_limits.py b/utils/calculate_limits.py index f297a69..464051a 100755 --- a/utils/calculate_limits.py +++ b/utils/calculate_limits.py @@ -1,4 +1,19 @@ #!/usr/bin/env python3 +# Copyright (c) 2019, Anthony Latorre +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . + import numpy as np from scipy.integrate import quad from scipy.stats import expon diff --git a/utils/convert-genie-to-gst b/utils/convert-genie-to-gst index b2861e5..bb6ce6b 100755 --- a/utils/convert-genie-to-gst +++ b/utils/convert-genie-to-gst @@ -1,4 +1,19 @@ #!/usr/bin/env python +# Copyright (c) 2019, Anthony Latorre +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . + from subprocess import check_call from os.path import split, splitext, join import os diff --git a/utils/convert-ratdb b/utils/convert-ratdb index 5dd6ee4..08b4f73 100755 --- a/utils/convert-ratdb +++ b/utils/convert-ratdb @@ -1,4 +1,19 @@ #!/usr/bin/env python +# Copyright (c) 2019, Anthony Latorre +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . + """ Script to convert the PMT database in RAT to a CSV file (with spaces instead of commas). """ diff --git a/utils/index.py b/utils/index.py index 4edcd59..3e3aef6 100644 --- a/utils/index.py +++ b/utils/index.py @@ -1,4 +1,19 @@ #!/usr/bin/env python +# Copyright (c) 2019, Anthony Latorre +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . + """ This is a script to calculate the index of refraction of water as a function of wavelength, temperature, and pressure and fit it to a linear approximation in a diff --git a/utils/plot b/utils/plot index d671016..8fd2fae 100755 --- a/utils/plot +++ b/utils/plot @@ -1,4 +1,19 @@ #!/usr/bin/env python +# Copyright (c) 2019, Anthony Latorre +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . + from __future__ import print_function, division import yaml import numpy as np diff --git a/utils/plot-fit-results b/utils/plot-fit-results index c3d3f16..7a9708e 100755 --- a/utils/plot-fit-results +++ b/utils/plot-fit-results @@ -1,4 +1,19 @@ #!/usr/bin/env python +# Copyright (c) 2019, Anthony Latorre +
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 the plot program which can be installed
with:

    $ yum install plotutils

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

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

and make sure that -lasan is the first library in the list. 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