GetBinContent() rounded to closest 50

Hi Rooters,

This my first Root post* so here goes:
I am taking monte carlo data from a TTree (I know you guys dont have the data now, but drawing the histograms works fine) to create a histogram from it and then I want to find the amount of elements in each bin. My Macro spits out the simulated events in each bin rounded to the closest multiple of 50. My code gives this output:
in bin 1 there are 0 events and there are 0 wrong events
in bin 2 there are 16700 events and there are 3200 wrong events
in bin 3 there are 39900 events and there are 6500 wrong events
in bin 4 there are 43300 events and there are 8850 wrong events
in bin 5 there are 52100 events and there are 14050 wrong events
in bin 6 there are 76200 events and there are 22600 wrong events
in bin 7 there are 108900 events and there are 29750 wrong events
in bin 8 there are 38000 events and there are 5550 wrong events
in bin 9 there are 0 events and there are 0 wrong events

I however want my elements not to be rounded to the closest multiple 50. How do I solve this?
*NOTE: I just used exactly the same macro for a different mote carlo data set and did get ‘all events’ and not the rounded to 50 ones!
Hope you guys can help me out, and thanks in advance,
Stijn

void test()
{
//Create Tchain tree for deuteron MC events
TChain *ch = new TChain("reco");
ch->Add("directory*");
TTree *tree_deut = (TTree*) ch;
//Create histogram templates
size_t numBin = 10;
TH1F *hDE = new TH1F("hDE", "Total Events", numBin, 0.94, 1.03);
TH1F *hDWE = new TH1F("hDWE", "Wrong Events", numBin, 0.94, 1.03);
//draw histograms from tree
tree_deut->Draw("beta_rich>>hDE", "", "goff");
tree_deut->Draw("beta_rich>>hDWE", "rgt2[0]<0", "goff");
//Loop over bins and count amount of elements in them
Int_t elmBinDE = 0, elmBinDWE = 0;
for (size_t bin = 1; bin<numBin; ++bin)
  {
    elmBinDE = hDE->GetBinContent(bin);
    elmBinDWE = hDWE->GetBinContent(bin);
    cout<<"in bin "<<bin <<" there are " << elmBinDE << " events"
    <<" and there are " << elmBinDWE << " wrong events" << endl;
  }
}

ROOT Version ( 5.34/36):
Platform, compiler ( Windows 10, I think gcc5.?):


I am not sure, looking at your code, where this “rounding to the closest multiple of 50” comes from. I see you are counting the good events with some specific cut in the histogram hDE and the wrong ones with an other cut in the histogram hDWE. That’s all fine seems to me. The only rounding I can think of would be the one due to the binning (each histogram has only 10 bins may be you can have more). But that’s something you cannot avoid.

Thanks for your reply. I only posted it with 10 for now, because otherwise the post would be long, but I had the same issue with 10, 50, 100, 1000 bins. Judging from my NOTE, and your reply, I will look into the provided MC data a bit more, maybe the provided(by supervisor taken from AMS collaboration) data is already rounded off somehow.

Post here the output of: tree_deut->Print();

Pardon my syntax, I dont know all the details and will probably use a lot of words for trees leaves and chains in the wrong place. But it is a huge chain of trees.

They form a chain of 49 trees, I should note that the trees do not go in order from crazy.0…crazy.49. They follow a bit of a structure but sometimes skip a few, which get added later. It starts off with crazy.0 then crazy.1 but skips crazy.2 and then continues ‘normally’, and then somehwere around crazy.10, crazy.2 appears. Ill post just 1 tree:


*Chain :reco : D:/rootworkspace/BR/data/mote_carlo/AMS_MC/deuteron_mc/crazy.0.root *



*Tree :reco : Reconstruction ntuple *
*Entries : 37001 : Total = 8564841 bytes File Size = 3896853 *

  •    :          : Tree compression factor =   2.19                       *
    

*Br 0 :stat[2] : stat[2]/i *
*Entries : 37001 : Total Size= 303357 bytes File Size = 9258 *
*Baskets : 75 : Basket Size= 4096 bytes Compression= 32.57 *

*Br 1 :ustatus[2] : ustatus[2]/i *
*Entries : 37001 : Total Size= 303594 bytes File Size = 9483 *
*Baskets : 75 : Basket Size= 4096 bytes Compression= 31.82 *

*Br 2 :evt_run : evt_run/I *
*Entries : 37001 : Total Size= 162218 bytes File Size = 16450 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 9.66 *

*Br 3 :evt_n : evt_n/I *
*Entries : 37001 : Total Size= 161914 bytes File Size = 137712 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 1.15 *

*Br 4 :UTT : UTT/L *
*Entries : 37001 : Total Size= 309622 bytes File Size = 129507 *
*Baskets : 148 : Basket Size= 3584 bytes Compression= 2.37 *

*Br 5 :llratio : llratio[3]/D *
*Entries : 37001 : Total Size= 902252 bytes File Size = 364807 *
*Baskets : 148 : Basket Size= 11776 bytes Compression= 2.46 *

*Br 6 :trk_qin : trk_qin/F *
*Entries : 37001 : Total Size= 162218 bytes File Size = 129700 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 1.23 *

*Br 7 :ntrdhits : ntrdhits/I *
*Entries : 37001 : Total Size= 162370 bytes File Size = 50245 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 3.17 *

*Br 8 :betah : betah/F *
*Entries : 37001 : Total Size= 161914 bytes File Size = 143550 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 1.11 *

*Br 9 :tof_qup : tof_qup/F *
*Entries : 37001 : Total Size= 162218 bytes File Size = 145981 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 1.09 *

*Br 10 :tof_qlow : tof_qlow/F *
*Entries : 37001 : Total Size= 162370 bytes File Size = 146374 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 1.09 *

*Br 11 :tof_q : tof_q/F *
*Entries : 37001 : Total Size= 161914 bytes File Size = 144822 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 1.10 *

*Br 12 :hasl1 : hasl1/O *
*Entries : 37001 : Total Size= 50905 bytes File Size = 22810 *
*Baskets : 148 : Basket Size= 512 bytes Compression= 2.09 *

*Br 13 :hasl2 : hasl2/O *
*Entries : 37001 : Total Size= 50905 bytes File Size = 22787 *
*Baskets : 148 : Basket Size= 512 bytes Compression= 2.09 *

*Br 14 :hasl9 : hasl9/O *
*Entries : 37001 : Total Size= 50905 bytes File Size = 20675 *
*Baskets : 148 : Basket Size= 512 bytes Compression= 2.31 *

*Br 15 :ql1 : ql1/F *
*Entries : 37001 : Total Size= 161610 bytes File Size = 62974 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 2.51 *

*Br 16 :rgt2 : rgt2[3]/F *
*Entries : 37001 : Total Size= 457776 bytes File Size = 351060 *
*Baskets : 148 : Basket Size= 5632 bytes Compression= 1.29 *

*Br 17 :rgt_true : rgt_true/D *
*Entries : 37001 : Total Size= 303447 bytes File Size = 180989 *
*Baskets : 75 : Basket Size= 4096 bytes Compression= 1.67 *

*Br 18 :csx2 : csx2/F *
*Entries : 37001 : Total Size= 161762 bytes File Size = 118511 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 1.34 *

*Br 19 :csy2 : csy2/F *
*Entries : 37001 : Total Size= 161762 bytes File Size = 120080 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 1.32 *

*Br 20 :rich_q : rich_q/F *
*Entries : 37001 : Total Size= 162066 bytes File Size = 55960 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 2.84 *

*Br 21 :trd_q : trd_q/F *
*Entries : 37001 : Total Size= 161914 bytes File Size = 110747 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 1.43 *

*Br 22 :beta_rich : beta_rich/F *
*Entries : 37001 : Total Size= 162522 bytes File Size = 57179 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 2.79 *

*Br 23 :rich_kprob : rich_kprob/F *
*Entries : 37001 : Total Size= 162674 bytes File Size = 58380 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 2.73 *

*Br 24 :rich_dist : rich_kprob/F *
*Entries : 37001 : Total Size= 162525 bytes File Size = 58232 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 2.73 *

*Br 25 :rich_npe : rich_npe[3]/F *
*Entries : 37001 : Total Size= 458384 bytes File Size = 119684 *
*Baskets : 148 : Basket Size= 5632 bytes Compression= 3.80 *

*Br 26 :rich_nhit : rich_nhit[3]/I *
*Entries : 37001 : Total Size= 458536 bytes File Size = 51276 *
*Baskets : 148 : Basket Size= 5632 bytes Compression= 8.88 *

*Br 27 :rich_stat : rich_stat/I *
*Entries : 37001 : Total Size= 162522 bytes File Size = 44210 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 3.60 *

*Br 28 :rich_pmts : rich_pmts/I *
*Entries : 37001 : Total Size= 162522 bytes File Size = 33704 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 4.73 *

*Br 29 :rich_tile : rich_tile/I *
*Entries : 37001 : Total Size= 162522 bytes File Size = 39497 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 4.03 *

*Br 30 :rich_nrings : rich_nrings/I *
*Entries : 37001 : Total Size= 162826 bytes File Size = 33699 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 4.73 *

*Br 31 :trd_nsegt : trd_nsegt/I *
*Entries : 37001 : Total Size= 162522 bytes File Size = 48979 *
*Baskets : 148 : Basket Size= 2048 bytes Compression= 3.25 *

*Br 32 :tofql : tofql[4]/F *
*Entries : 37001 : Total Size= 605932 bytes File Size = 540017 *
*Baskets : 148 : Basket Size= 7680 bytes Compression= 1.12 *

*Br 33 :nhit : nhit[6]/I *
*Entries : 37001 : Total Size= 901788 bytes File Size = 281489 *
*Baskets : 148 : Basket Size= 11776 bytes Compression= 3.19 *


*Chain :reco : D:/rootworkspace/BR/data/mote_carlo/AMS_MC/deuteron_mc/crazy.1.root *


and this for 49 times…

hope this helps. Can always post all of it, if desired

So …

  1. You seem to have 50 files and that is possibly why you get everything “rounded to 50” (i.e. all files are very “similar”).
  2. Are you sure that for each event (in all files) rgt2[0] contains a “valid” (event specific) value?
  3. Try to remove the line TTree *tree_deut = (TTree*) ch; and use simply:
TChain *tree_deut = new TChain("reco");
tree_deut->Add("directory*");
  1. Yes indeed, I rechecked my other MC data and that contained 142 files and I check my output there, and surpise surprise the output are all multiple of 142, i.e. 142 events, 284 events, 1420 events etc.
  2. All have valid input, however in each tree I have mostly two files:
    reco;75 and reco;76.
    however all files except 4 out of 50 have reco;75 and reco;76. And these have the same data stored. I asked my supervisor and he said that there is an issue with the supplied files.
  3. Nothing changed

I will get new MC data soon, Ill reply when its resolved, thanks though!

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