-
Notifications
You must be signed in to change notification settings - Fork 0
/
pedestal-finder.py
71 lines (55 loc) · 2.39 KB
/
pedestal-finder.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#usage:
# For 1 pedestal file: ldmx python3 pedestal-finder.py pedestal_run.root
# For 2 pedestal files: ldmx python3 pedestal-finder.py pedestal_run.root pedestal_run2.root
from mapping import *
import csv
import ROOT as r
from optparse import OptionParser
parser = OptionParser()
parser.add_option('-o','--outputPath', dest='outputPath', default = '', help='Determines the output folder')
options = parser.parse_args()[0]
outputPath = options.outputPath
if outputPath != '' and outputPath[-1] != '/': outputPath +='/'
inputFileName=sys.argv[1]
inputFileNameNoExtension=sys.argv[1][inputFileName.find('adc'):inputFileName.find('.root')]
inputFile=r.TFile(inputFileName, "read")
allData=inputFile.Get('ntuplizehgcroc').Get("hgcroc") #
IDpositions={}
hists={}
for t in allData : #for timestamp in allData
if t.raw_id not in hists:
hists[t.raw_id] = r.TH1F(str(t.raw_id),'',1024,0,1024)
polarfire= t.fpga
hrocindex= int(t.link/2)
channel= 36*(t.link%2) + t.channel
IDpositions[t.raw_id] = str(polarfire)+':'+str(hrocindex)+':'+str(channel)
hists[t.raw_id].Fill(t.adc)
try:
inputFileName2=sys.argv[2]
inputFileName2NoExtension=sys.argv[2][inputFileName2.find('adc'):inputFileName2.find('.root')]
inputFile2=r.TFile(inputFileName2, "read")
allData=inputFile2.Get('ntuplizehgcroc').Get("hgcroc") #
for t in allData : #for timestamp in allData
if t.raw_id not in hists:
hists[t.raw_id] = r.TH1F(str(t.raw_id),'',1024,0,1204)
polarfire= t.fpga
hrocindex= int(t.link/2)
channel= 36*t.link%2 + t.channel
IDpositions[t.raw_id] = str(polarfire)+':'+str(hrocindex)+':'+str(channel)
hists[t.raw_id].Fill(t.adc)
except: print("Second pedestal root file unspecified, missing, or invalid. Moving on.")
outputFileName = outputPath+'pedestals_'+inputFileNameNoExtension
try: outputFileName += '_'+inputFileName2NoExtension
except: pass
csvfile = open(outputFileName+'.csv', 'w', newline='')
csvwriter = csv.writer(csvfile, delimiter=',')
csvwriter.writerow(['DetID', 'ElLoc', 'ADC_PEDESTAL'])
pedestalPlot = r.TH1F('','Pedestals',384,0,0)
for i in hists:
μ = hists[i].GetMean()
pedestalPlot.Fill(int(i),μ)
csvwriter.writerow([i, IDpositions[i], μ])
# file = r.TFile(outputFileName+'.root', "RECREATE")
# pedestalPlot.SetDirectory(file)
# pedestalPlot.Write()
# file.Close()