A question about Hit and SensitiveDetector usage

Hi everyone,
a) I have a question about Hit and Sensitive Detector works. Can anyone help me to explain how they work?

b) I want to score the deposited dose in volumes. I found that Geant4 Basic Examples (B2, B4c ) used the ProcessHits method to process deposited energy in volumes. Then using EventAction to get deposited energy for each event and sum total energy in RunAction class using G4AccumulablesManager::Merge() or Run::Merge() method.

But I also found an example in Github, they wrote results to file using the EndOfEvent method of PhantomSD class. I don’t know if that will be the result of a run (including events)? And if using multi-threading when calculating, will the results be merged together?

void PhantomSD::EndOfEvent(G4HCofThisEvent*)
G4RunManager* runManager = G4RunManager::GetRunManager();
G4int event_numbers= runManager->GetCurrentRun()->GetNumberOfEventToBeProcessed() ;
const G4Event * event = runManager->GetCurrentEvent();
G4int event_id= event->GetEventID();
static int n=1;

if((event_id==10000*n) or (event_id==event_numbers-1) )


Thank you in advance.