Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python programming The test cells are shown below # test cell can't work since reading a file is called that you don't have. Consider it

Python programming

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

The test cells are shown below

image text in transcribed

# test cell can't work since reading a file is called that you don't have. Consider it example code. # main script import time start = time.process_time() success = runFit("ringdata.txt.gz", "output.txt.gz") stop = time.process_time() print ("success: ", success) print ("fit time: ", (stop-start))

# testing part truthdata = readData("ringtruth.txt") outputdata = readData("output.txt.gz")

# test 1 nevents = int(outputdata[-1,0]) assert nevents == int(len(truthdata) / 2) ,'equality of data volume test failed.'

image text in transcribed

# test 2: compare your fit results with the truth data and determine the fit efficiency. # Again, can't run since you don't have the 1000 event data file for the assignment but # may clarify what is meant by fit efficiency. truthrow = 0 counter = 0 for evt in range(1,nevents+1): # select event number data evtdata = outputdata[outputdata[:,0]==evt] for i in range(2): # now check on values trueixy = truthdata[truthrow, 0] trueslxy = truthdata[truthrow, 2] ixy = evtdata[i, 2] slxy = evtdata[i, 4] errixy = evtdata[i, 3] errslxy = evtdata[i, 5] # catch fit failed case if errixy==0.0 and errslxy==0.0: truthrow += 1 # next line continue # skip the rest below bool1 = trueixy = ixy - errixy bool2 = trueslxy = slxy - errslxy if bool1 and bool2: counter += 1 else: print(bool1, bool2) print('True: ', trueixy, trueslxy) print('Fit 1: ', ixy, slxy) print('Error 1: ', errixy, errslxy) truthrow += 1 # next line print('efficiency: ', counter/(2*nevents)) assert counter/(2*nevents)>=0.98, 'Less than 98% efficiency. Reduce marks'

########################################################

The two data files given are tendata.txt and tentruth.txt.

image text in transcribedimage text in transcribed

Please make sure the code runs both test cells.

You have access to a file containing 10 events. The format is defined below. Each event contains data corresponding to two lines. Each line originates from simulated electron, each starting at the x=0 plane from the same point, one emitted to the left, i.e. negative x-coordinates, one to the right, with positive coordinates. Coordinates are given in millimetres. The file arrives in compressed form. You can read it as given using np.loadtxt(filename, delimiter=',') . The column entries (and type) are - Event number (int, starting at value 1) - Line number (int, starting at value 1) - Wire x-coordinate (float) - Wire y-coordinate (float) - Wire z-coordinate (float) - Radius (float) - Radius error (float) - Wire z-coordinate error (float) An example event is shown in the figure below. For your own figure, note that the matplotlib.pyplot library has a pyplot. Circle((x, y), radius, fill=False, lw=2) function that can be added as a 'patch' to a figure. Devt The formula describing the distance of a line to a cylinder is D=(xpx0)ur where u is the unit direction vector of the line and x0 is a point on the line. This assumes the line is not parallel to the y-z plane like in this exercise. The residuals between model and data also come with a weighting factor, made from the data errors, r and z according to W=[(zuz)2+(zuy)2+(ruz)2+(zux)2+(ruy)2+(rux)2]1 where ux,y,z represents the three components of the unit vector. Project: Write an application that 1. reads the data and 2. fits lines to all events, 3. counts and returns the number of successful fits, 4. stores your results in a file with the format given below and finally 5. plots the first event following the plot format from the example picture above. The given code in the cell should be incorporated into your solution since its function names will be used in the tests. The runfit(infile, outfile) data files will be supplied for the project for your own testing. One contains 10 events in the right data format and one contains truth information (as human readable file) for checking your own code. The model solution fits all 10 events correctly. Hint: The data in the file has been created with an intercept in the z-coordinate at 0.0 in order to stabilize the fits a little and simplify your task. Note that you should not take that insight as a fixed parameter (would lead to a reduction of marks) but as a reassurance to test your attempts relatively easily. The assessment data file also has the creation intercept set at z=0 for all events. Hint 2: The errors on the intercept in z and the slope in the x - z plane are likely to be big, occasionally. Not to worry, this reflects the large error on the coordinate which can induce a broad minimum and hence big errors. This observation simply is in the nature of the data. Output format for fit results: - Event number (int, starting at 1) - Line number (int, starting at value 1) - intercept in y (float) - error on intercept in y (float) - slope in xy plane (float) - error on slope in x-y plane (float) - intercept in z (float) - error on intercept in z (float) - slope in xz plane (float) - error on slope in xz plane (float) On storing results: it is important that every line in every event has a result, even for failed hits in order to enable the comparison for your assessment. A failed fit should therefore store a result as datastore. append ((evtnr, linenr, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)) with evtnr the event number (int) and linenr the line number (int). \# test cell can't work since reading a file is called that you don't have. Consider it example code. \# main script import time start = time.process time() success = runFit("ringdata.txt.gz", "output.txt.gz") stop = time.process time() print ("success: ", success) print ("fit time: ", (stop-start)) \# testing part truthdata = readData("ringtruth.txt") outputdata = readData("output.txt.gz") \# test 1 nevents = int (outputdata[-1,0]) assert nevents = int(len(truthdata) / 2) , equality of data volume test failed." tendata - Notepad File Edit Format View Help \# event counter, line counter, wirex, wirey, wirez, radius, radius error, z-error tentruth - Notepad File Edit Format View Help \# intercepty, interceptz, slopexy, slopexz 356.749503,0.000000,1.289205,0.835110 356.749503,0.000000,2.767934,0.569496 44.218841,0.000000,4.157547,0.415716 44.218841,0.000000,2.904457,1.372122 525.940812,0.000000,0.309688,0.410017 525.940812,0.000000,1.114542,1.494825 812.937349,0.000000,0.471576,2.041709 812.937349,0.000000,0.727205,2.137225 660.206719,0.000000,1.743949,1.694747 660.206719,0.000000,1.477933,0.158218 25.750842,0.000000,1.231083,0.612854 25.750842,0.000000,0.115341,1.345622 412.747306,0.000000,0.340800,0.582351 412.747306,0.000000,5.281985,0.060729 463.466952,0.000000,0.872751,0.781760 463.466952,0.000000,2.999518,0.476997 109.005950,0.000000,0.906118,1.347475 109.005950,0.000000,5.339613,0.399403 420.008123,0.000000,4.676006,0.957135 420.008123,0.000000,0.513084,0.199957

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions