Using FindBin for a collection of events

Hi

I am having a vector which includes floats, and want to match these values with a certain collection of TH1 objects–Those TH1 were filled after some additional cuts on these values, which means that the vector which holds the floats, has more values that were put in the TH1 plots… I just want to loop inside the vector, and if this value is found in some of the bins in one of the TH1 plots then do some stuff, otherwise, skip this event and go to the next one… So, is my following script correct ?

///event is the vector which holds all the values

[code]for(unsigned int i = 0; i < event.size(); i++) {

int bin;
bin = histos_Obs_data[i]->FindBin(event[i]);

            if (!bin); continue;

}[/code]

Thanks in advance

Hi,

I don’t understand what you are trying to do. Are you looking for a bin with a certain content y? In that case TH1::GetBinWithContent() is probably what you need, see root.cern.ch/root/html/TH1#TH1:GetBinWithContent

Cheers, Axel.

Hi Axel

Thanks for your reply… I think, is better to stick in FindBin, as I am using TAxis method to define the bins (in a previous step)… Nevertheless, the

if (!bin) continue;

part is enough to ensure that if the value is not found in any of the bins, then just skip this one ?

Cheers

Hi,

if I guessed right concerning what you want to do in my previous post (you didn’t confirm that): you are welcome to use FindBin(), but it doesn’t do nor return what you want :slight_smile:

Cheers, Axel.

Hi again!

Well, actually, the complete script is like

                int bin;
                float binContent_data;
                float binContent_estim;
                bin = histos_Obs_data[i]->FindBin(event[i]);
                if (!bin)  continue;
                binContent_data = histos_Obs_data[i]->GetBinContent(bin);
                binContent_estim = histos_Obs_estim[i]->GetBinContent(bin);

which if I am not wrong, could work fine wrt to what you said, ie supplementary also using GetBinContent…no ?? The only reason to use FindBin, is in order just to skip this event if is not also present in the TH1 with the additional step of

if (!bin) continue;

Is there a way to do this in one step with GetBinContent(float) ?

Thanks in advance!

Cheers

Hi,

FindBin() does not do what you need, TH1::GetBinWithContent() does, see root.cern.ch/root/html/TH1#TH1:GetBinWithContent

Cheers, Axel.

Hi

I discovered ( probably the hard way :confused: ) that you were right about FindBin , as in case that the “event” I am looking in not in the h1, then it will just return the overflow bin, which is not what I need…

So, about the GetBinWithContent method,sorry, but it looks I am too stupid to get it…I cannot really understand in the documentation the first line

“compute first binx in the range [firstx,lastx] for which…”

what ‘compute’ stands for?

so, can you give me a specific example how to find a value in the histogram and in case the value really exist in the histo get the correspondant bin ?

Thanks in advance!

Alex

Hi…Any volunteer to help ?? :wink: :wink:

in the doc “compute” should be replaced by “find”

Rene