#!/usr/bin/env python # ----------------------------------------------------------------------------------- # # # ROOT macro for reading data for the Applied Statistics exam 2016 problem 5.1. # # Author: Troels C. Petersen (NBI) # Email: petersen@nbi.dk # Date: 11th of January 2017 # # ----------------------------------------------------------------------------------- # from ROOT import * from array import array import math def sqr(a) : return a*a # ----------------------------------------------------------------------------------- # # ----------------------------------------------------------------------------------- # # Setting what to be shown in statistics box: gStyle.SetOptStat("eMR") gStyle.SetOptFit(1111) # Text to write on the plot: text = TLatex() text.SetNDC() pi = TMath.Pi() SavePlots = False # ----------------------------------------------------------------------------------- # # Read data: # ----------------------------------------------------------------------------------- # # Define points for a graph with errors and then the graph: Ndata = 41 x = array("f", []) y = array("f", []) ex = array("f", []) ey = array("f", []) with open( 'data_LukeLightningLights.txt', 'r' ) as infile : for line in infile: line = line.strip().split() x.append(float(line[0])) ex.append(float(line[1])) y.append(float(line[2])) ey.append(float(line[3])) # Print the numbers as a sanity check print " Read data: %6.3f %6.3f %6.3f %6.3f"%(float(line[0]), float(line[1]), float(line[2]), float(line[3])) Graph_x = TGraphErrors(Ndata, x, y, ex, ey) canvas = TCanvas("canvas", "", 20, 20, 1000, 600) Graph_x.Draw("AP") canvas.Update() #---------------------------------------------------------------------------------- # End program... #---------------------------------------------------------------------------------- raw_input('Press Enter to exit')