Home | News | Documentation | Download

Branch & corresponding histogram


ROOT Version: 6.23/01
Platform: 64 bit Fedora 32
Compiler: gcc version 10.1.1 20200507 (Red Hat 10.1.1-1) (GCC)


Hello,

I have a conceptual problem.

I have a data file from an experiment which contains several signals. I am converting entire data into a ROOT Tree format as follows:

CandleTree->Branch(sig_name[br_loop], &signals[br_loop],sig_format[br_loop]);

Now, when I display (say, using TBrowser or TTreeViewer ) one of the signals, I get the following:

But, this is not how actual the signal should look. Therefore, from the tree generated above, I sorted the entries into histogram as below:

        Long64_t nentries = t1->GetEntriesFast();

        for (Int_t i=0; i<nentries; i++) {
                t1->GetEntry(i);
                for(int j = 0; j < n_signals; j++){
                        if(signals[j]>0) his[j]->Fill(signals[j]);
                }
        }

then the histogram corresponding to that branch looks as follows:

Okay, I understand the difference in the entries. The second histogram is filled excluding zeros.
But, apart from entries - Why the two histograms are different when I am filling the data in both the cases?

Please can you help me understand what is happening.

Thank you.

Looking at the plots, it seems the two histogram do not have the same bin width. The one below seems to have many more bins than the upper one.

Thank you @couet for you reply. Yes, that possibly could be the reason. Then, how to create a branch to contain histograms with desired bin width?

The second histogram in my first post is made using TH1F(nm,nm,16384,0.,16384.); while the first histogram (from) has no specific width.

Yes it has 16384 bins … try:

TH1F(nm,nm,100,0.,16384.);

Thank you.

Actually, I want second histogram (because that correctly represents energy spectrum from the detector) directly from TTreeViewer.

Or, if at all possible, to generate branches with 16384 bins, with bindiwth=1.

Is this possible?

The bin width is not a parameter you can set when you book an histogram. It is computed from the histogram limits and the number of bins: (xmax-xmin)/nbins

Okay. May be I was not clear enough earlier. Let me try to rephrase my question.

Is it at all possible to create a branch to store histogram with say nbins = 16384?

“brand creation” and “number of bins for the resulting histogram” are two unrelated things. You specify the number of bins at the histogram creation time. Let say:

auto h = new TH1F(nm,nm, 16384,0.,16384.);
t-Draw("x >> h");

I hope that answer your question

That is exactly how I have generated the second histogram in the first post.

One last question: can I generate the second histogram directly from TTreeViewer by using corresponding branch? If yes, the please explain how?

In the TTree Viewer there is a field called “histogram”. I guess you can put your histogram there.

I dragged SIG007 branch to x, and then clocked Draw current selection box.
With this, I still do not get the behaviour that I am expecting. Please see below

it works for me:

1 Like

It worked! Thank you very much @couet. Your time and efforts are much appreciated.