diff --git a/src/ctbin/Makefile.am b/src/ctbin/Makefile.am new file mode 100644 index 0000000..fb6a06f --- /dev/null +++ b/src/ctbin/Makefile.am @@ -0,0 +1,18 @@ +## 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 + +INCLUDES = -I$(top_srcdir)/include \ + -I$(top_builddir)/src \ + -I$(top_srcdir)/src + +bin_PROGRAMS = ctbin + +ctbin_SOURCES = ctbin.cpp +ctbin_LDFLAGS = @LDFLAGS@ +ctbin_CPPFLAGS = @CPPFLAGS@ + +pfilesdir = $(prefix)/syspfiles +pfiles_DATA = ctbin.par diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp new file mode 100644 index 0000000..f0f7efa --- /dev/null +++ b/src/ctbin/ctbin.cpp @@ -0,0 +1,134 @@ +/*************************************************************************** + * ctbin - CTA data binning 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 ctbin.cpp + * @brief CTA data binning tool implementation + * @author J. Knodlseder + */ + +/* __ Includes ___________________________________________________________ */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include "ctbin.hpp" +#include "GTools.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; +} + + +/***********************************************************************//** + * @brief Run gtbin application + ***************************************************************************/ +int ctbin::run(void) +{ + // Test dump + std::cout << *this << std::endl; + + // Get events and output file names + std::string evfile = par("evfile")->value(); + std::string outfile = par("outfile")->value(); + + // Get clobber + std::string sclobber = par("clobber")->value(); + int clobber = 0; + if (tolower(sclobber) == "yes") + clobber = 1; + + // Load events as unbinned data + GCTAObservation obs; + obs.load_unbinned(evfile); + + // Setup energy range covered by data + GEnergy emin; + GEnergy emax; + emin.TeV(todouble(par("emin")->value())); + emax.TeV(todouble(par("emax")->value())); + int enumbins = toint(par("enumbins")->value()); + obs.ebounds()->setlog(emin, emax, enumbins); + + // Setup time range covered by data + GTime tstart; + GTime tstop; + tstart.met(0.0); + tstop.met(10000.0); + obs.gti()->add(tstart, tstop); + + std::cout << obs; + + // Create skymap + std::string wcs = par("proj")->value(); + std::string coords = par("coordsys")->value(); + double x = todouble(par("xref")->value()); + double y = todouble(par("yref")->value()); + double dx = todouble(par("binsz")->value()); + double dy = todouble(par("binsz")->value()); + int nx = toint(par("nxpix")->value()); + int ny = toint(par("nypix")->value()); + GSkymap map = GSkymap(wcs, coords, x, y, dx, dy, nx, ny, enumbins); + + // Fill sky map + GCTAEventList* events = (GCTAEventList*)obs.events(); + for (GCTAEventList::iterator event = events->begin(); event != events->end(); ++event) { + + // Determine sky pixel + GSkyDir dir = ((GCTAInstDir*)event->dir())->skydir(); + GSkyPixel pixel = map.dir2xy(dir); + + // Skip if pixel is out of range + if (pixel.x() < -0.5 || pixel.x() > (nx-0.5) || + pixel.y() < -0.5 || pixel.y() > (ny-0.5)) + continue; + + // Determine energy bin. Skip if we are outside the energy range + int index = obs.ebounds()->index(*(event->energy())); + if (index == -1) + continue; + + // Fill event in skymap + map(pixel, index) += 1.0; + + } // endfor: looped over all events + + std::cout << map; + + // Save counts map + GFits file; + map.write(&file); + obs.ebounds()->write(&file); + obs.gti()->write(&file); + file.saveto(outfile, clobber); + + // Return + return 0; +} \ No newline at end of file diff --git a/src/ctbin/ctbin.hpp b/src/ctbin/ctbin.hpp new file mode 100644 index 0000000..54b6375 --- /dev/null +++ b/src/ctbin/ctbin.hpp @@ -0,0 +1,46 @@ +/*************************************************************************** + * ctbin - CTA data binning 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 ctbin.hpp + * @brief CTA data binning tool definition + * @author J. Knodlseder + */ + +#ifndef CTBIN_HPP +#define CTBIN_HPP + +/* __ Includes ___________________________________________________________ */ +#include "GammaLib.hpp" +#include "GCTALib.hpp" + +/* __Definitions _________________________________________________________ */ +#define APP_NAME "ctbin" +#define APP_VERSION "v1r0p0" + + +/***********************************************************************//** + * @class ctbin + * + * @brief CTA data binning tool interface defintion. + ***************************************************************************/ +class ctbin : public GApplication { +public: + // Constructors and destructors + ctbin(int argc, char *argv[]) : + GApplication(APP_NAME, APP_VERSION, argc, argv) { return; } + + // Methods + int run(void); +}; + +#endif /* CTBIN_HPP */ diff --git a/src/ctbin/ctbin.par b/src/ctbin/ctbin.par new file mode 100644 index 0000000..427d5b3 --- /dev/null +++ b/src/ctbin/ctbin.par @@ -0,0 +1,50 @@ +############################################################################# +# # +# Centre d'Etude Spatiale des Rayonnements # +# # +# CTA Science Analysis Tools # +# # +# ------------------------------------------------------------------------- # +# # +# File: ctbin.par # +# Version: v1r0p0 # +# # +# Author: Jurgen Knodlseder # +# knodlseder@cesr.fr # +# CESR # +# # +# Purpose: Parameter file for the ctbin application # +# # +############################################################################# +# +# General parameters +#=================== +evfile, f, a, "../gammalib/inst/cta/test/data/run_00006028_eventlist_reco.fits.gz",,,"Event data file name" +outfile, f, a, "cntmap.fits",,, "Output file name" +# +# Energy binning parameters +#========================== +ebinalg, s, a, "LOG", FILE|LIN|LOG,,"Algorithm for defining energy bins" +emin, r, a, 0.02,,,"Start value for first energy bin in TeV" +emax, r, a, 100.0,,,"Stop value for last energy bin in TeV" +enumbins, i, a, 20,,,"Number of energy bins" +ebinfile, f, a, "NONE",,,"Name of the file containing the energy bin definition" +# +# Spatial binning parameters +#=========================== +nxpix, i, a, 200,,, "Size of the X axis in pixels" +nypix, i, a, 200,,, "Size of the Y axis in pixels" +binsz, r, a, 0.02,,, "Image scale (in degrees/pixel)" +coordsys, s, a, "CEL", CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galactic)" +xref, r, a, 117.02,,, "First coordinate of image center in degrees (RA or galactic l)" +yref, r, a, -33.35,,, "Second coordinate of image center in degrees (DEC or galactic b)" +axisrot, r, a, 0.0,,, "Rotation angle of image axis, in degrees" +proj, s, a, "CAR",,, "Projection method e.g. AIT|ARC|CAR|GLS|MER|NCP|SIN|STG|TAN" + +# +# 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"