Commit cb1f36d63e87932a766efc4c42c66f0579290eaa

Authored by knodlseder
1 parent 0e711992

initial version

pyext/ctlike.i 0 → 100644
  1 +/***************************************************************************
  2 + * ctlike - CTA maximum likelihood tool *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file ctlike.i
  15 + * @brief CTA maximum likelihood tool SWIG definition
  16 + * @author J. Knodlseder
  17 + */
  18 +%{
  19 +/* Put headers and other declarations here that are needed for compilation */
  20 +#include "ctlike.hpp"
  21 +%}
  22 +%include gammalib.i
  23 +
  24 +
  25 +/***********************************************************************//**
  26 + * @class ctlike
  27 + *
  28 + * @brief CTA maximum likelihood tool SWIG interface defintion.
  29 + ***************************************************************************/
  30 +class ctlike : public GApplication {
  31 +public:
  32 + // Constructors and destructors
  33 + ctlike(void) : GApplication(CTLIKE_NAME, CTLIKE_VERSION) { return; }
  34 +
  35 + // Methods
  36 + int run(void);
  37 +};
  38 +
  39 +
  40 +/***********************************************************************//**
  41 + * @brief CTA maximum likelihood tool SWIG extension
  42 + ***************************************************************************/
  43 +%extend ctlike {
  44 + ctlike copy() {
  45 + return (*self);
  46 + }
  47 +}
... ...
src/ctbin/main.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * ctbin - CTA data binning main code *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file main.cpp
  15 + * @brief CTA data binning tool main code
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#ifdef HAVE_CONFIG_H
  21 +#include <config.h>
  22 +#endif
  23 +#include <stdio.h>
  24 +#include "ctbin.hpp"
  25 +
  26 +
  27 +/***********************************************************************//**
  28 + * @brief Main entry point of application
  29 + *
  30 + * @param[in] argc Number of command line arguments.
  31 + * @param[in] argv Command line arguments.
  32 + *
  33 + * This is the main entry point of the gtbin application. It allocates a
  34 + * ctbin object and runs the application.
  35 + ***************************************************************************/
  36 +int main (int argc, char *argv[])
  37 +{
  38 + // Create instance of application
  39 + ctbin application(argc, argv);
  40 +
  41 + // Run application
  42 + int rc = application.run();
  43 +
  44 + // Return
  45 + return rc;
  46 +}
... ...
src/ctlike/Makefile.am 0 → 100644
  1 +## Process this file with automake to produce Makefile.in
  2 +
  3 +# we use srcdir/src for "private" includes
  4 +# we use srcdir/include for the static global include files
  5 +# we use builddir/src for the generated include files to get found
  6 +
  7 +# Include directories
  8 +INCLUDES = -I$(top_srcdir)/include \
  9 + -I$(top_builddir)/src \
  10 + -I$(top_srcdir)/src
  11 +
  12 +# Program name
  13 +bin_PROGRAMS = ctlike
  14 +
  15 +# Sources
  16 +sources = ctlike.cpp
  17 +
  18 +# Program definition
  19 +ctlike_SOURCES = main.cpp $(sources)
  20 +ctlike_LDFLAGS = @LDFLAGS@
  21 +ctlike_CPPFLAGS = @CPPFLAGS@
  22 +
  23 +# Parameter files
  24 +pfilesdir = $(prefix)/syspfiles
  25 +pfiles_DATA = ctlike.par
  26 +
  27 +# Libtool library (only needed for python bindings)
  28 +noinst_LTLIBRARIES = libctlike.la
  29 +libctlike_la_SOURCES = $(sources)
... ...
src/ctlike/ctlike.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * ctlike - CTA maximum likelihood tool *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file ctlike.cpp
  15 + * @brief CTA maximum likelihood tool implementation
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#ifdef HAVE_CONFIG_H
  21 +#include <config.h>
  22 +#endif
  23 +#include <stdio.h>
  24 +#include "ctlike.hpp"
  25 +#include "GTools.hpp"
  26 +
  27 +
  28 +/***********************************************************************//**
  29 + * @brief Setup Crab point source powerlaw model.
  30 + ***************************************************************************/
  31 +GModels crab_plaw(void)
  32 +{
  33 + // Setup GModels for optimizing
  34 + GModelSpatialPtsrc point_source;
  35 + GModelSpectralPlaw power_law;
  36 + GModel crab;
  37 + GModels models;
  38 + try {
  39 + GSkyDir dir;
  40 + //dir.radec_deg(83.6331, +22.0145);
  41 + dir.radec_deg(117.0, -33.0); // Adapt to source position in file
  42 + point_source = GModelSpatialPtsrc(dir);
  43 + power_law = GModelSpectralPlaw(1.0e-7, -2.1);
  44 + power_law.par(0)->min(1.0e-12);
  45 + crab = GModel(point_source, power_law);
  46 + crab.name("Crab");
  47 + models.append(crab);
  48 + }
  49 + catch (std::exception &e) {
  50 + std::cout << std::endl
  51 + << "TEST ERROR: Unable setup GModels for optimizing."
  52 + << std::endl;
  53 + std::cout << e.what() << std::endl;
  54 + throw;
  55 + }
  56 +
  57 + // Return model
  58 + return models;
  59 +}
  60 +
  61 +
  62 +/***********************************************************************//**
  63 + * @brief Run maximum likelihood analysis
  64 + ***************************************************************************/
  65 +int ctlike::run(void)
  66 +{
  67 + // Initialise return code
  68 + int rc = 0;
  69 +
  70 + // Branch on method
  71 + std::string method = par("method")->value();
  72 + if (toupper(method) == "UNBINNED")
  73 + rc = unbinned();
  74 + else
  75 + rc = binned();
  76 +
  77 + // Return
  78 + return rc;
  79 +}
  80 +
  81 +
  82 +/***********************************************************************//**
  83 + * @brief Perform unbinned maximum likelihood analysis
  84 + ***************************************************************************/
  85 +int ctlike::unbinned(void)
  86 +{
  87 + // Initialise return code
  88 + int rc = 0;
  89 +
  90 + // Get parameters
  91 + std::string evfile = par("evfile")->value();
  92 + std::string caldb = par("caldb")->value();
  93 + std::string irf = par("irf")->value();
  94 +
  95 + // Declare observations
  96 + GObservations obs;
  97 + GCTAObservation run;
  98 +
  99 + // Setup ROI covered by data
  100 + GCTAInstDir instDir;
  101 + GCTARoi roi;
  102 + instDir.radec_deg(117.02, -33.35); // Adapt to file
  103 + roi.centre(instDir);
  104 + roi.radius(2.5);
  105 +
  106 + // Setup energy range covered by data
  107 + GEnergy emin;
  108 + GEnergy emax;
  109 + emin.TeV(0.02);
  110 + emax.TeV(100.0);
  111 +
  112 + // Setup time range covered by data
  113 + GTime tstart;
  114 + GTime tstop;
  115 + tstart.met(0.0);
  116 + tstop.met(10000.0);
  117 +
  118 + // Load data and response and set ROI, energy range and time range
  119 + // for analysis
  120 + run.load_unbinned(evfile);
  121 + run.response(irf,caldb);
  122 + run.roi(roi);
  123 + run.gti()->add(tstart, tstop);
  124 + run.ebounds()->append(emin, emax);
  125 + obs.append(run);
  126 +
  127 + // Setup GModels for optimizing
  128 + GModels models = crab_plaw();
  129 + obs.models(models);
  130 +
  131 + // Perform LM optimization
  132 + GOptimizerLM opt;
  133 + opt.max_iter(1000);
  134 + obs.optimize(opt);
  135 + std::cout << obs << std::endl;
  136 +
  137 + // Return
  138 + return rc;
  139 +}
  140 +
  141 +
  142 +/***********************************************************************//**
  143 + * @brief Perform binned maximum likelihood analysis
  144 + ***************************************************************************/
  145 +int ctlike::binned(void)
  146 +{
  147 + // Initialise return code
  148 + int rc = 0;
  149 +
  150 + // Get parameters
  151 + std::string cntmap = par("cntmap")->value();
  152 + std::string caldb = par("caldb")->value();
  153 + std::string irf = par("irf")->value();
  154 +
  155 + // Declare observations
  156 + GObservations obs;
  157 + GCTAObservation run;
  158 +
  159 + // Load binned CTA observation
  160 + run.load_binned(cntmap);
  161 + run.response(irf,caldb);
  162 + obs.append(run);
  163 +
  164 + // Setup GModels for optimizing
  165 + GModels models = crab_plaw();
  166 + obs.models(models);
  167 +
  168 + // Perform LM optimization
  169 + GOptimizerLM opt;
  170 + opt.max_iter(1000);
  171 + obs.optimize(opt);
  172 + std::cout << obs << std::endl;
  173 +
  174 + // Return
  175 + return rc;
  176 +}
... ...
src/ctlike/ctlike.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * ctlike - CTA maximum likelihood tool *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file ctlike.hpp
  15 + * @brief CTA maximum likelihood tool definition
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +#ifndef CTLIKE_HPP
  20 +#define CTLIKE_HPP
  21 +
  22 +/* __ Includes ___________________________________________________________ */
  23 +#include "GammaLib.hpp"
  24 +#include "GCTALib.hpp"
  25 +
  26 +/* __Definitions _________________________________________________________ */
  27 +#define CTLIKE_NAME "ctlike"
  28 +#define CTLIKE_VERSION "v1r0p0"
  29 +
  30 +
  31 +/***********************************************************************//**
  32 + * @class ctlike
  33 + *
  34 + * @brief CTA maximum likelihood tool interface defintion.
  35 + ***************************************************************************/
  36 +class ctlike : public GApplication {
  37 +public:
  38 + // Constructors and destructors
  39 + ctlike(void) :
  40 + GApplication(CTLIKE_NAME, CTLIKE_VERSION) { return; }
  41 + ctlike(int argc, char *argv[]) :
  42 + GApplication(CTLIKE_NAME, CTLIKE_VERSION, argc, argv) { return; }
  43 +
  44 + // Methods
  45 + int run(void);
  46 + int unbinned(void);
  47 + int binned(void);
  48 +};
  49 +
  50 +#endif /* CTLIKE_HPP */
... ...
src/ctlike/ctlike.par 0 → 100644
  1 +#############################################################################
  2 +# #
  3 +# Centre d'Etude Spatiale des Rayonnements #
  4 +# #
  5 +# CTA Science Analysis Tools #
  6 +# #
  7 +# ------------------------------------------------------------------------- #
  8 +# #
  9 +# File: ctlike.par #
  10 +# Version: v1r0p0 #
  11 +# #
  12 +# Author: Jurgen Knodlseder #
  13 +# knodlseder@cesr.fr #
  14 +# CESR #
  15 +# #
  16 +# Purpose: Parameter file for the ctlike application #
  17 +# #
  18 +#############################################################################
  19 +#
  20 +# Unbinned analysis
  21 +#==================
  22 +evfile, f, a, "../gammalib/inst/cta/test/data/run_00006028_eventlist_reco.fits.gz",,,"Event data file name"
  23 +#
  24 +# Binned analysis
  25 +#==================
  26 +cntmap, f, a, "../gammalib/inst/cta/test/data/run_00006028_cntmap.fits.gz",,, "Counts map"
  27 +#
  28 +# General parameters
  29 +#===================
  30 +method, s, a, "UNBINNED",,, "Maximum likelihood method"
  31 +caldb, s, a, "../gammalib/inst/cta/test/irf",,, "Calibration database"
  32 +irf, s, a, "kb_E_50h_v3",,, "Instrument response function"
  33 +#
  34 +# Standard parameters
  35 +#====================
  36 +chatter, i, h, 1,0,4, "Chattiness of output"
  37 +clobber, b, h, yes,,, "Overwrite existing output files with new output files?"
  38 +debug, b, h, no,,, "Debugging mode activated"
  39 +mode, s, h, "ql",,, "Mode of automatic parameters"
... ...
src/ctlike/main.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * ctlike - CTA maximum likelihood tool main code *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file main.cpp
  15 + * @brief CTA maximum likelihood tool main code
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#ifdef HAVE_CONFIG_H
  21 +#include <config.h>
  22 +#endif
  23 +#include <stdio.h>
  24 +#include "ctlike.hpp"
  25 +
  26 +
  27 +/***********************************************************************//**
  28 + * @brief Main entry point
  29 + *
  30 + * @param[in] argc Number of arguments
  31 + * @param[in] argv Arguments
  32 + ***************************************************************************/
  33 +int main (int argc, char *argv[])
  34 +{
  35 + // Create instance of application
  36 + ctlike application(argc, argv);
  37 +
  38 + // Run application
  39 + int rc = application.run();
  40 +
  41 + // Return
  42 + return rc;
  43 +}
... ...
src/ctselect/main.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * ctselect - CTA data selection tool main code *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file ctselect.cpp
  15 + * @brief CTA data selection tool main code
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#ifdef HAVE_CONFIG_H
  21 +#include <config.h>
  22 +#endif
  23 +#include <stdio.h>
  24 +#include "ctselect.hpp"
  25 +
  26 +
  27 +/***********************************************************************//**
  28 + * @brief Main entry point
  29 + *
  30 + * @param[in] argc Number of arguments
  31 + * @param[in] argv Arguments
  32 + ***************************************************************************/
  33 +int main (int argc, char *argv[])
  34 +{
  35 + // Create instance of application
  36 + ctselect application(argc, argv);
  37 +
  38 + // Run application
  39 + int rc = application.run();
  40 +
  41 + // Return
  42 + return rc;
  43 +}
... ...