Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:27

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 // INCL++ intra-nuclear cascade model
0027 // Alain Boudard, CEA-Saclay, France
0028 // Joseph Cugnon, University of Liege, Belgium
0029 // Jean-Christophe David, CEA-Saclay, France
0030 // Pekka Kaitaniemi, CEA-Saclay, France, and Helsinki Institute of Physics, Finland
0031 // Sylvie Leray, CEA-Saclay, France
0032 // Davide Mancusi, CEA-Saclay, France
0033 //
0034 #define INCLXX_IN_GEANT4_MODE 1
0035 
0036 #include "globals.hh"
0037 
0038 /** \file G4INCLIntersection.hh
0039  * \brief Simple class for computing intersections between a straight line and a sphere.
0040  *
0041  * \date 12 December 2011
0042  * \author Davide Mancusi
0043  */
0044 
0045 #ifndef G4INCLINTERSECTION_HH
0046 #define G4INCLINTERSECTION_HH 1
0047 
0048 #include "G4INCLThreeVector.hh"
0049 #include <utility>
0050 
0051 namespace G4INCL {
0052 
0053   /** \brief Intersection-point structure
0054    *
0055    * The structure contains the time and position of the intersection point
0056    * of a trajectory with a surface, if it exists.
0057    */
0058   struct Intersection {
0059     Intersection(const G4bool e, const G4double t, const ThreeVector &p) :
0060       exists(e), time(t), position(p) {}
0061     G4bool exists;
0062     G4double time;
0063     ThreeVector position;
0064   };
0065 
0066   namespace IntersectionFactory {
0067 
0068     /** \brief Compute the first intersection of a straight particle
0069      *         trajectory with a sphere.
0070      *
0071      * \param x0 the starting position of the trajectory
0072      * \param p the trajectory direction
0073      * \param r the radius of the sphere (centred in the origin)
0074      * \return an Intersection. The G4bool is true if an intersection exists,
0075      *         in which case its position is stored in the ThreeVector and
0076      *         its time in the G4double.
0077      */
0078     Intersection getEarlierTrajectoryIntersection(const ThreeVector &x0, const ThreeVector &p, const G4double r);
0079     /** \brief Compute the second intersection of a straight particle
0080      *         trajectory with a sphere.
0081      *
0082      * \param x0 the starting position of the trajectory
0083      * \param p the trajectory direction
0084      * \param r the radius of the sphere (centred in the origin)
0085      * \return an Intersection. The G4bool is true if an intersection exists,
0086      *         in which case its position is stored in the ThreeVector and
0087      *         its time in the G4double.
0088      */
0089     Intersection getLaterTrajectoryIntersection(const ThreeVector &x0, const ThreeVector &p, const G4double r);
0090     /** \brief Compute both intersections of a straight particle
0091      *         trajectory with a sphere.
0092      *
0093      * \param x0 the starting position of the trajectory
0094      * \param p the trajectory direction
0095      * \param r the radius of the sphere (centred in the origin)
0096      * \return an Intersection. The G4bool is true if an intersection exists,
0097      *         in which case its position is stored in the ThreeVector and
0098      *         its time in the G4double.
0099      */
0100     std::pair<Intersection,Intersection> getTrajectoryIntersections(const ThreeVector &x0, const ThreeVector &p, const G4double r);
0101 
0102     namespace {
0103 
0104       Intersection getTrajectoryIntersection(const ThreeVector &x0, const ThreeVector &v, const G4double r, const G4bool earliest) {
0105         const G4double scalarVelocity = v.mag();
0106         ThreeVector velocityUnitVector = v / scalarVelocity;
0107 
0108         ThreeVector positionTransverse = x0 - velocityUnitVector * x0.dot(velocityUnitVector);
0109         const G4double impactParameter = positionTransverse.mag();
0110 
0111         const G4double r2 = r*r;
0112         G4double distanceZ2 = r2 - impactParameter * impactParameter;
0113         if(distanceZ2 < 0.0)
0114           return Intersection(false, 0.0, ThreeVector());
0115 
0116         const G4double distanceZ = std::sqrt(distanceZ2);
0117         const ThreeVector position = positionTransverse + velocityUnitVector * (earliest ? -distanceZ : distanceZ);
0118         const G4double time = (position-x0).dot(velocityUnitVector)/scalarVelocity;
0119         return Intersection(true, time, position);
0120       }
0121 
0122     }
0123 
0124     inline Intersection getEarlierTrajectoryIntersection(const ThreeVector &x0, const ThreeVector &p, const G4double r) {
0125       return getTrajectoryIntersection(x0, p, r, true);
0126     }
0127 
0128     inline Intersection getLaterTrajectoryIntersection(const ThreeVector &x0, const ThreeVector &p, const G4double r) {
0129       return getTrajectoryIntersection(x0, p, r, false);
0130     }
0131 
0132     inline std::pair<Intersection,Intersection> getTrajectoryIntersections(const ThreeVector &x0, const ThreeVector &p, const G4double r) {
0133       return std::make_pair(
0134                             getTrajectoryIntersection(x0, p, r, true),
0135                             getTrajectoryIntersection(x0, p, r, false)
0136                            );
0137     }
0138   }
0139 
0140 }
0141 
0142 #endif /* G4INCLINTERSECTION_HH */