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

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.

As long as you stick to “top-bottom” and / or “left-right”, you can easily apply to your “h1” histogram: TH2::ProfileX, TH2::ProfileY, TH2::ProjectionX, TH2::ProjectionY

For the “45 degree angle”, you would need to draw the “distance from a point to a line”:

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

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