File indexing completed on 2026-04-17 07:51:43
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
0044
0045
0046 #include <iostream>
0047 #include <fstream>
0048 #include <sstream>
0049
0050
0051 #include "G4RunManager.hh"
0052
0053
0054
0055 #include "SteppingAction.hh"
0056 #include "MicroElecSdSey.hh"
0057 #include "MicroElecRun.hh"
0058 #include "G4StepPoint.hh"
0059 #include "G4HCofThisEvent.hh"
0060 #include "G4Step.hh"
0061 #include "G4ThreeVector.hh"
0062 #include "G4SDManager.hh"
0063 #include "G4ios.hh"
0064 #include "G4VProcess.hh"
0065 #include "G4EmCalculator.hh"
0066 #include "G4Material.hh"
0067 #include "G4UnitsTable.hh"
0068 #include "G4EnergyLossTables.hh"
0069 #include "G4VPhysicalVolume.hh"
0070 #include "PrimaryGeneratorAction.hh"
0071 #include "G4RunManager.hh"
0072 #include "DetectorConstruction.hh"
0073 #include "G4ParticleDefinition.hh"
0074 #include "G4SystemOfUnits.hh"
0075 #include "G4VHit.hh"
0076 #include "G4AttDef.hh"
0077
0078
0079
0080
0081 using namespace std;
0082
0083 #include <vector>
0084
0085
0086 MicroElecSdSey::MicroElecSdSey(const G4String& name,
0087 const G4String& hitsCollectionName)
0088 : G4VSensitiveDetector(name), fHitsCollection(NULL)
0089 {
0090 compteurPrimaire = 0.0, compteurSec= 0.0, compteurTot= 0.0, compteur50= 0.0, nbPrim= 0.0, nbSec= 0.0 , nbSup50= 0.0;
0091 ResetCounters();
0092
0093
0094
0095 G4String HCname = hitsCollectionName;
0096 collectionName.insert(HCname);
0097 }
0098
0099 MicroElecSdSey::~MicroElecSdSey() { }
0100
0101
0102
0103 void MicroElecSdSey::Initialize(G4HCofThisEvent* HCE)
0104 {
0105
0106 static G4int HCID = -1;
0107
0108 if (HCID < 0)
0109 {
0110 HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0111 }
0112
0113 fHitsCollection = new MicroElecHitSeyCollection();
0114
0115 HCE->AddHitsCollection(HCID, fHitsCollection);
0116
0117
0118 nbPrim = 0; nbSec = 0; nbSup50 = 0;
0119
0120 }
0121
0122
0123
0124 G4bool MicroElecSdSey::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0125 {
0126 G4Track* aTrack = aStep->GetTrack();
0127 G4int trackID = aStep->GetTrack()->GetTrackID();
0128 G4int ParentID = aStep->GetTrack()->GetParentID();
0129
0130
0131 G4String processName;
0132 const G4VProcess* creatorProcess = aStep->GetTrack()->GetCreatorProcess();
0133 if (creatorProcess) { processName = creatorProcess->GetProcessName(); }
0134 if (aStep->GetPostStepPoint()) { G4String processNamePSP = aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName(); }
0135
0136
0137 const G4DynamicParticle* particleDyn = aStep->GetTrack()->GetDynamicParticle();
0138 G4ParticleDefinition* particleDef = particleDyn->GetDefinition();
0139 G4int PDGEncoding = particleDef->GetPDGEncoding();
0140 G4String ParticleTypeName = particleDef->GetParticleType();
0141 G4String ParticleName = particleDef->GetParticleName();
0142
0143 G4int Z = particleDef->GetAtomicNumber();
0144 G4int A = particleDef->GetAtomicMass();
0145 G4double Vertex_kinetic_energy = aStep->GetTrack()->GetVertexKineticEnergy();
0146 G4ThreeVector Vertex_Position = aStep->GetTrack()->GetVertexPosition();
0147 G4ThreeVector Vertex_Moment = aStep->GetTrack()->GetVertexMomentumDirection();
0148
0149 G4double Particle_kinetic_energy=999.;
0150 G4double Post_kinetic_energy=999.;
0151 G4ThreeVector PreImpulsion;
0152 G4ThreeVector PostImpulsion;
0153 G4ThreeVector PrePosition;
0154 G4ThreeVector PostPosition;
0155
0156 if (aStep->GetPreStepPoint()) {
0157 Particle_kinetic_energy = aStep->GetPreStepPoint()->GetKineticEnergy();
0158 PreImpulsion = aStep->GetPreStepPoint()->GetMomentumDirection();
0159 PrePosition = aStep->GetPreStepPoint()->GetPosition();
0160 }
0161 if (aStep->GetPostStepPoint()) {
0162 Post_kinetic_energy = aStep->GetPostStepPoint()->GetKineticEnergy();
0163 PostImpulsion = aStep->GetPostStepPoint()->GetMomentumDirection();
0164 PostPosition = aStep->GetPostStepPoint()->GetPosition();
0165 }
0166
0167
0168 G4double edep = aStep->GetTotalEnergyDeposit();
0169 G4double NIedep = aStep->GetNonIonizingEnergyDeposit();
0170 G4double stepLength = aStep->GetStepLength();
0171
0172 G4String originalVolume_;
0173 G4String originalVolume_materialName;
0174 originalVolume_ = aStep->GetTrack()->GetTouchableHandle()->GetVolume()->GetName();
0175 originalVolume_materialName = aStep->GetTrack()->GetMaterial()->GetName();
0176
0177
0178 if (ParentID == 0) {nbPrim++;}
0179 if (ParentID > 0) {nbSec++;}
0180 if (Particle_kinetic_energy/eV >= 50.0) { nbSup50++; }
0181
0182
0183
0184 MicroElecHitSey* newHit = new MicroElecHitSey();
0185
0186 newHit->SetNbPrim(nbPrim);
0187 newHit->SetNbSec(nbSec);
0188 newHit->SetNbSup50(nbSup50);
0189 newHit->SetPDGEncoding(PDGEncoding);
0190 newHit->SetParentID(ParentID);
0191 newHit->SetTrackID(trackID);
0192 newHit->SetParticleType(ParticleTypeName);
0193 newHit->SetParticleName(ParticleName);
0194 newHit->SetVolumeName(originalVolume_);
0195 newHit->SetZ(Z);
0196 newHit->SetA(A);
0197 newHit->SetVertexKineticEnergy(Vertex_kinetic_energy);
0198 newHit->SetVertexPos(Vertex_Position);
0199 newHit->SetVertexMomentum(Vertex_Moment);
0200 newHit->SetPreStepKineticEnergy(Particle_kinetic_energy);
0201 newHit->SetPostStepKineticEnergy(Post_kinetic_energy);
0202 newHit->SetEdep(edep);
0203 newHit->SetNi_Edep(NIedep);
0204 newHit->SetStepLength(stepLength);
0205 newHit->SetPreStepMomentum(PreImpulsion);
0206 newHit->SetPostStepMomentum(PostImpulsion);
0207 newHit->SetPrePos(PrePosition);
0208 newHit->SetPostPos(PostPosition);
0209
0210 fHitsCollection->insert(newHit);
0211 aTrack->SetTrackStatus(fStopAndKill);
0212
0213 return true;
0214
0215 }
0216
0217
0218
0219 void MicroElecSdSey::EndOfEvent(G4HCofThisEvent*)
0220 {
0221
0222 MicroElecRun* run = static_cast<MicroElecRun*>(
0223 G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0224
0225 std::stringstream ss;
0226 ss << 1 + run->GetRunID() << G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID();
0227
0228 compteurPrimaire = compteurPrimaire + nbPrim;
0229 compteurSec = compteurSec + nbSec;
0230 compteur50 = compteur50 + nbSup50;
0231 compteurTot = compteurTot+ nbPrim+ nbSec;
0232
0233 run->AddElecPrimScorer(nbPrim);
0234 run->AddElecSecoScorer(nbSec);
0235 run->AddElecSup50Scorer(nbSup50);
0236 run->AddElecTotaScorer(nbPrim+ nbSec);
0237
0238
0239 nbPrim = 0.0;
0240 nbSec = 0.0;
0241 nbSup50 = 0.0;
0242
0243
0244 }
0245
0246
0247
0248