# How to select events in a 2D plot to make an ellipse

**URL:** <https://root-forum.cern.ch/t/how-to-select-events-in-a-2d-plot-to-make-an-ellipse/46424>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [August 24, 2021, 10:13am UTC](https://root-forum.cern.ch/t/how-to-select-events-in-a-2d-plot-to-make-an-ellipse/46424 "2021-08-24T10:13:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siddharth\_Parashari](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/siddharth_parashari/32/25501_2.png) [@Siddharth\_Parashari](https://root-forum.cern.ch/u/Siddharth_Parashari)\
**Post date:** [August 24, 2021, 10:13am UTC](https://root-forum.cern.ch/t/how-to-select-events-in-a-2d-plot-to-make-an-ellipse/46424/1 "2021-08-24T10:13:21Z")

</div>

Hi,  
I am trying to use an equation to select only specific events to plot an elliptical shape for my data. I have used all sorts of equations for ellipse but the process doesn’t seem to work. The plot in which the events should be selected is attached below. One easily see the elliptical shape at the line joining 400 keV at both axes, I need to select only those events.  
Is there any way to do that?

Thanks.  
[Mod A E1 vs E2.pdf](https://root-forum.cern.ch/uploads/short-url/6ldg9F8kqrWGLBG60LeLHbXWWIJ.pdf) (38.6 KB)

* * *

_Please read [tips for efficient and successful posting](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292) and [posting code](https://root-forum.cern.ch/t/posting-code-read-this-first/28293)_

_ROOT Version:_ Not Provided  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [August 24, 2021, 10:15am UTC](https://root-forum.cern.ch/t/how-to-select-events-in-a-2d-plot-to-make-an-ellipse/46424/2 "2021-08-24T10:15:22Z")

</div>

Hi @Siddharth_Parashari ,  
can you please share the code you used and point out what does not work exactly? Is the selection wrong (in which case I’m not sure we can help) or is there a problem with some calls to ROOT classes?

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![Siddharth\_Parashari](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/siddharth_parashari/32/25501_2.png) [@Siddharth\_Parashari](https://root-forum.cern.ch/u/Siddharth_Parashari)\
**Post date:** [August 24, 2021, 10:30am UTC](https://root-forum.cern.ch/t/how-to-select-events-in-a-2d-plot-to-make-an-ellipse/46424/3 "2021-08-24T10:30:37Z")

</div>

Here is the code that I’m using to fill the histogram.

firedPxA and B are the pixel energies.  
I am summing two pixel to check if their sum is 511±3sig and then I’m trying to plot correlated 2D histogram.

```auto
if( !((firedPxA[0]==32 && firedPxA[1]==13) || (firedPxA[0]==13 && firedPxA[1]==32)) ) continue;

 Float_t sum_2fired =0;
   if(!(q[firedPxA[0]]==-999) && !(q[firedPxA[1]]==-999))
    {
    sum_2fired= q[firedPxA[0]]+q[firedPxA[1]];
    }

if( sum_2fired>E_511min[0] && sum_2fired<E_511max[0] && (((pow((q[firedPxA[0]]-250)*(0.707),2)+(pow((q[firedPxA[1]]-250)*(0.707),2))))/pow(sum_2fired,2) + ((pow((q[firedPxA[0]]-250)*(0.85),2)-(pow((q[firedPxA[1]]-250)*(0.52),2))))/pow(q[firedPxA[0]],2))<1)

    
  {
    hE6Ac->Fill(sum_2fired);
    hE6A->Fill(q[firedPxA[0]]);
    hE5A->Fill(q[firedPxA[1]]);
    hE6_E4->Fill(q[firedPxA[0]],q[firedPxA[1]]);
  }

```

The output plots of this code is attached. You can find the 2D histo as the rightmost plot in the canvas.  
I need to select only the eliptical area at the center of the rightmost plot but it is not working.  
[two pix sum.pdf](https://root-forum.cern.ch/uploads/short-url/iLpG9bppE1wIw6WCTIkoBhUDD4W.pdf) (33.1 KB)

Thanks.

---

<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:** [August 24, 2021, 10:47am UTC](https://root-forum.cern.ch/t/how-to-select-events-in-a-2d-plot-to-make-an-ellipse/46424/4 "2021-08-24T10:47:33Z")

</div>

Try something like this (creates an “ellipse”):

`your_tree->Draw("E1:E2", "E1 > 0. && E2 > 0. && pow((E1 + E2 - 511.) / 50., 2.) + pow((E1 - E2) / 150., 2.) < 1."); // assumes 3sig(E1+E2) = 50. and 3sig(E1-E2) = 150.`

and / or that (creates a “rectangle”):

`your_tree->Draw("E1:E2", "E1 > 0. && E2 > 0. && abs(E1 + E2 - 511.) < 50. && abs(E1 - E2) < 150."); // assumes 3sig(E1+E2) = 50. and 3sig(E1-E2) = 150.`

---

<div class="post-metadata">

**Author:** ![Siddharth\_Parashari](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/siddharth_parashari/32/25501_2.png) [@Siddharth\_Parashari](https://root-forum.cern.ch/u/Siddharth_Parashari)\
**Post date:** [August 24, 2021, 11:57am UTC](https://root-forum.cern.ch/t/how-to-select-events-in-a-2d-plot-to-make-an-ellipse/46424/5 "2021-08-24T11:57:49Z")

</div>

Thank you so much. This works

---

<div class="post-metadata">

**Author:** ![George65](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/74df32/32.png) [@George65](https://root-forum.cern.ch/u/George65)\
**Post date:** [September 9, 2021, 6:35am UTC](https://root-forum.cern.ch/t/how-to-select-events-in-a-2d-plot-to-make-an-ellipse/46424/7 "2021-09-09T06:35:24Z")

</div>

Thanks for sharing. I found a lot of interesting information here!
