Skip to content

Commit

Permalink
RNs seeds in G4MT are now handled by us. We use Crypto++ to create ha…
Browse files Browse the repository at this point in the history
…shes for seeds based on art::event ID (Run#, Subrun#, Event#).
  • Loading branch information
Lisa Goodenough committed Dec 17, 2020
1 parent 13eedec commit 8556d31
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 135 deletions.
2 changes: 2 additions & 0 deletions Mu2eG4/inc/Mu2eG4Config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ namespace mu2e {

fhicl::Atom<std::string> generatorModuleLabel {Name("generatorModuleLabel"), ""};

fhicl::Atom<std::string> salt {Name("salt"), ""};

fhicl::Atom<bool> G4InteralFiltering {Name("G4InteralFiltering"), false};
};
}
Expand Down
5 changes: 1 addition & 4 deletions Mu2eG4/inc/Mu2eG4MTRunManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ namespace mu2e {
void initializeMasterRunAction();
void stopG4();
void terminateRun();

G4bool SetUpAnEvent(G4Event* evt,
long& s1, long& s2, long& s3,
G4bool reseedRequired);
G4bool SetUpEvent();

inline G4VUserPhysicsList* getMasterPhysicsList() {return physicsList_;}

Expand Down
7 changes: 4 additions & 3 deletions Mu2eG4/inc/Mu2eG4WorkerRunManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ namespace mu2e {
void initializeThread(Mu2eG4MTRunManager* mRM,
const G4ThreeVector& origin_in_world);
void initializeUserActions(const G4ThreeVector& origin_in_world);
void initializeRun(art::Event* art_event);
void processEvent(art::Event*);
G4Event* generateEvt(G4int i_event);
void initializeRun(art::Event* const art_event);
void processEvent(art::EventID);
G4Event* generateEvt(art::EventID);

inline bool workerRMInitialized() const { return m_managerInitialized; }

Expand All @@ -67,6 +67,7 @@ namespace mu2e {
bool m_steppingVerbose;
int m_mtDebugOutput;
int rmvlevel_;
std::string salt_;

std::unique_ptr<Mu2eG4PerThreadStorage> perThreadObjects_;

Expand Down
62 changes: 4 additions & 58 deletions Mu2eG4/src/Mu2eG4MTRunManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,49 +116,13 @@ namespace mu2e {
StoreRNGStatus(fileN);
}

/////////////////////////////////////////////////////////////////////////////////////
//RANDOM NUMBER SEEDING
SetEventModulo(1);//this sets eventModuloDef
int seedbunchsize = 10000;
int numworkers = 1;
numberOfEventToBeProcessed = std::numeric_limits<int>::max();
numberOfEventProcessed = 0;

nSeedsUsed = 0;
nSeedsFilled = 0;

if(verboseLevel>0)
{ timer->Start(); }

//if we are using G4's seed filling scheme
if ( InitializeSeeds(seedbunchsize) == false && seedbunchsize>0 ) {

G4RNGHelper* helper = G4RNGHelper::GetInstance();
switch(seedOncePerCommunication)
{
case 0://default value
nSeedsFilled = seedbunchsize;
break;
case 1:
nSeedsFilled = numworkers;
break;
case 2:
nSeedsFilled = seedbunchsize/eventModulo + 1;
break;
default:
G4ExceptionDescription msgd;
msgd << "Parameter value <" << seedOncePerCommunication
<< "> of seedOncePerCommunication is invalid. It is reset to 0." ;
G4Exception("G4MTRunManager::InitializeEventLoop()", "Run10036", JustWarning, msgd);
seedOncePerCommunication = 0;
nSeedsFilled = seedbunchsize;
}

// Generates up to nSeedsMax seed pairs only.
if(nSeedsFilled>nSeedsMax) nSeedsFilled=nSeedsMax;
const_cast<CLHEP::HepRandomEngine*>(getMasterRandomEngine())->flatArray(nSeedsPerEvent*nSeedsFilled,randDbl);
helper->Fill(randDbl,nSeedsFilled,seedbunchsize,nSeedsPerEvent);
}
}//Mu2eG4MTRunManager::initializeG4


Expand All @@ -167,8 +131,7 @@ namespace mu2e {
void Mu2eG4MTRunManager::initializeKernelAndRM()
{
G4RunManager::Initialize();
G4MTRunManager::GetMTMasterRunManagerKernel()->SetUpDecayChannels();//note, this is usually done in
//InitializeEventLoop
G4MTRunManager::GetMTMasterRunManagerKernel()->SetUpDecayChannels();//usually done in //InitializeEventLoop

if ( userWorkerThreadInitialization == 0 )
{ userWorkerThreadInitialization = new G4UserWorkerThreadInitialization(); }
Expand Down Expand Up @@ -248,30 +211,13 @@ namespace mu2e {
m_runTerminated = true;
}

G4bool Mu2eG4MTRunManager::SetUpAnEvent(G4Event* evt, long& s1, long& s2, long& s3,
G4bool reseedRequired) {

G4AutoLock l(&setUpEventMutex);

G4bool Mu2eG4MTRunManager::SetUpEvent() {

if( numberOfEventProcessed < numberOfEventToBeProcessed ) {

if(reseedRequired) {
G4RNGHelper* helper = G4RNGHelper::GetInstance();
G4int idx_rndm = nSeedsPerEvent*(evt->GetEventID()-1);
s1 = helper->GetSeed(idx_rndm);
s2 = helper->GetSeed(idx_rndm+1);
if(nSeedsPerEvent==3) s3 = helper->GetSeed(idx_rndm+2);
nSeedsUsed++;
//G4cout << "nSeedsUsed = " << nSeedsUsed << ", nSeedsFilled = " << nSeedsFilled << "\n";
if(nSeedsUsed==nSeedsFilled) {
RefillSeeds();
//G4cout << "Refilling Seeds\n";
}
}
numberOfEventProcessed++;
return true;
}

return false;
}

Expand Down
8 changes: 4 additions & 4 deletions Mu2eG4/src/Mu2eG4MT_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ namespace mu2e {
Mu2eG4WorkerRunManager* scheduleWorkerRM = (access_workerMap->second).get();
access_workerMap.release();

if (_mtDebugOutput > 0){
if (_mtDebugOutput > 1){
G4cout << "FOR SchedID: " << schedID << ", TID=" << tid << ", workerRunManagers[schedID].get() is:" << scheduleWorkerRM << "\n";
}

Expand All @@ -373,9 +373,9 @@ namespace mu2e {

Mu2eG4PerThreadStorage* perThreadStore = scheduleWorkerRM->getMu2eG4PerThreadStorage();
perThreadStore->initializeEventInfo(&event, &spHelper, &parentHelper, &genInputHits, _generatorModuleLabel);
scheduleWorkerRM->processEvent(&event);
scheduleWorkerRM->processEvent(event.id());

if (_mtDebugOutput > 0){
if (_mtDebugOutput > 2){
G4cout << "Current Event in RM is: " << scheduleWorkerRM->GetCurrentEvent()->GetEventID() << "\n";
}

Expand Down Expand Up @@ -418,7 +418,7 @@ namespace mu2e {
// Tell G4 that this run is over.
void Mu2eG4MT::endRun(art::Run & run, art::ProcessingFrame const& procFrame) {

if (_mtDebugOutput > 1){
if (_mtDebugOutput > 0){
G4cout << "At endRun pt1, we have " << myworkerRunManagerMap.size() << " members in the map "
<< "and are running " << num_threads << " threads.\n" ;
}
Expand Down
Loading

0 comments on commit 8556d31

Please sign in to comment.