File: MultiIterationStatistics.cc

package info (click to toggle)
herwig%2B%2B 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 27,128 kB
  • ctags: 24,739
  • sloc: cpp: 188,949; fortran: 23,193; sh: 11,365; python: 5,069; ansic: 3,539; makefile: 1,865; perl: 2
file content (119 lines) | stat: -rw-r--r-- 4,248 bytes parent folder | download
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
// -*- C++ -*-
//
// MultiIterationStatictis.cc is a part of Herwig++ - A multi-purpose Monte Carlo event generator
// Copyright (C) 2002-2012 The Herwig Collaboration
//
// Herwig++ is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
//
// This is the implementation of the non-inlined, non-templated member
// functions of the MultiIterationStatistics class.
//

#include "MultiIterationStatistics.h"

#include <cassert>

using namespace Herwig;

MultiIterationStatistics::MultiIterationStatistics() 
  : GeneralStatistics() {}

MultiIterationStatistics::~MultiIterationStatistics() {}

void MultiIterationStatistics::put(PersistentOStream & os) const {
  GeneralStatistics::put(os);
  os << theIterations;
}

void MultiIterationStatistics::get(PersistentIStream & is) {
  GeneralStatistics::get(is);
  is >> theIterations;
}

double MultiIterationStatistics::chi2() const {
  assert(!iterations().empty());
  double current = averageWeight();
  double res = 0.;
  for ( vector<GeneralStatistics>::const_iterator s =
	  iterations().begin(); s != iterations().end(); ++s ) {
    if ( s->selectedPoints() < 2 || s->averageWeightVariance() == 0.0 )
      continue;
    res += sqr(s->averageWeight()-current)/s->averageWeightVariance();
  }
  res += 
    selectedPoints() > 1 && GeneralStatistics::averageWeightVariance() != 0.0 ?
    sqr(GeneralStatistics::averageWeight()-current)/
    GeneralStatistics::averageWeightVariance() : 0.;
  res /= iterations().size();
  return res;
}

double MultiIterationStatistics::averageWeight() const {
  double invSigmaBar = 0.;
  double res = 0.;
  for ( vector<GeneralStatistics>::const_iterator s =
	  iterations().begin(); s != iterations().end(); ++s ) {
    if ( s->selectedPoints() < 2 || s->averageWeightVariance() == 0.0 )
      continue;
    invSigmaBar += 1./s->averageWeightVariance();
    res += s->averageWeight()/s->averageWeightVariance();
  }
  invSigmaBar += 
    selectedPoints() > 1 && GeneralStatistics::averageWeightVariance() != 0.0 ?
    1./GeneralStatistics::averageWeightVariance() : 0.;
  res += 
    selectedPoints() > 1 && GeneralStatistics::averageWeightVariance() != 0.0 ?
    GeneralStatistics::averageWeight()/GeneralStatistics::averageWeightVariance() : 0.;
  res /= invSigmaBar;
  return res;
}

double MultiIterationStatistics::averageWeightVariance() const {
  double invSigmaBar = 0.;
  for ( vector<GeneralStatistics>::const_iterator s =
	  iterations().begin(); s != iterations().end(); ++s ) {
    if ( s->selectedPoints() < 2 || s->averageWeightVariance() == 0.0 )
      continue;
    invSigmaBar += 1./s->averageWeightVariance();
  }
  invSigmaBar += 
    selectedPoints() > 1 && GeneralStatistics::averageWeightVariance() != 0.0 ?
    1./GeneralStatistics::averageWeightVariance() : 0.;
  return 1./invSigmaBar;
}

double MultiIterationStatistics::averageAbsWeight() const {
  double invSigmaBar = 0.;
  double res = 0.;
  for ( vector<GeneralStatistics>::const_iterator s =
	  iterations().begin(); s != iterations().end(); ++s ) {
    if ( s->selectedPoints() < 2 || s->averageAbsWeightVariance() == 0.0 )
      continue;
    invSigmaBar += 1./s->averageAbsWeightVariance();
    res += s->averageAbsWeight()/s->averageAbsWeightVariance();
  }
  invSigmaBar += 
    selectedPoints() > 1 && GeneralStatistics::averageAbsWeightVariance() != 0.0 ?
    1./GeneralStatistics::averageAbsWeightVariance() : 0.;
  res += 
    selectedPoints() > 1 && GeneralStatistics::averageAbsWeightVariance() != 0.0 ?
    GeneralStatistics::averageAbsWeight()/GeneralStatistics::averageAbsWeightVariance() : 0.;
  res /= invSigmaBar;
  return res;
}

double MultiIterationStatistics::averageAbsWeightVariance() const {
  double invSigmaBar = 0.;
  for ( vector<GeneralStatistics>::const_iterator s =
	  iterations().begin(); s != iterations().end(); ++s ) {
    if ( s->selectedPoints() < 2 || s->averageAbsWeightVariance() == 0.0 )
      continue;
    invSigmaBar += 1./s->averageAbsWeightVariance();
  }
  invSigmaBar += 
    selectedPoints() > 1 && GeneralStatistics::averageAbsWeightVariance() != 0.0 ?
    1./GeneralStatistics::averageAbsWeightVariance() : 0.;
  return 1./invSigmaBar;
}