// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_histo_slice #define tools_histo_slice #include "h1" #include "h2" #include "h3" namespace tools { namespace histo { template inline bool fill_slice_x(const h2& a_from, int aJbeg,int aJend, h1& a_to) { if(!a_from.dimension()) return false; typedef typename axis::bn_t bn_t; bn_t jbeg; if(!a_from.axis_y().in_range_to_absolute_index(aJbeg,jbeg)) return false; bn_t jend; if(!a_from.axis_y().in_range_to_absolute_index(aJend,jend)) return false; if(jbeg>jend) return false; if(a_from.axis_x().bins()!=a_to.axis().bins()) return false; histo_data hdata = a_to.get_histo_data(); bn_t aoffset,offset,jbin; bn_t yoffset = a_from.axis_y().m_offset; const std::vector& af_bin_entries = a_from.bins_entries(); const std::vector& af_bin_Sw = a_from.bins_sum_w(); const std::vector& af_bin_Sw2 = a_from.bins_sum_w2(); const std::vector< std::vector >& af_bin_Sxw = a_from.bins_sum_xw(); const std::vector< std::vector >& af_bin_Sx2w = a_from.bins_sum_x2w(); // Fill also the outflow. bn_t abins = hdata.m_axes[0].bins()+2; for(bn_t aibin=0;aibin inline h1* slice_x(const h2& a_from, int aJbeg,int aJend, const std::string& a_title) { h1* slice = new h1(a_title, a_from.axis_x().bins(), a_from.axis_x().lower_edge(), a_from.axis_x().upper_edge()); if(!fill_slice_x(a_from,aJbeg,aJend,*slice)) {delete slice;return 0;} return slice; } template inline h1* projection_x(const h2& a_from,const std::string& a_title) { return slice_x(a_from,axis::UNDERFLOW_BIN,axis::OVERFLOW_BIN,a_title); } template inline bool fill_slice_y(const h2& a_from, int aIbeg,int aIend, h1& a_to) { if(!a_from.dimension()) return false; typedef typename axis::bn_t bn_t; bn_t ibeg; if(!a_from.axis_x().in_range_to_absolute_index(aIbeg,ibeg)) return false; bn_t iend; if(!a_from.axis_x().in_range_to_absolute_index(aIend,iend)) return false; if(ibeg>iend) return false; if(a_from.axis_y().bins()!=a_to.axis().bins()) return false; histo_data hdata = a_to.get_histo_data(); bn_t aibin,aoffset,offset,ibin; bn_t yoffset = a_from.axis_y().m_offset; const std::vector& af_bin_entries = a_from.bins_entries(); const std::vector& af_bin_Sw = a_from.bins_sum_w(); const std::vector& af_bin_Sw2 = a_from.bins_sum_w2(); const std::vector< std::vector >& af_bin_Sxw = a_from.bins_sum_xw(); const std::vector< std::vector >& af_bin_Sx2w = a_from.bins_sum_x2w(); // Fill also the outflow. bn_t abins = hdata.m_axes[0].bins()+2; for(aibin=0;aibin inline h1* slice_y(const h2& a_from, int aIbeg,int aIend, const std::string& a_title) { h1* slice = new h1(a_title, a_from.axis_y().bins(), a_from.axis_y().lower_edge(), a_from.axis_y().upper_edge()); if(!fill_slice_y(a_from,aIbeg,aIend,*slice)) {delete slice;return 0;} return slice; } template inline h1* projection_y(const h2& a_from,const std::string& a_title) { return slice_y(a_from,axis::UNDERFLOW_BIN,axis::OVERFLOW_BIN,a_title); } template inline bool fill_slice_yz(const h3& a_from, int aIbeg,int aIend,h2& a_to) { if(!a_from.dimension()) return false; typedef typename axis::bn_t bn_t; bn_t ibeg; if(!a_from.axis_x().in_range_to_absolute_index(aIbeg,ibeg)) return false; bn_t iend; if(!a_from.axis_x().in_range_to_absolute_index(aIend,iend)) return false; if(ibeg>iend) return false; if(a_from.axis_y().bins()!=a_to.axis_x().bins()) return false; if(a_from.axis_z().bins()!=a_to.axis_y().bins()) return false; histo_data hdata = a_to.get_histo_data(); bn_t aibin,ajbin,aoffset,offset,ibin; bn_t ayoffset = hdata.m_axes[1].m_offset; bn_t yoffset = a_from.axis_y().m_offset; bn_t zoffset = a_from.axis_z().m_offset; bn_t axbins = hdata.m_axes[0].bins()+2; bn_t aybins = hdata.m_axes[1].bins()+2; const std::vector& af_bin_entries = a_from.bins_entries(); const std::vector& af_bin_Sw = a_from.bins_sum_w(); const std::vector& af_bin_Sw2 = a_from.bins_sum_w2(); const std::vector< std::vector >& af_bin_Sxw = a_from.bins_sum_xw(); const std::vector< std::vector >& af_bin_Sx2w = a_from.bins_sum_x2w(); // Fill also the outflow. for(aibin=0;aibin inline bool fill_slice_xy(const h3& a_from, int aKbeg,int aKend,h2& a_to) { if(!a_from.dimension()) return false; typedef typename axis::bn_t bn_t; bn_t kbeg; if(!a_from.axis_z().in_range_to_absolute_index(aKbeg,kbeg)) return false; bn_t kend; if(!a_from.axis_z().in_range_to_absolute_index(aKend,kend)) return false; if(kbeg>kend) return false; if(a_from.axis_x().bins()!=a_to.axis_x().bins()) return false; if(a_from.axis_y().bins()!=a_to.axis_y().bins()) return false; histo_data hdata = a_to.get_histo_data(); bn_t kbin; bn_t aibin,ajbin,aoffset,offset; bn_t ayoffset = hdata.m_axes[1].m_offset; bn_t yoffset = a_from.axis_y().m_offset; bn_t zoffset = a_from.axis_z().m_offset; bn_t axbins = hdata.m_axes[0].bins()+2; bn_t aybins = hdata.m_axes[1].bins()+2; const std::vector& af_bin_entries = a_from.bins_entries(); const std::vector& af_bin_Sw = a_from.bins_sum_w(); const std::vector& af_bin_Sw2 = a_from.bins_sum_w2(); const std::vector< std::vector >& af_bin_Sxw = a_from.bins_sum_xw(); const std::vector< std::vector >& af_bin_Sx2w = a_from.bins_sum_x2w(); // Fill also the outflow. for(aibin=0;aibin inline bool fill_slice_xz(const h3& a_from, int aJbeg,int aJend,h2& a_to) { if(!a_from.dimension()) return false; typedef typename axis::bn_t bn_t; bn_t jbeg; if(!a_from.axis_y().in_range_to_absolute_index(aJbeg,jbeg)) return false; bn_t jend; if(!a_from.axis_y().in_range_to_absolute_index(aJend,jend)) return false; if(jbeg>jend) return false; if(a_from.axis_x().bins()!=a_to.axis_x().bins()) return false; if(a_from.axis_z().bins()!=a_to.axis_y().bins()) return false; histo_data hdata = a_to.get_histo_data(); bn_t aibin,ajbin,aoffset,offset,jbin; bn_t ayoffset = hdata.m_axes[1].m_offset; bn_t yoffset = a_from.axis_y().m_offset; bn_t zoffset = a_from.axis_z().m_offset; bn_t axbins = hdata.m_axes[0].bins()+2; bn_t aybins = hdata.m_axes[1].bins()+2; const std::vector& af_bin_entries = a_from.bins_entries(); const std::vector& af_bin_Sw = a_from.bins_sum_w(); const std::vector& af_bin_Sw2 = a_from.bins_sum_w2(); const std::vector< std::vector >& af_bin_Sxw = a_from.bins_sum_xw(); const std::vector< std::vector >& af_bin_Sx2w = a_from.bins_sum_x2w(); // Fill also the outflow. for(aibin=0;aibin inline h2* slice_xy(const h3& a_from, int aKbeg,int aKend, const std::string& a_title) { h2* slice = new h2(a_title, a_from.axis_x().bins(), a_from.axis_x().lower_edge(), a_from.axis_x().upper_edge(), a_from.axis_y().bins(), a_from.axis_y().lower_edge(), a_from.axis_y().upper_edge()); if(!fill_slice_xy(a_from,aKbeg,aKend,*slice)) {delete slice;return 0;} return slice; } template inline h2* slice_yz(const h3& a_from, int aIbeg,int aIend, const std::string& a_title) { h2* slice = new h2(a_title, a_from.axis_y().bins(), a_from.axis_y().lower_edge(), a_from.axis_y().upper_edge(), a_from.axis_z().bins(), a_from.axis_z().lower_edge(), a_from.axis_z().upper_edge()); if(!fill_slice_yz(a_from,aIbeg,aIend,*slice)) {delete slice;return 0;} return slice; } template inline h2* slice_xz(const h3& a_from, int aJbeg,int aJend, const std::string& a_title) { h2* slice = new h2(a_title, a_from.axis_x().bins(), a_from.axis_x().lower_edge(), a_from.axis_x().upper_edge(), a_from.axis_z().bins(), a_from.axis_z().lower_edge(), a_from.axis_z().upper_edge()); if(!fill_slice_xz(a_from,aJbeg,aJend,*slice)) {delete slice;return 0;} return slice; } }} #endif