Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:10

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 #include "BoundedBrownianAction.hh"
0028 
0029 #include "G4DNABoundingBox.hh"
0030 #include "G4Molecule.hh"
0031 #include "G4Track.hh"
0032 
0033 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0034 
0035 BoundedBrownianAction::BoundedBrownianAction() : G4VUserBrownianAction() {}
0036 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0037 
0038 G4double BoundedBrownianAction::GetDistanceToBoundary(const G4Track& track)
0039 {
0040   if (!fpBoundingBox->contains(track.GetPosition())) {
0041     G4ExceptionDescription errMsg;
0042     errMsg << "Point is out of box : " << *fpBoundingBox
0043            << " of particle : " << GetIT(track)->GetName() << "(" << track.GetTrackID()
0044            << ") : " << track.GetPosition();
0045     G4Exception(
0046       "BoundedBrownianAction::GetDistanceToBoundary"
0047       "BoundedBrownianAction",
0048       "BoundedBrownianAction", FatalErrorInArgument, errMsg);
0049   }
0050 
0051   auto dx = std::min(track.GetPosition().getX() - fpBoundingBox->Getxlo(),
0052                      fpBoundingBox->Getxhi() - track.GetPosition().getX());
0053   auto dy = std::min(track.GetPosition().getY() - fpBoundingBox->Getylo(),
0054                      fpBoundingBox->Getyhi() - track.GetPosition().getY());
0055   auto dz = std::min(track.GetPosition().getZ() - fpBoundingBox->Getzlo(),
0056                      fpBoundingBox->Getzhi() - track.GetPosition().getZ());
0057   return std::min({dx, dy, dz});
0058 }
0059 
0060 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0061 
0062 void BoundedBrownianAction::Transport(G4ThreeVector& nextposition, G4Track*)
0063 {
0064   BouncingAction(nextposition);
0065 }
0066 
0067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0068 
0069 void BoundedBrownianAction::BouncingAction(G4ThreeVector& nextposition) const
0070 {
0071   // This algorithm is implemented based on Karamitros, Mathieu et al.2020,arXiv:2006.14225 (2020)
0072   //  https://doi.org/10.48550/arXiv.2006.14225
0073   G4double RxM = fpBoundingBox->Getxhi();
0074   G4double RyM = fpBoundingBox->Getyhi();
0075   G4double RzM = fpBoundingBox->Getzhi();
0076 
0077   G4double Rxm = fpBoundingBox->Getxlo();
0078   G4double Rym = fpBoundingBox->Getylo();
0079   G4double Rzm = fpBoundingBox->Getzlo();
0080   G4double Lx = RxM - Rxm;
0081   G4double Ly = RyM - Rym;
0082   G4double Lz = RzM - Rzm;
0083   G4double trunx = trunc(std::abs(nextposition.getX() - Rxm) / Lx);
0084   G4double truny = trunc(std::abs(nextposition.getY() - Rym) / Ly);
0085   G4double trunz = trunc(std::abs(nextposition.getZ() - Rzm) / Lz);
0086   G4double hx = std::fmod(trunx, 2);
0087   G4double hy = std::fmod(truny, 2);
0088   G4double hz = std::fmod(trunz, 2);
0089   G4double x = Rxm + hx * Lx + (1 - 2 * hx) * std::abs(std::fmod(nextposition.getX() - Rxm, Lx));
0090   G4double y = Rym + hy * Ly + (1 - 2 * hy) * std::abs(std::fmod(nextposition.getY() - Rym, Ly));
0091   G4double z = Rzm + hz * Lz + (1 - 2 * hz) * std::abs(std::fmod(nextposition.getZ() - Rzm, Lz));
0092   nextposition.set(x, y, z);
0093 }
0094 
0095 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......