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;
433 static const int iter_phi = 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;
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);
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;
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) {
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) {
872 result.append(
"\n"+(*
spectral())[i].print());
876 for (
int i = 0; i < n_temporal; ++i) {
877 result.append(
"\n"+(*
temporal())[i].print());
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 ) {
1127 detx += m_theta * std::cos(phi);
1128 dety += m_theta * std::sin(phi);
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=" +
CTA background model base class definition.
CTA event bin class interface definition.
const GCTAModelIrfBackground g_cta_inst_background_seed
CTA IRF background model class definition.
CTA observation class interface definition.
CTA instrument response function class definition.
Definition of support function used by CTA classes.
Integration class interface definition.
Mathematical function definitions.
Model registry class definition.
Spectral nodes model class definition.
Spectral model registry class definition.
Constant temporal model class interface definition.
Temporal model registry class definition.
double norm(const GVector &vector)
Computes vector norm.
Abstract base class for the CTA background model.
virtual GCTAInstDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const =0
virtual const GModelSpectralNodes & spectrum(void) const =0
virtual double rate_ebin(const GCTAInstDir &dir, const GEnergy &emin, const GEnergy &emax) const =0
const GCTAInstDir & dir(void) const
Return instrument direction.
GCTAEventBin class interface definition.
const GEnergy & ewidth(void) const
Return energy width of event bin.
GEnergy emin(void) const
Return minimum energy of event bin.
virtual void roi(const GRoi &roi)
Set ROI.
void reserve(const int &number)
Reserves space for events.
void append(const GCTAEventAtom &event)
Append event to event list.
CTA instrument direction class.
void dir(const GSkyDir &dir)
Set sky direction.
void dety(const double &y)
Set DETY coordinate (in radians)
void detx(const double &x)
Set DETX coordinate (in radians)
double eval(const double &phi)
Kernel for azimuth angle integration of background model.
double eval(const double &theta)
Kernel for offset angle integration of background model.
const GCTABackground * m_bgd
Pointer to background.
int m_iter
Romberg iterations.
GCTAInstDir m_roi_centre
RoI centre.
double m_logE
Log10 of energy.
CTA IRF background model class.
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 * xml_temporal(const GXmlElement &temporal) const
Return pointer to temporal model from 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 .
virtual void write(GXmlElement &xml) const
Write CTA instrument background model into XML element.
GCTAModelIrfBackground & operator=(const GCTAModelIrfBackground &bgd)
Assignment operator.
GModelTemporal * temporal(void) const
Return temporal model component.
std::vector< GTime > m_npred_times
Model time.
GModelTemporal * m_temporal
Temporal model.
std::vector< double > m_npred_values
Model values.
GModelSpectral * m_spectral
Spectral model.
GCTAModelIrfBackground(void)
Void constructor.
void set_pointers(void)
Set pointers.
GModelSpectral * xml_spectral(const GXmlElement &spectral) const
Return pointer to spectral model from XML element.
void free_members(void)
Delete class members.
bool valid_model(void) const
Verifies if model has all components.
virtual GCTAEventList * mc(const GObservation &obs, GRan &ran) const
Return simulated list of events.
GModelSpectral * spectral(void) const
Return spectral model component.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print CTA instrument background model information.
void init_members(void)
Initialise class members.
virtual void clear(void)
Clear CTA instrument background model.
virtual ~GCTAModelIrfBackground(void)
Destructor.
virtual void read(const GXmlElement &xml)
Read CTA instrument background model from XML element.
std::vector< GEnergy > m_npred_energies
Model energy.
std::vector< std::string > m_npred_names
Model names.
virtual GCTAModelIrfBackground * clone(void) const
Clone CTA instrument background model.
void copy_members(const GCTAModelIrfBackground &bgd)
Copy class members.
GCTAInstDir instdir(const GSkyDir &skydir) const
Get instrument direction from sky direction.
GSkyDir skydir(const GCTAInstDir &instdir) const
Get sky direction direction from instrument direction.
Interface for the CTA region of interest class.
Energy boundaries container class.
const GEnergy & emax(void) const
Return maximum energy of all intervals.
int size(void) const
Return number of energy boundaries.
const GEnergy & emin(void) const
Return minimum energy of all intervals.
Class that handles energies in a unit independent way.
double log10TeV(void) const
Return log10 of energy in TeV.
double MeV(void) const
Return energy in MeV.
Abstract interface for the event classes.
virtual bool is_atom(void) const =0
virtual const GEnergy & energy(void) const =0
virtual const GTime & time(void) const =0
void gti(const GGti >i)
Set Good Time Intervals.
void ebounds(const GEbounds &ebounds)
Set energy boundaries.
Good Time Interval class.
const GTime & tstop(void) const
Returns latest stop time in Good Time Intervals.
int size(void) const
Return number of Good Time Intervals.
const GTime & tstart(void) const
Returns earliest start time in Good Time Intervals.
GIntegral class interface definition.
double romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
void fixed_iter(const int &iter)
Set fixed number of iterations.
Abstract data model class.
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
virtual GModelData & operator=(const GModelData &model)
Assignment operator.
Interface definition for the model registry class.
Spectral nodes model class.
Interface definition for the spectral model registry class.
GModelSpectral * alloc(const GXmlElement &xml) const
Allocate spectral model that is found in XML element.
Abstract spectral model base class.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const =0
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const =0
virtual double flux(const GEnergy &emin, const GEnergy &emax) const =0
virtual GModelSpectral * clone(void) const =0
Clones object.
virtual void write(GXmlElement &xml) const =0
virtual std::string type(void) const =0
int size(void) const
Return number of parameters.
Constant temporal model class.
virtual GModelTemporalConst * clone(void) const
Clone constant temporal model.
Interface definition for the temporal model registry class.
GModelTemporal * alloc(const GXmlElement &xml) const
Allocate temporal model that is found in XML element.
Abstract temporal model base class.
virtual GModelTemporal * clone(void) const =0
Clones object.
virtual double eval(const GTime &srcTime, const bool &gradients=false) const =0
int size(void) const
Return number of parameters.
virtual std::string type(void) const =0
virtual GTimes mc(const double &rate, const GTime &tmin, const GTime &tmax, GRan &ran) const =0
virtual void write(GXmlElement &xml) const =0
std::vector< GModelPar * > m_pars
Pointers to all model parameters.
void write_attributes(GXmlElement &xml) const
Write model attributes.
std::string print_attributes(void) const
Print model attributes.
int size(void) const
Return number of parameters in model.
void read_attributes(const GXmlElement &xml)
Read model attributes.
const std::string & name(void) const
Return parameter name.
Abstract observation base class.
virtual std::string instrument(void) const =0
void id(const std::string &id)
Set observation identifier.
Random number generator class.
int size(void) const
Return number of times.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
virtual int elements(void) const
Return number of GXMLElement children of node.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
bool is_infinite(const double &x)
Signal if argument is infinite.
bool is_notanumber(const double &x)
Signal if argument is not a number.
const GCTAPointing & cta_pnt(const std::string &origin, const GObservation &obs)
Retrieve CTA pointing from generic observation.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
const GCTAInstDir & cta_dir(const std::string &origin, const GEvent &event)
Retrieve CTA instrument direction from generic event.
const GCTABackground & cta_rsp_bkg(const std::string &origin, const GObservation &obs)
Retrieve CTA background response from generic observation.
const GCTAEventList & cta_event_list(const std::string &origin, const GObservation &obs)
Retrieve CTA event list from generic observation.
void warning(const std::string &origin, const std::string &message)
Emits warning.