So in this file there is a tree with some branches constructed in TH1F. In the command line I created a hist whith some branches (difference the KE(final and initial) per distance (using the eq: sqrt(sqrt(pow((Step_FinalPosX),2)+pow((Step_FinalPosY),2)+pow((Step_FinalPosZ),2)))) that generated a TH2F histogram. So, How can I selected a region of the distance and I generated a TH1F of difference KE?

I don’t know if I was clear, it’s possible understand?

#include "TFile.h"
#include "TTree.h"
#include "TRandom.h"
#include "TROOT.h"
#include "TBranch.h"
#include "TH1.h"
#include "TH2.h"
#include "Rtypes.h"
void test()
{
TFile *f = TFile::Open("testSIConInGALAIR35_tree_1000.root");
if ((!f) || f->IsZombie()) { delete f; return; } // just a precaution
f->ls();
TTree *t; f->GetObject("testSIConInGALAIR35", t);
if (!t) { delete f; return; } // just a precaution
t->Print();
gROOT->cd();
// create one 3D histogram
TH2F *h = new TH2F("EXD", "Energy versus distance from the center",
100, 0.0, 13.,
100, 0., 0.03849);
#if 1 /* 0 or 1 */
//Double_t SQ = sqrt(pow((Step_FinalPosX),2)+pow((Step_FinalPosY),2)+pow((Step_FinalPosZ),2));
//Double_t delta_KIN = (Step_InitialKineticEnergy-Step_FinalKineticEnergy);
t->Project("EXD", "(Step_InitialKineticEnergy-Step_FinalKineticEnergy):(sqrt(pow((Step_FinalPosX),2)+pow((Step_FinalPosY),2)+pow((Step_FinalPosZ),2)))");
#else /* 0 or 1 */
Double_t Step_InitialKineticEnergy, Step_FinalKineticEnergy, Step_FinalPosX, Step_FinalPosY, Step_FinalPosZ;
t->SetBranchAddress("Step_InitialKineticEnergy", &Step_InitialKineticEnergy);
t->SetBranchAddress("Step_FinalKineticEnergy", &Step_FinalKineticEnergy);
t->SetBranchAddress("Step_FinalPosX", &Step_FinalPosX);
t->SetBranchAddress("Step_FinalPosY", &Step_FinalPosY);
t->SetBranchAddress("Step_FinalPosZ", &Step_FinalPosZ);
//read all entries and fill the histograms
Long64_t n = t->GetEntries();
for (Long64_t i = 0; i < n; i++) {
t->GetEntry(i);
h->Fill(Step_InitialKineticEnergy,
Step_FinalKineticEnergy,
Step_FinalPosX,
Step_FinalPosY,
Step_FinalPosZ
);
}
#endif /* 0 or 1 */
// This is to selected for each bin of X the sum of the values in Y and then draw it
int n2 = GetBin();
for(int i=0;i<n2;i++){
float y[i] = h->sum(GetYAxis(i));
for(int j=0;j<n2;j++)){
float y1[i]= y1[i] + y[i];
}
}
// h->SetDirectory(gROOT); // (gROOT) ... or ... (0)
//h->Draw("hist C");
h->Draw("hist C");
//TProfile *h1 = h->ProfileY("EXD_1D", 2, 97); // where firstXbin = 0 and lastXbin = 9
//h1->Draw("hist C");
// t->ResetBranchAddresses(); // "disconnect" from local variables
delete f; // automatically deletes "t", too
}

But it is an error always in the function GetBin().

But what I wanted is a graphic Energy versus distance ( (Step_InitialKineticEnergy-Step_FinalKineticEnergy):(sqrt(pow((Step_FinalPosX),2)+pow((Step_FinalPosY),2)+pow((Step_FinalPosZ),2)))) in TH1F.

May I ask other question: I need is to for each bin of the X axis I want to calculated the sum of the values in Y and then put this in a new Th1f histogram, how could I do it?