Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:12:07

0001 #! /usr/bin/env python
0002 from optparse import OptionParser
0003 import sys
0004 import os
0005 import datetime
0006 from array import *
0007 from ROOT import *
0008 import numpy
0009 import math
0010 import glob
0011 
0012 gROOT.SetBatch(True)
0013 
0014 def read_data(file_path):
0015     eta = []
0016     dn_deta = []
0017     err_plus = []
0018     err_minus = []
0019 
0020     with open(file_path, 'r') as file:
0021         lines = file.readlines()
0022 
0023     start_reading = False
0024 
0025     for line in lines:
0026         if line.strip() == "&":  # Check for the end marker
0027             break
0028 
0029         if start_reading:
0030             # Split the line into components and convert them to float
0031             columns = line.split()
0032             if len(columns) == 4:
0033                 eta.append(float(columns[0]))
0034                 dn_deta.append(float(columns[1]))
0035                 err_plus.append(float(columns[2]))
0036                 err_minus.append(-1.*float(columns[3]))
0037 
0038         if "dN/dEta vs. Eta" in line:
0039             start_reading = True
0040 
0041     return eta, dn_deta, err_plus, err_minus
0042 
0043 
0044 if __name__ == '__main__':
0045     fout = TFile("./PHOBOS-PhysRevC.83.024913/auau_200GeV.root", "RECREATE") # Reference: https://journals.aps.org/prc/supplemental/10.1103/PhysRevC.83.024913
0046     
0047     phobos_list = glob.glob("./PHOBOS-PhysRevC.83.024913/*.txt")
0048     for f in phobos_list:
0049         eta, dn_deta, err_plus, err_minus = read_data(f)
0050         print(f)
0051         print(eta)
0052         print(dn_deta)
0053         print(err_plus)
0054         print(err_minus)
0055         print("")
0056         
0057         gr = TGraphAsymmErrors(len(eta), array('d', eta), array('d', dn_deta), array('d', [0]*len(eta)), array('d', [0]*len(eta)), array('d', err_minus), array('d', err_plus))
0058         gr.SetName(f.split("/")[-1].replace(".txt", "").replace("-", "to"))
0059         gr.SetTitle(f.split("/")[-1].replace(".txt", "").replace("-", "to"))
0060         gr.Write(f.split("/")[-1].replace(".txt", "").replace("-", "to"))
0061     
0062     fout.Close()
0063     
0064