# Using GetEntries()

**URL:** <https://root-forum.cern.ch/t/using-getentries/52582>\
**Category:** ROOT\
**Created:** [December 1, 2022, 6:37pm UTC](https://root-forum.cern.ch/t/using-getentries/52582 "2022-12-01T18:37:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charlie](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/d6d6ee/32.png) [@Charlie](https://root-forum.cern.ch/u/Charlie)\
**Post date:** [December 1, 2022, 6:37pm UTC](https://root-forum.cern.ch/t/using-getentries/52582/1 "2022-12-01T18:37:01Z")

</div>

Hello,

I’m trying to find a way to get the final amount of entries for one of x scatter plots in the an array of scatter plots. I’m also trying to fill these scatter plots using the floor function. I used a similar method method that I posted before on this forum. I will provide the link below. When I use GetEntries() in a string output in my code, the terminal spits out the amount of entries as the code compiles, which cause multiple lines to print out and it’s too much to keep track of when the root files I’m using have 100 million events each. I just want my code to output one number which would be the total number of entries, and I’m not sure what I need to change in my code in order to do that. I’ll provide some parts of my code to show what I have so far. I hope to hear a response soon. Thanks in advance.

-Charlie Clark

Code:

Code that creates arrays of scatter plots.

```auto
    for (Int_t i = 0; i < x; i++){
      TString nameA1 = Form("hA%d",i);
      TString nameA2 = Form("%dmrad<Angle<%dmrad Cut;X-Position [m];Y-Position [m]",i,i+1);
      hA[i] = new TH2F(nameA1,nameA2,400,-0.07,0.07,400,-0.15,0.15);
      hA[i]->SetMarkerStyle(3);
    }
    for (Int_t j = 0; j < x; j++){
      TString nameAMol1 = Form("hAMol%d",j);
      TString nameAMol2 = Form("Moller %dmrad<Angle<%dmrad Cut;X-Position [m];Y-Position [m]",j,j+1);
      hAMol[j] = new TH2F(nameAMol1,nameAMol2,400,-0.07,0.07,400,-0.15,0.15);
      hAMol[j]->SetMarkerStyle(3);
      hAMol[j]->SetMarkerColor(kRed);
    }
    for (Int_t k = 0; k < x; k++){
      TString nameAMot1 = Form("hAMot%d",k);
      TString nameAMot2 = Form("Mott %dmrad<Angle<%dmrad Cut;X-Position [m];Y-Position [m]",k,k+1);
      hAMot[k] = new TH2F(nameAMot1,nameAMot2,400,-0.07,0.07,400,-0.15,0.15);
      hAMot[k]->SetMarkerStyle(3);
      hAMot[k]->SetMarkerColor(kBlue);
    }

```

Code that fills and gives amount of entries for each scatter plot.

```auto
for (Int_t j = 0; j < hitN; j++){
        //Double_t hitxy = TMath::Sqrt(TMath::Sq(hitX[j])+TMath::Sq(hitLy[j]));
        Double_t hitPxy = TMath::Sqrt(TMath::Sq(hitPx[j])+TMath::Sq(hitPy[j]));
        //if (hitPxy >= 0 && hitPxy <= (.3*B_1*R_s1*TMath::Sin(0.05)) && hitPz[j] >= (.3*B_1*R_s1*TMath::Cos(0.05)) && hitPz[j] <= (.3*B_1*R_l1)) continue;
        Double_t a = TMath::ATan(hitPxy/hitPz[j]);
        //Double_t b = TMath::ATan(hitxy/hitZ[j]);
        //Double_t b1 = TMath::Sqrt(2*m*(E-hitE[j])/(E*hitE[j]));
        //Double_t b2 = TMath::Sqrt(2*m*hitE[j]/(E*(E+m)-E*hitE[j]));
        //Double_t c = TMath::Sqrt(2*M*(E-hitE[j])/(E*hitE[j]));
        //Double_t p = TMath::ATan(m/((E+m)*TMath::Tan(b/2)));

        //if ( a < 0.0001 ) continue;

//Plotting Scattering Angle vs. Energy on 1st flux plane (entrance to 1st quadrupole)
        Int_t i = floor(a*1000);
        if (hitDet[j]==1 && i >= 0 && i < x) hA[i]->Fill ( hitX[j] , hitLy[j] );
        if (hitDet[j]==1 && i >= 0 && i < x && hitE[j]>(E/(1+(E/m)*(1-TMath::Cos(i/1000)))) && hitE[j]<(E/(1+(E/m)*(1-TMath::Cos((i+1)/1000))))) {
          hAMol[i]->Fill ( hitX[j] , hitLy[j] );
          TString MolEn = Form("Moller Entries %dmrad<Angle<%dmrad: ",i,i+1);
          std::cout << MolEn << hAMol[i]->GetEntries() <<"\n";
        }
        //TString MolEn = Form("Moller Entries %dmrad<Angle<%dmrad: ",i,i+1);
        //std::cout << MolEn << hAMol[i]->GetEntries() <<"\n";
        if (hitDet[j]==1 && i >= 0 && i < x && hitE[j]>(E/(1+(E/M)*(1-TMath::Cos(i)))) && hitE[j]<(E/(1+(E/M)*(1-TMath::Cos((i+1)/1000))))) {
          hAMot[i]->Fill ( hitX[j] , hitLy[j] );
          TString MotEn = Form("Mott Entries %dmrad<Angle<%dmrad: ",i,i+1);
          std::cout << MotEn << hAMot[i]->GetEntries() << "\n";
        }

```

ROOT Version: 6.26/06  
Platform: Ubuntu 22  
Compiler: from file root\_v6.26.06.Linux-ubuntu22-x86\_64-gcc11.2.tar.gz

Forum of using the floor function to fill histograms:

> [@Root crashed after trying to analyze more events](https://root-forum.cern.ch/t/root-crashed-after-trying-to-analyze-more-events/52033):
>
> 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 r…

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [December 2, 2022, 9:10am UTC](https://root-forum.cern.ch/t/using-getentries/52582/2 "2022-12-02T09:10:13Z")

</div>

> [@Charlie](#):
>
> which cause multiple lines to print out and it’s too much

May be I misundersttod what you are doing but it looks like you are printing `GetEntries` in a loop. That would explain why you are getting it so many times. Simply print it outsie of the loop.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [December 16, 2022, 9:11am UTC](https://root-forum.cern.ch/t/using-getentries/52582/3 "2022-12-16T09:11:08Z")

</div>

Closed on December 16, 2022, 9:11am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
