GammaLib 2.2.0.dev
Loading...
Searching...
No Matches
GCOSObservation Class Reference

COSI observation class. More...

#include <GCOSObservation.hpp>

Inheritance diagram for GCOSObservation:
GObservation GBase

Public Member Functions

 GCOSObservation (void)
 Void constructor.
 
 GCOSObservation (const GXmlElement &xml)
 XML constructor.
 
 GCOSObservation (const GFilename &eventname, const GFilename &spacename, const GFilename &rspname)
 Load constructor.
 
 GCOSObservation (const std::vector< GFilename > &eventnames, const GFilename &spacename, const GFilename &rspname)
 Load constructor.
 
 GCOSObservation (const GCOSObservation &obs)
 Copy constructor.
 
virtual ~GCOSObservation (void)
 Destructor.
 
virtual GCOSObservationoperator= (const GCOSObservation &obs)
 Assignment operator.
 
virtual void clear (void)
 Clear COSI observation.
 
virtual GCOSObservationclone (void) const
 Clone COSI observation.
 
virtual std::string classname (void) const
 Return class name.
 
virtual void response (const GResponse &rsp)
 Set COSI response function.
 
virtual const GCOSResponseresponse (void) const
 Return pointer to response function.
 
virtual std::string instrument (void) const
 Return instrument.
 
virtual double ontime (void) const
 Return ontime.
 
virtual double livetime (void) const
 Return livetime.
 
virtual double deadc (const GTime &time=GTime()) const
 Return deadtime correction factor.
 
virtual void read (const GXmlElement &xml)
 Read COSI observation from XML element.
 
virtual void write (GXmlElement &xml) const
 Write COSI observation into XML element.
 
virtual std::string print (const GChatter &chatter=NORMAL) const
 Print observation information.
 
bool is_unbinned (void) const
 Check whether observation is unbinned.
 
bool is_binned (void) const
 Check whether observation is binned.
 
const GCOSSpaceCraftspacecraft (void) const
 Return space craft information.
 
void ontime (const double &ontime)
 Set ontime.
 
void livetime (const double &livetime)
 Set livetime.
 
void deadc (const double &deadc)
 Set deadtime correction factor.
 
void load (const GFilename &eventname, const GFilename &spacename, const GFilename &rspname)
 Load data for an unbinned observation.
 
void load (const std::vector< GFilename > &eventnames, const GFilename &spacename, const GFilename &rspname)
 Load data for an unbinned observation.
 
- Public Member Functions inherited from GObservation
 GObservation (void)
 Void constructor.
 
 GObservation (const GObservation &obs)
 Copy constructor.
 
virtual ~GObservation (void)
 Destructor.
 
virtual GObservationoperator= (const GObservation &obs)
 Assignment operator.
 
virtual GEventsevents (void)
 Return events.
 
virtual const GEventsevents (void) const
 Return events (const version)
 
virtual void events (const GEvents &events)
 Set event container.
 
virtual double likelihood (const GModels &models, GVector *gradients, GMatrixSparse *curvature, double *npred) const
 Compute likelihood function.
 
virtual double model (const GModels &models, const GEvent &event, GVector *gradients=NULL) const
 Return model value and (optionally) gradients.
 
virtual GVector model (const GModels &models, GMatrixSparse *gradients=NULL) const
 Return vector of model values and (optionally) gradients.
 
virtual double nobserved (void) const
 Return total number of observed events.
 
virtual double npred (const GModels &models, GVector *gradients=NULL) const
 Return total number (and optionally gradients) of predicted counts for all models.
 
virtual double npred (const GModel &model) const
 Return total number of predicted counts for one model.
 
virtual double model_grad (const GModel &model, const GModelPar &par, const GEvent &event) const
 Returns parameter gradient of model for a given event.
 
virtual GVector model_grad (const GModel &model, const GModelPar &par) const
 Returns parameter gradients of model for all events.
 
virtual double npred_grad (const GModel &model, const GModelPar &par) const
 Returns parameter gradient of Npred.
 
virtual void remove_response_cache (const std::string &name)
 Remove response cache for specific model.
 
virtual double grad_step_size (const GModelPar &par) const
 Return gradient step size for a given model parameter.
 
bool has_events (void) const
 Signal if observation has events.
 
bool has_gradient (const GModel &model, const GModelPar &par) const
 Check whether a model parameter has an analytical gradient.
 
void name (const std::string &name)
 Set observation name.
 
void id (const std::string &id)
 Set observation identifier.
 
void statistic (const std::string &statistic)
 Set optimizer statistic.
 
const std::string & name (void) const
 Return observation name.
 
const std::string & id (void) const
 Return observation identifier.
 
const std::string & statistic (void) const
 Return optimizer statistic.
 
void computed_gradient (const GModel &model, const GModelPar &par) const
 Signals that an analytical gradient was computed for a model parameter.
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor.
 

Protected Member Functions

void init_members (void)
 Initialise class members.
 
void copy_members (const GCOSObservation &obs)
 Copy class members.
 
void free_members (void)
 Delete class members.
 
- Protected Member Functions inherited from GObservation
void init_members (void)
 Initialise class members.
 
void copy_members (const GObservation &obs)
 Copy class members.
 
void free_members (void)
 Delete class members.
 
virtual double likelihood_poisson_unbinned (const GModels &models, GVector *gradients, GMatrixSparse *curvature, double *npred) const
 Evaluate log-likelihood function for Poisson statistic and unbinned analysis (version with working arrays)
 
virtual double likelihood_poisson_binned (const GModels &models, GVector *gradients, GMatrixSparse *curvature, double *npred) const
 Evaluate log-likelihood function for Poisson statistic and binned analysis (version with working arrays)
 
virtual double likelihood_gaussian_binned (const GModels &models, GVector *gradients, GMatrixSparse *curvature, double *npred) const
 Evaluate log-likelihood function for Gaussian statistic and binned analysis (version with working arrays)
 
virtual bool use_event_for_likelihood (const int &index) const
 Check whether bin should be used for likelihood analysis.
 
virtual double npred_spec (const GModel &model, const GTime &obsTime) const
 Integrates spatially integrated Npred kernel spectrally.
 

Protected Attributes

std::string m_instrument
 Instrument name.
 
GCOSResponse m_response
 Response functions.
 
GCOSSpaceCraft m_spacecraft
 Space craft information.
 
double m_ontime
 Ontime (sec)
 
double m_livetime
 Livetime (sec)
 
double m_deadc
 Deadtime correction.
 
std::vector< GFilenamem_eventnames
 Event list filenames.
 
GFilename m_spacename
 Space craft filename.
 
GFilename m_rspname
 Response filename.
 
- Protected Attributes inherited from GObservation
std::string m_name
 Observation name.
 
std::string m_id
 Observation identifier.
 
std::string m_statistic
 Optimizer statistic.
 
GEventsm_events
 Pointer to event container.
 
std::vector< std::string > m_pars_with_gradients
 

Detailed Description

COSI observation class.

The COSI observation class defines an observation.

Todo
Complete the class description.

Definition at line 57 of file GCOSObservation.hpp.

Constructor & Destructor Documentation

◆ GCOSObservation() [1/5]

GCOSObservation::GCOSObservation ( void )

Void constructor.

Creates an empty COSI observation.

Definition at line 65 of file GCOSObservation.cpp.

References init_members().

Referenced by clone().

◆ GCOSObservation() [2/5]

GCOSObservation::GCOSObservation ( const GXmlElement & xml)
explicit

XML constructor.

Parameters
[in]xmlXML element.

Constructs a COSI observation from the information that is found in an XML element. See the read() method for more information.

Definition at line 83 of file GCOSObservation.cpp.

References init_members(), and read().

◆ GCOSObservation() [3/5]

GCOSObservation::GCOSObservation ( const GFilename & eventname,
const GFilename & spacename,
const GFilename & rspname )

Load constructor.

Parameters
[in]eventnameEvent list FITS file name.
[in]spacenameSpace craft file name.
[in]rspnameResponse file name.

Creates an unbinned COSI observation by loading an event list, a space craft file and a response file.

Definition at line 106 of file GCOSObservation.cpp.

References init_members(), and load().

◆ GCOSObservation() [4/5]

GCOSObservation::GCOSObservation ( const std::vector< GFilename > & eventnames,
const GFilename & spacename,
const GFilename & rspname )

Load constructor.

Parameters
[in]eventnamesVector of event list FITS file names.
[in]spacenameSpace craft file name.
[in]rspnameResponse file name.

Creates an unbinned COSI observation by loading event lists, a space craft file and a response file. Multiple event lists are appended to each other and events are sorted by increasing time.

Definition at line 132 of file GCOSObservation.cpp.

References init_members(), and load().

◆ GCOSObservation() [5/5]

GCOSObservation::GCOSObservation ( const GCOSObservation & obs)

Copy constructor.

Parameters
[in]obsCOSI observation.

Creates COSI observation by copying from an existing COSI observation.

Definition at line 155 of file GCOSObservation.cpp.

References copy_members(), and init_members().

◆ ~GCOSObservation()

GCOSObservation::~GCOSObservation ( void )
virtual

Destructor.

Definition at line 171 of file GCOSObservation.cpp.

References free_members().

Member Function Documentation

◆ classname()

std::string GCOSObservation::classname ( void ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GCOSObservation").

Implements GObservation.

Definition at line 132 of file GCOSObservation.hpp.

◆ clear()

void GCOSObservation::clear ( void )
virtual

Clear COSI observation.

Clears COSI observation by resetting all class members to an initial state. Any information that was present before will be lost.

Implements GObservation.

Definition at line 234 of file GCOSObservation.cpp.

References free_members(), GObservation::free_members(), init_members(), and GObservation::init_members().

Referenced by load(), load(), and read().

◆ clone()

GCOSObservation * GCOSObservation::clone ( void ) const
virtual

Clone COSI observation.

Returns
Pointer to deep copy of COSI observation.

Implements GObservation.

Definition at line 254 of file GCOSObservation.cpp.

References GCOSObservation().

◆ copy_members()

void GCOSObservation::copy_members ( const GCOSObservation & obs)
protected

Copy class members.

Parameters
[in]obsCOSI observation.

Definition at line 612 of file GCOSObservation.cpp.

References m_deadc, m_eventnames, m_instrument, m_livetime, m_ontime, m_response, m_rspname, m_spacecraft, and m_spacename.

Referenced by GCOSObservation(), and operator=().

◆ deadc() [1/2]

void GCOSObservation::deadc ( const double & deadc)
inline

Set deadtime correction factor.

Parameters
[in]deadcDeadtime correction factor.

Definition at line 273 of file GCOSObservation.hpp.

References deadc(), and m_deadc.

◆ deadc() [2/2]

double GCOSObservation::deadc ( const GTime & time = GTime()) const
inlinevirtual

Return deadtime correction factor.

Parameters
[in]timeTime.
Returns
Deadtime correction factor.

Implements GObservation.

Definition at line 198 of file GCOSObservation.hpp.

References m_deadc.

Referenced by deadc().

◆ free_members()

void GCOSObservation::free_members ( void )
protected

Delete class members.

Definition at line 635 of file GCOSObservation.cpp.

Referenced by clear(), operator=(), and ~GCOSObservation().

◆ init_members()

◆ instrument()

std::string GCOSObservation::instrument ( void ) const
inlinevirtual

Return instrument.

Returns
Instrument name.

Implements GObservation.

Definition at line 157 of file GCOSObservation.hpp.

References m_instrument.

Referenced by print().

◆ is_binned()

bool GCOSObservation::is_binned ( void ) const
inline

Check whether observation is binned.

Returns
True if observation is binned.

Definition at line 223 of file GCOSObservation.hpp.

References GObservation::m_events.

Referenced by write().

◆ is_unbinned()

bool GCOSObservation::is_unbinned ( void ) const
inline

Check whether observation is unbinned.

Returns
True if observation is unbinned.

Definition at line 211 of file GCOSObservation.hpp.

References GObservation::m_events.

Referenced by write().

◆ livetime() [1/2]

void GCOSObservation::livetime ( const double & livetime)
inline

Set livetime.

Parameters
[in]livetimeLivetime.

Definition at line 260 of file GCOSObservation.hpp.

References livetime(), and m_livetime.

◆ livetime() [2/2]

double GCOSObservation::livetime ( void ) const
inlinevirtual

Return livetime.

Returns
Livetime (seconds).

Implements GObservation.

Definition at line 183 of file GCOSObservation.hpp.

References m_livetime.

Referenced by livetime(), and print().

◆ load() [1/2]

void GCOSObservation::load ( const GFilename & eventname,
const GFilename & spacename,
const GFilename & rspname )

Load data for an unbinned observation.

Parameters
[in]eventnameEvent list FITS file name.
[in]spacenameSpace craft file name.
[in]rspnameResponse file name.

Loads the event list, space craft file and the response for an unbinned observation.

Definition at line 433 of file GCOSObservation.cpp.

References clear(), and load().

Referenced by GCOSObservation(), GCOSObservation(), load(), and read().

◆ load() [2/2]

void GCOSObservation::load ( const std::vector< GFilename > & eventnames,
const GFilename & spacename,
const GFilename & rspname )

Load data for an unbinned observation.

Parameters
[in]eventnamesVector of event list FITS file names.
[in]spacenameSpace craft file name.
[in]rspnameResponse file name.
Exceptions
GException::invalid_argumentEmpty event list name vector provided.

Loads the event lists, space craft file and the response for an unbinned observation. Multiple event lists are appended to each other and events are sorted by increasing time.

The method uses the Good Time Intervals provided in the space craft file and attaches them to the event list. The method also sets the m_ontime, m_livetime and m_deadc members from the information provided by the space craft file.

The specified file names are stored in the m_eventnames, m_spacename and m_rspname class members which are used when writing the observation information into an XML element.

Definition at line 475 of file GCOSObservation.cpp.

References clear(), GCOSSpaceCraft::deadc(), GObservation::events(), G_LOAD, GCOSSpaceCraft::gti(), GEvents::gti(), GCOSSpaceCraft::livetime(), GCOSResponse::load(), GCOSSpaceCraft::load(), m_deadc, m_eventnames, GObservation::m_events, m_livetime, m_ontime, m_response, m_rspname, m_spacecraft, m_spacename, and GCOSSpaceCraft::ontime().

◆ ontime() [1/2]

void GCOSObservation::ontime ( const double & ontime)
inline

Set ontime.

Parameters
[in]ontimeOntime.

Definition at line 247 of file GCOSObservation.hpp.

References m_ontime, and ontime().

◆ ontime() [2/2]

double GCOSObservation::ontime ( void ) const
inlinevirtual

Return ontime.

Returns
Ontime (seconds).

Implements GObservation.

Definition at line 170 of file GCOSObservation.hpp.

References m_ontime.

Referenced by ontime(), and print().

◆ operator=()

GCOSObservation & GCOSObservation::operator= ( const GCOSObservation & obs)
virtual

Assignment operator.

Parameters
[in]obsCOSI observation.
Returns
COSI observation.

Assign COSI observation to this object. The assignment performs a deep copy of all information, hence the original object from which the assignment was made can be destroyed after this operation without any loss of information.

Definition at line 198 of file GCOSObservation.cpp.

References copy_members(), free_members(), init_members(), and GObservation::operator=().

◆ print()

std::string GCOSObservation::print ( const GChatter & chatter = NORMAL) const
virtual

Print observation information.

Parameters
[in]chatterChattiness.
Returns
String containing COSI observation information.

Implements GObservation.

Definition at line 540 of file GCOSObservation.cpp.

References instrument(), livetime(), m_deadc, GObservation::m_events, GObservation::name(), ontime(), gammalib::parformat(), GEvents::print(), gammalib::reduce(), SILENT, GObservation::statistic(), and gammalib::str().

◆ read()

void GCOSObservation::read ( const GXmlElement & xml)
virtual

Read COSI observation from XML element.

Parameters
[in]xmlXML element.

Reads information for a COSI observation from an XML element. The method supports both an unbinned and a binned observation.

For an unbinned observation the XML format is

<observation name="Crab" id="00001" instrument="COS">
  <parameter name="EventList"      file="cosi_event_list.fits"/>
  <parameter name="SpaceCraftFile" file="cosi_orientation.ori"/>
  <parameter name="Response"       file="cosi_response.h5"/>
</observation>

The method supports the presence of multiple "EventList" entries which will load all specified event lists and merge them into a single event list. The events will be ordered by increasing time.

For a binned observation the XML format is

<observation name="Crab" id="00001" instrument="COS">
</observation>

Implements GObservation.

Definition at line 316 of file GCOSObservation.cpp.

References GXmlElement::attribute(), clear(), GXmlNode::element(), GXmlNode::elements(), G_READ, load(), GObservation::m_id, m_instrument, GObservation::m_name, gammalib::xml_file_expand(), gammalib::xml_get_attr(), and gammalib::xml_has_par().

Referenced by GCOSObservation().

◆ response() [1/2]

void GCOSObservation::response ( const GResponse & rsp)
virtual

Set COSI response function.

Parameters
[in]rspCOSI response function.
Exceptions
GException::invalid_argumentSpecified response is not a COSI response.

Sets the response function for the observation.

Implements GObservation.

Definition at line 270 of file GCOSObservation.cpp.

References G_RESPONSE, m_response, and GObservation::name().

◆ response() [2/2]

const GCOSResponse * GCOSObservation::response ( void ) const
inlinevirtual

Return pointer to response function.

Returns
Response function pointer.

Implements GObservation.

Definition at line 144 of file GCOSObservation.hpp.

References m_response.

◆ spacecraft()

const GCOSSpaceCraft & GCOSObservation::spacecraft ( void ) const
inline

Return space craft information.

Returns
Space craft information.

Definition at line 235 of file GCOSObservation.hpp.

References m_spacecraft.

◆ write()

void GCOSObservation::write ( GXmlElement & xml) const
virtual

Write COSI observation into XML element.

Parameters
[in]xmlXML element.

Writes information for a COSI observation into an XML element. The method supports both an unbinned and a binned observation.

For an unbinned observation the XML format is

<observation name="Crab" id="00001" instrument="COS">
  <parameter name="EventList"      file="cosi_event_list.fits"/>
  <parameter name="SpaceCraftFile" file="cosi_orientation.ori"/>
  <parameter name="Response"       file="cosi_response.h5"/>
</observation>

If multiple event lists were read by the read() method, the method will write back the file names of all the event lists.

For a binned observation the XML format is

<observation name="Crab" id="00001" instrument="COS">
</observation>

Implements GObservation.

Definition at line 389 of file GCOSObservation.cpp.

References GXmlNode::append(), GXmlElement::attribute(), G_WRITE, is_binned(), is_unbinned(), m_eventnames, m_rspname, m_spacename, gammalib::xml_file_reduce(), and gammalib::xml_need_par().

Member Data Documentation

◆ m_deadc

double GCOSObservation::m_deadc
protected

Deadtime correction.

Definition at line 115 of file GCOSObservation.hpp.

Referenced by copy_members(), deadc(), deadc(), init_members(), load(), and print().

◆ m_eventnames

std::vector<GFilename> GCOSObservation::m_eventnames
protected

Event list filenames.

Definition at line 120 of file GCOSObservation.hpp.

Referenced by copy_members(), init_members(), load(), and write().

◆ m_instrument

std::string GCOSObservation::m_instrument
protected

Instrument name.

Definition at line 110 of file GCOSObservation.hpp.

Referenced by copy_members(), init_members(), instrument(), and read().

◆ m_livetime

double GCOSObservation::m_livetime
protected

Livetime (sec)

Definition at line 114 of file GCOSObservation.hpp.

Referenced by copy_members(), init_members(), livetime(), livetime(), and load().

◆ m_ontime

double GCOSObservation::m_ontime
protected

Ontime (sec)

Definition at line 113 of file GCOSObservation.hpp.

Referenced by copy_members(), init_members(), load(), ontime(), and ontime().

◆ m_response

GCOSResponse GCOSObservation::m_response
protected

Response functions.

Definition at line 111 of file GCOSObservation.hpp.

Referenced by copy_members(), init_members(), load(), response(), and response().

◆ m_rspname

GFilename GCOSObservation::m_rspname
protected

Response filename.

Definition at line 122 of file GCOSObservation.hpp.

Referenced by copy_members(), init_members(), load(), and write().

◆ m_spacecraft

GCOSSpaceCraft GCOSObservation::m_spacecraft
protected

Space craft information.

Definition at line 112 of file GCOSObservation.hpp.

Referenced by copy_members(), init_members(), load(), and spacecraft().

◆ m_spacename

GFilename GCOSObservation::m_spacename
protected

Space craft filename.

Definition at line 121 of file GCOSObservation.hpp.

Referenced by copy_members(), init_members(), load(), and write().


The documentation for this class was generated from the following files: