57 const std::string& version) :
ctool(name, version)
79 const std::string& version,
80 const GApplicationPars& pars) :
81 ctool(name, version, pars)
103 const std::string& version,
105 char *argv[]) :
ctool(name, version, argc, argv)
126 const std::string& version,
127 const GObservations& obs) :
ctool(name, version)
277 const GCTAObservation*
obs = NULL;
292 std::string msg =
" Skipping "+
300 if (obs->eventtype() ==
"CountsCube") {
302 std::string msg =
" Skipping binned "+
359 m_ogip_telescope = (hdu->has_card(
"TELESCOP")) ? hdu->string(
"TELESCOP") :
"";
362 std::string date_obs = (hdu->has_card(
"DATE-OBS")) ? hdu->string(
"DATE-OBS") :
"";
363 std::string time_obs = (hdu->has_card(
"TIME-OBS")) ? hdu->string(
"TIME-OBS") :
"";
364 std::string date_end = (hdu->has_card(
"DATE-END")) ? hdu->string(
"DATE-END") :
"";
365 std::string time_end = (hdu->has_card(
"TIME-END")) ? hdu->string(
"TIME-END") :
"";
366 m_ogip_telapse = (hdu->has_card(
"TELAPSE")) ? hdu->real(
"TELAPSE") : 0.0;
367 m_ogip_ontime = (hdu->has_card(
"ONTIME")) ? hdu->real(
"ONTIME") : 0.0;
368 m_ogip_livetime = (hdu->has_card(
"LIVETIME")) ? hdu->real(
"LIVETIME") : 0.0;
369 m_ogip_exposure = (hdu->has_card(
"EXPOSURE")) ? hdu->real(
"EXPOSURE") : 0.0;
372 std::string tstart = date_obs +
"T" + time_obs;
373 std::string tstop = date_end +
"T" + time_end;
401 std::string creator = this->name() +
" v" + this->version();
406 std::string date_obs = utc_obs.substr(0, 10);
407 std::string time_obs = utc_obs.substr(11, 8);
408 std::string date_end = utc_end.substr(0, 10);
409 std::string time_end = utc_end.substr(11, 8);
415 hdu->card(
"CREATOR", creator,
"Program which created the file");
419 hdu->card(
"DATE-OBS", date_obs,
"Observation start date");
420 hdu->card(
"TIME-OBS", time_obs,
"Observation start time");
421 hdu->card(
"DATE-END", date_end,
"Observation end date");
422 hdu->card(
"TIME-END", time_end,
"Observation end time");
424 hdu->card(
"ONTIME",
m_ogip_ontime,
"[s] Total good time including deadtime");
427 hdu->card(
"DEADC", deadc,
"Deadtime correction factor");
458 std::string ustatistic = gammalib::toupper(statistic);
461 bool handle_cta = ((ustatistic ==
"POISSON") ||
462 (ustatistic ==
"GAUSSIAN") ||
463 (ustatistic ==
"CHI2"));
464 bool handle_onoff = ((ustatistic ==
"POISSON") ||
465 (ustatistic ==
"CSTAT") ||
466 (ustatistic ==
"WSTAT"));
469 for (
int i = 0; i <
m_obs.size(); ++i) {
473 if ((
m_obs[i]->classname() ==
"GCTAObservation") && handle_cta) {
474 if (
m_obs[i]->events()->classname() ==
"GCTAEventCube") {
475 m_obs[i]->statistic(statistic);
480 else if ((
m_obs[i]->classname() ==
"GCTAOnOffObservation") &&
482 m_obs[i]->statistic(statistic);
517 for (
int i = 0; i <
m_obs.size(); ++i) {
520 GCTAObservation*
obs =
dynamic_cast<GCTAObservation*
>(
m_obs[i]);
524 if ((obs == NULL) || (!obs->has_events())) {
529 GCTAEventList* list =
const_cast<GCTAEventList*
>
530 (
dynamic_cast<const GCTAEventList*
>(obs->events()));
539 if (!list->roi().is_valid()) {
540 if (has_par(
"rad") && (*this)[
"rad"].is_valid()) {
541 if (obs->pointing().is_valid() ||
542 (has_par(
"ra") && (*this)[
"ra"].is_valid() &&
543 has_par(
"dec") && (*this)[
"dec"].is_valid())) {
547 if (obs->pointing().is_valid()) {
548 dir = obs->pointing().dir();
551 dir.radec_deg((*
this)[
"ra"].real(),
552 (*
this)[
"dec"].real());
556 GCTAInstDir instdir(dir);
559 double rad = (*this)[
"rad"].real();
562 GCTARoi roi(instdir, rad);
573 if (list->ebounds().is_empty()) {
574 if (has_par(
"emin") && (*this)[
"emin"].is_valid() &&
575 has_par(
"emax") && (*this)[
"emax"].is_valid()) {
576 double emin((*
this)[
"emin"].real());
577 double emax((*
this)[
"emax"].real());
578 GEbounds ebounds(GEnergy(emin,
"TeV"),
579 GEnergy(emax,
"TeV"));
580 list->ebounds(ebounds);
586 if (list->gti().is_empty()) {
587 if (has_par(
"tmin") && (*this)[
"tmin"].is_valid() &&
588 has_par(
"tmax") && (*this)[
"tmax"].is_valid()) {
591 GTimeReference ref = (has_par(
"mjdref"))
592 ? GTimeReference((*
this)[
"mjdref"].real(),
"s",
"TT",
"LOCAL")
593 : GTimeReference(G_CTA_MJDREF,
"s",
"TT",
"LOCAL");
596 GTime tmin = (*this)[
"tmin"].time(ref);
597 GTime tmax = (*this)[
"tmax"].time(ref);
600 GGti gti(tmin, tmax);
624 if (
m_obs.size() > 0) {
627 std::string outobs = (*this)[
"outobs"].filename();
634 std::string infile =
obs->eventfile();
635 std::string evtname = gammalib::extname_cta_events;
636 std::string gtiname = gammalib::extname_gti;
639 GFilename fname(outobs);
642 std::string outfile = fname.url();
646 if (fname.has_extname()) {
647 outfile +=
"["+fname.extname()+
"]";
650 outfile +=
"["+gammalib::extname_cta_events+
"]";
654 log_value(NORMAL,
"Event list file", outfile);
686 std::string outobs = (*this)[
"outobs"].filename();
696 std::string infile =
obs->eventfile();
697 std::string evtname = gammalib::extname_cta_events;
698 std::string gtiname = gammalib::extname_gti;
701 GFilename fname(infile);
702 if (fname.has_extname()) {
703 evtname = fname.extname();
711 outfile +=
"["+evtname+
"]";
714 log_value(NORMAL,
"Event list file", outfile);
717 obs->eventfile(outfile);
725 log_value(NORMAL,
"Obs. definition file", outobs);
const GObservations & obs(void) const
Return observation container.
GCTAObservation * next_unbinned_observation(void)
Return next unbinned CTA observation.
GTime m_ogip_tstop
Stop time for OGIP keywords.
void copy_members(const ctobservation &app)
Copy class members.
double m_ogip_ontime
Ontime for OGIP keywords.
ctobservation(const std::string &name, const std::string &version)
Name constructor.
void set_obs_statistic(const std::string &statistic)
Set fit statistic for CTA observations.
double m_ogip_telapse
Elapsed time.
double m_ogip_exposure
Exposure time.
double m_ogip_livetime
Livetime for OGIP keywords.
int m_index_unbinned
Current index of unbinned observation.
Observation tool base class interface definition.
Base class for observation tools.
void read_ogip_keywords(GFitsHDU *hdu) const
Read OGIP keywords from FITS HDU.
void save_events_fits(void)
Save event list in FITS format.
virtual ~ctobservation(void)
Destructor.
GTime m_ogip_tstart
Start time for OGIP keywords.
void free_members(void)
Delete class members.
std::string m_ogip_telescope
Name of telescope.
void write_ogip_keywords(GFitsHDU *hdu) const
Write OGIP keywords in FITS HDU.
void set_obs_bounds()
Set observation boundaries for CTA observations.
void init_members(void)
Initialise class members.
GCTAObservation * first_unbinned_observation(void)
Return first unbinned CTA observation.
ctobservation & operator=(const ctobservation &app)
Assignment operator.
GObservations m_obs
Observation container.
void save_events_xml(void)
Save event list(s) in XML format.