50#define G_EVAL "GCTAModelAeffBackground::eval(GEvent&, GObservation&, bool&)"
51#define G_NPRED "GCTAModelAeffBackground::npred(GEnergy&, GTime&,"\
53#define G_MC "GCTAModelAeffBackground::mc(GObservation&, GRan&)"
54#define G_XML_SPECTRAL "GCTAModelAeffBackground::xml_spectral(GXmlElement&)"
55#define G_XML_TEMPORAL "GCTAModelAeffBackground::xml_temporal(GXmlElement&)"
56#define G_AEFF_INTEGRAL "GCTAModelAeffBackground::aeff_integral("\
57 "GObservation&, double&)"
62#define G_USE_NPRED_CACHE
370 const bool& gradients)
const
382 double logE =
event.energy().log10TeV();
383 double spat = aeff(logE,
395 double value = spat * spec * temp;
402 double fact = spat * temp;
405 (*
spectral())[i].factor_gradient((*
spectral())[i].factor_gradient() * fact );
411 double fact = spat * spec;
414 (*
temporal())[i].factor_gradient((*
temporal())[i].factor_gradient() * fact );
440 const GTime& obsTime,
445 bool has_npred =
false;
451 #if defined(G_USE_NPRED_CACHE)
460 #if defined(G_DEBUG_NPRED)
461 std::cout <<
"GCTAModelAeffBackground::npred:";
462 std::cout <<
" cache=" << i;
463 std::cout <<
" npred=" <<
npred << std::endl;
485 #if defined(G_USE_NPRED_CACHE)
493 #if defined(G_NAN_CHECK)
495 std::string origin =
"GCTAModelAeffBackground::npred";
496 std::string message =
" NaN/Inf encountered (npred=" +
550 const GGti& gti = events.
gti();
555 double cos_max_theta = std::cos(max_theta);
571 for (
int i = 0; i < spectral_ebounds.
size(); ++i) {
575 double arg =
norm * intensity;
582 for (
int ieng = 0; ieng < ebounds.
size(); ++ieng) {
591 #if defined(G_DUMP_MC)
592 std::cout <<
"GCTAModelAeffBackground::mc(\"" <<
name() <<
"\": ";
593 std::cout <<
"rate=" << rate <<
" cts/s)" << std::endl;
602 for (
int itime = 0; itime < gti.
size(); ++itime) {
611 int n_events = times.
size();
620 #if defined(G_DUMP_MC)
621 std::cout <<
" Interval " << itime;
622 std::cout <<
" times=" << n_events << std::endl;
623 int n_killed_by_roi = 0;
627 for (
int i = 0; i < n_events; ++i) {
640 if (max_aeff <= 0.0) {
650 double acceptance_fraction = 0.0;
658 offset = std::acos(1.0 - ran.
uniform() *
659 (1.0 - cos_max_theta));
663 double value = aeff(energy.
log10TeV(), offset, phi,
679 acceptance_fraction = value / max_aeff;
681 }
while ((ran.
uniform() > acceptance_fraction) &&
703 event.energy(energy);
704 event.time(times[i]);
707 if (events.
roi().contains(event)) {
710 #if defined(G_DUMP_MC)
719 #if defined(G_DUMP_MC)
720 std::cout <<
" Killed by ROI=";
721 std::cout << n_killed_by_roi << std::endl;
834 for (
int k = 0; k < n; ++k) {
847 bool write_temporal = ((
m_temporal != NULL) &&
849 (*m_temporal)[0].value() != 1.0));
853 src = xml.
append(
"source");
865 if (write_temporal) {
895 result.append(
"=== GCTAModelAeffBackground ===");
906 if (n_spectral > 0) {
908 if (n_temporal > 0) {
909 result.append(
" * ");
912 if (n_temporal > 0) {
921 for (
int i = 0; i < n_spectral; ++i) {
922 result.append(
"\n"+(*
spectral())[i].print());
926 for (
int i = 0; i < n_temporal; ++i) {
927 result.append(
"\n"+(*
temporal())[i].print());
1022 int n_pars = n_spectral + n_temporal;
1028 for (
int i = 0; i < n_spectral; ++i) {
1033 for (
int i = 0; i < n_temporal; ++i) {
1109 const double& logE)
const
1112 static const int iter_theta = 6;
1113 static const int iter_phi = 6;
1140 double value = integral.
romberg(0.0, roi_radius);
1143 #if defined(G_NAN_CHECK)
1145 std::string origin =
"GCTAModelAeffBackground::aeff_integral";
1146 std::string message =
" NaN/Inf encountered (value=" +
1200 #if defined(G_NAN_CHECK)
1202 std::string origin =
"GCTAModelAeffBackground::npred_roi_kern_theta::eval"
1204 std::string message =
" NaN/Inf encountered (value=" +
1233 double detx = m_roi_centre.detx();
1234 double dety = m_roi_centre.dety();
1235 if (m_theta > 0.0 ) {
1236 detx += m_theta * std::cos(phi);
1237 dety += m_theta * std::sin(phi);
1242 double theta_prime = dir.
theta();
1243 double phi_prime = dir.
phi();
1246 double value = (*m_aeff)(m_logE, theta_prime, phi_prime);
1249 #if defined(G_NAN_CHECK)
1251 std::string origin =
"GCTAModelAeffBackground::npred_roi_kern_phi::eval"
1253 std::string message =
" NaN/Inf encountered (value=" +
CTA background model base class definition.
const GCTAModelAeffBackground g_cta_aeff_background_seed
CTA Aeff 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 effective area.
virtual double max(const double &logE, const double &zenith, const double &azimuth, const bool &etrue=true) const =0
const GCTAInstDir & dir(void) const
Return instrument direction.
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.
double theta(void) const
Return offset angle (in radians)
void dir(const GSkyDir &dir)
Set sky direction.
double phi(void) const
Return azimuth angle (in radians)
double eval(const double &phi)
Kernel for azimuth angle integration of effective area background model.
const GCTAAeff * m_aeff
Pointer to effectve area.
GCTAInstDir m_roi_centre
RoI centre.
int m_iter
Romberg iterations.
double eval(const double &theta)
Kernel for offset angle integration of effective area background model.
double m_logE
Log10 of energy.
virtual GCTAModelAeffBackground * clone(void) const
Clone CTA effective area background model.
void copy_members(const GCTAModelAeffBackground &bgd)
Copy class members.
GModelTemporal * temporal(void) const
Return temporal model component.
void init_members(void)
Initialise class members.
virtual void read(const GXmlElement &xml)
Read CTA effective area background model from XML element.
virtual ~GCTAModelAeffBackground(void)
Destructor.
GCTAModelAeffBackground & operator=(const GCTAModelAeffBackground &bgd)
Assignment operator.
virtual double eval(const GEvent &event, const GObservation &obs, const bool &gradients=false) const
Return background rate in units of events MeV s sr .
GModelSpectral * spectral(void) const
Return spectral model component.
GModelSpectral * m_spectral
Spectral model.
virtual GCTAEventList * mc(const GObservation &obs, GRan &ran) const
Return simulated list of events.
virtual void clear(void)
Clear CTA effective area background model.
GCTAModelAeffBackground(void)
Void constructor.
void free_members(void)
Delete class members.
virtual void write(GXmlElement &xml) const
Write CTA effective area background model into XML element.
std::vector< GTime > m_npred_times
Model time.
int m_n_mc_energies
Energy sampling for MC spectrum.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print CTA effective area background model information.
GModelSpectral * xml_spectral(const GXmlElement &spectral) const
Return pointer to spectral model from XML element.
std::vector< GEnergy > m_npred_energies
Model energy.
void set_pointers(void)
Set pointers.
virtual double npred(const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return spatially integrated background rate in units of events MeV s .
std::vector< double > m_npred_values
Model values.
bool valid_model(void) const
Verifies if model has all components.
GModelTemporal * m_temporal
Temporal model.
std::vector< std::string > m_npred_names
Model names.
GModelTemporal * xml_temporal(const GXmlElement &temporal) const
Return pointer to temporal model from XML element.
double aeff_integral(const GObservation &obs, const double &logE) const
Spatially integrate effective area for given energy.
const double & zenith(void) const
Return pointing zenith angle.
GCTAInstDir instdir(const GSkyDir &skydir) const
Get instrument direction from sky direction.
const GSkyDir & dir(void) const
Return pointing sky direction.
const double & azimuth(void) const
Return pointing azimuth angle.
Interface for the CTA region of interest class.
const double & radius(void) const
Returns radius of region of interest in degrees.
const GCTAInstDir & centre(void) const
Returns region of interest centre.
Energy boundaries container class.
const GEnergy & emax(void) const
Return maximum energy of all intervals.
int size(void) const
Return number of energy boundaries.
GEnergy elogmean(const int &index) const
Returns logarithmic mean energy for a given energy interval.
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.
Abstract interface for the event classes.
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.
const GTime & tstart(void) const
Return start time.
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.
double uniform(void)
Returns random double precision floating value in range 0 to 1.
void rotate_deg(const double &phi, const double &theta)
Rotate sky direction by zenith and azimuth angle.
double dist(const GSkyDir &dir) const
Compute angular distance between sky directions in radians.
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 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.
const GCTAAeff & cta_rsp_aeff(const std::string &origin, const GObservation &obs)
Retrieve CTA effective area response from generic observation.