From cb1f36d63e87932a766efc4c42c66f0579290eaa Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Wed, 21 Jul 2010 21:52:33 +0000 Subject: [PATCH] initial version --- pyext/ctlike.i | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/ctbin/main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/ctlike/Makefile.am | 29 +++++++++++++++++++++++++++++ src/ctlike/ctlike.cpp | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ctlike/ctlike.hpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/ctlike/ctlike.par | 39 +++++++++++++++++++++++++++++++++++++++ src/ctlike/main.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ src/ctselect/main.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 473 insertions(+), 0 deletions(-) create mode 100644 pyext/ctlike.i create mode 100644 src/ctbin/main.cpp create mode 100644 src/ctlike/Makefile.am create mode 100644 src/ctlike/ctlike.cpp create mode 100644 src/ctlike/ctlike.hpp create mode 100644 src/ctlike/ctlike.par create mode 100644 src/ctlike/main.cpp create mode 100644 src/ctselect/main.cpp diff --git a/pyext/ctlike.i b/pyext/ctlike.i new file mode 100644 index 0000000..c170e79 --- /dev/null +++ b/pyext/ctlike.i @@ -0,0 +1,47 @@ +/*************************************************************************** + * ctlike - CTA maximum likelihood tool * + * ----------------------------------------------------------------------- * + * copyright (C) 2010 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/** + * @file ctlike.i + * @brief CTA maximum likelihood tool SWIG definition + * @author J. Knodlseder + */ +%{ +/* Put headers and other declarations here that are needed for compilation */ +#include "ctlike.hpp" +%} +%include gammalib.i + + +/***********************************************************************//** + * @class ctlike + * + * @brief CTA maximum likelihood tool SWIG interface defintion. + ***************************************************************************/ +class ctlike : public GApplication { +public: + // Constructors and destructors + ctlike(void) : GApplication(CTLIKE_NAME, CTLIKE_VERSION) { return; } + + // Methods + int run(void); +}; + + +/***********************************************************************//** + * @brief CTA maximum likelihood tool SWIG extension + ***************************************************************************/ +%extend ctlike { + ctlike copy() { + return (*self); + } +} diff --git a/src/ctbin/main.cpp b/src/ctbin/main.cpp new file mode 100644 index 0000000..3b0e8b4 --- /dev/null +++ b/src/ctbin/main.cpp @@ -0,0 +1,46 @@ +/*************************************************************************** + * ctbin - CTA data binning main code * + * ----------------------------------------------------------------------- * + * copyright (C) 2010 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/** + * @file main.cpp + * @brief CTA data binning tool main code + * @author J. Knodlseder + */ + +/* __ Includes ___________________________________________________________ */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include "ctbin.hpp" + + +/***********************************************************************//** + * @brief Main entry point of application + * + * @param[in] argc Number of command line arguments. + * @param[in] argv Command line arguments. + * + * This is the main entry point of the gtbin application. It allocates a + * ctbin object and runs the application. + ***************************************************************************/ +int main (int argc, char *argv[]) +{ + // Create instance of application + ctbin application(argc, argv); + + // Run application + int rc = application.run(); + + // Return + return rc; +} diff --git a/src/ctlike/Makefile.am b/src/ctlike/Makefile.am new file mode 100644 index 0000000..9bcd3f0 --- /dev/null +++ b/src/ctlike/Makefile.am @@ -0,0 +1,29 @@ +## Process this file with automake to produce Makefile.in + +# we use srcdir/src for "private" includes +# we use srcdir/include for the static global include files +# we use builddir/src for the generated include files to get found + +# Include directories +INCLUDES = -I$(top_srcdir)/include \ + -I$(top_builddir)/src \ + -I$(top_srcdir)/src + +# Program name +bin_PROGRAMS = ctlike + +# Sources +sources = ctlike.cpp + +# Program definition +ctlike_SOURCES = main.cpp $(sources) +ctlike_LDFLAGS = @LDFLAGS@ +ctlike_CPPFLAGS = @CPPFLAGS@ + +# Parameter files +pfilesdir = $(prefix)/syspfiles +pfiles_DATA = ctlike.par + +# Libtool library (only needed for python bindings) +noinst_LTLIBRARIES = libctlike.la +libctlike_la_SOURCES = $(sources) diff --git a/src/ctlike/ctlike.cpp b/src/ctlike/ctlike.cpp new file mode 100644 index 0000000..6db4459 --- /dev/null +++ b/src/ctlike/ctlike.cpp @@ -0,0 +1,176 @@ +/*************************************************************************** + * ctlike - CTA maximum likelihood tool * + * ----------------------------------------------------------------------- * + * copyright (C) 2010 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/** + * @file ctlike.cpp + * @brief CTA maximum likelihood tool implementation + * @author J. Knodlseder + */ + +/* __ Includes ___________________________________________________________ */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include "ctlike.hpp" +#include "GTools.hpp" + + +/***********************************************************************//** + * @brief Setup Crab point source powerlaw model. + ***************************************************************************/ +GModels crab_plaw(void) +{ + // Setup GModels for optimizing + GModelSpatialPtsrc point_source; + GModelSpectralPlaw power_law; + GModel crab; + GModels models; + try { + GSkyDir dir; + //dir.radec_deg(83.6331, +22.0145); + dir.radec_deg(117.0, -33.0); // Adapt to source position in file + point_source = GModelSpatialPtsrc(dir); + power_law = GModelSpectralPlaw(1.0e-7, -2.1); + power_law.par(0)->min(1.0e-12); + crab = GModel(point_source, power_law); + crab.name("Crab"); + models.append(crab); + } + catch (std::exception &e) { + std::cout << std::endl + << "TEST ERROR: Unable setup GModels for optimizing." + << std::endl; + std::cout << e.what() << std::endl; + throw; + } + + // Return model + return models; +} + + +/***********************************************************************//** + * @brief Run maximum likelihood analysis + ***************************************************************************/ +int ctlike::run(void) +{ + // Initialise return code + int rc = 0; + + // Branch on method + std::string method = par("method")->value(); + if (toupper(method) == "UNBINNED") + rc = unbinned(); + else + rc = binned(); + + // Return + return rc; +} + + +/***********************************************************************//** + * @brief Perform unbinned maximum likelihood analysis + ***************************************************************************/ +int ctlike::unbinned(void) +{ + // Initialise return code + int rc = 0; + + // Get parameters + std::string evfile = par("evfile")->value(); + std::string caldb = par("caldb")->value(); + std::string irf = par("irf")->value(); + + // Declare observations + GObservations obs; + GCTAObservation run; + + // Setup ROI covered by data + GCTAInstDir instDir; + GCTARoi roi; + instDir.radec_deg(117.02, -33.35); // Adapt to file + roi.centre(instDir); + roi.radius(2.5); + + // Setup energy range covered by data + GEnergy emin; + GEnergy emax; + emin.TeV(0.02); + emax.TeV(100.0); + + // Setup time range covered by data + GTime tstart; + GTime tstop; + tstart.met(0.0); + tstop.met(10000.0); + + // Load data and response and set ROI, energy range and time range + // for analysis + run.load_unbinned(evfile); + run.response(irf,caldb); + run.roi(roi); + run.gti()->add(tstart, tstop); + run.ebounds()->append(emin, emax); + obs.append(run); + + // Setup GModels for optimizing + GModels models = crab_plaw(); + obs.models(models); + + // Perform LM optimization + GOptimizerLM opt; + opt.max_iter(1000); + obs.optimize(opt); + std::cout << obs << std::endl; + + // Return + return rc; +} + + +/***********************************************************************//** + * @brief Perform binned maximum likelihood analysis + ***************************************************************************/ +int ctlike::binned(void) +{ + // Initialise return code + int rc = 0; + + // Get parameters + std::string cntmap = par("cntmap")->value(); + std::string caldb = par("caldb")->value(); + std::string irf = par("irf")->value(); + + // Declare observations + GObservations obs; + GCTAObservation run; + + // Load binned CTA observation + run.load_binned(cntmap); + run.response(irf,caldb); + obs.append(run); + + // Setup GModels for optimizing + GModels models = crab_plaw(); + obs.models(models); + + // Perform LM optimization + GOptimizerLM opt; + opt.max_iter(1000); + obs.optimize(opt); + std::cout << obs << std::endl; + + // Return + return rc; +} diff --git a/src/ctlike/ctlike.hpp b/src/ctlike/ctlike.hpp new file mode 100644 index 0000000..19987e0 --- /dev/null +++ b/src/ctlike/ctlike.hpp @@ -0,0 +1,50 @@ +/*************************************************************************** + * ctlike - CTA maximum likelihood tool * + * ----------------------------------------------------------------------- * + * copyright (C) 2010 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/** + * @file ctlike.hpp + * @brief CTA maximum likelihood tool definition + * @author J. Knodlseder + */ + +#ifndef CTLIKE_HPP +#define CTLIKE_HPP + +/* __ Includes ___________________________________________________________ */ +#include "GammaLib.hpp" +#include "GCTALib.hpp" + +/* __Definitions _________________________________________________________ */ +#define CTLIKE_NAME "ctlike" +#define CTLIKE_VERSION "v1r0p0" + + +/***********************************************************************//** + * @class ctlike + * + * @brief CTA maximum likelihood tool interface defintion. + ***************************************************************************/ +class ctlike : public GApplication { +public: + // Constructors and destructors + ctlike(void) : + GApplication(CTLIKE_NAME, CTLIKE_VERSION) { return; } + ctlike(int argc, char *argv[]) : + GApplication(CTLIKE_NAME, CTLIKE_VERSION, argc, argv) { return; } + + // Methods + int run(void); + int unbinned(void); + int binned(void); +}; + +#endif /* CTLIKE_HPP */ diff --git a/src/ctlike/ctlike.par b/src/ctlike/ctlike.par new file mode 100644 index 0000000..cad202e --- /dev/null +++ b/src/ctlike/ctlike.par @@ -0,0 +1,39 @@ +############################################################################# +# # +# Centre d'Etude Spatiale des Rayonnements # +# # +# CTA Science Analysis Tools # +# # +# ------------------------------------------------------------------------- # +# # +# File: ctlike.par # +# Version: v1r0p0 # +# # +# Author: Jurgen Knodlseder # +# knodlseder@cesr.fr # +# CESR # +# # +# Purpose: Parameter file for the ctlike application # +# # +############################################################################# +# +# Unbinned analysis +#================== +evfile, f, a, "../gammalib/inst/cta/test/data/run_00006028_eventlist_reco.fits.gz",,,"Event data file name" +# +# Binned analysis +#================== +cntmap, f, a, "../gammalib/inst/cta/test/data/run_00006028_cntmap.fits.gz",,, "Counts map" +# +# General parameters +#=================== +method, s, a, "UNBINNED",,, "Maximum likelihood method" +caldb, s, a, "../gammalib/inst/cta/test/irf",,, "Calibration database" +irf, s, a, "kb_E_50h_v3",,, "Instrument response function" +# +# Standard parameters +#==================== +chatter, i, h, 1,0,4, "Chattiness of output" +clobber, b, h, yes,,, "Overwrite existing output files with new output files?" +debug, b, h, no,,, "Debugging mode activated" +mode, s, h, "ql",,, "Mode of automatic parameters" diff --git a/src/ctlike/main.cpp b/src/ctlike/main.cpp new file mode 100644 index 0000000..587c900 --- /dev/null +++ b/src/ctlike/main.cpp @@ -0,0 +1,43 @@ +/*************************************************************************** + * ctlike - CTA maximum likelihood tool main code * + * ----------------------------------------------------------------------- * + * copyright (C) 2010 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/** + * @file main.cpp + * @brief CTA maximum likelihood tool main code + * @author J. Knodlseder + */ + +/* __ Includes ___________________________________________________________ */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include "ctlike.hpp" + + +/***********************************************************************//** + * @brief Main entry point + * + * @param[in] argc Number of arguments + * @param[in] argv Arguments + ***************************************************************************/ +int main (int argc, char *argv[]) +{ + // Create instance of application + ctlike application(argc, argv); + + // Run application + int rc = application.run(); + + // Return + return rc; +} diff --git a/src/ctselect/main.cpp b/src/ctselect/main.cpp new file mode 100644 index 0000000..e15f63c --- /dev/null +++ b/src/ctselect/main.cpp @@ -0,0 +1,43 @@ +/*************************************************************************** + * ctselect - CTA data selection tool main code * + * ----------------------------------------------------------------------- * + * copyright (C) 2010 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/** + * @file ctselect.cpp + * @brief CTA data selection tool main code + * @author J. Knodlseder + */ + +/* __ Includes ___________________________________________________________ */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include "ctselect.hpp" + + +/***********************************************************************//** + * @brief Main entry point + * + * @param[in] argc Number of arguments + * @param[in] argv Arguments + ***************************************************************************/ +int main (int argc, char *argv[]) +{ + // Create instance of application + ctselect application(argc, argv); + + // Run application + int rc = application.run(); + + // Return + return rc; +} -- libgit2 0.21.4