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 10.4.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/advanced/hadrontherapy/src/HadrontherapyPrimaryGeneratorAction.cc (Version 11.3.0) and /examples/advanced/hadrontherapy/src/HadrontherapyPrimaryGeneratorAction.cc (Version 9.5.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 // Hadrontherapy advanced example for Geant4   <<  26 // This is the *BASIC* version of Hadrontherapy, a Geant4-based application
 27 // See more at: https://twiki.cern.ch/twiki/bi <<  27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
                                                   >>  28 //
                                                   >>  29 // Visit the Hadrontherapy web site (http://www.lns.infn.it/link/Hadrontherapy) to request 
                                                   >>  30 // the *COMPLETE* version of this program, together with its documentation;
                                                   >>  31 // Hadrontherapy (both basic and full version) are supported by the Italian INFN
                                                   >>  32 // Institute in the framework of the MC-INFN Group
                                                   >>  33 //
 28                                                    34 
 29 #include "HadrontherapyPrimaryGeneratorAction.     35 #include "HadrontherapyPrimaryGeneratorAction.hh"
 30 #include "HadrontherapyPrimaryGeneratorMesseng     36 #include "HadrontherapyPrimaryGeneratorMessenger.hh"
 31                                                << 
 32 #include "HadrontherapyMatrix.hh"              << 
 33 #include "HadrontherapyDetectorSD.hh"          << 
 34 #include "G4SystemOfUnits.hh"                  << 
 35 #include "G4Event.hh"                              37 #include "G4Event.hh"
 36 #include "G4ParticleGun.hh"                        38 #include "G4ParticleGun.hh"
 37 #include "G4GeneralParticleSource.hh"          << 
 38 #include "G4ParticleTable.hh"                      39 #include "G4ParticleTable.hh"
 39 #include "G4ParticleDefinition.hh"                 40 #include "G4ParticleDefinition.hh"
 40 #include "Randomize.hh"                            41 #include "Randomize.hh"
 41 #include "G4IonTable.hh"                       <<  42 #include "HadrontherapyAnalysisManager.hh"
 42                                                << 
 43                                                << 
 44 #include "G4VUserPrimaryGeneratorAction.hh"    << 
 45 #include "G4ParticleTable.hh"                  << 
 46                                                    43 
 47 #include "G4Event.hh"                          <<  44 HadrontherapyPrimaryGeneratorAction::HadrontherapyPrimaryGeneratorAction()
 48 #include "G4Timer.hh"                          <<  45 {
 49                                                <<  46   // Define the messenger
 50 #include "G4RunManager.hh"                     <<  47   gunMessenger = new HadrontherapyPrimaryGeneratorMessenger(this);
 51                                                    48 
                                                   >>  49   particleGun  = new G4ParticleGun();
 52                                                    50 
                                                   >>  51   SetDefaultPrimaryParticle();  
                                                   >>  52 }  
 53                                                    53 
 54 ////////////////////////////////////////////// <<  54 HadrontherapyPrimaryGeneratorAction::~HadrontherapyPrimaryGeneratorAction()
 55 HadrontherapyPrimaryGeneratorAction::Hadronthe << 
 56   fNewSource(false)                            << 
 57 {                                                  55 {
 58     PrimaryGeneratorMessenger = new Hadronther <<  56   delete particleGun;
 59     particleGun = new G4GeneralParticleSource( <<  57 
 60     calculatedPhaseSpaceFileIN = "NULL";       <<  58   delete gunMessenger;
 61 }                                                  59 }
                                                   >>  60   
                                                   >>  61 void HadrontherapyPrimaryGeneratorAction::SetDefaultPrimaryParticle()
                                                   >>  62 {    
                                                   >>  63   // ****************************
                                                   >>  64   // Default primary particle
                                                   >>  65   // ****************************
                                                   >>  66   
                                                   >>  67   // Define primary particles: protons
                                                   >>  68   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
                                                   >>  69   G4ParticleDefinition* particle = particleTable -> FindParticle("proton");
                                                   >>  70   particleGun -> SetParticleDefinition(particle); 
                                                   >>  71 
                                                   >>  72   // Define the energy of primary particles:
                                                   >>  73   // gaussian distribution with mean energy = 62.0 *MeV
                                                   >>  74   // and sigma = 400.0 *keV
                                                   >>  75   G4double defaultMeanKineticEnergy = 62.0 *MeV;
                                                   >>  76   meanKineticEnergy = defaultMeanKineticEnergy;
                                                   >>  77 
                                                   >>  78   G4double defaultsigmaEnergy = 400.0 *keV;
                                                   >>  79   sigmaEnergy = defaultsigmaEnergy;
                                                   >>  80   
                                                   >>  81 #ifdef G4ANALYSIS_USE_ROOT
                                                   >>  82   // Write these values into the analysis if needed. Have to be written separately on change.
                                                   >>  83   HadrontherapyAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);
                                                   >>  84 #endif
                                                   >>  85 
                                                   >>  86   // Define the parameters of the initial position: 
                                                   >>  87   // the y, z coordinates have a gaussian distribution
                                                   >>  88   
                                                   >>  89   G4double defaultX0 = -3000.0 *mm;
                                                   >>  90   X0 = defaultX0;
                                                   >>  91 
                                                   >>  92   G4double defaultY0 = 0.0 *mm;  
                                                   >>  93   Y0 = defaultY0;
                                                   >>  94 
                                                   >>  95   G4double defaultZ0 = 0.0 *mm;  
                                                   >>  96   Z0 = defaultZ0;
                                                   >>  97 
                                                   >>  98   G4double defaultsigmaY = 1. *mm;  
                                                   >>  99   sigmaY = defaultsigmaY;
                                                   >> 100 
                                                   >> 101   G4double defaultsigmaZ = 1. *mm;  
                                                   >> 102   sigmaZ = defaultsigmaZ;
                                                   >> 103 
                                                   >> 104   // Define the parameters of the momentum of primary particles: 
                                                   >> 105   // The momentum along the y and z axis has a gaussian distribution
                                                   >> 106   G4double defaultsigmaMomentumY = 0.0;  
                                                   >> 107   sigmaMomentumY = defaultsigmaMomentumY;
 62                                                   108 
 63 ////////////////////////////////////////////// << 109   G4double defaultsigmaMomentumZ = 0.0;  
 64 HadrontherapyPrimaryGeneratorAction::~Hadronth << 110   sigmaMomentumZ = defaultsigmaMomentumZ;
 65 {                                              << 
 66     delete PrimaryGeneratorMessenger;          << 
 67     delete particleGun;                        << 
 68 }                                                 111 }
 69                                                   112 
 70 ////////////////////////////////////////////// << 
 71 void HadrontherapyPrimaryGeneratorAction::Gene    113 void HadrontherapyPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
 72 {                                                 114 {
 73   if(fNewSource==true)                         << 115 #ifdef G4ANALYSIS_USE_ROOT
                                                   >> 116   // Increment the event counter
                                                   >> 117   HadrontherapyAnalysisManager::GetInstance()->startNewEvent();
                                                   >> 118 #endif
                                                   >> 119 
                                                   >> 120   // ****************************************
                                                   >> 121   // Set the beam angular apread 
                                                   >> 122   // and spot size
                                                   >> 123   // beam spot size
                                                   >> 124   // ****************************************
                                                   >> 125 
                                                   >> 126   // Set the position of the primary particles
                                                   >> 127   G4double x = X0;
                                                   >> 128   G4double y = Y0;
                                                   >> 129   G4double z = Z0;
                                                   >> 130 
                                                   >> 131   if ( sigmaY > 0.0 )
                                                   >> 132     {
                                                   >> 133       y += G4RandGauss::shoot( Y0, sigmaY );
                                                   >> 134     }
                                                   >> 135  
                                                   >> 136   if ( sigmaZ > 0.0 )
 74     {                                             137     {
 75       std::ifstream in(calculatedPhaseSpaceFil << 138       z += G4RandGauss::shoot( Z0, sigmaZ );
 76       G4double e, xpos, ypos, zpos,dirx,diry,d << 
 77       G4int PDG;                               << 
 78       G4ThreeVector pos,dir;                   << 
 79                                                << 
 80       if(in.eof())                             << 
 81         {                                      << 
 82     G4Exception("HadrontherapyPrimaryGenerator << 
 83         }                                      << 
 84                                                << 
 85       while(!in.eof())                         << 
 86         {                                      << 
 87                                                << 
 88     in >> e >> xpos >> ypos >>zpos >>dirx>>dir << 
 89     dir= G4ThreeVector(dirx,diry,dirz);        << 
 90     particleGun->GetCurrentSource()->GetEneDis << 
 91                                                << 
 92     particleGun->GetCurrentSource()->GetPartic << 
 93     particleGun->GetCurrentSource()->GetPartic << 
 94     particleGun->GetCurrentSource()->GetPartic << 
 95     particleGun->GetCurrentSource()->GetAngDis << 
 96                                                << 
 97     G4ParticleDefinition* particleDef = nullpt << 
 98     if (PDG > 1000000000)                      << 
 99             {                                  << 
100         int a=(PDG-1000000000)-(((PDG-10000000 << 
101         if(a>0)                                << 
102                 {                              << 
103       PDG=PDG-a;                               << 
104       particleDef = G4IonTable::GetIonTable()- << 
105       G4String Nome = particleDef->GetParticle << 
106                 }                              << 
107                                                << 
108         else                                   << 
109                 {                              << 
110       particleDef = G4IonTable::GetIonTable()- << 
111       G4String Nome = particleDef->GetParticle << 
112                 }                              << 
113             }                                  << 
114                                                << 
115     else                                       << 
116             {                                  << 
117         particleDef = G4ParticleTable::GetPart << 
118             }                                  << 
119                                                << 
120     particleGun->GetCurrentSource()->SetPartic << 
121     particleGun->GeneratePrimaryVertex(anEvent << 
122                                                << 
123         }                                      << 
124                                                << 
125         in.close();                            << 
126                                                << 
127     }                                             139     }
128     else                                       << 140 
                                                   >> 141   particleGun -> SetParticlePosition(G4ThreeVector( x , y , z ) );
                                                   >> 142  
                                                   >> 143   // ********************************************
                                                   >> 144   // Set the beam energy and energy spread
                                                   >> 145   // ********************************************
                                                   >> 146 
                                                   >> 147   G4double kineticEnergy = G4RandGauss::shoot( meanKineticEnergy, sigmaEnergy );
                                                   >> 148   particleGun -> SetParticleEnergy ( kineticEnergy );
                                                   >> 149 
                                                   >> 150   // Set the direction of the primary particles
                                                   >> 151   G4double momentumX = 1.0;
                                                   >> 152   G4double momentumY = 0.0;
                                                   >> 153   G4double momentumZ = 0.0;
                                                   >> 154 
                                                   >> 155   if ( sigmaMomentumY  > 0.0 )
                                                   >> 156     {
                                                   >> 157       momentumY += G4RandGauss::shoot( 0., sigmaMomentumY );
                                                   >> 158     }
                                                   >> 159   if ( sigmaMomentumZ  > 0.0 )
129     {                                             160     {
130         particleGun->GeneratePrimaryVertex(anE << 161       momentumZ += G4RandGauss::shoot( 0., sigmaMomentumZ );
131     }                                             162     }
132                                                << 163  
                                                   >> 164   particleGun -> SetParticleMomentumDirection( G4ThreeVector(momentumX,momentumY,momentumZ) );
                                                   >> 165 
                                                   >> 166   // Generate a primary particle
                                                   >> 167   particleGun -> GeneratePrimaryVertex( anEvent ); 
                                                   >> 168 } 
                                                   >> 169 
                                                   >> 170 void HadrontherapyPrimaryGeneratorAction::SetmeanKineticEnergy (G4double val )  
                                                   >> 171 {
                                                   >> 172   meanKineticEnergy = val;
                                                   >> 173 #ifdef G4ANALYSIS_USE_ROOT
                                                   >> 174   // Update the beam-data in the analysis manager
                                                   >> 175   HadrontherapyAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);
                                                   >> 176 #endif
                                                   >> 177 
                                                   >> 178 } 
                                                   >> 179 
                                                   >> 180 void HadrontherapyPrimaryGeneratorAction::SetsigmaEnergy (G4double val )  
                                                   >> 181 { 
                                                   >> 182   sigmaEnergy = val;
                                                   >> 183 #ifdef G4ANALYSIS_USE_ROOT
                                                   >> 184   // Update the sigmaenergy in the metadata.
                                                   >> 185   HadrontherapyAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);
                                                   >> 186 #endif
133 }                                                 187 }
134                                                   188 
                                                   >> 189 void HadrontherapyPrimaryGeneratorAction::SetXposition (G4double val )  
                                                   >> 190 { X0 = val;}
                                                   >> 191 
                                                   >> 192 void HadrontherapyPrimaryGeneratorAction::SetYposition (G4double val )  
                                                   >> 193 { Y0 = val;}
                                                   >> 194 
                                                   >> 195 void HadrontherapyPrimaryGeneratorAction::SetZposition (G4double val )  
                                                   >> 196 { Z0 = val;}
                                                   >> 197 
                                                   >> 198 void HadrontherapyPrimaryGeneratorAction::SetsigmaY (G4double val )  
                                                   >> 199 { sigmaY = val;}
                                                   >> 200 
                                                   >> 201 void HadrontherapyPrimaryGeneratorAction::SetsigmaZ (G4double val )  
                                                   >> 202 { sigmaZ = val;}
                                                   >> 203 
                                                   >> 204 void HadrontherapyPrimaryGeneratorAction::SetsigmaMomentumY (G4double val )  
                                                   >> 205 { sigmaMomentumY = val;}
                                                   >> 206 
                                                   >> 207 void HadrontherapyPrimaryGeneratorAction::SetsigmaMomentumZ (G4double val )  
                                                   >> 208 { sigmaMomentumZ = val;}
                                                   >> 209 
                                                   >> 210 G4double HadrontherapyPrimaryGeneratorAction::GetmeanKineticEnergy(void)
                                                   >> 211 { return meanKineticEnergy;}
135                                                   212 
136                                                   213