183 lines
4.7 KiB
Plaintext
183 lines
4.7 KiB
Plaintext
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
|
// See the file tools.license for terms.
|
|
|
|
#ifndef tools_histo_h3
|
|
#define tools_histo_h3
|
|
|
|
#include "b3"
|
|
|
|
namespace tools {
|
|
namespace histo {
|
|
|
|
template <class TC,class TN,class TW,class TH>
|
|
class h3 : public b3<TC,TN,TW,TH> {
|
|
typedef b3<TC,TN,TW,TH> parent;
|
|
public:
|
|
typedef typename b3<TC,TN,TW,TH>::bn_t bn_t;
|
|
protected:
|
|
virtual TH get_bin_height(int a_offset) const { //TH should be the same as TW
|
|
return parent::m_bin_Sw[a_offset];
|
|
}
|
|
public:
|
|
|
|
virtual TH bin_error(int aI,int aJ,int aK) const {
|
|
if(parent::m_bin_number==0) return 0;
|
|
bn_t ibin;
|
|
if(!parent::m_axes[0].in_range_to_absolute_index(aI,ibin)) return 0;
|
|
bn_t jbin;
|
|
if(!parent::m_axes[1].in_range_to_absolute_index(aJ,jbin)) return 0;
|
|
bn_t kbin;
|
|
if(!parent::m_axes[2].in_range_to_absolute_index(aK,kbin)) return 0;
|
|
bn_t offset = ibin + jbin * parent::m_axes[1].m_offset +
|
|
kbin * parent::m_axes[2].m_offset;
|
|
|
|
return ::sqrt(parent::m_bin_Sw2[offset]);
|
|
}
|
|
|
|
public:
|
|
bool multiply(TW aFactor){
|
|
if(!parent::base_multiply(aFactor)) return false;
|
|
this->update_fast_getters();
|
|
return true;
|
|
}
|
|
bool scale(TW aFactor) {return multiply(aFactor);}
|
|
|
|
void copy_from_data(const histo_data<TC,TN,TW>& a_from) {
|
|
parent::base_from_data(a_from);
|
|
}
|
|
histo_data<TC,TN,TW> get_histo_data() const {
|
|
return parent::base_get_data();
|
|
}
|
|
|
|
bool reset() {
|
|
parent::base_reset();
|
|
this->update_fast_getters();
|
|
return true;
|
|
}
|
|
|
|
bool fill(TC aX,TC aY,TC aZ,TW aWeight = 1) {
|
|
//m_coords[0] = aX;
|
|
//m_coords[1] = aY;
|
|
//m_coords[2] = aZ;
|
|
//return fill_bin(m_coords,aWeight);
|
|
|
|
if(parent::m_dimension<=0) return false;
|
|
|
|
bn_t ibin,jbin,kbin;
|
|
if(!parent::m_axes[0].coord_to_absolute_index(aX,ibin)) return false;
|
|
if(!parent::m_axes[1].coord_to_absolute_index(aY,jbin)) return false;
|
|
if(!parent::m_axes[3].coord_to_absolute_index(aZ,kbin)) return false;
|
|
|
|
bn_t offset = ibin + jbin * parent::m_axes[1].m_offset +
|
|
kbin * parent::m_axes[2].m_offset;
|
|
|
|
parent::m_bin_entries[offset]++;
|
|
parent::m_bin_Sw[offset] += aWeight;
|
|
parent::m_bin_Sw2[offset] += aWeight * aWeight;
|
|
|
|
TC xw = aX * aWeight;
|
|
TC x2w = aX * xw;
|
|
parent::m_bin_Sxw[offset][0] += xw;
|
|
parent::m_bin_Sx2w[offset][0] += x2w;
|
|
|
|
TC yw = aY * aWeight;
|
|
TC y2w = aY * yw;
|
|
parent::m_bin_Sxw[offset][1] += yw;
|
|
parent::m_bin_Sx2w[offset][1] += y2w;
|
|
|
|
TC zw = aZ * aWeight;
|
|
TC z2w = aZ * zw;
|
|
parent::m_bin_Sxw[offset][2] += zw;
|
|
parent::m_bin_Sx2w[offset][2] += z2w;
|
|
|
|
bool inRange = true;
|
|
if(ibin==0) inRange = false;
|
|
else if(ibin==(parent::m_axes[0].m_number_of_bins+1)) inRange = false;
|
|
|
|
if(jbin==0) inRange = false;
|
|
else if(jbin==(parent::m_axes[1].m_number_of_bins+1)) inRange = false;
|
|
|
|
if(kbin==0) inRange = false;
|
|
else if(kbin==(parent::m_axes[2].m_number_of_bins+1)) inRange = false;
|
|
|
|
if(inRange) {
|
|
parent::m_in_range_entries++;
|
|
parent::m_in_range_Sw += aWeight;
|
|
|
|
parent::m_in_range_Sxw += xw;
|
|
parent::m_in_range_Sx2w += x2w;
|
|
|
|
parent::m_in_range_Syw += yw;
|
|
parent::m_in_range_Sy2w += y2w;
|
|
|
|
parent::m_in_range_Szw += zw;
|
|
parent::m_in_range_Sz2w += z2w;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool add(const h3& a_histo){
|
|
parent::base_add(a_histo);
|
|
this->update_fast_getters();
|
|
return true;
|
|
}
|
|
bool subtract(const h3& a_histo){
|
|
parent::base_subtract(a_histo);
|
|
this->update_fast_getters();
|
|
return true;
|
|
}
|
|
|
|
bool multiply(const h3& a_histo) {
|
|
if(!parent::base_multiply(a_histo)) return false;
|
|
this->update_fast_getters();
|
|
return true;
|
|
}
|
|
|
|
bool divide(const h3& a_histo) {
|
|
if(!parent::base_divide(a_histo)) return false;
|
|
this->update_fast_getters();
|
|
return true;
|
|
}
|
|
|
|
public:
|
|
/*
|
|
// Slices :
|
|
h2d* slice_xy(int aKbeg,int aKend) const;
|
|
h2d* slice_yz(int aIbeg,int aIend) const;
|
|
h2d* slice_xz(int aJbeg,int aJend) const;
|
|
*/
|
|
public:
|
|
h3(const std::string& a_title,
|
|
bn_t aXnumber,TC aXmin,TC aXmax,
|
|
bn_t aYnumber,TC aYmin,TC aYmax,
|
|
bn_t aZnumber,TC aZmin,TC aZmax)
|
|
: parent(a_title,aXnumber,aXmin,aXmax,
|
|
aYnumber,aYmin,aYmax,
|
|
aZnumber,aZmin,aZmax)
|
|
{}
|
|
|
|
h3(const std::string& a_title,
|
|
const std::vector<TC>& aEdgesX,
|
|
const std::vector<TC>& aEdgesY,
|
|
const std::vector<TC>& aEdgesZ)
|
|
: parent(a_title,aEdgesX,aEdgesY,aEdgesZ)
|
|
{}
|
|
|
|
virtual ~h3(){}
|
|
public:
|
|
h3(const h3& a_from): parent(a_from){}
|
|
h3& operator=(const h3& a_from){
|
|
parent::operator=(a_from);
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
}}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|