LDMX Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
simcore::ReSimulator Class Reference

Public Member Functions

 ReSimulator (const std::string &name, framework::Process &process)
 
void configure (framework::config::Parameters &parameters) override
 Callback for the processor to configure itself from the given set of parameters.
 
void produce (framework::Event &event) override
 Run resimulation if the event is part of the requested sets of events to resimulate.
 
- Public Member Functions inherited from simcore::SimulatorBase
 SimulatorBase (const std::string &name, framework::Process &process)
 
void configure (framework::config::Parameters &parameters) override
 Callback for the EventProcessor to configure itself from the given set of parameters.
 
- Public Member Functions inherited from framework::Producer
 Producer (const std::string &name, Process &process)
 Class constructor.
 
virtual void beforeNewRun (ldmx::RunHeader &header)
 Handle allowing producers to modify run headers before the run begins.
 
- Public Member Functions inherited from framework::EventProcessor
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()
 Class destructor.
 
virtual void onNewRun (const ldmx::RunHeader &runHeader)
 Callback for the EventProcessor to take any necessary action when the run being processed changes.
 
virtual void onFileOpen (EventFile &eventFile)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &eventFile)
 Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
 
template<class T >
const T & getCondition (const std::string &condition_name)
 Access a conditions object for the current event.
 
TDirectory * getHistoDirectory ()
 Access/create a directory in the histogram file for this event processor to create histograms and analysis tuples.
 
void setStorageHint (framework::StorageControl::Hint hint)
 Mark the current event as having the given storage control hint from this module.
 
void setStorageHint (framework::StorageControl::Hint hint, const std::string &purposeString)
 Mark the current event as having the given storage control hint from this module and the given purpose string.
 
int getLogFrequency () const
 Get the current logging frequency from the process.
 
int getRunNumber () const
 Get the run number from the process.
 
std::string getName () const
 Get the processor name.
 
void createHistograms (const std::vector< framework::config::Parameters > &histos)
 Internal function which is used to create histograms passed from the python configuration @parma histos vector of Parameters that configure histograms to create.
 

Private Member Functions

bool skip (framework::Event &event) const
 Check if an event should be skipped during resimulation.
 

Private Attributes

std::vector< std::pair< int, int > > events_to_resimulate_
 List of events in the input files that should be resimulated if resimulate_all_events is false.
 
bool resimulate_all_events_
 Whether to resimulate all events in the input files.
 
bool care_about_run_
 Whether or not we should check the run number when seeing if a specific event should be resimulated.
 
int events_resimulated_ = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from framework::EventProcessor
static void declare (const std::string &classname, int classtype, EventProcessorMaker *)
 Internal function which is part of the PluginFactory machinery.
 
- Static Public Attributes inherited from framework::Producer
static const int CLASSTYPE {1}
 Constant used to track EventProcessor types by the PluginFactory.
 
- Protected Member Functions inherited from simcore::SimulatorBase
void onProcessEnd () override
 Callback called once processing is complete.
 
void onProcessStart () override
 Initialization of simulation.
 
virtual void updateEventHeader (ldmx::EventHeader &eventHeader) const
 
virtual void saveTracks (framework::Event &event)
 
virtual void saveSDHits (framework::Event &event)
 
- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from simcore::SimulatorBase
ConditionsInterface conditionsIntf_
 Conditions interface.
 
G4UImanager * uiManager_ {nullptr}
 User interface handle.
 
std::unique_ptr< RunManagerrunManager_
 Manager controlling G4 simulation run.
 
std::unique_ptr< G4UIsession > sessionHandle_
 Handle to the G4Session -> how to deal with G4cout and G4cerr.
 
int verbosity_ {1}
 Vebosity for the simulation.
 
framework::config::Parameters parameters_
 The parameters used to configure the simulation.
 
std::vector< std::string > preInitCommands_
 
std::vector< std::string > postInitCommands_
 
- Protected Attributes inherited from framework::EventProcessor
HistogramHelper histograms_
 Interface class for making and filling histograms.
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger theLog_
 The logger for this EventProcessor.
 
- Static Protected Attributes inherited from simcore::SimulatorBase
static const std::vector< std::string > invalidCommands_
 Commands not allowed to be passed from python config file This is because Simulator already runs them.
 

Detailed Description

Definition at line 9 of file ReSimulator.h.

Constructor & Destructor Documentation

◆ ReSimulator()

simcore::ReSimulator::ReSimulator ( const std::string &  name,
framework::Process process 
)
inline

Definition at line 11 of file ReSimulator.h.

12 : SimulatorBase{name, process} {}

Member Function Documentation

◆ configure()

void simcore::ReSimulator::configure ( framework::config::Parameters parameters)
overridevirtual

Callback for the processor to configure itself from the given set of parameters.

Parameters
parametersParameterSet for configuration.

Reimplemented from framework::EventProcessor.

Definition at line 5 of file ReSimulator.cxx.

5 {
6 SimulatorBase::configure(parameters);
8 parameters.getParameter<bool>("resimulate_all_events");
10 care_about_run_ = parameters.getParameter<bool>("care_about_run");
11 auto configured_events{
12 parameters.getParameter<std::vector<framework::config::Parameters>>(
13 "events_to_resimulate", {})};
14 if (configured_events.size() == 0) {
15 EXCEPTION_RAISE(
16 "ReSimNoEvents",
17 "ReSim was configured with resimulate_all_events marked false but "
18 "no event numbers were requested.\n\nDid you forget to configure "
19 "the events_to_resimulate parameter?\n");
20 }
21 for (const auto& run_event : configured_events) {
22 events_to_resimulate_.emplace_back(run_event.getParameter<int>("run"),
23 run_event.getParameter<int>("event"));
24 }
25 }
26}
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
std::vector< std::pair< int, int > > events_to_resimulate_
List of events in the input files that should be resimulated if resimulate_all_events is false.
Definition ReSimulator.h:45
bool care_about_run_
Whether or not we should check the run number when seeing if a specific event should be resimulated.
Definition ReSimulator.h:56
bool resimulate_all_events_
Whether to resimulate all events in the input files.
Definition ReSimulator.h:50
void configure(framework::config::Parameters &parameters) override
Callback for the EventProcessor to configure itself from the given set of parameters.

References care_about_run_, simcore::SimulatorBase::configure(), events_to_resimulate_, framework::config::Parameters::getParameter(), and resimulate_all_events_.

◆ produce()

void simcore::ReSimulator::produce ( framework::Event event)
overridevirtual

Run resimulation if the event is part of the requested sets of events to resimulate.

Parameters
eventThe event to process.

Implements simcore::SimulatorBase.

Definition at line 28 of file ReSimulator.cxx.

28 {
29 /* numEventsBegan_++; */
30 auto& eventHeader{event.getEventHeader()};
31 const auto eventNumber{eventHeader.getEventNumber()};
32 if (skip(event)) {
33 if (verbosity_ > 1) {
34 std::cout << "Skipping event: " << eventNumber
35 << " since it wasn't part of the requested events..."
36 << std::endl;
37 }
38 this->abortEvent(); // get out of processors loop
39 return;
40 }
41 if (verbosity_ > 0) {
42 std::cout << "Resimulating " << eventNumber << std::endl;
43 }
44
45 std::istringstream iss(eventHeader.getStringParameter("eventSeed"));
46 G4Random::restoreFullState(iss);
47 runManager_->ProcessOneEvent(eventNumber);
48 if (verbosity_ > 1) {
49 std::cout << "Finished with event number " << eventNumber << std::endl;
50 }
51 if (runManager_->GetCurrentEvent()->IsAborted()) {
52 runManager_->TerminateOneEvent();
54 [](auto sd) { sd->OnFinishedEvent(); });
55 EXCEPTION_RAISE(
56 "ReSimAbortedEvent",
57 "Resimulation resulted in an aborted event, something is wrong with "
58 "the seed from event " +
59 std::to_string(eventNumber));
60 }
61
62 eventHeader.setEventNumber(++events_resimulated_);
63 updateEventHeader(eventHeader);
64 saveTracks(event);
65
66 saveSDHits(event);
67
68 runManager_->TerminateOneEvent();
69}
void abortEvent()
Abort the event immediately.
void apply(UnaryFunction f) const
Apply the input UnaryFunction to each entry in the inventory.
Definition Factory.h:283
static Factory & get()
get the factory instance
Definition Factory.h:217
bool skip(framework::Event &event) const
Check if an event should be skipped during resimulation.
std::unique_ptr< RunManager > runManager_
Manager controlling G4 simulation run.
int verbosity_
Vebosity for the simulation.

References framework::EventProcessor::abortEvent(), simcore::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs >::apply(), simcore::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs >::get(), simcore::SimulatorBase::runManager_, skip(), and simcore::SimulatorBase::verbosity_.

◆ skip()

bool simcore::ReSimulator::skip ( framework::Event event) const
private

Check if an event should be skipped during resimulation.

Parameters
[in]eventhandle to the current event being processed

If we are configured to simply resimulate all events, this function always returns false.

Otherwise, we check the event number (and also its run number if we care_about_run_) against the list of run/event pairs that we are interested in re-simulating.

Definition at line 71 of file ReSimulator.cxx.

71 {
76 if (resimulate_all_events_) return false;
83 auto found_event_to_resim = std::find_if(
84 std::begin(events_to_resimulate_), std::end(events_to_resimulate_),
85 [&](const std::pair<int, int>& run_event) -> bool {
86 bool runs_match = true;
88 runs_match = (event.getEventHeader().getRun() == run_event.first);
89 return event.getEventNumber() == run_event.second and runs_match;
90 });
91 return (found_event_to_resim == std::end(events_to_resimulate_));
92}
ldmx::EventHeader & getEventHeader()
Get the event header.
Definition Event.h:58
int getRun() const
Return the run number.
Definition EventHeader.h:84

References care_about_run_, events_to_resimulate_, framework::Event::getEventHeader(), ldmx::EventHeader::getRun(), and resimulate_all_events_.

Referenced by produce().

Member Data Documentation

◆ care_about_run_

bool simcore::ReSimulator::care_about_run_
private

Whether or not we should check the run number when seeing if a specific event should be resimulated.

Definition at line 56 of file ReSimulator.h.

Referenced by configure(), and skip().

◆ events_resimulated_

int simcore::ReSimulator::events_resimulated_ = 0
private

Definition at line 63 of file ReSimulator.h.

◆ events_to_resimulate_

std::vector<std::pair<int, int> > simcore::ReSimulator::events_to_resimulate_
private

List of events in the input files that should be resimulated if resimulate_all_events is false.

Each event is identified uniquely by its run number and event number.

Note
: If an event in events_to_resimulate_ is not part of the input file, it will be ignored.

Definition at line 45 of file ReSimulator.h.

Referenced by configure(), and skip().

◆ resimulate_all_events_

bool simcore::ReSimulator::resimulate_all_events_
private

Whether to resimulate all events in the input files.

Definition at line 50 of file ReSimulator.h.

Referenced by configure(), and skip().


The documentation for this class was generated from the following files: