Commit 68896b275c7c81e4d4392d338ec67ebcaaebb09a
1 parent
fb39a2b9
In absence of IRF background template, use constant background for RING method in ctskymap
Showing
2 changed files
with
52 additions
and
23 deletions
doc/source/users/reference_manual/ctskymap.rst
| @@ -19,6 +19,11 @@ background subtraction method can be selected using the ``bkgsubtract`` | @@ -19,6 +19,11 @@ background subtraction method can be selected using the ``bkgsubtract`` | ||
| 19 | parameter. By default, no background model is subtracted (method ``NONE``). | 19 | parameter. By default, no background model is subtracted (method ``NONE``). |
| 20 | If ``IRF`` is selected, the background template that are shipped with the | 20 | If ``IRF`` is selected, the background template that are shipped with the |
| 21 | Instrument Response Functions will be used for background subtraction. | 21 | Instrument Response Functions will be used for background subtraction. |
| 22 | +If ``RING`` is selected, the background is estimated from a ring with the | ||
| 23 | +inner radius specified by the ``inradius`` parameter and the other radius | ||
| 24 | +specified by the ``outradius`` parameter. If a background template is available, | ||
| 25 | +that template will be used for weighting the counts in the ring. Otherwise, a | ||
| 26 | +constant background rate will be assumed. | ||
| 22 | 27 | ||
| 23 | :ref:`ctskymap` generates a FITS file comprising a sky map as primary extension. | 28 | :ref:`ctskymap` generates a FITS file comprising a sky map as primary extension. |
| 24 | If a background subtraction method was selected, the FITS file will contain | 29 | If a background subtraction method was selected, the FITS file will contain |
src/ctskymap/ctskymap.cpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * ctskymap - Sky mapping tool * | 2 | * ctskymap - Sky mapping tool * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2018 by Juergen Knoedlseder * | 4 | + * copyright (C) 2011-2019 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -33,8 +33,9 @@ | @@ -33,8 +33,9 @@ | ||
| 33 | 33 | ||
| 34 | /* __ Method name definitions ____________________________________________ */ | 34 | /* __ Method name definitions ____________________________________________ */ |
| 35 | #define G_GET_PARAMETERS "ctskymap::get_parameter()" | 35 | #define G_GET_PARAMETERS "ctskymap::get_parameter()" |
| 36 | -#define G_MAP_EVENTS "ctskymap::map_events(GCTAObservation*)" | ||
| 37 | -#define G_MAP_BACKGROUND_IRF "ctskymap::map_background_irf(GCTAObservation*)" | 36 | +#define G_FILL_MAPS_COUNTS "ctskymap::fill_maps_counts(GCTAObservation*)" |
| 37 | +#define G_FILL_MAPS_ACCEPTANCE "ctskymap::fill_maps_acceptance("\ | ||
| 38 | + "GCTAObservation*)" | ||
| 38 | #define G_RING_BOUNDING_BOX "ctskymap::ring_bounding_box(int&, int&, int&, "\ | 39 | #define G_RING_BOUNDING_BOX "ctskymap::ring_bounding_box(int&, int&, int&, "\ |
| 39 | "int&, int&)" | 40 | "int&, int&)" |
| 40 | #define G_RING_KERNEL "ctskymap::ring_kernel(double&, double&)" | 41 | #define G_RING_KERNEL "ctskymap::ring_kernel(double&, double&)" |
| @@ -813,7 +814,7 @@ void ctskymap::fill_maps_counts(GCTAObservation* obs) | @@ -813,7 +814,7 @@ void ctskymap::fill_maps_counts(GCTAObservation* obs) | ||
| 813 | // Make sure that the observation holds a CTA event list. If this | 814 | // Make sure that the observation holds a CTA event list. If this |
| 814 | // is not the case then throw an exception. | 815 | // is not the case then throw an exception. |
| 815 | if (events == NULL) { | 816 | if (events == NULL) { |
| 816 | - throw GException::no_list(G_MAP_EVENTS); | 817 | + throw GException::no_list(G_FILL_MAPS_COUNTS); |
| 817 | } | 818 | } |
| 818 | 819 | ||
| 819 | // Setup energy range covered by data | 820 | // Setup energy range covered by data |
| @@ -863,14 +864,14 @@ void ctskymap::fill_maps_counts(GCTAObservation* obs) | @@ -863,14 +864,14 @@ void ctskymap::fill_maps_counts(GCTAObservation* obs) | ||
| 863 | } | 864 | } |
| 864 | 865 | ||
| 865 | // Fill event in skymap | 866 | // Fill event in skymap |
| 866 | - #pragma omp critical(ctskymap_map_events) | 867 | + #pragma omp critical(ctskymap_fill_maps_counts_1) |
| 867 | m_counts(pixel) += 1.0; | 868 | m_counts(pixel) += 1.0; |
| 868 | num_in_map++; | 869 | num_in_map++; |
| 869 | 870 | ||
| 870 | } // endfor: looped over all events | 871 | } // endfor: looped over all events |
| 871 | 872 | ||
| 872 | // Log binning results | 873 | // Log binning results |
| 873 | - #pragma omp critical(ctskymap_map_events) | 874 | + #pragma omp critical(ctskymap_fill_maps_counts_2) |
| 874 | { | 875 | { |
| 875 | log_header3(TERSE, get_obs_header(obs)); | 876 | log_header3(TERSE, get_obs_header(obs)); |
| 876 | log_value(NORMAL, "Events in list", obs->events()->size()); | 877 | log_value(NORMAL, "Events in list", obs->events()->size()); |
| @@ -898,35 +899,52 @@ void ctskymap::fill_maps_counts(GCTAObservation* obs) | @@ -898,35 +899,52 @@ void ctskymap::fill_maps_counts(GCTAObservation* obs) | ||
| 898 | * No response information available for observation. | 899 | * No response information available for observation. |
| 899 | * No background template available in instrument response function. | 900 | * No background template available in instrument response function. |
| 900 | * | 901 | * |
| 901 | - * Computes a background acceptance sky map using the IRF template for a | ||
| 902 | - * given observation and adds the estimate to the acceptance sky map. | 902 | + * Computes a background acceptance sky map for a given observation and adds |
| 903 | + * the estimate to the acceptance sky map. | ||
| 904 | + * | ||
| 905 | + * If the response contains a background template, that template is used to | ||
| 906 | + * compute the background acceptance map. | ||
| 907 | + * | ||
| 908 | + * If no background template is available, the outcome depends on the | ||
| 909 | + * background subtraction method. If ``IRF`` background subtraction is | ||
| 910 | + * requested, an exception is thrown. For ``RING`` background subtraction, | ||
| 911 | + * a constant background rate is assumed. | ||
| 903 | ***************************************************************************/ | 912 | ***************************************************************************/ |
| 904 | void ctskymap::fill_maps_acceptance(GCTAObservation* obs) | 913 | void ctskymap::fill_maps_acceptance(GCTAObservation* obs) |
| 905 | { | 914 | { |
| 915 | + // Initialise IRF background template pointer | ||
| 916 | + const GCTABackground* bkg = NULL; | ||
| 917 | + | ||
| 906 | // Get IRF response | 918 | // Get IRF response |
| 907 | const GCTAResponseIrf* rsp = dynamic_cast<const GCTAResponseIrf*> | 919 | const GCTAResponseIrf* rsp = dynamic_cast<const GCTAResponseIrf*> |
| 908 | (obs->response()); | 920 | (obs->response()); |
| 909 | 921 | ||
| 910 | // Throw an exception if observation has no instrument response function | 922 | // Throw an exception if observation has no instrument response function |
| 911 | - if (rsp == NULL) { | 923 | + if ((rsp == NULL) && (m_bkgsubtract != "RING")) { |
| 912 | std::string msg = "No response information available for "+ | 924 | std::string msg = "No response information available for "+ |
| 913 | get_obs_header(obs)+" to compute IRF background. " | 925 | get_obs_header(obs)+" to compute IRF background. " |
| 914 | "Please specify response information or use " | 926 | "Please specify response information or use " |
| 915 | "another background subtraction method."; | 927 | "another background subtraction method."; |
| 916 | - throw GException::invalid_value(G_MAP_BACKGROUND_IRF, msg); | 928 | + throw GException::invalid_value(G_FILL_MAPS_ACCEPTANCE, msg); |
| 917 | } | 929 | } |
| 918 | 930 | ||
| 919 | - // Get IRF background template | ||
| 920 | - const GCTABackground* bkg = rsp->background(); | 931 | + // ... otherwise get IRF background template |
| 932 | + else { | ||
| 933 | + | ||
| 934 | + // Get IRF background template | ||
| 935 | + bkg = rsp->background(); | ||
| 936 | + | ||
| 937 | + // Throw an exception if observation has no IRF background template | ||
| 938 | + if ((bkg == NULL) && (m_bkgsubtract != "RING")) { | ||
| 939 | + std::string msg = "No IRF background template found in instrument " | ||
| 940 | + "response function for "+ | ||
| 941 | + get_obs_header(obs)+". Please specify an " | ||
| 942 | + "instrument response function containing a " | ||
| 943 | + "background template."; | ||
| 944 | + throw GException::invalid_value(G_FILL_MAPS_ACCEPTANCE, msg); | ||
| 945 | + } | ||
| 921 | 946 | ||
| 922 | - // Throw an exception if observation has no IRF background template | ||
| 923 | - if (bkg == NULL) { | ||
| 924 | - std::string msg = "No IRF background template found in instrument " | ||
| 925 | - "response function for "+ | ||
| 926 | - get_obs_header(obs)+". Please specify an instrument " | ||
| 927 | - "response function containing a background template."; | ||
| 928 | - throw GException::invalid_value(G_MAP_BACKGROUND_IRF, msg); | ||
| 929 | - } | 947 | + } // endelse: got IRF background template |
| 930 | 948 | ||
| 931 | // Set minimum and maximum energy as GEnergy instances | 949 | // Set minimum and maximum energy as GEnergy instances |
| 932 | GEnergy emin(m_emin, "TeV"); | 950 | GEnergy emin(m_emin, "TeV"); |
| @@ -961,13 +979,13 @@ void ctskymap::fill_maps_acceptance(GCTAObservation* obs) | @@ -961,13 +979,13 @@ void ctskymap::fill_maps_acceptance(GCTAObservation* obs) | ||
| 961 | GCTAInstDir instdir = obs->pointing().instdir(skydir); | 979 | GCTAInstDir instdir = obs->pointing().instdir(skydir); |
| 962 | 980 | ||
| 963 | // Compute background value | 981 | // Compute background value |
| 964 | - double value = bkg->rate_ebin(instdir, emin, emax); | 982 | + double value = (bkg != NULL) ? bkg->rate_ebin(instdir, emin, emax) : 1.0; |
| 965 | 983 | ||
| 966 | // Multiply background rate with livetime and solid angle | 984 | // Multiply background rate with livetime and solid angle |
| 967 | value *= exposure * m_solidangle[i]; | 985 | value *= exposure * m_solidangle[i]; |
| 968 | 986 | ||
| 969 | // Add number of background events to acceptance map | 987 | // Add number of background events to acceptance map |
| 970 | - #pragma omp critical(ctskymap_map_acceptance) | 988 | + #pragma omp critical(ctskymap_fill_maps_acceptance_1) |
| 971 | m_acceptance(i) += value; | 989 | m_acceptance(i) += value; |
| 972 | 990 | ||
| 973 | // Update total number of background events | 991 | // Update total number of background events |
| @@ -976,8 +994,14 @@ void ctskymap::fill_maps_acceptance(GCTAObservation* obs) | @@ -976,8 +994,14 @@ void ctskymap::fill_maps_acceptance(GCTAObservation* obs) | ||
| 976 | } // endfor: looped over acceptance map pixels | 994 | } // endfor: looped over acceptance map pixels |
| 977 | 995 | ||
| 978 | // Log acceptance results | 996 | // Log acceptance results |
| 979 | - #pragma omp critical(ctskymap_map_events) | 997 | + #pragma omp critical(ctskymap_fill_maps_acceptance_2) |
| 980 | { | 998 | { |
| 999 | + // Set message string | ||
| 1000 | + std::string msg = (bkg != NULL) ? "Use IRF background template" | ||
| 1001 | + : "Use constant background rate"; | ||
| 1002 | + | ||
| 1003 | + // Log information | ||
| 1004 | + log_value(NORMAL, "Background estimate", msg); | ||
| 981 | log_value(NORMAL, "Events in background", int(total+0.5)); | 1005 | log_value(NORMAL, "Events in background", int(total+0.5)); |
| 982 | } | 1006 | } |
| 983 | 1007 |