forked from Vindaar/TimepixAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis_graph.nim
More file actions
119 lines (95 loc) · 3.54 KB
/
analysis_graph.nim
File metadata and controls
119 lines (95 loc) · 3.54 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
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
import nimgraphviz, strutils, sequtils, macros
#[
This little piece of code generates a GraphViz flow chart representing
the whole TPA analysis chain.
]#
proc sanitize(s: string): string =
result = "\"" & s & "\""
proc connectNodes(g: var Graph, s: seq[string]) =
for i in 0 ..< s.high:
g.addEdge(s[i].sanitize, s[i + 1].sanitize)
template `<-`(lhs, rhs: untyped): untyped {.dirty.} =
g.addEdge(rhs.sanitize, lhs.sanitize)
lhs
func `<-`(g: var Graph, lhs, rhs: string) =
g.addEdge(rhs.sanitize, lhs.sanitize)
func `<-`(g: var Graph, h: Graph) =
g.addEdge(h.name.sanitize, g.name.sanitize,
attrs = [("ltail", h.clusterName),
("lhead", g.clusterName)])
macro graph(stmts: untyped): untyped =
result = newStmtList()
for stmt in stmts:
echo stmt.treerepr
expectKind(stmt, nnkCall)
expectKind(stmt[1], nnkStmtList)
let arg = stmt[1][0]
expectKind(arg, nnkInfix)
case arg[0].strVal
of "<-":
result.add nnkCall.newTree(bindSym"addEdge", stmt[0],
nnkCall.newTree(bindSym"sanitize", arg[1]),
nnkCall.newTree(bindSym"sanitize", arg[2]))
of "->":
result.add nnkCall.newTree(bindSym"addEdge", stmt[0],
nnkCall.newTree(bindSym"sanitize", arg[2]),
nnkCall.newTree(bindSym"sanitize", arg[1]))
else:
error("Invalid identifier: " & arg[0].repr & " for graph macro.")
var g = newGraph(directed = true)
# set some attributes of the graph:
g.graphAttr["fontsize"] = "32"
g.graphAttr["label"] = "Timepix Analysis pipeline"
g.graphAttr["compound"] = "true"
var sData = g.newSubgraph("readout")
let ascii = "ASCII files"
block Readout:
let dataParts = @["GridPix", "scintillator", "FADC"]
for d in dataParts:
graph:
sData: "FPGA" -> d
let nodes = @["FPGA", "TOS", ascii]
sData.connectNodes(nodes)
var types = g.newSubgraph("datasets")
block TypesOfDatasets:
let dataTypeNodes = @["calibration (⁵⁵Fe)",
"background+tracking", #
"x-ray finger",
"CDL"]
for d in dataTypeNodes:
graph:
types: d -> "datasets"
types <- sData
let rawStr = "raw data manipulation"
var raw = g.newSubgraph(rawStr)
block RawDataManipulation:
#graph:
# raw: "raw data manipulation" <- "data"
raw <- types
let nodes = @[ascii, rawStr, "HDF5 files"]
raw.connectNodes(nodes)
let eCalib = "energy calibration"
block Reconstruction:
# these are the nodes general to all data
let reconstruction = @["cluster finding" <- "50 pix radius",
"eccentricity optimization",
"calc of other geometric properties",
"charge calibration" <- "ToT calibration",
"gas gain calculation" <- "Polya fit",
eCalib <- "Fit to all ⁵⁵Fe spectra vs. gas gain"]
var reco = g.newSubgraph("reconstruction")
reco.connectNodes(reconstruction)
reco <- raw
let calibrationPath = @["generalNodes",
"⁵⁵Fe pixel fit",
"⁵⁵Fe charge fit",
"linear fit to photo+escape peak"]
block LikelihoodLimit:
let recoCdl = "Reco'd CDL data"
let CDLdata = "CDL data"
let softwareSteps = @[ "likelihood" <- (recoCDL <- CDLdata) <- ("CDL Reference spectra" <- CDLdata),
"limit calculation"]
g.connectNodes(softwareSteps)
discard recoCdl <- eCalib
# Export graph as PNG:
g.exportImage("/tmp/test_G.svg")