# Applying cuts after drawing a histogram

**URL:** <https://root-forum.cern.ch/t/applying-cuts-after-drawing-a-histogram/33937>\
**Category:** Newbie\
**Created:** [May 7, 2019, 11:58am UTC](https://root-forum.cern.ch/t/applying-cuts-after-drawing-a-histogram/33937 "2019-05-07T11:58:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KatR](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/d9b06d/32.png) [@KatR](https://root-forum.cern.ch/u/KatR)\
**Post date:** [May 7, 2019, 11:58am UTC](https://root-forum.cern.ch/t/applying-cuts-after-drawing-a-histogram/33937/1 "2019-05-07T11:58:51Z")

</div>

Hi all,

I think this is probably a really basic question, but my knowledge of coding in general is very shaky so I’m finding it hard to understand the documentation. I’ve been asked to ‘plot variable x in bins of variable y’. To do this I’ve put together a macro based on MakeClass, plotted a TH1F of variable x and now I want to plot specific ranges to display it in bins of variable y.

For example, if x is the number of tracks in a jet and y is the jet energy, I have a loop that determines the range of jet energy and finds the upper and lower limits of bins when the jet energy is split into 10 bins.

Given I know these limits, I’d like 10 plots of the number of tracks, each in one of the ranges I’ve found. I thought this should be doable by plotting the number of tracks, and then repeatedly applying axis-\>SetLimits(), GetXaxis-\>SetRangeUser or even just SetRange, but none of these do what I’d like. Should these commands work (i.e. it’s a problem with how I’m using them in my code) or is it likely I’ll need to try an entirely different approach?

Thanks for any help!

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 7, 2019, 12:27pm UTC](https://root-forum.cern.ch/t/applying-cuts-after-drawing-a-histogram/33937/3 "2019-05-07T12:27:11Z")

</div>

How about you fill a [TH2D or TH2F](https://root.cern.ch/doc/master/classTH2.html) (i.e. “y:x”) and then use some of the [TH2::ProjectionX](https://root.cern.ch/doc/master/classTH2.html#a974ece9e7d260f92df00a39dba14e5b0), [TH2::ProjectionY](https://root.cern.ch/doc/master/classTH2.html#a04917d549aa802ce2489692da74348f8), [TH2::ProfileX](https://root.cern.ch/doc/master/classTH2.html#a19eb4ae4f4d399b0f4ad820d838de75e) and / or [TH2::ProfileY](https://root.cern.ch/doc/master/classTH2.html#a37dfa8181177e3a9d71274c0df9144f8) methods.

See also the [THistPainter Class Reference](https://root.cern.ch/doc/master/classTHistPainter.html).
