TH1::GetSum() of a defined interval

Hello,

I’m using the GetSum() method to sum all the electrons produced in a simulation, but I would like to sum only electrons with an energy >=1.5MeV, for example.

Is there an easy way to do this with GetSum()?

Thanks a lot.

TH1::Integral(Int_t binx1, Int_t binx2, Option_t* option = “”)
Note: In order to bind the “bin number”, use: TH1::FindFixBin

Thank you for the answer!

So, I want to sum from this energy threshold (1.5MeV) to the last bin:

double E_threshold = 1.5;

int first_bin_gamma = Object_Gamma->GetXaxis()->FindFixBin(E_threshold);
int last_bin_gamma = Object_Gamma->FindLastBinAbove(E_threshold,1);

double GammaSum = Object_Gamma->Integral(first_bin_gamma,last_bin_gamma);

Is that correct to use FindLastBinAbove()?

int first_bin_gamma = MyTH1->FindFixBin(E_threshold);
int last_bin_gamma = MyTH1->GetNbinsX(); // excluding the "overflow bin"
int last_bin_gamma = MyTH1->GetNbinsX() + 1; // including the “overflow bin”

Thanks a lot!

Worked perfectly.