4 #ifndef tools_histo_slice
5 #define tools_histo_slice
16 template <
class H2,
class H1>
17 inline bool fill_slice_x(
const H2& a_from,
int aJbeg,
int aJend,H1& a_to) {
19 if(!a_from.dimension())
return false;
21 typedef typename H2::bn_t bn_t;
24 if(!a_from.axis_y().in_range_to_absolute_index(aJbeg,jbeg))
return false;
26 if(!a_from.axis_y().in_range_to_absolute_index(aJend,jend))
return false;
27 if(jbeg>jend)
return false;
29 if(a_from.axis_x().bins()!=a_to.axis().bins())
return false;
31 typedef typename H1::hd_t hd_t;
32 hd_t hdata = a_to.dac();
34 bn_t aoffset,offset,jbin;
35 bn_t yoffset = a_from.axis_y().m_offset;
37 typedef typename H2::num_entries_t TN;
38 typedef typename H2::weight_t TW;
39 typedef typename H2::coordinate_t TC;
41 const std::vector<TN>& af_bin_entries = a_from.bins_entries();
42 const std::vector<TW>& af_bin_Sw = a_from.bins_sum_w();
43 const std::vector<TW>& af_bin_Sw2 = a_from.bins_sum_w2();
44 const std::vector< std::vector<TC> >& af_bin_Sxw = a_from.bins_sum_xw();
45 const std::vector< std::vector<TC> >& af_bin_Sx2w = a_from.bins_sum_x2w();
48 bn_t abins = hdata.m_axes[0].bins()+2;
49 for(bn_t aibin=0;aibin<abins;aibin++) {
52 for(jbin=jbeg;jbin<=jend;jbin++) {
55 offset = aibin + jbin * yoffset;
57 hdata.m_bin_entries[aoffset] += af_bin_entries[offset];
58 hdata.m_bin_Sw[aoffset] += af_bin_Sw[offset];
59 hdata.m_bin_Sw2[aoffset] += af_bin_Sw2[offset];
60 hdata.m_bin_Sxw[aoffset][0] += af_bin_Sxw[offset][0];
61 hdata.m_bin_Sx2w[aoffset][0] += af_bin_Sx2w[offset][0];
65 hdata.m_in_range_plane_Sxyw.assign(a_to.number_of_planes(),0);
67 hdata.update_fast_getters();
68 a_to.copy_from_data(hdata);
72 template <
class H2,
class H1>
73 inline H1*
slice_x(
const H2& a_from,
int aJbeg,
int aJend,
const std::string& a_title) {
74 H1* slice =
new H1(a_title,a_from.axis_x().bins(),a_from.axis_x().lower_edge(),a_from.axis_x().upper_edge());
75 if(!
fill_slice_x(a_from,aJbeg,aJend,*slice)) {
delete slice;
return 0;}
79 template <
class H2,
class H1>
80 inline H1*
projection_x(
const H2& a_from,
const std::string& a_title) {
84 template <
class H2,
class H1>
85 inline bool fill_slice_y(
const H2& a_from,
int aIbeg,
int aIend,H1& a_to) {
87 if(!a_from.dimension())
return false;
89 typedef typename H2::bn_t bn_t;
92 if(!a_from.axis_x().in_range_to_absolute_index(aIbeg,ibeg))
return false;
94 if(!a_from.axis_x().in_range_to_absolute_index(aIend,iend))
return false;
95 if(ibeg>iend)
return false;
97 if(a_from.axis_y().bins()!=a_to.axis().bins())
return false;
99 typedef typename H1::hd_t hd_t;
100 hd_t hdata = a_to.dac();
102 bn_t aibin,aoffset,offset,ibin;
103 bn_t yoffset = a_from.axis_y().m_offset;
105 typedef typename H2::num_entries_t TN;
106 typedef typename H2::weight_t TW;
107 typedef typename H2::coordinate_t TC;
109 const std::vector<TN>& af_bin_entries = a_from.bins_entries();
110 const std::vector<TW>& af_bin_Sw = a_from.bins_sum_w();
111 const std::vector<TW>& af_bin_Sw2 = a_from.bins_sum_w2();
112 const std::vector< std::vector<TC> >& af_bin_Sxw = a_from.bins_sum_xw();
113 const std::vector< std::vector<TC> >& af_bin_Sx2w = a_from.bins_sum_x2w();
116 bn_t abins = hdata.m_axes[0].bins()+2;
117 for(aibin=0;aibin<abins;aibin++) {
120 for(ibin=ibeg;ibin<=iend;ibin++) {
123 offset = ibin + aibin * yoffset;
125 hdata.m_bin_entries[aoffset] += af_bin_entries[offset];
126 hdata.m_bin_Sw[aoffset] += af_bin_Sw[offset];
127 hdata.m_bin_Sw2[aoffset] += af_bin_Sw2[offset];
128 hdata.m_bin_Sxw[aoffset][0] += af_bin_Sxw[offset][1];
129 hdata.m_bin_Sx2w[aoffset][0] += af_bin_Sx2w[offset][1];
133 hdata.m_in_range_plane_Sxyw.assign(a_to.number_of_planes(),0);
135 hdata.update_fast_getters();
136 a_to.copy_from_data(hdata);
140 template <
class H2,
class H1>
141 inline H1*
slice_y(
const H2& a_from,
int aIbeg,
int aIend,
const std::string& a_title) {
142 H1* slice =
new H1(a_title,a_from.axis_y().bins(),a_from.axis_y().lower_edge(),a_from.axis_y().upper_edge());
143 if(!
fill_slice_y(a_from,aIbeg,aIend,*slice)) {
delete slice;
return 0;}
147 template <
class H2,
class H1>
156 template <
class H2,
class P1>
158 if(!a_from.dimension())
return false;
160 typedef typename H2::bn_t bn_t;
163 if(!a_from.axis_y().in_range_to_absolute_index(aJbeg,jbeg))
return false;
165 if(!a_from.axis_y().in_range_to_absolute_index(aJend,jend))
return false;
166 if(jbeg>jend)
return false;
168 if(a_from.axis_x().bins()!=a_to.axis().bins())
return false;
170 typedef typename P1::pd_t pd_t;
171 pd_t hdata = a_to.get_histo_data();
173 bn_t aoffset,offset,jbin;
174 bn_t yoffset = a_from.axis_y().m_offset;
176 typedef typename H2::num_entries_t TN;
177 typedef typename H2::weight_t TW;
178 typedef typename H2::coordinate_t TC;
180 const std::vector<TN>& af_bin_entries = a_from.bins_entries();
181 const std::vector<TW>& af_bin_Sw = a_from.bins_sum_w();
182 const std::vector<TW>& af_bin_Sw2 = a_from.bins_sum_w2();
183 const std::vector< std::vector<TC> >& af_bin_Sxw = a_from.bins_sum_xw();
184 const std::vector< std::vector<TC> >& af_bin_Sx2w = a_from.bins_sum_x2w();
187 bn_t abins = hdata.m_axes[0].bins()+2;
188 for(bn_t aibin=0;aibin<abins;aibin++) {
191 for(jbin=jbeg;jbin<=jend;jbin++) {
194 offset = aibin + jbin * yoffset;
196 hdata.m_bin_entries[aoffset] += af_bin_entries[offset];
197 hdata.m_bin_Sw[aoffset] += af_bin_Sw[offset];
198 hdata.m_bin_Sw2[aoffset] += af_bin_Sw2[offset];
199 hdata.m_bin_Sxw[aoffset][0] += af_bin_Sxw[offset][0];
200 hdata.m_bin_Sx2w[aoffset][0] += af_bin_Sx2w[offset][0];
202 hdata.m_bin_Svw[aoffset] += af_bin_Sxw[offset][1];
203 hdata.m_bin_Sv2w[aoffset] += af_bin_Sx2w[offset][1];
208 hdata.m_in_range_plane_Sxyw.assign(a_to.number_of_planes(),0);
210 hdata.update_fast_getters();
211 a_to.copy_from_data(hdata);
215 template <
class H2,
class P1>
218 if(!a_from.dimension())
return false;
220 typedef typename H2::bn_t bn_t;
223 if(!a_from.axis_x().in_range_to_absolute_index(aIbeg,ibeg))
return false;
225 if(!a_from.axis_x().in_range_to_absolute_index(aIend,iend))
return false;
226 if(ibeg>iend)
return false;
228 if(a_from.axis_y().bins()!=a_to.axis().bins())
return false;
230 typedef typename P1::pd_t pd_t;
231 pd_t hdata = a_to.get_histo_data();
233 bn_t aibin,aoffset,offset,ibin;
234 bn_t yoffset = a_from.axis_y().m_offset;
236 typedef typename H2::num_entries_t TN;
237 typedef typename H2::weight_t TW;
238 typedef typename H2::coordinate_t TC;
240 const std::vector<TN>& af_bin_entries = a_from.bins_entries();
241 const std::vector<TW>& af_bin_Sw = a_from.bins_sum_w();
242 const std::vector<TW>& af_bin_Sw2 = a_from.bins_sum_w2();
243 const std::vector< std::vector<TC> >& af_bin_Sxw = a_from.bins_sum_xw();
244 const std::vector< std::vector<TC> >& af_bin_Sx2w = a_from.bins_sum_x2w();
247 bn_t abins = hdata.m_axes[0].bins()+2;
248 for(aibin=0;aibin<abins;aibin++) {
251 for(ibin=ibeg;ibin<=iend;ibin++) {
254 offset = ibin + aibin * yoffset;
256 hdata.m_bin_entries[aoffset] += af_bin_entries[offset];
257 hdata.m_bin_Sw[aoffset] += af_bin_Sw[offset];
258 hdata.m_bin_Sw2[aoffset] += af_bin_Sw2[offset];
259 hdata.m_bin_Sxw[aoffset][0] += af_bin_Sxw[offset][1];
260 hdata.m_bin_Sx2w[aoffset][0] += af_bin_Sx2w[offset][1];
262 hdata.m_bin_Svw[aoffset] += af_bin_Sxw[offset][0];
263 hdata.m_bin_Sv2w[aoffset] += af_bin_Sx2w[offset][0];
267 hdata.m_in_range_plane_Sxyw.assign(a_to.number_of_planes(),0);
269 hdata.update_fast_getters();
270 a_to.copy_from_data(hdata);
278 template <
class H3,
class H2>
281 if(!a_from.dimension())
return false;
283 typedef typename H3::bn_t bn_t;
286 if(!a_from.axis_x().in_range_to_absolute_index(aIbeg,ibeg))
return false;
288 if(!a_from.axis_x().in_range_to_absolute_index(aIend,iend))
return false;
289 if(ibeg>iend)
return false;
291 if(a_from.axis_y().bins()!=a_to.axis_x().bins())
return false;
292 if(a_from.axis_z().bins()!=a_to.axis_y().bins())
return false;
294 typedef typename H2::hd_t hd_t;
295 hd_t hdata = a_to.dac();
297 bn_t aibin,ajbin,aoffset,offset,ibin;
299 bn_t ayoffset = hdata.m_axes[1].m_offset;
300 bn_t yoffset = a_from.axis_y().m_offset;
301 bn_t zoffset = a_from.axis_z().m_offset;
303 bn_t axbins = hdata.m_axes[0].bins()+2;
304 bn_t aybins = hdata.m_axes[1].bins()+2;
306 typedef typename H3::num_entries_t TN;
307 typedef typename H3::weight_t TW;
308 typedef typename H3::coordinate_t TC;
310 const std::vector<TN>& af_bin_entries = a_from.bins_entries();
311 const std::vector<TW>& af_bin_Sw = a_from.bins_sum_w();
312 const std::vector<TW>& af_bin_Sw2 = a_from.bins_sum_w2();
313 const std::vector< std::vector<TC> >& af_bin_Sxw = a_from.bins_sum_xw();
314 const std::vector< std::vector<TC> >& af_bin_Sx2w = a_from.bins_sum_x2w();
317 for(aibin=0;aibin<axbins;aibin++) {
318 for(ajbin=0;ajbin<aybins;ajbin++) {
320 aoffset = aibin + ajbin * ayoffset;
321 for(ibin=ibeg;ibin<=iend;ibin++) {
324 offset = ibin + aibin * yoffset + ajbin * zoffset;
327 hdata.m_bin_entries[aoffset] += af_bin_entries[offset];
328 hdata.m_bin_Sw[aoffset] += af_bin_Sw[offset];
329 hdata.m_bin_Sw2[aoffset] += af_bin_Sw2[offset];
330 hdata.m_bin_Sxw[aoffset][0] += af_bin_Sxw[offset][1];
331 hdata.m_bin_Sxw[aoffset][1] += af_bin_Sxw[offset][2];
332 hdata.m_bin_Sx2w[aoffset][0] += af_bin_Sx2w[offset][1];
333 hdata.m_bin_Sx2w[aoffset][1] += af_bin_Sx2w[offset][2];
338 hdata.m_in_range_plane_Sxyw.assign(a_to.number_of_planes(),0);
340 hdata.update_fast_getters();
341 a_to.copy_from_data(hdata);
345 template <
class H3,
class H2>
348 if(!a_from.dimension())
return false;
350 typedef typename H3::bn_t bn_t;
353 if(!a_from.axis_z().in_range_to_absolute_index(aKbeg,kbeg))
return false;
355 if(!a_from.axis_z().in_range_to_absolute_index(aKend,kend))
return false;
356 if(kbeg>kend)
return false;
358 if(a_from.axis_x().bins()!=a_to.axis_x().bins())
return false;
359 if(a_from.axis_y().bins()!=a_to.axis_y().bins())
return false;
361 typedef typename H2::hd_t hd_t;
362 hd_t hdata = a_to.dac();
365 bn_t aibin,ajbin,aoffset,offset;
367 bn_t ayoffset = hdata.m_axes[1].m_offset;
368 bn_t yoffset = a_from.axis_y().m_offset;
369 bn_t zoffset = a_from.axis_z().m_offset;
371 bn_t axbins = hdata.m_axes[0].bins()+2;
372 bn_t aybins = hdata.m_axes[1].bins()+2;
374 typedef typename H3::num_entries_t TN;
375 typedef typename H3::weight_t TW;
376 typedef typename H3::coordinate_t TC;
378 const std::vector<TN>& af_bin_entries = a_from.bins_entries();
379 const std::vector<TW>& af_bin_Sw = a_from.bins_sum_w();
380 const std::vector<TW>& af_bin_Sw2 = a_from.bins_sum_w2();
381 const std::vector< std::vector<TC> >& af_bin_Sxw = a_from.bins_sum_xw();
382 const std::vector< std::vector<TC> >& af_bin_Sx2w = a_from.bins_sum_x2w();
385 for(aibin=0;aibin<axbins;aibin++) {
386 for(ajbin=0;ajbin<aybins;ajbin++) {
388 aoffset = aibin + ajbin * ayoffset;
389 for(kbin=kbeg;kbin<=kend;kbin++) {
392 offset = aibin + ajbin * yoffset + kbin * zoffset;
395 hdata.m_bin_entries[aoffset] += af_bin_entries[offset];
396 hdata.m_bin_Sw[aoffset] += af_bin_Sw[offset];
397 hdata.m_bin_Sw2[aoffset] += af_bin_Sw2[offset];
398 hdata.m_bin_Sxw[aoffset][0] += af_bin_Sxw[offset][0];
399 hdata.m_bin_Sxw[aoffset][1] += af_bin_Sxw[offset][1];
400 hdata.m_bin_Sx2w[aoffset][0] += af_bin_Sx2w[offset][0];
401 hdata.m_bin_Sx2w[aoffset][1] += af_bin_Sx2w[offset][1];
406 hdata.m_in_range_plane_Sxyw.assign(a_to.number_of_planes(),0);
408 hdata.update_fast_getters();
409 a_to.copy_from_data(hdata);
413 template <
class H3,
class H2>
416 if(!a_from.dimension())
return false;
418 typedef typename H3::bn_t bn_t;
421 if(!a_from.axis_y().in_range_to_absolute_index(aJbeg,jbeg))
return false;
423 if(!a_from.axis_y().in_range_to_absolute_index(aJend,jend))
return false;
424 if(jbeg>jend)
return false;
426 if(a_from.axis_x().bins()!=a_to.axis_x().bins())
return false;
427 if(a_from.axis_z().bins()!=a_to.axis_y().bins())
return false;
429 typedef typename H2::hd_t hd_t;
430 hd_t hdata = a_to.dac();
432 bn_t aibin,ajbin,aoffset,offset,jbin;
434 bn_t ayoffset = hdata.m_axes[1].m_offset;
435 bn_t yoffset = a_from.axis_y().m_offset;
436 bn_t zoffset = a_from.axis_z().m_offset;
438 bn_t axbins = hdata.m_axes[0].bins()+2;
439 bn_t aybins = hdata.m_axes[1].bins()+2;
441 typedef typename H3::num_entries_t TN;
442 typedef typename H3::weight_t TW;
443 typedef typename H3::coordinate_t TC;
445 const std::vector<TN>& af_bin_entries = a_from.bins_entries();
446 const std::vector<TW>& af_bin_Sw = a_from.bins_sum_w();
447 const std::vector<TW>& af_bin_Sw2 = a_from.bins_sum_w2();
448 const std::vector< std::vector<TC> >& af_bin_Sxw = a_from.bins_sum_xw();
449 const std::vector< std::vector<TC> >& af_bin_Sx2w = a_from.bins_sum_x2w();
452 for(aibin=0;aibin<axbins;aibin++) {
453 for(ajbin=0;ajbin<aybins;ajbin++) {
455 aoffset = aibin + ajbin * ayoffset;
456 for(jbin=jbeg;jbin<=jend;jbin++) {
459 offset = aibin + jbin * yoffset + ajbin * zoffset;
462 hdata.m_bin_entries[aoffset] += af_bin_entries[offset];
463 hdata.m_bin_Sw[aoffset] += af_bin_Sw[offset];
464 hdata.m_bin_Sw2[aoffset] += af_bin_Sw2[offset];
465 hdata.m_bin_Sxw[aoffset][0] += af_bin_Sxw[offset][0];
466 hdata.m_bin_Sxw[aoffset][1] += af_bin_Sxw[offset][2];
467 hdata.m_bin_Sx2w[aoffset][0] += af_bin_Sx2w[offset][0];
468 hdata.m_bin_Sx2w[aoffset][1] += af_bin_Sx2w[offset][2];
473 hdata.m_in_range_plane_Sxyw.assign(a_to.number_of_planes(),0);
475 hdata.update_fast_getters();
476 a_to.copy_from_data(hdata);
480 template <
class H3,
class H2>
481 inline H2*
slice_xy(
const H3& a_from,
int aKbeg,
int aKend,
const std::string& a_title) {
482 H2* slice =
new H2(a_title,
483 a_from.axis_x().bins(),a_from.axis_x().lower_edge(),a_from.axis_x().upper_edge(),
484 a_from.axis_y().bins(),a_from.axis_y().lower_edge(),a_from.axis_y().upper_edge());
485 if(!
fill_slice_xy(a_from,aKbeg,aKend,*slice)) {
delete slice;
return 0;}
489 template <
class H3,
class H2>
490 inline H2*
slice_yz(
const H3& a_from,
int aIbeg,
int aIend,
const std::string& a_title) {
491 H2* slice =
new H2(a_title,
492 a_from.axis_y().bins(),a_from.axis_y().lower_edge(),a_from.axis_y().upper_edge(),
493 a_from.axis_z().bins(),a_from.axis_z().lower_edge(),a_from.axis_z().upper_edge());
494 if(!
fill_slice_yz(a_from,aIbeg,aIend,*slice)) {
delete slice;
return 0;}
498 template <
class H3,
class H2>
499 inline H2*
slice_xz(
const H3& a_from,
int aJbeg,
int aJend,
const std::string& a_title) {
500 H2* slice =
new H2(a_title,
501 a_from.axis_x().bins(),a_from.axis_x().lower_edge(),a_from.axis_x().upper_edge(),
502 a_from.axis_z().bins(),a_from.axis_z().lower_edge(),a_from.axis_z().upper_edge());
503 if(!
fill_slice_xz(a_from,aJbeg,aJend,*slice)) {
delete slice;
return 0;}