File indexing completed on 2025-01-31 09:21:47
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
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 #include "G4HCofThisEvent.hh"
0044 #include "G4Step.hh"
0045 #include "G4ThreeVector.hh"
0046 #include "G4SDManager.hh"
0047 #include "G4ios.hh"
0048 #include "G4SystemOfUnits.hh"
0049
0050 #include "InteractionSD.hh"
0051 #include "ParticleChange.hh"
0052
0053 InteractionSD::InteractionSD(G4String name)
0054 : G4VSensitiveDetector(name)
0055 {
0056 G4String HCname = name + "_HC";
0057 collectionName.insert(HCname);
0058 G4cout << collectionName.size() << " InteractionSD name: " << name
0059 << " collection Name: " << HCname << G4endl;
0060 fHCID = -1;
0061 }
0062
0063 InteractionSD::~InteractionSD()
0064 {
0065 delete fFirstInter;
0066 delete fOtherInter;
0067 }
0068
0069 void InteractionSD::Initialize(G4HCofThisEvent* HCE)
0070 {
0071 G4cout << "Hits Collection capacity: " << HCE->GetCapacity() << G4endl;
0072 fInteractionHitsCollection =
0073 new InteractionHitsCollection(SensitiveDetectorName, collectionName[0]);
0074 if(fHCID < 0)
0075 {
0076 G4cout << "InteractionSD::Initialize: " << SensitiveDetectorName << " "
0077 << collectionName[0] << G4endl;
0078 fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0079 }
0080 HCE->AddHitsCollection(fHCID, fInteractionHitsCollection);
0081 fFirstInter = new ParticleChange(true);
0082 fOtherInter = new ParticleChange();
0083 }
0084
0085 G4bool InteractionSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0086 {
0087 G4int nsc = fFirstInter->GetNumberOfSecondaries();
0088 if(nsc > 0)
0089 {
0090 for(G4int i = 0; i < nsc; i++)
0091 {
0092 delete fFirstInter->GetSecondary(i);
0093 }
0094 fFirstInter->Clear();
0095 }
0096 nsc = fOtherInter->GetNumberOfSecondaries();
0097 if(nsc > 0)
0098 {
0099 for(G4int i = 0; i < nsc; i++)
0100 {
0101 delete fOtherInter->GetSecondary(i);
0102 }
0103 fOtherInter->Clear();
0104 }
0105 const std::vector<const G4Track*>* secs = aStep->GetSecondaryInCurrentStep();
0106 G4int nsec = secs->size();
0107 for(G4int i = 0; i < nsec; i++)
0108 {
0109 G4Track* tr = new G4Track(*((*secs)[i]));
0110 if(aStep->GetTrack()->GetTrackStatus() != fAlive)
0111 {
0112 if(aStep->GetTrack()->GetParentID() == 0)
0113 {
0114 fFirstInter->AddSecondary(tr);
0115 }
0116 else
0117 {
0118 fOtherInter->AddSecondary(tr);
0119 }
0120 }
0121 }
0122 G4int NSec = fFirstInter->GetNumberOfSecondaries();
0123 if(NSec > 0)
0124 {
0125 const G4DynamicParticle* sec = 0;
0126 for(G4int i = 0; i < NSec; i++)
0127 {
0128 sec = fFirstInter->GetSecondary(i)->GetDynamicParticle();
0129 const G4String& pname = sec->GetDefinition()->GetParticleName();
0130 G4double pmom = (sec->GetTotalMomentum()) / GeV;
0131 G4double Ekin = (sec->GetKineticEnergy()) / GeV;
0132 G4double theta = (sec->GetMomentum()).theta();
0133 InteractionHit* newHit = new InteractionHit(pname, pmom, Ekin, theta);
0134 fInteractionHitsCollection->insert(newHit);
0135 }
0136 }
0137 return true;
0138 }