Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDSim: correct the number of events when running over all events (-1) #1258

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DDG4/python/DDG4.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ def _get(self, name):
a = Interface.toAction(self)
ret = Interface.getProperty(a, name)
if ret.status > 0:
return ret.data
return _evalProperty(ret.data)
elif hasattr(self.action, name):
return getattr(self.action, name)
return _evalProperty(getattr(self.action, name))
elif hasattr(a, name):
return getattr(a, name)
return _evalProperty(getattr(a, name))
msg = 'Geant4Action::GetProperty [Unhandled]: Cannot access property ' + a.name() + '.' + name
raise KeyError(msg)

Expand Down
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.debug(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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarkusFrankATcernch
Is this the best way to let me read the number of events from the plugin, or is there something else that would be cleaner?

declareProperty("numberOfRuns", m_evtRun);
}

/// Default destructor
Expand Down
Loading