# Plotting events while sweeping across Plane instead of events in X and Y separately

**URL:** <https://root-forum.cern.ch/t/plotting-events-while-sweeping-across-plane-instead-of-events-in-x-and-y-separately/32355>\
**Category:** Newbie\
**Created:** [January 18, 2019, 6:09pm UTC](https://root-forum.cern.ch/t/plotting-events-while-sweeping-across-plane-instead-of-events-in-x-and-y-separately/32355 "2019-01-18T18:09:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gibster15](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/7993a0/32.png) [@gibster15](https://root-forum.cern.ch/u/gibster15)\
**Post date:** [January 18, 2019, 6:09pm UTC](https://root-forum.cern.ch/t/plotting-events-while-sweeping-across-plane-instead-of-events-in-x-and-y-separately/32355/1 "2019-01-18T18:09:11Z")

</div>

Hello Experts,

I’m not sure if this is possible/simple, but I’ll ask anyway.

I have two 1D histograms, one that is events in X, and one that is events in Y.

Normally, I create 2D plots that are X vs Y, creating simple histograms using the following snippet of code:

ch.Draw(“Y:X\>\>h1(500,-10,10,500,-10,10)”,"(X\>10&&X\<10)&&(Y\>-10&&Y\<10))",“COL4Z”);

SO this works fine as intended. But what I want to try and do though, is create a 1D plot of events in the XY plane. So as I sweep from left to right on the XY plane, I can figure out how many specific events were there. And then I want to be able to choose the angle I sweep across. Say, maybe I want to sweep top to bottom, or sweep from a 45 degree angle from corner to corner.

I am not sure how to do this, and would be grateful if someone could point me in the right direction if it’s possible?

Thank you very much.

---

<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:** [January 18, 2019, 6:19pm UTC](https://root-forum.cern.ch/t/plotting-events-while-sweeping-across-plane-instead-of-events-in-x-and-y-separately/32355/2 "2019-01-18T18:19:40Z")

</div>

As long as you stick to “top-bottom” and / or “left-right”, you can easily apply to your “h1” histogram: [TH2::ProfileX](https://root.cern.ch/doc/master/classTH2.html#a19eb4ae4f4d399b0f4ad820d838de75e), [TH2::ProfileY](https://root.cern.ch/doc/master/classTH2.html#a37dfa8181177e3a9d71274c0df9144f8), [TH2::ProjectionX](https://root.cern.ch/doc/master/classTH2.html#a974ece9e7d260f92df00a39dba14e5b0), [TH2::ProjectionY](https://root.cern.ch/doc/master/classTH2.html#a04917d549aa802ce2489692da74348f8)

For the “45 degree angle”, you would need to draw the “[distance from a point to a line](https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line)”:

```auto
ch.Draw("X * TMath::Sin(TMath::DegToRad() * 45.) - Y * TMath::Cos(TMath::DegToRad() * 45.)");

```

---

<div class="post-metadata">

**Author:** ![gibster15](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/7993a0/32.png) [@gibster15](https://root-forum.cern.ch/u/gibster15)\
**Post date:** [January 21, 2019, 12:39pm UTC](https://root-forum.cern.ch/t/plotting-events-while-sweeping-across-plane-instead-of-events-in-x-and-y-separately/32355/3 "2019-01-21T12:39:55Z")

</div>

Great. Thank’s for the insight! This is helpful.
