forked from mrw7816/PMT-Data-Analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoot_PMT_Script.py
51 lines (42 loc) · 1.66 KB
/
Root_PMT_Script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 8 15:22:41 2019
@author: Michael
"""
import ROOT as r
import sys
import array as ar
import matplotlib.pyplot as plt
if len(sys.argv) != 3:
print " USAGE : %s <input file > <output file >" %(sys.argv [0])
sys.exit (1) #this if statement assures that you get three input params
inFileName = sys.argv [1] #assigns variable names to input and output files
outFileName = sys.argv [2]
print " Reading from ", inFileName , "and writing to", outFileName
inFile = r.TFile.Open ( inFileName ," READ ") #open the TFile
Graph_DarkPlot = inFile.Get("dark_plot") #point it to which tree I want
print(Graph_DarkPlot)
DarkPlot_canvas = r.TCanvas('Dark_Canvas')
Graph_DarkPlot.Draw()
#DarkPlot_canvas.SaveAs('Dark_Count_Long')
#These three lines grap the x and y arrays and their errors from the root file
DarkX_buff = Graph_DarkPlot.GetX()
DarkY_buff = Graph_DarkPlot.GetY()
Yerror_buff = Graph_DarkPlot.GetEY()
# These two lines provide the pythonization of the buffers into actual doubles
DarkX_buff.SetSize(Graph_DarkPlot.GetN())
DarkY_buff.SetSize(Graph_DarkPlot.GetN())
Yerror_buff.SetSize(Graph_DarkPlot.GetN())
#These two create the actual arrays
DarkX = ar.array('d' ,DarkX_buff)
DarkY = ar.array('d' ,DarkY_buff)
DarkYerror = ar.array('d', Yerror_buff)
plt.errorbar(DarkX,DarkY,yerr=DarkYerror)
#points = r.TH1D("dark rate", "Dark Count Rate", 0,100)
#for entryNum in range(0,tree.GetEntries()): #fills histo
#tree.GetEntry(entryNum)
#points.Fill()
#points.SetDirectory(0) #makes sure hist doesnt close if input files is closed
#inFile.Close() #close input file
#outHistFile = r.TFile.Open(outFileName, "RECREATE")
#outHistFile.cd()