I checked the file “dirs.C” from root tutorials. Although I understand how the directories/folders are generated, I have many questions about the histograms generated,
When checking the generated histograms, why there are two with the same name h0_0N and h0_0N;1 ? Also they are the same. What is their difference and why they are saved with those labels?
Can someone explain how the histograms are filled ?
// ^^^^^^ Fill histograms
TRandom r;
for (i=0;i<nplanes;i++) { // nplanes=#folder[1-9]
cdplane[i]->cd(); // open forder [i]
for (j=0;j<ncounters;j++) { // j[0-99], number of histo
for (k=0;k<100;k++) {
hn[i][j]->Fill(100*r.Rndm(),i+j);
hs[i][j]->Fill(100*r.Rndm(),i+j+k);
} // For over k
} //For over j
} // For over i
For example i=0 j=0 k==[0-99], k runing from 0 to 100. hn[0][0]->Fill(100*r.Rndm(),0);
Does this mean hn[0][0]->Fill(x value = random number, here is the weight?)
And for hs[0][0]->Fill(100*r.Rndm(),0+0+[0-99]); what is the function of k here? is that adding k in the second entry of Fill(), does hs have a larger weight?
If I want to print and get any the entry of any of the histograms, inside the planes directories how can I access to such information? I tried to print inside the k loop std::cout<<hn[i][j];
to get the value of the entry k
but it gives me the address in memory 0x55fd7b494e20.
How can I obtain the entry number and its value?
_ROOT Version: root.v6.20 Platform: Not Provided Compiler: Not Provided
It’s just an internal detail of how data is stored in the ROOT file, they refer to the same histogram. You can access it with name h0_0N.
Yes, the second parameter in Fill is the weight. The hs histograms are being filled randomly and with larger weights that the hn in the loop over k. k is used to provide that extra weight to hs (if there is a reason behind this besides demonstration purposes, I don’t know).
hn[i][j] is a TH1F object, you can check here how to obtain information from it here: https://root.cern.ch/doc/master/classTH1F.html . The entry you are filling is determined by i, j and k, and the value you are filling with is the result of calling 100*r.Rndm().
Thank you for your reply. However I have already had a look to TH1F documentation, without having success when I tried to obtain the values of hn. I get error like member reference base type 'TH1 *[100]' is not a structure or union. And sincerely, I do not know what it means.
I can see the values, e.g. h2_0N has two entries(corresponding to k=0,1): xentry(k=0)=84.3097, xentry(k=1)16.5796 with wight (y axis value center in ): nweight(k=0)=11, nweight(k=1)=53 respectively. But I want to obtain the x value with GetBinCenter or the y value GetBinContent bur it gives 0.5 and 0, when I am expecting to obtain the xnentry and the nweight. Do you know the correct way to obtain such values?