# No of events in the bins

**URL:** <https://root-forum.cern.ch/t/no-of-events-in-the-bins/49512>\
**Category:** Newbie\
**Created:** [April 7, 2022, 5:23pm UTC](https://root-forum.cern.ch/t/no-of-events-in-the-bins/49512 "2022-04-07T17:23:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dil](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dil/32/26887_2.png) [@Dil](https://root-forum.cern.ch/u/Dil)\
**Post date:** [April 7, 2022, 5:23pm UTC](https://root-forum.cern.ch/t/no-of-events-in-the-bins/49512/1 "2022-04-07T17:23:51Z")

</div>

Hello rooters,  
I need to find out number of events in each bin.(see attached plot)  
For that I wrote a little code.I got 0 events . I am not sure why GetBinContent is not working.

```auto
void NoOfEvents(){
    int i_Q2_bins=4;
    int i_xBj=7;
    
    char histName[64];
   int events;
    
    TH1F *h_pion_invariant_mass[i_Q2_bins][i_xBj];
    
    TFile *hFile1=TFile::Open("MC_generated.root");
    hFile1->ls();
    
    for(int iQ2=0; iQ2 < i_Q2_bins; iQ2++){
        for(int ixB=0; ixB <i_xBj; ixB++ ){
        
            sprintf(histName,"h_pioninvariantmass_Q2%03d_xB%03d", iQ2,ixB);
            h_pion_invariant_mass[iQ2][ixB]=(TH1F *) hFile1->Get(histName);
            events = h_pion_invariant_mass[iQ2][ixB]->GetBinContent(iQ2,ixB);
            printf("events_Q2%03d_xB%03d = %d \n",iQ2,ixB,events);
        }
    }
    
    
    
}

```

```auto
events_Q2000_xB000 = 0 
events_Q2000_xB001 = 0 
events_Q2000_xB002 = 0 
events_Q2000_xB003 = 0 
events_Q2000_xB004 = 0 
events_Q2000_xB005 = 0 
events_Q2000_xB006 = 0 
events_Q2001_xB000 = 0 
events_Q2001_xB001 = 0 
events_Q2001_xB002 = 0 
events_Q2001_xB003 = 0 
events_Q2001_xB004 = 0 
events_Q2001_xB005 = 0 
events_Q2001_xB006 = 0 
events_Q2002_xB000 = 0 
events_Q2002_xB001 = 0 
events_Q2002_xB002 = 0 
events_Q2002_xB003 = 0 
events_Q2002_xB004 = 0 
events_Q2002_xB005 = 0 
events_Q2002_xB006 = 0 
events_Q2003_xB000 = 0 
events_Q2003_xB001 = 0 
events_Q2003_xB002 = 0 
events_Q2003_xB003 = 0 
events_Q2003_xB004 = 0 
events_Q2003_xB005 = 0 
events_Q2003_xB006 = 0 

```

Something wrong?? any help would be greatly apperciated.

Thanks  
Dil

 ![Screen Shot 2022-04-07 at 11.36.31 AM](https://root-forum.cern.ch/uploads/default/original/3X/2/e/2edf7603be264993a21e172d64e26c85559bf680.png)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 7, 2022, 5:27pm UTC](https://root-forum.cern.ch/t/no-of-events-in-the-bins/49512/2 "2022-04-07T17:27:47Z")

</div>

Maybe you want:  
`events = h_pion_invariant_mass[iQ2][ixB]->Integral(iQ2, ixB);`  
or:  
`events = h_pion_invariant_mass[iQ2][ixB]->Integral();`

---

<div class="post-metadata">

**Author:** ![Dil](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dil/32/26887_2.png) [@Dil](https://root-forum.cern.ch/u/Dil)\
**Post date:** [April 7, 2022, 5:29pm UTC](https://root-forum.cern.ch/t/no-of-events-in-the-bins/49512/3 "2022-04-07T17:29:36Z")

</div>

You must be right.Thank you for the suggestion.
