Commit 7c0b7939f9d8e23e3a94ca4cc0aae86904c52995
1 parent
4a0642aa
Reconsider calibration database handling.
Instead of passing a string providing the calibration database path, the GCTAObservation and GCTAResponse classes now take a GCaldb object. This allows for a more flexible handling and selection of response functions through passing the corresponding calibration database object. The rmffile member and method has become obsolete in GCTAResponse, so it was deleted. Now everything is handled by the GCTAEdisp class.
Showing
7 changed files
with
169 additions
and
126 deletions
inst/cta/include/GCTAObservation.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCTAObservation.hpp - CTA Observation class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2014 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -38,6 +38,7 @@ class GTime; |
| 38 | 38 | class GFitsHDU; |
| 39 | 39 | class GResponse; |
| 40 | 40 | class GXmlElement; |
| 41 | +class GCaldb; | |
| 41 | 42 | |
| 42 | 43 | |
| 43 | 44 | /***********************************************************************//** |
| ... | ... | @@ -77,8 +78,8 @@ public: |
| 77 | 78 | void load_binned(const std::string& filename); |
| 78 | 79 | void save(const std::string& filename, |
| 79 | 80 | const bool& clobber = false) const; |
| 80 | - void response(const std::string& irfname, | |
| 81 | - const std::string& caldb = ""); | |
| 81 | + void response(const std::string& rspname, | |
| 82 | + const GCaldb& caldb); | |
| 82 | 83 | void pointing(const GCTAPointing& pointing); |
| 83 | 84 | const GCTAPointing& pointing(void) const; |
| 84 | 85 | void obs_id(const int& id); |
| ... | ... | @@ -117,6 +118,8 @@ protected: |
| 117 | 118 | |
| 118 | 119 | /***********************************************************************//** |
| 119 | 120 | * @brief Return CTA response function |
| 121 | + * | |
| 122 | + * @return Response function. | |
| 120 | 123 | ***************************************************************************/ |
| 121 | 124 | inline |
| 122 | 125 | const GCTAResponse& GCTAObservation::response(void) const |
| ... | ... | @@ -126,7 +129,9 @@ const GCTAResponse& GCTAObservation::response(void) const |
| 126 | 129 | |
| 127 | 130 | |
| 128 | 131 | /***********************************************************************//** |
| 129 | - * @brief Return instrument | |
| 132 | + * @brief Return instrument name | |
| 133 | + * | |
| 134 | + * @return Instrument name. | |
| 130 | 135 | ***************************************************************************/ |
| 131 | 136 | inline |
| 132 | 137 | std::string GCTAObservation::instrument(void) const |
| ... | ... | @@ -137,6 +142,8 @@ std::string GCTAObservation::instrument(void) const |
| 137 | 142 | |
| 138 | 143 | /***********************************************************************//** |
| 139 | 144 | * @brief Return ontime |
| 145 | + * | |
| 146 | + * @return Ontime in seconds. | |
| 140 | 147 | ***************************************************************************/ |
| 141 | 148 | inline |
| 142 | 149 | double GCTAObservation::ontime(void) const |
| ... | ... | @@ -147,6 +154,8 @@ double GCTAObservation::ontime(void) const |
| 147 | 154 | |
| 148 | 155 | /***********************************************************************//** |
| 149 | 156 | * @brief Return livetime |
| 157 | + * | |
| 158 | + * @return Livetime in seconds. | |
| 150 | 159 | ***************************************************************************/ |
| 151 | 160 | inline |
| 152 | 161 | double GCTAObservation::livetime(void) const |
| ... | ... | @@ -156,7 +165,13 @@ double GCTAObservation::livetime(void) const |
| 156 | 165 | |
| 157 | 166 | |
| 158 | 167 | /***********************************************************************//** |
| 159 | - * @brief Return deadtime | |
| 168 | + * @brief Return deadtime correction factor | |
| 169 | + * | |
| 170 | + * @param[in] time Time. | |
| 171 | + * @return Deadtime correction factor. | |
| 172 | + * | |
| 173 | + * Returns the deadtime correction factor as function of time. The deadtime | |
| 174 | + * correction factor is defined by the livetime divided by the ontime. | |
| 160 | 175 | ***************************************************************************/ |
| 161 | 176 | inline |
| 162 | 177 | double GCTAObservation::deadc(const GTime& time) const |
| ... | ... | @@ -166,7 +181,9 @@ double GCTAObservation::deadc(const GTime& time) const |
| 166 | 181 | |
| 167 | 182 | |
| 168 | 183 | /***********************************************************************//** |
| 169 | - * @brief Return CTA pointing direction | |
| 184 | + * @brief Return CTA pointing | |
| 185 | + * | |
| 186 | + * @return CTA pointing | |
| 170 | 187 | ***************************************************************************/ |
| 171 | 188 | inline |
| 172 | 189 | const GCTAPointing& GCTAObservation::pointing(void) const |
| ... | ... | @@ -176,9 +193,9 @@ const GCTAPointing& GCTAObservation::pointing(void) const |
| 176 | 193 | |
| 177 | 194 | |
| 178 | 195 | /***********************************************************************//** |
| 179 | - * @brief Set CTA pointing direction | |
| 196 | + * @brief Set CTA pointing | |
| 180 | 197 | * |
| 181 | - * @param[in] pointing Pointing. | |
| 198 | + * @param[in] pointing CTA pointing. | |
| 182 | 199 | ***************************************************************************/ |
| 183 | 200 | inline |
| 184 | 201 | void GCTAObservation::pointing(const GCTAPointing& pointing) | ... | ... |
inst/cta/include/GCTAResponse.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCTAResponse.hpp - CTA Response class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2014 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -33,6 +33,7 @@ |
| 33 | 33 | #include "GEnergy.hpp" |
| 34 | 34 | #include "GTime.hpp" |
| 35 | 35 | #include "GResponse.hpp" |
| 36 | +#include "GCaldb.hpp" | |
| 36 | 37 | |
| 37 | 38 | /* __ Type definitions ___________________________________________________ */ |
| 38 | 39 | |
| ... | ... | @@ -63,7 +64,7 @@ public: |
| 63 | 64 | // Constructors and destructors |
| 64 | 65 | GCTAResponse(void); |
| 65 | 66 | GCTAResponse(const GCTAResponse& rsp); |
| 66 | - GCTAResponse(const std::string& rspname, const std::string& caldb = ""); | |
| 67 | + GCTAResponse(const std::string& rspname, const GCaldb& caldb); | |
| 67 | 68 | virtual ~GCTAResponse(void); |
| 68 | 69 | |
| 69 | 70 | // Operators |
| ... | ... | @@ -101,12 +102,11 @@ public: |
| 101 | 102 | // Other Methods |
| 102 | 103 | GCTAEventAtom* mc(const double& area, const GPhoton& photon, |
| 103 | 104 | const GObservation& obs, GRan& ran) const; |
| 104 | - void caldb(const std::string& caldb); | |
| 105 | - const std::string& caldb(void) const; | |
| 105 | + void caldb(const GCaldb& caldb); | |
| 106 | + const GCaldb& caldb(void) const; | |
| 106 | 107 | void load(const std::string& rspname); |
| 107 | 108 | void eps(const double& eps); |
| 108 | 109 | const double& eps(void) const; |
| 109 | - const std::string& rmffile(void) const; | |
| 110 | 110 | void load_aeff(const std::string& filename); |
| 111 | 111 | void load_psf(const std::string& filename); |
| 112 | 112 | void load_edisp(const std::string& filename); |
| ... | ... | @@ -166,15 +166,15 @@ private: |
| 166 | 166 | const GObservation& obs) const; |
| 167 | 167 | const GCTAInstDir& retrieve_dir(const std::string& origin, |
| 168 | 168 | const GEvent& event) const; |
| 169 | + std::string irf_filename(const std::string& filename) const; | |
| 169 | 170 | |
| 170 | 171 | // Private data members |
| 171 | - std::string m_caldb; //!< Name of or path to the calibration database | |
| 172 | - std::string m_rspname; //!< Name of the instrument response | |
| 173 | - std::string m_rmffile; //!< Name of RMF file | |
| 174 | - double m_eps; //!< Integration precision | |
| 175 | - GCTAAeff* m_aeff; //!< Effective area | |
| 176 | - GCTAPsf* m_psf; //!< Point spread function | |
| 177 | - GCTAEdisp* m_edisp; //!< Energy dispersion | |
| 172 | + GCaldb m_caldb; //!< Calibration database | |
| 173 | + std::string m_rspname; //!< Name of the instrument response | |
| 174 | + double m_eps; //!< Integration precision | |
| 175 | + GCTAAeff* m_aeff; //!< Effective area | |
| 176 | + GCTAPsf* m_psf; //!< Point spread function | |
| 177 | + GCTAEdisp* m_edisp; //!< Energy dispersion | |
| 178 | 178 | |
| 179 | 179 | // Npred cache |
| 180 | 180 | mutable std::vector<std::string> m_npred_names; //!< Model names |
| ... | ... | @@ -214,46 +214,49 @@ bool GCTAResponse::has_tdisp(void) const |
| 214 | 214 | * @return Calibration database. |
| 215 | 215 | ***************************************************************************/ |
| 216 | 216 | inline |
| 217 | -const std::string& GCTAResponse::caldb(void) const | |
| 217 | +const GCaldb& GCTAResponse::caldb(void) const | |
| 218 | 218 | { |
| 219 | 219 | return m_caldb; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | |
| 223 | 223 | /***********************************************************************//** |
| 224 | - * @brief Set computation precision | |
| 224 | + * @brief Set path to the calibration database | |
| 225 | 225 | * |
| 226 | - * @param[in] eps Computation precision. | |
| 226 | + * @param[in] caldb Calibration database. | |
| 227 | + * | |
| 228 | + * Sets the calibration database for the CTA response. | |
| 227 | 229 | ***************************************************************************/ |
| 228 | 230 | inline |
| 229 | -void GCTAResponse::eps(const double& eps) | |
| 231 | +void GCTAResponse::caldb(const GCaldb& caldb) | |
| 230 | 232 | { |
| 231 | - m_eps = eps; | |
| 233 | + m_caldb = caldb; | |
| 232 | 234 | return; |
| 233 | 235 | } |
| 234 | 236 | |
| 235 | 237 | |
| 236 | 238 | /***********************************************************************//** |
| 237 | - * @brief Return computation precision | |
| 239 | + * @brief Set computation precision | |
| 238 | 240 | * |
| 239 | - * @return Computation precision. | |
| 241 | + * @param[in] eps Computation precision. | |
| 240 | 242 | ***************************************************************************/ |
| 241 | 243 | inline |
| 242 | -const double& GCTAResponse::eps(void) const | |
| 244 | +void GCTAResponse::eps(const double& eps) | |
| 243 | 245 | { |
| 244 | - return m_eps; | |
| 246 | + m_eps = eps; | |
| 247 | + return; | |
| 245 | 248 | } |
| 246 | 249 | |
| 247 | 250 | |
| 248 | 251 | /***********************************************************************//** |
| 249 | - * @brief Return Redistribution Matrix File name | |
| 252 | + * @brief Return computation precision | |
| 250 | 253 | * |
| 251 | - * @return Redistribution Matrix File name. | |
| 254 | + * @return Computation precision. | |
| 252 | 255 | ***************************************************************************/ |
| 253 | 256 | inline |
| 254 | -const std::string& GCTAResponse::rmffile(void) const | |
| 257 | +const double& GCTAResponse::eps(void) const | |
| 255 | 258 | { |
| 256 | - return m_rmffile; | |
| 259 | + return m_eps; | |
| 257 | 260 | } |
| 258 | 261 | |
| 259 | 262 | ... | ... |
inst/cta/pyext/GCTAObservation.i
| 1 | 1 | /*************************************************************************** |
| 2 | - * GCTAObservation.i - CTA Observation class interface * | |
| 2 | + * GCTAObservation.i - CTA Observation class interface * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2012 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2014 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file GCTAObservation.i |
| 23 | - * @brief CTA observation class Python interface definition | |
| 23 | + * @brief CTA observation interface definition | |
| 24 | 24 | * @author Juergen Knoedlseder |
| 25 | 25 | */ |
| 26 | 26 | %{ |
| ... | ... | @@ -32,7 +32,7 @@ |
| 32 | 32 | /***********************************************************************//** |
| 33 | 33 | * @class GCTAObservation |
| 34 | 34 | * |
| 35 | - * @brief CTA observation class Python interface | |
| 35 | + * @brief CTA observation class | |
| 36 | 36 | ***************************************************************************/ |
| 37 | 37 | class GCTAObservation : public GObservation { |
| 38 | 38 | public: |
| ... | ... | @@ -59,8 +59,8 @@ public: |
| 59 | 59 | void load_binned(const std::string& filename); |
| 60 | 60 | void save(const std::string& filename, |
| 61 | 61 | const bool& clobber = false) const; |
| 62 | - void response(const std::string& irfname, | |
| 63 | - const std::string& caldb = ""); | |
| 62 | + void response(const std::string& rspname, | |
| 63 | + const GCaldb& caldb); | |
| 64 | 64 | void pointing(const GCTAPointing& pointing); |
| 65 | 65 | const GCTAPointing& pointing(void) const; |
| 66 | 66 | void obs_id(const int& id); | ... | ... |
inst/cta/pyext/GCTAResponse.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCTAResponse.i - CTA instrument response function class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2014 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -39,7 +39,7 @@ public: |
| 39 | 39 | // Constructors and destructors |
| 40 | 40 | GCTAResponse(void); |
| 41 | 41 | GCTAResponse(const GCTAResponse& rsp); |
| 42 | - GCTAResponse(const std::string& rspname, const std::string& caldb = ""); | |
| 42 | + GCTAResponse(const std::string& rspname, const GCaldb& caldb); | |
| 43 | 43 | virtual ~GCTAResponse(void); |
| 44 | 44 | |
| 45 | 45 | // Implement pure virtual base class methods |
| ... | ... | @@ -68,12 +68,11 @@ public: |
| 68 | 68 | // Other Methods |
| 69 | 69 | GCTAEventAtom* mc(const double& area, const GPhoton& photon, |
| 70 | 70 | const GObservation& obs, GRan& ran) const; |
| 71 | - void caldb(const std::string& caldb); | |
| 72 | - const std::string& caldb(void) const; | |
| 71 | + void caldb(const GCaldb& caldb); | |
| 72 | + const GCaldb& caldb(void) const; | |
| 73 | 73 | void load(const std::string& rspname); |
| 74 | 74 | void eps(const double& eps); |
| 75 | 75 | const double& eps(void) const; |
| 76 | - const std::string& rmffile(void) const; | |
| 77 | 76 | void load_aeff(const std::string& filename); |
| 78 | 77 | void load_psf(const std::string& filename); |
| 79 | 78 | void load_edisp(const std::string& filename); | ... | ... |
inst/cta/src/GCTAObservation.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCTAObservation.cpp - CTA Observation class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2014 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -43,6 +43,7 @@ |
| 43 | 43 | #include "GCTAAeff2D.hpp" |
| 44 | 44 | #include "GCTAAeffArf.hpp" |
| 45 | 45 | #include "GCTAAeffPerfTable.hpp" |
| 46 | +#include "GCTAEdisp.hpp" | |
| 46 | 47 | |
| 47 | 48 | /* __ Globals ____________________________________________________________ */ |
| 48 | 49 | const GCTAObservation g_obs_cta_seed("CTA"); |
| ... | ... | @@ -75,7 +76,7 @@ const GObservationRegistry g_obs_veritas_registry(&g_obs_veritas_seed); |
| 75 | 76 | /***********************************************************************//** |
| 76 | 77 | * @brief Void constructor |
| 77 | 78 | * |
| 78 | - * Creates empty class instance. | |
| 79 | + * Creates an empty CTA observation. | |
| 79 | 80 | ***************************************************************************/ |
| 80 | 81 | GCTAObservation::GCTAObservation(void) : GObservation() |
| 81 | 82 | { |
| ... | ... | @@ -95,7 +96,8 @@ GCTAObservation::GCTAObservation(void) : GObservation() |
| 95 | 96 | * Creates empty CTA observation class for a given instrument. This enables |
| 96 | 97 | * using the CTA specific interface for any other THE instrument. Note that |
| 97 | 98 | * each other THE instruments needs a specific registry at the beginning |
| 98 | - * of the GCTAObservation.cpp file. | |
| 99 | + * of the GCTAObservation.cpp file. So far the following instruments are | |
| 100 | + * supported: CTA, HESS, VERITAS, MAGIC. | |
| 99 | 101 | ***************************************************************************/ |
| 100 | 102 | GCTAObservation::GCTAObservation(const std::string& instrument) : GObservation() |
| 101 | 103 | { |
| ... | ... | @@ -115,7 +117,7 @@ GCTAObservation::GCTAObservation(const std::string& instrument) : GObservation() |
| 115 | 117 | * |
| 116 | 118 | * @param[in] obs CTA observation. |
| 117 | 119 | * |
| 118 | - * Creates class instance by copying an existing CTA observation. | |
| 120 | + * Creates CTA observation by copying an existing CTA observation. | |
| 119 | 121 | ***************************************************************************/ |
| 120 | 122 | GCTAObservation::GCTAObservation(const GCTAObservation& obs) : GObservation(obs) |
| 121 | 123 | { |
| ... | ... | @@ -156,7 +158,7 @@ GCTAObservation::~GCTAObservation(void) |
| 156 | 158 | * |
| 157 | 159 | * Assign CTA observation to this object. |
| 158 | 160 | ***************************************************************************/ |
| 159 | -GCTAObservation& GCTAObservation::operator= (const GCTAObservation& obs) | |
| 161 | +GCTAObservation& GCTAObservation::operator=(const GCTAObservation& obs) | |
| 160 | 162 | { |
| 161 | 163 | // Execute only if object is not identical |
| 162 | 164 | if (this != &obs) { |
| ... | ... | @@ -187,7 +189,7 @@ GCTAObservation& GCTAObservation::operator= (const GCTAObservation& obs) |
| 187 | 189 | ==========================================================================*/ |
| 188 | 190 | |
| 189 | 191 | /***********************************************************************//** |
| 190 | - * @brief Clear instance | |
| 192 | + * @brief Clear CTA observation | |
| 191 | 193 | ***************************************************************************/ |
| 192 | 194 | void GCTAObservation::clear(void) |
| 193 | 195 | { |
| ... | ... | @@ -205,8 +207,10 @@ void GCTAObservation::clear(void) |
| 205 | 207 | |
| 206 | 208 | |
| 207 | 209 | /***********************************************************************//** |
| 208 | - * @brief Clone instance | |
| 209 | -***************************************************************************/ | |
| 210 | + * @brief Clone CTA observation | |
| 211 | + * | |
| 212 | + * @return Pointer to deep copy of CTA observation. | |
| 213 | + ***************************************************************************/ | |
| 210 | 214 | GCTAObservation* GCTAObservation::clone(void) const |
| 211 | 215 | { |
| 212 | 216 | return new GCTAObservation(*this); |
| ... | ... | @@ -243,11 +247,14 @@ void GCTAObservation::response(const GResponse& rsp) |
| 243 | 247 | /***********************************************************************//** |
| 244 | 248 | * @brief Set CTA response function |
| 245 | 249 | * |
| 246 | - * @param[in] irfname Name of CTA response function. | |
| 247 | - * @param[in] caldb Optional name of calibration database (defaults to ""). | |
| 250 | + * @param[in] rspname Response name. | |
| 251 | + * @param[in] caldb Calibration database. | |
| 252 | + * | |
| 253 | + * Sets the CTA response function by specifying a response name and a | |
| 254 | + * calibration database. This method also loads the response function so that | |
| 255 | + * it is available for data analysis. | |
| 248 | 256 | ***************************************************************************/ |
| 249 | -void GCTAObservation::response(const std::string& irfname, | |
| 250 | - const std::string& caldb) | |
| 257 | +void GCTAObservation::response(const std::string& rspname, const GCaldb& caldb) | |
| 251 | 258 | { |
| 252 | 259 | // Clear response function |
| 253 | 260 | m_response.clear(); |
| ... | ... | @@ -256,7 +263,7 @@ void GCTAObservation::response(const std::string& irfname, |
| 256 | 263 | m_response.caldb(caldb); |
| 257 | 264 | |
| 258 | 265 | // Load instrument response function |
| 259 | - m_response.load(irfname); | |
| 266 | + m_response.load(rspname); | |
| 260 | 267 | |
| 261 | 268 | // Return |
| 262 | 269 | return; |
| ... | ... | @@ -605,7 +612,9 @@ void GCTAObservation::write(GXmlElement& xml) const |
| 605 | 612 | // Handle RMF |
| 606 | 613 | else if (par->attribute("name") == "EnergyDispersion") { |
| 607 | 614 | std::string filename = ""; |
| 608 | - filename = m_response.rmffile(); | |
| 615 | + if (m_response.edisp() != NULL) { | |
| 616 | + filename = m_response.edisp()->filename(); | |
| 617 | + } | |
| 609 | 618 | par->attribute("file", filename); |
| 610 | 619 | npar[3]++; |
| 611 | 620 | } | ... | ... |
inst/cta/src/GCTAResponse.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCTAResponse.cpp - CTA Response class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2014 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -59,7 +59,7 @@ |
| 59 | 59 | #include "GCTAEdisp.hpp" |
| 60 | 60 | |
| 61 | 61 | /* __ Method name definitions ____________________________________________ */ |
| 62 | -#define G_CALDB "GCTAResponse::caldb(std::string&)" | |
| 62 | +#define G_CALDB "GCTAResponse::caldb(GCaldb&)" | |
| 63 | 63 | #define G_IRF "GCTAResponse::irf(GInstDir&, GEnergy&, GTime&, GSkyDir&,"\ |
| 64 | 64 | " GEnergy&, GTime&, GObservation&)" |
| 65 | 65 | #define G_NPRED "GCTAResponse::npred(GSkyDir&, GEnergy&, GTime&,"\ |
| ... | ... | @@ -144,27 +144,23 @@ GCTAResponse::GCTAResponse(const GCTAResponse& rsp) : GResponse(rsp) |
| 144 | 144 | * @brief Response constructor |
| 145 | 145 | * |
| 146 | 146 | * @param[in] rspname Response file name. |
| 147 | - * @param[in] caldb Calibration database path (defaults to ""). | |
| 147 | + * @param[in] caldb Calibration database. | |
| 148 | 148 | * |
| 149 | - * Create instance of a CTA response object by specifying the response file | |
| 150 | - * name and the calibration database path. | |
| 151 | - * | |
| 152 | - * If an empty string is passed as calibration database path, the method will | |
| 153 | - * use the CALDB environment variable to determine calibration database path. | |
| 154 | - * This is done in the method GCTAResponse::caldb which makes use of a | |
| 155 | - * GCaldb object to locate the calibration database. | |
| 149 | + * Create instance of CTA response by specifying the response name and the | |
| 150 | + * calibration database. The response name can be either a response identifier | |
| 151 | + * or a filename (see GCTAResponse::load for more information). | |
| 156 | 152 | ***************************************************************************/ |
| 157 | 153 | GCTAResponse::GCTAResponse(const std::string& rspname, |
| 158 | - const std::string& caldb) : GResponse() | |
| 154 | + const GCaldb& caldb) : GResponse() | |
| 159 | 155 | { |
| 160 | 156 | // Initialise members |
| 161 | 157 | init_members(); |
| 162 | 158 | |
| 163 | 159 | // Set calibration database |
| 164 | - this->caldb(caldb); | |
| 160 | + m_caldb = caldb; | |
| 165 | 161 | |
| 166 | 162 | // Load IRF |
| 167 | - this->load(rspname); | |
| 163 | + load(rspname); | |
| 168 | 164 | |
| 169 | 165 | // Return |
| 170 | 166 | return; |
| ... | ... | @@ -513,56 +509,49 @@ GCTAEventAtom* GCTAResponse::mc(const double& area, const GPhoton& photon, |
| 513 | 509 | |
| 514 | 510 | |
| 515 | 511 | /***********************************************************************//** |
| 516 | - * @brief Set path to the calibration database | |
| 512 | + * @brief Load CTA response | |
| 517 | 513 | * |
| 518 | - * @param[in] caldb Path to calibration database | |
| 519 | - * | |
| 520 | - * This method stores the CALDB root directory as the path to the CTA | |
| 521 | - * calibration database. Once the final calibration format has been decided | |
| 522 | - * on, this method should be adjusted. | |
| 523 | - ***************************************************************************/ | |
| 524 | -void GCTAResponse::caldb(const std::string& caldb) | |
| 525 | -{ | |
| 526 | - // Allocate calibration database | |
| 527 | - GCaldb db(caldb); | |
| 528 | - | |
| 529 | - // Store the path to the calibration database | |
| 530 | - m_caldb = db.dir(); | |
| 531 | - | |
| 532 | - // Return | |
| 533 | - return; | |
| 534 | -} | |
| 535 | - | |
| 536 | - | |
| 537 | -/***********************************************************************//** | |
| 538 | - * @brief Load CTA response. | |
| 514 | + * @param[in] rspname CTA response name. | |
| 539 | 515 | * |
| 540 | - * @param[in] irfname Name of CTA response (without any file extension). | |
| 516 | + * Loads the CTA response with specified name @p rspname. The method first | |
| 517 | + * searchs for an appropriate response in the calibration database. If no | |
| 518 | + * appropriate response is found, the method takes the database root path | |
| 519 | + * and response name to build the full path to the response file, and tries | |
| 520 | + * to load the response from these paths. | |
| 541 | 521 | ***************************************************************************/ |
| 542 | -void GCTAResponse::load(const std::string& irfname) | |
| 522 | +void GCTAResponse::load(const std::string& rspname) | |
| 543 | 523 | { |
| 544 | - // Save calibration database name | |
| 545 | - std::string caldb = m_caldb; | |
| 546 | - | |
| 547 | - // Clear instance | |
| 524 | + // Clear instance but conserve calibration database | |
| 525 | + GCaldb caldb = m_caldb; | |
| 548 | 526 | clear(); |
| 549 | - | |
| 550 | - // Restore calibration database name | |
| 551 | 527 | m_caldb = caldb; |
| 552 | 528 | |
| 553 | - // Build filename. If file is not a FITS file then add ".dat" extension | |
| 554 | - // which is typical for a performance table. | |
| 555 | - std::string filename = m_caldb + "/" + irfname; | |
| 556 | - if (irfname.rfind(".fits") == std::string::npos && | |
| 557 | - irfname.rfind(".fits.gz") == std::string::npos) { | |
| 558 | - filename += ".dat"; | |
| 529 | + // First attempt reading the response using the GCaldb interface | |
| 530 | + std::string expr = "NAME("+gammalib::toupper(rspname)+")"; | |
| 531 | + std::string aeffname = m_caldb.filename("","","EFF_AREA","","",expr); | |
| 532 | + std::string psfname = m_caldb.filename("","","RPSF","","",expr); | |
| 533 | + std::string edispname = m_caldb.filename("","","EDISP","","",expr); | |
| 534 | + | |
| 535 | + // If filenames are empty then build filenames from CALDB root path and | |
| 536 | + // response name | |
| 537 | + if (aeffname.length() < 1) { | |
| 538 | + aeffname = irf_filename(m_caldb.dir() + "/" + rspname); | |
| 539 | + } | |
| 540 | + if (psfname.length() < 1) { | |
| 541 | + psfname = irf_filename(m_caldb.dir() + "/" + rspname); | |
| 542 | + } | |
| 543 | + if (edispname.length() < 1) { | |
| 544 | + edispname = irf_filename(m_caldb.dir() + "/" + rspname); | |
| 559 | 545 | } |
| 560 | 546 | |
| 561 | 547 | // Load effective area |
| 562 | - load_aeff(filename); | |
| 548 | + load_aeff(aeffname); | |
| 563 | 549 | |
| 564 | 550 | // Load point spread function |
| 565 | - load_psf(filename); | |
| 551 | + load_psf(psfname); | |
| 552 | + | |
| 553 | + // Load energy dispersion | |
| 554 | + load_edisp(edispname); | |
| 566 | 555 | |
| 567 | 556 | // Remove theta cut |
| 568 | 557 | GCTAAeffArf* arf = const_cast<GCTAAeffArf*>(dynamic_cast<const GCTAAeffArf*>(m_aeff)); |
| ... | ... | @@ -571,7 +560,7 @@ void GCTAResponse::load(const std::string& irfname) |
| 571 | 560 | } |
| 572 | 561 | |
| 573 | 562 | // Store response name |
| 574 | - m_rspname = irfname; | |
| 563 | + m_rspname = rspname; | |
| 575 | 564 | |
| 576 | 565 | // Return |
| 577 | 566 | return; |
| ... | ... | @@ -801,9 +790,10 @@ std::string GCTAResponse::print(const GChatter& chatter) const |
| 801 | 790 | result.append("=== GCTAResponse ==="); |
| 802 | 791 | |
| 803 | 792 | // Append response information |
| 804 | - result.append("\n"+gammalib::parformat("Calibration database")+m_caldb); | |
| 805 | 793 | result.append("\n"+gammalib::parformat("Response name")+m_rspname); |
| 806 | - result.append("\n"+gammalib::parformat("RMF file name")+m_rmffile); | |
| 794 | + | |
| 795 | + // Append calibration database | |
| 796 | + result.append("\n"+m_caldb.print(gammalib::reduce(chatter))); | |
| 807 | 797 | |
| 808 | 798 | // Append effective area information |
| 809 | 799 | if (m_aeff != NULL) { |
| ... | ... | @@ -2166,7 +2156,6 @@ void GCTAResponse::init_members(void) |
| 2166 | 2156 | // Initialise members |
| 2167 | 2157 | m_caldb.clear(); |
| 2168 | 2158 | m_rspname.clear(); |
| 2169 | - m_rmffile.clear(); | |
| 2170 | 2159 | m_eps = 1.0e-5; // Precision for Romberg integration |
| 2171 | 2160 | m_aeff = NULL; |
| 2172 | 2161 | m_psf = NULL; |
| ... | ... | @@ -2193,7 +2182,6 @@ void GCTAResponse::copy_members(const GCTAResponse& rsp) |
| 2193 | 2182 | // Copy members |
| 2194 | 2183 | m_caldb = rsp.m_caldb; |
| 2195 | 2184 | m_rspname = rsp.m_rspname; |
| 2196 | - m_rmffile = rsp.m_rmffile; | |
| 2197 | 2185 | m_eps = rsp.m_eps; |
| 2198 | 2186 | |
| 2199 | 2187 | // Copy cache |
| ... | ... | @@ -2344,3 +2332,30 @@ const GCTAInstDir& GCTAResponse::retrieve_dir(const std::string& origin, |
| 2344 | 2332 | return *dir; |
| 2345 | 2333 | } |
| 2346 | 2334 | |
| 2335 | + | |
| 2336 | +/***********************************************************************//** | |
| 2337 | + * @brief Return filename with appropriate extension | |
| 2338 | + * | |
| 2339 | + * @param[in] filename File name. | |
| 2340 | + * @return File name. | |
| 2341 | + * | |
| 2342 | + * Checks if the specified @p filename exists, and if not, checks whether a | |
| 2343 | + * file with the added suffix .dat exists. Returns the file name with the | |
| 2344 | + * appropriate extension. | |
| 2345 | + ***************************************************************************/ | |
| 2346 | +std::string GCTAResponse::irf_filename(const std::string& filename) const | |
| 2347 | +{ | |
| 2348 | + // Set input filename as result filename | |
| 2349 | + std::string result = filename; | |
| 2350 | + | |
| 2351 | + // If file does not exist then try a variant with extension .dat | |
| 2352 | + if (!gammalib::file_exists(result)) { | |
| 2353 | + std::string testname = result + ".dat"; | |
| 2354 | + if (gammalib::file_exists(testname)) { | |
| 2355 | + result = testname; | |
| 2356 | + } | |
| 2357 | + } | |
| 2358 | + | |
| 2359 | + // Return result | |
| 2360 | + return result; | |
| 2361 | +} | ... | ... |
inst/cta/test/test_CTA.cpp
| ... | ... | @@ -181,7 +181,7 @@ void TestGCTAResponse::test_response_aeff(void) |
| 181 | 181 | { |
| 182 | 182 | // Load response |
| 183 | 183 | GCTAResponse rsp; |
| 184 | - rsp.caldb(cta_caldb); | |
| 184 | + rsp.caldb(GCaldb(cta_caldb)); | |
| 185 | 185 | rsp.load(cta_irf); |
| 186 | 186 | |
| 187 | 187 | // Sum over effective area for control |
| ... | ... | @@ -213,7 +213,7 @@ void TestGCTAResponse::test_response_psf(void) |
| 213 | 213 | { |
| 214 | 214 | // Load response |
| 215 | 215 | GCTAResponse rsp; |
| 216 | - rsp.caldb(cta_caldb); | |
| 216 | + rsp.caldb(GCaldb(cta_caldb)); | |
| 217 | 217 | rsp.load(cta_irf); |
| 218 | 218 | |
| 219 | 219 | // Integrate Psf |
| ... | ... | @@ -250,7 +250,7 @@ void TestGCTAResponse::test_response_psf_king(void) |
| 250 | 250 | { |
| 251 | 251 | // Load response |
| 252 | 252 | GCTAResponse rsp; |
| 253 | - rsp.caldb(cta_caldb_king); | |
| 253 | + rsp.caldb(GCaldb(cta_caldb_king)); | |
| 254 | 254 | rsp.load(cta_irf_king); |
| 255 | 255 | |
| 256 | 256 | // Integrate Psf |
| ... | ... | @@ -283,7 +283,7 @@ void TestGCTAResponse::test_response_npsf(void) |
| 283 | 283 | { |
| 284 | 284 | // Setup CTA response |
| 285 | 285 | GCTAResponse rsp; |
| 286 | - rsp.caldb(cta_caldb); | |
| 286 | + rsp.caldb(GCaldb(cta_caldb)); | |
| 287 | 287 | rsp.load(cta_irf); |
| 288 | 288 | |
| 289 | 289 | // Setup npsf computation |
| ... | ... | @@ -371,7 +371,7 @@ void TestGCTAResponse::test_response_irf_diffuse(void) |
| 371 | 371 | obs.ontime(1800.0); |
| 372 | 372 | obs.livetime(1600.0); |
| 373 | 373 | obs.deadc(1600.0/1800.0); |
| 374 | - obs.response(cta_irf, cta_caldb); | |
| 374 | + obs.response(cta_irf, GCaldb(cta_caldb)); | |
| 375 | 375 | obs.events(cube); |
| 376 | 376 | obs.pointing(pnt); |
| 377 | 377 | |
| ... | ... | @@ -453,7 +453,7 @@ void TestGCTAResponse::test_response_npred_diffuse(void) |
| 453 | 453 | obs.ontime(1800.0); |
| 454 | 454 | obs.livetime(1600.0); |
| 455 | 455 | obs.deadc(1600.0/1800.0); |
| 456 | - obs.response(cta_irf, cta_caldb); | |
| 456 | + obs.response(cta_irf, GCaldb(cta_caldb)); | |
| 457 | 457 | obs.events(events); |
| 458 | 458 | obs.pointing(pnt); |
| 459 | 459 | |
| ... | ... | @@ -481,7 +481,7 @@ void TestGCTAResponse::test_response(void) |
| 481 | 481 | try { |
| 482 | 482 | // Load response |
| 483 | 483 | GCTAResponse rsp; |
| 484 | - rsp.caldb(cta_caldb); | |
| 484 | + rsp.caldb(GCaldb(cta_caldb)); | |
| 485 | 485 | rsp.load(cta_irf); |
| 486 | 486 | test_try_success(); |
| 487 | 487 | } |
| ... | ... | @@ -558,7 +558,7 @@ void TestGCTAModelBackground::test_modelbg_npred(void) |
| 558 | 558 | obs.ontime(1800.0); |
| 559 | 559 | obs.livetime(1800.0); |
| 560 | 560 | obs.deadc(1.0); |
| 561 | - obs.response(cta_irf, cta_caldb); | |
| 561 | + obs.response(cta_irf, GCaldb(cta_caldb)); | |
| 562 | 562 | obs.events(events); |
| 563 | 563 | obs.pointing(pnt); |
| 564 | 564 | |
| ... | ... | @@ -593,7 +593,7 @@ void TestGCTAObservation::test_unbinned_obs(void) |
| 593 | 593 | test_try("Load unbinned CTA observation"); |
| 594 | 594 | try { |
| 595 | 595 | run.load_unbinned(cta_events); |
| 596 | - run.response(cta_irf,cta_caldb); | |
| 596 | + run.response(cta_irf, GCaldb(cta_caldb)); | |
| 597 | 597 | test_try_success(); |
| 598 | 598 | } |
| 599 | 599 | catch (std::exception &e) { |
| ... | ... | @@ -654,7 +654,7 @@ void TestGCTAObservation::test_binned_obs(void) |
| 654 | 654 | test_try("Load unbinned CTA observation"); |
| 655 | 655 | try { |
| 656 | 656 | run.load_binned(cta_cntmap); |
| 657 | - run.response(cta_irf,cta_caldb); | |
| 657 | + run.response(cta_irf, GCaldb(cta_caldb)); | |
| 658 | 658 | test_try_success(); |
| 659 | 659 | } |
| 660 | 660 | catch (std::exception &e) { |
| ... | ... | @@ -691,7 +691,7 @@ void TestGCTAOptimize::test_unbinned_optimizer(void) |
| 691 | 691 | test_try("Load unbinned CTA observation"); |
| 692 | 692 | try { |
| 693 | 693 | run.load_unbinned(cta_events); |
| 694 | - run.response(cta_irf,cta_caldb); | |
| 694 | + run.response(cta_irf, GCaldb(cta_caldb)); | |
| 695 | 695 | obs.append(run); |
| 696 | 696 | test_try_success(); |
| 697 | 697 | } |
| ... | ... | @@ -753,7 +753,7 @@ void TestGCTAOptimize::test_binned_optimizer(void) |
| 753 | 753 | test_try("Load binned CTA observation"); |
| 754 | 754 | try { |
| 755 | 755 | run.load_binned(cta_cntmap); |
| 756 | - run.response(cta_irf,cta_caldb); | |
| 756 | + run.response(cta_irf, GCaldb(cta_caldb)); | |
| 757 | 757 | obs.append(run); |
| 758 | 758 | test_try_success(); |
| 759 | 759 | } | ... | ... |