42#define G_AT "GObservations::at(int&)"
43#define G_SET "GObservations::set(int&, GObservation&)"
44#define G_APPEND "GObservations::append(GObservation&)"
45#define G_INSERT "GObservations::insert(int&, GObservation&)"
46#define G_REMOVE "GObservations::remove(int&)"
47#define G_EXTEND "GObservations::extend(GObservations&)"
48#define G_READ "GObservations::read(GXml&)"
49#define G_NPRED "GObservations::npred(std::string&, std::string&)"
211 if (index < 0 || index >=
size()) {
235 if (index < 0 || index >=
size()) {
264 #if defined(G_RANGE_CHECK)
265 if (index < 0 || index >=
size()) {
274 if (inx != -1 && inx != index) {
276 "Attempt to set \""+obs.
instrument()+
"\" observation with"
277 " identifier \""+obs.
id()+
"\" in observation container at"
278 " index "+
gammalib::str(index)+
", but an observation with the"
279 " same attributes exists already at index "+
gammalib::str(inx)+
280 " in the container.\n"
281 "Every observation for a given instrument in the observation"
282 " container needs a unique identifier.";
287 if (
m_obs[index] != NULL)
delete m_obs[index];
316 "Attempt to append \""+obs.
instrument()+
"\" observation with"
317 " identifier \""+obs.
id()+
"\" to observation container, but an"
318 " observation with the same attributes exists already at"
320 "Every observation for a given instrument in the observation"
321 " container needs a unique identifier.";
329 m_obs.push_back(ptr);
355 #if defined(G_RANGE_CHECK)
363 if (index < 0 || index >=
size()) {
373 if (inx != -1 && inx != index) {
375 "Attempt to insert \""+obs.
instrument()+
"\" observation with"
376 " identifier \""+obs.
id()+
"\" in observation container before"
377 " index "+
gammalib::str(index)+
", but an observation with the"
378 " same attributes exists already at index "+
gammalib::str(inx)+
379 " in the container.\n"
380 "Every observation for a given instrument in the observation"
381 " container needs a unique identifier.";
409 #if defined(G_RANGE_CHECK)
410 if (index < 0 || index >=
size()) {
446 int num = obs.
size();
453 for (
int i = 0; i < num; ++i) {
457 int inx =
get_index(obs[i]->instrument(), obs[i]->
id());
460 "Attempt to append \""+obs[i]->instrument()+
"\""
461 " observation with identifier \""+obs[i]->id()+
"\""
462 " to observation container, but an observation with the"
463 " same attributes exists already at index "+
465 "Every observation for a given instrument in the"
466 " observation container needs a unique identifier.";
494 const std::string&
id)
const
500 return (index != -1);
595 int n = lib->
elements(
"observation");
596 for (
int i = 0; i < n; ++i) {
602 std::string name = obs->
attribute(
"name");
604 std::string instrument = obs->
attribute(
"instrument");
624 std::string msg =
"Instrument \""+instrument+
"\" unknown. The "
625 "following instruments are available: "+
626 registry.
content()+
". Please specify one of "
627 "the available instruments.";
657 if (xml.
elements(
"observation_list") == 0) {
665 for (
int i = 0; i <
size(); ++i) {
671 int n = xml.
elements(
"observation");
672 for (
int k = 0; k < n; ++k) {
685 obs = lib->
append(
"observation");
692 m_obs[i]->write(*obs);
732 for (
int i = 0; i < nobs; ++i) {
781 int npars = pars.
size();
787 bool diag_loaded =
false;
790 for (
int i = 0; i < 2; ++i) {
796 for (
int ipar = 0; ipar < npars; ++ipar) {
799 if (x[ipar] >= 0.0) {
800 pars[ipar]->factor_error(
sqrt(x[ipar]));
803 pars[ipar]->factor_error(0.0);
814 std::cout <<
"Non-Positive definite hessian matrix encountered."
816 std::cout <<
"Load diagonal elements with 1e-10."
817 <<
" Fit errors may be inaccurate."
821 for (
int ipar = 0; ipar < npars; ++ipar) {
822 hessian(ipar,ipar) += 1.0e-10;
835 std::cout <<
"Non-Positive definite hessian matrix encountered,"
836 <<
" even after diagonal loading." << std::endl;
840 catch (std::exception &e) {
886 for (
int i = 0; i <
size(); ++i) {
909 const std::string& instrument)
const
916 std::string msg =
"Model \""+name+
"\" not found in observation "
917 "container. Please specify a valid model name.";
948 const std::string& instrument)
const
954 for (
int i = 0; i <
size(); ++i) {
958 if (!instrument.empty()) {
959 if ((*
this)[i]->instrument() != instrument) {
965 if (model.
is_valid(instrument,
"")) {
966 npred += (*this)[i]->npred(model);
1004 for (
int i = 0; i <
size(); ++i) {
1005 (*this)[i]->remove_response_cache(name);
1028 result.append(
"=== GObservations ===");
1045 for (
int i = 0; i <
size(); ++i) {
1046 result.append(
"\n");
1047 result.append((*
this)[i]->print(reduced_chatter));
1100 for (
int i = 0; i < obs.
m_obs.size(); ++i) {
1124 for (
int i = 0; i <
m_obs.size(); ++i) {
1147 const std::string&
id)
const
1153 for (
int i = 0; i <
size(); ++i) {
1154 if ((
m_obs[i]->instrument() == instrument) &&
1155 (
m_obs[i]->id() == id)) {
Exception handler interface definition.
Filename class interface definition.
Sparse matrix class definition.
Abstract model base class interface definition.
Observation registry class definition.
Observations container class interface definition.
Abstract optimizer abstract base class interface definition.
GVector sqrt(const GVector &vector)
Computes square root of vector elements.
XML class interface definition.
std::string url(void) const
Return Uniform Resource Locator (URL)
Sparse matrix class interface definition.
GMatrixSparse cholesky_decompose(const bool &compress=true) const
Return Cholesky decomposition.
GVector cholesky_solver(const GVector &vector, const bool &compress=true) const
Cholesky solver.
bool is_valid(const std::string &instruments, const std::string &ids) const
Verifies if model is valid for a given instrument and identifier.
bool contains(const std::string &name) const
Signals if model name exists.
void setup(const GObservation &obs) const
Setup all models for a given observation.
void clear(void)
Clear object.
void load(const GFilename &filename)
Load models from XML file.
GOptimizerPars pars(void) const
Return optimizer parameter container.
int size(void) const
Return number of models in container.
std::string print(const GChatter &chatter=NORMAL) const
Print models.
Interface definition for the observation registry class.
GObservation * alloc(const std::string &name) const
Allocate observation of given name.
Abstract observation base class.
virtual void read(const GXmlElement &xml)=0
virtual GObservation * clone(void) const =0
Clones object.
virtual std::string instrument(void) const =0
void name(const std::string &name)
Set observation name.
void id(const std::string &id)
Set observation identifier.
void set(GObservations *obs)
Set observation container.
virtual void eval(const GOptimizerPars &pars)
Evaluate log-likelihood function.
GMatrixSparse hessian(const GOptimizerPars &pars)
Compute Hessian matrix.
Observation container class.
bool contains(const std::string &instrument, const std::string &id) const
Signals if observation exists.
void init_members(void)
Initialise class members.
GObservations & operator=(const GObservations &obs)
Assignment operator.
std::vector< GObservation * > m_obs
List of observations.
void reserve(const int &num)
Reserves space for observations in container.
void copy_members(const GObservations &obs)
Copy class members.
void extend(const GObservations &obs)
Append observations from observation container.
void clear(void)
Clear observations.
double nobserved(void) const
Return total number of observed events.
GModels m_models
List of models.
int size(void) const
Return number of observations in container.
GObservations * clone(void) const
Clone observations.
GObservations::likelihood m_fct
Optimizer function.
void read(const GXml &xml)
Read observations from XML document.
bool is_empty(void) const
Signals if there are no observations in container.
void remove(const int &index)
Remove observation from container.
GObservation * set(const int &index, const GObservation &obs)
Set observation in container.
std::string print(const GChatter &chatter=NORMAL) const
Print observation list information.
virtual ~GObservations(void)
Destructor.
GObservations(void)
Void constructor.
void remove_response_cache(void)
Remove response cache for all models.
const GModels & models(void) const
Return model container.
void eval(void)
Evaluate function.
int get_index(const std::string &instrument, const std::string &id) const
Return observation index by instrument and identifier.
double npred(void) const
Return total number of predicted events in models.
void save(const GFilename &filename) const
Save observations into XML file.
void optimize(GOptimizer &opt)
Optimize model parameters using optimizer.
void errors(GOptimizer &opt)
Computes parameter errors using optimizer.
GObservation * insert(const int &index, const GObservation &obs)
Insert observation into container.
void write(GXml &xml) const
Write observations into XML document.
void errors_hessian(void)
Computes parameter errors using hessian matrix and optimizer.
void load(const GFilename &filename)
Load observations from XML file.
GObservation * append(const GObservation &obs)
Append observation to container.
void free_members(void)
Delete class members.
GObservation * at(const int &index)
Return pointer to observation.
Optimizer parameter container class.
int size(void) const
Return number of parameters in container.
Abstract optimizer abstract base class.
virtual void optimize(GOptimizerFunction &fct, GOptimizerPars &pars)=0
virtual void errors(GOptimizerFunction &fct, GOptimizerPars &pars)=0
std::string content(void) const
Return list of names in registry.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
virtual int elements(void) const
Return number of GXMLElement children of node.
void save(const GFilename &filename) const
Save XML document into file.
GXmlElement * element(const int &index)
Return pointer to child element.
GXmlNode * append(const GXmlNode &node)
Append child node to XML document root.
int elements(void) const
Return number of child elements in XML document root.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
GChatter reduce(const GChatter &chatter)
Reduce chattiness by one level.