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.
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:
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.
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.
Nothing changed
I will get new MC data soon, Ill reply when its resolved, thanks though!