-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathefficiencyPurityPlot.py
More file actions
53 lines (40 loc) · 1.67 KB
/
efficiencyPurityPlot.py
File metadata and controls
53 lines (40 loc) · 1.67 KB
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
# External Dependencies
import sys
import math
import numpy as np
import ROOT as root
from array import array
# Internal Dependencies
from dataTypes import *
import driver
import draw
def efficiencyPurityGraph(volume, wirePitches, angles, numberOfBlobs, alphas, numberOfIterations):
efficiency = array('f', len(alphas) * [0.])
purity = array('f', len(alphas) * [0.])
eventNo = 0
for pointNo, alpha in enumerate(alphas):
correctSum = 0
fakeSum = 0
for i in range(numberOfIterations):
blobs, cells, channelList, geometryMatrix, recoWireMatrix, recoCellMatrix, trueCellMatrix = driver.drive(
volume, wirePitches, angles, numberOfBlobs, alpha)
if (eventNo % 1000 == 0) or (eventNo == 0):
print("Processed ", eventNo, "/", len(alphas)
* numberOfIterations, " events")
eventNo += 1
recoCells = list(map(lambda x: not math.isclose(
x, 0, rel_tol=1e-5), recoCellMatrix))
trueCells = list(map(lambda x: not math.isclose(
x, 0, rel_tol=1e-5), trueCellMatrix))
correctID = sum(bool(x[0]) and bool(x[1])
for x in zip(trueCells, recoCells))
fakeID = sum(not bool(x[0]) and bool(x[1])
for x in zip(trueCells, recoCells))
correctSum += correctID / len(blobs)
fakeSum += fakeID / len(blobs)
efficiency[pointNo] = correctSum / numberOfIterations
purity[pointNo] = 1 - fakeSum / numberOfIterations
g = root.TGraph(len(alphas), efficiency, purity)
return g
if __name__ == "__main__":
main(sys.argv)