Warning, /include/Geant4/tools/histo/axes is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_histo_axes
0005 #define tools_histo_axes
0006
0007 #include "axis"
0008
0009 namespace tools {
0010 namespace histo {
0011
0012 //TC is for a coordinate.
0013 //TO is for an offset used to identify a bin.
0014
0015 template <class TC,class TO>
0016 inline bool is_out(const std::vector< axis<TC,TO> >& a_axes,TO a_offset) {
0017 TO offset = a_offset;
0018 int index;
0019 typename std::vector< axis<TC,TO> >::size_type dimension = a_axes.size();
0020 for(int iaxis=int(dimension)-1;iaxis>=0;iaxis--) {
0021 index = int(offset/a_axes[iaxis].m_offset);
0022 if(index==0) return true;
0023 if(index==(int(a_axes[iaxis].m_number_of_bins)+1)) return true;
0024 offset -= index * a_axes[iaxis].m_offset;
0025 }
0026 return false;
0027 }
0028
0029 template <class TC,class TO>
0030 inline void get_indices(const std::vector< axis<TC,TO> >& a_axes,TO a_offset,std::vector<int>& a_is) {
0031 TO offset = a_offset;
0032 typename std::vector< axis<TC,TO> >::size_type dimension = a_axes.size();
0033 {for(int iaxis=int(dimension)-1;iaxis>=0;iaxis--) {
0034 a_is[iaxis] = int(offset/a_axes[iaxis].m_offset);
0035 offset -= a_is[iaxis] * a_axes[iaxis].m_offset;
0036 }}
0037 typedef unsigned int dim_t;
0038 for(dim_t iaxis=0;iaxis<dimension;iaxis++) {
0039 if(a_is[iaxis]==0) {
0040 a_is[iaxis] = axis_UNDERFLOW_BIN;
0041 } else if(a_is[iaxis]==int(a_axes[iaxis].m_number_of_bins)+1) {
0042 a_is[iaxis] = axis_OVERFLOW_BIN;
0043 } else {
0044 a_is[iaxis]--;
0045 }
0046 }
0047 }
0048
0049 template <class TC,class TO>
0050 inline bool get_offset(const std::vector< axis<TC,TO> >& a_axes,const std::vector<int>& a_is,TO& a_offset) {
0051 // a_is[iaxis] is given in in-range indexing :
0052 // - [0,n[iaxis]-1] for in-range bins
0053 // - UNDERFLOW_BIN for the iaxis underflow bin
0054 // - OVERFLOW_BIN for the iaxis overflow bin
0055 a_offset = 0;
0056 if(a_axes.empty()) return false;
0057 typename std::vector< axis<TC,TO> >::size_type dimension = a_axes.size();
0058 typename axis<TC,TO>::bn_t ibin;
0059 typedef unsigned int dim_t;
0060 for(dim_t iaxis=0;iaxis<dimension;iaxis++) {
0061 if(!a_axes[iaxis].in_range_to_absolute_index(a_is[iaxis],ibin)) {
0062 a_offset = 0;
0063 return false;
0064 }
0065 a_offset += ibin * a_axes[iaxis].m_offset;
0066 }
0067 return true;
0068 }
0069
0070 }}
0071
0072 #endif
0073
0074
0075
0076