Creating, Filling and Drawing a TH1F Histogram

Hi,

This is no doubt a very basic question, but looking through the HOWTO’s, the Tutorials, and a quick search of the ROOT Discussion Forums i haven’t found how to do it.

Ok I have a Array which correspond to the Eta of particles. This array has been created from an ntup file, and was created earlier in the code.

Now I would like to have a histogram showing the number of particles changing with eta.

What i have so far is:-

c1 = new TCanvas("c1","Eta Difference",200,10,700,500); //creating a canvas

TH1F *h_ptsecond = new TH1F("h_ptsecond","pt of first particle in chain",100,-3.5,3.5); //creating the histogram i am going to fill

The array which i am filling it from is called “etadiffb”

I would appriciate any help at all.

Assuming that your array etadiffb has 100 elements, do

TH1F *h_ptsecond = new TH1F("h_ptsecond","pt of first particle in chain",100,-3.5,3.5); //creating the histogram i am going to fill for (int i=0;i<100>SetBinContent(i+1,etadiffb[i]);

Rene

[quote=“brun”]Assuming that your array etadiffb has 100 elements, do

TH1F *h_ptsecond = new TH1F("h_ptsecond","pt of first particle in chain",100,-3.5,3.5); //creating the histogram i am going to fill for (int i=0;i<100>SetBinContent(i+1,etadiffb[i]);

Rene[/quote]

using that I got the errors

[quote]/afs/cern.ch/user/s/scottw/public/gjab02/AtlasOffline-12.0.0/LoadTree02.C: In
function void LoadTree02(const char*)': /afs/cern.ch/user/s/scottw/public/gjab02/AtlasOffline-12.0.0/LoadTree02.C:153: request for memberFill’ in eta', which is of non-aggregate typeTH1F*’
/afs/cern.ch/user/s/scottw/public/gjab02/AtlasOffline-12.0.0/LoadTree02.C:156: request
for member Fill' ineta’, which is of non-aggregate type TH1F*' /afs/cern.ch/user/s/scottw/public/gjab02/AtlasOffline-12.0.0/LoadTree02.C:163:
SetBinContent’ undeclared (first use this function)
/afs/cern.ch/user/s/scottw/public/gjab02/AtlasOffline-12.0.0/LoadTree02.C:163: (Each
undeclared identifier is reported only once for each function it appears
in.)
/afs/cern.ch/user/s/scottw/public/gjab02/AtlasOffline-12.0.0/LoadTree02.C:165: syntax
error before `;’ token
[/quote]

so i thought maybe you missed a ) after the (i+1

but i then got errors of

so not sure what is happening. I have added the code i am using just incase you wanted to see that.

Thanks for any help.

Gareth

Not sure if it attached last time
LoadTree.txt (4.56 KB)

Use eta->Fill(etadiffb[s]);(pointer notation instead of object notation)

Cheers,
Philippe

[quote=“pcanal”]Use [code]eta->Fill(etadiffb[s]);[code](pointer notation instead of object notation)

Cheers,
Philippe[/quote]

world that be instead of

I mean that most place where you haveeta.useeta->
Philippe

still getting error of

[quote]/afs/cern.ch/user/s/scottw/public/gjab02/AtlasOffline-12.0.0/LoadTree02.C: In
function void LoadTree02(const char*)': /afs/cern.ch/user/s/scottw/public/gjab02/AtlasOffline-12.0.0/LoadTree02.C:153: request for memberFill’ in eta', which is of non-aggregate typeTH1F*’
/afs/cern.ch/user/s/scottw/public/gjab02/AtlasOffline-12.0.0/LoadTree02.C:156: request
for member Fill' ineta’, which is of non-aggregate type `TH1F*’
/afs/cern.ch/user/s/scottw/public/gjab02/AtlasOffline-12.0.0/LoadTree02.C:173: syntax
error at end of input[/quote]

I think it is sorted now.

Thanks for all your help

Gareth