Skip to content

Commit 42b0e9a

Browse files
committed
* 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]
1 parent 43e6a13 commit 42b0e9a

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/GlueXUserEventInformation.cc

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,18 @@ long int *GlueXUserEventInformation::fStartingSeeds = 0;
9393
G4Mutex GlueXUserEventInformation::fMutex = G4MUTEX_INITIALIZER;
9494

9595
GlueXUserEventInformation::GlueXUserEventInformation(hddm_s::HDDM *hddmevent)
96-
: fKeepEvent(true),
96+
: fOutputRecord(0),
97+
fKeepEvent(true),
9798
fNprimaries(0),
9899
fNvertices(0)
99100
{
101+
fEventSequenceNo = HddmOutput::incrementEventNo();
100102
if (hddmevent == 0) {
103+
int runNo = GetRunNo();
101104
fOutputRecord = new hddm_s::HDDM();
102-
fOutputRecord->addPhysicsEvents();
105+
hddm_s::PhysicsEventList pev = fOutputRecord->addPhysicsEvents();
106+
pev(0).setEventNo(fEventSequenceNo);
107+
pev(0).setRunNo(runNo);
103108
}
104109
else {
105110
fOutputRecord = hddmevent;
@@ -120,12 +125,6 @@ GlueXUserEventInformation::~GlueXUserEventInformation()
120125
}
121126
if (fKeepEvent) {
122127
hddm_s::PhysicsEventList pev = fOutputRecord->getPhysicsEvents();
123-
int runno = HddmOutput::getRunNo();
124-
if (runno > 0)
125-
pev(0).setRunNo(runno);
126-
if (pev(0).getEventNo() == 0) {
127-
pev(0).setEventNo(HddmOutput::incrementEventNo());
128-
}
129128
if (fWriteNoHitEvents || pev(0).getHitViews().size() > 0) {
130129
HddmOutput::WriteOutputHDDM(*fOutputRecord);
131130
}
@@ -452,19 +451,16 @@ void GlueXUserEventInformation::SetRandomSeeds()
452451

453452
hddm_s::PhysicsEventList pev = fOutputRecord->getPhysicsEvents();
454453
hddm_s::ReactionList rea = pev(0).getReactions();
455-
long int eventNo = GetEventSequenceNo();
456454
if (rea.size() == 0) {
457455
rea = pev(0).addReactions();
458456
}
459457
hddm_s::RandomList rnd = rea(0).getRandoms();
460458
if (rnd.size() > 0) {
461459
fEventSeeds[0] = rnd(0).getSeed1();
462460
fEventSeeds[1] = rnd(0).getSeed2();
463-
if (pev(0).getEventNo() > 0)
464-
eventNo = pev(0).getEventNo();
465461
G4Random::setTheSeeds(fEventSeeds);
466462
#if VERBOSE_RANDOMS
467-
G4cout << "New event " << eventNo << " with starting seeds "
463+
G4cout << "New event " << pev(0).getEventNo() << " with starting seeds "
468464
<< fEventSeeds[0] << ", " << fEventSeeds[1] << G4endl;
469465
#endif
470466
}
@@ -486,7 +482,7 @@ void GlueXUserEventInformation::SetRandomSeeds()
486482
rnd(0).setSeed3(709975946 + pev(0).getEventNo());
487483
rnd(0).setSeed4(912931182 + pev(0).getEventNo());
488484
#if VERBOSE_RANDOMS
489-
G4cout << "New event " << eventNo << " with starting seeds "
485+
G4cout << "New event " << pev(0).getEventNo() << " with starting seeds "
490486
<< fEventSeeds[0] << ", " << fEventSeeds[1] << G4endl;
491487
#endif
492488
}
@@ -495,7 +491,8 @@ void GlueXUserEventInformation::SetRandomSeeds()
495491
int GlueXUserEventInformation::GetRunNo()
496492
{
497493
if (fOutputRecord && fOutputRecord->getPhysicsEvents().size() > 0) {
498-
return fOutputRecord->getPhysicsEvent().getRunNo();
494+
hddm_s::PhysicsEventList pev = fOutputRecord->getPhysicsEvents();
495+
return pev(0).getRunNo();
499496
}
500497
G4RunManager *runmgr = G4RunManager::GetRunManager();
501498
if (runmgr != 0 && runmgr->GetCurrentRun() != 0) {
@@ -504,13 +501,13 @@ int GlueXUserEventInformation::GetRunNo()
504501
return 0;
505502
}
506503

507-
long int GlueXUserEventInformation::GetEventSequenceNo()
504+
long int GlueXUserEventInformation::GetEventNo()
508505
{
509-
G4RunManager *runmgr = G4RunManager::GetRunManager();
510-
if (runmgr != 0 && runmgr->GetCurrentEvent() != 0) {
511-
return runmgr->GetCurrentEvent()->GetEventID();
506+
if (fOutputRecord && fOutputRecord->getPhysicsEvents().size() > 0) {
507+
hddm_s::PhysicsEventList pev = fOutputRecord->getPhysicsEvents();
508+
return pev(0).getEventNo();
512509
}
513-
return 0;
510+
return fEventSequenceNo;
514511
}
515512

516513
double GlueXUserEventInformation::GetBeamPhotonEnergy()

src/GlueXUserEventInformation.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class GlueXUserEventInformation: public G4VUserEventInformation
4545
void AddMCtrajectoryPoint(const G4Step &step, int save_option);
4646

4747
int GetRunNo();
48-
long int GetEventSequenceNo();
48+
long int GetEventNo();
4949
double GetBeamPhotonEnergy();
5050
int GetGlueXTrackID(int g4ID);
5151
int GetGlueXTrackID(const G4Track *track);
@@ -93,6 +93,7 @@ class GlueXUserEventInformation: public G4VUserEventInformation
9393
std::map<std::string, std::fstream*> fDlogfile;
9494
std::map<std::string, int> fDlogreading;
9595
long int fEventSeeds[2];
96+
long int fEventSequenceNo;
9697

9798
static G4Mutex fMutex;
9899
};

0 commit comments

Comments
 (0)