Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-13 07:54:41

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 /// \file TrackingAction.cc
0027 /// \brief Implementation of the TrackingAction class
0028 
0029 #include "TrackingAction.hh"
0030 
0031 #include "EventAction.hh"
0032 #include "HistoManager.hh"
0033 #include "Run.hh"
0034 #include "TrackingMessenger.hh"
0035 
0036 #include "G4ParticleTypes.hh"
0037 #include "G4RunManager.hh"
0038 #include "G4StepStatus.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4Track.hh"
0041 #include "G4UnitsTable.hh"
0042 
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0044 
0045 TrackingAction::TrackingAction(EventAction* event) : fEventAction(event)
0046 {
0047   fTrackMessenger = new TrackingMessenger(this);
0048 }
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 
0052 TrackingAction::~TrackingAction()
0053 {
0054   delete fTrackMessenger;
0055 }
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0058 
0059 void TrackingAction::PreUserTrackingAction(const G4Track* track)
0060 {
0061   // count secondary particles
0062   if (track->GetTrackID() == 1) return;
0063 
0064   Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0065 
0066   const G4ParticleDefinition* particle = track->GetParticleDefinition();
0067   G4String name = particle->GetParticleName();
0068   G4double meanLife = particle->GetPDGLifeTime();
0069   G4double energy = track->GetKineticEnergy();
0070   if (fParticleCount) run->ParticleCount(name, energy, meanLife);
0071 
0072   // histograms: energy at creation
0073   //
0074   G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0075 
0076   G4int ih = 0;
0077   G4String type = particle->GetParticleType();
0078   G4double charge = particle->GetPDGCharge();
0079   if (charge > 3.)
0080     ih = 10;
0081   else if (particle == G4Gamma::Gamma())
0082     ih = 4;
0083   else if (particle == G4Electron::Electron())
0084     ih = 5;
0085   else if (particle == G4Positron::Positron())
0086     ih = 5;
0087   else if (particle == G4Neutron::Neutron())
0088     ih = 6;
0089   else if (particle == G4Proton::Proton())
0090     ih = 7;
0091   else if (particle == G4Deuteron::Deuteron())
0092     ih = 8;
0093   else if (particle == G4Alpha::Alpha())
0094     ih = 9;
0095   else if (type == "nucleus")
0096     ih = 10;
0097   else if (type == "baryon")
0098     ih = 11;
0099   else if (type == "meson")
0100     ih = 12;
0101   else if (type == "lepton")
0102     ih = 13;
0103   if (ih > 0) analysis->FillH1(ih, energy);
0104 
0105   // to force only 1 fission : kill secondary neutrons
0106   if (fKillNeutron && (particle == G4Neutron::Neutron())) {
0107     fEventAction->AddEdep(energy);
0108     G4Track* aTrack = (G4Track*)track;
0109     aTrack->SetTrackStatus(fStopAndKill);
0110   }
0111 }
0112 
0113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0114 
0115 void TrackingAction::PostUserTrackingAction(const G4Track* track)
0116 {
0117   // keep only emerging particles
0118   G4StepStatus status = track->GetStep()->GetPostStepPoint()->GetStepStatus();
0119   if (status != fWorldBoundary) return;
0120 
0121   const G4ParticleDefinition* particle = track->GetParticleDefinition();
0122   G4String name = particle->GetParticleName();
0123   G4double energy = track->GetKineticEnergy();
0124 
0125   fEventAction->AddEflow(energy);
0126 
0127   Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0128   run->ParticleFlux(name, energy);
0129 
0130   // histograms: energy at exit
0131   //
0132   G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0133 
0134   G4int ih = 0;
0135   G4String type = particle->GetParticleType();
0136   G4double charge = particle->GetPDGCharge();
0137   if (charge > 3.)
0138     ih = 20;
0139   else if (particle == G4Gamma::Gamma())
0140     ih = 14;
0141   else if (particle == G4Electron::Electron())
0142     ih = 15;
0143   else if (particle == G4Positron::Positron())
0144     ih = 15;
0145   else if (particle == G4Neutron::Neutron())
0146     ih = 16;
0147   else if (particle == G4Proton::Proton())
0148     ih = 17;
0149   else if (particle == G4Deuteron::Deuteron())
0150     ih = 18;
0151   else if (particle == G4Alpha::Alpha())
0152     ih = 19;
0153   else if (type == "nucleus")
0154     ih = 20;
0155   else if (type == "baryon")
0156     ih = 21;
0157   else if (type == "meson")
0158     ih = 22;
0159   else if (type == "lepton")
0160     ih = 23;
0161   if (ih > 0) analysis->FillH1(ih, energy);
0162 }
0163 
0164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......