Home | News | Documentation | Download

Creating graphs using histogram class

Dear Root users,

I am trying to explore patterns in some data that I have fed into a tree called “testData” using TTree.

TTree *testData = new TTree("TESTDATA", "TESTDATA")

After creating and filling a tree and specifying branches, I do as follows

TH1F *h1=new TH1F("xMomemtum","Momentum with cuts",100,0.,-100.);
TH2F *h2=new TH2F("xMomentum vs depth","xMomemtum vs depth",40,0,100,40,0,100);
TH2F *h3=new TH2F("Test","",40,-100,100,40,-100,100);

testData->Project("h1","xMomemtum");
testData->Project("h2","xMomemtum:depth");
testData->Project("h3", "columni:columnj");

c1->cd(1);
h1->Draw();

c1->cd(2);
h2->Draw();

c1->cd(3);
h3->Draw();

c1->Update();
testData->Print(); //Check whether tree has entries

Executing this pulls up a canvas which has 0 entries in each of the graphs. I have checked the data file and my histogram declarations and I believe the ranges are correct. I’ve also checked that there is at least one non-zero entry, and therefore I’d expect some entries for the following histogram projections.

I’m not too sure why this is the case. Any help would be appreciated.

TH1F *h1 = new TH1F("xMomemtum", "Momentum with cuts",100,0.,-100.);
TH2F *h2 = new TH2F("xMomentum_vs_depth", "xMomemtum vs depth",40,0,100,40,0,100);
TH2F *h3 = new TH2F("Test", "",40,-100,100,40,-100,100);

testData->Project("xMomemtum", "xMomemtum");
testData->Project("xMomentum_vs_depth", "xMomemtum:depth");
testData->Project("Test", "columni:columnj");
1 Like

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