2D Histogram Plotting as a 1D Histogram

I am attempting to declare and fill a 2D histogram with two variables, but for some reason it just fills the x and y axes as if it were a 1D histogram. In the header file I have declared the 2D histogram as follows with 100 bins for both axes:

TH2F *invm1234 = new TH2F(“invm1234”,“Invariant mass jets 1 2 3 4”,100,0.,300,100,0.,300);

After specifying the variables I to try to fill it as follows:

if(i==0 & j ==3 & (jet1->PT)>30 & (jet2->PT)>30 & (jet3->PT)>30 & (jet4->PT)>30)
invm1234->Fill(invmass,invmass34,norm);

The result I get fills for the x and y axes but it’s as if the code doesn’t process the fact that there needs to be another axis in 3D space for the number count.

attemptat2Dhisto

THistPainter

Right, I see, I didn’t realize the scatter diagram was just the default option. I have tried following one of the examples to get the LEGO example plot but when I add the TCanvas to my header file and put return c2 into my analysis code it produces an error when I try to re-compile. I take it the TCanvas part is necessary when making stylistic changes to a 2D histogram in this way?

If your code isn’t meant to return a TCanvas, you should just delete the return in the end.

S

I’ve deleted the return and just asked it to draw it in the style I am looking for (ie. LEGO), but it still won’t do it, is it something to do with the way I am filling the histogram? I am simply taking a 2D histogram and asking it to fill with 2 variables where I have specified the number of bins for each axis.

In the first post above you show a picture which you probably got using something like invm1234->Draw(); so try simply with invm1234->Draw("LEGO"); instead and you should get it, too.

Unfortunately not, that picture gets produced without any draw command, I just ask it to fill the histogram and it produces that picture. When I try Draw(“LEGO”) it just produces the same picture again.

That’s not possible.
Search for the “Draw” call in your ROOT macros.

I am using analysis code rather than ROOT macros, I have looked through the cpp file, the makefile and the header file which together make up the analysis code and there is no other reference to a Draw command apart from the one I am trying to add to the cpp file.

Basically I have a line of code in the header file:

TH2F *invm1234 = new TH2F(“invm1234”,“Invariant mass jets 1 2 3 4”,100,0.,300,100,0.,300);

If I ask it to fill with 2 variables in the cpp file, it just draws a scatter plot by default: is there something I can do to the code above in the header file to specify that I need it to draw the plot in a style different from the default one?

Read my lips … “Fill” will NEVER “Draw” it.
If you cannot find the “Draw” in your source code, try to add (right after you create the histogram):

invm1234->SetOption("LEGO20"); // e.g. "LEGO20" or "LEGO0" or "LEGO"

Note: this trick should also work if you use the ROOT Browser to draw this histogram.

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