43 #define G_MC "GCTABackground3D::mc(GEnergy&, GTime&, GRan&)"
44 #define G_SET_MEMBERS "GCTABackground3D::set_members()"
45 #define G_INIT_MC_CACHE "GCTABackground3D::init_mc_cache()"
193 const double& dety)
const
210 double rate_emin = this->
rate(energy_nodes.
inx_left(), detx, dety);
211 double rate_emax = this->
rate(energy_nodes.
inx_right(), detx, dety);
215 if (rate_emin > 0.0 && rate_emax > 0.0) {
307 for (
int i = 0; i < table.
ncols(); ++i) {
308 std::string colname = table[i]->name();
309 if ((colname !=
"DETX_LO") && (colname !=
"DETX_HI") &&
310 (colname !=
"DETY_LO") && (colname !=
"DETY_HI") &&
311 (colname !=
"ENERG_LO") && (colname !=
"ENERG_HI") &&
312 (colname !=
"BKG") && (colname !=
"BGD")) {
368 GFits fits(filename);
373 if (extname.empty()) {
420 if (fits.contains(extname)) {
470 if (energy < emin || energy > emax) {
471 std::string msg =
"Event energy "+energy.
print()+
" is outside the "
472 "energy range ["+emin.
print()+
", "+emax.print()+
"] "
473 "covered by the background response table. Please "
474 "restrict the energy range of the simulation to the "
475 "validity range of the background response table.";
495 int inx_left = energy_nodes.
inx_left();
496 int inx_right = energy_nodes.
inx_right();
500 double max_rate =
m_mc_max[inx_left];
501 if (
m_mc_max[inx_right] > max_rate) {
520 double value = this->
operator()(logE, detx, dety);
527 if (value > max_rate) {
528 std::string msg =
"Background rate "+
gammalib::str(value)+
" "
529 "for "+energy.
print()+
" at "
533 "is larger than the maximum expected rate "+
535 "wrong with the code.";
540 double uniform = ran.
uniform() * max_rate;
543 if (uniform <= value) {
591 double x1 = emin.
MeV();
617 if (f1 > 0.0 && f2 > 0.0) {
634 if (x1 < emax.
MeV()) {
637 if (f1 > 0.0 && f2 > 0.0) {
664 result.append(
"=== GCTABackground3D ===");
818 std::string msg =
"Expected three-dimensional background "
819 "response table but found "+
821 " dimensions. Please specify a three-dimensional "
902 const int& iebin)
const
929 const int nsubbins = 10;
954 enodes.remove(enodes.size()-1);
960 if (i < m_num_energy-1) {
978 for (
int i = 0; i < energies.
size(); ++i) {
981 double logE = energies[i].log10TeV();
986 double total_flux = 0.0;
987 double dx = 0.5 * detx_bin;
988 double dy = 0.5 * dety_bin;
990 for (
int ix = 0; ix <
m_num_detx; ++ix, detx += detx_bin) {
992 for (
int iy = 0; iy <
m_num_dety; ++iy, dety += dety_bin) {
995 double i0 = (*this)(logE, detx, dety);
996 double i1 = (*this)(logE, detx-dx, dety-dy);
997 double i2 = (*this)(logE, detx, dety-dy);
998 double i3 = (*this)(logE, detx+dx, dety-dy);
999 double i4 = (*this)(logE, detx+dx, dety);
1000 double i5 = (*this)(logE, detx+dx, dety+dy);
1001 double i6 = (*this)(logE, detx, dety+dy);
1002 double i7 = (*this)(logE, detx-dx, dety+dy);
1003 double i8 = (*this)(logE, detx-dx, dety);
1006 double s1 =
solid_angle(detx, dety, detx-dx, dety-dy, detx, dety-dy);
1007 double s2 =
solid_angle(detx, dety, detx, dety-dy, detx+dx, dety-dy);
1008 double s3 =
solid_angle(detx, dety, detx+dx, dety-dy, detx+dx, dety);
1009 double s4 =
solid_angle(detx, dety, detx+dx, dety, detx+dx, dety+dy);
1010 double s5 =
solid_angle(detx, dety, detx+dx, dety+dy, detx, dety+dy);
1011 double s6 =
solid_angle(detx, dety, detx, dety+dy, detx-dx, dety+dy);
1012 double s7 =
solid_angle(detx, dety, detx-dx, dety+dy, detx-dx, dety);
1013 double s8 =
solid_angle(detx, dety, detx-dx, dety, detx-dx, dety-dy);
1016 double flux1 = s1 * (i1 + i2 + i0);
1017 double flux2 = s2 * (i2 + i3 + i0);
1018 double flux3 = s3 * (i3 + i4 + i0);
1019 double flux4 = s4 * (i4 + i5 + i0);
1020 double flux5 = s5 * (i5 + i6 + i0);
1021 double flux6 = s6 * (i6 + i7 + i0);
1022 double flux7 = s7 * (i7 + i8 + i0);
1023 double flux8 = s8 * (i8 + i1 + i0);
1024 double flux = (flux1 + flux2 + flux3 + flux4 +
1025 flux5 + flux6 + flux7 + flux8) / 3.0;
1037 if (total_flux > 0.0) {
1042 #if defined(G_DEBUG_MC_INIT)
1043 std::cout <<
"Energy=" << energies[i];
1044 std::cout <<
" Rate_total=" << total_flux;
1045 std::cout <<
" events/(s MeV)" << std::endl;
1053 std::string msg =
"Background response table is empty. Please provide "
1054 "a valid three-dimensional background template.";
1079 double max_rate = 0.0;
1086 int inx =
index(ix, iy, iebin);
1093 if (rate > max_rate) {
1142 const double& detx2,
const double& dety2,
1143 const double& detx3,
const double& dety3)
const
1146 double theta1 =
std::sqrt(detx1 * detx1 + dety1 * dety1);
1148 double theta2 =
std::sqrt(detx2 * detx2 + dety2 * dety2);
1150 double theta3 =
std::sqrt(detx3 * detx3 + dety3 * dety3);
1160 double a12 = dir1.
dist(dir2);
1161 double a13 = dir1.
dist(dir3);
1162 double a23 = dir2.
dist(dir3);
1165 double s = 0.5 * (a12 + a23 + a13);
1186 const double& dety)
const
double m_dety_max
DETY maximum (radians)
const GNodeArray & axis_nodes(const int &axis) const
Return axis nodes.
const int & ncols(void) const
Return number of columns in table.
void clear(void)
Clear energy container.
GCTABackground3D & operator=(const GCTABackground3D &bgd)
Assignment operator.
GFilename m_filename
Name of background response file.
GFitsTable * table(const int &extno)
Get pointer to table HDU.
void init_mc_max_rate(void) const
Initialise array of maximum background rate.
void detx(const double &x)
Set DETX coordinate (in radians)
double m_dety_min
DETY minimum (radians)
Random number generator class definition.
void warning(const std::string &origin, const std::string &message)
Emits warning.
int m_num_dety
Number of DETY bins.
int m_num[3]
Array of number of bins.
const GCTAResponseTable & table(void) const
Return response table.
std::vector< double > m_mc_max
Maximum background rate.
GCTABackground & operator=(const GCTABackground &bgd)
Assignment operator.
void write(GFitsBinTable &table) const
Write background into FITS table.
const std::string extname_cta_background3d
const double & wgt_left(void) const
Returns left node weight.
GEnergies m_energy
Vector of energies.
std::string extname(const std::string &defaultname="") const
Return extension name.
double log10TeV(void) const
Return log10 of energy in TeV.
Random number generator class.
double MeV(void) const
Return energy in MeV.
double solid_angle(const double &detx1, const double &dety1, const double &detx2, const double &dety2, const double &detx3, const double &dety3) const
Compute solid angle of pixel wedge.
void axis_radians(const int &axis)
Set nodes for a radians axis.
FITS file class interface definition.
void set_value(const double &value) const
Set indices and weighting factors for interpolation.
int m_inx_detx
DETX index.
void read(const GFitsTable &table)
Read response table from FITS table HDU.
void clear(void)
Clear background.
const double & axis_lo(const int &axis, const int &bin) const
Return lower bin boundary for bin in axis.
void append(const GEnergy &energy, const double &intensity)
Append node.
Definition of support function used by CTA classes.
void write(GFitsTable &table) const
Write response table into FITS table HDU.
int axis(const std::string &name) const
Determine index of an axis.
void radec(const double &ra, const double &dec)
Set equatorial sky direction (radians)
void copy_members(const GCTABackground3D &bgd)
Copy class members.
void remove(const int &index)
Remove energy from container.
double m_detx_max
DETX maximum (radians)
GVector sqrt(const GVector &vector)
Computes square root of vector elements.
int m_num_energy
Number of energy bins.
void init_members(void)
Initialise class members.
bool has_table(const std::string &name) const
Check whether a table exists.
void save(const GFilename &filename, const bool &clobber=false) const
Save background into FITS file.
const double & wgt_right(void) const
Returns right node weight.
void remove(const int &extno)
Remove HDU from FITS file.
void free_members(void)
Delete class members.
GVector tan(const GVector &vector)
Computes tangens of vector elements.
int m_num_detx
Number of DETX bins.
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
void set_members(void)
Set members from background table.
void clear(void)
Clear response table.
GCTAInstDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC instrument direction.
int index(const int &idetx, const int &idety, const int &iebin) const
Return background rate bin index.
double m_logE_min
Log10(E/TeV) minimum.
int size(void) const
Return number of energies in container.
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
double uniform(void)
Returns random double precision floating value in range 0 to 1.
void init_mc_cache(void) const
Initialise Monte Carlo cache.
CTA instrument direction class interface definition.
Abstract interface for FITS table.
bool is_valid(void) const
Return validity of background model.
GCTAResponseTable m_background
Background response table.
const int & inx_left(void) const
Returns left node index.
GEnergy energy(const int &index) const
Return node energy.
CTA 3D background class definition.
void extend(const GEnergies &energies)
Append energy container.
void load(const GFilename &filename)
Load background from FITS file.
const std::string & extname(void) const
Return extension name.
void axis_log10(const int &axis)
Set nodes for a logarithmic (base 10) axis.
int table(const std::string &name) const
Determine index of table.
std::string gadf_hduclas4(const GFits &fits, const std::string &hduclas4)
Return extension name for GADF response table of given HDU class 4.
const int & inx_right(void) const
Returns right node index.
void init_members(void)
Initialise class members.
double plaw_integral(const double &x1, const double &f1, const double &x2, const double &f2)
Returns the integral of a power law.
std::string url(void) const
Return Uniform Resource Locator (URL)
int m_inx_dety
DETY index.
virtual double operator()(const double &logE, const double &detx, const double &dety) const
Return background rate in units of events MeV s sr .
int axis_bins(const int &axis) const
Return number bins in an axis.
void clear(void)
Clear file name.
virtual void clear(void)
Clear spectral nodes model.
double m_logE_max
Log10(E/TeV) maximum.
GModelSpectralNodes m_mc_spectrum
Response cube spectrum.
int nodes(void) const
Return number of nodes.
int m_inx_energy
Energy index.
const double & axis_hi(const int &axis, const int &bin) const
Return upper bin boundary for bin in axis.
void remove(const int &colnum)
Remove column from the table.
virtual GFitsTable * clone(void) const =0
Clones object.
GCTABackground3D(void)
Void constructor.
GEnergy & append(const GEnergy &energy)
Append energy to container.
Exception handler interface definition.
Abstract base class for the CTA background model.
double dist(const GSkyDir &dir) const
Compute angular distance between sky directions in radians.
FITS binary table class definition.
double atan2(const double &y, const double &x)
Compute arc tangens in radians.
std::string print(const GChatter &chatter=NORMAL) const
Print background information.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
CTA instrument direction class.
void dety(const double &y)
Set DETY coordinate (in radians)
const std::string & axis_lo_unit(const int &axis) const
Return lower bin boundary unit for axis.
double rate(const int &iebin, const double &detx, const double &dety) const
Return background rate for a given energy bin and DETX-DETY value (events/s/MeV/sr) ...
const std::string & axis_hi_unit(const int &axis) const
Return upper bin boundary unit for axis.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
void close(void)
Close FITS file.
const int & axes(void) const
Return number of axes of the tables.
double rate_ebin(const GCTAInstDir &dir, const GEnergy &emin, const GEnergy &emax) const
Returns background rate integrated over energy interval in units of events s sr .
GVector atan(const GVector &vector)
Computes arctan of vector elements.
GFilename filename(void) const
Return filename.
Filename class interface definition.
virtual ~GCTABackground3D(void)
Destructor.
Mathematical function definitions.
int m_inx_bgd
Background index.
void read(const GFitsTable &table)
Read background from FITS table.
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 free_members(void)
Delete class members.
GCTABackground3D * clone(void) const
Clone background.
double m_detx_min
DETX minimum (radians)