Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TUnuranEmpDist.cxx
Go to the documentation of this file.
1// @(#)root/unuran:$Id$
2// Authors: L. Moneta, J. Leydold Wed Feb 28 2007
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Implementation file for class TUnuranEmpDist
12
13#include "TUnuranEmpDist.h"
14
15#include "TH1.h"
16
17#include <cassert>
18
19
20
21TUnuranEmpDist::TUnuranEmpDist (const TH1 * h1, bool useBuffer) :
22 fDim(0),
23 fMin(0),
24 fMax(0),
25 fBinned(false)
26{
27 //Constructor from a TH1 objects.
28 //The buffer of the histo, if available, can be used for
29 // the estimation of the parent distribution using smoothing
30
31 if (!h1) return; // in case of default ctor for I/O
32
33 fDim = h1->GetDimension();
34
35 bool unbin = useBuffer && h1->GetBufferLength() > 0 ;
36 fBinned = !unbin;
37
38 if (fBinned ) {
39 int nbins = h1->GetNbinsX();
40 fData.reserve(nbins);
41 for (int i =0; i < nbins; ++i)
42 fData.push_back( h1->GetBinContent(i+1) );
43
44 fMin = h1->GetXaxis()->GetXmin();
45 fMax = h1->GetXaxis()->GetXmax();
46 }
47 else {
48 //std::cout << "use kernel smoothing method" << std::endl;
49
50 int n = h1->GetBufferLength();
51 const double * bf = h1->GetBuffer();
52 fData.reserve(n);
53 // fill buffer (assume weights are equal to 1)
54 // bugger is : [n,w0,x0,y0,..,w1,x1,y1,...wn,xn,yn]
55 // buffer contains size
56 for (int i = 0; i < n; ++i) {
57 int index = (fDim+1)*i + fDim + 1;
58 fData.push_back( bf[index] );
59 }
60 }
61}
62
63TUnuranEmpDist::TUnuranEmpDist (unsigned int n, double * x) :
64 fData(std::vector<double>(x,x+n) ),
65 fDim(1),
66 fMin(0), fMax(0),
67 fBinned(false)
68{
69 // constructor for 1D unbinned data
70}
71
72TUnuranEmpDist::TUnuranEmpDist (unsigned int n, double * x, double * y) :
73 fData(std::vector<double>(2*n) ),
74 fDim(2),
75 fMin(0), fMax(0),
76 fBinned(false)
77{
78 // constructor for 2D unbinned data
79 for (unsigned int i = 0; i < n; ++i) {
80 fData[i*2] = x[i];
81 fData[i*2+1] = y[i];
82 }
83}
84
85TUnuranEmpDist::TUnuranEmpDist (unsigned int n, double * x, double * y, double *z) :
86 fData(std::vector<double>(3*n) ),
87 fDim(3),
88 fMin(0), fMax(0),
89 fBinned(false)
90{
91 // constructor for 3D unbinned data
92 for (unsigned int i = 0; i < n; ++i) {
93 fData[i*3] = x[i];
94 fData[i*3+1] = y[i];
95 fData[i*3+2] = z[i];
96 }
97}
98
99
100
103{
104 // Implementation of copy ctor using assignment operator
105 operator=(rhs);
106}
107
109{
110 // Implementation of assignment operator (copy only the function pointer not the function itself)
111 if (this == &rhs) return *this; // time saving self-test
112 fData = rhs.fData;
113 fDim = rhs.fDim;
114 fMin = rhs.fMin;
115 fMax = rhs.fMax;
116 fBinned = rhs.fBinned;
117 return *this;
118}
119
120
121
122
123
124
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Double_t GetXmax() const
Definition TAxis.h:140
Double_t GetXmin() const
Definition TAxis.h:139
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
virtual Int_t GetDimension() const
Definition TH1.h:283
TAxis * GetXaxis()
Definition TH1.h:324
Int_t GetBufferLength() const
Definition TH1.h:237
virtual Int_t GetNbinsX() const
Definition TH1.h:297
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5029
const Double_t * GetBuffer() const
Definition TH1.h:239
TUnuranBaseDist, base class for Unuran distribution classes such as TUnuranContDist (for one-dimensio...
TUnuranEmpDist class for describing empirical distributions.
double fMax
max values (used in the binned case)
double fMin
min values (used in the binned case)
bool fBinned
flag for binned/unbinned data
TUnuranEmpDist & operator=(const TUnuranEmpDist &rhs)
Assignment operator.
unsigned int fDim
data dimensionality
TUnuranEmpDist(const TH1 *h1=nullptr, bool useBuffer=true)
Constructor from a TH1 objects.
std::vector< double > fData
pointer to the data vector (used for generation from un-binned data)
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TH1F * h1
Definition legend1.C:5