Hello I'm working with a data file in the following format:
.
.
Where each set corresponds to an "Event". If the user is interested and knows some particle physics the four rightmost values represent the components of the four-momentum of a particle. I'm analyzing a particle reaction of a photon and proton turning into a neutron + 2 pi plus + pi min. The first row, '1', displays the four-momentum of the photon, and second row '8', displays the four momentum of the piplus, the third row '9' displays the four momentum of the piminus and the last row is for the remaining piplus. The first column after the binary is the particles momentum in the x-direction, the second is the y, the third is the z, and the final column is the particle energy.
Anyway my goal here is to look through this particularly large .dat file (There are over 100,000 events) and store these momentum values into vectors and print out the neutron mass. Here is the code:
I'm currently working with just the first event which is why the I created the Event iterator from lines 0 to 5. Now that you've seen the code my issue if the following:
When assigning values to both PiPlus mesons using the SetPxPyPz function the function will make the PiPlus[0] and PiPlus[1] TLorentzVectors the same. I'm not sure how to fix this. For example the program will read through the first event given above and it will properly assign the four-momentum values to each particle but it will duplicate the PiPlus momentums. I've tried to do something like single out the exact line which contains the PiPlus[0] and the second PiPlus and store them separately but this doesn't work. Any ideas? I've been working with this specific part of code for two weeks and I can't get it to run properly.
Thanks!
Output:4
1 0 0.000e+00 0.00000e+00 5.00000e+00 5.00000+00
8 1 2.842390e-01 -1.818300e-01 6.695100e-01 7.626910e-01
9 -1 -5.239400 e-02 4.074490e-01 4.607670e-01 6.329820e-01
8 1 -4.561950e-01 -1.510400e-02 3.427575e+00 3.460667e+00
4
1 0 0.000000e+00 0.000000e+00 5.000000e+00 5.000000e+00
8 1 2.842390e-01 -1.818300e-01 6.695100e-01 7.626910e-01
9 -1 -5.239400e-02 4.074490e-01 4.607670e-01 6.329820e-01
8 1 -4.561950e-01 -1.510400e-02 3.427575e+00 3.460667e+00
..
.
Where each set corresponds to an "Event". If the user is interested and knows some particle physics the four rightmost values represent the components of the four-momentum of a particle. I'm analyzing a particle reaction of a photon and proton turning into a neutron + 2 pi plus + pi min. The first row, '1', displays the four-momentum of the photon, and second row '8', displays the four momentum of the piplus, the third row '9' displays the four momentum of the piminus and the last row is for the remaining piplus. The first column after the binary is the particles momentum in the x-direction, the second is the y, the third is the z, and the final column is the particle energy.
Anyway my goal here is to look through this particularly large .dat file (There are over 100,000 events) and store these momentum values into vectors and print out the neutron mass. Here is the code:
import numpy as np import itertools from ROOT import TLorentzVector Proton = TLorentzVector(0.0,0.0,0.0,0.938) Photon,PiPlus=TLorentzVector(),2*[TLorentzVector()] PiMinus=TLorentzVector(0.0,0.0,0.0,0.0) Neutron=TLorentzVector(0.0,0.0,0.0,0.0) # nEvents = 0 nPiPlus = 0 # with open("n3pi.dat", "r") as dataFile: # open file and read in ascii events line-by-line # the line will contain either the number of particles which indicates start of an event # or the line contains particle information: id charge Px Py Pz E # Events= list(itertools.islice(dataFile,0,5,1)) for line in Events: word = line.split() # split line into a list of words value = int(word[0]) if value == 4: nPiPlus = 0 nEvents += 1 elif value == 1: #Photon beam Photon.SetPxPyPzE(float(word[2]),float(word[3]),float(word[4]),float(word[5])) elif value == 8: # piPlus meson PiPlus[nPiPlus].SetPxPyPzE(float(word[2]),float(word[3]),float(word[4]),float(word[5])) nPiPlus += 1 elif value == 9: PiMinus.SetPxPyPzE(float(word[2]),float(word[3]),float(word[4]),float(word[5])) Neutron = (Photon+Proton-(PiMinus+PiPlus[0]+PiPlus[1])).Mag() print("The mass of the Neutron for the first event is",Neutron)...
I'm currently working with just the first event which is why the I created the Event iterator from lines 0 to 5. Now that you've seen the code my issue if the following:
When assigning values to both PiPlus mesons using the SetPxPyPz function the function will make the PiPlus[0] and PiPlus[1] TLorentzVectors the same. I'm not sure how to fix this. For example the program will read through the first event given above and it will properly assign the four-momentum values to each particle but it will duplicate the PiPlus momentums. I've tried to do something like single out the exact line which contains the PiPlus[0] and the second PiPlus and store them separately but this doesn't work. Any ideas? I've been working with this specific part of code for two weeks and I can't get it to run properly.
Thanks!