#include "mySD.hh" #include "G4Step.hh" #include "G4StepStatus.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) { G4StepPoint* pre = aStep->GetPreStepPoint();G4StepPoint* pro = aStep->GetPostStepPoint(); G4Track* track = aStep->GetTrack(); G4ParticleDefinition* par=track->GetDefinition(); G4String nom=aStep->GetPreStepPoint()->GetTouchable()->GetVolume()->GetName(); G4String numt = track->GetParticleDefinition()->GetParticleName(); if(pre->GetStepStatus() == fGeomBoundary && pro->GetStepStatus() == fGeomBoundary) { auto newHit = new myHit(); G4double edep = aStep->GetTotalEnergyDeposit();if (edep==0.) return false; newHit->SetEdep(edep); G4ThreeVector pos=aStep->GetPreStepPoint()->GetPosition(); newHit->SetPos(pos); newHit->SetPart(par); fHitsCollection->insert( newHit );} auto man = G4RootAnalysisManager::Instance(); man->FillNtupleDColumn(0,edep); man->FillNtupleDColumn(1,pos[0]); man->FillNtupleDColumn(2,pos[1]); man->FillNtupleDColumn(3,pos[2]); 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(); }