Home | News | Documentation | Download

Filtering the events using a std::map in a TTree and create a histogram with the results

Hi,

lets assume I have a TTree that contains a standard branch Double_t dblVar, and a std::map mapVar.

Now, I want to create a histogram of dblVar applying some cuts to the events fulfilling that any of the second elements of mapVar fulfils a given condition.

The problem is that if I do

myTree->Draw("dblVar>>histo", "mapVar.second<100" );

This will create an entry at histo for each element at map (for the corresponding entry) that fulfils the condition. While, I would be willing that for any element (for the corresponding entry) at varMap fulfilling the condition would create a single entry in my histogram.

I hope the problem is clearly stated.

In brief, if my map would be the following for a given entry {{0,50},{1,50},{1,150}}, it will create two entries in my histogram because there are two elements bellow 100.

What would be the most elegant way to achieve what I am looking for?

I would expect I could apply something like

myTree->Draw("dblVar>>histo", "MapMin(mapVar)<100" );

where I implement that MapMin should return the minimum value of the second element of the std::map, and myTree is inherited from TTree so I could implement there my MinMax method.

Any insight is welcome!
Thanks!

Hello,

Iā€™m not sure if this can be easily done with TTree->Draw(), Iā€™d suggest to use RDataFrame. You can use a filter that calls your own MapMin(const std::map<...> &mapVar) function and then the Histo1D action to create the historgram.

Cheers,
Jakob

1 Like

Can you be spelt either

myTree->Draw("dblVar>>histo", "Min$(mapVar.second)<100" );

or

myTree->Draw("dblVar>>histo", "Sum$( (mapVar.second<100) ) > 0" );

Ok, that works awesome. It does exactly what I need.

Where I can learn what other functions I am allowed to use on the std::map apart from Min and Sum? Where this is documented?

Thanks!

@jblomer Yes, we should think about migrating our code to RDataFrame approach. But for the moment we are using so much the Draw method that will take some time to do the transition.

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