Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:20:54

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