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
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:
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.
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) ?
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).