Home | News | Documentation | Download

Question about TTree->Draw() methode


#1

Hi,

I need you to help me about how to get values contained inside my TTree.

I know that I have to do something like:


TFile* f = TFile::Open("name_of_file");
TTree* tree = (TTree*)f->Get("my_ttree");

tree->Draw("parameter>>h1()","cut1");
TH1F* htemp1 = (TH1F*)gDirectory->Get("h1");
float* tmp_tab = htemp1->GetArray();

My problem is that:
I have a 5 TBranch TTree. One is called “seed”, an other “time” and the last one wich interest us is “n” <=> the number of detection for a time between t and t+dt.
“seed” is a value between 1 and 5 that give me the origine of my datas (those datas come from 5 differents files).
When I want to draw “n” over “time” like this:


tree->Draw("n:time>>hist_tmp()","r==40");

I see 5 point by time value for number of detection “n”.
Those 5 values are the 5 files I speaked before.

I don’t want 5 but 1 value that give me the total number of detection for a time between t and t+dt.

I tried something like this:


tree->Draw("n*5:time>>hist_tmp()","r==40","prof");

But all I get in hist_tmp is zero values…

Do you know why this happened ?
Why this not happen with “r” values if I put nothing for the TString cut1 value like this: ?


tree->Draw("n:time>>hist_tmp()","");

Cheers,
William

PS: This is all my files:
converted_group_1.root (7.6 KB)
main.cpp (383 Bytes)


Read values from root file
#2

tree->Draw("n >> hist_tmp", "r==40"); TH1F *htemp1 = (TH1F *)gDirectory->Get("hist_tmp"); // assumes Hist.Precision.1D: float

tree->Draw("n:time >> hist_tmp", "r==40"); TH2F *htemp1 = (TH2F *)gDirectory->Get("hist_tmp"); // assumes Hist.Precision.2D: float

tree->Draw("n:time >> hist_tmp", "r==40", "prof"); TProfile *htemp1 = (TProfile *)gDirectory->Get("hist_tmp");


#3

Hi,

I tried the three solution but it don’t change anything : the values are still zero.

More than that, I can’t understand why their is multiple “n” values for each time bin…
I just want to get the total number of detection per each time bin and put it into an histogramme.

Regard,
William


#4

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


#5

More than that, I can’t understand why their is multiple “n” values for each time bin…

Please re-read the documentation of TH1F, TH2F and TProfile and in particular the difference between the three.

just want to get the total number of detection per each time bin and put it into an histogramme.

Maybe you are insterested in the concept of weight and this is the graph you are looking for:

tree->Draw("time","(r==40)*n","");

Cheers,
Philippe.