# Getting the Primary Vertex for Event Cuts

**URL:** <https://root-forum.cern.ch/t/getting-the-primary-vertex-for-event-cuts/36251>\
**Category:** Newbie\
**Created:** [October 8, 2019, 1:58am UTC](https://root-forum.cern.ch/t/getting-the-primary-vertex-for-event-cuts/36251 "2019-10-08T01:58:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Skip](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/skip/32/16865_2.png) [@Skip](https://root-forum.cern.ch/u/Skip)\
**Post date:** [October 8, 2019, 1:58am UTC](https://root-forum.cern.ch/t/getting-the-primary-vertex-for-event-cuts/36251/1 "2019-10-08T01:58:45Z")

</div>

_ROOT Version:_ 6.14/02  
_Platform:_ Ubuntu  
_Compiler:_ Default

* * *

Hey, all. I’m trying to make some event cuts and having a heck of a time doing so. I want to cut for Vz \< 40.0 cm and Vr \< 2.0 cm. This is the code I’m trying to use to call Vx, Vy, and Vz:

```auto
if (TMath::Abs(event->primaryVertex().z()) > 40.0 )
     {
       continue;
     }

if (TMath::Abs( sqrt(pow(event->primaryVertex().x(),2) + pow(event->primaryVertex().y(),2))) > 2.0 )
     {
       continue;
     }

```

The code runs fine, but The cuts seem to do nothing. I created some histograms to check the output, and they’re all at 0 for Vz and Vr both before and after the cuts. I looked at the picos I’m using and Vz, Vx, and Vy are all in there. What am I doing wrong?

Thanks!

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [October 8, 2019, 4:01pm UTC](https://root-forum.cern.ch/t/getting-the-primary-vertex-for-event-cuts/36251/2 "2019-10-08T16:01:36Z")

</div>

Hi,

could you do a printout right before these two cuts, for example

`printf("Vz = %.0f cm, Vr = %.0f\n", TMath::Abs(event->primaryVertex().z()), TMath::Abs(TMath::Sqrt(TMath::Sq(event->primaryVertex().x()) + TMath::Sq(event->primaryVertex().y()))));`

to make sure these numbers you are trying to cut on are indeed valid and are in cm - a lot of things may be wrong with them!

> [@Skip](#):
>
> they’re all at 0 for Vz and Vr

I think this suggests they are stored in meters, not cm.

---

<div class="post-metadata">

**Author:** ![Skip](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/skip/32/16865_2.png) [@Skip](https://root-forum.cern.ch/u/Skip)\
**Post date:** [October 9, 2019, 2:27pm UTC](https://root-forum.cern.ch/t/getting-the-primary-vertex-for-event-cuts/36251/3 "2019-10-09T14:27:43Z")

</div>

I thought that might be the case, but when I would change the histogram axis scale nothing would happen. I had done some cout statements and they all came up 0. Here’s the cout code, in the event loop prior to the cuts:

```auto
cout << "Vz: " << TMath::Abs(event->primaryVertex().z()) << endl;
    cout << "Vr: " << TMath::Abs( sqrt(pow(event->primaryVertex().x(),2) + 
      pow(event->primaryVertex().y(),2))) << endl;
    cout << "VzVPD: " << event->vzVpd() << endl;
    cout << "Full Vertex: " << event->primaryVertex() << endl;

```

And here’s what I get when I run it, as an example; obviously there are thousands of these, but they all have 0 for every primaryVertex() entry:  
Vz: 0  
Vr: 0  
VzVPD: 5.60292  
Full Vertex: 0 0 0

When I do the cuts in Python, everything is fine. Python calls (via uproot) “Event.mPrimaryVertexX”. My code for reading those is as follows:

```auto
data = up.open('st_physics_19999_raw_1234.picoDst.root')

PicoDst = data["PicoDst"]

# These jagged arrays are to get the data out of the .root file.
mEpdId = PicoDst.arrays([b"EpdHit.mId"])
mEpdnMIP = PicoDst.arrays([b"EpdHit.mnMIP"])
mRefMult = PicoDst.arrays([b"Event.mGRefMult"])
mxVert = PicoDst.arrays([b"Event.mPrimaryVertexX"])
myVert = PicoDst.arrays([b"Event.mPrimaryVertexY"])
mzVert = PicoDst.arrays([b"Event.mPrimaryVertexZ"])
mVzVpd = PicoDst.arrays([b"Event.mVzVpd"])
mNBTOFMatch = PicoDst.arrays([b"Event.mNBTOFMatch"])

```

Is there a way I can just call these in ROOT? I thought that would be event-\>primaryVertex().X(), but that clearly isn’t working.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [October 9, 2019, 5:11pm UTC](https://root-forum.cern.ch/t/getting-the-primary-vertex-for-event-cuts/36251/4 "2019-10-09T17:11:27Z")

</div>

> [@Skip](#):
>
> Is there a way I can just call these in ROOT?

No idea. I guess I could come up with a solution if I had access to your `st_physics_19999_raw_1234.picoDst.root`.

---

<div class="post-metadata">

**Author:** ![Skip](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/skip/32/16865_2.png) [@Skip](https://root-forum.cern.ch/u/Skip)\
**Post date:** [October 9, 2019, 5:48pm UTC](https://root-forum.cern.ch/t/getting-the-primary-vertex-for-event-cuts/36251/5 "2019-10-09T17:48:49Z")

</div>

Here’s a link to a similar pico:  
[https://drive.google.com/file/d/1BjZJZiu9wsbZZGTwxS3d7C7w0TK4Ekfu/view?usp=sharing](https://drive.google.com/file/d/1BjZJZiu9wsbZZGTwxS3d7C7w0TK4Ekfu/view?usp=sharing)

It’s for 27 GeV Au+Au. Not sure what all’s included, but I can get the primary vertex information out of this in Python and the pico has histograms for it in ROOT.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [October 9, 2019, 6:22pm UTC](https://root-forum.cern.ch/t/getting-the-primary-vertex-for-event-cuts/36251/6 "2019-10-09T18:22:45Z")

</div>

Ok, it looks like this file has to be processed in a dedicated framework, which I don’t have obviously. But you should definitely access branches named `Event.mPrimaryVertexX`, `Event.mPrimaryVertexY`, and `Event.mPrimaryVertexZ` rather than `event->primaryVertex().x()` and so on.

---

<div class="post-metadata">

**Author:** ![Skip](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/skip/32/16865_2.png) [@Skip](https://root-forum.cern.ch/u/Skip)\
**Post date:** [October 10, 2019, 8:54pm UTC](https://root-forum.cern.ch/t/getting-the-primary-vertex-for-event-cuts/36251/7 "2019-10-10T20:54:57Z")

</div>

Problem solved. I was using an outdated version of StPicoEvent.h, so it was reading something that was allowed (i.e. no syntax errors), but that didn’t have any values associated. It feels like that ought to throw an error, but instead it just gave back all zeroes.

Thanks; and happy ROOTing, all!
