TH1F array

x axis =30
y axis =72

there are 30x72 cell for this plane.

For every cell since I would like to get an information, I did 30x72 TH1 histogram----->TH1F *h[30][72];

and fill them like this logic;

h[a][b]->Fill©;

It works fine.

How could I put all these cells in only one histogram ?

I guess I need TH2F or TProfile2D. But I am not very familiar with TH1F_array so I am not sure.

Will it be something like that ? and how could I do this by using TH2F ?

TProfile2D* iii_=new TProfile2D(“yuwrb”,“ecjgy”,31,-15,15,72,0,72,0,200);

Regards…

Your question is not terribly clear.

How many dimensions do you have? From what I can see you have three: a), b) and c). This means you want a TH3F or TH3D. You would fill it like so:

TH3F *h = new TH3F( “name”, “title” … )

h->Fill( a, b, c );

You could then draw it either by Projecting it down to a TH2F with TH3::Project3D() or you could make a Profile with a Project3DProfile.

See the documentation here for more detail:

root.cern.ch/root/html/TH3.html

To replicate your example as best as I can:

h->Project3D(“xy”) would give project out the x and y dimensions and give you the equivalent of Sum_{a,b}( h[a][b] ).

You can just obtain a particular a and b by setting ranges on the x and y axes:

h->GetXaxis()->SetRange(a,a);
h->GetYaxis()->SetRange(b,b);

This would give you just h[a][b].

Hope this helps.

I will try to clear the question;

There are 30x72 cells in a plane. I want to get energy value for each cell on the plane.

when I write;

h[a][b]->Fill(energy[c])

this means a and b are indexes of the cells and fill the cell with the energy value. (since the energy vector is one dimensional array in the ntuple, I have to do this like this.)

Now I have 30x72 TH1F energy histogram for each cell. I want to do it only one histogram like that

TProfile2D* iii_=new TProfile2D(“yuwrb”,“ecjgy”,31,-15,15,72,0,72,0,200);

I hope it is clear now…

This does not make the question clearer.

Was my reply relevant, or not?

It seems to me that if you make these ‘cells in a plane’ dimensions of your histogram, your problem would get more simple.

[color=green]TH1F *h[30][72];
for (int ie=0; ie<=29; ie++ ){
for (int ip=0; ip<=71; ip++ ){
h[ie][ip] = new TH1F(histoname,“energy”+histoname[/color],100,-10,50);[/color]

this operation make 30x72 TH1F histo. And I fill them like this;

[color=green]for (int cell=0; cell<ihohit;cell++) {
h[RecHa[cell]][RecHb[cell]]->Fill(energy[cell]);
[/color]

RecHa, RecHb, energy are vectors (one dimensinal array) and ihohit is integer.

All I want to do it, I want to fill energy value for each RecHa and RecHb values.

I guess I dont need TH3F. Maybe I have three dimensions but I use two dimension as a one index.

I cannot define the problem clearer :frowning:

By the way, I can send the code if you want to check it.

Post a working version of your code… let’s take a look.

Just so I understand your question: You’re asking how you could dispense with the many histogram objects, and just have one?

You’re asking how you could dispense with the many histogram objects, and just have one?

Right! And I send a message to your inbox about the code.

Right, to clarify for anyone else reading the thread:

The poster has a TTree with three arrays, eta, phi and energy.

Eta and Phi are ‘binned’ and these bins are the ‘cells in the plane’.

Now my question: you want to get this information out of the tree and into a histogram as quickly as possible, but it is not clear what information you want from it. You sent me an (unlabelled) 2D histogram of what I guess is eta against phi. How does energy come into this?

There is a nice and easy way of plotting your distributions, by the way:

TFile input( "yourRootFile.root" ); TTree *myTree = (TTree *)input.Get("t"); myTree->Draw("RecHOen");

For example. ROOT will fill a histogram with RecHOen for all entries in the array.

For example you can also do

This will probably make your life easier for testing.

I have used bold not for shouting, but just to highlight the important part of my post :slight_smile:

TFile input( "yourRootFile.root" ); TTree *myTree = (TTree *)input.Get("t"); myTree->Draw("RecHOen");

That is not what I need since I would like to get RecHOen separately for each eta-phi channel. This code gives all RecHOen entries not cell by cell.

myTree->Draw("RecHOen:RecHOPhi:RecHOEta >>MyHistogram");

That works normally. But the problem is;

There are 30x72 eta-phi cells but for each event RecHOen array has approximately 300 values. I mean, in an event If a cell has not an energy input, there is no input related to this cell in RecHOen array.

For example in the first event;

RecHOen[0]: 0.3062501 eta:-3 phi:12

in the second event it comes different eta phi values since there is no energy input for the eta:-3 phi:12 channel.

RecHOen[0]: 0.2940446 eta:-3 phi: 28

So I solve the problem like this

[code]
TH1F *h[30][72];
for (int ie=0; ie<=29; ie++ ){
for (int ip=0; ip<=71; ip++ ){
h[ie][ip] = new TH1F(histoname,“energy”+histoname,100,-10,50);[/color]

this operation make 30x72 TH1F histo. And I fill them like this;

for (int cell=0; cell<ihohit;cell++) {
h[RecHa[cell]][RecHb[cell]]->Fill(energy[cell]); [/code]

But I would like to do the same job with only one plot.

Any idea would be welcome.

What is it you want to end up with?

To be able to get the average RecHOen in a cell of (RecHOPhi,RecHOEta) ? The total RecHOen for a cell of RecHOPhi,RecHOEta?
A histogram of RecHOen in each cell of (RecHOPhi,RecHOEta) ?

I am able to start with the last one :slight_smile:

A histogram of RecHOen in each cell of (RecHOPhi,RecHOEta) ?

Try this:

root [0] TFile f( "Your ROOT File" ) root [1] TTree *tree = (TTree *)f.Get("t"); root [2] tree->Draw("RecHOen:RecHOPhi:RecHOEta >> Histo( 31, -15.5, 15.5, 74, 0, 74, 100, -2, 14 )") root [3] Histo->GetXaxis()->SetRange( 1, 1 ) root [4] Histo->GetYaxis()->SetRange( 1, 1 ) root [5] Histo->Project3D("z")->Draw()

This will produce you a histogram of RecHOen for (RecHOEta,RecHOPhi) = (1,1).

Fine but it did not work.

I get a histo which has

Entries 0
Mean 0
RMS 0

I guess the solution is not far away. At least we define the problem. You should use the code which I send to you.

Sorry, I managed to choose one (1,1) that had no entries. If you change the 1’s to 2’s (SetRange( 2, 2 )) - you will find one with entries. You could iterate over all of GetXaxis()->SetRange( i, i ) GetYaxis()->SetRange(j,j) and Project3D() and that would get you back to your TH1F array.

I’m not going to write more code for you - if you want to do it in loop form, just replace your TH1 [][] with a TH3 and instead of hist[i][j]->Fill(k) do hist->Fill(i,j,k).

Good luck :slight_smile: