Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/histo/b1 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_b1
0005 #define tools_histo_b1
0006 
0007 #include "base_histo"
0008 
0009 #include <ostream>
0010 
0011 namespace tools {
0012 namespace histo {
0013 
0014 template <class TC,class TO,class TN,class TW,class TH>
0015 class b1 : public base_histo<TC,TO,TN,TW,TH> {
0016   typedef base_histo<TC,TO,TN,TW,TH> parent;
0017 protected:
0018   enum {AxisX=0};
0019 public:
0020   typedef base_histo<TC,TO,TN,TW,TH> base_histo_t;
0021   typedef typename parent::axis_t axis_t;
0022   typedef typename parent::bn_t bn_t;
0023 public:
0024   virtual TH bin_error(int) const = 0; //for print
0025 public:
0026   // Partition :
0027   int coord_to_index(TC aCoord) const {
0028     return axis().coord_to_index(aCoord);
0029   }
0030   TC mean() const {
0031     //TC value;
0032     //parent::get_ith_axis_mean(AxisX,value); //can return false.
0033     //return value;
0034     if(parent::m_in_range_Sw==0) return 0;
0035     return parent::m_in_range_Sxw[0]/parent::m_in_range_Sw;
0036   }
0037   TC rms() const {
0038     //TC value;
0039     //parent::get_ith_axis_rms(AxisX,value); //can return false.
0040     //return value;
0041     if(parent::m_in_range_Sw==0) return 0;
0042     TC _mean = parent::m_in_range_Sxw[0]/parent::m_in_range_Sw;
0043     return ::sqrt(::fabs((parent::m_in_range_Sx2w[0] / parent::m_in_range_Sw) - _mean * _mean));
0044   }
0045 
0046   // bins :
0047   TN bin_entries(int aI) const {
0048     TO offset;
0049     if(!_find_offset(aI,offset)) return 0;
0050     return parent::m_bin_entries[offset];
0051   }
0052 
0053   TW bin_Sw(int aI) const {
0054     TO offset;
0055     if(!_find_offset(aI,offset)) return 0;
0056     return parent::m_bin_Sw[offset];
0057   }
0058 
0059   TW bin_Sw2(int aI) const {
0060     TO offset;
0061     if(!_find_offset(aI,offset)) return 0;
0062     return parent::m_bin_Sw2[offset];
0063   }
0064   TC bin_Sxw(int aI) const {
0065     TO offset;
0066     if(!_find_offset(aI,offset)) return 0;
0067     return parent::m_bin_Sxw[offset][AxisX];
0068   }
0069   TC bin_Sx2w(int aI) const {
0070     TO offset;
0071     if(!_find_offset(aI,offset)) return 0;
0072     return parent::m_bin_Sx2w[offset][AxisX];
0073   }
0074 
0075   TH bin_height(int aI) const {
0076     TO offset;
0077     if(!_find_offset(aI,offset)) return 0;
0078     return this->get_bin_height(offset);
0079   }
0080 
0081   TC bin_center(int aI) const {return parent::m_axes[0].bin_center(aI);}
0082 
0083   TC bin_mean(int aI) const {
0084     TO offset;
0085     if(!_find_offset(aI,offset)) return 0;
0086     TW sw = parent::m_bin_Sw[offset];
0087     if(sw==0) return 0;
0088     return parent::m_bin_Sxw[offset][AxisX]/sw;
0089   }
0090 
0091   TC bin_rms(int aI) const {
0092     TO offset;
0093     if(!_find_offset(aI,offset)) return 0;
0094     TW sw = parent::m_bin_Sw[offset];
0095     if(sw==0) return 0;
0096     TC sxw = parent::m_bin_Sxw[offset][AxisX];
0097     TC sx2w = parent::m_bin_Sx2w[offset][AxisX];
0098     TC _mean = sxw/sw;
0099     return ::sqrt(::fabs((sx2w / sw) - _mean * _mean));
0100   }
0101 
0102   // Axis :
0103   const axis_t& axis() const {return parent::m_axes[0];}
0104   axis_t& axis() {return parent::m_axes[0];} //touchy
0105 public:
0106   //NOTE : print is a Python keyword.
0107   void hprint(std::ostream& a_out) {
0108     // A la HPRINT.
0109     a_out << parent::dimension() << parent::title() << std::endl;
0110     a_out
0111       << " * ENTRIES = " << parent::all_entries()
0112       << " * ALL CHANNELS = " << parent::sum_bin_heights()
0113       << " * UNDERFLOW = " << bin_height(axis_t::UNDERFLOW_BIN)
0114       << " * OVERFLOW = " << bin_height(axis_t::OVERFLOW_BIN)
0115       << std::endl;
0116     a_out
0117       << " * BIN WID = " << axis().bin_width(0)
0118       << " * MEAN VALUE = " << mean()
0119       << " * R . M . S = " << rms()
0120       << std::endl;
0121 
0122     // Some bins :
0123     bn_t bins = axis().bins();
0124     a_out
0125       << " * ENTRIES[0]   = "
0126       << bin_entries(0)
0127       << " * HEIGHT[0] = "
0128       << bin_height(0)
0129       << " * ERROR[0] = "
0130       << bin_error(0)
0131       << std::endl;
0132     a_out
0133       << " * ENTRIES[N/2] = "
0134       << bin_entries(bins/2)
0135       << " * HEIGHT[N/2] = "
0136       << bin_height(bins/2)
0137       << " * ERROR[N/2] = "
0138       << bin_error(bins/2)
0139       << std::endl;
0140     a_out
0141       << " * ENTRIES[N-1] = "
0142       << bin_entries(bins-1)
0143       << " * HEIGHT[N-1] = "
0144       << bin_height(bins-1)
0145       << " * ERROR[N-1] = "
0146       << bin_error(bins-1)
0147       << std::endl;
0148   }
0149 protected:
0150   b1(const std::string& a_title,bn_t aXnumber,TC aXmin,TC aXmax) {
0151     parent::m_title = a_title;
0152     std::vector<bn_t> nbins;
0153     nbins.push_back(aXnumber);
0154     std::vector<TC> mins;
0155     mins.push_back(aXmin);
0156     std::vector<TC> maxs;
0157     maxs.push_back(aXmax);
0158     parent::configure(1,nbins,mins,maxs);
0159   }
0160   b1(const std::string& a_title,const std::vector<TC>& a_edges) {
0161     parent::m_title = a_title;
0162     std::vector< std::vector<TC> > edges(1);
0163     edges[0] = a_edges;
0164     parent::configure(1,edges);
0165   }
0166 
0167   virtual ~b1(){}
0168 protected:
0169   b1(const b1& a_from):parent(a_from){}
0170   b1& operator=(const b1& a_from) {
0171     if(&a_from==this) return *this;
0172     parent::operator=(a_from);
0173     return *this;
0174   }
0175 public:
0176   bool configure(bn_t aXnumber,TC aXmin,TC aXmax){
0177     std::vector<bn_t> nbins;
0178     nbins.push_back(aXnumber);
0179     std::vector<TC> mins;
0180     mins.push_back(aXmin);
0181     std::vector<TC> maxs;
0182     maxs.push_back(aXmax);
0183     return parent::configure(1,nbins,mins,maxs);
0184   }
0185   bool configure(const std::vector<TC>& a_edges) {
0186     std::vector< std::vector<TC> > edges(1);
0187     edges[0] = a_edges;
0188     return parent::configure(1,edges);
0189   }
0190 protected:
0191   bool _find_offset(int aI,TO& a_offset) const {
0192     if(parent::m_dimension!=1) {a_offset=0;return false;}
0193     bn_t ibin;
0194     if(!parent::m_axes[0].in_range_to_absolute_index(aI,ibin)) {a_offset=0;return false;}
0195     a_offset = ibin;
0196     return true;
0197   }
0198 };
0199 
0200 }}
0201 
0202 #endif
0203 
0204 
0205 
0206