Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-29 07:38:52

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 "G4EmProcessSubType.hh"
0035 #include "G4ParticleTypes.hh"
0036 #include "G4RunManager.hh"
0037 #include "G4SteppingManager.hh"
0038 #include "G4SystemOfUnits.hh"
0039 #include "G4UnitsTable.hh"
0040 #include "G4VProcess.hh"
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 SteppingAction::SteppingAction() : G4UserSteppingAction() {}
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 void SteppingAction::UserSteppingAction(const G4Step* aStep)
0049 {
0050   Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0051 
0052   const G4VProcess* process = aStep->GetPostStepPoint()->GetProcessDefinedStep();
0053   if (process == nullptr) return;
0054 
0055   G4int eventID = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
0056   G4Track* trk = aStep->GetTrack();
0057 
0058   thread_local G4int iCalled = 0;
0059   const G4int nprint = 10;  // set to 10 to get debug print for first 10 calls
0060   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0061 
0062   if (fSynchrotronRadiation == process->GetProcessSubType()) {
0063     const G4StepPoint* PrePoint = aStep->GetPreStepPoint();
0064     const G4TrackVector* secondary = fpSteppingManager->GetSecondary();
0065     size_t lp = (*secondary).size();
0066     if (lp) {
0067       G4double Egamma = (*secondary)[lp - 1]->GetTotalEnergy();
0068       run->f_n_gam_sync++;
0069       run->f_e_gam_sync += Egamma;
0070       run->f_e_gam_sync2 += Egamma * Egamma;
0071       if (Egamma > run->f_e_gam_sync_max) run->f_e_gam_sync_max = Egamma;
0072       run->f_lam_gam_sync += aStep->GetStepLength();
0073       if (iCalled < nprint) {
0074         G4double Eelec = PrePoint->GetTotalEnergy();
0075         G4ThreeVector Pelec = PrePoint->GetMomentum();
0076         G4ThreeVector PGamma = (*secondary)[lp - 1]->GetMomentum();
0077         G4bool IsGamma = ((*secondary)[lp - 1]->GetDefinition() == G4Gamma::Gamma());
0078         const G4int wid = 8;
0079         if (analysisManager->GetVerboseLevel() > 1 && iCalled < nprint)
0080           G4cout << __FILE__ << " line " << __LINE__ << " " << __FUNCTION__
0081                  << " processName=" << process->GetProcessName()
0082                  << " Step Length=" << std::setw(wid)
0083                  << G4BestUnit(aStep->GetStepLength(), "Length") << " Eelec=" << std::setw(wid)
0084                  << G4BestUnit(Eelec, "Energy") << " Pelec=" << G4BestUnit(Pelec, "Energy")
0085                  << " IsGamma=" << IsGamma << " Egamma=" << std::setw(8)
0086                  << G4BestUnit(Egamma, "Energy") << " PGamma=" << std::setw(8)
0087                  << G4BestUnit(PGamma, "Energy") << " #secondaries lp=" << lp << '\n';
0088       }
0089       analysisManager->FillH1(1, Egamma);
0090       analysisManager->FillH1(2, Egamma,
0091                               Egamma / keV);  // power spectrum : gamma weighted with its energy
0092       analysisManager->FillH1(3, aStep->GetStepLength());
0093     }
0094   }
0095 
0096   thread_local G4ThreeVector IncomingPhotonDirection;
0097   if (fGammaReflection == process->GetProcessSubType()) {
0098     const G4TrackVector* secondary = fpSteppingManager->GetSecondary();
0099     size_t lp = (*secondary).size();
0100     if (lp) {
0101       G4double Egamma = (*secondary)[lp - 1]->GetTotalEnergy();
0102       ++run->f_n_Xray_Refl;
0103       analysisManager->FillH1(1, Egamma, 1. / run->GetNumberOfEventToBeProcessed());
0104       if (analysisManager->GetVerboseLevel() > 1 && run->f_n_Xray_Refl < nprint)
0105         G4cout << __FILE__ << " line " << __LINE__ << " " << __FUNCTION__
0106                << " iCalled=" << std::setw(3) << iCalled << " eventID=" << std::setw(3) << eventID
0107                << " f_n_Xray_Refl=" << run->f_n_Xray_Refl
0108                << " ProcessName=" << process->GetProcessName()
0109                << " direction=" << trk->GetMomentumDirection() << " Egamma=" << Egamma / keV
0110                << " keV" << G4endl;
0111       IncomingPhotonDirection = trk->GetMomentumDirection();
0112     }
0113   }
0114 
0115   const G4VProcess* creator = trk->GetCreatorProcess();
0116   G4int CreatorProcessSubType = 0;
0117   if (creator != nullptr) CreatorProcessSubType = creator->GetProcessSubType();
0118   if (CreatorProcessSubType == fGammaReflection) {  // transportation after XrayReflection
0119     if (IncomingPhotonDirection != G4ThreeVector(0, 0, 0)) {
0120       G4double cos_angle =
0121         IncomingPhotonDirection * trk->GetMomentumDirection();  // incoming * outgoing direction
0122       G4double IncidentAngle = std::acos(cos_angle) / 2.;
0123       analysisManager->FillH1(4, IncidentAngle, 1. / run->GetNumberOfEventToBeProcessed());
0124       if (analysisManager->GetVerboseLevel() > 1 && iCalled < nprint)
0125         G4cout << __FILE__ << " line " << __LINE__ << " " << __FUNCTION__
0126                << " iCalled=" << std::setw(3) << iCalled << " eventID=" << std::setw(3) << eventID
0127                << " CreatorProcname=" << creator->GetProcessName()
0128                << " ProcessName=" << process->GetProcessName()
0129                << " IncomingPhotonDirection=" << IncomingPhotonDirection
0130                << "  outgoing PhotonDirection=" << trk->GetMomentumDirection()
0131                << " IncidentAngle=" << IncidentAngle
0132                << " NumberOfEventToBeProcessed=" << run->GetNumberOfEventToBeProcessed()
0133                << " RunID=" << run->GetRunID() << G4endl;
0134     }
0135   }
0136 
0137   ++iCalled;
0138 }
0139 
0140 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......