GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTAModelCubeBackground.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTAModelCubeBackground.cpp - CTA cube background model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2013-2018 by Michael Mayer *
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 GCTAModelCubeBackground.cpp
23  * @brief CTA cube background model class implementation
24  * @author Michael Mayer
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GTools.hpp"
32 #include "GModelRegistry.hpp"
35 #include "GModelTemporalConst.hpp"
36 #include "GModelSpectralNodes.hpp"
38 #include "GCTAObservation.hpp"
39 #include "GCTAResponseCube.hpp"
40 #include "GCTACubeBackground.hpp"
41 #include "GCTASupport.hpp"
42 
43 /* __ Globals ____________________________________________________________ */
45 const GModelRegistry g_cta_inst_background_registry(&g_cta_inst_background_seed);
46 
47 /* __ Method name definitions ____________________________________________ */
48 #define G_EVAL "GCTAModelCubeBackground::eval(GEvent&, GObservation&, bool&)"
49 #define G_NPRED "GCTAModelCubeBackground::npred(GEnergy&, GTime&,"\
50  " GObservation&)"
51 #define G_MC "GCTAModelCubeBackground::mc(GObservation&, GRan&)"
52 #define G_XML_SPECTRAL "GCTAModelCubeBackground::xml_spectral(GXmlElement&)"
53 #define G_XML_TEMPORAL "GCTAModelCubeBackground::xml_temporal(GXmlElement&)"
54 
55 /* __ Macros _____________________________________________________________ */
56 
57 /* __ Coding definitions _________________________________________________ */
58 #define G_USE_NPRED_CACHE
59 
60 /* __ Debug definitions __________________________________________________ */
61 //#define G_DUMP_MC
62 //#define G_DEBUG_NPRED
63 
64 /* __ Constants __________________________________________________________ */
65 
66 
67 /*==========================================================================
68  = =
69  = Constructors/destructors =
70  = =
71  ==========================================================================*/
72 
73 /***********************************************************************//**
74  * @brief Void constructor
75  ***************************************************************************/
77 {
78  // Initialise class members
79  init_members();
80 
81  // Return
82  return;
83 }
84 
85 
86 /***********************************************************************//**
87  * @brief XML constructor
88  *
89  * @param[in] xml XML element.
90  *
91  * Constructs a CTA cube background model from the information provided by
92  * an XML elements (see GCTAModelCubeBackground::read method).
93  ***************************************************************************/
95  GModelData(xml)
96 {
97  // Initialise members
98  init_members();
99 
100  // Read XML
101  read(xml);
102 
103  // Set parameter pointers
104  set_pointers();
105 
106  // Return
107  return;
108 }
109 
110 
111 /***********************************************************************//**
112  * @brief Construct from spectral component
113  *
114  * @param[in] spectral Spectral model component.
115  *
116  * Constructs a CTA cube background model from a @p spectral model component.
117  * The temporal component is assumed to be constant.
118  ***************************************************************************/
120  GModelData()
121 {
122  // Initialise members
123  init_members();
124 
125  // Allocate temporal constant model
127 
128  // Clone model components
129  m_spectral = spectral.clone();
130  m_temporal = temporal.clone();
131 
132  // Set parameter pointers
133  set_pointers();
134 
135  // Return
136  return;
137 }
138 
139 
140 /***********************************************************************//**
141  * @brief Construct from model components
142  *
143  * @param[in] spectral Spectral model component.
144  * @param[in] temporal Temporal model component.
145  *
146  * Constructs a CTA cube background model from a @p spectral and a
147  * @p temporal component.
148  ***************************************************************************/
150  const GModelTemporal& temporal) :
151  GModelData()
152 {
153  // Initialise members
154  init_members();
155 
156  // Clone model components
157  m_spectral = spectral.clone();
158  m_temporal = temporal.clone();
159 
160  // Set parameter pointers
161  set_pointers();
162 
163  // Return
164  return;
165 }
166 
167 
168 /***********************************************************************//**
169  * @brief Copy constructor
170  *
171  * @param[in] bgd CTA cube background model.
172  ***************************************************************************/
174  GModelData(bgd)
175 {
176  // Initialise class members
177  init_members();
178 
179  // Copy members
180  copy_members(bgd);
181 
182  // Return
183  return;
184 }
185 
186 
187 /***********************************************************************//**
188  * @brief Destructor
189  ***************************************************************************/
191 {
192  // Free members
193  free_members();
194 
195  // Return
196  return;
197 }
198 
199 
200 /*==========================================================================
201  = =
202  = Operators =
203  = =
204  ==========================================================================*/
205 
206 /***********************************************************************//**
207  * @brief Assignment operator
208  *
209  * @param[in] bgd CTA cube background model.
210  * @return CTA cube background model.
211  ***************************************************************************/
213 {
214  // Execute only if object is not identical
215  if (this != &bgd) {
216 
217  // Copy base class members
218  this->GModelData::operator=(bgd);
219 
220  // Free members
221  free_members();
222 
223  // Initialise private members
224  init_members();
225 
226  // Copy members
227  copy_members(bgd);
228 
229  } // endif: object was not identical
230 
231  // Return this object
232  return *this;
233 }
234 
235 
236 /*==========================================================================
237  = =
238  = Public methods =
239  = =
240  ==========================================================================*/
241 
242 /***********************************************************************//**
243  * @brief Clear CTA cube background model
244  *
245  * This method properly resets the CTA cube background model to an
246  * initial state.
247  ***************************************************************************/
249 {
250  // Free class members (base and derived classes, derived class first)
251  free_members();
252  this->GModelData::free_members();
253 
254  // Initialise members
255  this->GModelData::init_members();
256  init_members();
257 
258  // Return
259  return;
260 }
261 
262 
263 /***********************************************************************//**
264  * @brief Clone CTA cube background model
265  *
266  * @return Pointer to deep copy of CTA cube background model.
267  ***************************************************************************/
269 {
270  return new GCTAModelCubeBackground(*this);
271 }
272 
273 
274 /***********************************************************************//**
275  * @brief Set spectral model component
276  *
277  * @param[in] spectral Pointer to spectral model component.
278  *
279  * Sets the spectral model component of the model.
280  ***************************************************************************/
282 {
283  // Free spectral model component only if it differs from current
284  // component. This prevents unintential deallocation of the argument
285  if ((m_spectral != NULL) && (m_spectral != spectral)) {
286  delete m_spectral;
287  }
288 
289  // Clone spectral model component if it exists, otherwise set pointer
290  // to NULL
291  m_spectral = (spectral != NULL) ? spectral->clone() : NULL;
292 
293  // Set parameter pointers
294  set_pointers();
295 
296  // Return
297  return;
298 }
299 
300 
301 /***********************************************************************//**
302  * @brief Set temporal model component
303  *
304  * @param[in] temporal Pointer to temporal model component.
305  *
306  * Sets the temporal model component of the model.
307  ***************************************************************************/
309 {
310  // Free temporal model component only if it differs from current
311  // component. This prevents unintential deallocation of the argument
312  if ((m_temporal != NULL) && (m_temporal != temporal)) {
313  delete m_temporal;
314  }
315 
316  // Clone temporal model component if it exists, otherwise set pointer
317  // to NULL
318  m_temporal = (temporal != NULL) ? temporal->clone() : NULL;
319 
320  // Set parameter pointers
321  set_pointers();
322 
323  // Return
324  return;
325 }
326 
327 
328 /***********************************************************************//**
329  * @brief Return background rate in units of events MeV\f$^{-1}\f$
330  * s\f$^{-1}\f$ sr\f$^{-1}\f$
331  *
332  * @param[in] event Observed event.
333  * @param[in] obs Observation.
334  * @param[in] gradients Compute gradients?
335  * @return Background rate (events MeV\f$^{-1}\f$ s\f$^{-1}\f$ sr\f$^{-1}\f$).
336  *
337  * Evaluates the background model. The method returns a real rate, defined
338  * as the number of counts per MeV, steradian and ontime.
339  *
340  * If the @p gradients flag is true the method will also set the parameter
341  * gradients of the model parameters.
342  ***************************************************************************/
344  const GObservation& obs,
345  const bool& gradients) const
346 {
347  // Get reference on CTA response cube from observation and reference on
348  // CTA instrument direction from event
350  const GCTAInstDir& dir = gammalib::cta_dir(G_EVAL, event);
351 
352  // Retrieve reference to CTA cube background
353  const GCTACubeBackground& bgd = rsp.background();
354 
355  // Evaluate function
356  double spat = bgd(dir, event.energy());
357  double spec = (spectral() != NULL)
358  ? spectral()->eval(event.energy(), event.time(), gradients)
359  : 1.0;
360  double temp = (temporal() != NULL)
361  ? temporal()->eval(event.time(), gradients) : 1.0;
362 
363  // Compute value. Note that background rates are already per
364  // livetime, hence no deadtime correction is needed here.
365  double value = spat * spec * temp;
366 
367  // If gradients were requested then multiply factors to spectral and
368  // temporal gradients
369  if (gradients) {
370 
371  // Multiply factors to spectral gradients
372  if (spectral() != NULL) {
373  double fact = spat * temp;
374  if (fact != 1.0) {
375  for (int i = 0; i < spectral()->size(); ++i)
376  (*spectral())[i].factor_gradient((*spectral())[i].factor_gradient() * fact);
377  }
378  }
379 
380  // Multiply factors to temporal gradients
381  if (temporal() != NULL) {
382  double fact = spat * spec;
383  if (fact != 1.0) {
384  for (int i = 0; i < temporal()->size(); ++i)
385  (*temporal())[i].factor_gradient((*temporal())[i].factor_gradient() * fact);
386  }
387  }
388 
389  } // endif: gradients were requested
390 
391  // Return value
392  return value;
393 }
394 
395 
396 /***********************************************************************//**
397  * @brief Return spatially integrated background rate in units of
398  * events MeV\f$^{-1}\f$ s\f$^{-1}\f$
399  *
400  * @param[in] obsEng Measured event energy.
401  * @param[in] obsTime Measured event time.
402  * @param[in] obs Observation.
403  * @return Spatially integrated background rate
404  * (events MeV\f$^{-1}\f$ s\f$^{-1}\f$)
405  *
406  * Spatially integrates the cube background model for a given measured event
407  * energy and event time. The method returns a real rate,
408  * defined as the number of counts per MeV and ontime.
409  ***************************************************************************/
411  const GTime& obsTime,
412  const GObservation& obs) const
413 {
414  // Initialise result
415  double npred = 0.0;
416  bool has_npred = false;
417 
418  // Build unique identifier
419  std::string id = obs.instrument() + "::" + obs.id();
420 
421  // Check if Npred value is already in cache
422  #if defined(G_USE_NPRED_CACHE)
423  if (!m_npred_names.empty()) {
424 
425  // Search for unique identifier, and if found, recover Npred value
426  // and break
427  for (int i = 0; i < m_npred_names.size(); ++i) {
428  if (m_npred_names[i] == id && m_npred_energies[i] == obsEng) {
429  npred = m_npred_values[i];
430  has_npred = true;
431  #if defined(G_DEBUG_NPRED)
432  std::cout << "GCTAModelCubeBackground::npred:";
433  std::cout << " cache=" << i;
434  std::cout << " npred=" << npred << std::endl;
435  #endif
436  break;
437  }
438  }
439 
440  } // endif: there were values in the Npred cache
441  #endif
442 
443  // Continue only if no Npred cache value has been found
444  if (!has_npred) {
445 
446  // Evaluate only if model is valid
447  if (valid_model()) {
448 
449  // Get reference on CTA response cube from observation
451 
452  // Retrieve CTA background
453  const GCTACubeBackground bgd = rsp.background();
454 
455  // Get log10 of energy in TeV
456  double logE = obsEng.log10TeV();
457 
458  // Integrate the background map at a certain energy
459  npred = bgd.integral(logE);
460 
461  // Store result in Npred cache
462  #if defined(G_USE_NPRED_CACHE)
463  m_npred_names.push_back(id);
464  m_npred_energies.push_back(obsEng);
465  m_npred_times.push_back(obsTime);
466  m_npred_values.push_back(npred);
467  #endif
468 
469  // Debug: Check for NaN
470  #if defined(G_NAN_CHECK)
471  if (gammalib::is_notanumber(npred) || gammalib::is_infinite(npred)) {
472  std::string origin = "GCTAModelCubeBackground::npred";
473  std::string message = " NaN/Inf encountered (npred=" +
474  gammalib::str(npred) + ")";
475  gammalib::warning(origin, message);
476  }
477  #endif
478 
479  } // endif: model was valid
480 
481  } // endif: Npred computation required
482 
483  // Multiply in spectral and temporal components
484  npred *= spectral()->eval(obsEng, obsTime);
485  npred *= temporal()->eval(obsTime);
486 
487  // Return Npred
488  return npred;
489 }
490 
491 
492 /***********************************************************************//**
493  * @brief Return simulated list of events
494  *
495  * @param[in] obs Observation.
496  * @param[in] ran Random number generator.
497  * @return Pointer to list of simulated events (needs to be de-allocated by
498  * client)
499  *
500  * @exception GException::feature_not_implemented
501  * Specified observation is not a CTA observation.
502  *
503  * The simulation of an event list from a cube background model is not
504  * implemented, hence the method will always throw an exception.
505  ***************************************************************************/
507 {
508  // Feature not yet implemented
510  "MC computation not implemented for binned analysis.");
511 
512  // Return NULL pointer
513  return NULL;
514 
515 }
516 
517 
518 /***********************************************************************//**
519  * @brief Read CTA cube background model from XML element
520  *
521  * @param[in] xml XML element.
522  *
523  * Set up CTA cube background model from the information provided by
524  * an XML element. The XML element is expected to have the following
525  * structure
526  *
527  * <source name="..." type="..." instrument="...">
528  * <spectrum type="...">
529  * ...
530  * </spectrum>
531  * </source>
532  *
533  * Optionally, a temporal model may be provided using the following
534  * syntax
535  *
536  * <source name="..." type="..." instrument="...">
537  * <spectrum type="...">
538  * ...
539  * </spectrum>
540  * <temporalModel type="...">
541  * ...
542  * </temporalModel>
543  * </source>
544  *
545  * If no temporal component is found a constant model is assumed.
546  ***************************************************************************/
548 {
549  // Clear model
550  clear();
551 
552  // Initialise XML elements
553  const GXmlElement* spectral = NULL;
554  const GXmlElement* temporal = NULL;
555 
556  // Get pointer on spectrum
557  spectral = xml.element("spectrum", 0);
558 
559  // Extract spectral model
560  m_spectral = xml_spectral(*spectral);
561 
562  // Optionally get temporal model
563  if (xml.elements("temporalModel")) {
564  temporal = xml.element("temporalModel", 0);
565  m_temporal = xml_temporal(*temporal);
566  }
567  else {
568  GModelTemporalConst constant;
569  m_temporal = constant.clone();
570  }
571 
572  // Read model attributes
573  read_attributes(xml);
574 
575  // Set parameter pointers
576  set_pointers();
577 
578  // Return
579  return;
580 }
581 
582 
583 /***********************************************************************//**
584  * @brief Write CTA cube background model into XML element
585  *
586  * @param[in] xml XML element.
587  *
588  * Write CTA cube background model information into an XML element.
589  * The XML element will have the following structure
590  *
591  * <source name="..." type="..." instrument="...">
592  * <spectrum type="...">
593  * ...
594  * </spectrum>
595  * </source>
596  *
597  * If the model contains a non-constant temporal model, the temporal
598  * component will also be written following the syntax
599  *
600  * <source name="..." type="..." instrument="...">
601  * <spectrum type="...">
602  * ...
603  * </spectrum>
604  * <temporalModel type="...">
605  * ...
606  * </temporalModel>
607  * </source>
608  *
609  * If no temporal component is found a constant model is assumed.
610  ***************************************************************************/
612 {
613  // Initialise pointer on source
614  GXmlElement* src = NULL;
615 
616  // Search corresponding source
617  int n = xml.elements("source");
618  for (int k = 0; k < n; ++k) {
619  GXmlElement* element = xml.element("source", k);
620  if (element->attribute("name") == name()) {
621  src = element;
622  break;
623  }
624  }
625 
626  // If we have a temporal model that is either not a constant, or a
627  // constant with a normalization value that differs from 1.0 then
628  // write the temporal component into the XML element. This logic
629  // assures compatibility with the Fermi/LAT format as this format
630  // does not handle temporal components.
631  bool write_temporal = ((m_temporal != NULL) &&
632  (m_temporal->type() != "Constant" ||
633  (*m_temporal)[0].value() != 1.0));
634 
635  // If no source with corresponding name was found then append one
636  if (src == NULL) {
637  src = xml.append("source");
638  if (spectral() != NULL) src->append(GXmlElement("spectrum"));
639  if (write_temporal) src->append(GXmlElement("temporalModel"));
640  }
641 
642  // Write spectral model
643  if (spectral() != NULL) {
644  GXmlElement* spec = src->element("spectrum", 0);
645  spectral()->write(*spec);
646  }
647 
648  // Optionally write temporal model
649  if (write_temporal) {
650  if (dynamic_cast<GModelTemporalConst*>(temporal()) == NULL) {
651  GXmlElement* temp = src->element("temporalModel", 0);
652  temporal()->write(*temp);
653  }
654  }
655 
656  // Write model attributes
657  write_attributes(*src);
658 
659  // Return
660  return;
661 }
662 
663 
664 /***********************************************************************//**
665  * @brief Print CTA cube background model information
666  *
667  * @param[in] chatter Chattiness.
668  * @return String containing CTA cube background model information.
669  ***************************************************************************/
670 std::string GCTAModelCubeBackground::print(const GChatter& chatter) const
671 {
672  // Initialise result string
673  std::string result;
674 
675  // Continue only if chatter is not silent
676  if (chatter != SILENT) {
677 
678  // Append header
679  result.append("=== GCTAModelCubeBackground ===");
680 
681  // Determine number of parameters per type
682  int n_spectral = (spectral() != NULL) ? spectral()->size() : 0;
683  int n_temporal = (temporal() != NULL) ? temporal()->size() : 0;
684 
685  // Append attributes
686  result.append("\n"+print_attributes());
687 
688  // Append model type
689  result.append("\n"+gammalib::parformat("Model type"));
690  if (n_spectral > 0) {
691  result.append("\""+spectral()->type()+"\"");
692  if (n_temporal > 0) {
693  result.append(" * ");
694  }
695  }
696  if (n_temporal > 0) {
697  result.append("\""+temporal()->type()+"\"");
698  }
699 
700  // Append parameters
701  result.append("\n"+gammalib::parformat("Number of parameters") +
702  gammalib::str(size()));
703  result.append("\n"+gammalib::parformat("Number of spectral par's") +
704  gammalib::str(n_spectral));
705  for (int i = 0; i < n_spectral; ++i) {
706  result.append("\n"+(*spectral())[i].print());
707  }
708  result.append("\n"+gammalib::parformat("Number of temporal par's") +
709  gammalib::str(n_temporal));
710  for (int i = 0; i < n_temporal; ++i) {
711  result.append("\n"+(*temporal())[i].print());
712  }
713 
714  } // endif: chatter was not silent
715 
716  // Return result
717  return result;
718 }
719 
720 
721 /*==========================================================================
722  = =
723  = Private methods =
724  = =
725  ==========================================================================*/
726 
727 /***********************************************************************//**
728  * @brief Initialise class members
729  ***************************************************************************/
731 {
732  // Initialise members
733  m_spectral = NULL;
734  m_temporal = NULL;
735 
736  // Initialise Npred cache
737  m_npred_names.clear();
738  m_npred_energies.clear();
739  m_npred_times.clear();
740  m_npred_values.clear();
741 
742  // Return
743  return;
744 }
745 
746 
747 /***********************************************************************//**
748  * @brief Copy class members
749  *
750  * @param[in] bgd CTA background model.
751  ***************************************************************************/
753 {
754  // Copy cache
759 
760  // Clone spectral and temporal model components
761  m_spectral = (bgd.m_spectral != NULL) ? bgd.m_spectral->clone() : NULL;
762  m_temporal = (bgd.m_temporal != NULL) ? bgd.m_temporal->clone() : NULL;
763 
764  // Set parameter pointers
765  set_pointers();
766 
767  // Return
768  return;
769 }
770 
771 
772 /***********************************************************************//**
773  * @brief Delete class members
774  ***************************************************************************/
776 {
777  // Free memory
778  if (m_spectral != NULL) delete m_spectral;
779  if (m_temporal != NULL) delete m_temporal;
780 
781  // Signal free pointers
782  m_spectral = NULL;
783  m_temporal = NULL;
784 
785  // Return
786  return;
787 }
788 
789 
790 /***********************************************************************//**
791  * @brief Set pointers
792  *
793  * Set pointers to all model parameters. The pointers are stored in a vector
794  * that is member of the GModelData base class.
795  ***************************************************************************/
797 {
798  // Clear parameters
799  m_pars.clear();
800 
801  // Determine the number of parameters
802  int n_spectral = (spectral() != NULL) ? spectral()->size() : 0;
803  int n_temporal = (temporal() != NULL) ? temporal()->size() : 0;
804  int n_pars = n_spectral + n_temporal;
805 
806  // Continue only if there are parameters
807  if (n_pars > 0) {
808 
809  // Gather spectral parameters
810  for (int i = 0; i < n_spectral; ++i) {
811  m_pars.push_back(&((*spectral())[i]));
812  }
813 
814  // Gather temporal parameters
815  for (int i = 0; i < n_temporal; ++i) {
816  m_pars.push_back(&((*temporal())[i]));
817  }
818 
819  }
820 
821  // Return
822  return;
823 }
824 
825 
826 /***********************************************************************//**
827  * @brief Verifies if model has all components
828  *
829  * Returns 'true' if models has a spectral and a temporal component.
830  * Otherwise returns 'false'.
831  ***************************************************************************/
833 {
834  // Set result
835  bool result = ((spectral() != NULL) && (temporal() != NULL));
836 
837  // Return result
838  return result;
839 }
840 
841 
842 /***********************************************************************//**
843  * @brief Return pointer to spectral model from XML element
844  *
845  * @param[in] spectral XML element.
846  * @return Pointer to spectral model.
847  *
848  * Returns pointer to spectral model that is defined in an XML element.
849  ***************************************************************************/
851 {
852  // Get spectral model
853  GModelSpectralRegistry registry;
854  GModelSpectral* ptr = registry.alloc(spectral);
855 
856  // Return pointer
857  return ptr;
858 }
859 
860 
861 /***********************************************************************//**
862  * @brief Return pointer to temporal model from XML element
863  *
864  * @param[in] temporal XML element.
865  * @return Pointer to temporal model.
866  *
867  * Returns pointer to temporal model that is defined in an XML element.
868  ***************************************************************************/
870 {
871  // Get temporal model
872  GModelTemporalRegistry registry;
873  GModelTemporal* ptr = registry.alloc(temporal);
874 
875  // Return pointer
876  return ptr;
877 }
878 
virtual void write(GXmlElement &xml) const =0
Constant temporal model class interface definition.
void init_members(void)
Initialise class members.
const GCTAInstDir & cta_dir(const std::string &origin, const GEvent &event)
Retrieve CTA instrument direction from generic event.
CTA cube-style response function class definition.
std::string print_attributes(void) const
Print model attributes.
Definition: GModel.cpp:748
void warning(const std::string &origin, const std::string &message)
Emits warning.
Definition: GTools.cpp:1265
Abstract spectral model base class.
Interface definition for the model registry class.
virtual std::string instrument(void) const =0
GModelSpectral * spectral(void) const
Return spectral model component.
void set_pointers(void)
Set pointers.
Abstract temporal model base class.
int size(void) const
Return number of parameters.
const GCTACubeBackground & background(void) const
Return cube analysis background cube.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const =0
CTA cube background class.
CTA cube-style response function class.
Abstract interface for the event classes.
Definition: GEvent.hpp:71
CTA event list class.
XML element node class.
Definition: GXmlElement.hpp:47
void free_members(void)
Delete class members.
Definition: GModelData.cpp:181
Spectral model registry class definition.
virtual void write(GXmlElement &xml) const =0
double log10TeV(void) const
Return log10 of energy in TeV.
Definition: GEnergy.cpp:457
Random number generator class.
Definition: GRan.hpp:44
Spectral nodes model class definition.
virtual int elements(void) const
Return number of GXMLElement children of node.
Definition: GXmlNode.cpp:580
const GCTAResponseCube & cta_rsp_cube(const std::string &origin, const GObservation &obs)
Retrieve CTA cube response from generic observation.
Time class.
Definition: GTime.hpp:54
Gammalib tools definition.
std::vector< GEnergy > m_npred_energies
Model energy.
virtual GCTAEventList * mc(const GObservation &obs, GRan &ran) const
Return simulated list of events.
virtual GModelTemporalConst * clone(void) const
Clone constant temporal model.
#define G_NPRED
virtual const GTime & time(void) const =0
GModelTemporal * m_temporal
Temporal model.
void id(const std::string &id)
Set observation identifier.
bool is_notanumber(const double &x)
Signal if argument is not a number.
Definition: GTools.hpp:184
CTA cube background class definition.
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
bool is_infinite(const double &x)
Signal if argument is infinite.
Definition: GTools.hpp:167
bool valid_model(void) const
Verifies if model has all components.
#define G_MC
Definition of support function used by CTA classes.
std::vector< std::string > m_npred_names
Model names.
GCTAModelCubeBackground(void)
Void constructor.
GModelSpectral * xml_spectral(const GXmlElement &spectral) const
Return pointer to spectral model from XML element.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
std::vector< GTime > m_npred_times
Model time.
const std::string & name(void) const
Return parameter name.
Definition: GModel.hpp:245
#define G_EVAL
int size(void) const
Return number of parameters.
GModelTemporal * alloc(const GXmlElement &xml) const
Allocate temporal model that is found in XML element.
virtual const GEnergy & energy(void) const =0
CTA cube background model class.
Abstract data model class.
Definition: GModelData.hpp:53
GModelSpectral * alloc(const GXmlElement &xml) const
Allocate spectral model that is found in XML element.
virtual GModelData & operator=(const GModelData &model)
Assignment operator.
Definition: GModelData.cpp:120
GChatter
Definition: GTypemaps.hpp:33
virtual double eval(const GTime &srcTime, const bool &gradients=false) const =0
double integral(const double &logE) const
Return spatially integrated background rate in units of events MeV s .
Abstract observation base class.
virtual void read(const GXmlElement &xml)
Read CTA cube background model from XML element.
GModelTemporal * xml_temporal(const GXmlElement &temporal) const
Return pointer to temporal model from XML element.
std::vector< double > m_npred_values
Model values.
CTA observation class interface definition.
Interface definition for the spectral model registry class.
Interface definition for the temporal model registry class.
void write_attributes(GXmlElement &xml) const
Write model attributes.
Definition: GModel.cpp:704
virtual GModelSpectral * clone(void) const =0
Clones object.
virtual std::string type(void) const =0
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
Definition: GXmlNode.cpp:634
void free_members(void)
Delete class members.
Temporal model registry class definition.
void copy_members(const GCTAModelCubeBackground &bgd)
Copy class members.
virtual GCTAModelCubeBackground & operator=(const GCTAModelCubeBackground &model)
Assignment operator.
const GCTAModelCubeBackground g_cta_inst_background_seed
CTA cube background model class interface definition.
virtual GModelTemporal * clone(void) const =0
Clones object.
void read_attributes(const GXmlElement &xml)
Read model attributes.
Definition: GModel.cpp:668
CTA instrument direction class.
Definition: GCTAInstDir.hpp:59
virtual GCTAModelCubeBackground * clone(void) const
Clone CTA cube background model.
Model registry class definition.
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:1022
virtual std::string type(void) const
Return data model type.
virtual void write(GXmlElement &xml) const
Write CTA cube background model into XML element.
virtual double npred(const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return spatially integrated background rate in units of events MeV s .
GModelSpectral * m_spectral
Spectral model.
virtual void clear(void)
Clear CTA cube background model.
void init_members(void)
Initialise class members.
Definition: GModelData.cpp:159
Constant temporal model class.
GModelTemporal * temporal(void) const
Return temporal model component.
virtual ~GCTAModelCubeBackground(void)
Destructor.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
virtual std::string print(const GChatter &chatter=NORMAL) const
Print CTA cube background model information.
virtual double eval(const GEvent &event, const GObservation &obs, const bool &gradients=false) const
Return background rate in units of events MeV s sr .
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:413