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);
775 int npars = pars.
size();
781 bool diag_loaded =
false;
784 for (
int i = 0; i < 2; ++i) {
790 for (
int ipar = 0; ipar < npars; ++ipar) {
793 if (x[ipar] >= 0.0) {
794 pars[ipar]->factor_error(
sqrt(x[ipar]));
797 pars[ipar]->factor_error(0.0);
808 std::cout <<
"Non-Positive definite hessian matrix encountered."
810 std::cout <<
"Load diagonal elements with 1e-10."
811 <<
" Fit errors may be inaccurate."
815 for (
int ipar = 0; ipar < npars; ++ipar) {
816 hessian(ipar,ipar) += 1.0e-10;
829 std::cout <<
"Non-Positive definite hessian matrix encountered,"
830 <<
" even after diagonal loading." << std::endl;
834 catch (std::exception &e) {
880 for (
int i = 0; i <
size(); ++i) {
903 const std::string& instrument)
const
910 std::string msg =
"Model \""+name+
"\" not found in observation "
911 "container. Please specify a valid model name.";
942 const std::string& instrument)
const
948 for (
int i = 0; i <
size(); ++i) {
952 if (!instrument.empty()) {
953 if ((*
this)[i]->instrument() != instrument) {
959 if (model.
is_valid(instrument,
"")) {
960 npred += (*this)[i]->npred(model);
998 for (
int i = 0; i <
size(); ++i) {
999 (*this)[i]->remove_response_cache(name);
1022 result.append(
"=== GObservations ===");
1039 for (
int i = 0; i <
size(); ++i) {
1040 result.append(
"\n");
1041 result.append((*
this)[i]->print(reduced_chatter));
1094 for (
int i = 0; i < obs.
m_obs.size(); ++i) {
1118 for (
int i = 0; i <
m_obs.size(); ++i) {
1141 const std::string&
id)
const
1147 for (
int i = 0; i <
size(); ++i) {
1148 if ((
m_obs[i]->instrument() == instrument) &&
1149 (
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 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.
int nobserved(void) const
Return total number of observed events.
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.
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.