I am creating a LaBr3 scintillator but getting more particle deposits than particles thrown

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

_Geant4 Version:_v11.2.0
_Operating System:_macOS Sonoma
_Compiler/Version:_clang-1500.1.0.2.5
_CMake Version:_3.29.0-rc3

I have created a simulation of LaBr3:CE but when I am working on 10^5 particles I am getting too many depositions. Here is my detetctor and generator code.

**#include “detector.hh”

MySensitiveDetector::MySensitiveDetector(G4String name) : G4VSensitiveDetector(name)
{}

MySensitiveDetector::~MySensitiveDetector()
{}

G4bool MySensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
{
// G4cout << “~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~” << G4endl;

number_of_interactions = number_of_interactions + 1;

    G4cout << "number_of_interactions: " << number_of_interactions << G4endl;

G4Track *track = aStep->GetTrack();
G4int trackID = track->GetTrackID();
G4double kenergy = track->GetKineticEnergy();
{

// G4cout << "Kinetic Energy: " << kenergy << G4endl;

    if (kenergy > 0) {
        kgammaparticleCount = kgammaparticleCount + 1;

// G4cout << "kgammaparticleCount: " << kgammaparticleCount << G4endl;

    }
    
    if(kenergy >= 662*keV) {
        ktotalgammaCount = ktotalgammaCount + 1;

// G4cout << "KEnergy deposited by a gamma particle: " << kenergy << G4endl;
// G4cout << "ktotalgammaCount: " << ktotalgammaCount << G4endl;

    }
}

// G4cout << "Deposition: " << kgammaparticleCount << G4endl;

// G4cout << trackID << G4endl;
//
// G4cout << kenergy << G4endl;

track->SetTrackStatus(fStopAndKill);

   const G4TrackVector* secondary = aStep->GetSecondary();
   for (size_t i = 0; i < secondary->size(); ++i) {
       G4Track* secondaryTrack = (*secondary)[i];
       const G4ParticleDefinition* daughterParticleDef = secondaryTrack->GetDefinition();
       
       G4String daughterParticleName = daughterParticleDef->GetParticleName();

// G4cout << "Daughter particle produced: " << daughterParticleName << G4endl;
}

G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
G4StepPoint *postStepPoint = aStep->GetPostStepPoint();

G4ThreeVector posGamma = preStepPoint->GetPosition();

// G4cout << "Gamma position: " << posGamma << G4endl;

const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();

G4int copyNo = touchable->GetCopyNumber();

// G4cout << "Copy number: " << copyNo << G4endl;

G4VPhysicalVolume *physVol = touchable->GetVolume();
G4ThreeVector posDetector = physVol->GetTranslation();

// G4cout << "Detector position: " << posDetector << G4endl;

// G4double energyDeposit = preStepPoint->GetTotalEnergy() - postStepPoint->GetTotalEnergy();
auto energyDeposit = aStep->GetTotalEnergyDeposit();
const G4ParticleDefinition* particleDef = track->GetDefinition();

if (particleDef->GetParticleName() == "gamma") {

// G4cout << "Energy deposited by a gamma particle: " << energyDeposit << G4endl;

    if (energyDeposit > 0) {
        gammaparticleCount = gammaparticleCount + 1;
        
    }
    
    if(energyDeposit >= 662*keV) {
        totalgammaCount = totalgammaCount + 1;

// G4cout << "Energy deposited by a gamma particle: " << energyDeposit << G4endl;
// G4cout << "totalgammaCount: " << totalgammaCount << G4endl;

    }
}

// G4cout << "Deposition: " << gammaparticleCount << G4endl;
//
// G4cout << "Energy: " << energyDeposit << G4endl;

if (energyDeposit > 0) {
    particleCount = particleCount + 1;
}

// G4cout << "Total Deposition: " << particleCount << G4endl;

G4int evt = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();

// G4cout << evt << G4endl;

G4AnalysisManager *man = G4AnalysisManager::Instance();
man->FillNtupleIColumn(0, 0, evt);
man->FillNtupleDColumn(0, 1, posDetector[0]);
man->FillNtupleDColumn(0, 2, posDetector[1]);
man->FillNtupleDColumn(0, 3, posDetector[2]);
man->AddNtupleRow(0);

man->FillNtupleDColumn(1, 0, kenergy);
man->FillNtupleIColumn(1, 1, gammaparticleCount);
man->FillNtupleIColumn(1, 2, trackID);

man->AddNtupleRow(1);

// G4cout << “xxxxxxxxxxxxxxxxxxxxxxx” << G4endl;

}
**

**#include “generator.hh”

MyPrimaryGenerator::MyPrimaryGenerator()
{
fParticleGun = new G4ParticleGun(100000);
}

MyPrimaryGenerator::~MyPrimaryGenerator()
{
delete fParticleGun;
}

void MyPrimaryGenerator::GeneratePrimaries(G4Event *anEvent)
{
G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
G4String particleName=“gamma”;
G4ParticleDefinition *particle = particleTable->FindParticle(“gamma”);

// G4ThreeVector pos(0., 0., -2mm);
G4ThreeVector pos(0., 0., -14.7
mm);
G4ThreeVector mom(0., 0., 1.);

fParticleGun->SetParticlePosition(pos);
fParticleGun->SetParticleMomentum(mom);
fParticleGun->SetParticleEnergy(662*keV);
fParticleGun->SetParticleDefinition(particle);

fParticleGun->GeneratePrimaryVertex(anEvent);

eventCount = eventCount + 1;

// G4cout << “--------------------” << G4endl;

// G4cout << "eventCount: " << eventCount << G4endl;
}

**

Please see the pinned post :How to post code snippets as it’s otherwise a bit difficult to makes sense of things.

Also, what do you mean by “too many depositions”?