Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:31:53

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 //
0027 /// \file Par02Smearer.cc
0028 /// \brief Implementation of the Par02Smearer class
0029 
0030 #include "Par02Smearer.hh"
0031 
0032 #include "Par02PrimaryParticleInformation.hh"
0033 
0034 #include "G4FieldManager.hh"
0035 #include "G4PrimaryParticle.hh"
0036 #include "G4SystemOfUnits.hh"
0037 #include "G4TransportationManager.hh"
0038 #include "G4UniformMagField.hh"
0039 #include "G4UnitsTable.hh"
0040 
0041 #include <ctime>
0042 
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0044 
0045 Par02Smearer* Par02Smearer::fPar02Smearer = nullptr;
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 Par02Smearer::Par02Smearer()
0050 {
0051   time_t seed = time(NULL);
0052   fRandomEngine = new CLHEP::HepJamesRandom(static_cast<long>(seed));
0053   fRandomGauss = new CLHEP::RandGauss(fRandomEngine);
0054 }
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0057 
0058 Par02Smearer::~Par02Smearer() = default;
0059 
0060 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0061 
0062 Par02Smearer* Par02Smearer::Instance()
0063 {
0064   if (!fPar02Smearer) {
0065     fPar02Smearer = new Par02Smearer();
0066   }
0067   return fPar02Smearer;
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 G4ThreeVector Par02Smearer::SmearMomentum(const G4Track* aTrackOriginal, G4double aResolution)
0073 {
0074   return SmearGaussian(aTrackOriginal, aResolution);
0075 }
0076 
0077 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0078 
0079 G4double Par02Smearer::SmearEnergy(const G4Track* aTrackOriginal, G4double aResolution)
0080 {
0081   G4double newE = -1.0;
0082   while (newE < 0.0) {  // To ensure that the resulting value is not negative
0083                         // (vital for energy smearing, does not change direction
0084                         // for momentum smearing)
0085     if (aResolution != -1.0) {
0086       newE = aTrackOriginal->GetKineticEnergy() * Gauss(1.0, aResolution);
0087     }
0088     else {
0089       newE = aTrackOriginal->GetKineticEnergy();
0090     }
0091   }
0092   return newE;
0093 }
0094 
0095 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0096 
0097 G4ThreeVector Par02Smearer::SmearGaussian(const G4Track* aTrackOriginal, G4double aResolution)
0098 {
0099   G4ThreeVector originP = aTrackOriginal->GetMomentum();
0100   G4ThreeVector originPos = aTrackOriginal->GetPosition();
0101   G4double rdm = Gauss(1.0, aResolution);
0102   G4ThreeVector smearedMom(originP.x() * rdm, originP.y() * rdm, originP.z() * rdm);
0103   return smearedMom;
0104 }
0105 
0106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0107 
0108 G4double Par02Smearer::Gauss(G4double aMean, G4double aStandardDeviation)
0109 {
0110   return fRandomGauss->fire(aMean, aStandardDeviation);
0111 }
0112 
0113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......