ROOTPWA
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
src
rootscripts
mcmcglidingmean.C
Go to the documentation of this file.
1
2
//
3
// Copyright 2009 Sebastian Neubert
4
//
5
// This file is part of rootpwa
6
//
7
// rootpwa is free software: you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation, either version 3 of the License, or
10
// (at your option) any later version.
11
//
12
// rootpwa is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
16
//
17
// You should have received a copy of the GNU General Public License
18
// along with rootpwa. If not, see <http://www.gnu.org/licenses/>.
19
//
21
#include "TTree.h"
22
#include "TGraph.h"
23
#include "TMultiGraph.h"
24
#include <iostream>
25
using namespace
std;
26
27
28
29
void
mcmcglidingmean
(TTree* tree,
unsigned
int
ndim,
unsigned
int
burnin=0,
unsigned
int
win=10){
30
double
X[ndim];
31
double
Grad[ndim];
32
double
Xsum[ndim];
33
double
Var2[ndim];
// variances
34
double
Var3[ndim];
// sum_k (x_k - x_mean)^3*dL/dx_k
35
double
C[ndim];
// Convergence Ratio
36
vector<TGraph*> graphs(ndim);
37
unsigned
int
nentries=tree->GetEntriesFast();
38
TMultiGraph* mgraph=
new
TMultiGraph();
39
40
for
(
unsigned
int
ip=0;ip<ndim;++ip){
41
Xsum[ip]=0;
42
Grad[ip]=0;
43
Var2[ip]=0;
44
Var3[ip]=0;
45
graphs[ip]=
new
TGraph(nentries-win);
46
mgraph->Add(graphs[ip]);
47
}
// end loop over parameters
48
49
tree->SetBranchAddress(
"dL"
,&Grad);
50
tree->SetBranchAddress(
"X"
,&X);
51
52
// calculate first mean value
53
for
(
unsigned
int
i
=0;
i
<win;
i
+=1){
54
tree->GetEntry(
i
);
55
for
(
unsigned
int
ip=0;ip<ndim;++ip){
56
Xsum[ip]+=X[ip];
57
}
// end loop over parameters
58
}
59
60
61
// start sliding:
62
for
(
unsigned
int
i
=win;
i
<nentries;
i
+=1){
63
// calculate sliding mean
64
tree->GetEntry(
i
-win);
65
// remove first point
66
for
(
unsigned
int
ip=0;ip<ndim;++ip){
67
Xsum[ip]-=X[ip];
68
}
// end loop over parameters
69
tree->GetEntry(
i
);
70
// add new point
71
for
(
unsigned
int
ip=0;ip<ndim;++ip){
72
Xsum[ip]+=X[ip];
73
// Fill Graph
74
graphs[ip]->SetPoint(
i
-win,
i
,Xsum[ip]/(
double
)win);
75
}
// end loop over parameters
76
77
}
78
mgraph->Draw(
"AP"
);
79
}
Generated by
1.8.1.2