File indexing completed on 2026-04-01 07:50:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "SAXSSensitiveDetector.hh"
0030
0031 #include "SAXSSensitiveDetectorHit.hh"
0032
0033 #include "G4HCofThisEvent.hh"
0034 #include "G4Navigator.hh"
0035 #include "G4SDManager.hh"
0036 #include "G4Step.hh"
0037 #include "G4TouchableHistory.hh"
0038 #include "G4Track.hh"
0039 #include "G4ios.hh"
0040
0041
0042
0043 SAXSSensitiveDetector::SAXSSensitiveDetector(G4String name) : G4VSensitiveDetector(name)
0044 {
0045 G4String HCname;
0046 collectionName.insert(HCname = "collection");
0047 fHCID = -1;
0048
0049 fVarStopAndKill = true;
0050
0051 fSDMessenger = new SAXSSensitiveDetectorMessenger(this);
0052 }
0053
0054
0055
0056 SAXSSensitiveDetector::~SAXSSensitiveDetector() {}
0057
0058
0059
0060 void SAXSSensitiveDetector::Initialize(G4HCofThisEvent* HCE)
0061 {
0062 fHitsCollection = new SensitiveDetectorHitsCollection(SensitiveDetectorName, collectionName[0]);
0063 if (fHCID < 0) fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
0064 HCE->AddHitsCollection(fHCID, fHitsCollection);
0065 }
0066
0067
0068
0069 bool SAXSSensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0070 {
0071 G4Track* vTrack = aStep->GetTrack();
0072
0073 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
0074
0075 G4ThreeVector worldPosition = preStepPoint->GetPosition();
0076 G4ThreeVector localPosition =
0077 preStepPoint->GetTouchableHandle()->GetHistory()->GetTopTransform().TransformPoint(
0078 worldPosition);
0079
0080 G4ThreeVector mom = preStepPoint->GetMomentumDirection();
0081
0082
0083 if (!(preStepPoint->GetStepStatus() == fGeomBoundary)) {
0084 return false;
0085 }
0086
0087 G4int vType = -1;
0088 if (preStepPoint->GetMass() == 0 && preStepPoint->GetCharge() == 0) {
0089 vType = 0;
0090 }
0091 else if (preStepPoint->GetMass() != 0 && preStepPoint->GetCharge() == 0) {
0092 vType = 1;
0093 }
0094 else if (preStepPoint->GetMass() != 0 && preStepPoint->GetCharge() > 0) {
0095 vType = 2;
0096 }
0097 else if (preStepPoint->GetMass() != 0 && preStepPoint->GetCharge() < 0) {
0098 vType = 3;
0099 }
0100
0101
0102 SAXSSensitiveDetectorHit* aHit = new SAXSSensitiveDetectorHit();
0103 aHit->SetPos(localPosition);
0104 aHit->SetMom(mom);
0105 aHit->SetType(vType);
0106 aHit->SetEnergy(preStepPoint->GetKineticEnergy());
0107 aHit->SetTime(preStepPoint->GetGlobalTime());
0108 aHit->SetTrackID(vTrack->GetTrackID());
0109 aHit->SetWeight(vTrack->GetWeight());
0110 fHitsCollection->insert(aHit);
0111
0112 if (fVarStopAndKill) {
0113 vTrack->SetTrackStatus(fStopAndKill);
0114 }
0115
0116 return true;
0117 }
0118
0119
0120 void SAXSSensitiveDetector::EndOfEvent(G4HCofThisEvent*) {}
0121
0122