Dear Rooters,
I have some data in a tree. Let admit I have a branch with peculiar values of “Time”.
- I fill an THF1 histogram with Time. For one Time value t_0, I would integrate the histogram for t>t_0, then iterate it for each t_i values for t_i > t_0. See my code :
#include <TH1F.h>
#include <TTree.h>
#include <TGraph.h>
using namespace std;
void root_extract(){
TFile *file = TFile::Open("file_name");
TTree *tree = (TTree*)file->Get("tree_name");
Double_t time;
tree->SetBranchAddress("time",&time);
TH1F *htime = new TH1F("h_time","Time histogram",nbins,xmin_time,xmax_time);
TH1F *hintegration = new TH1F("h_integration","Integration",nbins,xmin_integration,xmax_integration);
for (Long64_t i=0;i<nbins;i++) {
tree->GetEntry(i);
htime->Fill(time);
Double_t TimeBinContent = htime->GetBinContent(i);
Double_t TimeXValue = htime->GetXaxis()->GetBinCenter(i);
Int_t bin = htime->GetXaxis()->FindBin(i);
TAxis *axis = htime->GetXaxis();
Int_t bmin = axis->FindBin(TimeXValue);
Int_t bmax = axis->FindBin(xmax_time);
Double_t integral = (htime->Integral(bmin,bmax));
hintegration->Fill(integral);
}
}
I think this is working. But I’m not totally sure of what I am exactly doing, because I do not take into account the TimeBinContent of each bin : should I do
double integral = htime->Integral(bmin,bmax))*TimeBinContent;
?
- Filling an histogram with the TTree Time values lead to a lost of information, cause of the binning. Does it exist a way of doing this integration without filling a tree ? I mean, directly working with the TTree data
tree->GetEntry(i)
? Maybe something with GSLIntegrator ?
Thanks for the reading, hoping this is all clear.
Cloé
ROOT Version 6.08/06