Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JToolsSupportkit.hh
Go to the documentation of this file.
1#ifndef __JROOT__JTOOLSSUPPORTKIT__
2#define __JROOT__JTOOLSSUPPORTKIT__
3
4#include "TH1.h"
5#include "TH2.h"
6#include "TH3.h"
7
8#include "JTools/JElement.hh"
9#include "JTools/JMapList.hh"
10#include "JTools/JDistance.hh"
14
15
16/**
17 * \author bjung
18 */
19
20namespace JROOT {}
21namespace JPP { using namespace JROOT; }
22
23namespace JROOT {
24
26 using JTOOLS::JBin1D;
28 using JTOOLS::JMapList;
29 using JTOOLS::JMAPLIST;
32
33
34 /**
35 * Auxiliary class for copying ROOT histograms to Jpp histograms.
36 */
38 {
39 public:
40
41 /**
42 * Default constructor.
43 */
46
47
48 /**
49 * Copy histogram from <tt>from</tt> to <tt>to</tt>.
50 *
51 * \param from ROOT histogram
52 * \param to Jpp histogram
53 */
54 template<class JAbscissa_t,
55 class JOrdinate_t,
56 template<class, class> class JContainer_t,
57 class JDistance_t = JDistance<JAbscissa_t> >
58 static void copy(const TH1& from, JHistogram1D<JBin1D<JAbscissa_t, JOrdinate_t>, JContainer_t, JDistance_t>& to)
59 {
60 to.clear();
61
62 const Int_t NbinsX = from.GetXaxis()->GetNbins();
63
64 to.underflow = from.GetBinContent(0);
65 to.overflow = from.GetBinContent(NbinsX+1);
66 to.integral = from.Integral(0, NbinsX+1);
67
68 for (Int_t i = 1; i <= NbinsX; ++i) {
69
70 const double x0 = from.GetXaxis()->GetBinLowEdge(i);
71 const double xc = from.GetXaxis()->GetBinCenter (i);
72
73 const double y = from.GetBinContent(i);
74 const double ye = from.GetBinError (i);
75
76 JBin1D<JAbscissa_t, JOrdinate_t> bin(x0, y, xc*y, ye*ye);
77
78 to.insert(bin);
79 }
80 }
81
82
83 /**
84 * Copy histogram from <tt>from</tt> to <tt>to</tt>.
85 *
86 * \param from ROOT histogram
87 * \param to Jpp histogram
88 */
89 template<class JAbscissa_t,
90 class JOrdinate_t,
91 template<class, class> class JContainer_t,
92 template<class, class, class> class JMap_t = JHistogramGridMap_t,
93 class JDistance_t = JDistance<JAbscissa_t> >
94 static void copy(const TH2& from, JMultiHistogram<JHistogram1D<JBin1D<JAbscissa_t, JOrdinate_t>, JContainer_t, JDistance_t>, JMapList<JMap_t>, JDistance_t>& to)
95 {
96 typedef JHistogram1D<JBin1D<JAbscissa_t, JOrdinate_t>, JContainer_t, JDistance_t> JHistogram1D_t;
97
98 const Int_t NbinsX = from.GetXaxis()->GetNbins();
99 const Int_t NbinsY = from.GetYaxis()->GetNbins();
100
101 for (Int_t i = 0; i <= NbinsX+1; ++i) {
102
103 JHistogram1D_t histogram;
104
105 const double xc = from.GetXaxis()->GetBinCenter(i);
106
107 for (Int_t j = 0; j <= NbinsY+1; ++j) {
108
109 const Int_t N = from.GetBin(i,j);
110
111 const double y0 = from.GetYaxis()->GetBinLowEdge(j);
112 const double yc = from.GetYaxis()->GetBinCenter (j);
113
114 const double z = from.GetBinContent(N);
115 const double ze = from.GetBinError (N);
116
117 histogram.integral += z;
118
119 if (from.IsBinUnderflow(N)) {
120 histogram.underflow += z;
121 } else if (from.IsBinOverflow(N)) {
122 histogram.overflow += z;
123 } else {
124 JBin1D<JAbscissa_t, JOrdinate_t> bin(y0, z, yc*z, ze*ze);
125 histogram.insert(bin);
126 }
127 }
128
129 if (histogram.getSize() > 0) {
130 to[xc] = histogram;
131 }
132 }
133 }
134
135
136 /**
137 * Copy histogram from <tt>from</tt> to <tt>to</tt>.
138 *
139 * \param from ROOT histogram
140 * \param to Jpp histogram
141 */
142 template<class JAbscissa_t,
143 class JOrdinate_t,
144 template<class, class> class JContainer_t,
145 template<class, class, class> class JMap_t1 = JHistogramGridMap_t,
146 template<class, class, class> class JMap_t2 = JHistogramGridMap_t,
147 class JDistance_t = JDistance<JAbscissa_t> >
148 static void copy(const TH3& from, JMultiHistogram<JHistogram1D<JBin1D<JAbscissa_t, JOrdinate_t>, JContainer_t, JDistance_t>, typename JMAPLIST<JMap_t1, JMap_t2>::maplist, JDistance_t>& to)
149 {
150 typedef JHistogram1D<JBin1D<JAbscissa_t, JOrdinate_t>, JContainer_t, JDistance_t> JHistogram1D_t;
151
152 const Int_t NbinsX = from.GetXaxis()->GetNbins();
153 const Int_t NbinsY = from.GetYaxis()->GetNbins();
154 const Int_t NbinsZ = from.GetZaxis()->GetNbins();
155
156 for (Int_t i = 0; i <= NbinsX+1; ++i) {
157
158 const double xc = from.GetXaxis()->GetBinCenter(i);
159
160 for (Int_t j = 0; j <= NbinsY+1; ++j) {
161
162 JHistogram1D_t histogram;
163
164 const double yc = from.GetYaxis()->GetBinCenter(j);
165
166 for (Int_t k = 0; k <= NbinsZ+1; ++k) {
167
168 const Int_t N = from.GetBin(i,j,k);
169
170 const double z0 = from.GetYaxis()->GetBinLowEdge(j);
171 const double zc = from.GetYaxis()->GetBinCenter (j);
172
173 const double w = from.GetBinContent(N);
174 const double we = from.GetBinError (N);
175
176 histogram.integral += w;
177
178 if (from.IsBinUnderflow(N)) {
179 histogram.underflow += w;
180 } else if (from.IsBinOverflow(N)) {
181 histogram.overflow += w;
182 } else {
183 JBin1D<JAbscissa_t, JOrdinate_t> bin(z0, w, zc*w, we*we);
184 histogram.insert(bin);
185 }
186 }
187
188 if (histogram.getSize() > 0) {
189 to[xc][yc] = histogram;
190 }
191 }
192 }
193 }
194
195
196 /**
197 * Copy histogram from <tt>from</tt> to <tt>to</tt>.
198 *
199 * \param from ROOT histogram
200 * \param to Jpp histogram
201 */
202 template<class JAbscissa_t,
203 class JOrdinate_t,
204 template<class, class> class JContainer_t,
205 class JDistance_t = JDistance<JAbscissa_t> >
206 void operator()(const TH1& from, JHistogram1D<JBin1D<JAbscissa_t, JOrdinate_t>, JContainer_t, JDistance_t>& to) const
207 {
208 return copy(from, to);
209 }
210
211
212 /**
213 * Copy histogram from <tt>from</tt> to <tt>to</tt>.
214 *
215 * \param from ROOT histogram
216 * \param to Jpp histogram
217 */
218 template<class JAbscissa_t,
219 class JOrdinate_t,
220 template<class, class> class JContainer_t,
221 template<class, class, class> class JMap_t = JHistogramGridMap_t,
222 class JDistance_t = JDistance<JAbscissa_t> >
223 void operator()(const TH2& from, JMultiHistogram<JHistogram1D<JBin1D<JAbscissa_t, JOrdinate_t>, JContainer_t, JDistance_t>, JMapList<JMap_t>, JDistance_t>& to) const
224 {
225 return copy(from, to);
226 }
227
228
229 /**
230 * Copy histogram from <tt>from</tt> to <tt>to</tt>.
231 *
232 * \param from ROOT histogram
233 * \param to Jpp histogram
234 */
235 template<class JAbscissa_t,
236 class JOrdinate_t,
237 template<class, class> class JContainer_t,
238 template<class, class, class> class JMap_t1 = JHistogramGridMap_t,
239 template<class, class, class> class JMap_t2 = JHistogramGridMap_t,
240 class JDistance_t = JDistance<JAbscissa_t> >
241 void operator()(const TH3& from, JMultiHistogram<JHistogram1D<JBin1D<JAbscissa_t, JOrdinate_t>, JContainer_t, JDistance_t>, typename JMAPLIST<JMap_t1, JMap_t2>::maplist, JDistance_t>& to) const
242 {
243 return copy(from, to);
244 }
245 };
246
247
248 /**
249 * Function object for copying histograms.
250 */
252}
253
254#endif
The elements in a collection are sorted according to their abscissa values and a given distance opera...
Auxiliary class for copying ROOT histograms to Jpp histograms.
static void copy(const TH1 &from, JHistogram1D< JBin1D< JAbscissa_t, JOrdinate_t >, JContainer_t, JDistance_t > &to)
Copy histogram from from to to.
void operator()(const TH1 &from, JHistogram1D< JBin1D< JAbscissa_t, JOrdinate_t >, JContainer_t, JDistance_t > &to) const
Copy histogram from from to to.
JHistogramHelper()
Default constructor.
void operator()(const TH2 &from, JMultiHistogram< JHistogram1D< JBin1D< JAbscissa_t, JOrdinate_t >, JContainer_t, JDistance_t >, JMapList< JMap_t >, JDistance_t > &to) const
Copy histogram from from to to.
static void copy(const TH2 &from, JMultiHistogram< JHistogram1D< JBin1D< JAbscissa_t, JOrdinate_t >, JContainer_t, JDistance_t >, JMapList< JMap_t >, JDistance_t > &to)
Copy histogram from from to to.
static void copy(const TH3 &from, JMultiHistogram< JHistogram1D< JBin1D< JAbscissa_t, JOrdinate_t >, JContainer_t, JDistance_t >, typename JMAPLIST< JMap_t1, JMap_t2 >::maplist, JDistance_t > &to)
Copy histogram from from to to.
void operator()(const TH3 &from, JMultiHistogram< JHistogram1D< JBin1D< JAbscissa_t, JOrdinate_t >, JContainer_t, JDistance_t >, typename JMAPLIST< JMap_t1, JMap_t2 >::maplist, JDistance_t > &to) const
Copy histogram from from to to.
Histogram in 1D.
Multidimensional histogram.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
static const JHistogramHelper copyHistogram
Function object for copying histograms.
1D Binned element with bin centering.
Definition JElement.hh:355
Template class for distance evaluation.
Definition JDistance.hh:24
Type definition of a JHistogramMap based on JGridMap implementation.
Auxiliary class for recursive map list generation.
Definition JMapList.hh:109
Map list.
Definition JMapList.hh:25