Commit 8140e337613ed3f1fdfe15f5980a41ae28e4dd98
1 parent
c496e8e7
new implementation using logger and separate methods
Showing
4 changed files
with
223 additions
and
44 deletions
pyext/ctbin.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * ctbin - CTA data binning tool * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010 by Jurgen Knodlseder * | |
| 4 | + * copyright (C) 2010-2011 by Jurgen Knodlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software; you can redistribute it and/or modify * |
| ... | ... | @@ -30,10 +30,14 @@ |
| 30 | 30 | class ctbin : public GApplication { |
| 31 | 31 | public: |
| 32 | 32 | // Constructors and destructors |
| 33 | - ctbin(void) : GApplication(CTBIN_NAME, CTBIN_VERSION) { return; } | |
| 33 | + ctbin(void); | |
| 34 | + ctbin(int argc, char *argv[]); | |
| 35 | + ~ctbin(void); | |
| 34 | 36 | |
| 35 | 37 | // Methods |
| 36 | - int run(void); | |
| 38 | + void run(void); | |
| 39 | + void get_parameters(void); | |
| 40 | + void bin(void); | |
| 37 | 41 | }; |
| 38 | 42 | |
| 39 | 43 | ... | ... |
src/ctbin/ctbin.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * ctbin - CTA data binning tool * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010 by Jurgen Knodlseder * | |
| 4 | + * copyright (C) 2010-2011 by Jurgen Knodlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software; you can redistribute it and/or modify * |
| ... | ... | @@ -24,36 +24,142 @@ |
| 24 | 24 | #include "ctbin.hpp" |
| 25 | 25 | #include "GTools.hpp" |
| 26 | 26 | |
| 27 | +/* __ Debug definitions __________________________________________________ */ | |
| 28 | + | |
| 29 | +/* __ Coding definitions _________________________________________________ */ | |
| 30 | + | |
| 31 | + | |
| 32 | +/*========================================================================== | |
| 33 | + = = | |
| 34 | + = Constructors/destructors = | |
| 35 | + = = | |
| 36 | + ==========================================================================*/ | |
| 37 | + | |
| 38 | +/***********************************************************************//** | |
| 39 | + * @brief Void constructor | |
| 40 | + ***************************************************************************/ | |
| 41 | +ctbin::ctbin(void) : GApplication(CTBIN_NAME, CTBIN_VERSION) | |
| 42 | +{ | |
| 43 | + // Initialise members | |
| 44 | + init_members(); | |
| 45 | + | |
| 46 | + // Write header into logger | |
| 47 | + log_header(); | |
| 48 | + | |
| 49 | + // Return | |
| 50 | + return; | |
| 51 | +} | |
| 52 | + | |
| 53 | + | |
| 54 | +/***********************************************************************//** | |
| 55 | + * @brief Command line constructor | |
| 56 | + * | |
| 57 | + * @param[in] argc Number of arguments in command line. | |
| 58 | + * @param[in] argv Array of command line arguments. | |
| 59 | + ***************************************************************************/ | |
| 60 | +ctbin::ctbin(int argc, char *argv[]) : | |
| 61 | + GApplication(CTBIN_NAME, CTBIN_VERSION, argc, argv) | |
| 62 | +{ | |
| 63 | + // Initialise members | |
| 64 | + init_members(); | |
| 65 | + | |
| 66 | + // Write header into logger | |
| 67 | + log_header(); | |
| 68 | + | |
| 69 | + // Return | |
| 70 | + return; | |
| 71 | +} | |
| 72 | + | |
| 73 | + | |
| 74 | +/***********************************************************************//** | |
| 75 | + * @brief Destructor | |
| 76 | + ***************************************************************************/ | |
| 77 | +ctbin::~ctbin(void) | |
| 78 | +{ | |
| 79 | + // Free members | |
| 80 | + free_members(); | |
| 81 | + | |
| 82 | + // Return | |
| 83 | + return; | |
| 84 | +} | |
| 85 | + | |
| 86 | + | |
| 87 | +/*========================================================================== | |
| 88 | + = = | |
| 89 | + = Operators = | |
| 90 | + = = | |
| 91 | + ==========================================================================*/ | |
| 92 | + | |
| 93 | +/*========================================================================== | |
| 94 | + = = | |
| 95 | + = Public methods = | |
| 96 | + = = | |
| 97 | + ==========================================================================*/ | |
| 27 | 98 | |
| 28 | 99 | /***********************************************************************//** |
| 29 | 100 | * @brief Run gtbin application |
| 30 | 101 | ***************************************************************************/ |
| 31 | -int ctbin::run(void) | |
| 102 | +void ctbin::run(void) | |
| 32 | 103 | { |
| 33 | - // Test dump | |
| 34 | - std::cout << *this << std::endl; | |
| 104 | + // Get parameters | |
| 105 | + get_parameters(); | |
| 35 | 106 | |
| 36 | - // Get events and output file names | |
| 37 | - std::string evfile = par("evfile")->value(); | |
| 38 | - std::string outfile = par("outfile")->value(); | |
| 39 | - | |
| 40 | - // Get clobber | |
| 41 | - std::string sclobber = par("clobber")->value(); | |
| 42 | - int clobber = 0; | |
| 43 | - if (tolower(sclobber) == "yes") | |
| 44 | - clobber = 1; | |
| 107 | + // Write parameters into logger | |
| 108 | + if (logTerse()) { | |
| 109 | + log_parameters(); | |
| 110 | + log << std::endl; | |
| 111 | + } | |
| 112 | + | |
| 113 | + // Bin data | |
| 114 | + bin(); | |
| 45 | 115 | |
| 116 | + // Return | |
| 117 | + return; | |
| 118 | +} | |
| 119 | + | |
| 120 | + | |
| 121 | +/***********************************************************************//** | |
| 122 | + * @brief Get application parameters | |
| 123 | + * | |
| 124 | + * Get all task parameters from parameter file or (if required) by querying | |
| 125 | + * the user. | |
| 126 | + ***************************************************************************/ | |
| 127 | +void ctbin::get_parameters(void) | |
| 128 | +{ | |
| 129 | + // Get parameters | |
| 130 | + m_evfile = par("evfile")->value(); | |
| 131 | + m_outfile = par("outfile")->value(); | |
| 132 | + m_emin = par("emin")->real(); | |
| 133 | + m_emax = par("emax")->real(); | |
| 134 | + m_enumbins = par("enumbins")->integer(); | |
| 135 | + m_proj = par("proj")->value(); | |
| 136 | + m_coordsys = par("coordsys")->value(); | |
| 137 | + m_xref = par("xref")->real(); | |
| 138 | + m_yref = par("yref")->real(); | |
| 139 | + m_binsz = par("binsz")->real(); | |
| 140 | + m_nxpix = par("nxpix")->integer(); | |
| 141 | + m_nypix = par("nypix")->integer(); | |
| 142 | + | |
| 143 | + // Return | |
| 144 | + return; | |
| 145 | +} | |
| 146 | + | |
| 147 | + | |
| 148 | +/***********************************************************************//** | |
| 149 | + * @brief Run gtbin application | |
| 150 | + ***************************************************************************/ | |
| 151 | +void ctbin::bin(void) | |
| 152 | +{ | |
| 46 | 153 | // Load events as unbinned data |
| 47 | 154 | GCTAObservation obs; |
| 48 | - obs.load_unbinned(evfile); | |
| 155 | + obs.load_unbinned(m_evfile); | |
| 49 | 156 | |
| 50 | 157 | // Setup energy range covered by data |
| 51 | 158 | GEnergy emin; |
| 52 | 159 | GEnergy emax; |
| 53 | - emin.TeV(todouble(par("emin")->value())); | |
| 54 | - emax.TeV(todouble(par("emax")->value())); | |
| 55 | - int enumbins = toint(par("enumbins")->value()); | |
| 56 | - obs.ebounds()->setlog(emin, emax, enumbins); | |
| 160 | + emin.TeV(m_emin); | |
| 161 | + emax.TeV(m_emax); | |
| 162 | + obs.ebounds()->setlog(emin, emax, m_enumbins); | |
| 57 | 163 | |
| 58 | 164 | // Setup time range covered by data |
| 59 | 165 | GTime tstart; |
| ... | ... | @@ -62,18 +168,17 @@ int ctbin::run(void) |
| 62 | 168 | tstop.met(10000.0); |
| 63 | 169 | obs.gti()->add(tstart, tstop); |
| 64 | 170 | |
| 65 | - std::cout << obs; | |
| 66 | - | |
| 171 | + // Log observation | |
| 172 | + if (logExplicit()) { | |
| 173 | + log << std::endl; | |
| 174 | + log.header1("Observation"); | |
| 175 | + log << obs << std::endl; | |
| 176 | + } | |
| 177 | + | |
| 67 | 178 | // Create skymap |
| 68 | - std::string wcs = par("proj")->value(); | |
| 69 | - std::string coords = par("coordsys")->value(); | |
| 70 | - double x = todouble(par("xref")->value()); | |
| 71 | - double y = todouble(par("yref")->value()); | |
| 72 | - double dx = todouble(par("binsz")->value()); | |
| 73 | - double dy = todouble(par("binsz")->value()); | |
| 74 | - int nx = toint(par("nxpix")->value()); | |
| 75 | - int ny = toint(par("nypix")->value()); | |
| 76 | - GSkymap map = GSkymap(wcs, coords, x, y, dx, dy, nx, ny, enumbins); | |
| 179 | + GSkymap map = GSkymap(m_proj, m_coordsys, | |
| 180 | + m_xref, m_yref, m_binsz, m_binsz, | |
| 181 | + m_nxpix, m_nypix, m_enumbins); | |
| 77 | 182 | |
| 78 | 183 | // Fill sky map |
| 79 | 184 | GCTAEventList* events = (GCTAEventList*)obs.events(); |
| ... | ... | @@ -85,8 +190,8 @@ int ctbin::run(void) |
| 85 | 190 | GSkyPixel pixel = map.dir2xy(dir); |
| 86 | 191 | |
| 87 | 192 | // Skip if pixel is out of range |
| 88 | - if (pixel.x() < -0.5 || pixel.x() > (nx-0.5) || | |
| 89 | - pixel.y() < -0.5 || pixel.y() > (ny-0.5)) | |
| 193 | + if (pixel.x() < -0.5 || pixel.x() > (m_nxpix-0.5) || | |
| 194 | + pixel.y() < -0.5 || pixel.y() > (m_nypix-0.5)) | |
| 90 | 195 | continue; |
| 91 | 196 | |
| 92 | 197 | // Determine energy bin. Skip if we are outside the energy range |
| ... | ... | @@ -99,15 +204,65 @@ int ctbin::run(void) |
| 99 | 204 | |
| 100 | 205 | } // endfor: looped over all events |
| 101 | 206 | |
| 102 | - std::cout << map; | |
| 207 | + // Log observation | |
| 208 | + if (logTerse()) { | |
| 209 | + log << std::endl; | |
| 210 | + log.header1("Counts map"); | |
| 211 | + log << map << std::endl; | |
| 212 | + } | |
| 103 | 213 | |
| 104 | 214 | // Save counts map |
| 105 | 215 | GFits file; |
| 106 | 216 | map.write(&file); |
| 107 | 217 | obs.ebounds()->write(&file); |
| 108 | 218 | obs.gti()->write(&file); |
| 109 | - file.saveto(outfile, clobber); | |
| 219 | + file.saveto(m_outfile, clobber()); | |
| 220 | + | |
| 221 | + // Return | |
| 222 | + return; | |
| 223 | +} | |
| 224 | + | |
| 225 | + | |
| 226 | +/*========================================================================== | |
| 227 | + = = | |
| 228 | + = Private methods = | |
| 229 | + = = | |
| 230 | + ==========================================================================*/ | |
| 231 | + | |
| 232 | +/***********************************************************************//** | |
| 233 | + * @brief Initialise class members | |
| 234 | + ***************************************************************************/ | |
| 235 | +void ctbin::init_members(void) | |
| 236 | +{ | |
| 237 | + // Initialise members | |
| 238 | + m_evfile.clear(); | |
| 239 | + m_outfile.clear(); | |
| 240 | + m_emin = 0.0; | |
| 241 | + m_emax = 0.0; | |
| 242 | + m_enumbins = 0; | |
| 243 | + m_proj.clear(); | |
| 244 | + m_coordsys.clear(); | |
| 245 | + m_xref = 0.0; | |
| 246 | + m_yref = 0.0; | |
| 247 | + m_binsz = 0.0; | |
| 248 | + m_nxpix = 0; | |
| 249 | + m_nypix = 0; | |
| 250 | + | |
| 251 | + // Set logger properties | |
| 252 | + log.date(true); | |
| 253 | + | |
| 254 | + // Return | |
| 255 | + return; | |
| 256 | +} | |
| 257 | + | |
| 258 | + | |
| 259 | +/***********************************************************************//** | |
| 260 | + * @brief Delete class members | |
| 261 | + ***************************************************************************/ | |
| 262 | +void ctbin::free_members(void) | |
| 263 | +{ | |
| 264 | + // Free members | |
| 110 | 265 | |
| 111 | 266 | // Return |
| 112 | - return 0; | |
| 267 | + return; | |
| 113 | 268 | } | ... | ... |
src/ctbin/ctbin.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * ctbin - CTA data binning tool * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010 by Jurgen Knodlseder * | |
| 4 | + * copyright (C) 2010-2011 by Jurgen Knodlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software; you can redistribute it and/or modify * |
| ... | ... | @@ -36,13 +36,33 @@ |
| 36 | 36 | class ctbin : public GApplication { |
| 37 | 37 | public: |
| 38 | 38 | // Constructors and destructors |
| 39 | - ctbin(void) : | |
| 40 | - GApplication(CTBIN_NAME, CTBIN_VERSION) { return; } | |
| 41 | - ctbin(int argc, char *argv[]) : | |
| 42 | - GApplication(CTBIN_NAME, CTBIN_VERSION, argc, argv) { return; } | |
| 39 | + ctbin(void); | |
| 40 | + ctbin(int argc, char *argv[]); | |
| 41 | + ~ctbin(void); | |
| 43 | 42 | |
| 44 | 43 | // Methods |
| 45 | - int run(void); | |
| 44 | + void run(void); | |
| 45 | + void get_parameters(void); | |
| 46 | + void bin(void); | |
| 47 | + | |
| 48 | +protected: | |
| 49 | + // Protected methods | |
| 50 | + void init_members(void); | |
| 51 | + void free_members(void); | |
| 52 | + | |
| 53 | + // User parameters | |
| 54 | + std::string m_evfile; //!< Input event list | |
| 55 | + std::string m_outfile; //!< Output counts map | |
| 56 | + double m_emin; //!< Lower energy | |
| 57 | + double m_emax; //!< Upper energy | |
| 58 | + int m_enumbins; //!< Number of energy bins | |
| 59 | + std::string m_proj; //!< WCS projection | |
| 60 | + std::string m_coordsys; //!< Coordinate system | |
| 61 | + double m_xref; //!< Longitude reference coordinate | |
| 62 | + double m_yref; //!< Latitude reference coordinate | |
| 63 | + double m_binsz; //!< Pixel size | |
| 64 | + int m_nxpix; //!< Number of pixels in longitude | |
| 65 | + int m_nypix; //!< Number of pixels in latitude | |
| 46 | 66 | }; |
| 47 | 67 | |
| 48 | 68 | #endif /* CTBIN_HPP */ | ... | ... |
src/ctbin/main.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * ctbin - CTA data binning main code * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010 by Jurgen Knodlseder * | |
| 4 | + * copyright (C) 2010-2011 by Jurgen Knodlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software; you can redistribute it and/or modify * | ... | ... |