-
Notifications
You must be signed in to change notification settings - Fork 0
/
VectFunc.h
74 lines (57 loc) · 1.81 KB
/
VectFunc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <vector>
#include <iostream>
#include "TMath.h"
Float_t getMean(std::vector<Float_t>* inVect_p)
{
if(inVect_p->size() == 0){
std::cout << "Passed empty vector. Return 0." << std::endl;
return 0;
}
Float_t sum = 0;
for(Int_t jtIter = 0; jtIter < (Int_t)inVect_p->size(); jtIter++){
sum += inVect_p->at(jtIter);
}
return sum/((Float_t)inVect_p->size());
}
Float_t getError(std::vector<Float_t>* inVect_p, Float_t mean)
{
if(inVect_p->size() < 2){
std::cout << "Passed vector of size 1 or less. Return 0." << std::endl;
return 0;
}
Float_t error = 0;
for(Int_t jtIter = 0; jtIter < (Int_t)inVect_p->size(); jtIter++){
error += TMath::Power((inVect_p->at(jtIter) - mean), 2);
}
error = TMath::Sqrt(error/((Float_t)inVect_p->size() - 1.0));
return error/TMath::Sqrt((Float_t)inVect_p->size());
}
Float_t getMeanWeighted(std::vector<Float_t>* inVect_p, std::vector<Float_t>* weightVect_p)
{
if(inVect_p->size() == 0){
std::cout << "Passed empty vector. Return 0." << std::endl;
return 0;
}
Float_t sum = 0;
Float_t denom = 0;
for(Int_t jtIter = 0; jtIter < (Int_t)inVect_p->size(); jtIter++){
sum += inVect_p->at(jtIter)*weightVect_p->at(jtIter);
denom += weightVect_p->at(jtIter);
}
return sum/denom;
}
Float_t getErrorWeighted(std::vector<Float_t>* inVect_p, Float_t mean, std::vector<Float_t>* weightVect_p)
{
if(inVect_p->size() < 2){
std::cout << "Passed vector of size 1 or less. Return 0." << std::endl;
return 0;
}
Float_t error = 0;
Float_t denom = 0;
for(Int_t jtIter = 0; jtIter < (Int_t)inVect_p->size(); jtIter++){
error += TMath::Power((inVect_p->at(jtIter) - mean), 2)*weightVect_p->at(jtIter);
denom += weightVect_p->at(jtIter);
}
error = TMath::Sqrt(error/(denom - 1.0));
return error/TMath::Sqrt(denom);
}