Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
KFMCCounter.h
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file KFMCCounter.h
1
/*
2
* This file is part of KFParticle package
3
* Copyright (C) 2007-2019 FIAS Frankfurt Institute for Advanced Studies
4
* 2007-2019 Goethe University of Frankfurt
5
* 2007-2019 Ivan Kisel <I.Kisel@compeng.uni-frankfurt.de>
6
* 2007-2019 Maksym Zyzak
7
*
8
* KFParticle is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
12
*
13
* KFParticle is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20
*/
21
22
#ifndef KFMCCounter_H
23
#define KFMCCounter_H
24
25
#include <iostream>
26
#include <fstream>
27
#include <vector>
28
38
template
<
typename
T>
39
struct
KFMCCounter
40
{
41
int
NCounters
;
42
43
std::vector<T>
counters
;
44
45
KFMCCounter
():
NCounters
(0),
counters
(0) { }
46
KFMCCounter
(
int
nCounters):
NCounters
(nCounters),
counters
(nCounters,
T
(0)) { }
47
48
void
AddCounter
(){
NCounters
++;
counters
.push_back(
T
(0)); }
49
void
AddCounters
(
int
nCounters){
NCounters
+= nCounters;
counters
.resize(
NCounters
,
T
(0)); }
50
52
KFMCCounter
&
operator+=
(
KFMCCounter
&
a
){
53
if
(
NCounters
!= a.
NCounters
){
54
std::cout <<
" KFMCCounter: Error. Addition of counters of different sizes: "
<<
NCounters
<<
" "
<< a.
NCounters
<< std::endl;
55
}
56
else
{
57
for
(
int
iC = 0; iC <
NCounters
; iC++){
58
counters
[iC] += a.
counters
[iC];
59
}
60
}
61
return
*
this
;
62
};
64
KFMCCounter
operator+
(
KFMCCounter
&
a
){
65
KFMCCounter
res = *
this
;
66
res +=
a
;
67
return
res;
68
};
70
template
<
typename
T2>
71
KFMCCounter<double>
operator/
(
KFMCCounter<T2>
&
a
){
72
KFMCCounter<double>
b
(
NCounters
);
73
if
(
NCounters
!= a.
NCounters
){
74
std::cout <<
" KFMCCounter: Error. Addition of counters of different sizes: "
<<
NCounters
<<
" "
<< a.
NCounters
<< std::endl;
75
}
76
else
{
77
for
(
int
iC = 0; iC <
NCounters
; iC++){
78
b.
counters
[iC] =
Div
(
counters
[iC],a.
counters
[iC]);
79
}
80
}
81
return
b
;
82
}
84
template
<
typename
T2>
85
KFMCCounter<T2>
operator/
(
double
a
){
86
KFMCCounter<T2>
b
(
NCounters
);
87
for
(
int
iC = 0; iC <
NCounters
; iC++){
88
b.
counters
[iC] = (
T2
)
Div
(
counters
[iC],a);
89
}
90
return
b
;
91
}
93
friend
std::fstream & operator<<(std::fstream &strm, const KFMCCounter<T> &
a
){
94
strm <<
a
.NCounters <<
" "
<<
a
.counters.size() <<
" "
;
95
for
(
unsigned
int
iV=0; iV<
a
.counters.size(); iV++)
96
strm <<
a
.counters[iV] <<
" "
;
97
strm << std::endl;
98
return
strm;
99
}
101
friend
std::ostream & operator<<(std::ostream &strm, const KFMCCounter<T> &
a
){
102
strm <<
a
.NCounters <<
" "
<<
a
.counters.size() <<
" "
;
103
for
(
unsigned
int
iV=0; iV<
a
.counters.size(); iV++)
104
strm <<
a
.counters[iV] <<
" "
;
105
strm << std::endl;
106
return
strm;
107
}
109
friend
std::fstream &
operator>>
(std::fstream &strm,
KFMCCounter<T>
&
a
){
110
int
tmp
;
111
strm >>
tmp
;
112
a.
NCounters
=
tmp
;
113
strm >>
tmp
;
114
a.
counters
.resize(tmp,
T
(0));
115
for
(
int
iV=0; iV<
tmp
; iV++)
116
{
117
T
tmp1;
118
strm >> tmp1;
119
a.
counters
[iV] = tmp1;
120
}
121
return
strm;
122
}
123
124
private
:
126
double
Div
(
double
a
,
double
b
){
return
(b > 0) ? a/b : -1.;}
127
};
128
129
#endif
KFParticle
blob
master
KFParticlePerformance
KFMCCounter.h
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:26
using
1.8.2 with
sPHENIX GitHub integration