48 const GModelRegistry g_cta_inst_background_registry(&g_cta_inst_background_seed);
51 #define G_EVAL "GCTAModelIrfBackground::eval(GEvent&, GObservation&, bool&)"
52 #define G_NPRED "GCTAModelIrfBackground::npred(GEnergy&, GTime&,"\
54 #define G_MC "GCTAModelIrfBackground::mc(GObservation&, GRan&)"
55 #define G_XML_SPECTRAL "GCTAModelIrfBackground::xml_spectral(GXmlElement&)"
56 #define G_XML_TEMPORAL "GCTAModelIrfBackground::xml_temporal(GXmlElement&)"
61 #define G_USE_NPRED_CACHE
62 #define G_USE_RATE_EBIN
344 const bool& gradients)
const
356 #if defined(G_USE_RATE_EBIN)
359 double logE =
event.energy().log10TeV();
360 spat = bgd(logE, inst_dir.
detx(), inst_dir.
dety());
370 double logE =
event.energy().log10TeV();
371 double spat = bgd(logE, inst_dir.
detx(), inst_dir.
dety());
382 double value = spat * spec * temp;
390 double fact = spat * temp;
393 (*
spectral())[i].factor_gradient((*
spectral())[i].factor_gradient() * fact);
399 double fact = spat * spec;
402 (*
temporal())[i].factor_gradient((*
temporal())[i].factor_gradient() * fact);
428 const GTime& obsTime,
432 static const int iter_theta = 6;
437 bool has_npred =
false;
443 #if defined(G_USE_NPRED_CACHE)
452 #if defined(G_DEBUG_NPRED)
453 std::cout <<
"GCTAModelIrfBackground::npred:";
454 std::cout <<
" cache=" << i;
455 std::cout <<
" npred=" << npred << std::endl;
498 npred = integral.
romberg(0.0, roi_radius);
501 #if defined(G_USE_NPRED_CACHE)
509 #if defined(G_NAN_CHECK)
511 std::string origin =
"GCTAModelIrfBackground::npred";
512 std::string message =
" NaN/Inf encountered (npred=" +
567 const GGti& gti = events.
gti();
577 for (
int i = 0; i <
spectral.nodes(); ++i) {
579 double intensity =
spectral.intensity(i);
581 spectral.intensity(i, norm*intensity);
585 for (
int ieng = 0; ieng < ebounds.
size(); ++ieng) {
594 #if defined(G_DUMP_MC)
595 std::cout <<
"GCTAModelIrfBackground::mc(\"" <<
name() <<
"\": ";
596 std::cout <<
"rate=" << rate <<
" cts/s)" << std::endl;
605 for (
int itime = 0; itime < gti.
size(); ++itime) {
614 int n_events = times.
size();
623 #if defined(G_DUMP_MC)
624 std::cout <<
" Interval " << itime;
625 std::cout <<
" events=" << n_events << std::endl;
626 int n_killed_by_roi = 0;
630 for (
int i = 0; i < n_events; ++i) {
653 event.energy(energy);
654 event.time(times[i]);
657 if (events.
roi().contains(event)) {
660 #if defined(G_DUMP_MC)
669 #if defined(G_DUMP_MC)
670 std::cout <<
" Killed by ROI=";
671 std::cout << n_killed_by_roi << std::endl;
723 spectral = xml.
element(
"spectrum", 0);
784 for (
int k = 0; k < n; ++k) {
797 bool write_temporal = ((
m_temporal != NULL) &&
799 (*m_temporal)[0].value() != 1.0));
803 src = xml.
append(
"source");
815 if (write_temporal) {
816 if (dynamic_cast<GModelTemporalConst*>(
temporal()) == NULL) {
845 result.append(
"=== GCTAModelIrfBackground ===");
856 if (n_spectral > 0) {
858 if (n_temporal > 0) {
859 result.append(
" * ");
862 if (n_temporal > 0) {
871 for (
int i = 0; i < n_spectral; ++i) {
876 for (
int i = 0; i < n_temporal; ++i) {
970 int n_pars = n_spectral + n_temporal;
976 for (
int i = 0; i < n_spectral; ++i) {
981 for (
int i = 0; i < n_temporal; ++i) {
1086 #if defined(G_NAN_CHECK)
1088 std::string origin =
"GCTAModelIrfBackground::npred_roi_kern_theta::eval"
1090 std::string message =
" NaN/Inf encountered (value=" +
1124 double detx = m_roi_centre.detx();
1125 double dety = m_roi_centre.dety();
1126 if (m_theta > 0.0 ) {
1132 double value = (*m_bgd)(m_logE, detx, dety);
1135 #if defined(G_NAN_CHECK)
1137 std::string origin =
"GCTAModelIrfBackground::npred_roi_kern_phi::eval"
1139 std::string message =
" NaN/Inf encountered (value=" +
void copy_members(const GCTAModelIrfBackground &bgd)
Copy class members.
virtual void write(GXmlElement &xml) const =0
CTA background model base class definition.
const GCTABackground * m_bgd
Pointer to background.
Constant temporal model class interface definition.
std::vector< GEnergy > m_npred_energies
Model energy.
virtual double eval(const GEvent &event, const GObservation &obs, const bool &gradients=false) const
Return background rate in units of events MeV s sr .
GModelTemporal * m_temporal
Temporal model.
std::vector< GTime > m_npred_times
Model time.
virtual GCTAEventList * mc(const GObservation &obs, GRan &ran) const
Return simulated list of events.
GEnergy emin(void) const
Return minimum energy of event bin.
virtual GTimes mc(const double &rate, const GTime &tmin, const GTime &tmax, GRan &ran) const =0
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const =0
double norm(const GVector &vector)
Computes vector norm.
double romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
void detx(const double &x)
Set DETX coordinate (in radians)
const GCTAInstDir & cta_dir(const std::string &origin, const GEvent &event)
Retrieve CTA instrument direction from generic event.
int size(void) const
Return number of times.
std::string print_attributes(void) const
Print model attributes.
void warning(const std::string &origin, const std::string &message)
Emits warning.
Abstract spectral model base class.
Interface definition for the model registry class.
virtual std::string instrument(void) const =0
CTA IRF background model class.
CTA IRF background model class definition.
Abstract temporal model base class.
virtual void roi(const GRoi &roi)
Set ROI.
GSkyDir skydir(const GCTAInstDir &instdir) const
Get sky direction direction from instrument direction.
virtual std::string type(void) const
Return data model type.
int size(void) const
Return number of parameters.
void ebounds(const GEbounds &ebounds)
Set energy boundaries.
virtual GCTAModelIrfBackground * clone(void) const
Clone CTA instrument background model.
int size(void) const
Return number of energy boundaries.
GCTAEventBin class interface definition.
GVector cos(const GVector &vector)
Computes cosine of vector elements.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const =0
CTA event bin class interface definition.
void append(const GCTAEventAtom &event)
Append event to event list.
GCTAModelIrfBackground(void)
Void constructor.
CTA instrument response function class definition.
const GCTAPointing & cta_pnt(const std::string &origin, const GObservation &obs)
Retrieve CTA pointing from generic observation.
Abstract interface for the event classes.
void gti(const GGti >i)
Set Good Time Intervals.
void free_members(void)
Delete class members.
Spectral model registry class definition.
GModelTemporal * xml_temporal(const GXmlElement &temporal) const
Return pointer to temporal model from XML element.
virtual void write(GXmlElement &xml) const =0
double log10TeV(void) const
Return log10 of energy in TeV.
Random number generator class.
virtual const GModelSpectralNodes & spectrum(void) const =0
Spectral nodes model class definition.
bool valid_model(void) const
Verifies if model has all components.
double MeV(void) const
Return energy in MeV.
Interface for the CTA region of interest class.
virtual int elements(void) const
Return number of GXMLElement children of node.
double eval(const double &theta)
Kernel for offset angle integration of background model.
GIntegral class interface definition.
virtual GModelTemporalConst * clone(void) const
Clone constant temporal model.
void free_members(void)
Delete class members.
virtual const GTime & time(void) const =0
void init_members(void)
Initialise class members.
const GCTABackground & cta_rsp_bkg(const std::string &origin, const GObservation &obs)
Retrieve CTA background response from generic observation.
void dir(const GSkyDir &dir)
Set sky direction.
void set_pointers(void)
Set pointers.
int size(void) const
Return number of Good Time Intervals.
Spectral nodes model class.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print CTA instrument background model information.
void id(const std::string &id)
Set observation identifier.
bool is_notanumber(const double &x)
Signal if argument is not a number.
std::vector< GModelPar * > m_pars
Pointers to all model parameters.
int size(void) const
Return number of parameters in model.
bool is_infinite(const double &x)
Signal if argument is infinite.
Definition of support function used by CTA classes.
int m_iter
Romberg iterations.
GCTAModelIrfBackground & operator=(const GCTAModelIrfBackground &bgd)
Assignment operator.
const GEnergy & ewidth(void) const
Return energy width of event bin.
Energy boundaries container class.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
const std::string & name(void) const
Return parameter name.
void reserve(const int &number)
Reserves space for events.
const GEnergy & emin(void) const
Return minimum energy of all intervals.
virtual void write(GXmlElement &xml) const
Write CTA instrument background model into XML element.
int size(void) const
Return number of parameters.
GCTAInstDir instdir(const GSkyDir &skydir) const
Get instrument direction from sky direction.
GModelTemporal * alloc(const GXmlElement &xml) const
Allocate temporal model that is found in XML element.
virtual const GEnergy & energy(void) const =0
virtual ~GCTAModelIrfBackground(void)
Destructor.
Abstract data model class.
const GCTAEventList & cta_event_list(const std::string &origin, const GObservation &obs)
Retrieve CTA event list from generic observation.
GModelSpectral * alloc(const GXmlElement &xml) const
Allocate spectral model that is found in XML element.
virtual GModelData & operator=(const GModelData &model)
Assignment operator.
std::vector< double > m_npred_values
Model values.
GModelSpectral * spectral(void) const
Return spectral model component.
Good Time Interval class.
virtual double eval(const GTime &srcTime, const bool &gradients=false) const =0
Abstract observation base class.
const GTime & tstop(void) const
Returns latest stop time in Good Time Intervals.
const GTime & tstart(void) const
Returns earliest start time in Good Time Intervals.
CTA observation class interface definition.
double m_logE
Log10 of energy.
virtual void clear(void)
Clear CTA instrument background model.
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.
virtual GModelSpectral * clone(void) const =0
Clones object.
GModelSpectral * xml_spectral(const GXmlElement &spectral) const
Return pointer to spectral model from XML element.
GModelTemporal * temporal(void) const
Return temporal model component.
virtual std::string type(void) const =0
int iter_phi(const double &rho, const double &resolution, const int &iter_min, const int &iter_max)
Determine number of azimuthal Romberg iterations.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
virtual bool is_atom(void) const =0
Temporal model registry class definition.
const GCTAModelCubeBackground g_cta_inst_background_seed
GCTAInstDir m_roi_centre
RoI centre.
virtual void read(const GXmlElement &xml)
Read CTA instrument background model from XML element.
GVector sin(const GVector &vector)
Computes sine of vector elements.
double eval(const double &phi)
Kernel for azimuth angle integration of background model.
Abstract base class for the CTA background model.
void fixed_iter(const int &iter)
Set fixed number of iterations.
GModelSpectral * m_spectral
Spectral model.
virtual GModelTemporal * clone(void) const =0
Clones object.
void read_attributes(const GXmlElement &xml)
Read model attributes.
CTA instrument direction class.
virtual GCTAInstDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const =0
void dety(const double &y)
Set DETY coordinate (in radians)
const GEnergy & emax(void) const
Return maximum energy of all intervals.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const =0
Model registry class definition.
std::vector< std::string > m_npred_names
Model names.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
virtual double npred(const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return spatially integrated background rate in units of events MeV s .
Integration class interface definition.
virtual double rate_ebin(const GCTAInstDir &dir, const GEnergy &emin, const GEnergy &emax) const =0
void init_members(void)
Initialise class members.
Constant temporal model class.
const GCTAInstDir & dir(void) const
Return instrument direction.
Mathematical function definitions.
Class that handles energies in a unit independent way.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.