Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:51:43

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //---------------------------------------------------------------------------
0026 //
0027 // ClassName:   MicroElecSdSey
0028 //
0029 // Description: The process to kill e- to save CPU
0030 //
0031 // Author:      C. Inguimbert 16/02/2022
0032 //              ONERA
0033 //----------------------------------------------------------------------------
0034 //
0035 // Class description:
0036 //
0037 // SEY : Secondary Electron Emission Yield
0038 // detecteor to be used to count the number of secondary electrons
0039 // emitted by a surface of irradiated material
0040 //
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0044 
0045 
0046 #include    <iostream>
0047 #include    <fstream>
0048 #include    <sstream>
0049 
0050 
0051 #include "G4RunManager.hh"
0052 
0053 //#include "DepthSampling.hh"
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 //#include "Analysis.hh"
0078 
0079 
0080 
0081 using namespace std;
0082 
0083 #include    <vector>
0084 
0085 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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     //G4String HCname;
0094     //collectionName.insert(HCname = "DetecteurMicroElecSdSey");
0095     G4String HCname = hitsCollectionName;
0096     collectionName.insert(HCname);
0097 }
0098 
0099 MicroElecSdSey::~MicroElecSdSey() { }
0100 
0101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0102 //Called at beginning of event
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0123 //called for each step in sensitive volume
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0218 //called at end of event
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