-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscriminatorCalibration.py
executable file
·174 lines (128 loc) · 4.78 KB
/
DiscriminatorCalibration.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# -*- coding: utf-8 -*-
from array import array
import math
import ROOT
import Configuration
import Base
discriminatorModulesPerModule = 2
channelsPerDiscriminatorModule = 32
numModules = 8
numBoards = 16
class DiscriminatorCalibrator:
def __init__(self):
print "Calibrating Discrimiantors"
self.discModuleRuns = []
def setup(self):
for board in range(numBoards):
for module in range(numModules):
for trip in range(discriminatorModulesPerModule):
discModRun = DiscriminatorModuleRun(board, module, trip)
self.discModuleRuns.append(discModRun)
def loadDataCampaign(self, campaign):
self.dataCampaign = campaign
configuration = Configuration.ConfigurationReader(campaign)
for run in self.dataCampaign.runs:
print "Looking at run " + str(run.runNumber)
settings = configuration.loadSettings(run.runNumber)
vth = settings.getVTh()
for discModRun in self.discModuleRuns:
discModule = DiscriminatorModule()
discModule.setVThreshold(vth)
discModRun.modules.append(discModule)
print "Added a disc module with vth = " + str(vth)
i = 0
for run in self.dataCampaign.runs:
run.setup()
settings = configuration.loadSettings(run.runNumber)
vth = settings.getVTh()
readeri = Base.DATEReader(self.dataCampaign.fileNames[i])
print "Starting to analyse file:"
print self.dataCampaign.fileNames[i]
readeri.readBinary(run)
for channel in run.channelRuns:
discModRun = self.findDiscriminatorModuleRun(channel.board, channel.module, channel.trip)
discMod = discModRun.getDiscriminatorModule(vth)
discMod.addChannelFiredRatio(channel.getDiscriminatorRatio())
if (channel.getDiscriminatorRatio() != 0.0):
print "ratio = " + str(channel.getDiscriminatorRatio())
i = i + 1
run.clear()
def getBestModules(self, optimumRatio):
for moduleRun in self.discModuleRuns:
bestVth = 255
for module in moduleRun.modules:
vth = module.vTh
ratio = module.getAverageRatio()
if ((ratio < optimumRatio) and(vth < bestVth)):
bestVth = vth
print "Disc board, module, trip:"
print moduleRun.board, moduleRun.module, moduleRun.trip
print "Vth:"
print bestVth
def findDiscriminatorModuleRun(self, board, module, trip):
for dMod in self.discModuleRuns:
if ((dMod.board == board) and (dMod.module == module) and (dMod.trip == trip)):
return dMod
print "Couldn't find module with board, module, trip:"
print board, module, trip
def makeHistograms(self):
for dModRun in self.discModuleRuns:
moduleString = "Board " + str(dModRun.board) + " Module " + str(dModRun.module) + " Trip " + str(dModRun.trip) + " DiscMod"
moduleFileName = str(dModRun.board) + "-" + str(dModRun.module) + "-" + str(dModRun.trip) + "DiscMod"
discModuleRunHist = ROOT.TH1F(moduleString, moduleFileName, 256,0,255)
for mod in dModRun.modules:
ratio = mod.getAverageRatio()
vth = mod.vTh
discModuleRunHist.Fill(vth,ratio)
discModuleRunHist.Write()
def makeGraphs(self):
for dModRun in self.discModuleRuns:
moduleString = "Board " + str(dModRun.board) + " Module " + str(dModRun.module) + " Trip " + str(dModRun.trip) + " DiscMod"
moduleFileName = str(dModRun.board) + "-" + str(dModRun.module) + "-" + str(dModRun.trip) + "DiscMod"
vths = array("d")
ratios = array("d")
for mod in dModRun.modules:
ratio = mod.getAverageRatio()
print ratio
vth = mod.vTh
print vth
ratios.append(ratio)
vths.append(vth)
print len(dModRun.modules)
print vths
print ratios
dModRun.graph = ROOT.TGraph(len(dModRun.modules),vths,ratios)
dModRun.graph.SetName(moduleFileName)
dModRun.graph.SetTitle(moduleString)
dModRun.graph.SetMinimum(0.0)
dModRun.graph.Write()
class DiscriminatorModule:
def __init__(self):
print "Making a trip-t"
#self.board = board
#self.module = module
#self.trip = trip
self.channelFiredRatios = []
def setVThreshold(self, vth):
self.vTh = vth
print "Vth = " + str(self.vTh)
def addChannelFiredRatio(self, ratio):
self.channelFiredRatios.append(ratio)
def getAverageRatio(self):
sumRatio = 0
for channel in self.channelFiredRatios:
sumRatio += channel
ratio = (sumRatio/channelsPerDiscriminatorModule)
return ratio
class DiscriminatorModuleRun:
def __init__(self, board, module, trip):
print "Making disc mod run"
self.board = board
self.module = module
self.trip = trip
self.modules = []
def getDiscriminatorModule(self, vth):
for mod in self.modules:
if (mod.vTh == vth):
return mod
print "Couldn't find module with vth " + str(vth)