Issue TH1F from TTree

Hi,

I am trying to create a TH1F from a TTree, extracting leaves with a certain condition (in my datas I have some with variables flag=0 and flag=1).

        TTree *T = (TTree*)f.Get("mytree"); //open the tree
        TH1F *h = new TH1F("h","h",100,0.,0.);
        TCanvas *myCanvas = new TCanvas();
        T->Draw("flux>>h","energy>>h","flag == 1"); //draw histograms with var flag==1

As you may see I am trying to plot a spectrum (a flux vs an energy), is a TH1 adapted ? Or should I rather use a TH2F ?

I have this error : 'Bad numerical expression : β€œh” ’ followed by a ’ Variable compilation failed: {flux,energy>>h} '.
I don’t get my mistake hence asking for help please, thanks :slight_smile:


See the documentation of TTree::Draw()

1 Like

AH yes of cours it is rather T->Draw("flux:energy>>h","flag == 1");

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