Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-15 08:29:22

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