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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/histo/b1 (Version 11.3.0) and /externals/g4tools/include/tools/histo/b1 (Version 11.2)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_histo_b1                              4 #ifndef tools_histo_b1
  5 #define tools_histo_b1                              5 #define tools_histo_b1
  6                                                     6 
  7 #include "base_histo"                               7 #include "base_histo"
  8                                                     8 
  9 #include <ostream>                                  9 #include <ostream>
 10                                                    10 
 11 namespace tools {                                  11 namespace tools {
 12 namespace histo {                                  12 namespace histo {
 13                                                    13 
 14 template <class TC,class TO,class TN,class TW,     14 template <class TC,class TO,class TN,class TW,class TH>
 15 class b1 : public base_histo<TC,TO,TN,TW,TH> {     15 class b1 : public base_histo<TC,TO,TN,TW,TH> {
 16   typedef base_histo<TC,TO,TN,TW,TH> parent;       16   typedef base_histo<TC,TO,TN,TW,TH> parent;
 17 protected:                                         17 protected:
 18   enum {AxisX=0};                                  18   enum {AxisX=0};
 19 public:                                            19 public:
 20   typedef base_histo<TC,TO,TN,TW,TH> base_hist     20   typedef base_histo<TC,TO,TN,TW,TH> base_histo_t;
 21   typedef typename parent::axis_t axis_t;          21   typedef typename parent::axis_t axis_t;
 22   typedef typename parent::bn_t bn_t;              22   typedef typename parent::bn_t bn_t;
 23 public:                                            23 public:
 24   virtual TH bin_error(int) const = 0; //for p     24   virtual TH bin_error(int) const = 0; //for print
 25 public:                                            25 public:
 26   // Partition :                                   26   // Partition :
 27   int coord_to_index(TC aCoord) const {            27   int coord_to_index(TC aCoord) const {
 28     return axis().coord_to_index(aCoord);          28     return axis().coord_to_index(aCoord);
 29   }                                                29   }
 30   TC mean() const {                                30   TC mean() const {
 31     //TC value;                                    31     //TC value;
 32     //parent::get_ith_axis_mean(AxisX,value);      32     //parent::get_ith_axis_mean(AxisX,value); //can return false.
 33     //return value;                                33     //return value;
 34     if(parent::m_in_range_Sw==0) return 0;         34     if(parent::m_in_range_Sw==0) return 0;
 35     return parent::m_in_range_Sxw[0]/parent::m     35     return parent::m_in_range_Sxw[0]/parent::m_in_range_Sw;
 36   }                                                36   }
 37   TC rms() const {                                 37   TC rms() const {
 38     //TC value;                                    38     //TC value;
 39     //parent::get_ith_axis_rms(AxisX,value); /     39     //parent::get_ith_axis_rms(AxisX,value); //can return false.
 40     //return value;                                40     //return value;
 41     if(parent::m_in_range_Sw==0) return 0;         41     if(parent::m_in_range_Sw==0) return 0;
 42     TC _mean = parent::m_in_range_Sxw[0]/paren     42     TC _mean = parent::m_in_range_Sxw[0]/parent::m_in_range_Sw;
 43     return ::sqrt(::fabs((parent::m_in_range_S     43     return ::sqrt(::fabs((parent::m_in_range_Sx2w[0] / parent::m_in_range_Sw) - _mean * _mean));
 44   }                                                44   }
 45                                                    45 
 46   // bins :                                        46   // bins :
 47   TN bin_entries(int aI) const {                   47   TN bin_entries(int aI) const {
 48     TO offset;                                     48     TO offset;
 49     if(!_find_offset(aI,offset)) return 0;         49     if(!_find_offset(aI,offset)) return 0;
 50     return parent::m_bin_entries[offset];          50     return parent::m_bin_entries[offset];
 51   }                                                51   }
 52                                                    52 
 53   TW bin_Sw(int aI) const {                        53   TW bin_Sw(int aI) const {
 54     TO offset;                                     54     TO offset;
 55     if(!_find_offset(aI,offset)) return 0;         55     if(!_find_offset(aI,offset)) return 0;
 56     return parent::m_bin_Sw[offset];               56     return parent::m_bin_Sw[offset];
 57   }                                                57   }
 58                                                    58 
 59   TW bin_Sw2(int aI) const {                       59   TW bin_Sw2(int aI) const {
 60     TO offset;                                     60     TO offset;
 61     if(!_find_offset(aI,offset)) return 0;         61     if(!_find_offset(aI,offset)) return 0;
 62     return parent::m_bin_Sw2[offset];              62     return parent::m_bin_Sw2[offset];
 63   }                                                63   }
 64   TC bin_Sxw(int aI) const {                       64   TC bin_Sxw(int aI) const {
 65     TO offset;                                     65     TO offset;
 66     if(!_find_offset(aI,offset)) return 0;         66     if(!_find_offset(aI,offset)) return 0;
 67     return parent::m_bin_Sxw[offset][AxisX];       67     return parent::m_bin_Sxw[offset][AxisX];
 68   }                                                68   }
 69   TC bin_Sx2w(int aI) const {                      69   TC bin_Sx2w(int aI) const {
 70     TO offset;                                     70     TO offset;
 71     if(!_find_offset(aI,offset)) return 0;         71     if(!_find_offset(aI,offset)) return 0;
 72     return parent::m_bin_Sx2w[offset][AxisX];      72     return parent::m_bin_Sx2w[offset][AxisX];
 73   }                                                73   }
 74                                                    74 
 75   TH bin_height(int aI) const {                    75   TH bin_height(int aI) const {
 76     TO offset;                                     76     TO offset;
 77     if(!_find_offset(aI,offset)) return 0;         77     if(!_find_offset(aI,offset)) return 0;
 78     return this->get_bin_height(offset);           78     return this->get_bin_height(offset);
 79   }                                                79   }
 80                                                    80 
 81   TC bin_center(int aI) const {return parent::     81   TC bin_center(int aI) const {return parent::m_axes[0].bin_center(aI);}
 82                                                    82 
 83   TC bin_mean(int aI) const {                      83   TC bin_mean(int aI) const {
 84     TO offset;                                     84     TO offset;
 85     if(!_find_offset(aI,offset)) return 0;         85     if(!_find_offset(aI,offset)) return 0;
 86     TW sw = parent::m_bin_Sw[offset];              86     TW sw = parent::m_bin_Sw[offset];
 87     if(sw==0) return 0;                            87     if(sw==0) return 0;
 88     return parent::m_bin_Sxw[offset][AxisX]/sw     88     return parent::m_bin_Sxw[offset][AxisX]/sw;
 89   }                                                89   }
 90                                                    90 
 91   TC bin_rms(int aI) const {                       91   TC bin_rms(int aI) const {
 92     TO offset;                                     92     TO offset;
 93     if(!_find_offset(aI,offset)) return 0;         93     if(!_find_offset(aI,offset)) return 0;
 94     TW sw = parent::m_bin_Sw[offset];              94     TW sw = parent::m_bin_Sw[offset];
 95     if(sw==0) return 0;                            95     if(sw==0) return 0;
 96     TC sxw = parent::m_bin_Sxw[offset][AxisX];     96     TC sxw = parent::m_bin_Sxw[offset][AxisX];
 97     TC sx2w = parent::m_bin_Sx2w[offset][AxisX     97     TC sx2w = parent::m_bin_Sx2w[offset][AxisX];
 98     TC _mean = sxw/sw;                             98     TC _mean = sxw/sw;
 99     return ::sqrt(::fabs((sx2w / sw) - _mean *     99     return ::sqrt(::fabs((sx2w / sw) - _mean * _mean));
100   }                                               100   }
101                                                   101 
102   // Axis :                                       102   // Axis :
103   const axis_t& axis() const {return parent::m    103   const axis_t& axis() const {return parent::m_axes[0];}
104   axis_t& axis() {return parent::m_axes[0];} /    104   axis_t& axis() {return parent::m_axes[0];} //touchy
105 public:                                           105 public:
106   //NOTE : print is a Python keyword.             106   //NOTE : print is a Python keyword.
107   void hprint(std::ostream& a_out) {              107   void hprint(std::ostream& a_out) {
108     // A la HPRINT.                               108     // A la HPRINT.
109     a_out << parent::dimension() << parent::ti    109     a_out << parent::dimension() << parent::title() << std::endl;
110     a_out                                         110     a_out
111       << " * ENTRIES = " << parent::all_entrie    111       << " * ENTRIES = " << parent::all_entries()
112       << " * ALL CHANNELS = " << parent::sum_b    112       << " * ALL CHANNELS = " << parent::sum_bin_heights()
113       << " * UNDERFLOW = " << bin_height(axis_    113       << " * UNDERFLOW = " << bin_height(axis_t::UNDERFLOW_BIN)
114       << " * OVERFLOW = " << bin_height(axis_t    114       << " * OVERFLOW = " << bin_height(axis_t::OVERFLOW_BIN)
115       << std::endl;                               115       << std::endl;
116     a_out                                         116     a_out
117       << " * BIN WID = " << axis().bin_width(0    117       << " * BIN WID = " << axis().bin_width(0)
118       << " * MEAN VALUE = " << mean()             118       << " * MEAN VALUE = " << mean()
119       << " * R . M . S = " << rms()               119       << " * R . M . S = " << rms()
120       << std::endl;                               120       << std::endl;
121                                                   121 
122     // Some bins :                                122     // Some bins :
123     bn_t bins = axis().bins();                    123     bn_t bins = axis().bins();
124     a_out                                         124     a_out
125       << " * ENTRIES[0]   = "                     125       << " * ENTRIES[0]   = "
126       << bin_entries(0)                           126       << bin_entries(0)
127       << " * HEIGHT[0] = "                        127       << " * HEIGHT[0] = "
128       << bin_height(0)                            128       << bin_height(0)
129       << " * ERROR[0] = "                         129       << " * ERROR[0] = "
130       << bin_error(0)                             130       << bin_error(0)
131       << std::endl;                               131       << std::endl;
132     a_out                                         132     a_out
133       << " * ENTRIES[N/2] = "                     133       << " * ENTRIES[N/2] = "
134       << bin_entries(bins/2)                      134       << bin_entries(bins/2)
135       << " * HEIGHT[N/2] = "                      135       << " * HEIGHT[N/2] = "
136       << bin_height(bins/2)                       136       << bin_height(bins/2)
137       << " * ERROR[N/2] = "                       137       << " * ERROR[N/2] = "
138       << bin_error(bins/2)                        138       << bin_error(bins/2)
139       << std::endl;                               139       << std::endl;
140     a_out                                         140     a_out
141       << " * ENTRIES[N-1] = "                     141       << " * ENTRIES[N-1] = "
142       << bin_entries(bins-1)                      142       << bin_entries(bins-1)
143       << " * HEIGHT[N-1] = "                      143       << " * HEIGHT[N-1] = "
144       << bin_height(bins-1)                       144       << bin_height(bins-1)
145       << " * ERROR[N-1] = "                       145       << " * ERROR[N-1] = "
146       << bin_error(bins-1)                        146       << bin_error(bins-1)
147       << std::endl;                               147       << std::endl;
148   }                                               148   }
149 protected:                                        149 protected:
150   b1(const std::string& a_title,bn_t aXnumber,    150   b1(const std::string& a_title,bn_t aXnumber,TC aXmin,TC aXmax) {
151     parent::m_title = a_title;                    151     parent::m_title = a_title;
152     std::vector<bn_t> nbins;                      152     std::vector<bn_t> nbins;
153     nbins.push_back(aXnumber);                    153     nbins.push_back(aXnumber);
154     std::vector<TC> mins;                         154     std::vector<TC> mins;
155     mins.push_back(aXmin);                        155     mins.push_back(aXmin);
156     std::vector<TC> maxs;                         156     std::vector<TC> maxs;
157     maxs.push_back(aXmax);                        157     maxs.push_back(aXmax);
158     parent::configure(1,nbins,mins,maxs);         158     parent::configure(1,nbins,mins,maxs);
159   }                                               159   }
160   b1(const std::string& a_title,const std::vec    160   b1(const std::string& a_title,const std::vector<TC>& a_edges) {
161     parent::m_title = a_title;                    161     parent::m_title = a_title;
162     std::vector< std::vector<TC> > edges(1);      162     std::vector< std::vector<TC> > edges(1);
163     edges[0] = a_edges;                           163     edges[0] = a_edges;
164     parent::configure(1,edges);                   164     parent::configure(1,edges);
165   }                                               165   }
166                                                   166 
167   virtual ~b1(){}                                 167   virtual ~b1(){}
168 protected:                                        168 protected:
169   b1(const b1& a_from):parent(a_from){}           169   b1(const b1& a_from):parent(a_from){}
170   b1& operator=(const b1& a_from) {               170   b1& operator=(const b1& a_from) {
171     if(&a_from==this) return *this;               171     if(&a_from==this) return *this;
172     parent::operator=(a_from);                    172     parent::operator=(a_from);
173     return *this;                                 173     return *this;
174   }                                               174   }
175 public:                                           175 public:
176   bool configure(bn_t aXnumber,TC aXmin,TC aXm    176   bool configure(bn_t aXnumber,TC aXmin,TC aXmax){
177     std::vector<bn_t> nbins;                      177     std::vector<bn_t> nbins;
178     nbins.push_back(aXnumber);                    178     nbins.push_back(aXnumber);
179     std::vector<TC> mins;                         179     std::vector<TC> mins;
180     mins.push_back(aXmin);                        180     mins.push_back(aXmin);
181     std::vector<TC> maxs;                         181     std::vector<TC> maxs;
182     maxs.push_back(aXmax);                        182     maxs.push_back(aXmax);
183     return parent::configure(1,nbins,mins,maxs    183     return parent::configure(1,nbins,mins,maxs);
184   }                                               184   }
185   bool configure(const std::vector<TC>& a_edge    185   bool configure(const std::vector<TC>& a_edges) {
186     std::vector< std::vector<TC> > edges(1);      186     std::vector< std::vector<TC> > edges(1);
187     edges[0] = a_edges;                           187     edges[0] = a_edges;
188     return parent::configure(1,edges);            188     return parent::configure(1,edges);
189   }                                               189   }
190 protected:                                        190 protected:
191   bool _find_offset(int aI,TO& a_offset) const    191   bool _find_offset(int aI,TO& a_offset) const {
192     if(parent::m_dimension!=1) {a_offset=0;ret    192     if(parent::m_dimension!=1) {a_offset=0;return false;}
193     bn_t ibin;                                    193     bn_t ibin;
194     if(!parent::m_axes[0].in_range_to_absolute    194     if(!parent::m_axes[0].in_range_to_absolute_index(aI,ibin)) {a_offset=0;return false;}
195     a_offset = ibin;                              195     a_offset = ibin;
196     return true;                                  196     return true;
197   }                                               197   }
198 };                                                198 };
199                                                   199 
200 }}                                                200 }}
201                                                   201 
202 #endif                                            202 #endif
203                                                   203 
204                                                   204 
205                                                   205 
206                                                   206