Is there an easy way to fill TProfile2D from TTree?

I cannot figure that thing out.

I have serie of values: x,y,z. I would like to create a TProfile2D, that for each trio of x,y,z is filled like Fill(x,y,z) was invoked - x,y are coordinates, z is the variable I want to histogram. Unfortunately, as far as I understand, TTree::Draw does not allow to do that even for TH2, for Draw(“x:y:z”) creates a TH3 (noth TH2). So I figured out a way to fill TH2 with values x,y,z (in my case they are called ccdx, ccdy and mean):

fin_res->Draw("ccdx:ccdy:mean", "", "");
TGraph2D *g = new TGraph2D(fin_res->GetSelectedRows(), fin_res->GetV1(), fin_res->GetV2(), fin_res->GetV3()); 
g->Draw("p0");
TH2D *h = g->Project("xy");
new TCanvas;
h->Draw("colz"); 

That works how it is supposed to work. However, I have no idea how to do a simillar thing, but to fill a TProfile2, not TH2. Could anyone help? Or maybe I even missed a simple way to directly create such TProfile2 and TH2 with TTree::Draw()?

OK, sorry for bothering you. I found an answer - call Project3D or Project3DProfile for TH3 created by TTree::Draw()

Hi,

fin_res->Draw("ccdx:ccdy:mean", "", "prof");should also do the trick. Note that if you suffix prof with either of the letter ‘s’,‘i’ or ‘g’, those are passed to the TProfile2D constructor.

Cheers,
Philippe.

Thank, it truly works! Is there a similar way to create a TH2 histogram?

Yes … the same :slight_smile:fin_res->Draw("ccdx:ccdy", "", "prof");Cheers,
Philippe.

I was thinking about exactly the same effect as using

fin_res->Draw("ccdx:ccdy:mean", "", "prof");

but resulting in a TH2, not TProfile2D (sum instead of mean in each bin) :slight_smile: Removing “prof” from options creates TH3…

Hi,

It works for me:root [11] ntuple->Draw("px:py:pz","","prof"); root [12] htemp->IsA()->Print() OBJ: TClass TProfile2D Profile2D histogram class. Which version of ROOT are you using?

Philippe.

Somehow I cannot explain what I mean properly :slight_smile: Creating TProfile2D also works fine for me, but I don’t know the way to create exactly the same TH2 (as TProfile2D, but having sums in bins instead of means) from 3 variables…

Hi,

Do you mean:root [11] ntuple->Draw("px:py","pz","hist");?

Philippe.