Hello, guys.
I started learning Geant4.
I want to count the number of gamma rays produced after passing the target. Please tell me how to do it correctly. Thanks for the answer.
#include “detector.hh”
#include “G4ParticleDefinition.hh”
#include “G4DynamicParticle.hh”
#include “G4Step.hh”
#include “G4Track.hh”
#include “G4ParticleTable.hh”
//////////#include “G4ParticleTable.hh”
#include “G4Gamma.hh”
#include
#include
#include “G4SystemOfUnits.hh”
#include “G4ThreeVector.hh”
using namespace std;
///////////////
MySensitiveDetector::MySensitiveDetector(G4String name) : G4VSensitiveDetector(name)
{}
MySensitiveDetector::~MySensitiveDetector()
{}
G4bool MySensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
{
// Retrieve from the current step the track (after PostStepDoIt of step is completed)
G4Track *track = aStep->GetTrack();
// From the track you can obtain the pointer to the dynamic particle
const G4DynamicParticle* dynamicParticle = track ->GetDynamicParticle();
// From the dynamic particle, retrieve the particle definition
G4ParticleDefinition* particle = dynamicParticle ->GetDefinition();
//G4String particleName = particle ->GetParticleName();
if (track->GetDefinition() == G4Gamma::Definition()) { G4cout << " got a photon " << G4endl}