#include "MyEventAction.hh" #include "MyHit.hh" #include "G4Event.hh" #include "G4RunManager.hh" #include "G4EventManager.hh" #include "G4HCofThisEvent.hh" #include "G4VHitsCollection.hh" #include "G4SDManager.hh" #include "G4SystemOfUnits.hh" #include "G4ios.hh" #include "G4AnalysisManager.hh" #include "globals.hh" //namespace //{ // Utility function which finds a hit collection with the given Id // and print warnings if not found G4VHitsCollection* GetHC(const G4Event* event, G4int collId) {auto hce = event->GetHCofThisEvent(); auto hc = hce->GetHC(collId);} /*{ auto hce = event->GetHCofThisEvent(); if (!hce) { G4ExceptionDescription msg; msg << "No hits collection of this event found." << G4endl; G4Exception("EventAction::EndOfEventAction()", "Code001", JustWarning, msg); return nullptr; } auto hc = hce->GetHC(collId); if ( ! hc) { G4ExceptionDescription msg; msg << "Hits collection " << collId << " of this event not found." << G4endl; G4Exception("EventAction::EndOfEventAction()", "Code001", JustWarning, msg); } return hc; }*/ //} //namespace SIM //{ EventAction::EventAction() { // set printing per each event G4RunManager::GetRunManager()->SetPrintProgress(1); } void EventAction::BeginOfEventAction(const G4Event*) { //auto analysisManager = G4AnalysisManager::Instance(); //auto sdManager = G4SDManager::GetSDMpointer(); // hits collections names //G4String cHCName = "Calorimeter/MyHitsCollection"; //sdManager->AddNewCollection(cHCName, "CalorimeterHitsCollection"); // hit collections IDs // fCalHCID = sdManager->GetCollectionID(cHCName); //if (fCalHCID < 0) { // G4cerr << "Error: Hits collection ID not found for " << cHCName << G4endl; } void EventAction::EndOfEventAction(const G4Event* event) { auto analysisManager = G4AnalysisManager::Instance(); //G4int totalCalHit = 0; //G4double totalCalEdep = 0.; //if (fCalHCID < 0) return; auto hc = GetHC(event, fCalHCID); if ( ! hc ) return; for (G4int i = 0; i < hc->GetSize(); i++) { auto hit = static_cast(hc->GetHit(i)); analysisManager->FillNtupleIColumn(0, hit->GetCellID()); analysisManager->FillNtupleDColumn(1, hit->GetTime()); analysisManager->FillNtupleDColumn(2, hit->GetEdep()); analysisManager->AddNtupleRow(); } } //}