Skip to content

Commit

Permalink
DDSim: correct the number of events when running over all events (-1)
Browse files Browse the repository at this point in the history
GenerationActionInit: declare properties to access number of processed runs and events
  • Loading branch information
andresailer committed May 3, 2024
1 parent 58fa8c0 commit 816820a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 16 additions & 7 deletions DDG4/python/DDSim/DD4hepSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,10 @@ def run(self):
actionList.append(gen)
self.__applyBoostOrSmear(kernel, actionList, index)

generationInit = None
if actionList:
self._buildInputStage(geant4, actionList, output_level=self.output.inputStage,
have_mctruth=self._enablePrimaryHandler())
generationInit = self._buildInputStage(geant4, actionList, output_level=self.output.inputStage,
have_mctruth=self._enablePrimaryHandler())

# ================================================================================================

Expand Down Expand Up @@ -524,13 +525,20 @@ def run(self):
logger.error("Termination failed!")

totalTimeUser, totalTimeSys, _cuTime, _csTime, _elapsedTime = os.times()
processedEvents = self.numberOfEvents
if generationInit:
processedEvents = int(generationInit.numberOfEvents)
if self.numberOfEvents < 0:
processedEvents -= 1
logger.info(f"Correcting number of events to: {processedEvents}")

if self.printLevel <= 3:
logger.info("DDSim INFO Total Time: %3.2f s (User), %3.2f s (System)" %
logger.info("Total Time: %3.2f s (User), %3.2f s (System)" %
(totalTimeUser, totalTimeSys))
if self.numberOfEvents != 0:
if processedEvents != 0:
eventTime = totalTimeUser - startUpTime
perEventTime = eventTime / self.numberOfEvents
logger.info("DDSim INFO StartUp Time: %3.2f s, Event Processing: %3.2f s (%3.2f s/Event) "
perEventTime = eventTime / processedEvents
logger.info("StartUp Time: %3.2f s, Event Processing: %3.2f s (%3.2f s/Event) "
% (startUpTime, eventTime, perEventTime))
return exitCode

Expand Down Expand Up @@ -752,6 +760,7 @@ def _buildInputStage(self, geant4, generator_input_modules, output_level=None, h

# Register Generation initialization action
gen = GeneratorAction(geant4.kernel(), "Geant4GeneratorActionInit/GenerationInit")
generationInit = gen
if output_level is not None:
gen.OutputLevel = output_level
ga.adopt(gen)
Expand Down Expand Up @@ -781,7 +790,7 @@ def _buildInputStage(self, geant4, generator_input_modules, output_level=None, h
gen.OutputLevel = output_level
ga.adopt(gen)
# Puuuhh! All done.
return None
return generationInit


################################################################################
Expand Down
2 changes: 2 additions & 0 deletions DDG4/src/Geant4GeneratorActionInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Geant4GeneratorActionInit::Geant4GeneratorActionInit(Geant4Context* ctxt, const
InstanceCount::increment(this);
context()->kernel().runAction().callAtEnd(this,&Geant4GeneratorActionInit::end);
context()->kernel().runAction().callAtBegin(this,&Geant4GeneratorActionInit::begin);
declareProperty("numberOfEvents", m_evtTotal);
declareProperty("numberOfRuns", m_evtRun);
}

/// Default destructor
Expand Down

0 comments on commit 816820a

Please sign in to comment.