From 5c8c12cc8a471f4f621b3fbf642c0a9f8c6b50c9 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Fri, 28 Aug 2020 14:24:55 -0400 Subject: [PATCH 1/4] * protect the output serialization from writing out nan and inf values [rtj] --- src/AdaptiveSampler.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/AdaptiveSampler.cc b/src/AdaptiveSampler.cc index 90d5252..891a50f 100644 --- a/src/AdaptiveSampler.cc +++ b/src/AdaptiveSampler.cc @@ -134,6 +134,7 @@ // of AdaptiveSampler. #include +#include #include #include #include @@ -834,18 +835,20 @@ int AdaptiveSampler::Cell::serialize(std::ofstream &ofs, bool optimized) if (nhit != 0) ofs << "nhit=" << nhit << std::endl; if (sum_wI != 0) - ofs << "sum_wI=" << sum_wI << std::endl; + ofs << "sum_wI=" << (std::isfinite(sum_wI)? sum_wI : 0) << std::endl; if (sum_wI2 != 0) - ofs << "sum_wI2=" << sum_wI2 << std::endl; + ofs << "sum_wI2=" << (std::isfinite(sum_wI2)? sum_wI2 : 0) << std::endl; if (sum_wI4 != 0) - ofs << "sum_wI4=" << sum_wI4 << std::endl; + ofs << "sum_wI4=" << (std::isfinite(sum_wI4)? sum_wI4 : 0) << std::endl; for (int i=0; i < 3*ndim; ++i) { if (sum_wI2d[i] != 0) - ofs << "sum_wI2d[" << i << "]=" << sum_wI2d[i] << std::endl; + ofs << "sum_wI2d[" << i << "]=" + << (std::isfinite(sum_wI2d[i])? sum_wI2d[i] : 0) << std::endl; } for (int i=0; i < 3*ndim; ++i) { if (sum_wI4d[i] != 0) - ofs << "sum_wI4d[" << i << "]=" << sum_wI4d[i] << std::endl; + ofs << "sum_wI4d[" << i << "]=" + << (std::isfinite(sum_wI4d[i])? sum_wI4d[i] : 0) << std::endl; } if (optimized) ofs << "subset=" << std::setprecision(20) << opt_subset << std::endl; From 67b420ad470a461b5765acc8bcdaa158d292deb0 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Fri, 28 Aug 2020 14:26:09 -0400 Subject: [PATCH 2/4] * protect methods with mutex that modify static data members [rtj] --- src/HddmOutput.cc | 1 + src/HddmOutput.hh | 1 + 2 files changed, 2 insertions(+) diff --git a/src/HddmOutput.cc b/src/HddmOutput.cc index d33ed26..dfdd393 100644 --- a/src/HddmOutput.cc +++ b/src/HddmOutput.cc @@ -54,6 +54,7 @@ HddmOutput& HddmOutput::operator=(HddmOutput &src) void HddmOutput::setRunNo(int runno) { + G4AutoLock barrier(&fMutex); fRunNo = runno; } diff --git a/src/HddmOutput.hh b/src/HddmOutput.hh index 78cd5b5..773b731 100644 --- a/src/HddmOutput.hh +++ b/src/HddmOutput.hh @@ -57,6 +57,7 @@ inline int HddmOutput::getEventNo() inline void HddmOutput::setEventNo(int eventno) { + G4AutoLock barrier(&fMutex); fEventNo = eventno; } From 43e6a133290c272556825ff625414708cccac9aa Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Fri, 28 Aug 2020 14:27:26 -0400 Subject: [PATCH 3/4] * add instantiation of fresh instances of GlueXPhotonBeamGenerator for each worker thread action object [rtj] --- src/GlueXPrimaryGeneratorAction.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GlueXPrimaryGeneratorAction.cc b/src/GlueXPrimaryGeneratorAction.cc index aaace11..619edb5 100644 --- a/src/GlueXPrimaryGeneratorAction.cc +++ b/src/GlueXPrimaryGeneratorAction.cc @@ -79,6 +79,7 @@ GlueXPrimaryGeneratorAction::GlueXPrimaryGeneratorAction() fParticleGun = new GlueXParticleGun(); if (fSourceType == SOURCE_TYPE_HDDM) { + clone_photon_beam_generator(); fPrimaryGenerator = new GlueXPrimaryGenerator(fHDDMistream); return; } @@ -493,7 +494,7 @@ GlueXPrimaryGeneratorAction &GlueXPrimaryGeneratorAction::operator=(const else if (fSourceType == SOURCE_TYPE_PARTICLE_GUN) { fParticleGun->SetParticleDefinition(fGunParticle.partDef); } - if (fPhotonBeamGenerator) { + if (src.fPhotonBeamGenerator) { clone_photon_beam_generator(); } fBeamvertex = src.fBeamvertex; From 42b0e9a19ed92fd3bd2cc8195d20209c4fc9e077 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Fri, 28 Aug 2020 14:30:44 -0400 Subject: [PATCH 4/4] * add event counting to the constructor, and use it to assign a unique event number to each event at the start instead of the end of event simulation.[rtj] --- src/GlueXUserEventInformation.cc | 35 +++++++++++++++----------------- src/GlueXUserEventInformation.hh | 3 ++- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/GlueXUserEventInformation.cc b/src/GlueXUserEventInformation.cc index fe56ad8..1aaa7ed 100644 --- a/src/GlueXUserEventInformation.cc +++ b/src/GlueXUserEventInformation.cc @@ -93,13 +93,18 @@ long int *GlueXUserEventInformation::fStartingSeeds = 0; G4Mutex GlueXUserEventInformation::fMutex = G4MUTEX_INITIALIZER; GlueXUserEventInformation::GlueXUserEventInformation(hddm_s::HDDM *hddmevent) - : fKeepEvent(true), + : fOutputRecord(0), + fKeepEvent(true), fNprimaries(0), fNvertices(0) { + fEventSequenceNo = HddmOutput::incrementEventNo(); if (hddmevent == 0) { + int runNo = GetRunNo(); fOutputRecord = new hddm_s::HDDM(); - fOutputRecord->addPhysicsEvents(); + hddm_s::PhysicsEventList pev = fOutputRecord->addPhysicsEvents(); + pev(0).setEventNo(fEventSequenceNo); + pev(0).setRunNo(runNo); } else { fOutputRecord = hddmevent; @@ -120,12 +125,6 @@ GlueXUserEventInformation::~GlueXUserEventInformation() } if (fKeepEvent) { hddm_s::PhysicsEventList pev = fOutputRecord->getPhysicsEvents(); - int runno = HddmOutput::getRunNo(); - if (runno > 0) - pev(0).setRunNo(runno); - if (pev(0).getEventNo() == 0) { - pev(0).setEventNo(HddmOutput::incrementEventNo()); - } if (fWriteNoHitEvents || pev(0).getHitViews().size() > 0) { HddmOutput::WriteOutputHDDM(*fOutputRecord); } @@ -452,7 +451,6 @@ void GlueXUserEventInformation::SetRandomSeeds() hddm_s::PhysicsEventList pev = fOutputRecord->getPhysicsEvents(); hddm_s::ReactionList rea = pev(0).getReactions(); - long int eventNo = GetEventSequenceNo(); if (rea.size() == 0) { rea = pev(0).addReactions(); } @@ -460,11 +458,9 @@ void GlueXUserEventInformation::SetRandomSeeds() if (rnd.size() > 0) { fEventSeeds[0] = rnd(0).getSeed1(); fEventSeeds[1] = rnd(0).getSeed2(); - if (pev(0).getEventNo() > 0) - eventNo = pev(0).getEventNo(); G4Random::setTheSeeds(fEventSeeds); #if VERBOSE_RANDOMS - G4cout << "New event " << eventNo << " with starting seeds " + G4cout << "New event " << pev(0).getEventNo() << " with starting seeds " << fEventSeeds[0] << ", " << fEventSeeds[1] << G4endl; #endif } @@ -486,7 +482,7 @@ void GlueXUserEventInformation::SetRandomSeeds() rnd(0).setSeed3(709975946 + pev(0).getEventNo()); rnd(0).setSeed4(912931182 + pev(0).getEventNo()); #if VERBOSE_RANDOMS - G4cout << "New event " << eventNo << " with starting seeds " + G4cout << "New event " << pev(0).getEventNo() << " with starting seeds " << fEventSeeds[0] << ", " << fEventSeeds[1] << G4endl; #endif } @@ -495,7 +491,8 @@ void GlueXUserEventInformation::SetRandomSeeds() int GlueXUserEventInformation::GetRunNo() { if (fOutputRecord && fOutputRecord->getPhysicsEvents().size() > 0) { - return fOutputRecord->getPhysicsEvent().getRunNo(); + hddm_s::PhysicsEventList pev = fOutputRecord->getPhysicsEvents(); + return pev(0).getRunNo(); } G4RunManager *runmgr = G4RunManager::GetRunManager(); if (runmgr != 0 && runmgr->GetCurrentRun() != 0) { @@ -504,13 +501,13 @@ int GlueXUserEventInformation::GetRunNo() return 0; } -long int GlueXUserEventInformation::GetEventSequenceNo() +long int GlueXUserEventInformation::GetEventNo() { - G4RunManager *runmgr = G4RunManager::GetRunManager(); - if (runmgr != 0 && runmgr->GetCurrentEvent() != 0) { - return runmgr->GetCurrentEvent()->GetEventID(); + if (fOutputRecord && fOutputRecord->getPhysicsEvents().size() > 0) { + hddm_s::PhysicsEventList pev = fOutputRecord->getPhysicsEvents(); + return pev(0).getEventNo(); } - return 0; + return fEventSequenceNo; } double GlueXUserEventInformation::GetBeamPhotonEnergy() diff --git a/src/GlueXUserEventInformation.hh b/src/GlueXUserEventInformation.hh index 1304746..47a9add 100644 --- a/src/GlueXUserEventInformation.hh +++ b/src/GlueXUserEventInformation.hh @@ -45,7 +45,7 @@ class GlueXUserEventInformation: public G4VUserEventInformation void AddMCtrajectoryPoint(const G4Step &step, int save_option); int GetRunNo(); - long int GetEventSequenceNo(); + long int GetEventNo(); double GetBeamPhotonEnergy(); int GetGlueXTrackID(int g4ID); int GetGlueXTrackID(const G4Track *track); @@ -93,6 +93,7 @@ class GlueXUserEventInformation: public G4VUserEventInformation std::map fDlogfile; std::map fDlogreading; long int fEventSeeds[2]; + long int fEventSequenceNo; static G4Mutex fMutex; };