thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Analysis
LWH
DataPointSet.h
1
// -*- C++ -*-
2
//
3
// DataPointSet.h is a part of ThePEG - Toolkit for HEP Event Generation
4
// Copyright (C) 1999-2019 Leif Lonnblad
5
//
6
// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8
//
9
#ifndef LWH_DataPointSet_H
10
#define LWH_DataPointSet_H
11
//
12
// This is the declaration of the DataPointSet class representing
13
//
14
15
16
#include <vector>
17
#include <limits>
18
#include <cmath>
19
#include <algorithm>
20
#include "AIDataPointSet.h"
21
#include "ManagedObject.h"
22
#include "DataPoint.h"
23
24
namespace
LWH
{
25
26
using namespace
AIDA;
27
33
class
DataPointSet
:
public
IDataPointSet,
public
ManagedObject
{
34
35
public
:
36
41
DataPointSet
(
int
D):
dim
(D) {}
42
46
virtual
~DataPointSet
() {}
47
51
IAnnotation &
annotation
() {
52
throw
std::runtime_error(
"LWH cannot handle annotations"
);
53
}
54
58
const
IAnnotation &
annotation
()
const
{
59
throw
std::runtime_error(
"LWH cannot handle annotations"
);
60
}
61
66
std::string
title
()
const
{
67
return
theTitle
;
68
}
69
74
std::string
name
()
const
{
75
return
theTitle
;
76
}
77
83
bool
setTitle
(
const
std::string &
title
) {
84
theTitle
=
title
;
85
return
true
;
86
}
87
93
int
dimension
()
const
{
94
return
dim
;
95
}
96
101
void
clear
() {
102
dset
.clear();
103
}
104
110
int
size
()
const
{
111
return
dset
.size();
112
}
113
119
IDataPoint *
point
(
int
index) {
120
return
&(
dset
[index]);
121
}
122
136
bool
setCoordinate
(
int
coord,
137
const
std::vector<double> & val,
138
const
std::vector<double> & err) {
139
return
setCoordinate
(coord, val, err, err);
140
}
141
157
bool
setCoordinate
(
int
coord,
158
const
std::vector<double> & val,
159
const
std::vector<double> & errp,
160
const
std::vector<double> & errm) {
161
if
( coord < 0 || coord >=
dimension
() )
return
false
;
162
if
( val.size() !=
dset
.size() || errp.size() !=
dset
.size() ||
163
errm.size() !=
dset
.size() )
return
false
;
164
for
(
int
i = 0, N = val.size(); i < N; ++i ) {
165
dset
[i].coordinate(coord)->setValue(val[i]);
166
dset
[i].coordinate(coord)->setErrorPlus(errp[i]);
167
dset
[i].coordinate(coord)->setErrorMinus(errm[i]);
168
}
169
return
true
;
170
}
171
176
const
IDataPoint *
point
(
int
index)
const
{
177
if
( index < 0 ||
unsigned
(index) >=
dset
.size() )
return
0;
178
return
&(
dset
[index]);
179
}
180
185
IDataPoint *
addPoint
() {
186
dset
.push_back(
DataPoint
(
dimension
()));
187
return
&(
dset
.back());
188
}
189
196
bool
addPoint
(
const
IDataPoint &
point
) {
197
if
(
dimension
() &&
dimension
() !=
point
.dimension() )
return
false
;
198
dset
.push_back(
DataPoint
(
point
));
199
return
true
;
200
}
201
207
bool
removePoint
(
int
index) {
208
if
( index < 0 ||
unsigned
(index) >=
dset
.size() )
return
false
;
209
dset
.erase(
dset
.begin() + index);
210
return
true
;
211
}
212
220
double
lowerExtent
(
int
coord)
const
{
221
if
(
dset
.empty() )
return
std::numeric_limits<double>::quiet_NaN();
222
if
( coord < 0 || coord >=
dimension
() )
223
return
std::numeric_limits<double>::quiet_NaN();
224
double
low =
dset
[0].coordinate(coord)->value();
225
for
(
int
i = 1, N =
dset
.size(); i < N; ++i )
226
low = std::min(low,
dset
[i].coordinate(coord)->value());
227
return
low;
228
}
229
237
double
upperExtent
(
int
coord)
const
{
238
if
(
dset
.empty() )
return
std::numeric_limits<double>::quiet_NaN();
239
if
( coord < 0 || coord >=
dimension
() )
240
return
std::numeric_limits<double>::quiet_NaN();
241
double
upp =
dset
[0].coordinate(coord)->value();
242
for
(
int
i = 1, N =
dset
.size(); i < N; ++i )
243
upp = std::max(upp,
dset
[i].coordinate(coord)->value());
244
return
upp;
245
}
246
253
bool
scale
(
double
scale
) {
254
for
(
int
i = 0, N =
dset
.size(); i < N; ++i )
255
for
(
int
j = 0, M =
dset
[i].
dimension
(); j < M; ++j ) {
256
IMeasurement * m =
dset
[i].coordinate(j);
257
m->setValue(m->value()*
scale
);
258
m->setErrorPlus(m->errorPlus()*
scale
);
259
m->setErrorMinus(m->errorPlus()*
scale
);
260
}
261
return
true
;
262
}
263
270
bool
scaleValues
(
double
scale
) {
271
for
(
int
i = 0, N =
dset
.size(); i < N; ++i )
272
for
(
int
j = 0, M =
dset
[i].
dimension
(); j < M; ++j ) {
273
IMeasurement * m =
dset
[i].coordinate(j);
274
m->setValue(m->value()*
scale
);
275
}
276
return
true
;
277
}
278
285
bool
scaleErrors
(
double
scale
) {
286
for
(
int
i = 0, N =
dset
.size(); i < N; ++i )
287
for
(
int
j = 0, M =
dset
[i].
dimension
(); j < M; ++j ) {
288
IMeasurement * m =
dset
[i].coordinate(j);
289
m->setErrorPlus(m->errorPlus()*
scale
);
290
m->setErrorMinus(m->errorPlus()*
scale
);
291
}
292
return
true
;
293
}
294
299
void
*
cast
(
const
std::string &)
const
{
300
return
0;
301
}
302
306
bool
writeXML
(std::ostream & os, std::string path, std::string
name
) {
307
os <<
" <dataPointSet name=\""
<<
name
308
<<
"\"\n title=\""
<<
title
()
309
<<
"\" path=\""
<< path
310
<<
"\" dimension=\""
<<
dimension
() <<
"\">\n"
;
311
for
(
int
d = 0; d <
dimension
(); ++d )
312
os <<
" <dimension dim=\""
<< d <<
"\" title=\"unknown\" />\n"
;
313
for
(
int
i = 0, N =
size
(); i < N; ++i ) {
314
os <<
" <dataPoint>\n"
;
315
for
(
int
j = 0, M =
dimension
(); j < M; ++j )
316
os <<
" <measurement value=\""
317
<<
point
(i)->coordinate(j)->value()
318
<<
"\" errorPlus=\""
319
<<
point
(i)->coordinate(j)->errorPlus()
320
<<
"\" errorMinus=\""
321
<<
point
(i)->coordinate(j)->errorMinus()
322
<<
"\"/>\n"
;
323
os <<
" </dataPoint>\n"
;
324
}
325
os <<
" </dataPointSet>"
<< std::endl;
326
return
true
;
327
}
328
334
bool
writeFLAT
(std::ostream & os, std::string path, std::string
name
) {
335
os <<
"# "
<< path <<
"/"
<<
name
<<
" "
<<
size
()
336
<<
" \""
<<
title
() <<
" \" dimension "
<<
dimension
() << std::endl;
337
for
(
int
i = 0, N =
size
(); i < N; ++i ) {
338
for
(
int
j = 0, M =
dimension
(); j < M; ++j )
339
os <<
point
(i)->coordinate(j)->value() <<
" "
;
340
for
(
int
j = 0, M =
dimension
(); j < M; ++j )
341
os <<
point
(i)->coordinate(j)->errorPlus() <<
" "
;
342
for
(
int
j = 0, M =
dimension
(); j < M; ++j )
343
os <<
point
(i)->coordinate(j)->errorMinus() <<
" "
;
344
os << std::endl;
345
}
346
os << std::endl;
347
return
true
;
348
}
349
350
private
:
351
353
std::string
theTitle
;
354
358
std::vector<DataPoint>
dset
;
359
363
unsigned
int
dim
;
364
365
366
};
367
368
}
369
370
#endif
/* LWH_DataPointSet_H */
LWH::DataPointSet
An DataPointSet represents a binned histogram axis.
Definition:
DataPointSet.h:33
LWH::DataPointSet::~DataPointSet
virtual ~DataPointSet()
Destructor.
Definition:
DataPointSet.h:46
LWH::DataPointSet::scale
bool scale(double scale)
Scales the values and the errors of all the measurements of each point by a given factor.
Definition:
DataPointSet.h:253
LWH::DataPointSet::theTitle
std::string theTitle
The title.
Definition:
DataPointSet.h:353
LWH::DataPointSet::dim
unsigned int dim
The dimension of the points in this set.
Definition:
DataPointSet.h:363
LWH::DataPointSet::writeXML
bool writeXML(std::ostream &os, std::string path, std::string name)
Write out the data set in the AIDA xml format.
Definition:
DataPointSet.h:306
LWH::DataPointSet::title
std::string title() const
Get the data set's title.
Definition:
DataPointSet.h:66
LWH::DataPointSet::dset
std::vector< DataPoint > dset
The included data points.
Definition:
DataPointSet.h:358
LWH::DataPointSet::clear
void clear()
Remove all the IDataPoints in the set.
Definition:
DataPointSet.h:101
LWH::DataPointSet::name
std::string name() const
Get the data set's title.
Definition:
DataPointSet.h:74
LWH::DataPointSet::lowerExtent
double lowerExtent(int coord) const
Get the lower value for a give axis.
Definition:
DataPointSet.h:220
LWH::DataPointSet::setCoordinate
bool setCoordinate(int coord, const std::vector< double > &val, const std::vector< double > &err)
Set the values and errors of a given coordinate all at once.
Definition:
DataPointSet.h:136
LWH::DataPointSet::addPoint
IDataPoint * addPoint()
Add a new empty IDataPoint at the end of the set.
Definition:
DataPointSet.h:185
LWH::DataPointSet::annotation
IAnnotation & annotation()
Not implemented in LWH.
Definition:
DataPointSet.h:51
LWH::DataPointSet::dimension
int dimension() const
Get the dimension of the IDataPoints that can be stored in the set.
Definition:
DataPointSet.h:93
LWH::DataPointSet::setTitle
bool setTitle(const std::string &title)
Set the data set's title.
Definition:
DataPointSet.h:83
LWH::DataPointSet::addPoint
bool addPoint(const IDataPoint &point)
Add a copy of an IDataPoint at the end of the set.
Definition:
DataPointSet.h:196
LWH::DataPointSet::scaleValues
bool scaleValues(double scale)
Scales the values of all the measurements of each point by a given factor.
Definition:
DataPointSet.h:270
LWH::DataPointSet::upperExtent
double upperExtent(int coord) const
Get the upper value for a give axis.
Definition:
DataPointSet.h:237
LWH::DataPointSet::scaleErrors
bool scaleErrors(double scale)
Scales the errors of all the measurements of each point by a given factor.
Definition:
DataPointSet.h:285
LWH::DataPointSet::annotation
const IAnnotation & annotation() const
Not implemented in LWH.
Definition:
DataPointSet.h:58
LWH::DataPointSet::point
IDataPoint * point(int index)
Get the IDataPoint at a give index in the set.
Definition:
DataPointSet.h:119
LWH::DataPointSet::writeFLAT
bool writeFLAT(std::ostream &os, std::string path, std::string name)
Write out the data set in a flat text file suitable for eg.
Definition:
DataPointSet.h:334
LWH::DataPointSet::cast
void * cast(const std::string &) const
Not implemented in LWH.
Definition:
DataPointSet.h:299
LWH::DataPointSet::size
int size() const
Get the current size of the IDataPointSet, i.e.
Definition:
DataPointSet.h:110
LWH::DataPointSet::removePoint
bool removePoint(int index)
Remove the IDataPoint at a given index.
Definition:
DataPointSet.h:207
LWH::DataPointSet::DataPointSet
DataPointSet(int D)
Standard constructor takes the dimension, D, of the data points as argument.
Definition:
DataPointSet.h:41
LWH::DataPointSet::setCoordinate
bool setCoordinate(int coord, const std::vector< double > &val, const std::vector< double > &errp, const std::vector< double > &errm)
Set the values and errors of a given coordinate all at once.
Definition:
DataPointSet.h:157
LWH::DataPointSet::point
const IDataPoint * point(int index) const
Return the data point at the given index.
Definition:
DataPointSet.h:176
LWH::DataPoint
An DataPoint represents a binned histogram axis.
Definition:
DataPoint.h:31
LWH::ManagedObject
The creator of trees.
Definition:
ManagedObject.h:25
LWH
The LWH namespace contains a Light-Weight Histogram package which implements the most rudimentary his...
Definition:
AnalysisFactory.h:35
Generated on Thu Jun 20 2024 14:47:00 for ThePEG by
1.9.6