Hello, I was wondering if anyone could help me with this.
I am trying to simulate a tau- and tau+ decay. I successfully coded the tau- decay, but then I was told to introduce “with equal probability” a tau+ in the simulation, so I tried to do the following:
/// \file AmBePrimaryGeneratorAction.cc
/// \brief Implementation of the AmBePrimaryGeneratorAction class; adapted from
/// Geant4 example B5 B5PrimaryGeneratorAction.cc
#include "AmBePrimaryGeneratorAction.hh"
#include "G4Event.hh"
#include "G4ParticleTable.hh"
#include "G4IonTable.hh"
#include "G4ParticleDefinition.hh"
#include "G4Geantino.hh"
#include "G4SystemOfUnits.hh"
#include "G4RandomDirection.hh"
#include "Randomize.hh"
#include <iostream>
#include <cstdlib>
#include <ctime>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
AmBePrimaryGeneratorAction::AmBePrimaryGeneratorAction()
{
fParticleGun = new G4ParticleGun(1);
G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
G4ParticleDefinition *particle = particleTable->FindParticle("geantino");
G4ThreeVector pos(0., 0., 0.);
G4ThreeVector mom(0., 0., 1.);
fParticleGun->SetParticlePosition(pos);
fParticleGun->SetParticleMomentumDirection(mom);
fParticleGun->SetParticleMomentum(0.*GeV);
fParticleGun->SetParticleDefinition(particle);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
AmBePrimaryGeneratorAction::~AmBePrimaryGeneratorAction()
{
delete fParticleGun;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void AmBePrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
//create vertex
G4ParticleDefinition *particle = fParticleGun->GetParticleDefinition();
G4double r = ((double) rand() / (RAND_MAX));
if(particle == G4Geantino::Geantino())
{
G4double energy_tot = 45000 - 1776.8600;
G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
if(r >= 0.5){
G4ParticleDefinition *particle = particleTable->FindParticle("tau-");
}
else{
G4ParticleDefinition *particle = particleTable->FindParticle("tau+");
}
fParticleGun->SetParticleEnergy(energy_tot*MeV);
fParticleGun->SetParticlePosition(G4ThreeVector(0.,0.,0.));
fParticleGun->SetParticleMomentumDirection(G4RandomDirection());
fParticleGun->SetParticleDefinition(particle);
}
fParticleGun->GeneratePrimaryVertex(anEvent);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
The only thing that I changed from the first tau- simulation is that I introduced that new variable “r” and the if else condition, but I does not work.
Anyone could help me understand why it does not work and how to make it do? Thank you so much in advance, Diego.