Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:20:26

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 //  Author: F. Poignant, floriane.poignant@gmail.com
0027 // 
0028 // file STyclotronPrimaryGeneratorAction.cc
0029 
0030 #include "STCyclotronPrimaryGeneratorAction.hh"
0031 #include "STCyclotronRun.hh"
0032 
0033 #include "G4RunManager.hh"
0034 #include "G4Event.hh"
0035 #include "G4GeneralParticleSource.hh"
0036 #include "G4ParticleTable.hh"
0037 #include "G4ParticleDefinition.hh"
0038 #include "G4SystemOfUnits.hh"
0039 #include "STCyclotronPrimaryGeneratorActionMessenger.hh"
0040 
0041 STCyclotronPrimaryGeneratorAction::STCyclotronPrimaryGeneratorAction()
0042   : G4VUserPrimaryGeneratorAction()
0043 {
0044   fMessenger = new STCyclotronPrimaryGeneratorActionMessenger(this);
0045   fParticleBeam  = new G4GeneralParticleSource();
0046   fBeamCurrent = 10.E-6 ; //ampere;
0047   //The rest of the parameters (type of particle, energy, beam shape ..) are defined in the init_beam.vis class.
0048 }
0049 
0050 STCyclotronPrimaryGeneratorAction::~STCyclotronPrimaryGeneratorAction()
0051 {
0052   delete fMessenger;
0053   delete fParticleBeam;
0054 }
0055 
0056 void STCyclotronPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0057 {
0058   //Set up the number of particles per event 
0059   G4double timePerEvent = 1.E-11 ; //s;
0060   G4double chargeParticle = fParticleBeam->GetParticleDefinition()->GetPDGCharge()*1.6E-19;
0061   G4double numberOfPart = std::abs(fBeamCurrent*timePerEvent/chargeParticle); 
0062   G4String name = fParticleBeam->GetParticleDefinition()->GetParticleName();
0063  // G4double energy = fParticleBeam->GetParticleEnergy();
0064   G4double energy = fParticleBeam -> GetCurrentSource()->GetEneDist()->GetMonoEnergy();
0065   G4int fPrimariesPerEvent = (G4int)numberOfPart;
0066   
0067   if(fPrimariesPerEvent < 1){
0068     G4cout << "Warning: number of particles per event below 0: " << numberOfPart << G4endl;
0069     return;
0070   }
0071 
0072   fParticleBeam->SetNumberOfParticles(fPrimariesPerEvent);
0073   fParticleBeam->GeneratePrimaryVertex(anEvent);
0074   
0075   STCyclotronRun* fRun = static_cast<STCyclotronRun*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0076   fRun->SetPrimariesPerEvent(fPrimariesPerEvent);
0077   fRun->SetTimePerEvent(timePerEvent);
0078 
0079   fRun->SetBeamName(name);
0080   fRun->SetBeamCurrent(fBeamCurrent);
0081   fRun->SetBeamEnergy(energy);
0082   
0083   //G4cout << "The new beam current is the following : " << fBeamCurrent << " Ampere." << G4endl;
0084   //G4cout << "Particles per event : " << numberOfParticlePerEvent << " particles." << G4endl;
0085 
0086 }
0087 
0088 void STCyclotronPrimaryGeneratorAction::SetBeamCurrent(G4double current)
0089 {
0090   if(fBeamCurrent!=current){
0091     fBeamCurrent=current;
0092     G4cout << "The new beam current is the following : " << fBeamCurrent << " Ampere." << G4endl;
0093   } 
0094 }