#include "detector.hh" MySensitiveDetector::MySensitiveDetector(G4String name) : G4VSensitiveDetector(name), fHitsCollection(nullptr), fHitsCollectionID(-1) { collectionName.insert("MyDetectorHitsCollection"); } MySensitiveDetector::~MySensitiveDetector() {} void MySensitiveDetector::Initialize(G4HCofThisEvent* hce) { fHitsCollection = new MyHitsCollection("RadiatorSensitiveDetector", collectionName[0]); if (fHitsCollectionID < 0) { fHitsCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); } hce->AddHitsCollection(fHitsCollectionID, fHitsCollection); G4cout << "Sensitive Detector initialized. Hits Collection created with ID: " << fHitsCollectionID << G4endl; } G4bool MySensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) { G4cout << "ProcessHits called." << G4endl; G4double edep = aStep->GetTotalEnergyDeposit(); if(edep==0.) return false; MyHit* newHit = new MyHit(); newHit->SetWorldPos(aStep->GetPreStepPoint()->GetPosition()); newHit->SetEdep(edep); newHit->SetGlobalTime(aStep->GetPreStepPoint()->GetGlobalTime()); fHitsCollection->insert(newHit); G4Track *track = aStep->GetTrack(); track->SetTrackStatus(fStopAndKill); G4StepPoint *preStepPoint = aStep->GetPreStepPoint(); G4StepPoint *postStepPoint = aStep->GetPostStepPoint(); G4ThreeVector posPhoton = preStepPoint->GetPosition(); //G4cout << "Photon position: " << posPhoton << G4endl; const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable(); G4int copyNo = touchable->GetCopyNumber(); //G4cout << "Copy number: " << copyNo << G4endl; G4VPhysicalVolume *physVol = touchable->GetVolume(); G4ThreeVector posDetector = physVol->GetTranslation(); G4cout << "Detector position: " << posDetector << G4endl; G4int evt = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID(); G4AnalysisManager *man = G4AnalysisManager::Instance(); man->FillNtupleIColumn(0, evt); man->FillNtupleDColumn(1, posDetector[0]); man->FillNtupleDColumn(2, posDetector[1]); man->FillNtupleDColumn(3, posDetector[2]); man->AddNtupleRow(0); return true; } void MySensitiveDetector::EndOfEvent(G4HCofThisEvent* hce) { G4int nofHits = fHitsCollection->entries(); if (nofHits > 0){ G4cout << "\n------------------- EndOfEven in " << "RadiatorSensitiveDetector" << " ---------------" << G4endl; G4cout << " " << nofHits << " hits were recorded." << G4endl; G4cout << "------------------------------------------------" << G4endl;} }