Trying to make a histogram out of a delphes .root file

Hello, I have a .root file that was generated by Delphes (and MadGraph). I am currently interested in the parton level, so I’m focusing on bottom quarks before they undergo hadronization.

I want to create histograms for PT, ETA, and PHI associated with the second-highest PT bottom quarks. I’m using PyROOT and I’m trying to extract data on the second-highest PT bottom quarks, as well as their PT, PHI, and ETA values. Here’s a snippet of my code:

Loop over all particles in the event

for i in range(branchParticle.GetEntries()):
    particle = branchParticle.At(i)  # Get the current particle

    # Check if the particle is a bottom
    if particle.PID == 5:  # Bottoms have PID equal to 5
        # Store the PT, ETA, and PHI of the bottom
        event_bottom_pts.append(particle.PT)
        event_bottom_etas.append(particle.Eta)
        event_bottom_phis.append(particle.Phi)

# Check if there are at least two bottoms in this event
if len(event_bottom_pts) < 2:
    print("Less than two bottoms in the event. Skipping this event.")
    continue

# Sort the list of PTs of the bottoms in descending order
sorted_pts = sorted(event_bottom_pts, reverse=True)

# The second highest PT is the second element of the sorted list
second_highest_pt = sorted_pts[1]

# Find the information of the bottom with the second highest PT
index_second_highest = event_bottom_pts.index(second_highest_pt)
second_highest_eta = event_bottom_etas[index_second_highest]
second_highest_phi = event_bottom_phis[index_second_highest]

# Add the information of the bottom with the second highest PT to the lists
second_highest_bottom_pts.append(second_highest_pt)
second_highest_bottom_etas.append(second_highest_eta)
second_highest_bottom_phis.append(second_highest_phi)

Fill the histograms with the PTs, ETAs, and PHIs of the bottoms with the second highest PT

for pt, eta, phi in zip(second_highest_bottom_pts, second_highest_bottom_etas, second_highest_bottom_phis):
hist_second_highest_bottom_pt.Fill(pt)
hist_second_highest_bottom_eta.Fill(eta)
hist_second_highest_bottom_phi.Fill(phi)

The problem is that the average value I’m getting is too high, which makes me think there might be a mistake in my code.

I’m quite new to this framework and I’ve never done anything very complex in Python, so please excuse me if I’ve made any significant errors.

ROOT Version:_ 6.30/0.2

Hi,

Welcome to the ROOT community!
It is hard to say that here we are in presence of a misbehaviour of ROOT, so I tend to assume the tool is working fine.
My suggestion would be to simplify the code to the minimum and try to figure out if everything is as you expect, step by step.
Another approach might be more efficient for analyzing ROOT columnar datasets, RDataFrame. As an exercise, reformulating the study in terms of RDataFrame could help you understand even better what’s going on.

Cheers,
D

1 Like

Thank you, Danilo! I’ll review this data frame.

Additionally, I’d like to inquire: could the method I’m using to access the Root file be causing the issue? As mentioned, I’m attempting to access the bottom quarks at the partonic level, before they undergo hadronization. I’m trying to retrieve these particles using the following code:

# Create chain of root trees (chain is a clas that contain all the root trees)
chain = ROOT.TChain("Delphes")
chain.Add(inputFile)


# Create an ExRootTreeReader object to read the tree chain
tree = ROOT.ExRootTreeReader(chain)
# Get the total number of events in the file
numberOfEntries = tree.GetEntries()


# Use the branch "Particle"
branchParticle = tree.UseBranch("Particle")


# Lists to store the PTs, ETAs, and PHIs of the bottoms with second highest PT of each event
second_highest_bottom_pts = []
second_highest_bottom_etas = []
second_highest_bottom_phis = []

# Create histograms for PT, ETA, and PHI of bottoms with second highest PT
hist_second_highest_bottom_pt = ROOT.TH1F("second_highest_bottom_pt", "PT of bottoms with second highest PT; PT (GeV/c); Number of events", 40, 0, 1000)
hist_second_highest_bottom_eta = ROOT.TH1F("second_highest_bottom_eta", "ETA of bottoms with second highest PT; ETA; Number of events", 40, -5, 5)
hist_second_highest_bottom_phi = ROOT.TH1F("second_highest_bottom_phi", "PHI of bottoms with second highest PT; PHI; Number of events", 40, -7, 7)

# Loop over all events in the tree
for entry in range(numberOfEntries):
    # Read the current event from the tree
    tree.ReadEntry(entry)
    
    # List to store the PTs, ETAs, and PHIs of the bottoms in this event
    event_bottom_pts = []
    event_bottom_etas = []
    event_bottom_phis = []

    # Loop over all particles in the event
    for i in range(branchParticle.GetEntries()):
        particle = branchParticle.At(i)  # Get the current particle

        # Check if the particle is a bottom
        if particle.PID == 5:  # Bottoms have PID equal to 5
            # Store the PT, ETA, and PHI of the bottom
            event_bottom_pts.append(particle.PT)
            event_bottom_etas.append(particle.Eta)
            event_bottom_phis.append(particle.Phi)

    # Check if there are at least two bottoms in this event
    if len(event_bottom_pts) < 2:
        print("Less than two bottoms in the event. Skipping this event.")
        continue

    # Sort the list of PTs of the bottoms in descending order
    sorted_pts = sorted(event_bottom_pts, reverse=True)
    
    # The second highest PT is the second element of the sorted list
    second_highest_pt = sorted_pts[1]

    # Find the information of the bottom with the second highest PT
    index_second_highest = event_bottom_pts.index(second_highest_pt)
    second_highest_eta = event_bottom_etas[index_second_highest]
    second_highest_phi = event_bottom_phis[index_second_highest]

    # Add the information of the bottom with the second highest PT to the lists
    second_highest_bottom_pts.append(second_highest_pt)
    second_highest_bottom_etas.append(second_highest_eta)
    second_highest_bottom_phis.append(second_highest_phi)

# Fill the histograms with the PTs, ETAs, and PHIs of the bottoms with second highest PT
for pt, eta, phi in zip(second_highest_bottom_pts, second_highest_bottom_etas, second_highest_bottom_phis):
    hist_second_highest_bottom_pt.Fill(pt)
    hist_second_highest_bottom_eta.Fill(eta)
    hist_second_highest_bottom_phi.Fill(phi)

Again, please excuse me if I’ve made any significant errors.

Hi,

There are no apparent errors in this long snippet. I think it’s just a matter to debug the issue, which does not look to be related to ROOT itself.

Cheers,
D

I have an update:

After applying the condition ‘particle.Status == 23’ to all particles, I successfully obtained the correct results. However, I was uncertain about the precise meaning of this condition. Upon further investigation, I discovered that in the context of Delphes, it typically indicates that the particle is stable and has not undergone further decay.

Additionally, I found that in the context of Pythia, it refers to outgoing particles from the hardest subprocess (source : Particle Properties).

Given my limited knowledge of both frameworks, I’m unsure of the exact implications of this condition on my results. However, it appears to have resolved the issue and produced accurate results.