Commit 75bde4e8c2048ae5045d1bcad0da20c528dad437

Authored by Josh Cardenzana
1 parent 803c48d3

Add sky position caching for each bin (#1970)

Removed dynamic scheduling as it introduces a small amount of overhead (it was only done so that the observations would be analyzed in numerical order)
Added caching of sky directions for each pixel to prevent the need to re-convert the positions from index for each observation.
Fill cached sky positions with RA,Dec values to prevent need to convert between galactic->celestial every time the distance is compute a distance from an observation ROI.
src/ctbin/ctbin.cpp
@@ -248,7 +248,7 @@ void ctbin::run(void) @@ -248,7 +248,7 @@ void ctbin::run(void)
248 log_header1(TERSE, gammalib::number("Bin observation", m_obs.size())); 248 log_header1(TERSE, gammalib::number("Bin observation", m_obs.size()));
249 249
250 // Loop over all unbinned CTA observations in the container 250 // Loop over all unbinned CTA observations in the container
251 - #pragma omp parallel for schedule(dynamic) 251 + #pragma omp parallel for
252 for (int oindx=0; oindx<obs_list.size(); ++oindx) { 252 for (int oindx=0; oindx<obs_list.size(); ++oindx) {
253 GCTAObservation* obs = obs_list[oindx]; 253 GCTAObservation* obs = obs_list[oindx];
254 254
@@ -371,6 +371,7 @@ void ctbin::init_members(void) @@ -371,6 +371,7 @@ void ctbin::init_members(void)
371 m_ebounds.clear(); 371 m_ebounds.clear();
372 m_gti.clear(); 372 m_gti.clear();
373 m_cube.clear(); 373 m_cube.clear();
  374 + m_dirs.clear();
374 m_ontime = 0.0; 375 m_ontime = 0.0;
375 m_livetime = 0.0; 376 m_livetime = 0.0;
376 377
@@ -401,6 +402,7 @@ void ctbin::copy_members(const ctbin&amp; app) @@ -401,6 +402,7 @@ void ctbin::copy_members(const ctbin&amp; app)
401 m_ebounds = app.m_ebounds; 402 m_ebounds = app.m_ebounds;
402 m_gti = app.m_gti; 403 m_gti = app.m_gti;
403 m_cube = app.m_cube; 404 m_cube = app.m_cube;
  405 + m_dirs = app.m_dirs;
404 m_ontime = app.m_ontime; 406 m_ontime = app.m_ontime;
405 m_livetime = app.m_livetime; 407 m_livetime = app.m_livetime;
406 408
@@ -443,6 +445,13 @@ void ctbin::get_parameters(void) @@ -443,6 +445,13 @@ void ctbin::get_parameters(void)
443 m_counts = 0.0; 445 m_counts = 0.0;
444 m_weights = m_counts; 446 m_weights = m_counts;
445 447
  448 + // Cache sky directions in m_counts
  449 + m_dirs.resize(m_counts.npix());
  450 + for (int pix=0; pix<m_counts.npix(); pix++) {
  451 + m_dirs[pix] = m_counts.inx2dir(pix);
  452 + m_dirs[pix].radec(m_dirs[pix].ra(), m_dirs[pix].dec());
  453 + }
  454 +
446 // Get energy boundaries 455 // Get energy boundaries
447 m_ebounds = cube.ebounds(); 456 m_ebounds = cube.ebounds();
448 457
@@ -570,17 +579,17 @@ void ctbin::fill_cube(GCTAObservation* obs) @@ -570,17 +579,17 @@ void ctbin::fill_cube(GCTAObservation* obs)
570 // Update ontime and livetime 579 // Update ontime and livetime
571 m_ontime += obs->ontime(); 580 m_ontime += obs->ontime();
572 m_livetime += obs->livetime(); 581 m_livetime += obs->livetime();
573 -  
574 - // Log filling results  
575 - log_header3(TERSE, get_obs_header(obs));  
576 - log_value(NORMAL, "Events in list", obs->events()->size());  
577 - log_value(NORMAL, "Events in cube", num_in_map);  
578 - log_value(NORMAL, "Events outside RoI", num_outside_roi);  
579 - log_value(NORMAL, "Events with invalid WCS", num_invalid_wcs);  
580 - log_value(NORMAL, "Events outside cube area", num_outside_map);  
581 - log_value(NORMAL, "Events outside energy bins", num_outside_ebds);  
582 } 582 }
583 583
  584 + // Log filling results
  585 + log_header3(TERSE, get_obs_header(obs));
  586 + log_value(NORMAL, "Events in list", obs->events()->size());
  587 + log_value(NORMAL, "Events in cube", num_in_map);
  588 + log_value(NORMAL, "Events outside RoI", num_outside_roi);
  589 + log_value(NORMAL, "Events with invalid WCS", num_invalid_wcs);
  590 + log_value(NORMAL, "Events outside cube area", num_outside_map);
  591 + log_value(NORMAL, "Events outside energy bins", num_outside_ebds);
  592 +
584 // Return 593 // Return
585 return; 594 return;
586 } 595 }
@@ -627,12 +636,9 @@ void ctbin::set_weights(GCTAObservation* obs) @@ -627,12 +636,9 @@ void ctbin::set_weights(GCTAObservation* obs)
627 636
628 // Loop over all pixels in counts cube 637 // Loop over all pixels in counts cube
629 for (int pixel = 0; pixel < m_counts.npix(); ++pixel) { 638 for (int pixel = 0; pixel < m_counts.npix(); ++pixel) {
630 -  
631 - // Get pixel sky direction  
632 - GSkyDir dir = m_counts.inx2dir(pixel);  
633 - 639 +
634 // Skip pixel if it is outside the RoI 640 // Skip pixel if it is outside the RoI
635 - if (roi.centre().dir().dist_deg(dir) > roi.radius()) { 641 + if (roi.centre().dir().dist_deg(m_dirs[pixel]) > roi.radius()) {
636 continue; 642 continue;
637 } 643 }
638 644
src/ctbin/ctbin.hpp
@@ -102,6 +102,7 @@ protected: @@ -102,6 +102,7 @@ protected:
102 GCTAEventCube m_cube; //!< Events cube (for cube() method) 102 GCTAEventCube m_cube; //!< Events cube (for cube() method)
103 double m_ontime; //!< Total ontime 103 double m_ontime; //!< Total ontime
104 double m_livetime; //!< Total livetime 104 double m_livetime; //!< Total livetime
  105 + std::vector<GSkyDir> m_dirs; //!< Cached GSkyDir for each pixel in m_counts
105 }; 106 };
106 107
107 108