Back to home page

EIC code displayed by LXR

 
 

    


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

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: RodChromosome.cc
0028 /// brief: Implementation of virt chromosome class for rod chromosomes
0029 
0030 #include "RodChromosome.hh"
0031 
0032 #include "G4PhysicalConstants.hh"
0033 #include "G4RandomDirection.hh"
0034 #include "Randomize.hh"
0035 
0036 #include <utility>
0037 
0038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0039 
0040 const G4String RodChromosome::fShape = "rod";
0041 
0042 RodChromosome::RodChromosome(const G4String& name, const G4ThreeVector& pos, const G4double& radius,
0043                              const G4double& height)
0044   : VirtualChromosome(name),
0045     fCenter(pos),
0046     fRadius(radius),
0047     fHeight(height),
0048     fRotation(G4RotationMatrix())
0049 {
0050   fInverseRotation = fRotation.inverse();
0051 }
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 RodChromosome::RodChromosome(const G4String& name, const G4ThreeVector& pos, const G4double& radius,
0056                              const G4double& height, const G4RotationMatrix& rot)
0057   : VirtualChromosome(name), fCenter(pos), fRadius(radius), fHeight(height), fRotation(rot)
0058 {
0059   fInverseRotation = fRotation.inverse();
0060 }
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0063 
0064 RodChromosome::~RodChromosome() = default;
0065 
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0067 
0068 G4bool RodChromosome::PointInChromosome(G4ThreeVector const& pos)
0069 {
0070   G4ThreeVector rpos = pos - fCenter;
0071   rpos = fInverseRotation(rpos);
0072 
0073   // in the cylinder?
0074   bool height_ok;
0075   bool radius_ok;
0076   G4double height;
0077   G4double rad2;
0078 
0079   height = std::abs(rpos.getZ());
0080   rad2 = rpos.getX() * rpos.getX() + rpos.getY() * rpos.getY();
0081 
0082   height_ok = (height < fHeight);
0083   radius_ok = (rad2 < (fRadius * fRadius));
0084 
0085   G4bool in_cylinder = height_ok && radius_ok;
0086   // in the circles at each end?
0087   G4ThreeVector pos1 = rpos - G4ThreeVector(0, 0, height);
0088   G4bool in_sphere1 = (pos1.mag2() < (fRadius * fRadius));
0089   G4ThreeVector pos2 = rpos + G4ThreeVector(0, 0, height);
0090   G4bool in_sphere2 = (pos2.mag2() < (fRadius * fRadius));
0091 
0092   return (in_cylinder || in_sphere1 || in_sphere2);
0093 }
0094 
0095 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0096 
0097 // NOTE: Not uniformly random
0098 G4ThreeVector RodChromosome::RandomPointInChromosome()
0099 {
0100   G4ThreeVector point;
0101   if (G4UniformRand() < 0.5) {
0102     // in cylinder
0103     G4double z = 2 * (G4UniformRand() - 0.5) * fHeight;
0104     G4double theta = twopi * G4UniformRand();
0105     G4double r = fRadius * std::pow(G4UniformRand(), 0.5);
0106     G4double x = r * std::cos(theta);
0107     G4double y = r * std::sin(theta);
0108     point = G4ThreeVector(x, y, z);
0109   }
0110   else {
0111     // in spheres
0112     point = fRadius * std::pow(G4UniformRand(), 0.5) * G4RandomDirection();
0113     if (point.getZ() < 0) {
0114       // bottom half
0115       point.setZ(point.getZ() - fHeight);
0116     }
0117     else {
0118       // top half
0119       point.setZ(point.getZ() + fHeight);
0120     }
0121   }
0122   return fRotation(point) + fCenter;
0123 }
0124 
0125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......