forked from TaiSakuma/hcaltrg-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_f010_levelplot.R
executable file
·126 lines (98 loc) · 3.88 KB
/
draw_f010_levelplot.R
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
#!/usr/bin/env Rscript
# Tai Sakuma <[email protected]>
##__________________________________________________________________||
argv <- commandArgs(trailingOnly = FALSE)
olddir <- setwd('mianRs')
source('drawFuncs.R')
source('drawThemes.R')
source('all_outputs_are_newer_than_any_input.R')
setwd(olddir)
##__________________________________________________________________||
eval(readArgs)
##__________________________________________________________________||
library(tidyr, warn.conflicts = FALSE, quietly = TRUE)
library(dplyr, warn.conflicts = FALSE, quietly = TRUE)
##__________________________________________________________________||
theme.this <- function()
{
cols <- c("darkgreen", "orange", "#ff00ff", "#ff0000", "#0080ff", "#00ff00", "brown")
col.regions <- colorRampPalette(brewer.pal(9, "Blues"))(100)
theme <- list(
add.text = list(cex = 0.8, lineheight = 2.0), # text in strip
axis.text = list(cex = 0.8),
axis.line = list(lwd = 0.2, col = 'gray30'),
reference.line = list(col = '#eeeeee', lwd = 0.2),
regions = list(col = col.regions),
background = list(col = "transparent")
)
modifyList(theme.economist(), theme)
}
##__________________________________________________________________||
arg.tbl.dir <- if(exists('arg.tbl.dir')) arg.tbl.dir else 'tbl_01'
##__________________________________________________________________||
main <- function()
{
tblFileName <- 'tbl_Scan.run.lumi.evt.ieta-wp.iphi-b1.depth-b1.idxQIE10-b1.eta-b1.phi-b1.energy-b1.energy_th-b1.txt'
tblPath <- file.path(arg.tbl.dir, tblFileName)
if(!(file.exists(tblPath))) return()
fig.id <- mk.fig.id()
components <- strsplit('e030 e050 e070 e100 e150 e300 pi030 pi050 pi070 pi100 pi150 pi300', ' ')[[1]]
figFileNameNoSuf <- paste(fig.id, 'levelplot_energy', components, sep = '_')
suffixes <- c('.pdf', '.png')
figFileName <- outer(figFileNameNoSuf, suffixes, paste, sep = '')
figPaths <- file.path(arg.outdir, figFileName)
if( (!arg.force) && all_outputs_are_newer_than_any_input(figPaths, tblPath)) return()
dir.create(arg.outdir, recursive = TRUE, showWarnings = FALSE)
tbl <- read.table(tblPath, header = TRUE)
tbl$energy <- tbl$energy_th
evt <- sort(unique(tbl$evt))[2:7]
tbl <- tbl[tbl$evt %in% evt, ]
tbl$evt <- factor(tbl$evt)
tbl28 <- tbl[abs(tbl$ieta) == 29, ]
tbl28$ieta[tbl28$ieta == 29] <- 28
tbl28$ieta[tbl28$ieta == -29] <- -28
tbl28$energy <- NA
tbl <- rbind(tbl, tbl28)
tbl$depth_idx <- paste('depth = ', as.character(tbl$depth), ', idx = ', as.character(tbl$idxQIE10), sep ='')
tbl$depth_idx <- factor(tbl$depth_idx)
theme <- theme.this()
zmax <- ceiling(max(tbl$energy, na.rm = TRUE))
zmin <- floor(min(tbl$energy, na.rm = TRUE))
z.at <- seq(from = zmin, to = zmax, length.out = 50)
len_negative <- length(z.at[z.at < 0])
len_positive <- length(z.at[z.at >= 0])
col1 <- rev(colorRampPalette(brewer.pal(9, "Blues"))(len_negative))
col2 <- colorRampPalette(brewer.pal(9, "Reds"))(len_positive)
col.regions <- c(col1, col2)
theme = modifyList(
theme,
list(regions = list(col = col.regions))
)
for(component in components)
{
tbl_<- tbl[tbl$component == component, ]
p <- draw_figure(tbl_, z.at = z.at)
p <- useOuterStrips(p)
figFileNameNoSuf <- paste(fig.id, 'levelplot_energy', component, sep = '_')
print.figure(p, fig.id = figFileNameNoSuf, theme = theme, width = 8, height = 5)
}
invisible()
}
##__________________________________________________________________||
draw_figure <- function(tbl, z.at)
{
levelplot(
energy ~ ieta*iphi | depth_idx*evt,
data = tbl,
aspect = 3/8,
between = list(x = 0.2, y = 0.5),
## pretty = TRUE,
at = z.at,
scales = list(
x = list(alternating = '1', tick.number = 15),
y = list(alternating = '1')
)
)
}
##__________________________________________________________________||
main()