Create Histogram from a TTree in a root file

Hello Rooters,

I have a root file that contains two TTrees called raw_0;1 and raw_0;2. If I type raw_0;1->Scan() in cint, off course I get an error. If type raw_0->Print() I get the contents of the TTree ( I assume it’s the contents of the raw_0;2 i.e. the last cycle) which look like this

[code]******************************************************************************
*Tree :raw_0 : raw_0 *
*Entries : 89999999 : Total = 180284406 bytes File Size = 57151337 *

  •    :          : Tree compression factor =   3.15                       *
    

*Br 0 :signal_y : signal_y/S *
*Entries : 89999999 : Total Size= 180284076 bytes File Size = 57124673 *
*Baskets : 2956 : Basket Size= 3200000 bytes Compression= 3.15 *

[/code]

The problem is that I want to access both trees but I don’t know how to do it since I get puzzled about the “;” character.

Any idea on how to do it?

Thanks in advance!

Talk to the person who created these trees and ask to recreate them with two different names (e.g. “raw_0” and “raw_1”).

Well, that seems very difficult now…
So you’re implying that there is no way around it?

Regards

Usually, a new “cycle” contains all the data from all previous cycles. So, “;2” contains everything that “;1” has, plus additional new events (in other words, usually these are not two different trees).

Oh, I see…
This is very bad…
But in any case, how can I access both cycles?
If fir instance I make a histogram out of them I could subtract them to get them separately.

What do you get when you try: { TFile *f = TFile::Open("your_file.root"); TTree *t; t = (TTree*)f->Get("raw_0;1"); t->Print(); delete t; t = (TTree*)f->Get("raw_0;2"); t->Print(); delete t; t = (TTree*)f->Get("raw_0"); t->Print(); delete t; }

TFile *f = TFile::Open("your_file.root"); TTree *t; t = (TTree*)f->Get("raw_0;1"); t->Print();

I get

[code]******************************************************************************
*Tree :raw_0 : raw_0 *
*Entries : 46733808 : Total = 93749336 bytes File Size = 30027042 *

  •    :          : Tree compression factor =   3.12                       *
    

*Br 0 :signal_y : signal_y/S *
*Entries : 46733808 : Total Size= 93749006 bytes File Size = 30000378 *
*Baskets : 2928 : Basket Size= 3200000 bytes Compression= 3.12 *
[/code]

While for the second tree

[code]******************************************************************************
*Tree :raw_0 : raw_0 *
*Entries : 89999999 : Total = 180284406 bytes File Size = 57151337 *

  •    :          : Tree compression factor =   3.15                       *
    

*Br 0 :signal_y : signal_y/S *
*Entries : 89999999 : Total Size= 180284076 bytes File Size = 57124673 *
*Baskets : 2956 : Basket Size= 3200000 bytes Compression= 3.15 *
[/code]

Finally ignoring the cycles I get

[code]******************************************************************************
*Tree :raw_0 : raw_0 *
*Entries : 89999999 : Total = 180284406 bytes File Size = 57151337 *

  •    :          : Tree compression factor =   3.15                       *
    

*Br 0 :signal_y : signal_y/S *
*Entries : 89999999 : Total Size= 180284076 bytes File Size = 57124673 *
*Baskets : 2956 : Basket Size= 3200000 bytes Compression= 3.15 *
[/code]

Try (note that “raw_0;2” contains about twice as many entries as “raw_0;1”, so it really suggests that this is the second “cycle” of the same tree): { TFile *f = TFile::Open("your_file.root"); TTree *t1 = (TTree*)f->FindObjectAny("raw_0;1"); t1->Print(); TTree *t2 = (TTree*)f->FindObjectAny("raw_0;2"); t2->Print(); TCanvas *c = new TCanvas("c", "c"); c->Divide(1, 2); c->cd(1); t1->Draw("signal_y"); c->cd(2); t2->Draw("signal_y"); c->cd(0); }

t1->Print();

I get

[code]******************************************************************************
*Tree :raw_0 : raw_0 *
*Entries : 46733808 : Total = 93749336 bytes File Size = 30027042 *

  •    :          : Tree compression factor =   3.12                       *
    

*Br 0 :signal_y : signal_y/S *
*Entries : 46733808 : Total Size= 93749006 bytes File Size = 30000378 *
*Baskets : 2928 : Basket Size= 3200000 bytes Compression= 3.12 *

[/code]

t2->Print();

[code]******************************************************************************
*Tree :raw_0 : raw_0 *
*Entries : 89999999 : Total = 180284406 bytes File Size = 57151337 *

  •    :          : Tree compression factor =   3.15                       *
    

*Br 0 :signal_y : signal_y/S *
*Entries : 89999999 : Total Size= 180284076 bytes File Size = 57124673 *
*Baskets : 2956 : Basket Size= 3200000 bytes Compression= 3.15 *
[/code]

And if I print in the canvas

Try: { TFile *f = TFile::Open("your_file.root"); TTree *t1 = (TTree*)f->FindObjectAny("raw_0;1"); // t1->Print(); Long64_t t1_entries = t1->GetEntries(); TTree *t2 = (TTree*)f->FindObjectAny("raw_0;2"); // t2->Print(); Long64_t t2_entries = t2->GetEntries(); TCanvas *c = new TCanvas("c", "c"); c->Divide(2, 2); c->cd(1); t1->Draw("signal_y"); c->cd(2); t2->Draw("signal_y"); c->cd(3); t2->Draw("signal_y", "", "", t1_entries, 0); c->cd(4); t2->Draw("signal_y", "", "", (t2_entries - t1_entries), t1_entries); c->cd(0); }

Here is the output

So, everything is clear, isn’t it.
It seems that, in “t2”, entries from “0” to “t1_entries - 1” are the same as all entries in “t1”, and entries from “t1_entries” to “t2_entries - 1” are new (i.e. not contained in “t1”).

Yes, but how do you access them?

TTree::GetEntry -> "entry"
TTree::Project -> “firstentry” and "nentries"
TTree::Draw -> “firstentry” and “nentries” (see, for example, the macro from my previous post here how to do it)