Page MenuHomeHEPForge

D121.diff
No OneTemporary

D121.diff

diff --git a/EvtGenBase/EvtMTRandomEngine.hh b/EvtGenBase/EvtMTRandomEngine.hh
--- a/EvtGenBase/EvtMTRandomEngine.hh
+++ b/EvtGenBase/EvtMTRandomEngine.hh
@@ -29,7 +29,9 @@
public:
EvtMTRandomEngine( unsigned int seed = 1430957218 );
- virtual double random();
+ virtual double random() override;
+
+ virtual void setSeed( unsigned int seed ) override;
private:
std::mt19937 m_engine;
diff --git a/EvtGenBase/EvtRandom.hh b/EvtGenBase/EvtRandom.hh
--- a/EvtGenBase/EvtRandom.hh
+++ b/EvtGenBase/EvtRandom.hh
@@ -34,6 +34,8 @@
static double random();
+ static void setSeed( unsigned int seed );
+
//This class does not take ownership of the random engine;
//the caller needs to make sure that the engine is not
//destroyed.
diff --git a/EvtGenBase/EvtRandomEngine.hh b/EvtGenBase/EvtRandomEngine.hh
--- a/EvtGenBase/EvtRandomEngine.hh
+++ b/EvtGenBase/EvtRandomEngine.hh
@@ -31,6 +31,8 @@
virtual double random() = 0;
+ virtual void setSeed( unsigned int seed ) = 0;
+
private:
};
diff --git a/EvtGenBase/EvtSimpleRandomEngine.hh b/EvtGenBase/EvtSimpleRandomEngine.hh
--- a/EvtGenBase/EvtSimpleRandomEngine.hh
+++ b/EvtGenBase/EvtSimpleRandomEngine.hh
@@ -31,6 +31,8 @@
double random() override;
+ void setSeed( unsigned int seed ) override;
+
private:
unsigned long int m_next;
};
diff --git a/History.md b/History.md
--- a/History.md
+++ b/History.md
@@ -11,6 +11,9 @@
===
## R02-0X-00
+20 June 2024 Fernando Abudinen
+* D121: Introduced function `setSeed` to set seed for random number engines.
+
19 June 2024 Thomas Latham
* D120: Remove "reference" field from JSON test files.
Instead simply prepend "Ref/" to output ROOT file name.
diff --git a/src/EvtGenBase/EvtMTRandomEngine.cpp b/src/EvtGenBase/EvtMTRandomEngine.cpp
--- a/src/EvtGenBase/EvtMTRandomEngine.cpp
+++ b/src/EvtGenBase/EvtMTRandomEngine.cpp
@@ -37,3 +37,8 @@
{
return m_distribution( m_engine );
}
+
+void EvtMTRandomEngine::setSeed( unsigned int seed )
+{
+ m_engine.seed( seed );
+}
diff --git a/src/EvtGenBase/EvtRandom.cpp b/src/EvtGenBase/EvtRandom.cpp
--- a/src/EvtGenBase/EvtRandom.cpp
+++ b/src/EvtGenBase/EvtRandom.cpp
@@ -51,6 +51,18 @@
return m_randomEngine->random();
}
+void EvtRandom::setSeed( unsigned int seed )
+{
+ if ( m_randomEngine == nullptr ) {
+ EvtGenReport( EVTGEN_ERROR, "EvtGen" )
+ << "No random engine available in "
+ << "EvtRandom::random()." << endl;
+ ::abort();
+ }
+
+ m_randomEngine->setSeed( seed );
+}
+
// Random number routine to generate numbers between
// min and max. By djl on July 27, 1995.
double EvtRandom::Flat( double min, double max )
diff --git a/src/EvtGenBase/EvtSimpleRandomEngine.cpp b/src/EvtGenBase/EvtSimpleRandomEngine.cpp
--- a/src/EvtGenBase/EvtSimpleRandomEngine.cpp
+++ b/src/EvtGenBase/EvtSimpleRandomEngine.cpp
@@ -33,3 +33,8 @@
return ( temp + 1.0 ) / 32769.0;
}
+
+void EvtSimpleRandomEngine::setSeed( unsigned int seed )
+{
+ m_next = seed;
+}
diff --git a/test/testDecayModel.cc b/test/testDecayModel.cc
--- a/test/testDecayModel.cc
+++ b/test/testDecayModel.cc
@@ -457,6 +457,8 @@
std::cout << "Event " << nEvents - i << std::endl;
}
+ EvtRandom::setSeed( i );
+
// Initial 4-momentum and particle
EvtVector4R pInit( EvtPDL::getMass( parId ), 0.0, 0.0, 0.0 );
EvtParticle* parent{ nullptr };

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 18, 3:57 PM (21 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3803093
Default Alt Text
D121.diff (3 KB)

Event Timeline