Commit 9873ac97481f62fe29a0d55bb97812461b65d79a

Authored by L. Tibaldo
1 parent 5a62d5be

method to get counts spectrum from GPha as GNdarray

include/GPha.hpp
... ... @@ -32,6 +32,7 @@
32 32 #include "GBase.hpp"
33 33 #include "GEbounds.hpp"
34 34 #include "GFilename.hpp"
  35 +#include "GNdarray.hpp"
35 36  
36 37 /* __ Forward declarations _______________________________________________ */
37 38 class GEnergy;
... ... @@ -95,6 +96,7 @@ public:
95 96 const double& at(const int& index) const;
96 97 const GEbounds& ebounds(void) const;
97 98 double counts(void) const;
  99 + GNdarray counts_spectrum(void) const;
98 100 void areascal(const int& index, const double& areascal);
99 101 const double& areascal(const int& index) const;
100 102 void backscal(const int& index, const double& backscal);
... ...
pyext/GPha.i
... ... @@ -57,6 +57,7 @@ public:
57 57 double& at(const int& index);
58 58 const GEbounds& ebounds(void) const;
59 59 double counts(void) const;
  60 + GNdarray counts_spectrum(void) const;
60 61 void areascal(const int& index, const double& areascal);
61 62 const double& areascal(const int& index) const;
62 63 void backscal(const int& index, const double& backscal);
... ...
src/xspec/GPha.cpp
... ... @@ -37,6 +37,7 @@
37 37 #include "GFitsBinTable.hpp"
38 38 #include "GFitsTableShortCol.hpp"
39 39 #include "GFitsTableFloatCol.hpp"
  40 +#include "GNdarray.hpp"
40 41  
41 42 /* __ Method name definitions ____________________________________________ */
42 43 #define G_OPERATOR_PLUS "GPha::operator+=(GPha&)"
... ... @@ -580,6 +581,26 @@ double GPha::counts(void) const
580 581 return counts;
581 582 }
582 583  
  584 +/***********************************************************************//**
  585 + * @brief Number of counts in spectrum as GNdArray
  586 + *
  587 + * Returns the number of counts in the spectrum as a GNdArray.
  588 + ***************************************************************************/
  589 +GNdarray GPha::counts_spectrum(void) const
  590 +{
  591 + // Initialise array
  592 + int size = m_counts.size();
  593 + GNdarray counts = GNdarray(size);
  594 +
  595 + // Compute content
  596 + for (int i = 0; i < size; ++i) {
  597 + counts(i) = m_counts[i];
  598 + }
  599 +
  600 + // Return counts
  601 + return counts;
  602 +}
  603 +
583 604  
584 605 /***********************************************************************//**
585 606 * @brief Fill spectrum with a value.
... ...