00001 /*************************************************************************** 00002 * GCTAOnOffObservation.hpp - CTA On/Off observation class * 00003 * ----------------------------------------------------------------------- * 00004 * copyright (C) 2013-2016 by Chia-Chun Lu & Christoph Deil * 00005 * ----------------------------------------------------------------------- * 00006 * * 00007 * This program is free software: you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation, either version 3 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00019 * * 00020 ***************************************************************************/ 00021 /** 00022 * @file GCTAOnOffObservation.hpp 00023 * @brief CTA On/Off observation class definition 00024 * @author Chia-Chun Lu & Christoph Deil 00025 */ 00026 00027 #ifndef GCTAONOFFOBSERVATION_HPP 00028 #define GCTAONOFFOBSERVATION_HPP 00029 00030 /* __ Includes ___________________________________________________________ */ 00031 #include <string> 00032 #include <vector> 00033 #include "GObservation.hpp" 00034 #include "GPha.hpp" 00035 #include "GArf.hpp" 00036 #include "GRmf.hpp" 00037 #include "GSkyRegions.hpp" 00038 00039 /* __ Forward declarations _______________________________________________ */ 00040 class GModels; 00041 class GOptimizerPars; 00042 class GCTAObservation; 00043 class GBounds; 00044 00045 00046 /***********************************************************************//** 00047 * @class GCTAOnOffObservation 00048 * 00049 * @brief CTA On/Off observation class 00050 * 00051 * This class defines a CTA On/Off observation. An On/Off observation is 00052 * defined by two spectra, one for an On region including the source of 00053 * interest, and one for an Off region including only background. The 00054 * response of an On/Off observation is given by the Auxiliary Response File 00055 * (ARF) and the Redistribution Matrix File (RMF). 00056 * 00057 * The class uses GPha objects to store the On and Off spectra, and GArf and 00058 * GRmf objects to store the response information. 00059 ***************************************************************************/ 00060 class GCTAOnOffObservation : public GObservation { 00061 00062 public: 00063 // Constructors and destructors 00064 GCTAOnOffObservation(void); 00065 GCTAOnOffObservation(const GCTAObservation& obs, 00066 const GEbounds& etrue, 00067 const GEbounds& ereco, 00068 const GSkyRegions& on, 00069 const GSkyRegions& off); 00070 GCTAOnOffObservation(const GCTAOnOffObservation& obs); 00071 virtual ~GCTAOnOffObservation(void); 00072 00073 // Operators 00074 GCTAOnOffObservation& operator=(const GCTAOnOffObservation& obs); 00075 00076 // Implemented pure virtual methods 00077 virtual void clear(void); 00078 virtual GCTAOnOffObservation* clone(void) const; 00079 virtual std::string classname(void) const; 00080 virtual void response(const GResponse& rsp); 00081 virtual const GCTAResponse* response(void) const; 00082 virtual std::string instrument(void) const; 00083 virtual double ontime(void) const; 00084 virtual double livetime(void) const; 00085 virtual double deadc(const GTime& time = GTime()) const; 00086 virtual void read(const GXmlElement& xml); 00087 virtual void write(GXmlElement& xml) const; 00088 virtual std::string print(const GChatter& chatter = NORMAL) const; 00089 00090 // Overloaded virtual methods 00091 virtual double likelihood(const GModels& models, 00092 GVector* gradient, 00093 GMatrixSparse* curvature, 00094 double* npred) const; 00095 virtual int nobserved(void) const; 00096 00097 // Other methods 00098 void instrument(const std::string& instrument); 00099 void on_regions(const GSkyRegions& regions); 00100 void off_regions(const GSkyRegions& regions); 00101 const GSkyRegions& on_regions(void) const; 00102 const GSkyRegions& off_regions(void) const; 00103 const GPha& on_spec(void) const; 00104 const GPha& off_spec(void) const; 00105 const GArf& arf(void) const; 00106 const GRmf& rmf(void) const; 00107 00108 protected: 00109 // Protected methods 00110 void init_members(void); 00111 void copy_members(const GCTAOnOffObservation& obs); 00112 void free_members(void); 00113 void set(const GCTAObservation& obs); 00114 void compute_arf(const GCTAObservation& obs); 00115 void compute_bgd(const GCTAObservation& obs); 00116 void compute_alpha(const GCTAObservation& obs); 00117 void compute_rmf(const GCTAObservation& obs); 00118 double N_gamma(const GModels& models, const int& ibin, GVector* grad) const; 00119 double N_bgd(const GModels& models, const int& ibin, GVector* grad) const; 00120 00121 // Protected data members 00122 std::string m_instrument; //!< Instrument name 00123 GCTAResponse* m_response; //!< Pointer to IRFs 00124 double m_ontime; //!< Ontime (seconds) 00125 double m_livetime; //!< Livetime (seconds) 00126 double m_deadc; //!< Deadtime correction (livetime/ontime) 00127 GPha m_on_spec; //!< On counts spectrum 00128 GPha m_off_spec; //!< Off counts spectrum 00129 GArf m_arf; //!< Auxiliary Response Function vector 00130 GRmf m_rmf; //!< Redistribution matrix 00131 GSkyRegions m_on_regions; //!< Container of On region 00132 GSkyRegions m_off_regions; //!< Container of Off regions 00133 }; 00134 00135 00136 /***********************************************************************//** 00137 * @brief Return class name 00138 * 00139 * @return String containing the class name ("GCTAOnOffObservation"). 00140 ***************************************************************************/ 00141 inline 00142 std::string GCTAOnOffObservation::classname(void) const 00143 { 00144 return ("GCTAOnOffObservation"); 00145 } 00146 00147 00148 /***********************************************************************//** 00149 * @brief Return instrument 00150 * 00151 * @return Instrument. 00152 ***************************************************************************/ 00153 inline 00154 std::string GCTAOnOffObservation::instrument(void) const 00155 { 00156 return (m_instrument); 00157 } 00158 00159 00160 /***********************************************************************//** 00161 * @brief Return ontime 00162 * 00163 * @return Ontime in seconds. 00164 ***************************************************************************/ 00165 inline 00166 double GCTAOnOffObservation::ontime(void) const 00167 { 00168 return (m_ontime); 00169 } 00170 00171 00172 /***********************************************************************//** 00173 * @brief Return livetime 00174 * 00175 * @return Livetime in seconds. 00176 ***************************************************************************/ 00177 inline 00178 double GCTAOnOffObservation::livetime(void) const 00179 { 00180 return (m_livetime); 00181 } 00182 00183 00184 /***********************************************************************//** 00185 * @brief Return deadtime correction factor 00186 * 00187 * @param[in] time Time. 00188 * @return Deadtime correction factor. 00189 * 00190 * Returns the deadtime correction factor. Optionally, this method takes a 00191 * @p time argument that takes provision for returning the deadtime 00192 * correction factor as function of time. 00193 * 00194 * The deadtime correction factor is defined as the livetime divided by the 00195 * ontime. 00196 ***************************************************************************/ 00197 inline 00198 double GCTAOnOffObservation::deadc(const GTime& time) const 00199 { 00200 return (m_deadc); 00201 } 00202 00203 00204 /***********************************************************************//** 00205 * @brief Set instrument 00206 * 00207 * @param[in] instrument Instrument. 00208 ***************************************************************************/ 00209 inline 00210 void GCTAOnOffObservation::instrument(const std::string& instrument) 00211 { 00212 m_instrument = instrument; 00213 return; 00214 } 00215 00216 00217 /***********************************************************************//** 00218 * @brief Set On regions 00219 * 00220 * @param[in] regions On regions. 00221 ***************************************************************************/ 00222 inline 00223 void GCTAOnOffObservation::on_regions(const GSkyRegions& regions) 00224 { 00225 m_on_regions = regions; 00226 return; 00227 } 00228 00229 00230 /***********************************************************************//** 00231 * @brief Set Off regions 00232 * 00233 * @param[in] regions Off regions. 00234 ***************************************************************************/ 00235 inline 00236 void GCTAOnOffObservation::off_regions(const GSkyRegions& regions) 00237 { 00238 m_off_regions = regions; 00239 return; 00240 } 00241 00242 00243 /***********************************************************************//** 00244 * @brief Return On regions 00245 * 00246 * @return On regions. 00247 ***************************************************************************/ 00248 inline 00249 const GSkyRegions& GCTAOnOffObservation::on_regions(void) const 00250 { 00251 return (m_on_regions); 00252 } 00253 00254 00255 /***********************************************************************//** 00256 * @brief Return Off regions 00257 * 00258 * @return Off regions. 00259 ***************************************************************************/ 00260 inline 00261 const GSkyRegions& GCTAOnOffObservation::off_regions(void) const 00262 { 00263 return (m_off_regions); 00264 } 00265 00266 00267 /***********************************************************************//** 00268 * @brief Return On spectrum 00269 * 00270 * @return On spectrum. 00271 ***************************************************************************/ 00272 inline 00273 const GPha& GCTAOnOffObservation::on_spec(void) const 00274 { 00275 return (m_on_spec); 00276 } 00277 00278 00279 /***********************************************************************//** 00280 * @brief Return Off spectrum 00281 * 00282 * @return Off spectrum. 00283 ***************************************************************************/ 00284 inline 00285 const GPha& GCTAOnOffObservation::off_spec(void) const 00286 { 00287 return (m_off_spec); 00288 } 00289 00290 00291 /***********************************************************************//** 00292 * @brief Return Auxiliary Response File 00293 * 00294 * @return Auxiliary Response File. 00295 ***************************************************************************/ 00296 inline 00297 const GArf& GCTAOnOffObservation::arf(void) const 00298 { 00299 return (m_arf); 00300 } 00301 00302 00303 /***********************************************************************//** 00304 * @brief Return Redistribution Matrix File 00305 * 00306 * @return Redistribution Matrix File. 00307 ***************************************************************************/ 00308 inline 00309 const GRmf& GCTAOnOffObservation::rmf(void) const 00310 { 00311 return (m_rmf); 00312 } 00313 00314 00315 /***********************************************************************//** 00316 * @brief Return number of observed events 00317 * 00318 * @return Number of observed events. 00319 ***************************************************************************/ 00320 inline 00321 int GCTAOnOffObservation::nobserved(void) const 00322 { 00323 return (m_on_spec.counts()); 00324 } 00325 00326 #endif /* GCTAONOFFOBSERVATION_HPP */