GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GModel.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModel.cpp - Abstract virtual model base class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2009-2024 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
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
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 ***************************************************************************/
95{
96 // Initialise 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::invalid_argument
160 * Parameter with specified name not found.
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 ***************************************************************************/
165GModelPar& 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 std::string msg = "Model parameter \""+name+"\" not found in model. "
178 "Please specify a valid model parameter name.";
180 }
181
182 // Return reference
183 return *(m_pars[index]);
184}
185
186
187/***********************************************************************//**
188 * @brief Returns reference to model parameter by name const version)
189 *
190 * @param[in] name Parameter name.
191 * @return Reference to model parameter.
192 *
193 * @exception GException::invalid_argument
194 * Parameter with specified name not found.
195 *
196 * Returns a const reference to the model parameter of the specified
197 * @p name. Throws an exception if no parameter with @p name is found.
198 ***************************************************************************/
199const GModelPar& GModel::operator[](const std::string& name) const
200{
201 // Get parameter index
202 int index = 0;
203 for (; index < size(); ++index) {
204 if (m_pars[index]->name() == name) {
205 break;
206 }
207 }
208
209 // Throw exception if parameter name was not found
210 if (index >= size()) {
211 std::string msg = "Model parameter \""+name+"\" not found in model. "
212 "Please specify a valid model parameter name.";
214 }
215
216 // Return reference
217 return *(m_pars[index]);
218}
219
220
221/*==========================================================================
222 = =
223 = Public methods =
224 = =
225 ==========================================================================*/
226
227/***********************************************************************//**
228 * @brief Setup model for a given observation
229 *
230 * @param[in] obs Observation.
231 *
232 * Dummy setup hook for model that does nothing. This dummy hook may be
233 * overwritten by the derived class in case that a setup is needed.
234 ***************************************************************************/
235void GModel::setup(const GObservation& obs) const
236{
237 // Return
238 return;
239}
240
241
242/***********************************************************************//**
243 * @brief Returns reference to model parameter by index
244 *
245 * @param[in] index Parameter index [0,...,size()[.
246 * @return Reference to model parameter.
247 *
248 * @exception GException::out_of_range
249 * Parameter index is out of range.
250 *
251 * Returns a reference to the model parameter of the specified @p index.
252 * Throws an exception if @p index is not valid.
253 ***************************************************************************/
254GModelPar& GModel::at(const int& index)
255{
256 // Raise exception if index is out of range
257 if (index < 0 || index >= size()) {
258 throw GException::out_of_range(G_AT, "Parameter index", index, size());
259 }
260
261 // Return reference
262 return *(m_pars[index]);
263}
264
265
266/***********************************************************************//**
267 * @brief Returns reference to model parameter by index (const version)
268 *
269 * @param[in] index Parameter index [0,...,size()[.
270 * @return Const reference to model parameter.
271 *
272 * @exception GException::out_of_range
273 * Parameter index is out of range.
274 *
275 * Returns a const reference to the model parameter of the specified
276 * @p index. Throws an exception if @p index is not valid.
277 ***************************************************************************/
278const GModelPar& GModel::at(const int& index) const
279{
280 // Raise exception if index is out of range
281 if (index < 0 || index >= size()) {
282 throw GException::out_of_range(G_AT, "Parameter index", index, size());
283 }
284
285 // Return reference
286 return *(m_pars[index]);
287}
288
289
290/***********************************************************************//**
291 * @brief Checks if parameter name exists
292 *
293 * @param[in] name Parameter name.
294 * @return True if parameter with specified @p name exists.
295 *
296 * Searches all parameter names for a match with the specified @p name. If
297 * the specified name has been found, true is returned.
298 ***************************************************************************/
299bool GModel::has_par(const std::string& name) const
300{
301 // Default found flag to false
302 bool found = false;
303
304 // Search for parameter name
305 for (int i = 0; i < size(); ++i) {
306 if (m_pars[i]->name() == name) {
307 found = true;
308 break;
309 }
310 }
311
312 // Return
313 return found;
314}
315
316
317/***********************************************************************//**
318 * @brief Returns instruments to which model applies
319 *
320 * @return Instruments.
321 *
322 * Returns a comma separated list of instruments to which model applies. If
323 * no instrument exists then an empty string is returned.
324 ***************************************************************************/
325std::string GModel::instruments(void) const
326{
327 // Initialise string
328 std::string result;
329
330 // Attach all instruments
331 for (int i = 0; i < m_instruments.size(); ++i) {
332 if (i > 0) {
333 result += ",";
334 }
335 result += m_instruments[i];
336 }
337
338 // Return
339 return result;
340}
341
342
343/***********************************************************************//**
344 * @brief Set instruments to which model applies
345 *
346 * @param[in] instruments String of instruments.
347 *
348 * Sets the instruments to which the model applies from a comma separated
349 * list of strings. The instrument names are case sensitive.
350 *
351 * If the @p instrument string is empty, the model is considered to apply to
352 * all instruments.
353 ***************************************************************************/
354void GModel::instruments(const std::string& instruments)
355{
356 // Clear instruments vector
357 m_instruments.clear();
358
359 // Extract instruments
360 std::vector<std::string> inst = gammalib::split(instruments, ",");
361
362 // Attach all instruments
363 for (int i = 0; i < inst.size(); ++i) {
364 m_instruments.push_back(gammalib::strip_whitespace(inst[i]));
365 }
366
367 // Return
368 return;
369}
370
371
372/***********************************************************************//**
373 * @brief Returns reference to scale parameter by index
374 *
375 * @param[in] index Scale parameter index [0,...,scales()[.
376 * @return Reference to scale parameter.
377 *
378 * @exception GException::out_of_range
379 * Scale parameter index is out of range.
380 *
381 * Returns a reference to the scale parameter of the specified @p index.
382 * Throws an exception if @p index is not valid.
383 ***************************************************************************/
384GModelPar& GModel::scale(const int& index)
385{
386 // Raise exception if index is out of range
387 if (index < 0 || index >= scales()) {
388 throw GException::out_of_range(G_SCALE, "Scale parameter index",
389 index, scales());
390 }
391
392 // Return reference
393 return (m_scales[index]);
394}
395
396
397/***********************************************************************//**
398 * @brief Returns reference to scale parameter by index (const version)
399 *
400 * @param[in] index Scale parameter index [0,...,scales()[.
401 * @return Reference to scale parameter.
402 *
403 * @exception GException::out_of_range
404 * Scale parameter index is out of range.
405 *
406 * Returns a reference to the scale parameter of the specified @p index.
407 * Throws an exception if @p index is not valid.
408 ***************************************************************************/
409const GModelPar& GModel::scale(const int& index) const
410{
411 // Raise exception if index is out of range
412 if (index < 0 || index >= scales()) {
413 throw GException::out_of_range(G_SCALE, "Scale parameter index",
414 index, scales());
415 }
416
417 // Return reference
418 return (m_scales[index]);
419}
420
421
422/***********************************************************************//**
423 * @brief Returns model scale factor for a given instrument
424 *
425 * @param[in] instrument Instrument.
426 *
427 * Returns the model scale factor for a given @p instrument. The search is
428 * case sensitive.
429 *
430 * If the @p instrument is not found, the method returns a scale factor of
431 * unity.
432 ***************************************************************************/
433GModelPar GModel::scale(const std::string& instrument) const
434{
435 // Initialise unit scale factor
437 scale.value(1.0);
438 scale.name(instrument);
439 scale.fix();
440
441 // Search for instrument and recover scale factor if the instrument
442 // has been found.
443 for (int i = 0; i < m_scales.size(); ++i) {
444 if (m_scales[i].name() == instrument) {
445 scale = m_scales[i];
446 break;
447 }
448 }
449
450 // Return scale factor
451 return scale;
452}
453
454
455/***********************************************************************//**
456 * @brief Set model scale factor for a given instrument
457 *
458 * @param[in] par Model parameter for scaling.
459 *
460 * Sets the model parameter for a given instrument. The instrument name is
461 * case sensitive, but any leading to trailing white space will be stripped.
462 *
463 * If the instrument is not yet defined it will be appended to the list of
464 * instruments.
465 ***************************************************************************/
466void GModel::scale(const GModelPar& par)
467{
468 // String leading and trailing while space
469 std::string instrument = gammalib::strip_whitespace(par.name());
470
471 // Search for instrument and copy the model parameter if the instrument
472 // has been found. Make sure that the instrument name is in upper case.
473 bool found = false;
474 for (int i = 0; i < m_scales.size(); ++i) {
475 if (m_scales[i].name() == instrument) {
476 found = true;
477 m_scales[i] = par;
478 m_scales[i].name(instrument);
479 m_scales[i].has_grad(true);
480 break;
481 }
482 }
483
484 // If instrument has not been found then append it now to the list
485 // of instruments.
486 if (!found) {
487
488 // Push scale parameter in list
489 m_scales.push_back(par);
490
491 // Get index of last scale parameter
492 int i = m_scales.size()-1;
493
494 // Set instrument name and signal availability of gradient
495 m_scales[i].name(instrument);
496 m_scales[i].has_grad(true);
497
498 // Push scale parameter on parameter stack
499 m_pars.push_back(&m_scales[i]);
500
501 } // endif: new scale parameter
502
503 // Return
504 return;
505}
506
507
508/***********************************************************************//**
509 * @brief Returns observation identifiers to which model applies
510 *
511 * @return Observation identifiers.
512 *
513 * Returns a comma separated list of observation identifiers to which model
514 * applies. If no observation identifier exists then an empty string is
515 * returned.
516 ***************************************************************************/
517std::string GModel::ids(void) const
518{
519 // Initialise string
520 std::string result;
521
522 // Attach all observation identifiers
523 for (int i = 0; i < m_ids.size(); ++i) {
524 if (i > 0) {
525 result += ",";
526 }
527 result += m_ids[i];
528 }
529
530 // Return
531 return result;
532}
533
534
535/***********************************************************************//**
536 * @brief Set observation identifiers to which model applies
537 *
538 * @param[in] ids String of observation identifiers.
539 *
540 * Sets the observation identifiers to which the model applies from a comma
541 * separated list of strings. The observation identifiers are case sensitive,
542 * but any leading and trailing whitespace will be stripped.
543 *
544 * If the observation identifier string is empty, the model is considered to
545 * apply to all observation identifiers.
546 ***************************************************************************/
547void GModel::ids(const std::string& ids)
548{
549 // Clear observation identifier vector
550 m_ids.clear();
551
552 // Extract observation identifiers
553 std::vector<std::string> id = gammalib::split(ids, ",");
554
555 // Attach all observation identifiers
556 for (int i = 0; i < id.size(); ++i) {
557 m_ids.push_back(gammalib::strip_whitespace(id[i]));
558 }
559
560 // Return
561 return;
562}
563
564
565/***********************************************************************//**
566 * @brief Verifies if model is valid for a given instrument and identifier
567 *
568 * @param[in] instrument Instrument name.
569 * @param[in] id Observation identifier.
570 * @return Validity flag.
571 *
572 * Checks if specified instrument name and observation identifier is in list
573 * of applicable instruments and identifiers. The check is case sensitive.
574 *
575 * If the list of applicable instruments is empty, the model applies to all
576 * possible instruments. If the list of applicable observation identifiers
577 * is empty, the model applies to all identifiers.
578 *
579 * If an empty string is provided as @p instrument parameter, the check for
580 * instrument validity will be skipped. Similarily, if an empty string is
581 * provided as @p id parameter, the identifier check will be skipped. This
582 * allows for example to check for models of a given identifier whatever the
583 * instrument, or for models for a given instrument, whatever the identifier.
584 ***************************************************************************/
585bool GModel::is_valid(const std::string& instrument,
586 const std::string& id) const
587{
588 // Initialise validity
589 bool valid = true;
590
591 // Check if model applies to instrument
592 if (!m_instruments.empty() && !instrument.empty()) {
593
594 // Initialise validity flag
595 valid = false;
596
597 // Check if instrument is in list
598 for (int i = 0; i < m_instruments.size(); ++i) {
599 if (instrument == m_instruments[i]) {
600 valid = true;
601 break;
602 }
603 }
604
605 }
606
607 // Check if model applies to observation identifier
608 if (valid && !m_ids.empty() && !id.empty()) {
609
610 // Initialise validity flag
611 valid = false;
612
613 // Check if name is in list
614 for (int i = 0; i < m_ids.size(); ++i) {
615 if (id == m_ids[i]) {
616 valid = true;
617 break;
618 }
619 }
620
621 }
622
623 // Return
624 return valid;
625}
626
627
628/*==========================================================================
629 = =
630 = Private methods =
631 = =
632 ==========================================================================*/
633
634/***********************************************************************//**
635 * @brief Initialise class members
636 ***************************************************************************/
638{
639 // Initialise members
640 m_name.clear();
641 m_instruments.clear();
642 m_scales.clear();
643 m_ids.clear();
644 m_pars.clear();
646 m_ts = 0.0;
647 m_has_ts = false;
648 m_has_tscalc = false;
649 m_tscalc = false;
650 m_has_eval_inx = false;
651 m_eval_inx.clear();
652
653 // Return
654 return;
655}
656
657
658/***********************************************************************//**
659 * @brief Copy class members
660 *
661 * @param[in] model Model.
662 ***************************************************************************/
663void GModel::copy_members(const GModel& model)
664{
665 // Copy members
666 m_name = model.m_name;
668 m_scales = model.m_scales;
669 m_ids = model.m_ids;
670 m_pars = model.m_pars;
672 m_ts = model.m_ts;
673 m_has_ts = model.m_has_ts;
675 m_tscalc = model.m_tscalc;
677 m_eval_inx = model.m_eval_inx;
678
679 // Return
680 return;
681}
682
683
684/***********************************************************************//**
685 * @brief Delete class members
686 ***************************************************************************/
688{
689 // Return
690 return;
691}
692
693
694/***********************************************************************//**
695 * @brief Read model attributes
696 *
697 * @param[in] xml XML element.
698 ***************************************************************************/
700{
701 // Set model name
702 name(xml.attribute("name"));
703
704 // Set instruments
705 instruments(xml.attribute("instrument"));
706
707 // Set observation identifiers
708 ids(xml.attribute("id"));
709
710 // Set model TS
711 if (xml.has_attribute("ts")) {
712 std::string ts = xml.attribute("ts");
713 this->ts(gammalib::todouble(ts));
714 }
715
716 // Set TS computation flag
717 if (xml.has_attribute("tscalc")) {
718 bool tscalc = (xml.attribute("tscalc") == "1") ? true : false;
719 this->tscalc(tscalc);
720 }
721
722 // Read instrument scales
723 read_scales(xml);
724
725 // Read model associations
726 m_associations.read(xml);
727
728 // Return
729 return;
730}
731
732
733/***********************************************************************//**
734 * @brief Write model attributes
735 *
736 * @param[in] xml XML element.
737 ***************************************************************************/
739{
740 // Set model name
741 xml.attribute("name", name());
742
743 // Set model type
744 xml.attribute("type", type());
745
746 // Set instruments
747 std::string instruments = this->instruments();
748 if (instruments.length() > 0) {
749 xml.attribute("instrument", instruments);
750 }
751
752 // Set observation identifiers
753 std::string identifiers = ids();
754 if (identifiers.length() > 0) {
755 xml.attribute("id", identifiers);
756 }
757
758 // If available, set "ts" attribute
759 if (m_has_ts) {
760 xml.attribute("ts", gammalib::str(ts(), 3));
761 }
762
763 // If available, set "tscalc" attribute
764 if (m_has_tscalc) {
765 std::string ts_calc = tscalc() ? "1" : "0";
766 xml.attribute("tscalc", ts_calc);
767 }
768
769 // Write instrument scales
770 write_scales(xml);
771
772 // Write model associations
774
775 // Return
776 return;
777}
778
779
780/***********************************************************************//**
781 * @brief Print model attributes
782 *
783 * @return Returns string with model attributes.
784 ***************************************************************************/
785std::string GModel::print_attributes(void) const
786{
787 // Initialise result string
788 std::string result;
789
790 // Append model name
791 result.append(gammalib::parformat("Name")+name());
792
793 // Append instruments
794 result.append("\n"+gammalib::parformat("Instruments"));
795 if (!m_instruments.empty()) {
796 for (int i = 0; i < m_instruments.size(); ++i) {
797 if (i > 0) {
798 result.append(", ");
799 }
800 result.append(m_instruments[i]);
801 }
802 }
803 else {
804 result.append("all");
805 }
806
807 // Append Test Statistic
808 if (m_has_ts) {
809 result.append("\n"+gammalib::parformat("Test Statistic"));
810 result.append(gammalib::str(ts()));
811 }
812 else if (m_tscalc) {
813 result.append("\n"+gammalib::parformat("Test Statistic"));
814 result.append("Computation requested");
815 }
816
817 // Append observation identifiers
818 result.append("\n"+gammalib::parformat("Observation identifiers"));
819 if (!m_ids.empty()) {
820 for (int i = 0; i < m_ids.size(); ++i) {
821 if (i > 0) {
822 result.append(", ");
823 }
824 result.append(m_ids[i]);
825 }
826 }
827 else {
828 result.append("all");
829 }
830
831 // Append associations
832 if (!m_associations.is_empty()) {
833 result.append("\n"+gammalib::parformat("Associations"));
834 for (int i = 0; i < m_associations.size(); ++i) {
835 if (i > 0) {
836 result.append(", ");
837 }
838 result.append(m_associations[i].name());
839 }
840 }
841
842 // Return result
843 return result;
844}
845
846
847/***********************************************************************//**
848 * @brief Read instrument scales from XML element
849 *
850 * @param[in] xml XML source element.
851 *
852 * Reads the instrument scale factors from a tag with the following format
853 *
854 * <scaling>
855 * <instrument name="LAT" scale="1.0" min="0.1" max="10.0" value="1.0" free="0"/>
856 * <instrument name="CTA" scale="1.0" min="0.1" max="10.0" value="0.5" free="0"/>
857 * </scaling>
858 *
859 * The instrument name is case sensitive, but any leading and trailing white
860 * space will be removed.
861 *
862 * If no scaling tag is found, all instrument scale factors will be cleared.
863 ***************************************************************************/
865{
866 // Clear any existing scales
867 m_scales.clear();
868
869 // Continue only if there is a <scaling> tag
870 if (xml.elements("scaling") != 0) {
871
872 // Get pointer on first instrument scale factors
873 const GXmlElement* scales = xml.element("scaling", 0);
874
875 // Determine number of scale factors
876 int nscales = scales->elements("instrument");
877
878 // Read all scale factors
879 for (int i = 0; i < nscales; ++i) {
880 const GXmlElement* par = scales->element("instrument", i);
882 scale.read(*par);
884 scale.has_grad(true);
885 m_scales.push_back(scale);
886 m_pars.push_back(&m_scales[m_scales.size()-1]);
887 }
888
889 }
890
891 // Return
892 return;
893}
894
895
896/***********************************************************************//**
897 * @brief Write instrument scales into XML element
898 *
899 * @param[in] xml XML source element.
900 *
901 * @exception GException::invalid_value
902 * Invalid number of instrument tags found in XML element.
903 *
904 * If there are instrument scale factors then add a tag with the following
905 * format to the XML element:
906 *
907 * <scaling>
908 * <instrument name="LAT" scale="1" min="0.1" max="10" value="1.0" free="0"/>
909 * <instrument name="CTA" scale="1" min="0.1" max="10" value="0.5" free="0"/>
910 * </scaling>
911 ***************************************************************************/
913{
914 // Continue only is scale factors are present
915 if (!m_scales.empty()) {
916
917 // Get number of instruments
918 int num = m_scales.size();
919
920 // Initialise scaling tag
921 GXmlElement* scale = NULL;
922
923 // If no <scaling> tag exists then add one now with the required
924 // number of instruments ...
925 if (xml.elements("scaling") == 0) {
926 scale = xml.append("scaling");
927 for (int i = 0; i < num; ++i) {
928 scale->append(GXmlElement("instrument"));
929 }
930 }
931
932 // ... otherwise get first tag
933 else {
934 scale = xml.element("scaling", 0);
935 }
936
937 // Verify that scaling tag has the required number of instruments
938 if (scale->elements() != num) {
939 std::string msg = "Number of "+gammalib::str(scale->elements())+
940 " scale elements in XML file does not correspond "
941 "to expected number of "+gammalib::str(num)+
942 " elements. Please verify the XML format.";
944 }
945 int npars = scale->elements("instrument");
946 if (npars != num) {
947 std::string msg = "Number of "+gammalib::str(npars)+" \"instrument\" "
948 "scale elements in XML file does not correspond to "
949 "expected number of "+gammalib::str(num)+
950 " elements. Please verify the XML format.";
952 }
953
954 // Write all instruments
955 for (int i = 0; i < num; ++i) {
956
957 // Get instrument element
958 GXmlElement* inst = scale->element("instrument", i);
959
960 // Set instrument name
961 inst->attribute("name", m_scales[i].name());
962
963 // Write instrument scaling factor
964 m_scales[i].write(*inst);
965
966 } // endfor: looped over all instruments
967
968 }
969
970 // Return
971 return;
972}
#define G_AT
#define G_ACCESS
Exception handler interface definition.
#define G_WRITE_SCALES
Definition GModel.cpp:39
#define G_SCALE
Definition GModel.cpp:38
Abstract model base class interface definition.
Gammalib tools definition.
void read(const GXmlElement &xml)
Read model associations from XML document.
bool is_empty(void) const
Signals if there are no associations in container.
void clear(void)
Clear object.
void write(GXmlElement &xml) const
Write models into XML element.
int size(void) const
Return number of associations in container.
Model parameter class.
Definition GModelPar.hpp:87
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
Abstract model class.
Definition GModel.hpp:100
void read_scales(const GXmlElement &xml)
Read instrument scales from XML element.
Definition GModel.cpp:864
virtual ~GModel(void)
Destructor.
Definition GModel.cpp:110
const bool & tscalc(void) const
Return Test Statistic computation flag.
Definition GModel.hpp:330
GModelPar & scale(const int &index)
Returns reference to scale parameter by index.
Definition GModel.cpp:384
std::vector< std::string > m_instruments
Instruments to which model applies.
Definition GModel.hpp:179
std::vector< GModelPar * > m_pars
Pointers to all model parameters.
Definition GModel.hpp:182
void write_scales(GXmlElement &xml) const
Write instrument scales into XML element.
Definition GModel.cpp:912
virtual std::string type(void) const =0
const double & ts(void) const
Return Test Statistic value.
Definition GModel.hpp:296
void write_attributes(GXmlElement &xml) const
Write model attributes.
Definition GModel.cpp:738
std::string m_name
Model name.
Definition GModel.hpp:178
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:585
void free_members(void)
Delete class members.
Definition GModel.cpp:687
void init_members(void)
Initialise class members.
Definition GModel.cpp:637
void copy_members(const GModel &model)
Copy class members.
Definition GModel.cpp:663
std::string print_attributes(void) const
Print model attributes.
Definition GModel.cpp:785
std::vector< int > m_eval_inx
Definition GModel.hpp:192
int size(void) const
Return number of parameters in model.
Definition GModel.hpp:237
bool m_tscalc
Signals if TS should be computed.
Definition GModel.hpp:186
bool m_has_tscalc
Signals if tscalc attribute is available.
Definition GModel.hpp:185
bool has_par(const std::string &name) const
Checks if parameter name exists.
Definition GModel.cpp:299
GModel(void)
Void constructor.
Definition GModel.cpp:57
virtual GModelPar & operator[](const int &index)
Returns reference to model parameter by index.
Definition GModel.hpp:206
std::string instruments(void) const
Returns instruments to which model applies.
Definition GModel.cpp:325
std::string ids(void) const
Returns observation identifiers to which model applies.
Definition GModel.cpp:517
bool m_has_eval_inx
Definition GModel.hpp:190
GModelPar & at(const int &index)
Returns reference to model parameter by index.
Definition GModel.cpp:254
virtual GModel & operator=(const GModel &model)
Assignment operator.
Definition GModel.cpp:132
bool m_has_ts
Signals if TS is available.
Definition GModel.hpp:184
std::vector< std::string > m_ids
Identifiers to which model applies.
Definition GModel.hpp:181
void read_attributes(const GXmlElement &xml)
Read model attributes.
Definition GModel.cpp:699
double m_ts
Test Statistic of the model.
Definition GModel.hpp:187
GModelAssociations m_associations
Model associations.
Definition GModel.hpp:183
const std::string & name(void) const
Return parameter name.
Definition GModel.hpp:265
int scales(void) const
Return number of scale parameters in model.
Definition GModel.hpp:251
std::vector< GModelPar > m_scales
Model instrument scale factors.
Definition GModel.hpp:180
virtual void setup(const GObservation &obs) const
Setup model for a given observation.
Definition GModel.cpp:235
Abstract observation base class.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
void fix(void)
Fix a parameter.
double value(void) const
Return parameter value.
const std::string & name(void) const
Return parameter name.
XML element node class.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
bool has_attribute(const std::string &name) const
Check if element has a given attribute.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
Definition GXmlNode.cpp:287
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
Definition GXmlNode.cpp:640
virtual int elements(void) const
Return number of GXMLElement children of node.
Definition GXmlNode.cpp:586
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition GTools.cpp:1162
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition GTools.cpp:508
double todouble(const std::string &arg)
Convert string into double precision value.
Definition GTools.cpp:945
std::string strip_whitespace(const std::string &arg)
Strip leading and trailing whitespace from string.
Definition GTools.cpp:99
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split string.
Definition GTools.cpp:1002