# Projection on a axis from TH2D

Hi everyone!
I don’t know how to make projection on a axis from TH2D.
In this folder, I did plot 2D “SA_th23dcp” (with X-axis is th23 and Y-axis is dcp) , From this plot, I want to get two-dimensional chisquare on (theta_23, dcp) and do 1D plot with (dcp,that two-dimensional chisquare). test (1).zip (390.6 KB)

What is “two-dimensional chisquare on (theta_23, dcp)”? Suppose you have that as a 2D histogram, how do you expect to get to a “1D plot with (dcp,that two-dimensional chisquare)”?

Let me rephrase, maybe that makes it clear what I do not understand:

you have a rows of dcp, th23, chisq for some binIndexX and binIndexY. You have many rows of those. You now want to plot “(dcp,that two-dimensional chisquare)” - which seems to be a 2D plot, but you say it’s a 1D plot. I can see how you’d plot dcp versus chisq; I do not see how you can produce that from the 2D plot “SA_th23dcp”, or how that is related.

Let me know!

Axel.

hi Axel
I think SA_th23dcp is the plot on th23 versus dcp. With each value (th23,dcp) will correspond to a value of chisqua that I call it as two dimensional chisquare. Now I want to draw it in the 1D plot (dcp versus chisquare), it corresponds to projection the 2D plot onto dcp.

O I see - the bin content of SA_th23dcp is the chisq value for the pair of (th23,dcp). Now - that’s super dangerous: are you positive that you only ever call `SetBinContent` on empty bins? (Check!)

I guess the 1D histogram you’re after should add all all bin content (aka chisq) along th23 for one value of dcp? That would just be `SA_th23dcp->ProjectionY()`.

test.C (11.2 KB) you say it, right? it is “dcp”

Sorry, I do not understand your message.

can you check this code test.C (11.2 KB) . It is right or not?

I get many errors, so it seems to not be right:

``````/home/axel/Downloads/Jessica.PQ/test/test.C:60:12: error: expected unqualified-id
double M_PI = TMath::Pi();
^
/usr/include/math.h:1070:16: note: expanded from macro 'M_PI'
# define M_PI           3.14159265358979323846  /* pi */
^
In file included from input_line_11:1:
int nbinx = h1x->GetNbinsX();
^
int nbiny = h1y->GetNbinsX();
^
TH1F* dcp = new TH1F("dcp", "", nbiny, h1y->GetBinCenter(1), h1y->GetBinCenter(nbiny));
^
TH1F* dcp = new TH1F("dcp", "", nbiny, h1y->GetBinCenter(1), h1y->GetBinCenter(nbiny));
^
TCanvas *c1 = new TCanvas();
^
As I said, `SA_th23dcp->ProjectionY()` - that will give you a `TH1` and should be what you’re after.