# Projection in THnSparse

Hello,
I am new in ROOT. I am analyzing gamma-gamma coincidence data. I needed to build a 3D triple gamma coincident histogram. For that I have used THnSparse and got gamma energies along three axes that I generated by using THnSparse. Now I need the projections. I can get the full projection along any of my axes, and see 1D or 2D histograms.
However, I want to make a gate in my first axis (for a bin range, e.g., 260 to 280) and project onto the 2D histogram made by the second and the third axes. Can I do this by using a ROOT command line? Can anybody help me with this how can I see gated histogram made by THnSparse?

Thank You.
Becka

Some time ago, I wrote various source code (which deals with a creation of a 3D THnSparse and then its 1D and 2D projections) for someone else which you can reuse:

Hi, Thank you so much, this post is very helpful indeed. But I am a bit confused about the gated projection. I understand the following,

``````THnSparse *h;
TH1D *h1 = h->Projection(2, option);
``````

However, I failed to understand the following, I have taken it from the link you suggested,

``````TH1D *Project1D(THnSparse *h, Double_t low1, Double_t up1, Double_t low2, Double_t up2,  Option_t *option = "")
``````

Does it mean I am taking gates from the first (ranging from Double_t low1 to Double_t up1) and the second (Double_t low2 to Double_t up2) axes and projecting onto the third one? If this is so, can’t I take gates from the second and the third axes and project onto the first one? Also, can you tell me what does ‘option’ do?

Thank you,
Becka

The “gates” are applied to all possible axes combinations and these “partial” projections are summed.

For the “option”, see THnBase::Projection (forwarded from THnSparse::Projection).

I see. But is there a way if I want to make a gate from the first axis and project onto the 2D histogram made by the second and the third axes? I mean can I have the control on from which axis I want to make a gate?

And what prevents you from doing it the way you want it?
You do not have to use my full macros.
You can e.g. use only parts of their source codes which suit your needs.

I assume I could not explain it properly. What I understood from your second reply that if I apply the following on a cubic histogram,

``````TH2D *Project2D(THnSparse *h, Double_t low, Double_t up, Option_t *option = "")
``````

It will make gates on all three axes and project into the 2D histograms made by the rest two and finally all the partial projections will be summed up. However, I do not want the summed up histogram, I need to see the individual 2D histogram while gated and projected from the remaining axis. I am not sure if it is clear, or perhaps I am missing something as I said I am a new ROOT user.

I figured out what I was missing, thank you so much!

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