I have a TH3F *histo and when trying to make a 2d projection on TH2D *projection, like, projection = histo->Project3D(“xy”)
I get the following error:
Error: Incorrect assignment to projection, wrong type “TH1*”
Which is the correct way to do this projection?
Thanks in advance,
we need the minimal amount of running, self-contained code that shows this problem. Given your info so far I don’t see any issue:
root  TH3F *histo = new TH3F("h3","h3",10,0.,1.,11,0.,1.,12,0.,1.)
root  TH2D* projection = histo->Project3D("xy")
Thanks for the quick answer. I was cleaning the code before uploading and decided to give another try changing one line and now it works, before I had:
for a TH3F *histo,
TH2D *projection = new TH2D(“projection”, “projectiontest”, 10, 1, 10, 10, 1, 10)
projection = histo->Project3D(“xy”);
and now changed it as your example:
TH2D *projection = histo->Project3D(“xy”);
and it works. Then, should I not use the contructor for the histogram where I want to project?
when a function returns “A*” it creates A internally, you receive it by storing its address in a pointer variable. No need to create your own object.
I’m stuck with a similar problem but I can’t work out how to solve it from this thread and I would be very grateful for some help. I am trying to project a TH3F onto a TH2.
In COMPILED code I have (3dhisto is a previously declared TH3F):
This doesn’t compile. It returns error: invalid conversion from
So I do
This compiles, but gives segmentation violation when I try to run it.
Projecting onto a 1D histo compiles and runs fine. E.g:
So I can see there’s a problem with the pointer that I’m returning but I’m not sure what to do… cast the TH2* as a TH1*?
I would be very grateful for any help!
Thanks very much in advance
TH2D *proj2= (TH2D*)3dhisto->Project3D("xz");
Thank you Rene that command compiled and ran fine once I put it in a separate macro to do the plotting. For some reason it wouldn’t run when the command was in the .C file that I use for my analysis, but it probably shouldn’t be in there anyway!