next up previous contents
Next: Q6: How to overlap Up: Frequently Asked Questions Previous: Q4:How to get generator

Q5: Save seeds of random number to restart simulation later.

During course of our analysis, sometimes we want to restart Monte Calro event generation and simulation to study an event which apears only after generating many number of events. It is time consuming if we need to restart event generation from very beginning. In JSF, we can save seeds of random numbers of every events in a file and this file can be used to restart event simulation from middle of run.

The Quick Simulator uses CERNLIB subroutine, ranmar and rnorml to generate uniform and gausian random number generation. These routine requires to store about 200 words of array data to restore sequence of random number generation. To write these data in a file, a function JSFLCFULL::WriteRandomSeed(char* filename) can be used. If filename is ommitted, it is obtained from a jsf parameter JSFLCFULL.RandomSeedWriteFile. If the jsf parameter is not specified neither, the name jsf-lcfull-seed.XXXX is used, where XXXX is a Process ID (PID).

The seeds saved by JSFLCFULL::WriteRandomSeed(char* filename) are read by JSFLCFULL::ReadRandomSeed(char* filename), which resets the state of the random number generation. Thus the random number generation can be restarted from the status stored in filename. The jsf parameter, JSFLCFULL.RandomSeedReadFile, can be used to set the file name.

The Tauola library used for $\tau$ decay also uses ranmar and rnorml. Pythia generator uses different subroutines to generate random numbers, which uses about 100 words of array data to save random number status. Thus PythiaGenerator::WriteRandomSeed(char* filename) and PythiaGenerator::ReadRandomSeed(char* filename) are prepared to write/read seeds of random number.

A sample script to be put in the standard UserAnalysis.C file is shown below.

//_________________________________________________________
void UserInitialize()
{
    JSFLCFULL *lcfull=(JSFLCFULL*)jsf->FindModule("JSFLCFULL");
    lcfull->ReadRandomSeed("seed-lcfull-previous");
    lcfull->PrintRandomSeed();
    PythiaGenerator *pyg=(PythiaGenerator*)jsf->FindModule("PythiaGenerator");
    pyg->ReadRandomSeed("seed-pythia-previous");
    pyg->PrintRandomSeed();
}
//_________________________________________________________
void UserAnalysis()
{
    JSFLCFULL *lcfull=(JSFLCFULL*)jsf->FindModule("JSFLCFULL");
    PythiaGenerator *pyg=(PythiaGenerator*)jsf->FindModule("PythiaGenerator");
    lcfull->WriteRandomSeed("seed-lcfull");
    pyg->WriteRandomSeed("seed-pythia");
}

In UserAnalysis.C script, a function UserInitialize() is called at the begining of job and UserAnalysis() is called at the end of event data analysis. In this example, seeds of other run stored in files seed-lcfull-previous and seed-pythia-previous are obtained at the begining of run, and seeds at the end of event analysis are stored in files, seed-lcfull and seed-pythia.


next up previous contents
Next: Q6: How to overlap Up: Frequently Asked Questions Previous: Q4:How to get generator
Miyamoto Akiya
2001-11-07