LDMX Software
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 process (Event &event) final
 Processing an event for a Producer is calling produce.
 
- Public Member Functions inherited from framework::EventProcessor
 DECLARE_FACTORY (EventProcessor, EventProcessor *, const std::string &, Process &)
 declare that we have a factory for this class
 
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()=default
 Class destructor.
 
virtual void beforeNewRun (ldmx::RunHeader &run_header)
 Callback for Producers to add parameters to the run header before conditions are initialized.
 
virtual void onNewRun (const ldmx::RunHeader &run_header)
 Callback for the EventProcessor to take any necessary action when the run being processed changes.
 
virtual void onFileOpen (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &event_file)
 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

- 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 conditions_intf_
 Conditions interface.
 
G4UImanager * ui_manager_ {nullptr}
 User interface handle.
 
std::unique_ptr< RunManagerrun_manager_
 Manager controlling G4 simulation run.
 
std::unique_ptr< LoggedSessionsession_handle_
 Handle to the G4Session -> how to deal with G4cout and G4cerr.
 
framework::config::Parameters parameters_
 The parameters used to configure the simulation.
 
std::vector< std::string > pre_init_commands_
 
std::vector< std::string > post_init_commands_
 
- Protected Attributes inherited from framework::EventProcessor
HistogramPool histograms_
 helper object for making and filling histograms
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger the_log_
 The logger for this EventProcessor.
 
- Static Protected Attributes inherited from simcore::SimulatorBase
static const std::vector< std::string > INVALID_COMMANDS
 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} {}
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.

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);
7 resimulate_all_events_ = parameters.get<bool>("resimulate_all_events");
9 care_about_run_ = parameters.get<bool>("care_about_run");
10 auto configured_events{
11 parameters.get<std::vector<framework::config::Parameters>>(
12 "events_to_resimulate", {})};
13 if (configured_events.size() == 0) {
14 EXCEPTION_RAISE(
15 "ReSimNoEvents",
16 "ReSim was configured with resimulate_all_events marked false but "
17 "no event numbers were requested.\n\nDid you forget to configure "
18 "the events_to_resimulate parameter?\n");
19 }
20 for (const auto& run_event : configured_events) {
21 events_to_resimulate_.emplace_back(run_event.get<int>("run"),
22 run_event.get<int>("event"));
23 }
24 }
25}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
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::get(), 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 27 of file ReSimulator.cxx.

27 {
28 /* num_events_began_++; */
29 auto& event_header{event.getEventHeader()};
30 const auto event_number{event_header.getEventNumber()};
31 if (skip(event)) {
32 ldmx_log(trace) << "Skipping event: " << event_number
33 << " since it wasn't part of the requested events...";
34
35 this->abortEvent(); // get out of processors loop
36 return;
37 }
38
39 ldmx_log(trace) << "Resimulating " << event_number;
40
41 std::istringstream iss(event_header.getStringParameter("eventSeed"));
42 G4Random::restoreFullState(iss);
43 run_manager_->ProcessOneEvent(event_number);
44
45 ldmx_log(trace) << "Finished with event number " << event_number;
46
47 if (run_manager_->GetCurrentEvent()->IsAborted()) {
48 run_manager_->TerminateOneEvent();
49 SensitiveDetector::Factory::get().apply(
50 [](auto sd) { sd->onFinishedEvent(); });
51 EXCEPTION_RAISE(
52 "ReSimAbortedEvent",
53 "Resimulation resulted in an aborted event, something is wrong with "
54 "the seed from event " +
55 std::to_string(event_number));
56 }
57
58 event_header.setEventNumber(++events_resimulated_);
59 updateEventHeader(event_header);
60 saveTracks(event);
61
62 saveSDHits(event);
63
64 run_manager_->TerminateOneEvent();
65}
void abortEvent()
Abort the event immediately.
bool skip(framework::Event &event) const
Check if an event should be skipped during resimulation.
std::unique_ptr< RunManager > run_manager_
Manager controlling G4 simulation run.

References framework::EventProcessor::abortEvent(), simcore::SimulatorBase::run_manager_, and skip().

◆ 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 67 of file ReSimulator.cxx.

67 {
72 if (resimulate_all_events_) return false;
79 auto found_event_to_resim = std::find_if(
80 std::begin(events_to_resimulate_), std::end(events_to_resimulate_),
81 [&](const std::pair<int, int>& run_event) -> bool {
82 bool runs_match = true;
84 runs_match = (event.getEventHeader().getRun() == run_event.first);
85 return event.getEventNumber() == run_event.second and runs_match;
86 });
87 return (found_event_to_resim == std::end(events_to_resimulate_));
88}

References care_about_run_, events_to_resimulate_, 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: