File: StandardRandom.cc

package info (click to toggle)
thepeg 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 9,312 kB
  • ctags: 11,509
  • sloc: cpp: 57,129; sh: 11,315; java: 3,212; lisp: 1,402; makefile: 830; ansic: 58; perl: 3
file content (102 lines) | stat: -rw-r--r-- 2,308 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
// -*- C++ -*-
//
// StandardRandom.cc is a part of ThePEG - Toolkit for HEP Event Generation
// Copyright (C) 1999-2011 Leif Lonnblad
//
// ThePEG 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 StandardRandom class.
//

#include "StandardRandom.h"
#include "ThePEG/Interface/ClassDocumentation.h"

using namespace ThePEG;

IBPtr StandardRandom::clone() const {
  return new_ptr(*this);
}

IBPtr StandardRandom::fullclone() const {
  return new_ptr(*this);
}

void StandardRandom::setSeed(long seed) {
  if ( seed == -1 ) seed = 19940801;
  long ij = seed/30082;
  long kl = seed - 30082*ij;
  long i = (ij/177) % 177 + 2;
  long j = ij % 177 + 2;
  long k = (kl/169) % 178 + 1;
  long l = kl % 169;

  for ( int n = 1 ; n < 98 ; n++ ) {
    double s = 0.0;
    double t = 0.5;
    for ( int m = 1 ; m < 25 ; m++) {
      int mm = ( ( (i*j) % 179 ) * k ) % 179;
      i = j;
      j = k;
      k = mm;
      l = ( 53 * l + 1 ) % 169;
      if ( (l*mm % 64 ) >= 32 )
        s += t;
      t *= 0.5;
    }
    u[n-1] = s;
  }
  c = 362436.0 / 16777216.0;
  cd = 7654321.0 / 16777216.0;
  cm = 16777213.0 / 16777216.0;

  i97 = 96;
  j97 = 32;

  flush();
}

void StandardRandom::fill() {

  for ( int i = 0, N = theNumbers.size(); i < N; ++i ) {
    double & uni = theNumbers[i];
    do {
      uni = u[i97] - u[j97];
      if ( uni < 0.0 ) uni++;
      u[i97] = uni;
      
      if (i97 == 0) i97 = 96;
      else i97--;
      
      if (j97 == 0) j97 = 96;
      else j97--;
      
      c -= cd;
      if (c < 0.0) c += cm;
      
      uni -= c;
      if (uni < 0.0) uni += 1.0;
    } while ( uni <= 0.0 || uni >= 1.0 );
  }
  nextNumber = theNumbers.begin();
}

void StandardRandom::persistentOutput(PersistentOStream & os) const {
  os << u << c << cd << cm << i97 << j97;
}

void StandardRandom::persistentInput(PersistentIStream & is, int) {
  is >> u >> c >> cd >> cm >> i97 >> j97;
}

ClassDescription<StandardRandom> StandardRandom::initStandardRandom;

void StandardRandom::Init() {

  static ClassDocumentation<StandardRandom> documentation
    ("Interface to the CLHEP::JamesRandom engine class.");

}