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p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/medical/GammaTherapy/src/PrimaryGeneratorAction.cc (Version 11.3.0) and /examples/extended/medical/GammaTherapy/src/PrimaryGeneratorAction.cc (Version 9.5.p2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                             << 
 27 /// \file medical/GammaTherapy/src/PrimaryGene << 
 28 /// \brief Implementation of the PrimaryGenera << 
 29 //                                             << 
 30                                                    26 
 31 //--------------------------------------------     27 //---------------------------------------------------------------------------
 32 //                                                 28 //
 33 // ClassName:   PrimaryGeneratorAction             29 // ClassName:   PrimaryGeneratorAction
 34 //                                                 30 //
 35 // Description: Generate primary beam              31 // Description: Generate primary beam
 36 //                                                 32 //
 37 // Authors: V.Grichine, V.Ivanchenko               33 // Authors: V.Grichine, V.Ivanchenko
 38 //                                                 34 //
 39 // Modified:                                       35 // Modified:
 40 //                                                 36 //
 41 //--------------------------------------------     37 //----------------------------------------------------------------------------
 42 //                                                 38 //
 43                                                    39 
 44 #include "PrimaryGeneratorAction.hh"               40 #include "PrimaryGeneratorAction.hh"
 45                                                << 
 46 #include "DetectorConstruction.hh"                 41 #include "DetectorConstruction.hh"
 47 #include "PrimaryGeneratorMessenger.hh"            42 #include "PrimaryGeneratorMessenger.hh"
 48                                                <<  43 #include "Randomize.hh"
 49 #include "G4ParticleDefinition.hh"             << 
 50 #include "G4ParticleGun.hh"                        44 #include "G4ParticleGun.hh"
 51 #include "G4ParticleTable.hh"                      45 #include "G4ParticleTable.hh"
 52 #include "G4PhysicalConstants.hh"              <<  46 #include "G4ParticleDefinition.hh"
 53 #include "G4SystemOfUnits.hh"                  <<  47 #include "Histo.hh"
 54 #include "Randomize.hh"                        << 
 55                                                    48 
 56 //....oooOO0OOooo........oooOO0OOooo........oo     49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 57 //....oooOO0OOooo........oooOO0OOooo........oo     50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 58                                                    51 
 59 PrimaryGeneratorAction::PrimaryGeneratorAction <<  52 PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* pDet):
                                                   >>  53   fDetector(pDet)
 60 {                                                  54 {
 61   InitializeMe();                                  55   InitializeMe();
 62 }                                                  56 }
 63                                                    57 
 64 //....oooOO0OOooo........oooOO0OOooo........oo     58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 65                                                    59 
 66 void PrimaryGeneratorAction::InitializeMe()        60 void PrimaryGeneratorAction::InitializeMe()
 67 {                                                  61 {
 68   fVerbose = fDetector->GetVerbose();          <<  62   theMessenger = new PrimaryGeneratorMessenger(this);
 69   fMessenger = new PrimaryGeneratorMessenger(t <<  63   particleGun = new G4ParticleGun();
 70   fParticleGun = new G4ParticleGun();          <<  64   counter = 0;
 71   fCounter = 0;                                <<  65   verbose = 0;
 72   fX0 = 0.0;                                   <<  66   x0 = 0.0;
 73   fY0 = 0.0;                                   <<  67   y0 = 0.0;
 74   fZ0 = 0.0;                                   <<  68   z0 = 0.0;
 75   fSigmaX = 1.5 * mm;                          <<  69   sigmaX = 1.5*mm;
 76   fSigmaY = 1.5 * mm;                          <<  70   sigmaY = 1.5*mm;
 77   fSigmaZ = 0.0;                               <<  71   sigmaZ = 0.0;
 78   fSigmaE = 0.0;                               <<  72   sigmaE = 0.0;
 79   fRMax2 = 2.5 * 2.5 * mm * mm;                <<  73   rMax2  = 2.5*2.5*mm*mm;
 80   fSigmaTheta = 0.0;                           <<  74   sigmaTheta = 0.0;
 81   //  fSigmaTheta = 0.17*degree;               <<  75 //  sigmaTheta = 0.17*degree;
 82   fMinCosTheta = 2.0;                          <<  76   minCosTheta = 2.0;
 83   SetBeamEnergy(50.0 * MeV);                   <<  77   SetBeamEnergy(50.0*MeV);
 84   fPosition = G4ThreeVector(fX0, fY0, fZ0);    <<  78   position  = G4ThreeVector(x0,y0,z0);
 85   fDirection = G4ThreeVector(0.0, 0.0, 1.0);   <<  79   direction = G4ThreeVector(0.0,0.0,1.0);
 86   fGauss = true;                               <<  80   m_gauss = true;
                                                   >>  81   if(energy < (Histo::GetPointer())->GetMaxEnergy())
                                                   >>  82               (Histo::GetPointer())->SetMaxEnergy(energy);
 87 }                                                  83 }
 88                                                    84 
 89 //....oooOO0OOooo........oooOO0OOooo........oo     85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 90                                                    86 
 91 PrimaryGeneratorAction::~PrimaryGeneratorActio     87 PrimaryGeneratorAction::~PrimaryGeneratorAction()
 92 {                                                  88 {
 93   delete fParticleGun;                         <<  89   delete particleGun;
 94   delete fMessenger;                           <<  90   delete theMessenger;
 95 }                                                  91 }
 96                                                    92 
 97 //....oooOO0OOooo........oooOO0OOooo........oo     93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 98                                                    94 
 99 void PrimaryGeneratorAction::GeneratePrimaries     95 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
100 {                                                  96 {
101   fCounter++;                                  <<  97   counter++ ;
                                                   >>  98   verbose = (Histo::GetPointer())->GetVerbose();
102                                                    99 
103   // Simulation of beam position                  100   // Simulation of beam position
104   G4double x = fX0;                            << 101   G4double x = x0;
105   G4double y = fY0;                            << 102   G4double y = y0;
106   G4double z = fDetector->GetGeneratorPosZ();     103   G4double z = fDetector->GetGeneratorPosZ();
107   do {                                            104   do {
108     if (0.0 < fSigmaX) {                       << 105     if(0.0 < sigmaX) x = G4RandGauss::shoot(x0,sigmaX);
109       x = G4RandGauss::shoot(fX0, fSigmaX);    << 106     if(0.0 < sigmaY) y = G4RandGauss::shoot(y0,sigmaY);
110     }                                          << 107   } while (x*x + y*y > rMax2);
111     if (0.0 < fSigmaY) {                       << 
112       y = G4RandGauss::shoot(fY0, fSigmaY);    << 
113     }                                          << 
114   } while (x * x + y * y > fRMax2);            << 
115                                                   108 
116   fPosition = G4ThreeVector(x, y, z);          << 109   position  = G4ThreeVector(x,y,z);
117   fParticleGun->SetParticlePosition(fPosition) << 110   particleGun->SetParticlePosition(position);
118                                                   111 
119   // Simulation of beam direction                 112   // Simulation of beam direction
120   G4double ux = fDirection.x();                << 113   G4double ux = direction.x();
121   G4double uy = fDirection.y();                << 114   G4double uy = direction.y();
122   G4double uz = fDirection.z();                << 115   G4double uz = direction.z();
123                                                   116 
124   // Beam particles are uniformly distributed     117   // Beam particles are uniformly distributed over phi, cosTheta
125   if (1.0 > fMinCosTheta) {                    << 118   if(1.0 > minCosTheta) {
126     uz = fMinCosTheta + (1.0 - fMinCosTheta) * << 119     uz = minCosTheta + (1.0 - minCosTheta)*G4UniformRand() ;
127     ux = std::sqrt((1.0 - uz) * (1.0 + uz));   << 120     ux = std::sqrt(1.0 - uz*uz) ;
                                                   >> 121   } else if (sigmaTheta > 0.0) {
                                                   >> 122     ux = G4RandGauss::shoot(0.0,sigmaTheta);
                                                   >> 123     uz = std::sqrt(1.0 - ux*ux);
128   }                                               124   }
129   else if (fSigmaTheta > 0.0) {                << 
130     ux = G4RandGauss::shoot(0.0, fSigmaTheta); << 
131     uz = std::sqrt((1.0 - ux) * (1.0 + ux));   << 
132   }                                            << 
133                                                << 
134   G4double phi = twopi * G4UniformRand();      << 
135   uy = ux;                                     << 
136   ux *= std::cos(phi);                         << 
137   uy *= std::sin(phi);                         << 
138   fDirection = G4ThreeVector(ux, uy, uz);      << 
139                                                   125 
140   fParticleGun->SetParticleMomentumDirection(f << 126   G4double phi = twopi*G4UniformRand() ;
                                                   >> 127   uy = ux ;
                                                   >> 128   ux *= std::cos(phi) ;
                                                   >> 129   uy *= std::sin(phi) ;
                                                   >> 130   direction = G4ThreeVector(ux,uy,uz) ;
                                                   >> 131 
                                                   >> 132   direction = direction.unit();
                                                   >> 133   particleGun->SetParticleMomentumDirection(direction);
                                                   >> 134   G4ParticleDefinition* particle = particleGun->GetParticleDefinition();
141                                                   135 
142   // Simulation of beam kinetic energy            136   // Simulation of beam kinetic energy
143   G4double kinEnergy = fEnergy;                << 137   G4double kinEnergy = energy;
144                                                   138 
145   if (fGauss == "flatE") {                     << 139   if(m_gauss == "flatE") kinEnergy  = energy - sigmaE + 2.*sigmaE*G4UniformRand();
146     kinEnergy = fEnergy - fSigmaE + 2. * fSigm << 140   else if(0.0 < sigmaE)  kinEnergy  = energy + G4RandGauss::shoot(0.0,sigmaE);
147   }                                            << 141 
148   else if (0.0 < fSigmaE) {                    << 142   particleGun->SetParticleEnergy(kinEnergy);
149     kinEnergy = fEnergy + G4RandGauss::shoot(0 << 143 
150   }                                            << 144   G4String particleName = particle->GetParticleName() ;
151   fParticleGun->SetParticleEnergy(kinEnergy);  << 
152                                                   145 
153   if (fVerbose > 0) {                          << 146   if(verbose > 0) {
154     G4ParticleDefinition* particle = fParticle << 147     G4cout << "Event#  " << counter
155     G4String particleName = particle->GetParti << 148            << "  Beam particle is generated by PrimaryGeneratorAction "
156     G4cout << "Event#  " << fCounter << "  Bea << 
157            << G4endl;                             149            << G4endl;
158     G4cout << "ParticleName= " << particleName << 150     G4cout << "ParticleName= " << particleName
159            << std::setprecision(5) << "   KinE << 151            << "  PDGcode= " << particle->GetPDGEncoding()
160            << "   x(mm)= " << x / mm << " y(mm << 152            << std::setprecision(5)
161            << "   ux= " << ux << " uy= " << uy << 153      << "   KinEnergy(GeV)= "
162   }                                            << 154      << energy/GeV
                                                   >> 155      << "   x(mm)= "
                                                   >> 156      << x/mm
                                                   >> 157      << " y(mm)= "
                                                   >> 158      << y/mm
                                                   >> 159      << " z(mm)= "
                                                   >> 160      << z/mm
                                                   >> 161            << "   ux= "
                                                   >> 162      << ux
                                                   >> 163      << " uy= "
                                                   >> 164      << uy
                                                   >> 165      << " uz= "
                                                   >> 166      << uz
                                                   >> 167      << G4endl;
                                                   >> 168     }
163                                                   169 
164   fParticleGun->GeneratePrimaryVertex(anEvent) << 170   particleGun->GeneratePrimaryVertex(anEvent);
165 }                                                 171 }
166                                                   172 
167 //....oooOO0OOooo........oooOO0OOooo........oo    173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
168                                                   174 
                                                   >> 175 void PrimaryGeneratorAction::SetBeamSigmaE(G4double val)
                                                   >> 176 {
                                                   >> 177   sigmaE = val;
                                                   >> 178 }
                                                   >> 179 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
                                                   >> 180 
169 void PrimaryGeneratorAction::SetBeamEnergy(G4d    181 void PrimaryGeneratorAction::SetBeamEnergy(G4double val)
170 {                                                 182 {
171   fEnergy = val;                               << 183   energy = val;
172   if (fEnergy < fDetector->GetMaxEnergy()) fDe << 184   if(energy < (Histo::GetPointer())->GetMaxEnergy())
                                                   >> 185               (Histo::GetPointer())->SetMaxEnergy(energy);
173 }                                                 186 }
174                                                   187 
175 //....oooOO0OOooo........oooOO0OOooo........oo    188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
                                                   >> 189 
                                                   >> 190 
                                                   >> 191 
176                                                   192