Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:09:05

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 
0035 #include "G4ParticleTypes.hh"
0036 #include "G4RunManager.hh"
0037 #include "G4StepStatus.hh"
0038 #include "G4SystemOfUnits.hh"
0039 #include "G4Track.hh"
0040 #include "G4UnitsTable.hh"
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 TrackingAction::TrackingAction(EventAction* event) : fEventAction(event) {}
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 void TrackingAction::PreUserTrackingAction(const G4Track* track)
0049 {
0050   // count secondary particles
0051   if (track->GetTrackID() == 1) return;
0052 
0053   Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0054 
0055   G4String name = track->GetDefinition()->GetParticleName();
0056   G4double meanLife = track->GetDefinition()->GetPDGLifeTime();
0057   G4double energy = track->GetKineticEnergy();
0058   if (meanLife != 0) run->ParticleCount(name, energy, meanLife);
0059 }
0060 
0061 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0062 
0063 void TrackingAction::PostUserTrackingAction(const G4Track* track)
0064 {
0065   // keep only outgoing particle
0066   G4StepStatus status = track->GetStep()->GetPostStepPoint()->GetStepStatus();
0067   if (status != fWorldBoundary) return;
0068 
0069   const G4ParticleDefinition* particle = track->GetParticleDefinition();
0070   G4String name = particle->GetParticleName();
0071   G4double energy = track->GetKineticEnergy();
0072 
0073   fEventAction->AddEflow(energy);
0074 
0075   Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0076   run->ParticleFlux(name, energy);
0077 
0078   // histograms: enery flow
0079   //
0080   G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0081 
0082   G4int ih = 0;
0083   G4String type = particle->GetParticleType();
0084   G4double charge = particle->GetPDGCharge();
0085   if (charge > 3.)
0086     ih = 10;
0087   else if (particle == G4Gamma::Gamma())
0088     ih = 4;
0089   else if (particle == G4Electron::Electron())
0090     ih = 5;
0091   else if (particle == G4Positron::Positron())
0092     ih = 5;
0093   else if (particle == G4Neutron::Neutron())
0094     ih = 6;
0095   else if (particle == G4Proton::Proton())
0096     ih = 7;
0097   else if (particle == G4Deuteron::Deuteron())
0098     ih = 8;
0099   else if (particle == G4Alpha::Alpha())
0100     ih = 9;
0101   else if (type == "nucleus")
0102     ih = 10;
0103   else if (type == "baryon")
0104     ih = 11;
0105   else if (type == "meson")
0106     ih = 12;
0107   else if (type == "lepton")
0108     ih = 13;
0109   if (ih > 0) analysis->FillH1(ih, energy);
0110 }
0111 
0112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......