Project from de TTree to a TH2D


I am trying to use TTree::Project on two variable of a TTree to fill a TH2D and ultimately, use TH2::ProfileX on it. However, when I’m doing this :

TFile* file = TFile::Open("file.root", "READ");
TTree* tree = (TTree*)file->Get("Tuple");

TH2D* hist2 = new TH2D("h2", "", 100, 0, 25e6, 100, 0, 1);

tree->Project("h2", "B_Regression_Q2_BEST_LINEAR_Run2:Resp_MLP__SvsRun1_Vars_All_TRIMMER_AllCuts");


I’m obtaining the following canvas :
A.pdf (13.7 KB)

It is weird because when I’m doing :

tree->Draw("B_Regression_Q2_BEST_LINEAR_Run2:Resp_MLP__SvsRun1_Vars_All_TRIMMER_AllCuts", "", "colz");

It is working perfectly fine :
B.pdf (19.9 KB)

I just tried with a toy tree (produced by the ROOT tutorial hsimple.c0 and it iw working fine. I did:

 auto h2 = new TH2D("h2","h2",100,-5,5,100,-5,5);

100, 0., 1., 100, 0., 25.e6

1 Like

Thanks for the solution ! So TTree::Project takes the Y axis in first.

the same for TTree::Draw. “y:x” means “y versus x” .

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