Commit 3f9b4b23f05b6b22cd3819f11cd19e2568404633

Authored by knodlseder
1 parent 5999b560

initial versions

src/ctbin/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 +INCLUDES = -I$(top_srcdir)/include \
  8 + -I$(top_builddir)/src \
  9 + -I$(top_srcdir)/src
  10 +
  11 +bin_PROGRAMS = ctbin
  12 +
  13 +ctbin_SOURCES = ctbin.cpp
  14 +ctbin_LDFLAGS = @LDFLAGS@
  15 +ctbin_CPPFLAGS = @CPPFLAGS@
  16 +
  17 +pfilesdir = $(prefix)/syspfiles
  18 +pfiles_DATA = ctbin.par
... ...
src/ctbin/ctbin.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * ctbin - CTA data binning 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 ctbin.cpp
  15 + * @brief CTA data binning 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 "ctbin.hpp"
  25 +#include "GTools.hpp"
  26 +
  27 +
  28 +/***********************************************************************//**
  29 + * @brief Main entry point of application
  30 + *
  31 + * @param[in] argc Number of command line arguments.
  32 + * @param[in] argv Command line arguments.
  33 + *
  34 + * This is the main entry point of the gtbin application. It allocates a
  35 + * ctbin object and runs the application.
  36 + ***************************************************************************/
  37 +int main (int argc, char *argv[])
  38 +{
  39 + // Create instance of application
  40 + ctbin application(argc, argv);
  41 +
  42 + // Run application
  43 + int rc = application.run();
  44 +
  45 + // Return
  46 + return rc;
  47 +}
  48 +
  49 +
  50 +/***********************************************************************//**
  51 + * @brief Run gtbin application
  52 + ***************************************************************************/
  53 +int ctbin::run(void)
  54 +{
  55 + // Test dump
  56 + std::cout << *this << std::endl;
  57 +
  58 + // Get events and output file names
  59 + std::string evfile = par("evfile")->value();
  60 + std::string outfile = par("outfile")->value();
  61 +
  62 + // Get clobber
  63 + std::string sclobber = par("clobber")->value();
  64 + int clobber = 0;
  65 + if (tolower(sclobber) == "yes")
  66 + clobber = 1;
  67 +
  68 + // Load events as unbinned data
  69 + GCTAObservation obs;
  70 + obs.load_unbinned(evfile);
  71 +
  72 + // Setup energy range covered by data
  73 + GEnergy emin;
  74 + GEnergy emax;
  75 + emin.TeV(todouble(par("emin")->value()));
  76 + emax.TeV(todouble(par("emax")->value()));
  77 + int enumbins = toint(par("enumbins")->value());
  78 + obs.ebounds()->setlog(emin, emax, enumbins);
  79 +
  80 + // Setup time range covered by data
  81 + GTime tstart;
  82 + GTime tstop;
  83 + tstart.met(0.0);
  84 + tstop.met(10000.0);
  85 + obs.gti()->add(tstart, tstop);
  86 +
  87 + std::cout << obs;
  88 +
  89 + // Create skymap
  90 + std::string wcs = par("proj")->value();
  91 + std::string coords = par("coordsys")->value();
  92 + double x = todouble(par("xref")->value());
  93 + double y = todouble(par("yref")->value());
  94 + double dx = todouble(par("binsz")->value());
  95 + double dy = todouble(par("binsz")->value());
  96 + int nx = toint(par("nxpix")->value());
  97 + int ny = toint(par("nypix")->value());
  98 + GSkymap map = GSkymap(wcs, coords, x, y, dx, dy, nx, ny, enumbins);
  99 +
  100 + // Fill sky map
  101 + GCTAEventList* events = (GCTAEventList*)obs.events();
  102 + for (GCTAEventList::iterator event = events->begin(); event != events->end(); ++event) {
  103 +
  104 + // Determine sky pixel
  105 + GSkyDir dir = ((GCTAInstDir*)event->dir())->skydir();
  106 + GSkyPixel pixel = map.dir2xy(dir);
  107 +
  108 + // Skip if pixel is out of range
  109 + if (pixel.x() < -0.5 || pixel.x() > (nx-0.5) ||
  110 + pixel.y() < -0.5 || pixel.y() > (ny-0.5))
  111 + continue;
  112 +
  113 + // Determine energy bin. Skip if we are outside the energy range
  114 + int index = obs.ebounds()->index(*(event->energy()));
  115 + if (index == -1)
  116 + continue;
  117 +
  118 + // Fill event in skymap
  119 + map(pixel, index) += 1.0;
  120 +
  121 + } // endfor: looped over all events
  122 +
  123 + std::cout << map;
  124 +
  125 + // Save counts map
  126 + GFits file;
  127 + map.write(&file);
  128 + obs.ebounds()->write(&file);
  129 + obs.gti()->write(&file);
  130 + file.saveto(outfile, clobber);
  131 +
  132 + // Return
  133 + return 0;
  134 +}
0 135 \ No newline at end of file
... ...
src/ctbin/ctbin.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * ctbin - CTA data binning 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 ctbin.hpp
  15 + * @brief CTA data binning tool definition
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +#ifndef CTBIN_HPP
  20 +#define CTBIN_HPP
  21 +
  22 +/* __ Includes ___________________________________________________________ */
  23 +#include "GammaLib.hpp"
  24 +#include "GCTALib.hpp"
  25 +
  26 +/* __Definitions _________________________________________________________ */
  27 +#define APP_NAME "ctbin"
  28 +#define APP_VERSION "v1r0p0"
  29 +
  30 +
  31 +/***********************************************************************//**
  32 + * @class ctbin
  33 + *
  34 + * @brief CTA data binning tool interface defintion.
  35 + ***************************************************************************/
  36 +class ctbin : public GApplication {
  37 +public:
  38 + // Constructors and destructors
  39 + ctbin(int argc, char *argv[]) :
  40 + GApplication(APP_NAME, APP_VERSION, argc, argv) { return; }
  41 +
  42 + // Methods
  43 + int run(void);
  44 +};
  45 +
  46 +#endif /* CTBIN_HPP */
... ...
src/ctbin/ctbin.par 0 → 100644
  1 +#############################################################################
  2 +# #
  3 +# Centre d'Etude Spatiale des Rayonnements #
  4 +# #
  5 +# CTA Science Analysis Tools #
  6 +# #
  7 +# ------------------------------------------------------------------------- #
  8 +# #
  9 +# File: ctbin.par #
  10 +# Version: v1r0p0 #
  11 +# #
  12 +# Author: Jurgen Knodlseder #
  13 +# knodlseder@cesr.fr #
  14 +# CESR #
  15 +# #
  16 +# Purpose: Parameter file for the ctbin application #
  17 +# #
  18 +#############################################################################
  19 +#
  20 +# General parameters
  21 +#===================
  22 +evfile, f, a, "../gammalib/inst/cta/test/data/run_00006028_eventlist_reco.fits.gz",,,"Event data file name"
  23 +outfile, f, a, "cntmap.fits",,, "Output file name"
  24 +#
  25 +# Energy binning parameters
  26 +#==========================
  27 +ebinalg, s, a, "LOG", FILE|LIN|LOG,,"Algorithm for defining energy bins"
  28 +emin, r, a, 0.02,,,"Start value for first energy bin in TeV"
  29 +emax, r, a, 100.0,,,"Stop value for last energy bin in TeV"
  30 +enumbins, i, a, 20,,,"Number of energy bins"
  31 +ebinfile, f, a, "NONE",,,"Name of the file containing the energy bin definition"
  32 +#
  33 +# Spatial binning parameters
  34 +#===========================
  35 +nxpix, i, a, 200,,, "Size of the X axis in pixels"
  36 +nypix, i, a, 200,,, "Size of the Y axis in pixels"
  37 +binsz, r, a, 0.02,,, "Image scale (in degrees/pixel)"
  38 +coordsys, s, a, "CEL", CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galactic)"
  39 +xref, r, a, 117.02,,, "First coordinate of image center in degrees (RA or galactic l)"
  40 +yref, r, a, -33.35,,, "Second coordinate of image center in degrees (DEC or galactic b)"
  41 +axisrot, r, a, 0.0,,, "Rotation angle of image axis, in degrees"
  42 +proj, s, a, "CAR",,, "Projection method e.g. AIT|ARC|CAR|GLS|MER|NCP|SIN|STG|TAN"
  43 +
  44 +#
  45 +# Standard parameters
  46 +#====================
  47 +chatter, i, h, 1,0,4, "Chattiness of output"
  48 +clobber, b, h, yes,,, "Overwrite existing output files with new output files?"
  49 +debug, b, h, no,,, "Debugging mode activated"
  50 +mode, s, h, "ql",,, "Mode of automatic parameters"
... ...