/// \file B2EventAction.cc /// \brief Implementation of the B2EventAction class #include "B2EventAction.hh" #include "G4Event.hh" #include "G4EventManager.hh" #include "G4TrajectoryContainer.hh" #include "G4Trajectory.hh" #include "G4ios.hh"

This section includes necessary Geant4 headers and the header for this class.

Constructor and Destructor

B2EventAction::B2EventAction() : G4UserEventAction() {} B2EventAction::~B2EventAction() {}

The constructor initializes the class, inheriting fromĀ G4UserEventAction. The destructor is empty.

Begin of Event Action

void B2EventAction::BeginOfEventAction(const G4Event*) {}

This method is called at the beginning of each event but is currently empty, meaning no specific actions are taken at the start of an event.

End of Event Action

void B2EventAction::EndOfEventAction(const G4Event* event)

This method is called at the end of each event and contains the main functionality: a. Retrieve the number of trajectories:

G4TrajectoryContainer* trajectoryContainer = event->GetTrajectoryContainer(); G4int n_trajectories = 0; if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();

b. Periodic printing of event information:

G4int eventID = event->GetEventID(); if ( eventID < 100 || eventID % 100 == 0) { // Print event ID G4cout << ">>> Event: " << eventID << G4endl; // Print number of trajectories if available if ( trajectoryContainer ) { G4cout << " " << n_trajectories << " trajectories stored in this event." << G4endl; } // Print number of hits G4VHitsCollection* hc = event->GetHCofThisEvent()->GetHC(0); G4cout << " "
<< hc->GetSize() << " hits stored in this event" << G4endl; }

This code prints information for the first 100 events and then every 100th event thereafter. It outputs:

This class is crucial for monitoring and potentially processing each event in the Geant4 simulation, allowing for event-by-event analysis or data collection.