47 const GModelRegistry g_cta_aeff_background_registry(&g_cta_aeff_background_seed);
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) {
572 GEnergy energy = spectral_ebounds.elogmean(i);
575 double arg = norm * intensity;
577 spectral.append(energy, arg);
582 for (
int ieng = 0; ieng < ebounds.
size(); ++ieng) {
588 double rate = spectral.flux(ebounds.
emin(ieng), ebounds.
emax(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;
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) &&
693 offset * gammalib::rad2deg);
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;
773 spectral = xml.
element(
"spectrum", 0);
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) {
866 if (dynamic_cast<GModelTemporalConst*>(
temporal()) == NULL) {
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) {
926 for (
int i = 0; i < n_temporal; ++i) {
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;
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 ) {
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=" +
virtual void write(GXmlElement &xml) const =0
CTA background model base class definition.
Constant temporal model class interface definition.
void init_members(void)
Initialise class members.
CTA Aeff background model class definition.
double eval(const double &phi)
Kernel for azimuth angle integration of effective area background model.
virtual GTimes mc(const double &rate, const GTime &tmin, const GTime &tmax, 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.
int m_iter
Romberg iterations.
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
Abstract temporal model base class.
virtual void roi(const GRoi &roi)
Set ROI.
const GCTAModelAeffBackground g_cta_aeff_background_seed
int size(void) const
Return number of parameters.
void ebounds(const GEbounds &ebounds)
Set energy boundaries.
int size(void) const
Return number of energy boundaries.
GVector cos(const GVector &vector)
Computes cosine of vector elements.
virtual double eval(const GEvent &event, const GObservation &obs, const bool &gradients=false) const
Return background rate in units of events MeV s sr .
virtual void read(const GXmlElement &xml)
Read CTA effective area background model from XML element.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const =0
GModelTemporal * xml_temporal(const GXmlElement &temporal) const
Return pointer to temporal model from XML element.
void append(const GCTAEventAtom &event)
Append event to event list.
GModelTemporal * temporal(void) const
Return temporal model component.
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.
const double & radius(void) const
Returns radius of region of interest in degrees.
void gti(const GGti >i)
Set Good Time Intervals.
const GCTAAeff * m_aeff
Pointer to effectve area.
void free_members(void)
Delete class members.
Spectral model registry class definition.
const double & zenith(void) const
Return pointing zenith angle.
virtual void write(GXmlElement &xml) const =0
double acos(const double &arg)
Computes acos by avoiding NaN due to rounding errors.
double log10TeV(void) const
Return log10 of energy in TeV.
GModelSpectral * m_spectral
Spectral model.
Random number generator class.
virtual std::string type(void) const
Return data model type.
Spectral nodes model class definition.
Interface for the CTA region of interest class.
virtual int elements(void) const
Return number of GXMLElement children of node.
GIntegral class interface definition.
virtual GModelTemporalConst * clone(void) const
Clone constant temporal model.
virtual const GTime & time(void) const =0
void dir(const GSkyDir &dir)
Set sky direction.
double eval(const double &theta)
Kernel for offset angle integration of effective area background model.
int size(void) const
Return number of Good Time Intervals.
Spectral nodes model class.
GCTAModelAeffBackground(void)
Void constructor.
void id(const std::string &id)
Set observation identifier.
GCTAInstDir m_roi_centre
RoI centre.
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.
virtual GCTAModelAeffBackground * clone(void) const
Clone CTA effective area background model.
virtual GCTAEventList * mc(const GObservation &obs, GRan &ran) const
Return simulated list of events.
std::vector< double > m_npred_values
Model values.
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.
virtual void clear(void)
Clear CTA effective area background model.
double theta(void) const
Return offset angle (in radians)
virtual double npred(const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return spatially integrated background rate in units of events MeV s .
void rotate_deg(const double &phi, const double &theta)
Rotate sky direction by zenith and azimuth angle.
const GEnergy & emin(void) const
Return minimum energy of all intervals.
std::vector< GEnergy > m_npred_energies
Model energy.
const GCTAInstDir & centre(void) const
Returns region of interest centre.
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
double uniform(void)
Returns random double precision floating value in range 0 to 1.
Abstract data model class.
double m_logE
Log10 of energy.
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 std::string print(const GChatter &chatter=NORMAL) const
Print CTA effective area background model information.
virtual GModelData & operator=(const GModelData &model)
Assignment operator.
std::vector< GTime > m_npred_times
Model time.
std::vector< std::string > m_npred_names
Model names.
Good Time Interval class.
void copy_members(const GCTAModelAeffBackground &bgd)
Copy class members.
virtual double eval(const GTime &srcTime, const bool &gradients=false) const =0
Abstract observation base class.
virtual double max(const double &logE, const double &zenith, const double &azimuth, const bool &etrue=true) const =0
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.
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.
Abstract base class for the CTA effective area.
const double & azimuth(void) const
Return pointing azimuth angle.
virtual ~GCTAModelAeffBackground(void)
Destructor.
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.
Temporal model registry class definition.
GModelTemporal * m_temporal
Temporal model.
GModelSpectral * spectral(void) const
Return spectral model component.
void free_members(void)
Delete class members.
bool valid_model(void) const
Verifies if model has all components.
GVector sin(const GVector &vector)
Computes sine of vector elements.
double aeff_integral(const GObservation &obs, const double &logE) const
Spatially integrate effective area for given energy.
GCTAModelAeffBackground & operator=(const GCTAModelAeffBackground &bgd)
Assignment operator.
double dist(const GSkyDir &dir) const
Compute angular distance between sky directions in radians.
void fixed_iter(const int &iter)
Set fixed number of iterations.
virtual void write(GXmlElement &xml) const
Write CTA effective area background model into XML element.
virtual GModelTemporal * clone(void) const =0
Clones object.
void read_attributes(const GXmlElement &xml)
Read model attributes.
GModelSpectral * xml_spectral(const GXmlElement &spectral) const
Return pointer to spectral model from XML element.
CTA instrument direction class.
const GSkyDir & dir(void) const
Return pointing sky direction.
const GEnergy & emax(void) const
Return maximum energy of all intervals.
Model registry class definition.
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.
const GCTAAeff & cta_rsp_aeff(const std::string &origin, const GObservation &obs)
Retrieve CTA effective area response from generic observation.
const GTime & tstart(void) const
Return start time.
double phi(void) const
Return azimuth angle (in radians)
Integration class interface definition.
int m_n_mc_energies
Energy sampling for MC spectrum.
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.
void set_pointers(void)
Set pointers.