Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-21 07:54:01

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 "G4IonTable.hh"
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 void TrackingAction::PreUserTrackingAction(const G4Track* track)
0050 {
0051   Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0052 
0053   G4ParticleDefinition* particle = track->GetDefinition();
0054   G4String name = particle->GetParticleName();
0055   G4double meanLife = particle->GetPDGLifeTime();
0056   G4double ekin = track->GetKineticEnergy();
0057   fTimeBirth = track->GetGlobalTime();
0058 
0059   // count secondary particles (with meanLife > 0)
0060   if ((track->GetTrackID() > 1) && (meanLife != 0.)) run->ParticleCount(name, ekin, meanLife);
0061 }
0062 
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0064 
0065 void TrackingAction::PostUserTrackingAction(const G4Track* track)
0066 {
0067   Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0068 
0069   G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0070 
0071   const G4ParticleDefinition* particle = track->GetParticleDefinition();
0072   G4String name = particle->GetParticleName();
0073   G4double meanLife = particle->GetPDGLifeTime();
0074   G4double ekin = track->GetKineticEnergy();
0075   fTimeEnd = track->GetGlobalTime();
0076   if ((particle->GetPDGStable()) && (ekin == 0.)) fTimeEnd = DBL_MAX;
0077 
0078   // count population of ions with meanLife > 0.
0079   if ((G4IonTable::IsIon(particle)) && (meanLife != 0.)) {
0080     G4int id = run->GetIonId(name);
0081     G4double unit = analysis->GetH1Unit(id);
0082     G4double tmin = analysis->GetH1Xmin(id) * unit;
0083     G4double tmax = analysis->GetH1Xmax(id) * unit;
0084     G4double binWidth = analysis->GetH1Width(id) * unit;
0085     G4double weight = track->GetWeight();
0086 
0087     G4double t1 = std::max(fTimeBirth, tmin);
0088     G4double t2 = std::min(fTimeEnd, tmax);
0089     for (G4double time = t1; time < t2; time += binWidth)
0090       analysis->FillH1(id, time, weight);
0091   }
0092 
0093   // keep only emerging particles
0094   G4StepStatus status = track->GetStep()->GetPostStepPoint()->GetStepStatus();
0095   if (status != fWorldBoundary) return;
0096 
0097   fEventAction->AddEflow(ekin);
0098   run->ParticleFlux(name, ekin);
0099 
0100   // histograms: energy flow and activities of emerging particles
0101 
0102   G4int ih1 = 0, ih2 = 0;
0103   G4String type = particle->GetParticleType();
0104   G4double charge = particle->GetPDGCharge();
0105   G4double time = track->GetGlobalTime();
0106   G4double weight = track->GetWeight();
0107   if (charge > 3.) {
0108     ih1 = 10;
0109     ih2 = 20;
0110   }
0111   else if (particle == G4Gamma::Gamma()) {
0112     ih1 = 4;
0113     ih2 = 14;
0114   }
0115   else if (particle == G4Electron::Electron()) {
0116     ih1 = 5;
0117     ih2 = 15;
0118   }
0119   else if (particle == G4Positron::Positron()) {
0120     ih1 = 5;
0121     ih2 = 15;
0122   }
0123   else if (particle == G4Neutron::Neutron()) {
0124     ih1 = 6;
0125     ih2 = 16;
0126   }
0127   else if (particle == G4Proton::Proton()) {
0128     ih1 = 7;
0129     ih2 = 17;
0130   }
0131   else if (particle == G4Deuteron::Deuteron()) {
0132     ih1 = 8;
0133     ih2 = 18;
0134   }
0135   else if (particle == G4Alpha::Alpha()) {
0136     ih1 = 9;
0137     ih2 = 19;
0138   }
0139   else if (type == "nucleus") {
0140     ih1 = 10;
0141     ih2 = 20;
0142   }
0143   else if (type == "baryon") {
0144     ih1 = 11;
0145     ih2 = 21;
0146   }
0147   else if (type == "meson") {
0148     ih1 = 12;
0149     ih2 = 22;
0150   }
0151   else if (type == "lepton") {
0152     ih1 = 13;
0153     ih2 = 23;
0154   };
0155   if (ih1 > 0) analysis->FillH1(ih1, ekin, weight);
0156   if (ih2 > 0) analysis->FillH1(ih2, time, weight);
0157 }
0158 
0159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......