62 #define G_RESPONSE_SET "GCTAObservation::response(GResponse&)"
63 #define G_RESPONSE_GET "GCTAObservation::response()"
64 #define G_ROI "GCTAObservation::roi()"
65 #define G_GTI "GCTAObservation::gti()"
66 #define G_EBOUNDS "GCTAObservation::ebounds()"
67 #define G_READ "GCTAObservation::read(GXmlElement&)"
68 #define G_WRITE "GCTAObservation::write(GXmlElement&)"
69 #define G_LOAD1 "GCTAObservation::load(GFilename&, GFilename&, "\
70 "GFilename&, GFilename&)"
71 #define G_LOAD2 "GCTAObservation::load(GFilename&, GFilename&, "\
72 "GFilename&, GFilename&, GFilename&)"
117 const std::string& instrument) :
171 load(cntcube, expcube, psfcube, bkgcube);
200 load(cntcube, expcube, psfcube, edispcube, bkgcube);
360 std::string msg =
"No valid response function found in CTA "
496 std::string msg =
"Region of Interest is not defined since the "
497 "observation does not contain events.";
504 std::string msg =
"Region of Interest is not defined since the "
505 "observation does not contain an event list.";
510 return (list->
roi());
529 std::string msg =
"Good Time Intervals are not defined since the "
530 "observation does not contain events.";
554 std::string msg =
"Energy boundaries are not defined since the "
555 "observation does not contain events.";
669 if ((statistic !=
"POISSON") &&
670 (statistic !=
"CSTAT") &&
671 (statistic !=
"GAUSSIAN") &&
672 (statistic !=
"CHI2")) {
673 std::string msg =
"Invalid statistic \""+statistic+
"\" encountered "
674 "in observation definition XML file for "
676 "\""+xml.
attribute(
"id")+
"\". Only \"POISSON\", "
677 "\"CSTAT\", \"GAUSSIAN\" or \"CHI2\" are "
688 int npars = xml.
elements(
"parameter");
691 if (xml.
elements() < 1 || npars < 1) {
692 std::string msg =
"CTA observation contains "+
gammalib::str(npars)+
693 " parameters but at least one parameter is required. "
694 "Please verify the XML format.";
700 for (
int i = 0; i < npars; ++i) {
706 if ((par->
attribute(
"name") ==
"EventList") ||
707 (par->
attribute(
"name") ==
"CountsCube")) {
721 else if (par->
attribute(
"name") ==
"Background") {
729 else if (par->
attribute(
"name") ==
"OffRegions") {
743 bool has_evfile = (n_evfile > 0);
758 bool has_ebounds =
false;
759 bool has_gti =
false;
760 bool has_roi =
false;
788 if (has_ebounds || has_gti || has_roi) {
821 int response_type = 0;
822 for (
int i = 0; i < npars; ++i) {
828 if ((par->
attribute(
"name") ==
"EffectiveArea") ||
830 (par->
attribute(
"name") ==
"PointSpreadFunction") ||
832 (par->
attribute(
"name") ==
"EnergyDispersion") ||
834 (par->
attribute(
"name") ==
"Background") ||
835 (par->
attribute(
"name") ==
"Calibration")) {
836 if (response_type == 2) {
837 std::string msg =
"Response cube parameters expected but the "
838 "IRF response parameter \""+
839 par->
attribute(
"name")+
"\" was encountered. "
840 "Please verify the XML format.";
847 else if ((par->
attribute(
"name") ==
"ExposureCube") ||
850 if (response_type == 1) {
851 std::string msg =
"IRF response parameters expected but the "
852 "response cube parameter \""+
853 par->
attribute(
"name")+
"\" was encountered. "
854 "Please verify the XML format.";
863 switch (response_type) {
970 if ((evttype !=
"EventList") && (evttype !=
"CountsCube")) {
972 if (evttype.empty()) {
973 msg =
"The observation does not contain any events, hence "
974 "it cannot be written into an XML file.";
977 msg =
"The observation contains an unknown event type \""+
978 evttype+
"\". The event type needs to be either "
979 "\"EventList\" or \"CountsCube\".";
1018 list->
roi().write(xml);
1133 const std::string& gtiname)
const
1151 list->
write(fits, evtname, gtiname);
1162 else if (cube != NULL) {
1189 #pragma omp critical(GCTAObservation_load)
1195 GFits fits(filename);
1229 if (dynamic_cast<const GCTAEventCube*>(
events()) == NULL) {
1230 std::string msg =
"Specified file \""+cntcube.
url()+
"\" is not a CTA "
1231 "counts cube. Please provide a counts cube.";
1246 response(exposure, psf, background);
1275 if (dynamic_cast<const GCTAEventCube*>(
events()) == NULL) {
1276 std::string msg =
"Specified file \""+cntcube.
url()+
"\" is not a CTA "
1277 "counts cube. Please provide a counts cube.";
1295 response(exposure, psf, edisp, background);
1327 const bool& clobber)
const
1338 if (extnames.size() > 0) {
1341 if (extnames.size() > 1) {
1352 write(fits, evtname, gtiname);
1386 eventtype =
"EventList";
1393 eventtype =
"CountsCube";
1398 eventtype =
"Events";
1446 result.append(
"=== GCTAObservation ===");
1466 result.append(
" - ");
1468 result.append(
" TeV");
1471 result.append(
"> ");
1473 result.append(
" TeV");
1476 result.append(
"< ");
1478 result.append(
" TeV");
1481 result.append(
"undefined");
1486 if (reduced_chatter >
SILENT) {
1497 result.append(
"undefined");
1631 double ra_pnt = hdu.
real(
"RA_PNT");
1632 double dec_pnt = hdu.
real(
"DEC_PNT");
1641 std::string
id = (hdu.
has_card(
"OBS_ID")) ? hdu.
string(
"OBS_ID") :
"";
1642 double alt = (hdu.
has_card(
"ALT_PNT")) ? hdu.
real(
"ALT_PNT") : 0.0;
1643 double az = (hdu.
has_card(
"AZ_PNT")) ? hdu.
real(
"AZ_PNT") : 0.0;
1694 double telapse =
events()->
gti().telapse();
1700 std::string date_obs = utc_obs.substr(0, 10);
1701 std::string time_obs = utc_obs.substr(11, 8);
1702 std::string date_end = utc_end.substr(0, 10);
1703 std::string time_end = utc_end.substr(11, 8);
1706 hdu.
card(
"CREATOR",
"GammaLib",
"Program which created the file");
1708 hdu.
card(
"OBS_ID",
id(),
"Observation identifier");
1709 hdu.
card(
"DATE-OBS", date_obs,
"Observation start date");
1710 hdu.
card(
"TIME-OBS", time_obs,
"Observation start time");
1711 hdu.
card(
"DATE-END", date_end,
"Observation end date");
1712 hdu.
card(
"TIME-END", time_end,
"Observation end time");
1715 hdu.
card(
"TSTART", tstart,
"[s] Mission time of start of observation");
1716 hdu.
card(
"TSTOP", tstop,
"[s] Mission time of end of observation");
1718 hdu.
card(
"TELAPSE", telapse,
"[s] Mission elapsed time");
1719 hdu.
card(
"ONTIME", ontime,
"[s] Total good time including deadtime");
1720 hdu.
card(
"LIVETIME",
livetime(),
"[s] Total livetime");
1721 hdu.
card(
"DEADC", deadc,
"Deadtime correction factor");
1722 hdu.
card(
"TIMEDEL", 1.0,
"Time resolution");
1725 hdu.
card(
"OBJECT",
object(),
"Observed object");
1726 hdu.
card(
"RA_OBJ",
ra_obj(),
"[deg] Target Right Ascension");
1727 hdu.
card(
"DEC_OBJ",
dec_obj(),
"[deg] Target Declination");
1728 hdu.
card(
"RA_PNT", ra_pnt,
"[deg] Pointing Right Ascension");
1729 hdu.
card(
"DEC_PNT", dec_pnt,
"[deg] Pointing Declination");
1730 hdu.
card(
"ALT_PNT", alt,
"[deg] Average altitude of pointing");
1731 hdu.
card(
"AZ_PNT", az,
"[deg] Average azimuth of pointing");
1732 hdu.
card(
"RADECSYS",
"FK5",
"Coordinate system");
1733 hdu.
card(
"EQUINOX", 2000.0,
"Epoch");
1734 hdu.
card(
"CONV_DEP", 0.0,
"Convergence depth of telescopes");
1735 hdu.
card(
"CONV_RA", 0.0,
"[deg] Convergence Right Ascension");
1736 hdu.
card(
"CONV_DEC", 0.0,
"[deg] Convergence Declination");
1737 hdu.
card(
"OBSERVER",
"string",
"Observer");
1740 hdu.
card(
"N_TELS",
n_tels(),
"Number of telescopes in event list");
1741 hdu.
card(
"TELLIST",
"string",
"Telescope IDs");
1742 hdu.
card(
"GEOLAT", 0.0,
"[deg] Geographic latitude of array centre");
1743 hdu.
card(
"GEOLON", 0.0,
"[deg] Geographic longitude of array centre");
1744 hdu.
card(
"ALTITUDE", 0.0,
"[km] Altitude of array centre");
1747 hdu.
card(
"EUNIT",
"TeV",
"Energy unit");
1748 hdu.
card(
"EVTVER",
"draft1",
"Event list version number");
void clear(void)
Clear CTA pointing.
const std::string & statistic(void) const
Return optimizer statistic.
const GSkyRegions & off_regions(void) const
Return sky off regions.
GFitsHDU * at(const int &extno)
Get pointer to HDU.
virtual ~GCTAObservation(void)
Destructor.
const GFilename & eventfile(void) const
Return event file name.
void clear(void)
Clear object.
CTA event list class interface definition.
bool contains(const int &extno) const
Check if HDU exists in FITS file.
bool has_card(const int &cardno) const
Check existence of header card.
double dec_deg(void) const
Returns Declination in degrees.
void xml_check_par(const std::string &origin, const std::string &name, const int &number)
Checks whether a parameter has occured once.
void save(const GFilename &filename, const bool &clobber=false) const
Save CTA observation into FITS file.
CTA cube-style response function class definition.
double m_ontime
Ontime (seconds)
virtual void write(GFits &fits) const
Write CTA events and Good Time Intervals into FITS file.
virtual void roi(const GRoi &roi)
Set ROI.
void write(GFitsHDU &hdu) const
Write time reference into FITS header.
GFilename m_eventfile
Event filename.
void ebounds(const GEbounds &ebounds)
Set energy boundaries.
Abstract FITS extension base class.
virtual void read(const GXmlElement &xml)
Read observation from XML element.
CTA cube background class.
GEvents * m_events
Pointer to event container.
GEbounds ebounds(void) const
Get energy boundaries.
const GFilename & filename(void) const
Return FITS filename.
void load(const GFilename &filename)
Load unbinned or binned analysis data.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print CTA observation information.
CTA cube-style response function class.
const GCTAPointing & pointing(void) const
Return CTA pointing.
bool is_empty(void) const
Signal if filename is empty.
CTA instrument response function class definition.
const GTime & tstop(void) const
Return stop time.
void gti(const GGti >i)
Set Good Time Intervals.
bool has_extname(void) const
Signal if filename has an extension name.
const GCTAObservation g_obs_fact_seed(true,"FACT")
const double & zenith(void) const
Return pointing zenith angle.
void dispose_events(void)
Dispose events.
std::string extname(const std::string &defaultname="") const
Return extension name.
const GCTAObservation g_obs_astri_seed(true,"ASTRI")
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split string.
const int & n_tels(void) const
Return number of telescopes.
Interface for the CTA region of interest class.
void read(const GFitsTable &table)
Read energy boundaries from FITS table.
virtual int elements(void) const
Return number of GXMLElement children of node.
void read(const GXmlElement &xml)
Read pointing from XML element.
const std::string extname_gti
FITS file class interface definition.
double m_lo_user_thres
User defined lower energy threshold.
void write(GXmlElement &xml) const
Write pointing information into XML element.
virtual GCTAResponse * clone(void) const =0
Clones object.
virtual double deadc(const GTime &time=GTime()) const
Return deadtime correction factor.
double m_hi_user_thres
User defined upper energy boundary.
std::string strip_whitespace(const std::string &arg)
Strip leading and trailing whitespace from string.
GFilename xml_file_reduce(const GXmlElement &xml, const std::string &filename)
Reduce file name provided for writing as XML attribute.
Good time interval class interface definition.
void free_members(void)
Delete class members.
virtual double ontime(void) const
Return ontime.
Definition of support function used by CTA classes.
double real(const std::string &keyname) const
Return card value as double precision.
CTA event bin container class.
virtual double livetime(void) const
Return livetime.
Calibration database class.
const GFilename & filename(void) const
Return regions file name.
const std::string & id(void) const
Return observation identifier.
Energy boundaries container class.
void remove(const int &extno)
Remove HDU from FITS file.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
GCTARoi roi(void) const
Get Region of Interest.
const GCTAResponse * cta_rsp(const std::string &origin, const GResponse &rsp)
Retrieve CTA response from generic observation.
virtual void clear(void)
Clear CTA observation.
double m_deadc
Deadtime correction (livetime/ontime)
GGti gti(void) const
Get Good Time Intervals.
const double & dec_obj(void) const
Return CTA object Declination.
std::string m_object
Object name.
const double & ra_obj(void) const
Return CTA object Right Ascension.
const std::string extname_cta_events
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
virtual std::string instrument(void) const
Return instrument name.
Interface definition for the observation registry class.
const std::string & name(void) const
Return observation name.
Observation registry class definition.
void dispose(void) const
Dispose events.
double ra_deg(void) const
Returns Right Ascension in degrees.
const GCTAObservation g_obs_magic_seed(true,"MAGIC")
CTA energy dispersion for stacked analysis.
GCTAResponse * m_response
Pointer to instrument response functions.
GCTAObservation & operator=(const GCTAObservation &obs)
Assignment operator.
double deadc(void) const
Return deadtime correction.
int integer(const std::string &keyname) const
Return card value as integer.
Good Time Interval class.
virtual void write(GXmlElement &xml) const
Write observation into XML element.
void init_members(void)
Initialise class members.
Abstract observation base class.
void radec_deg(const double &ra, const double &dec)
Set equatorial sky direction (degrees)
void copy_members(const GCTAObservation &obs)
Copy class members.
virtual const GCTAResponse * response(void) const
Return pointer to CTA response function.
CTA region of interest class interface definition.
CTA observation class interface definition.
virtual void read(const GXmlElement &xml)=0
void load(const std::string &rspname)
Load CTA response.
bool xml_has_par(const GXmlElement &xml, const std::string &name)
Checks if parameter with given name in XML element exists.
CTA instrument response function class.
CTA instrument response function class.
Sky region container class.
const double & azimuth(void) const
Return pointing azimuth angle.
const GCTAObservation g_obs_veritas_seed(true,"VERITAS")
const GCTAObservation g_obs_hess_seed(true,"HESS")
std::string url(void) const
Return Uniform Resource Locator (URL)
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
void free_members(void)
Delete class members.
void clear(void)
Clear file name.
const GCTAObservation g_obs_cta_seed(true,"CTA")
CTA point spread function for cube analysis.
void init_members(void)
Initialise class members.
void write_attributes(GFitsHDU &hdu) const
Write observation attributes.
void read(const GFitsTable &table)
Read Good Time Intervals and time reference from FITS table.
double m_dec_obj
Declination of object (degrees)
GChatter reduce(const GChatter &chatter)
Reduce chattiness by one level.
virtual std::string print(const GChatter &chatter=NORMAL) const =0
Print content of object.
const double & ontime(void) const
Return ontime.
CTA event bin container class interface definition.
double m_ra_obj
Right Ascension of object (degrees)
const double & livetime(void) const
Return livetime.
virtual GObservation & operator=(const GObservation &obs)
Assignment operator.
virtual GEvents * events(void)
Return events.
std::string string(const std::string &keyname) const
Return card value as string.
std::string eventtype(void) const
Return event type string.
Exception handler interface definition.
std::string toupper(const std::string &s)
Convert string to upper case.
Implements a time reference.
GCTAPointing m_pointing
Pointing direction.
void read_attributes(const GFitsHDU &hdu)
Read observation attributes.
const GSkyDir & dir(void) const
Return pointing sky direction.
virtual GCTAObservation * clone(void) const
Clone CTA observation.
virtual void write(GXmlElement &xml) const =0
void read(const GXmlElement &xml)
Read region of interest from XML element.
virtual void write(GFits &file) const
Write CTA event cube into FITS file.
Abstract instrument response base class.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
const GTime & tstart(void) const
Return start time.
Integration class interface definition.
GFitsHeaderCard & card(const int &cardno)
Return header card.
void close(void)
Close FITS file.
GSkyRegions m_off_regions
Off regions.
std::string utc(const int &precision=0) const
Return time as string in UTC time system.
void caldb(const GCaldb &caldb)
Set calibration database.
const GXmlElement * xml_get_par(const std::string &origin, const GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
const double & ontime(void) const
Returns ontime.
virtual void read(const GFits &fits)
Read events from FITS file.
virtual void read(const GFits &file)
Read CTA event cube from FITS file.
double convert(const GTimeReference &ref) const
Return time in specified reference.
std::string m_instrument
Instrument name.
Filename class interface definition.
virtual std::string print(const GChatter &chatter=NORMAL) const =0
Print content of object.
int m_n_tels
Number of telescopes.
double todouble(const std::string &arg)
Convert string into double precision value.
GCTAObservation(void)
Void constructor.
double m_livetime
Livetime (seconds)
GFilename xml_file_expand(const GXmlElement &xml, const std::string &filename)
Expand file name provided as XML attribute for loading.
std::string m_bgdfile
Background filename.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.