inlib  1.2.0
/Users/barrand/private/dev/softinex/old/inexlib-1.2/inlib/inlib/histo/b1
Go to the documentation of this file.
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
00002 // See the file inlib.license for terms.
00003 
00004 #ifndef inlib_histo_b1
00005 #define inlib_histo_b1
00006 
00007 #include "base_histo"
00008 
00009 #include <ostream>
00010 
00011 namespace inlib {
00012 namespace histo {
00013 
00014 template <class TC,class TN,class TW,class TH>
00015 class b1 : public base_histo<TC,TN,TW,TH> {
00016   typedef base_histo<TC,TN,TW,TH> parent;
00017 protected:
00018   enum {AxisX=0};
00019 public:
00020   typedef typename base_histo<TC,TN,TW,TH>::bn_t bn_t;
00021 public:
00022   virtual TH bin_error(int) const = 0; //for print
00023 public:
00024   void update_fast_getters(){}
00025 
00026   // Partition :
00027   int coord_to_index(TC aCoord) const {
00028     return axis().coord_to_index(aCoord);
00029   }
00030   TC mean() const {
00031     TC value;
00032     get_ith_axis_mean(AxisX,value); //can return false.
00033     return value;
00034   }
00035   TC rms() const {
00036     TC value;
00037     get_ith_axis_rms(AxisX,value); //can return false.
00038     return value;
00039   }
00040 
00041   // bins :
00042   TN bin_entries(int aI) const {
00043     if(parent::m_bin_number==0) return 0;
00044     bn_t offset;
00045     if(!parent::m_axes[0].in_range_to_absolute_index(aI,offset)) return 0;
00046     return parent::m_bin_entries[offset];
00047   }
00048 
00049   TW bin_Sw(int aI) const {
00050     if(parent::m_bin_number==0) return 0;
00051     bn_t offset;
00052     if(!parent::m_axes[0].in_range_to_absolute_index(aI,offset)) return 0;
00053     return parent::m_bin_Sw(offset);
00054   }
00055 
00056   TW bin_Sw2(int aI) const {
00057     if(parent::m_bin_number==0) return 0;
00058     bn_t offset;
00059     if(!parent::m_axes[0].in_range_to_absolute_index(aI,offset)) return 0;
00060     return parent::m_bin_Sw2(offset);
00061   }
00062   TC bin_Sxw(int aI) const {
00063     if(parent::m_bin_number==0) return 0;
00064     bn_t offset;
00065     if(!parent::m_axes[0].in_range_to_absolute_index(aI,offset)) return 0;
00066     return parent::m_bin_Sxw[offset][AxisX];
00067   }
00068   TC bin_Sx2w(int aI) const {
00069     if(parent::m_bin_number==0) return 0;
00070     bn_t offset;
00071     if(!parent::m_axes[0].in_range_to_absolute_index(aI,offset)) return 0;
00072     return parent::m_bin_Sx2w[offset][AxisX];
00073   }
00074 
00075   TH bin_height(int aI) const {
00076     if(parent::m_bin_number==0) return 0;
00077     bn_t offset;
00078     if(!parent::m_axes[0].in_range_to_absolute_index(aI,offset)) return 0;
00079     return this->get_bin_height(offset);
00080   }
00081 
00082   TC bin_center(int aI) const {return parent::m_axes[0].bin_center(aI);}
00083 
00084   TC bin_mean(int aI) const {
00085     if(parent::m_bin_number==0) return 0;
00086     bn_t offset;
00087     if(!parent::m_axes[0].in_range_to_absolute_index(aI,offset)) return 0;
00088     TW sw = parent::m_bin_Sw[offset];
00089     if(sw==0) return 0;
00090     return parent::m_bin_Sxw[offset][AxisX]/sw;
00091   }
00092 
00093   TC bin_rms(int aI) const {
00094     if(parent::m_bin_number==0) return 0;
00095     bn_t offset;
00096     if(!parent::m_axes[0].in_range_to_absolute_index(aI,offset)) return 0;
00097     TW sw = parent::m_bin_Sw[offset];
00098     if(sw==0) return 0;
00099     TC sxw = parent::m_bin_Sxw[offset][AxisX];
00100     TC sx2w = parent::m_bin_Sx2w[offset][AxisX];
00101     TC mean = sxw/sw;
00102     return ::sqrt(::fabs((sx2w / sw) - mean * mean));
00103   }
00104 
00105   // Axis :
00106   const histo::axis<TC>& axis() const {return parent::m_axes[0];}
00107   histo::axis<TC>& axis() {return parent::m_axes[0];} //touchy
00108 public:
00109   //NOTE : print is a Python keyword.
00110   void hprint(std::ostream& a_out) {
00111     // A la HPRINT.
00112     a_out << parent::dimension() << parent::title() << std::endl;
00113     a_out 
00114       << " * ENTRIES = " << parent::all_entries()
00115       << " * ALL CHANNELS = " << parent::sum_bin_heights()
00116       << " * UNDERFLOW = " << bin_height(histo::axis<TC>::UNDERFLOW_BIN)
00117       << " * OVERFLOW = " << bin_height(histo::axis<TC>::OVERFLOW_BIN)
00118       << std::endl;
00119     a_out 
00120       << " * BIN WID = " << axis().bin_width(0)
00121       << " * MEAN VALUE = " << mean()
00122       << " * R . M . S = " << rms()
00123       << std::endl;
00124   
00125     // Some bins :
00126     bn_t bins = axis().bins();
00127     a_out 
00128       << " * ENTRIES[0]   = " 
00129       << bin_entries(0)    
00130       << " * HEIGHT[0] = " 
00131       << bin_height(0)    
00132       << " * ERROR[0] = "     
00133       << bin_error(0)    
00134       << std::endl;
00135     a_out 
00136       << " * ENTRIES[N/2] = " 
00137       << bin_entries(bins/2)    
00138       << " * HEIGHT[N/2] = " 
00139       << bin_height(bins/2)
00140       << " * ERROR[N/2] = " 
00141       << bin_error(bins/2)
00142       << std::endl;
00143     a_out 
00144       << " * ENTRIES[N-1] = " 
00145       << bin_entries(bins-1)    
00146       << " * HEIGHT[N-1] = " 
00147       << bin_height(bins-1)
00148       << " * ERROR[N-1] = " 
00149       << bin_error(bins-1)
00150       << std::endl;
00151   }
00152 protected:
00153   b1(const std::string& a_title,
00154              bn_t aXnumber,TC aXmin,TC aXmax){
00155     parent::m_title = a_title;
00156     std::vector<bn_t> ns;
00157     ns.push_back(aXnumber);
00158     std::vector<TC> mins;
00159     mins.push_back(aXmin);
00160     std::vector<TC> maxs;
00161     maxs.push_back(aXmax);
00162     configure(1,ns,mins,maxs);
00163   }
00164   b1(const std::string& a_title,const std::vector<TC>& aEdges) {
00165     parent::m_title = a_title;
00166     std::vector< std::vector<TC> > edges(1);
00167     edges[0] = aEdges;
00168     configure(1,edges);
00169   }
00170 
00171   virtual ~b1(){}
00172 protected:
00173   b1(const b1& a_from): parent(a_from) {
00174     update_fast_getters();
00175   }
00176   b1& operator=(const b1& a_from) {
00177     parent::operator=(a_from);
00178     update_fast_getters();
00179     return *this;
00180   }
00181 };
00182 
00183 }}
00184 
00185 #endif
00186 
00187 
00188 
00189 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines