Hello,

I’m running a simulation package in GEANT4 that simulates electron-iron atom scattering. Two events are simulated in this simulation: electron-electron scattering and electron-iron nucleus scattering. I’m using root to plot histograms for the energy of the scattered electrons based on a range of scattering angles in mrads. The amount of entries that I have are to large to run and get the plots in a short amount of time, so I decrease the amount of entries so that can I see if I have to right results. After increasing the entries, even by a magnitude by 10, I get a crash message. When I usually see that, I try to see where the mistake is in my, but I I’m sure enough that it should work no matter the amount of entries. Long story short, my code should work for any amount entries, but if I go larger than 0.01% of 7 billion root crashes. I will provide the code with some commits to explain my lines and the crash message. I hope to hear a response soon. Thanks in advance.

-Charlie Clark

_ROOT Version: 6.26/06

_Platform: Ubuntu 22

_Compiler: from file root_v6.26.06.Linux-ubuntu22-x86_64-gcc11.2.tar.gz

Code:

```
#define ScatteringAngle_cxx
#include "ScatteringAngle.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TMath.h>
void ScatteringAngle::Loop()
{
//Array of histograms with titles: radius between target and height of the detector.
Int_t m = 10;
TH1F * h[m];
for (Int_t i = 0; i < m; i++){
TString name1 = Form("h%d",i);
TString name2 = Form("r>%fcm;Energy [GeV];Frequency [arb]",TMath::Sqrt(TMath::Sq(i/10)+TMath::Sq(100)));
h[i] = new TH1F(name1,name2,200,0.0,2.2);
}
//TH1F * h2 = new TH1F("h2","Energy of All Electrons;Energy [GeV];Frequency [arb]",200,0.0,2.2);
//TH1F * h3 = new TH1F("h3","Energy of Electrons with Scattering Angles Greater than 1 mrad;Energy [GeV];Frequency [arb]",200,0.0,2.2);
/*for (Int_t i = 0; i < m; i++){
TString name1 = Form("h%d",i);
TString name2 = Form("r>%fmm",i/100.0);
h2[i] = new TH1F(name1,name2,200,0.0,2.2);
}*/
if (fChain == 0) return;
//First for loop goes through all of the entries. Amount of entries are in variable nentries=7e08.
Long64_t nentries = fChain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;
for (Long64_t jentry=0; jentry<nentries*0.0001;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
// if (Cut(ientry) < 0) continue;
//Second for loop goes through all of the events, calculates the scattering angles in rads, and fills the each histogram h[i] with energy of scattered electrons
//based on scattering angles. The floor function is used to cuts segments of the angles between entries i/1000 and (i+1)/1000. An example is commmented out where
//10 histograms are made with the floor function (the long way).
for (Int_t j = 0; j < hitN; j++){
Double_t a = TMath::ATan(TMath::Sqrt(TMath::Sq(hitPx[j])+TMath::Sq(hitPy[j]))/hitPz[j]);
Int_t i = floor(a*1000);
if (a>i/1000) h[i]->Fill ( hitE[j] );
if (a>0.001) std::cout << "Angle is (rad): " << a << "Floor function is: " << i << "\n";
/*if (a>0.0 && a<0.001) h[0]->Fill ( hitE[i] );
if (a>0.001 && a<0.002) h[1]->Fill ( hitE[i] );
if (a>0.002 && a<0.003) h[2]->Fill ( hitE[i] );
if (a>0.003 && a<0.004) h[3]->Fill ( hitE[i] );
if (a>0.004 && a<0.005) h[4]->Fill ( hitE[i] );
if (a>0.005 && a<0.006) h[5]->Fill ( hitE[i] );
if (a>0.006 && a<0.007) h[6]->Fill ( hitE[i] );
if (a>0.007 && a<0.008) h[7]->Fill ( hitE[i] );
if (a>0.008 && a<0.009) h[8]->Fill ( hitE[i] );
if (a>0.009 && a<0.01) h[9]->Fill ( hitE[i] );*/
}
}
//One canvas made to plot a histograms.
TCanvas * C1 = new TCanvas("C1","C1",3000,3000);
C1->Divide(5,2);
for (Int_t i = 0; i < m; i++){
C1->cd(i+1)->SetLogy(1);
h[i]->Draw();
}
/*TCanvas * C2 = new TCanvas("C2","C2",2000,2000);
C2->cd()->SetLogy(1);
h2->Draw();
TCanvas * C3 = new TCanvas("C3","C3",2000,2000);
C3->cd()->SetLogy(1);
h3->Draw();*/
}
```

Crash message:

```
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007fd9f504645a in __GI___wait4 (pid=4324, stat_loc=stat_loc
entry=0x7fff04640218, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1 0x00007fd9f504641b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7fff04640218, options=options
entry=0) at ./posix/waitpid.c:38
#2 0x00007fd9f4facbcb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:171
#3 0x00007fd9f56f82d4 in TUnixSystem::StackTrace() () from /home/tuo91122/root/lib/libCore.so.6.26
#4 0x00007fd9f56f55e5 in TUnixSystem::DispatchSignals(ESignals) () from /home/tuo91122/root/lib/libCore.so.6.26
#5 <signal handler called>
#6 0x00007fd9eef9a9fd in ?? ()
#7 0x00007fff04643518 in ?? ()
#8 0x01007fd9f3bfb613 in ?? ()
#9 0x00007fd9f53d2018 in ?? ()
#10 0x0000562281d59f10 in ?? ()
#11 0x00007fd9f0fb9380 in ?? () from /home/tuo91122/root/lib/libCling.so
#12 0x00000000edb74e00 in ?? ()
#13 0x0000000000000000 in ?? ()
===========================================================
The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6 0x00007fd9eef9a9fd in ?? ()
#7 0x00007fff04643518 in ?? ()
#8 0x01007fd9f3bfb613 in ?? ()
#9 0x00007fd9f53d2018 in ?? ()
#10 0x0000562281d59f10 in ?? ()
#11 0x00007fd9f0fb9380 in ?? () from /home/tuo91122/root/lib/libCling.so
#12 0x00000000edb74e00 in ?? ()
#13 0x0000000000000000 in ?? ()
===========================================================
```