GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModel.cpp - Abstract virtual model base class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2009-2019 by Juergen Knoedlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GModel.cpp
23  * @brief Abstract model base class implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GTools.hpp"
32 #include "GException.hpp"
33 #include "GModel.hpp"
34 
35 /* __ Method name definitions ____________________________________________ */
36 #define G_ACCESS "GModel::operator[](std::string&)"
37 #define G_AT "GModel::at(int&)"
38 #define G_SCALE "GModelPar& GModel::scale(int&)"
39 #define G_WRITE_SCALES "GModel::write_scales(GXmlElement&)"
40 
41 /* __ Macros _____________________________________________________________ */
42 
43 /* __ Coding definitions _________________________________________________ */
44 
45 /* __ Debug definitions __________________________________________________ */
46 
47 
48 /*==========================================================================
49  = =
50  = Constructors/destructors =
51  = =
52  ==========================================================================*/
53 
54 /***********************************************************************//**
55  * @brief Void constructor
56  ***************************************************************************/
58 {
59  // Initialise members
60  init_members();
61 
62  // Return
63  return;
64 }
65 
66 
67 /***********************************************************************//**
68  * @brief XML constructor
69  *
70  * @param[in] xml XML element.
71  *
72  * Construct model from XML element. The method extracts all model attributes
73  * from the XML file (see the read_attributes() method for more information
74  * about the supported attributes).
75  ***************************************************************************/
77 {
78  // Initialise members
79  init_members();
80 
81  // Read attributes
82  read_attributes(xml);
83 
84  // Return
85  return;
86 }
87 
88 
89 /***********************************************************************//**
90  * @brief Copy constructor
91  *
92  * @param[in] model Model.
93  ***************************************************************************/
94 GModel::GModel(const GModel& model)
95 {
96  // Initialise members
97  init_members();
98 
99  // Copy members
100  copy_members(model);
101 
102  // Return
103  return;
104 }
105 
106 
107 /***********************************************************************//**
108  * @brief Destructor
109  ***************************************************************************/
111 {
112  // Free members
113  free_members();
114 
115  // Return
116  return;
117 }
118 
119 
120 /*==========================================================================
121  = =
122  = Operators =
123  = =
124  ==========================================================================*/
125 
126 /***********************************************************************//**
127  * @brief Assignment operator
128  *
129  * @param[in] model Model.
130  * @return Model.
131  ***************************************************************************/
133 {
134  // Execute only if object is not identical
135  if (this != &model) {
136 
137  // Free members
138  free_members();
139 
140  // Initialise private members for clean destruction
141  init_members();
142 
143  // Copy members
144  copy_members(model);
145 
146  } // endif: object was not identical
147 
148  // Return
149  return *this;
150 }
151 
152 
153 /***********************************************************************//**
154  * @brief Returns reference to model parameter by name
155  *
156  * @param[in] name Parameter name.
157  * @return Reference to model parameter.
158  *
159  * @exception GException::par_not_found
160  * Parameter with specified name not found in container.
161  *
162  * Returns a reference to the model parameter of the specified @p name.
163  * Throws an exception if no parameter with @p name is found.
164  ***************************************************************************/
165 GModelPar& GModel::operator[](const std::string& name)
166 {
167  // Get parameter index
168  int index = 0;
169  for (; index < size(); ++index) {
170  if (m_pars[index]->name() == name) {
171  break;
172  }
173  }
174 
175  // Throw exception if parameter name was not found
176  if (index >= size()) {
177  throw GException::par_not_found(G_ACCESS, name);
178  }
179 
180  // Return reference
181  return *(m_pars[index]);
182 }
183 
184 
185 /***********************************************************************//**
186  * @brief Returns reference to model parameter by name const version)
187  *
188  * @param[in] name Parameter name.
189  * @return Reference to model parameter.
190  *
191  * @exception GException::par_not_found
192  * Parameter with specified name not found in container.
193  *
194  * Returns a const reference to the model parameter of the specified
195  * @p name. Throws an exception if no parameter with @p name is found.
196  ***************************************************************************/
197 const GModelPar& GModel::operator[](const std::string& name) const
198 {
199  // Get parameter index
200  int index = 0;
201  for (; index < size(); ++index) {
202  if (m_pars[index]->name() == name) {
203  break;
204  }
205  }
206 
207  // Throw exception if parameter name was not found
208  if (index >= size()) {
209  throw GException::par_not_found(G_ACCESS, name);
210  }
211 
212  // Return reference
213  return *(m_pars[index]);
214 }
215 
216 
217 /*==========================================================================
218  = =
219  = Public methods =
220  = =
221  ==========================================================================*/
222 
223 /***********************************************************************//**
224  * @brief Returns reference to model parameter by index
225  *
226  * @param[in] index Parameter index [0,...,size()-1].
227  * @return Reference to model parameter.
228  *
229  * @exception GException::out_of_range
230  * Parameter index is out of range.
231  *
232  * Returns a reference to the model parameter of the specified @p index.
233  * Throws an exception if @p index is not valid.
234  ***************************************************************************/
235 GModelPar& GModel::at(const int& index)
236 {
237  // Raise exception if index is out of range
238  if (index < 0 || index >= size()) {
239  throw GException::out_of_range(G_AT, index, 0, size()-1);
240  }
241 
242  // Return reference
243  return *(m_pars[index]);
244 }
245 
246 
247 /***********************************************************************//**
248  * @brief Returns reference to model parameter by index (const version)
249  *
250  * @param[in] index Parameter index [0,...,size()-1].
251  * @return Const reference to model parameter.
252  *
253  * @exception GException::out_of_range
254  * Parameter index is out of range.
255  *
256  * Returns a const reference to the model parameter of the specified
257  * @p index. Throws an exception if @p index is not valid.
258  ***************************************************************************/
259 const GModelPar& GModel::at(const int& index) const
260 {
261  // Raise exception if index is out of range
262  if (index < 0 || index >= size()) {
263  throw GException::out_of_range(G_AT, index, 0, size()-1);
264  }
265 
266  // Return reference
267  return *(m_pars[index]);
268 }
269 
270 
271 /***********************************************************************//**
272  * @brief Checks if parameter name exists
273  *
274  * @param[in] name Parameter name.
275  * @return True if parameter with specified @p name exists.
276  *
277  * Searches all parameter names for a match with the specified @p name. If
278  * the specified name has been found, true is returned.
279  ***************************************************************************/
280 bool GModel::has_par(const std::string& name) const
281 {
282  // Default found flag to false
283  bool found = false;
284 
285  // Search for parameter name
286  for (int i = 0; i < size(); ++i) {
287  if (m_pars[i]->name() == name) {
288  found = true;
289  break;
290  }
291  }
292 
293  // Return
294  return found;
295 }
296 
297 
298 /***********************************************************************//**
299  * @brief Returns instruments to which model applies
300  *
301  * Returns a comma separated list of instruments to which model applies. If
302  * no instrument exists then an empty string is returned.
303  ***************************************************************************/
304 std::string GModel::instruments(void) const
305 {
306  // Initialise string
307  std::string result;
308 
309  // Attach all instruments
310  for (int i = 0; i < m_instruments.size(); ++i) {
311  if (i > 0) {
312  result += ",";
313  }
314  result += m_instruments[i];
315  }
316 
317  // Return
318  return result;
319 }
320 
321 
322 /***********************************************************************//**
323  * @brief Set instruments to which model applies
324  *
325  * @param[in] instruments String of instruments.
326  *
327  * Sets the instruments to which the model applies from a comma separated
328  * list of strings. The instrument names are case sensitive.
329  *
330  * If the @p instrument string is empty, the model is considered to apply to
331  * all instruments.
332  ***************************************************************************/
333 void GModel::instruments(const std::string& instruments)
334 {
335  // Clear instruments vector
336  m_instruments.clear();
337 
338  // Extract instruments
339  std::vector<std::string> inst = gammalib::split(instruments, ",");
340 
341  // Attach all instruments
342  for (int i = 0; i < inst.size(); ++i) {
343  m_instruments.push_back(gammalib::strip_whitespace(inst[i]));
344  }
345 
346  // Return
347  return;
348 }
349 
350 
351 /***********************************************************************//**
352  * @brief Returns reference to scale parameter by index
353  *
354  * @param[in] index Parameter index [0,...,size()-1].
355  * @return Reference to scale parameter.
356  *
357  * @exception GException::out_of_range
358  * Scale parameter index is out of range.
359  *
360  * Returns a reference to the scale parameter of the specified @p index.
361  * Throws an exception if @p index is not valid.
362  ***************************************************************************/
363 GModelPar& GModel::scale(const int& index)
364 {
365  // Raise exception if index is out of range
366  if (index < 0 || index >= scales()) {
367  throw GException::out_of_range(G_SCALE, index, scales());
368  }
369 
370  // Return reference
371  return (m_scales[index]);
372 }
373 
374 
375 /***********************************************************************//**
376  * @brief Returns reference to scale parameter by index (const version)
377  *
378  * @param[in] index Parameter index [0,...,size()-1].
379  * @return Reference to scale parameter.
380  *
381  * @exception GException::out_of_range
382  * Scale parameter index is out of range.
383  *
384  * Returns a reference to the scale parameter of the specified @p index.
385  * Throws an exception if @p index is not valid.
386  ***************************************************************************/
387 const GModelPar& GModel::scale(const int& index) const
388 {
389  // Raise exception if index is out of range
390  if (index < 0 || index >= scales()) {
391  throw GException::out_of_range(G_SCALE, index, scales());
392  }
393 
394  // Return reference
395  return (m_scales[index]);
396 }
397 
398 
399 /***********************************************************************//**
400  * @brief Returns model scale factor for a given instrument
401  *
402  * @param[in] instrument Instrument.
403  *
404  * Returns the model scale factor for a given @p instrument. The search is
405  * case sensitive.
406  *
407  * If the @p instrument is not found, the method returns a scale factor of
408  * unity.
409  ***************************************************************************/
410 GModelPar GModel::scale(const std::string& instrument) const
411 {
412  // Initialise unit scale factor
414  scale.value(1.0);
415  scale.name(instrument);
416  scale.fix();
417 
418  // Search for instrument and recover scale factor if the instrument
419  // has been found.
420  for (int i = 0; i < m_scales.size(); ++i) {
421  if (m_scales[i].name() == instrument) {
422  scale = m_scales[i];
423  break;
424  }
425  }
426 
427  // Return scale factor
428  return scale;
429 }
430 
431 
432 /***********************************************************************//**
433  * @brief Set model scale factor for a given instrument
434  *
435  * @param[in] par Model parameter for scaling.
436  *
437  * Sets the model parameter for a given instrument. The instrument name is
438  * case sensitive, but any leading to trailing white space will be stripped.
439  *
440  * If the instrument is not yet defined it will be appended to the list of
441  * instruments.
442  ***************************************************************************/
443 void GModel::scale(const GModelPar& par)
444 {
445  // String leading and trailing while space
446  std::string instrument = gammalib::strip_whitespace(par.name());
447 
448  // Search for instrument and copy the model parameter if the instrument
449  // has been found. Make sure that the instrument name is in upper case.
450  bool found = false;
451  for (int i = 0; i < m_scales.size(); ++i) {
452  if (m_scales[i].name() == instrument) {
453  found = true;
454  m_scales[i] = par;
455  m_scales[i].name(instrument);
456  m_scales[i].has_grad(true);
457  break;
458  }
459  }
460 
461  // If instrument has not been found then append it now to the list
462  // of instruments.
463  if (!found) {
464 
465  // Push scale parameter in list
466  m_scales.push_back(par);
467 
468  // Get index of last scale parameter
469  int i = m_scales.size()-1;
470 
471  // Set instrument name and signal availability of gradient
472  m_scales[i].name(instrument);
473  m_scales[i].has_grad(true);
474 
475  // Push scale parameter on parameter stack
476  m_pars.push_back(&m_scales[i]);
477 
478  } // endif: new scale parameter
479 
480  // Return
481  return;
482 }
483 
484 
485 /***********************************************************************//**
486  * @brief Returns observation identifiers to which model applies
487  *
488  * Returns a comma separated list of observation identifiers to which model
489  * applies. If no observation identifier exists then an empty string is
490  * returned.
491  ***************************************************************************/
492 std::string GModel::ids(void) const
493 {
494  // Initialise string
495  std::string result;
496 
497  // Attach all observation identifiers
498  for (int i = 0; i < m_ids.size(); ++i) {
499  if (i > 0) {
500  result += ",";
501  }
502  result += m_ids[i];
503  }
504 
505  // Return
506  return result;
507 }
508 
509 
510 /***********************************************************************//**
511  * @brief Set observation identifiers to which model applies
512  *
513  * @param[in] ids String of observation identifiers.
514  *
515  * Sets the observation identifiers to which the model applies from a comma
516  * separated list of strings. The observation identifiers are case sensitive,
517  * but any leading and trailing whitespace will be stripped.
518  *
519  * If the observation identifier string is empty, the model is considered to
520  * apply to all observation identifiers.
521  ***************************************************************************/
522 void GModel::ids(const std::string& ids)
523 {
524  // Clear observation identifier vector
525  m_ids.clear();
526 
527  // Extract observation identifiers
528  std::vector<std::string> id = gammalib::split(ids, ",");
529 
530  // Attach all observation identifiers
531  for (int i = 0; i < id.size(); ++i) {
532  m_ids.push_back(gammalib::strip_whitespace(id[i]));
533  }
534 
535  // Return
536  return;
537 }
538 
539 
540 /***********************************************************************//**
541  * @brief Verifies if model is valid for a given instrument and identifier
542  *
543  * @param[in] instrument Instrument name.
544  * @param[in] id Observation identifier.
545  * @return Validity flag
546  *
547  * Checks if specified instrument name and observation identifier is in list
548  * of applicable instruments and identifiers. The check is case sensitive.
549  *
550  * If the list of applicable instruments is empty, the model applies to all
551  * possible instruments. If the list of applicable observation identifiers
552  * is empty, the model applies to all identifiers.
553  *
554  * If an empty string is provided as @p instrument parameter, the check for
555  * instrument validity will be skipped. Similarily, if an empty string is
556  * provided as @p id parameter, the identifier check will be skipped. This
557  * allows for example to check for models of a given identifier whatever the
558  * instrument, or for models for a given instrument, whatever the identifier.
559  ***************************************************************************/
560 bool GModel::is_valid(const std::string& instrument,
561  const std::string& id) const
562 {
563  // Initialise validity
564  bool valid = true;
565 
566  // Check if model applies to instrument
567  if (!m_instruments.empty() && !instrument.empty()) {
568 
569  // Initialise validity flag
570  valid = false;
571 
572  // Check if instrument is in list
573  for (int i = 0; i < m_instruments.size(); ++i) {
574  if (instrument == m_instruments[i]) {
575  valid = true;
576  break;
577  }
578  }
579 
580  }
581 
582  // Check if model applies to observation identifier
583  if (valid && !m_ids.empty() && !id.empty()) {
584 
585  // Initialise validity flag
586  valid = false;
587 
588  // Check if name is in list
589  for (int i = 0; i < m_ids.size(); ++i) {
590  if (id == m_ids[i]) {
591  valid = true;
592  break;
593  }
594  }
595 
596  }
597 
598  // Return
599  return valid;
600 }
601 
602 
603 /*==========================================================================
604  = =
605  = Private methods =
606  = =
607  ==========================================================================*/
608 
609 /***********************************************************************//**
610  * @brief Initialise class members
611  ***************************************************************************/
613 {
614  // Initialise members
615  m_name.clear();
616  m_instruments.clear();
617  m_scales.clear();
618  m_ids.clear();
619  m_pars.clear();
620  m_ts = 0.0;
621  m_has_ts = false;
622  m_has_tscalc = false;
623  m_tscalc = false;
624 
625  // Return
626  return;
627 }
628 
629 
630 /***********************************************************************//**
631  * @brief Copy class members
632  *
633  * @param[in] model Model.
634  ***************************************************************************/
635 void GModel::copy_members(const GModel& model)
636 {
637  // Copy members
638  m_name = model.m_name;
640  m_scales = model.m_scales;
641  m_ids = model.m_ids;
642  m_pars = model.m_pars;
643  m_ts = model.m_ts;
644  m_has_ts = model.m_has_ts;
645  m_has_tscalc = model.m_has_tscalc;
646  m_tscalc = model.m_tscalc;
647 
648  // Return
649  return;
650 }
651 
652 
653 /***********************************************************************//**
654  * @brief Delete class members
655  ***************************************************************************/
657 {
658  // Return
659  return;
660 }
661 
662 
663 /***********************************************************************//**
664  * @brief Read model attributes
665  *
666  * @param[in] xml XML element.
667  ***************************************************************************/
669 {
670  // Set model name
671  name(xml.attribute("name"));
672 
673  // Set instruments
674  instruments(xml.attribute("instrument"));
675 
676  // Set observation identifiers
677  ids(xml.attribute("id"));
678 
679  // Set model TS
680  if (xml.has_attribute("ts")) {
681  std::string ts = xml.attribute("ts");
682  this->ts(gammalib::todouble(ts));
683  }
684 
685  // Set TS computation flag
686  if (xml.has_attribute("tscalc")) {
687  bool tscalc = (xml.attribute("tscalc") == "1") ? true : false;
688  this->tscalc(tscalc);
689  }
690 
691  // Read instrument scales
692  read_scales(xml);
693 
694  // Return
695  return;
696 }
697 
698 
699 /***********************************************************************//**
700  * @brief Write model attributes
701  *
702  * @param[in] xml XML element.
703  ***************************************************************************/
705 {
706  // Set model name
707  xml.attribute("name", name());
708 
709  // Set model type
710  xml.attribute("type", type());
711 
712  // Set instruments
713  std::string instruments = this->instruments();
714  if (instruments.length() > 0) {
715  xml.attribute("instrument", instruments);
716  }
717 
718  // Set observation identifiers
719  std::string identifiers = ids();
720  if (identifiers.length() > 0) {
721  xml.attribute("id", identifiers);
722  }
723 
724  // If available, set "ts" attribute
725  if (m_has_ts) {
726  xml.attribute("ts", gammalib::str(ts(), 3));
727  }
728 
729  // If available, set "tscalc" attribute
730  if (m_has_tscalc) {
731  std::string ts_calc = tscalc() ? "1" : "0";
732  xml.attribute("tscalc", ts_calc);
733  }
734 
735  // Write instrument scales
736  write_scales(xml);
737 
738  // Return
739  return;
740 }
741 
742 
743 /***********************************************************************//**
744  * @brief Print model attributes
745  *
746  * @return Returns string with model attributes.
747  ***************************************************************************/
748 std::string GModel::print_attributes(void) const
749 {
750  // Initialise result string
751  std::string result;
752 
753  // Append model name
754  result.append(gammalib::parformat("Name")+name());
755 
756  // Append instruments
757  result.append("\n"+gammalib::parformat("Instruments"));
758  if (!m_instruments.empty()) {
759  for (int i = 0; i < m_instruments.size(); ++i) {
760  if (i > 0) {
761  result.append(", ");
762  }
763  result.append(m_instruments[i]);
764  }
765  }
766  else {
767  result.append("all");
768  }
769 
770  // Append Test Statistic
771  if (m_has_ts) {
772  result.append("\n"+gammalib::parformat("Test Statistic"));
773  result.append(gammalib::str(ts()));
774  }
775  else if (m_tscalc) {
776  result.append("\n"+gammalib::parformat("Test Statistic"));
777  result.append("Computation requested");
778  }
779 
780  // Append observation identifiers
781  result.append("\n"+gammalib::parformat("Observation identifiers"));
782  if (!m_ids.empty()) {
783  for (int i = 0; i < m_ids.size(); ++i) {
784  if (i > 0) {
785  result.append(", ");
786  }
787  result.append(m_ids[i]);
788  }
789  }
790  else {
791  result.append("all");
792  }
793 
794  // Return result
795  return result;
796 }
797 
798 
799 /***********************************************************************//**
800  * @brief Read instrument scales from XML element
801  *
802  * @param[in] xml XML source element.
803  *
804  * Reads the instrument scale factors from a tag with the following format
805  *
806  * <scaling>
807  * <instrument name="LAT" scale="1.0" min="0.1" max="10.0" value="1.0" free="0"/>
808  * <instrument name="CTA" scale="1.0" min="0.1" max="10.0" value="0.5" free="0"/>
809  * </scaling>
810  *
811  * The instrument name is case sensitive, but any leading and trailing white
812  * space will be removed.
813  *
814  * If no scaling tag is found, all instrument scale factors will be cleared.
815  ***************************************************************************/
817 {
818  // Clear any existing scales
819  m_scales.clear();
820 
821  // Continue only if there is a <scaling> tag
822  if (xml.elements("scaling") != 0) {
823 
824  // Get pointer on first instrument scale factors
825  const GXmlElement* scales = xml.element("scaling", 0);
826 
827  // Determine number of scale factors
828  int nscales = scales->elements("instrument");
829 
830  // Read all scale factors
831  for (int i = 0; i < nscales; ++i) {
832  const GXmlElement* par = scales->element("instrument", i);
834  scale.read(*par);
835  scale.name(gammalib::strip_whitespace(par->attribute("name")));
836  scale.has_grad(true);
837  m_scales.push_back(scale);
838  m_pars.push_back(&m_scales[m_scales.size()-1]);
839  }
840 
841  }
842 
843  // Return
844  return;
845 }
846 
847 
848 /***********************************************************************//**
849  * @brief Write instrument scales into XML element
850  *
851  * @param[in] xml XML source element.
852  *
853  * @exception GException::model_invalid_parnum
854  * Invalid number of instrument tags found in XML element.
855  *
856  * If there are instrument scale factors then add a tag with the following
857  * format to the XML element:
858  *
859  * <scaling>
860  * <instrument name="LAT" scale="1" min="0.1" max="10" value="1.0" free="0"/>
861  * <instrument name="CTA" scale="1" min="0.1" max="10" value="0.5" free="0"/>
862  * </scaling>
863  ***************************************************************************/
865 {
866  // Continue only is scale factors are present
867  if (!m_scales.empty()) {
868 
869  // Get number of instruments
870  int num = m_scales.size();
871 
872  // Initialise scaling tag
873  GXmlElement* scale = NULL;
874 
875  // If no <scaling> tag exists then add one now with the required
876  // number of instruments ...
877  if (xml.elements("scaling") == 0) {
878  scale = xml.append("scaling");
879  for (int i = 0; i < num; ++i) {
880  scale->append(GXmlElement("instrument"));
881  }
882  }
883 
884  // ... otherwise get first tag
885  else {
886  scale = xml.element("scaling", 0);
887  }
888 
889  // Verify that scaling tag has the required number of instruments
890  if (scale->elements() != num || scale->elements("instrument") != num) {
892  "Instrument scaling needs "+gammalib::str(num)+" instrument tags.");
893  }
894 
895  // Write all instruments
896  for (int i = 0; i < num; ++i) {
897 
898  // Get instrument element
899  GXmlElement* inst = scale->element("instrument", i);
900 
901  // Set instrument name
902  inst->attribute("name", m_scales[i].name());
903 
904  // Write instrument scaling factor
905  m_scales[i].write(*inst);
906 
907  } // endfor: looped over all instruments
908 
909  }
910 
911  // Return
912  return;
913 }
virtual ~GModel(void)
Destructor.
Definition: GModel.cpp:110
Abstract model class.
Definition: GModel.hpp:97
void free_members(void)
Delete class members.
Definition: GModel.cpp:656
int scales(void) const
Return number of scale parameters in model.
Definition: GModel.hpp:231
Abstract model base class interface definition.
const std::string & name(void) const
Return parameter name.
std::string print_attributes(void) const
Print model attributes.
Definition: GModel.cpp:748
double m_ts
Test Statistic of the model.
Definition: GModel.hpp:173
XML element node class.
Definition: GXmlElement.hpp:47
#define G_AT
Definition: GModel.cpp:37
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split string.
Definition: GTools.cpp:860
virtual int elements(void) const
Return number of GXMLElement children of node.
Definition: GXmlNode.cpp:580
Gammalib tools definition.
std::string ids(void) const
Returns observation identifiers to which model applies.
Definition: GModel.cpp:492
bool m_tscalc
Signals if TS should be computed.
Definition: GModel.hpp:172
#define G_ACCESS
Definition: GModel.cpp:36
std::string strip_whitespace(const std::string &arg)
Strip leading and trailing whitespace from string.
Definition: GTools.cpp:71
bool has_par(const std::string &name) const
Checks if parameter name exists.
Definition: GModel.cpp:280
bool m_has_ts
Signals if TS is available.
Definition: GModel.hpp:170
std::vector< GModelPar > m_scales
Model instrument scale factors.
Definition: GModel.hpp:167
bool m_has_tscalc
Signals if tscalc attribute is available.
Definition: GModel.hpp:171
#define G_SCALE
Definition: GModel.cpp:38
#define G_WRITE_SCALES
Definition: GModel.cpp:39
std::vector< GModelPar * > m_pars
Pointers to all model parameters.
Definition: GModel.hpp:169
int size(void) const
Return number of parameters in model.
Definition: GModel.hpp:217
void init_members(void)
Initialise class members.
Definition: GModel.cpp:612
bool is_valid(const std::string &instruments, const std::string &ids) const
Verifies if model is valid for a given instrument and identifier.
Definition: GModel.cpp:560
Model parameter class.
Definition: GModelPar.hpp:87
std::vector< std::string > m_instruments
Instruments to which model applies.
Definition: GModel.hpp:166
void copy_members(const GModel &model)
Copy class members.
Definition: GModel.cpp:635
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
GModelPar & at(const int &index)
Returns reference to model parameter by index.
Definition: GModel.cpp:235
virtual GModelPar & operator[](const int &index)
Returns reference to model parameter by index.
Definition: GModel.hpp:186
const GXmlAttribute * attribute(const int &index) const
Return attribute.
const std::string & name(void) const
Return parameter name.
Definition: GModel.hpp:245
void fix(void)
Fix a parameter.
bool has_attribute(const std::string &name) const
Check if element has a given attribute.
std::vector< std::string > m_ids
Identifiers to which model applies.
Definition: GModel.hpp:168
std::string instruments(void) const
Returns instruments to which model applies.
Definition: GModel.cpp:304
const double & ts(void) const
Return Test Statistic value.
Definition: GModel.hpp:275
GModelPar & scale(const int &index)
Returns reference to scale parameter by index.
Definition: GModel.cpp:363
void write_attributes(GXmlElement &xml) const
Write model attributes.
Definition: GModel.cpp:704
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
Definition: GXmlNode.cpp:634
std::string m_name
Model name.
Definition: GModel.hpp:165
GModel(void)
Void constructor.
Definition: GModel.cpp:57
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
Definition: GModelPar.cpp:229
double value(void) const
Return parameter value.
virtual std::string type(void) const =0
Exception handler interface definition.
void read_scales(const GXmlElement &xml)
Read instrument scales from XML element.
Definition: GModel.cpp:816
void read_attributes(const GXmlElement &xml)
Read model attributes.
Definition: GModel.cpp:668
virtual GModel & operator=(const GModel &model)
Assignment operator.
Definition: GModel.cpp:132
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
Definition: GXmlNode.cpp:284
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1020
void write_scales(GXmlElement &xml) const
Write instrument scales into XML element.
Definition: GModel.cpp:864
const bool & tscalc(void) const
Return Test Statistic computation flag.
Definition: GModel.hpp:309
double todouble(const std::string &arg)
Convert string into double precision value.
Definition: GTools.cpp:803
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:411