Taking a random subsample of a histogram

Dear ROOTers,
I have a histogram of a variable and I want to split it randomly into two histograms, one containing a random x% of the events (of the total sample, not splitting each bin into x% and 100-x%), and the other containing the remaining 100-x%. I am not sure if there is a built in function for what I need and if not, which would be the easiest way of implementing it.

Hi @Vangi ,
I think we need @moneta here, let’s ping him.

Just to clarify, I don’t want the value of x to be random (I want to be able to set its value manually), but the events chosen to be random - e.g. if I choose 10% the subset chosen is different each time I run my script.

Are your original data stored in histograms or in trees ? If they are stored in histograms that might be a bit tricky to pick up “some events” as the individual events are lost one a bin is filled. You will be able to pick only the bins contents.

Hi couet,
I also have the same problem. But for my case it is 2D histogram I want randomly split the histogram into two new histograms say 20% and 80% of the original histogram. Is it feasible?

Yes, the events are currently stored as histograms, unfortunately. I guess I could change this and store the value and weight of each event into tree branches instead. In that case, how would one proceed?

I guess you can look at this example