BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
CbmL1Counters.h
Go to the documentation of this file.
1
#ifndef CbmL1Counters_H
2
#define CbmL1Counters_H
3
4
#include "
TString.h
"
5
6
#include <fstream>
7
#include <iomanip>
8
#include <iostream>
9
#include <map>
10
#include <vector>
11
using
std::ios;
12
using
std::map;
13
using
std::setw;
14
using
std::vector;
15
16
/// counters used for efficiency calculation
17
template
<
typename
T>
18
struct
TL1TracksCatCounters
// counters for different tracks categories
19
{
20
TL1TracksCatCounters
()
21
:
NCounters
(0)
22
,
counters
()
23
{
24
counters
.clear();
25
};
26
TL1TracksCatCounters
(
int
nCounters)
27
:
NCounters
(nCounters)
28
,
counters
()
29
{
30
counters
.resize(
NCounters
, T(0));
31
};
32
33
void
AddCounter
()
34
{
35
NCounters
++;
36
counters
.push_back(T(0));
37
};
38
void
AddCounters
(
int
nCounters)
39
{
40
NCounters
+= nCounters;
41
counters
.resize(
NCounters
, T(0));
42
};
43
44
TL1TracksCatCounters
&
operator+=
(
TL1TracksCatCounters
& a)
45
{
46
if
(
NCounters
!= a.NCounters) {
47
std::cout <<
" TL1TracksCatCounters: Error. Addition of counters of different sizes: "
<<
NCounters
<<
" "
48
<< a.NCounters << std::endl;
49
}
else
{
50
for
(
int
iC = 0; iC <
NCounters
; iC++) {
51
counters
[iC] += a.counters[iC];
52
}
53
}
54
return
*
this
;
55
};
56
57
TL1TracksCatCounters
operator+
(
TL1TracksCatCounters
& a)
58
{
59
TL1TracksCatCounters
res = *
this
;
60
res += a;
61
return
res;
62
};
63
64
template
<
typename
T2>
65
TL1TracksCatCounters<double>
operator/
(
TL1TracksCatCounters<T2>
& a)
66
{
67
TL1TracksCatCounters<double>
b(
NCounters
);
68
if
(
NCounters
!= a.NCounters) {
69
std::cout <<
" TL1TracksCatCounters: Error. Addition of counters of different sizes: "
<<
NCounters
<<
" "
70
<< a.NCounters << std::endl;
71
}
else
{
72
for
(
int
iC = 0; iC <
NCounters
; iC++) {
73
b.counters[iC] =
Div
(
counters
[iC], a.counters[iC]);
74
}
75
}
76
return
b;
77
};
78
79
template
<
typename
T2>
80
TL1TracksCatCounters<T2>
operator/
(
double
a)
81
{
82
TL1TracksCatCounters<T2>
b(
NCounters
);
83
for
(
int
iC = 0; iC <
NCounters
; iC++) {
84
b.counters[iC] =
static_cast<
T2
>
(
Div
(
counters
[iC], a));
85
}
86
return
b;
87
};
88
89
friend
std::fstream&
operator<<
(std::fstream& strm,
const
TL1TracksCatCounters<T>
& a)
90
{
91
strm << a.NCounters <<
" "
<< a.counters.size() <<
" "
;
92
for
(
unsigned
int
iV = 0; iV < a.counters.size(); iV++)
93
strm << a.counters[iV] <<
" "
;
94
strm << std::endl;
95
return
strm;
96
}
97
98
friend
std::ostream&
operator<<
(std::ostream& strm,
const
TL1TracksCatCounters<T>
& a)
99
{
100
strm << a.NCounters <<
" "
<< a.counters.size() <<
" "
;
101
for
(
unsigned
int
iV = 0; iV < a.counters.size(); iV++)
102
strm << a.counters[iV] <<
" "
;
103
strm << std::endl;
104
return
strm;
105
}
106
107
friend
std::fstream&
operator>>
(std::fstream& strm,
TL1TracksCatCounters<T>
& a)
108
{
109
int
tmp;
110
strm >> tmp;
111
a.NCounters = tmp;
112
strm >> tmp;
113
a.counters.resize(tmp, T(0));
114
for
(
int
iV = 0; iV < tmp; iV++) {
115
T tmp1;
116
strm >> tmp1;
117
a.counters[iV] = tmp1;
118
}
119
return
strm;
120
}
121
122
private
:
123
double
Div
(
double
a,
double
b) {
return
(b > 0) ? a / b : -1.; };
124
125
public
:
126
int
NCounters
;
127
vector<T>
counters
;
128
};
129
130
struct
TL1Efficiencies
131
{
132
TL1Efficiencies
()
133
:
names
()
134
,
indices
()
135
,
ratio_reco
()
136
,
ratio_ghosts
(0)
137
,
ratio_clones
(0)
138
,
mc
()
139
,
reco
()
140
,
ghosts
(0)
141
,
clones
(0)
142
,
nEvents
(0) {
143
// you should add counter with shortname="total" !!
144
};
145
146
virtual
~TL1Efficiencies
() {};
147
148
virtual
void
AddCounter
(
TString
shortname,
TString
name);
149
150
TL1Efficiencies
&
operator+=
(
TL1Efficiencies
& a);
151
void
CalcEff
();
152
void
Inc
(
bool
isReco,
TString
name);
// increment counters according to parameters
153
void
IncNEvents
() {
nEvents
++; };
154
155
void
PrintEff
();
156
157
vector<TString>
names
;
// names counters indexed by index of counter
158
map<TString, int>
indices
;
// indices of counters indexed by a counter shortname
159
160
TL1TracksCatCounters<double>
ratio_reco
;
161
double
ratio_ghosts
;
162
double
ratio_clones
;
163
164
TL1TracksCatCounters<int>
mc
;
165
TL1TracksCatCounters<int>
reco
;
166
int
ghosts
;
167
int
clones
;
168
int
nEvents
;
169
};
170
171
inline
void
TL1Efficiencies::AddCounter
(
TString
shortname,
TString
name)
172
{
173
indices
[shortname] =
names
.size();
174
names
.push_back(name);
175
176
ratio_reco
.AddCounter();
177
mc
.AddCounter();
178
reco
.AddCounter();
179
}
180
181
inline
void
TL1Efficiencies::CalcEff
()
182
{
183
ratio_reco
=
reco
/
mc
;
184
const
double
total =
reco
.counters[
indices
[
"total"
]] +
ghosts
+
clones
;
185
if
(total > 0) {
186
ratio_clones
=
clones
/ total;
187
ratio_ghosts
=
ghosts
/ total;
188
}
else
{
189
ratio_clones
= -1;
190
ratio_ghosts
= -1;
191
}
192
};
193
194
inline
TL1Efficiencies
&
TL1Efficiencies::operator+=
(
TL1Efficiencies
& a)
195
{
196
mc
+= a.mc;
197
reco
+= a.reco;
198
ghosts
+= a.ghosts;
199
clones
+= a.clones;
200
nEvents
+= a.nEvents;
201
202
return
*
this
;
203
};
204
205
inline
void
TL1Efficiencies::Inc
(
bool
isReco,
TString
name)
206
{
207
const
int
index =
indices
[name];
208
209
mc
.counters[index]++;
210
if
(isReco)
211
reco
.counters[index]++;
212
};
213
214
inline
void
TL1Efficiencies::PrintEff
()
215
{
216
std::cout.setf(ios::fixed);
217
std::cout.setf(ios::showpoint);
218
std::cout.precision(3);
219
std::cout.setf(ios::right);
220
std::cout <<
"Track category : "
<<
" Eff "
<<
" | "
<<
"All MC"
<< std::endl;
221
222
int
NCounters =
mc
.NCounters;
223
for
(
int
iC = 0; iC < NCounters; iC++) {
224
std::cout <<
names
[iC] <<
" : "
<<
ratio_reco
.counters[iC] <<
" | "
<<
mc
.counters[iC] << std::endl;
225
}
226
227
std::cout <<
"Clone probability : "
<<
ratio_clones
<<
" | "
<<
clones
<< std::endl;
228
std::cout <<
"Ghost probability : "
<<
ratio_ghosts
<<
" | "
<<
ghosts
<< std::endl;
229
};
230
231
#endif
TString.h
TString
TL1Efficiencies
Definition
CbmL1Counters.h:131
TL1Efficiencies::reco
TL1TracksCatCounters< int > reco
Definition
CbmL1Counters.h:165
TL1Efficiencies::mc
TL1TracksCatCounters< int > mc
Definition
CbmL1Counters.h:164
TL1Efficiencies::names
vector< TString > names
Definition
CbmL1Counters.h:157
TL1Efficiencies::ghosts
int ghosts
Definition
CbmL1Counters.h:166
TL1Efficiencies::IncNEvents
void IncNEvents()
Definition
CbmL1Counters.h:153
TL1Efficiencies::PrintEff
void PrintEff()
Definition
CbmL1Counters.h:214
TL1Efficiencies::CalcEff
void CalcEff()
Definition
CbmL1Counters.h:181
TL1Efficiencies::nEvents
int nEvents
Definition
CbmL1Counters.h:168
TL1Efficiencies::ratio_ghosts
double ratio_ghosts
Definition
CbmL1Counters.h:161
TL1Efficiencies::ratio_clones
double ratio_clones
Definition
CbmL1Counters.h:162
TL1Efficiencies::indices
map< TString, int > indices
Definition
CbmL1Counters.h:158
TL1Efficiencies::TL1Efficiencies
TL1Efficiencies()
Definition
CbmL1Counters.h:132
TL1Efficiencies::operator+=
TL1Efficiencies & operator+=(TL1Efficiencies &a)
Definition
CbmL1Counters.h:194
TL1Efficiencies::clones
int clones
Definition
CbmL1Counters.h:167
TL1Efficiencies::ratio_reco
TL1TracksCatCounters< double > ratio_reco
Definition
CbmL1Counters.h:160
TL1Efficiencies::Inc
void Inc(bool isReco, TString name)
Definition
CbmL1Counters.h:205
TL1Efficiencies::AddCounter
virtual void AddCounter(TString shortname, TString name)
Definition
CbmL1Counters.h:171
TL1Efficiencies::~TL1Efficiencies
virtual ~TL1Efficiencies()
Definition
CbmL1Counters.h:146
TL1TracksCatCounters
counters used for efficiency calculation
Definition
CbmL1Counters.h:19
TL1TracksCatCounters::operator+
TL1TracksCatCounters operator+(TL1TracksCatCounters &a)
Definition
CbmL1Counters.h:57
TL1TracksCatCounters::operator+=
TL1TracksCatCounters & operator+=(TL1TracksCatCounters &a)
Definition
CbmL1Counters.h:44
TL1TracksCatCounters::AddCounters
void AddCounters(int nCounters)
Definition
CbmL1Counters.h:38
TL1TracksCatCounters::AddCounter
void AddCounter()
Definition
CbmL1Counters.h:33
TL1TracksCatCounters::counters
vector< T > counters
Definition
CbmL1Counters.h:127
TL1TracksCatCounters::Div
double Div(double a, double b)
Definition
CbmL1Counters.h:123
TL1TracksCatCounters::operator<<
friend std::fstream & operator<<(std::fstream &strm, const TL1TracksCatCounters< T > &a)
Definition
CbmL1Counters.h:89
TL1TracksCatCounters::operator/
TL1TracksCatCounters< double > operator/(TL1TracksCatCounters< T2 > &a)
Definition
CbmL1Counters.h:65
TL1TracksCatCounters::TL1TracksCatCounters
TL1TracksCatCounters(int nCounters)
Definition
CbmL1Counters.h:26
TL1TracksCatCounters::TL1TracksCatCounters
TL1TracksCatCounters()
Definition
CbmL1Counters.h:20
TL1TracksCatCounters::NCounters
int NCounters
Definition
CbmL1Counters.h:126
TL1TracksCatCounters::operator>>
friend std::fstream & operator>>(std::fstream &strm, TL1TracksCatCounters< T > &a)
Definition
CbmL1Counters.h:107
TL1TracksCatCounters::operator<<
friend std::ostream & operator<<(std::ostream &strm, const TL1TracksCatCounters< T > &a)
Definition
CbmL1Counters.h:98
TL1TracksCatCounters::operator/
TL1TracksCatCounters< T2 > operator/(double a)
Definition
CbmL1Counters.h:80
base
cbm
CbmL1Counters.h
Generated on
for BmnRoot by
1.17.0