Commit c4c9029b3dfdd2eadc031b753f67974e6294dba0
1 parent
68896b27
Add #pragma omp critical in ctfindvar::get_alphas and exclude all low count time…
… bins in ctfindvar::get_variability_sig before entering the iterative loop (#2804)
Showing
1 changed file
with
23 additions
and
22 deletions
src/ctfindvar/ctfindvar.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * ctfindvar - Time variability search tool * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2018 by Simon Bonnefoy * | |
| 4 | + * copyright (C) 2018-2019 by Simon Bonnefoy * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -229,7 +229,7 @@ void ctfindvar::run(void) |
| 229 | 229 | if (logDebug()) { |
| 230 | 230 | log.cout(true); |
| 231 | 231 | } |
| 232 | - | |
| 232 | + | |
| 233 | 233 | // Get task parameters |
| 234 | 234 | get_parameters(); |
| 235 | 235 | |
| ... | ... | @@ -544,7 +544,7 @@ void ctfindvar::init_gtis(void) |
| 544 | 544 | // Set up Good Time Intervals by appending all intervals that overlap |
| 545 | 545 | // with at least one of the observations |
| 546 | 546 | for (int i = 0; i < bins; ++i) { |
| 547 | - | |
| 547 | + | |
| 548 | 548 | // Get time interval |
| 549 | 549 | GTime tstart(m_tstart + i*tinterval); |
| 550 | 550 | GTime tstop(m_tstart + (i+1.0)*tinterval); |
| ... | ... | @@ -810,7 +810,7 @@ void ctfindvar::analyse_cube(void) |
| 810 | 810 | m_model_above_thr.append(sky_model(dir_pix)); |
| 811 | 811 | } |
| 812 | 812 | } |
| 813 | - | |
| 813 | + | |
| 814 | 814 | } // endfor: looped over pixels |
| 815 | 815 | |
| 816 | 816 | // Log results |
| ... | ... | @@ -872,7 +872,7 @@ std::vector<int> ctfindvar::get_pixels(void) |
| 872 | 872 | } // endfor: looped over all models |
| 873 | 873 | |
| 874 | 874 | } // endif: there were input models |
| 875 | - | |
| 875 | + | |
| 876 | 876 | // ... otherwise query the source position |
| 877 | 877 | else { |
| 878 | 878 | |
| ... | ... | @@ -917,7 +917,7 @@ GModelSky ctfindvar::sky_model(const GSkyDir& dir) const |
| 917 | 917 | |
| 918 | 918 | // Create a sky model |
| 919 | 919 | GModelSky model(spatial, spectral); |
| 920 | - | |
| 920 | + | |
| 921 | 921 | // Build model name from celestial coordinates |
| 922 | 922 | double ra = dir.ra_deg(); |
| 923 | 923 | double dec = dir.dec_deg(); |
| ... | ... | @@ -960,6 +960,14 @@ GNdarray ctfindvar::get_variability_sig(const int& ipix) |
| 960 | 960 | // Get alpha values for specified pixel |
| 961 | 961 | std::vector<double> alphas = get_alphas(ipix); |
| 962 | 962 | |
| 963 | + // Exclude all bins from the background estimate for which the | |
| 964 | + // number of events is below "minoff" or for which alpha is zero | |
| 965 | + for (int i = 0; i < m_gti.size(); ++i) { | |
| 966 | + if (m_counts(ipix, i) < m_minoff || alphas[i] == 0.0) { | |
| 967 | + accepted_bin_bckg_vector[i] = false; | |
| 968 | + } | |
| 969 | + } | |
| 970 | + | |
| 963 | 971 | // Loop over pixels until all background pixels are removed |
| 964 | 972 | bool background_validated = false; |
| 965 | 973 | while (background_validated == false) { |
| ... | ... | @@ -970,26 +978,18 @@ GNdarray ctfindvar::get_variability_sig(const int& ipix) |
| 970 | 978 | // Loop over all the GTIs of the pixel |
| 971 | 979 | for (int i = 0; i < m_gti.size(); ++i) { |
| 972 | 980 | |
| 973 | - // The GTI is discared from background calculation and not | |
| 981 | + // The GTI is discarded from background calculation and not | |
| 974 | 982 | // checked again |
| 975 | 983 | if (!accepted_bin_bckg_vector[i]) { |
| 976 | 984 | continue; |
| 977 | 985 | } |
| 978 | 986 | |
| 979 | - // ... otherwise check if bin fails minoff check or no observations | |
| 980 | - // overlap it | |
| 981 | - else if (m_counts(ipix, i) < m_minoff || alphas[i] == 0) { | |
| 982 | - accepted_bin_bckg_vector[i] = false; | |
| 983 | - continue; | |
| 984 | - } | |
| 985 | - | |
| 986 | - // ... otherwise | |
| 987 | + // ... otherwise GTI is selected, and we loop over all the | |
| 988 | + // others | |
| 987 | 989 | double noff = 0.0; |
| 988 | 990 | double alpha = 0.0; |
| 989 | - | |
| 990 | - // Got one GTI selected (i), looping over all the others (j). | |
| 991 | 991 | for (int j = 0; j < m_gti.size(); ++j) { |
| 992 | - if (j != i && accepted_bin_bckg_vector[j] == 1) { | |
| 992 | + if (j != i && accepted_bin_bckg_vector[j]) { | |
| 993 | 993 | noff += m_counts(ipix, j); |
| 994 | 994 | alpha += alphas[j]; |
| 995 | 995 | } |
| ... | ... | @@ -1019,7 +1019,7 @@ GNdarray ctfindvar::get_variability_sig(const int& ipix) |
| 1019 | 1019 | } |
| 1020 | 1020 | sig *= (non < alpha*noff) ? -1.0 : 1.0; |
| 1021 | 1021 | } |
| 1022 | - | |
| 1022 | + | |
| 1023 | 1023 | // Update the significance |
| 1024 | 1024 | sig_histogram(i) = sig; |
| 1025 | 1025 | |
| ... | ... | @@ -1071,7 +1071,7 @@ std::vector<double> ctfindvar::get_alphas(const int& ipix) const |
| 1071 | 1071 | if (roi_centre.dist_deg(pix_dir) > roi.radius()) { |
| 1072 | 1072 | continue; |
| 1073 | 1073 | } |
| 1074 | - | |
| 1074 | + | |
| 1075 | 1075 | // Convert sky direction to instrument direction |
| 1076 | 1076 | GCTAInstDir instdir = obs->pointing().instdir(pix_dir); |
| 1077 | 1077 | |
| ... | ... | @@ -1113,6 +1113,7 @@ std::vector<double> ctfindvar::get_alphas(const int& ipix) const |
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | // Add up background rate |
| 1116 | + #pragma omp critical(ctfindvar_get_alphas) | |
| 1116 | 1117 | alphas[j] += exposure * bkg->rate_ebin(instdir, m_emin, m_emax); |
| 1117 | 1118 | |
| 1118 | 1119 | } // endif: exposure was positive |
| ... | ... | @@ -1186,7 +1187,7 @@ GTime ctfindvar::get_tstart(void) |
| 1186 | 1187 | |
| 1187 | 1188 | // Get CTA observation |
| 1188 | 1189 | GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[k]); |
| 1189 | - | |
| 1190 | + | |
| 1190 | 1191 | // Continue only if observation is valid |
| 1191 | 1192 | if (obs != NULL) { |
| 1192 | 1193 | |
| ... | ... | @@ -1239,7 +1240,7 @@ GTime ctfindvar::get_tstop(void) |
| 1239 | 1240 | |
| 1240 | 1241 | // Get CTA observation |
| 1241 | 1242 | GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[k]); |
| 1242 | - | |
| 1243 | + | |
| 1243 | 1244 | // Continue only if observation is valid |
| 1244 | 1245 | if (obs != NULL) { |
| 1245 | 1246 | ... | ... |