herwig
is hosted by
Hepforge
,
IPPP Durham
Herwig
7.3.0
Utilities
Statistics
EventContribution.h
1
// -*- C++ -*-
2
//
3
// EventContribution.hpp is a part of myStatistics
4
// Copyright (C) 2012-2019 Simon Platzer, The Herwig Collaboration
5
//
6
// myStatistics is licenced under version 3 of the GPL, see COPYING for details.
7
//
8
#ifndef MYSTATISTICS_EventContribution_hpp_included
9
#define MYSTATISTICS_EventContribution_hpp_included
10
11
#include <cfloat>
12
13
namespace
Statistics {
14
19
class
EventContribution
{
20
21
public
:
22
26
EventContribution
(
double
newCentralValue,
27
double
newWeight,
28
double
newWidth = 0.0)
29
:
theCentralValue
(newCentralValue),
30
theSupport
(newCentralValue - newWidth/2.,
31
newCentralValue + newWidth/2.),
32
theWeight
(newWeight) {}
33
34
public
:
35
39
double
centralValue
()
const
{
return
theCentralValue
; }
40
44
const
std::pair<double,double>&
support
()
const
{
return
theSupport
; }
45
49
double
overlap
(
const
std::pair<double,double>& interval)
const
{
50
return
calculateOverlap
(interval,
support
(),
support
().second-
support
().first);
51
}
52
56
double
weight
()
const
{
return
theWeight
; }
57
58
public
:
59
65
void
periodic
(
const
std::pair<double,double>& periodicity) {
66
double
delta = periodicity.second - periodicity.first;
67
if
(
support
().second -
support
().first > delta ) {
68
theSupport
.first =
centralValue
() - delta/2.;
69
theSupport
.second =
centralValue
() + delta/2.;
70
}
71
double
shift = 0.;
72
if
(
centralValue
() >= periodicity.second ) {
73
while
(
centralValue
() >= periodicity.second ) {
74
shift -= delta;
75
theCentralValue
-= delta;
76
}
77
}
else
if
(
centralValue
() < periodicity.first ) {
78
while
(
centralValue
() <= periodicity.first ) {
79
shift += delta;
80
theCentralValue
+= delta;
81
}
82
}
83
theSupport
.first += shift;
84
theSupport
.second += shift;
85
if
(
theSupport
.first < periodicity.first )
86
theSupport
.first += delta;
87
if
(
theSupport
.second > periodicity.second )
88
theSupport
.second -= delta;
89
}
90
94
void
noUnderflow
(
double
lower) {
95
if
(
support
().first < lower ) {
96
double
shift = lower -
support
().first;
97
theSupport
.first += shift;
98
theSupport
.second += shift;
99
theCentralValue
+= shift;
100
}
101
}
102
106
void
noOverflow
(
double
upper) {
107
if
(
support
().second > upper ) {
108
double
shift = upper -
support
().second - DBL_EPSILON;
109
theSupport
.first += shift;
110
theSupport
.second += shift;
111
theCentralValue
+= shift;
112
}
113
}
114
119
double
overlap
(
const
std::pair<double,double>& interval,
120
const
std::pair<double,double>& periodicity)
const
{
121
if
(
support
().first <
support
().second )
122
return
calculateOverlap
(interval,
support
(),
support
().second-
support
().first);
123
double
norm =
124
support
().second - periodicity.first +
125
periodicity.second -
support
().first;
126
return
127
calculateOverlap
(interval,std::make_pair(periodicity.first,
support
().second),norm) +
128
calculateOverlap
(interval,std::make_pair(
support
().first,periodicity.second),norm);
129
}
130
131
private
:
132
136
double
calculateOverlap
(
const
std::pair<double,double>& interval,
137
const
std::pair<double,double>& newSupport,
138
double
norm)
const
{
139
if
( newSupport.first == newSupport.second ) {
140
if
( newSupport.first >= interval.first &&
141
newSupport.second < interval.second )
142
return
1.0;
143
return
0.0;
144
}
145
if
( newSupport.first <= interval.first &&
146
newSupport.second <= interval.first )
147
return
0.0;
148
if
( newSupport.first >= interval.second &&
149
newSupport.second >= interval.second )
150
return
0.0;
151
double
lower = std::max(newSupport.first,interval.first);
152
double
upper = std::min(newSupport.second,interval.second);
153
return
std::max(0.0,(upper-lower)/norm);
154
}
155
159
double
theCentralValue
;
160
164
std::pair<double,double>
theSupport
;
165
169
double
theWeight
;
170
171
};
172
173
}
174
175
#endif
// MYSTATISTICS_EventContribution_hpp_included
Statistics::EventContribution
A pointlike or boxlike eventContribution; serves to define the EventContribution concept.
Definition:
EventContribution.h:19
Statistics::EventContribution::overlap
double overlap(const std::pair< double, double > &interval) const
Return the normalized overlap with an interval.
Definition:
EventContribution.h:49
Statistics::EventContribution::calculateOverlap
double calculateOverlap(const std::pair< double, double > &interval, const std::pair< double, double > &newSupport, double norm) const
Calculate the normalized overlap with an interval.
Definition:
EventContribution.h:136
Statistics::EventContribution::weight
double weight() const
Return the eventContribution weight.
Definition:
EventContribution.h:56
Statistics::EventContribution::support
const std::pair< double, double > & support() const
Return the support.
Definition:
EventContribution.h:44
Statistics::EventContribution::noUnderflow
void noUnderflow(double lower)
Adjust to lower boundary.
Definition:
EventContribution.h:94
Statistics::EventContribution::theSupport
std::pair< double, double > theSupport
The support.
Definition:
EventContribution.h:164
Statistics::EventContribution::periodic
void periodic(const std::pair< double, double > &periodicity)
Remap the central value and support given a periodicity interval; if the support exceeds the periodic...
Definition:
EventContribution.h:65
Statistics::EventContribution::noOverflow
void noOverflow(double upper)
Adjust to upper boundary.
Definition:
EventContribution.h:106
Statistics::EventContribution::theWeight
double theWeight
The eventContribution weight.
Definition:
EventContribution.h:169
Statistics::EventContribution::overlap
double overlap(const std::pair< double, double > &interval, const std::pair< double, double > &periodicity) const
Return the normalized overlap with an interval, assuming a periodic quantity.
Definition:
EventContribution.h:119
Statistics::EventContribution::theCentralValue
double theCentralValue
The central value.
Definition:
EventContribution.h:159
Statistics::EventContribution::EventContribution
EventContribution(double newCentralValue, double newWeight, double newWidth=0.0)
Construct an eventContribution with given width.
Definition:
EventContribution.h:26
Statistics::EventContribution::centralValue
double centralValue() const
Return the central value.
Definition:
EventContribution.h:39
Generated on Thu Jun 20 2024 17:50:53 for Herwig by
1.9.6