Lab moderna: add p3

Change-Id: I33feba7f04f13e91bfddacfa04a3f5b2e4e1952a
diff --git a/quad12/labmoderna/p3/r/Pic_Am.r b/quad12/labmoderna/p3/r/Pic_Am.r
new file mode 100644
index 0000000..54c0ef4
--- /dev/null
+++ b/quad12/labmoderna/p3/r/Pic_Am.r
@@ -0,0 +1,98 @@
+library(tikzDevice)
+
+nom <- 'Pic_Am'
+scale <- 4
+
+plotbg <- function(table, number) {
+  col1 = ""
+  col2 = ""
+  if (number == 0) {
+    col1 = "#073B4C"
+    col2 = "#C7EDFA"
+  }
+  if (number == 2) {
+    col1 = "#118AB2"
+    col2 = "#B4E7F8"
+  }
+  if (number == 4) {
+    col1 = "#06DBA2"
+    col2 = "#AFFDE8"
+  }
+  if (number == 6) {
+    col1 = "#FFC233"
+    col2 = "#FFF3D6"
+  }
+  if (number == 8) {
+    col1 = "#EF436B"
+    col2 = "#FAC7D3"
+  }
+  if (number == 10) {
+    col1 = "#8377D1"
+    col2 = "#E2E0F5"
+  }
+
+  if (number == 0) {
+    plot(table$Energy, table$Impulses, type="l", col=col2, xlab="Energia (keV)", ylab="Comptes")
+  } else {
+    lines(table$Energy, table$Impulses, type="l", col=col2, xlab="Energia (keV)", ylab="Comptes")
+  }
+}
+
+plotfg <- function(table, number) {
+  col1 = ""
+  col2 = ""
+  if (number == 0) {
+    col1 = "#073B4C"
+    col2 = "#C7EDFA"
+  }
+  if (number == 2) {
+    col1 = "#118AB2"
+    col2 = "#B4E7F8"
+  }
+  if (number == 4) {
+    col1 = "#06DBA2"
+    col2 = "#AFFDE8"
+  }
+  if (number == 6) {
+    col1 = "#FFC233"
+    col2 = "#FFF3D6"
+  }
+  if (number == 8) {
+    col1 = "#EF436B"
+    col2 = "#FAC7D3"
+  }
+  if (number == 10) {
+    col1 = "#8377D1"
+    col2 = "#E2E0F5"
+  }
+
+  lines(table$Energy, table$ImpulsesSmooth, col=col1, type="l")
+}
+
+pdf(paste0('output/', nom, '.pdf'), width = 6, height = 5)
+numbers <- c(0:5)*2
+for (number in numbers) {
+  table <- read.table(paste0('dades/', nom, '_', number, '.txt'), sep="\t", dec='.', header=TRUE)
+  plotbg(table, number)
+}
+for (number in numbers) {
+  table <- read.table(paste0('dades/', nom, '_', number, '.txt'), sep="\t", dec='.', header=TRUE)
+  plotfg(table, number)
+}
+legendColors = c("#073B4C", "#118AB2", "#06DBA2", "#FFC233", "#EF436B", "#8377D1")
+legend("topright", inset = c(0.015, 0.03), col = legendColors, legend = c("Buit", "2 mangueres", "4 mangueres", "6 mangueres", "8 mangueres", "10 mangueres"), lty=c(1, 1, 1, 1, 1, 1))
+dev.off()
+
+tikz(paste0('output/', nom, '.tex'), width = 6, height = 5)
+numbers <- c(0:5)*2
+for (number in numbers) {
+  table <- read.table(paste0('dades/', nom, '_', number, '.txt'), sep="\t", dec='.', header=TRUE)
+  plotbg(table, number)
+}
+for (number in numbers) {
+  table <- read.table(paste0('dades/', nom, '_', number, '.txt'), sep="\t", dec='.', header=TRUE)
+  plotfg(table, number)
+}
+legendColors = c("#073B4C", "#118AB2", "#06DBA2", "#FFC233", "#EF436B", "#8377D1")
+legend("topright", inset = c(0.015, 0.03), col = legendColors, legend = c("Buit", "2 mangueres", "4 mangueres", "6 mangueres", "8 mangueres", "10 mangueres"), lty=c(1, 1, 1, 1, 1, 1))
+dev.off()
diff --git a/quad12/labmoderna/p3/r/Ra_aire.r b/quad12/labmoderna/p3/r/Ra_aire.r
new file mode 100644
index 0000000..a9217aa
--- /dev/null
+++ b/quad12/labmoderna/p3/r/Ra_aire.r
@@ -0,0 +1,34 @@
+library(tikzDevice)
+
+nom <- 'Ra_aire'
+scale <- 4
+
+table <- read.table(paste0('dades/', nom, '.txt'), sep="\t", dec='.', header=TRUE)
+
+# Plot the data
+plotall <- function() {
+  plot(table$Energy, table$Impulses, type="l", col="#EEEEFF", xlab="Energia (keV)", ylab="Comptes", ylim=c(0, 100))
+  lines(table$Energy, table$ImpulsesSmooth, type="l")
+
+  # Add arrows and text labels to the peaks
+  for (j in 1:nrow(peaks)) {
+    i <- peaks[j, 'indexes']
+    label <- peaks[j, 'labels']
+    arrows(table$Energy[i], table$ImpulsesSmooth[i] + scale*(if (j == 1) 5 else 3), table$Energy[i], table$ImpulsesSmooth[i] + scale*0.1, length = 0.05, code = 1, col = "#514E7E")
+    text(table$Energy[i], table$ImpulsesSmooth[i] + scale*(if (j == 1) 6.6 else 4.6), paste0(table$Energy[i], " keV", "\n", label), col = "#514E7E", cex = 0.75)
+  }
+}
+
+# Els valors dins de c(...) són les files del fitxer de dades.
+# Es resta 2 per trobar els índexs (2 columnes són headers).
+indexes <- c(207, 327, 645) - 2
+labels <- c("\\textsuperscript{210}Po + \\textsuperscript{222}Rn", "\\textsuperscript{218}Po", "\\textsuperscript{214}Po")
+peaks <- data.frame(indexes, labels)
+
+pdf(paste0('output/', nom, '.pdf'), width = 6, height = 5)
+plotall()
+dev.off()
+
+tikz(paste0('output/', nom, '.tex'), width = 6, height = 5)
+plotall()
+dev.off()
diff --git a/quad12/labmoderna/p3/r/calibracio_na.r b/quad12/labmoderna/p3/r/calibracio_na.r
new file mode 100644
index 0000000..e86eda1
--- /dev/null
+++ b/quad12/labmoderna/p3/r/calibracio_na.r
@@ -0,0 +1,29 @@
+library(tikzDevice)
+
+table <- read.table('dades/calibracio_ra.txt', sep="\t", dec='.', header=TRUE)
+
+# Plot the data
+plotall <- function() {
+  plot(table$ChannelNumber, table$Impulses, type="l", col="#EEEEFF", xlab="Nombre de canal", ylab="Comptes")
+  lines(table$ChannelNumber, table$ImpulsesSmooth, type="l")
+
+  # Add arrows and text labels to the peaks
+  for (j in 1:nrow(peaks)) {
+    i <- peaks[j, 'indexes']
+    label <- peaks[j, 'labels']
+    arrows(table$ChannelNumber[i], table$ImpulsesSmooth[i]+3, table$ChannelNumber[i], table$ImpulsesSmooth[i]+0.1, length = 0.05, code = 1, col = "#514E7E")
+    text(table$ChannelNumber[i], table$ImpulsesSmooth[i]+4.6, paste0("Canal ", table$ChannelNumber[i], "\n", label), col = "#514E7E", cex = 0.75)
+  }
+}
+
+indexes <- c(1601, 2359, 3373) + 1
+labels <- c("\\textsuperscript{226}Ra", "\\textsuperscript{218}Po", "\\textsuperscript{214}Po")
+peaks <- data.frame(indexes, labels)
+
+pdf('output/calibracio_ra.pdf', width = 6, height = 5)
+plotall()
+dev.off()
+
+tikz('output/calibracio_ra.tex', width = 6, height = 5)
+plotall()
+dev.off()
diff --git a/quad12/labmoderna/p3/r/na_calibrat.r b/quad12/labmoderna/p3/r/na_calibrat.r
new file mode 100644
index 0000000..86cb4fe
--- /dev/null
+++ b/quad12/labmoderna/p3/r/na_calibrat.r
@@ -0,0 +1,34 @@
+library(tikzDevice)
+
+nom <- 'Calibrat_Ra'
+scale <- 4
+
+table <- read.table(paste0('dades/', nom, '.txt'), sep="\t", dec='.', header=TRUE)
+
+# Plot the data
+plotall <- function() {
+  plot(table$Energy, table$Impulses, type="l", col="#EEEEFF", xlab="Energia (keV)", ylab="Comptes", ylim=c(0, 100))
+  lines(table$Energy, table$ImpulsesSmooth, type="l")
+
+  # Add arrows and text labels to the peaks
+  for (j in 1:nrow(peaks)) {
+    i <- peaks[j, 'indexes']
+    label <- peaks[j, 'labels']
+    arrows(table$Energy[i], table$ImpulsesSmooth[i] + scale*3, table$Energy[i], table$ImpulsesSmooth[i] + scale*0.1, length = 0.05, code = 1, col = "#514E7E")
+    text(table$Energy[i], table$ImpulsesSmooth[i] + scale*4.6, paste0(table$Energy[i], " keV", "\n", label), col = "#514E7E", cex = 0.75)
+  }
+}
+
+# Els valors dins de c(...) són les files del fitxer de dades.
+# Es resta 2 per trobar els índexs (2 columnes són headers).
+indexes <- c(396, 492, 581, 830) - 2
+labels <- c("\\textsuperscript{226}Ra", "\\textsuperscript{210}Po + \\textsuperscript{222}Rn", "\\textsuperscript{218}Po", "\\textsuperscript{214}Po")
+peaks <- data.frame(indexes, labels)
+
+pdf(paste0('output/', nom, '.pdf'), width = 6, height = 5)
+plotall()
+dev.off()
+
+tikz(paste0('output/', nom, '.tex'), width = 6, height = 5)
+plotall()
+dev.off()