I am a beginner with root and I am trying to project a TH2D histogram but instead of projecting it on one of the histogram axis with ProjectionX() or ProjectionY(), I would like to project it to a specific line not aligned to the initial axis. Is that possible?
The plot I join illustrates what I am trying to do. Another solution would be to realign the axis of the histogram itself in order to have the source more or less in the middle of the plot aligned parallel to RawY (according to the black line drawn in the plot). Then using ProjectionX() would be fine and easy. However I don’t know how to do that…
Thank you very much if someone can give me any help or hint!
HistoProjection.pdf (110 KB)
This type of projection is not supported (in particular because it would not be precise due to binning problems in the transformation). The solution is much simpler: Start from a TTree
and instead of filling a TH2 with Fill(x,y), do,eg to rotate with theta=30
double theta = TMath::Pi()/8;
double costet = TMath::Cos(theta);
double sintet = TMath::Sin(theta);
mytree.Draw(Form("x*%g-y*%g : x*%g+y*%g",costet,sintet,sintet,costet));
thank you for your answer. Indeed the solution is more simple then what I was trying to do.
I try to use TTree to rotate 2D histogram like this:
fTree->Draw(Form(“m_x*%g-m_y*%g : m_x*%g+m_y*%g>>PlotB”,costet,sintet,sintet,costet), CUT1, “goff”);
TH2I fDot = (TH2I)gDirectory->Get(“PlotB”);
But it doesn’t work. Is there anything wrong with my code? Could you please give me some suggestion?
Thank you very much!
Could you post a very short script and a small data file reproducing your problem?
I have solved the problem. I should use TH2F instead of TH2I.