forked from h2gglobe/h2gglobe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CounterContainer.cc
135 lines (102 loc) · 2.81 KB
/
CounterContainer.cc
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "CounterContainer.h"
#include <utility>
#include <iostream>
#include <assert.h>
CounterContainer::CounterContainer(int n) {
histVal = n;
}
CounterContainer::~CounterContainer()
{}
void CounterContainer::Add(std::string name, int categories,
std::string denom1, std::string denom2, std::string denom3) {
std::string d1(""), d2(""), d3("");
std::vector<float> temp;
for (unsigned int i=0; i<categories; i++)
temp.push_back(0.0);
c.push_back(temp);
names.push_back(name);
std::vector<std::string> stemp;
stemp.push_back(d1);
stemp.push_back(d2);
stemp.push_back(d3);
denoms_.push_back(stemp);
}
void CounterContainer::Fill(std::string name, int category) {
Fill(name, category, 1.0);
}
void CounterContainer::Fill(std::string name, int category, float weight) {
int index = -1;
for (unsigned int i=0; i<names.size(); i++) {
if (names[i] == name) {
index = i;
break;
}
}
if (index != -1)
c[index][category] += weight;
else
std::cout << "Wrong counter name: " <<name<< std::endl;
}
unsigned int CounterContainer::ncat(unsigned int length) {
return c[length].size();
}
float CounterContainer::tot(unsigned int length) {
std::vector<float> temp = c[length];
float t = 0;
for(unsigned int i=0; i<temp.size(); i++)
t += temp[i];
return t;
}
std::vector<float> CounterContainer::operator[](unsigned int length) {
return c[length];
}
std::string CounterContainer::denomName(unsigned int length, unsigned int den) {
return denoms_[length][den];
}
std::string CounterContainer::name(unsigned int length) {
return names[length];
}
float CounterContainer::efficiency(unsigned int index, unsigned int cat, unsigned int denom_type) {
if (index == -1)
return -1.;
if (denom_type > 2 || denom_type < 0) {
std::cout << "Wrong denominator" << std::endl;
return -1;
}
if (denoms_[index][denom_type] == "")
return -1.;
int den_index = -1;
for (unsigned int i=0; i<names.size(); i++) {
if (names[i] == denoms_[index][denom_type]) {
den_index = i;
break;
}
}
if (den_index == -1) {
std::cout << "Wrong denominator" << std::endl;
return -1;
} else
return c[index][cat]/c[den_index][cat];
}
float CounterContainer::efficiency(unsigned int index, unsigned int denom_type) {
if (index == -1)
return -1.;
if (denom_type > 2 || denom_type < 0) {
std::cout << "Wrong denominator" << std::endl;
return -1;
}
if (denoms_[index][denom_type] == "")
return -1.;
int den_index = -1;
for (unsigned int i=0; i<names.size(); i++) {
if (names[i] == denoms_[index][denom_type]) {
den_index = i;
break;
}
}
if (den_index == -1) {
std::cout << "Wrong denominator" << std::endl;
return -1;
} else
return tot(index)/tot(den_index);
}