#include "mySD.hh" #include "G4Step.hh" #include "G4Track.hh" #include "myHit.hh" #include "G4HCofThisEvent.hh" #include "G4Step.hh" #include "G4ThreeVector.hh" #include "G4SDManager.hh" #include "G4ios.hh" #include "G4RootAnalysisManager.hh" #include "DetectorConstruction.hh" #include "G4LogicalVolume.hh" #include "G4RunManager.hh" #include "DetectorConstruction.hh" class G4Step; class G4HCofThisEvent; mySD::mySD(const G4String& name, const G4String& hitsCollectionName):G4VSensitiveDetector(name),collectionID(-1) { collectionName.insert(hitsCollectionName);} mySD::~mySD() {} void mySD::Initialize(G4HCofThisEvent *HCE) { if(collectionID<0) collectionID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); fHitsCollection = new myHitCollection(GetName(),collectionName[0]); HCE->AddHitsCollection(collectionID,fHitsCollection); } G4bool mySD::ProcessHits(G4Step* aStep,G4TouchableHistory* ROhist) { const auto detConstruction = static_cast( G4RunManager::GetRunManager()->GetUserDetectorConstruction()); G4double mass = detConstruction->GetScoringVolume()->GetMass(); G4double edep = aStep->GetTotalEnergyDeposit(); G4double dose=edep/mass; G4ThreeVector pos=aStep->GetPreStepPoint()->GetPosition(); if (edep==0.) return false; auto newHit = new myHit();//page 254 gean4 all newHit->SetEdep(edep); newHit->SetTrackID(aStep->GetTrack()->GetTrackID()); newHit->SetPos(pos); fHitsCollection->insert( newHit ); //newHit->Print(); auto man = G4RootAnalysisManager::Instance(); man->FillNtupleDColumn(0,edep); man->FillNtupleDColumn(1,pos[0]); man->FillNtupleDColumn(2,pos[1]); man->FillNtupleDColumn(3,pos[2]); man->FillNtupleDColumn(4,dose); man->AddNtupleRow(0); return true; } void mySD::EndOfEvent(G4HCofThisEvent*) { if ( verboseLevel>1 ) { G4int nofHits = fHitsCollection->entries(); G4cout << G4endl << "-------->Hits Collection: in this event they are " << nofHits << " hits in the tracker chambers: " << G4endl; for ( G4int i=0; iPrint(); } fHitsCollection->PrintAllHits(); }