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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 10.6.p1)


  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 //                                                 26 //
 27 /// \file medical/GammaTherapy/src/PrimaryGene     27 /// \file medical/GammaTherapy/src/PrimaryGeneratorAction.cc
 28 /// \brief Implementation of the PrimaryGenera     28 /// \brief Implementation of the PrimaryGeneratorAction class
 29 //                                                 29 //
 30                                                    30 
 31 //--------------------------------------------     31 //---------------------------------------------------------------------------
 32 //                                                 32 //
 33 // ClassName:   PrimaryGeneratorAction             33 // ClassName:   PrimaryGeneratorAction
 34 //                                                 34 //
 35 // Description: Generate primary beam              35 // Description: Generate primary beam
 36 //                                                 36 //
 37 // Authors: V.Grichine, V.Ivanchenko               37 // Authors: V.Grichine, V.Ivanchenko
 38 //                                                 38 //
 39 // Modified:                                       39 // Modified:
 40 //                                                 40 //
 41 //--------------------------------------------     41 //----------------------------------------------------------------------------
 42 //                                                 42 //
 43                                                    43 
 44 #include "PrimaryGeneratorAction.hh"               44 #include "PrimaryGeneratorAction.hh"
 45                                                << 
 46 #include "DetectorConstruction.hh"                 45 #include "DetectorConstruction.hh"
 47 #include "PrimaryGeneratorMessenger.hh"            46 #include "PrimaryGeneratorMessenger.hh"
 48                                                <<  47 #include "Randomize.hh"
 49 #include "G4ParticleDefinition.hh"             << 
 50 #include "G4ParticleGun.hh"                        48 #include "G4ParticleGun.hh"
 51 #include "G4ParticleTable.hh"                      49 #include "G4ParticleTable.hh"
                                                   >>  50 #include "G4ParticleDefinition.hh"
 52 #include "G4PhysicalConstants.hh"                  51 #include "G4PhysicalConstants.hh"
 53 #include "G4SystemOfUnits.hh"                      52 #include "G4SystemOfUnits.hh"
 54 #include "Randomize.hh"                        << 
 55                                                    53 
 56 //....oooOO0OOooo........oooOO0OOooo........oo     54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 57 //....oooOO0OOooo........oooOO0OOooo........oo     55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 58                                                    56 
 59 PrimaryGeneratorAction::PrimaryGeneratorAction <<  57 PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* pDet):
                                                   >>  58   fDetector(pDet)
 60 {                                                  59 {
 61   InitializeMe();                                  60   InitializeMe();
 62 }                                                  61 }
 63                                                    62 
 64 //....oooOO0OOooo........oooOO0OOooo........oo     63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 65                                                    64 
 66 void PrimaryGeneratorAction::InitializeMe()        65 void PrimaryGeneratorAction::InitializeMe()
 67 {                                                  66 {
 68   fVerbose = fDetector->GetVerbose();              67   fVerbose = fDetector->GetVerbose();
 69   fMessenger = new PrimaryGeneratorMessenger(t     68   fMessenger = new PrimaryGeneratorMessenger(this);
 70   fParticleGun = new G4ParticleGun();              69   fParticleGun = new G4ParticleGun();
 71   fCounter = 0;                                    70   fCounter = 0;
 72   fX0 = 0.0;                                       71   fX0 = 0.0;
 73   fY0 = 0.0;                                       72   fY0 = 0.0;
 74   fZ0 = 0.0;                                       73   fZ0 = 0.0;
 75   fSigmaX = 1.5 * mm;                          <<  74   fSigmaX = 1.5*mm;
 76   fSigmaY = 1.5 * mm;                          <<  75   fSigmaY = 1.5*mm;
 77   fSigmaZ = 0.0;                                   76   fSigmaZ = 0.0;
 78   fSigmaE = 0.0;                                   77   fSigmaE = 0.0;
 79   fRMax2 = 2.5 * 2.5 * mm * mm;                <<  78   fRMax2  = 2.5*2.5*mm*mm;
 80   fSigmaTheta = 0.0;                               79   fSigmaTheta = 0.0;
 81   //  fSigmaTheta = 0.17*degree;                   80   //  fSigmaTheta = 0.17*degree;
 82   fMinCosTheta = 2.0;                              81   fMinCosTheta = 2.0;
 83   SetBeamEnergy(50.0 * MeV);                   <<  82   SetBeamEnergy(50.0*MeV);
 84   fPosition = G4ThreeVector(fX0, fY0, fZ0);    <<  83   fPosition  = G4ThreeVector(fX0,fY0,fZ0);
 85   fDirection = G4ThreeVector(0.0, 0.0, 1.0);   <<  84   fDirection = G4ThreeVector(0.0,0.0,1.0);
 86   fGauss = true;                                   85   fGauss = true;
 87 }                                                  86 }
 88                                                    87 
 89 //....oooOO0OOooo........oooOO0OOooo........oo     88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 90                                                    89 
 91 PrimaryGeneratorAction::~PrimaryGeneratorActio     90 PrimaryGeneratorAction::~PrimaryGeneratorAction()
 92 {                                                  91 {
 93   delete fParticleGun;                             92   delete fParticleGun;
 94   delete fMessenger;                               93   delete fMessenger;
 95 }                                                  94 }
 96                                                    95 
 97 //....oooOO0OOooo........oooOO0OOooo........oo     96 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 98                                                    97 
 99 void PrimaryGeneratorAction::GeneratePrimaries     98 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
100 {                                                  99 {
101   fCounter++;                                  << 100   fCounter++ ;
102                                                   101 
103   // Simulation of beam position                  102   // Simulation of beam position
104   G4double x = fX0;                               103   G4double x = fX0;
105   G4double y = fY0;                               104   G4double y = fY0;
106   G4double z = fDetector->GetGeneratorPosZ();     105   G4double z = fDetector->GetGeneratorPosZ();
107   do {                                            106   do {
108     if (0.0 < fSigmaX) {                       << 107     if(0.0 < fSigmaX) { x = G4RandGauss::shoot(fX0,fSigmaX); }
109       x = G4RandGauss::shoot(fX0, fSigmaX);    << 108     if(0.0 < fSigmaY) { y = G4RandGauss::shoot(fY0,fSigmaY); }
110     }                                          << 109   } while (x*x + y*y > fRMax2);
111     if (0.0 < fSigmaY) {                       << 
112       y = G4RandGauss::shoot(fY0, fSigmaY);    << 
113     }                                          << 
114   } while (x * x + y * y > fRMax2);            << 
115                                                   110 
116   fPosition = G4ThreeVector(x, y, z);          << 111   fPosition = G4ThreeVector(x,y,z);
117   fParticleGun->SetParticlePosition(fPosition)    112   fParticleGun->SetParticlePosition(fPosition);
118                                                   113 
119   // Simulation of beam direction                 114   // Simulation of beam direction
120   G4double ux = fDirection.x();                   115   G4double ux = fDirection.x();
121   G4double uy = fDirection.y();                   116   G4double uy = fDirection.y();
122   G4double uz = fDirection.z();                   117   G4double uz = fDirection.z();
123                                                   118 
124   // Beam particles are uniformly distributed     119   // Beam particles are uniformly distributed over phi, cosTheta
125   if (1.0 > fMinCosTheta) {                    << 120   if(1.0 > fMinCosTheta) {
126     uz = fMinCosTheta + (1.0 - fMinCosTheta) * << 121     uz = fMinCosTheta + (1.0 - fMinCosTheta)*G4UniformRand() ;
127     ux = std::sqrt((1.0 - uz) * (1.0 + uz));   << 122     ux = std::sqrt((1.0 - uz)*(1.0 + uz)) ;
128   }                                            << 123   } else if (fSigmaTheta > 0.0) {
129   else if (fSigmaTheta > 0.0) {                << 124     ux = G4RandGauss::shoot(0.0,fSigmaTheta);
130     ux = G4RandGauss::shoot(0.0, fSigmaTheta); << 125     uz = std::sqrt((1.0 - ux)*(1.0 + ux));
131     uz = std::sqrt((1.0 - ux) * (1.0 + ux));   << 
132   }                                               126   }
133                                                   127 
134   G4double phi = twopi * G4UniformRand();      << 128   G4double phi = twopi*G4UniformRand() ;
135   uy = ux;                                        129   uy = ux;
136   ux *= std::cos(phi);                         << 130   ux *= std::cos(phi) ;
137   uy *= std::sin(phi);                         << 131   uy *= std::sin(phi) ;
138   fDirection = G4ThreeVector(ux, uy, uz);      << 132   fDirection = G4ThreeVector(ux,uy,uz) ;
139                                                   133 
140   fParticleGun->SetParticleMomentumDirection(f    134   fParticleGun->SetParticleMomentumDirection(fDirection);
141                                                   135 
142   // Simulation of beam kinetic energy            136   // Simulation of beam kinetic energy
143   G4double kinEnergy = fEnergy;                   137   G4double kinEnergy = fEnergy;
144                                                   138 
145   if (fGauss == "flatE") {                     << 139   if(fGauss == "flatE") {
146     kinEnergy = fEnergy - fSigmaE + 2. * fSigm << 140     kinEnergy  = fEnergy - fSigmaE + 2.*fSigmaE*G4UniformRand();
147   }                                            << 141   } else if(0.0 < fSigmaE) {
148   else if (0.0 < fSigmaE) {                    << 142     kinEnergy  = fEnergy + G4RandGauss::shoot(0.0,fSigmaE);
149     kinEnergy = fEnergy + G4RandGauss::shoot(0 << 
150   }                                               143   }
151   fParticleGun->SetParticleEnergy(kinEnergy);     144   fParticleGun->SetParticleEnergy(kinEnergy);
152                                                   145 
153   if (fVerbose > 0) {                          << 146   if(fVerbose > 0) {
154     G4ParticleDefinition* particle = fParticle    147     G4ParticleDefinition* particle = fParticleGun->GetParticleDefinition();
155     G4String particleName = particle->GetParti << 148     G4String particleName = particle->GetParticleName() ;
156     G4cout << "Event#  " << fCounter << "  Bea << 149     G4cout << "Event#  " << fCounter
                                                   >> 150            << "  Beam particle is generated by PrimaryGeneratorAction "
157            << G4endl;                             151            << G4endl;
158     G4cout << "ParticleName= " << particleName << 152     G4cout << "ParticleName= " << particleName
159            << std::setprecision(5) << "   KinE << 153            << "  PDGcode= " << particle->GetPDGEncoding()
160            << "   x(mm)= " << x / mm << " y(mm << 154            << std::setprecision(5)
161            << "   ux= " << ux << " uy= " << uy << 155            << "   KinEnergy(GeV)= "
162   }                                            << 156            << fEnergy/GeV
                                                   >> 157            << "   x(mm)= "
                                                   >> 158            << x/mm
                                                   >> 159            << " y(mm)= "
                                                   >> 160            << y/mm
                                                   >> 161            << " z(mm)= "
                                                   >> 162            << z/mm
                                                   >> 163            << "   ux= "
                                                   >> 164            << ux
                                                   >> 165            << " uy= "
                                                   >> 166            << uy
                                                   >> 167            << " uz= "
                                                   >> 168            << uz
                                                   >> 169            << G4endl;
                                                   >> 170     }
163                                                   171 
164   fParticleGun->GeneratePrimaryVertex(anEvent)    172   fParticleGun->GeneratePrimaryVertex(anEvent);
165 }                                                 173 }
166                                                   174 
167 //....oooOO0OOooo........oooOO0OOooo........oo    175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
168                                                   176 
169 void PrimaryGeneratorAction::SetBeamEnergy(G4d    177 void PrimaryGeneratorAction::SetBeamEnergy(G4double val)
170 {                                                 178 {
171   fEnergy = val;                                  179   fEnergy = val;
172   if (fEnergy < fDetector->GetMaxEnergy()) fDe << 180   if(fEnergy<fDetector->GetMaxEnergy()) fDetector->SetMaxEnergy(fEnergy);  
173 }                                                 181 }
174                                                   182 
175 //....oooOO0OOooo........oooOO0OOooo........oo    183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
                                                   >> 184 
                                                   >> 185 
                                                   >> 186 
176                                                   187