Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 08:37:49

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 SteppingAction.cc
0027 /// \brief Implementation of the SteppingAction class
0028 
0029 #include "SteppingAction.hh"
0030 
0031 #include "HistoManager.hh"
0032 #include "Run.hh"
0033 
0034 #include "G4HadronicProcess.hh"
0035 #include "G4ParticleTypes.hh"
0036 #include "G4RunManager.hh"
0037 
0038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0039 
0040 // SteppingAction::SteppingAction()
0041 //: G4UserSteppingAction()
0042 //{ }
0043 
0044 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0045 
0046 void SteppingAction::UserSteppingAction(const G4Step* aStep)
0047 {
0048   // check trackID and stepNumber
0049   G4int trackID = aStep->GetTrack()->GetTrackID();
0050   G4int stepNb = aStep->GetTrack()->GetCurrentStepNumber();
0051   if (trackID * stepNb != 1) return;
0052   // ok, we are at first interaction of the primary particle
0053 
0054   Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0055 
0056   // count processes
0057   //
0058   const G4StepPoint* endPoint = aStep->GetPostStepPoint();
0059   G4VProcess* process = const_cast<G4VProcess*>(endPoint->GetProcessDefinedStep());
0060   run->CountProcesses(process);
0061 
0062   // check that an real interaction occured (eg. not a transportation)
0063   G4StepStatus stepStatus = endPoint->GetStepStatus();
0064   G4bool transmit = (stepStatus == fGeomBoundary || stepStatus == fWorldBoundary);
0065   if (transmit) return;
0066 
0067   // real processes : sum track length
0068   //
0069   G4double stepLength = aStep->GetStepLength();
0070   run->SumTrack(stepLength);
0071 
0072   // energy-momentum balance initialisation
0073   //
0074   const G4StepPoint* prePoint = aStep->GetPreStepPoint();
0075   G4double Q = -prePoint->GetKineticEnergy();
0076   G4ThreeVector Pbalance = -prePoint->GetMomentum();
0077 
0078   // initialisation of the nuclear channel identification
0079   //
0080   G4ParticleDefinition* particle = aStep->GetTrack()->GetDefinition();
0081   G4String partName = particle->GetParticleName();
0082   G4String nuclearChannel = partName;
0083   G4HadronicProcess* hproc = dynamic_cast<G4HadronicProcess*>(process);
0084   const G4Isotope* target = NULL;
0085   if (hproc) target = hproc->GetTargetIsotope();
0086   G4String targetName = "XXXX";
0087   if (target) targetName = target->GetName();
0088   nuclearChannel += " + " + targetName + " --> ";
0089   if (targetName == "XXXX") run->SetTargetXXX(true);
0090 
0091   // scattered primary particle (if any)
0092   //
0093   G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0094   G4int ih = 1;
0095   if (aStep->GetTrack()->GetTrackStatus() == fAlive) {
0096     G4double energy = endPoint->GetKineticEnergy();
0097     analysis->FillH1(ih, energy);
0098     //
0099     G4ThreeVector momentum = endPoint->GetMomentum();
0100     Q += energy;
0101     Pbalance += momentum;
0102     //
0103     nuclearChannel += partName + " + ";
0104   }
0105 
0106   // secondaries
0107   //
0108   const std::vector<const G4Track*>* secondary = aStep->GetSecondaryInCurrentStep();
0109   for (size_t lp = 0; lp < (*secondary).size(); lp++) {
0110     particle = (*secondary)[lp]->GetDefinition();
0111     G4String name = particle->GetParticleName();
0112     G4String type = particle->GetParticleType();
0113     G4double energy = (*secondary)[lp]->GetKineticEnergy();
0114     run->ParticleCount(name, energy);
0115     // energy spectrum
0116     ih = 0;
0117     if (particle == G4Gamma::Gamma())
0118       ih = 2;
0119     else if (particle == G4Electron::Electron())
0120       ih = 3;
0121     else if (particle == G4Neutron::Neutron())
0122       ih = 4;
0123     else if (particle == G4Proton::Proton())
0124       ih = 5;
0125     else if (particle == G4Deuteron::Deuteron())
0126       ih = 6;
0127     else if (particle == G4Alpha::Alpha())
0128       ih = 7;
0129     else if (type == "nucleus")
0130       ih = 8;
0131     else if (type == "meson")
0132       ih = 9;
0133     else if (type == "baryon")
0134       ih = 10;
0135     if (ih > 0) analysis->FillH1(ih, energy);
0136     // atomic mass
0137     if (type == "nucleus") {
0138       G4int A = particle->GetAtomicMass();
0139       analysis->FillH1(13, A);
0140     }
0141     // energy-momentum balance
0142     G4ThreeVector momentum = (*secondary)[lp]->GetMomentum();
0143     Q += energy;
0144     Pbalance += momentum;
0145     // count e- from internal conversion together with gamma
0146     if (particle == G4Electron::Electron()) particle = G4Gamma::Gamma();
0147     // particle flag
0148     fParticleFlag[particle]++;
0149   }
0150 
0151   // energy-momentum balance
0152   G4double Pbal = Pbalance.mag();
0153   run->Balance(Pbal);
0154   ih = 11;
0155   analysis->FillH1(ih, Q);
0156   ih = 12;
0157   analysis->FillH1(ih, Pbal);
0158 
0159   // nuclear channel
0160   const G4int kMax = 16;
0161   const G4String conver[] = {"0",  "",    "2 ",  "3 ",  "4 ",  "5 ",  "6 ",  "7 ", "8 ",
0162                              "9 ", "10 ", "11 ", "12 ", "13 ", "14 ", "15 ", "16 "};
0163   std::map<G4ParticleDefinition*, G4int>::iterator ip;
0164   for (ip = fParticleFlag.begin(); ip != fParticleFlag.end(); ip++) {
0165     particle = ip->first;
0166     G4String name = particle->GetParticleName();
0167     G4int nb = ip->second;
0168     if (nb > kMax) nb = kMax;
0169     G4String Nb = conver[nb];
0170     if (particle == G4Gamma::Gamma()) {
0171       run->CountGamma(nb);
0172       Nb = "N ";
0173       name = "gamma or e-";
0174     }
0175     if (ip != fParticleFlag.begin()) nuclearChannel += " + ";
0176     nuclearChannel += Nb + name;
0177   }
0178 
0179   /// G4cout << "\n nuclear channel: " << nuclearChannel << G4endl;
0180   run->CountNuclearChannel(nuclearChannel, Q);
0181 
0182   fParticleFlag.clear();
0183 
0184   // kill event after first interaction
0185   //
0186   G4RunManager::GetRunManager()->AbortEvent();
0187 }
0188 
0189 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......