Skip to content

Commit

Permalink
Add binding energy plot and Hubble constant determination
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoSchorlepp committed Nov 17, 2017
1 parent 86cb365 commit e30aa07
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CANAJAVA/src/main/java/groupwork/LiquidDropModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static double returnBindingEnergy(int Z, int N) {
ret -= delta;
}

return ret / 1000.;
return ret;
}

public static void plotHistogram() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package sixthclasshomeworktimo;

public class AllClusterObjectData {

}

class Virgo extends Cluster {
public Virgo() {
this.distance = 15;
this.velocity = 1200;
}
}

class UrsaMajor extends Cluster {
public UrsaMajor() {
this.distance = 190;
this.velocity = 15400;
}
}

class CoronaBorealis extends Cluster {
public CoronaBorealis() {
this.distance = 280;
this.velocity = 22000;
}
}

class Bootes extends Cluster {
public Bootes() {
this.distance = 490;
this.velocity = 39400;
}
}

class Hydra extends Cluster {
public Hydra() {
this.distance = 760;
this.velocity = 60600;
}
}

class Quasar extends Cluster {
public Quasar() {
this.distance = 4035;
this.velocity = 280000;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package sixthclasshomeworktimo;

public class AllNeededElements {

}

class Hydrogen extends Element {

public Hydrogen(int N) {
this.N = N;
this.Z = 1;
this.A = this.N + this.Z;
}

}

class Helium extends Element {

public Helium(int N) {
this.N = N;
this.Z = 2;
this.A = this.N + this.Z;
}

}

class Lithium extends Element {

public Lithium(int N) {
this.N = N;
this.Z = 3;
this.A = this.N + this.Z;
}

}

class Beryllium extends Element {

public Beryllium(int N) {
this.N = N;
this.Z = 4;
this.A = this.N + this.Z;
}

}

class Boron extends Element {

public Boron(int N) {
this.N = N;
this.Z = 5;
this.A = this.N + this.Z;
}

}
16 changes: 16 additions & 0 deletions CANAJAVA/src/main/java/sixthclasshomeworktimo/Cluster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package sixthclasshomeworktimo;

public class Cluster {

protected double distance; // Mpc
protected double velocity;// km/s

public double getDistance() {
return this.distance;
}

public double getVelocity() {
return this.velocity;
}

}
54 changes: 54 additions & 0 deletions CANAJAVA/src/main/java/sixthclasshomeworktimo/Element.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package sixthclasshomeworktimo;

public class Element {

protected int A;
protected int Z;
protected int N;

public double getBindingEnergy() {
double aV = 15.5; // MeV
double aS = 16.8; // MeV
double aC = 0.715; // MeV
double aA = 23.; // MeV
double aP = 11.3; // MeV

double ret = 0.;

ret += aV * this.A;
ret -= aS * Math.pow(this.A, 2. / 3.);
ret -= aC * Math.pow(this.Z, 2.) / Math.pow(this.A, 1. / 3.);
ret -= aA * Math.pow((this.Z - this.N), 2) / this.A;

int par1 = this.Z % 2;
int par2 = this.N % 2;
int par = par1 + par2;

double delta = aP / Math.pow(this.A, 0.5);

switch (par) {
case 0:
ret += delta;
case 1:
ret += 0;
case 2:
ret -= delta;
}

return ret / this.A;

}

public int getA() {
return this.A;
}

public int getN() {
return this.N;
}

public int getZ() {
return this.Z;
}

}
60 changes: 60 additions & 0 deletions CANAJAVA/src/main/java/sixthclasshomeworktimo/Plot2DHist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package sixthclasshomeworktimo;

import org.jlab.groot.data.H2F;
import org.jlab.groot.ui.TCanvas;

public class Plot2DHist {

static void plotHistogram() {
// plot binding energy per nucleon for Z <= 5, A <= 25

H2F aH2f = new H2F("LiquidDropModel", 5, 1, 5, 6, 0, 5);

for (int Z = 1; Z <= 5; Z++) {

Element[] elements = new Element[6];

for (int N = 0; N < 6; N++) {
// fill element array with correct atoms for each Z

if (Z == 1) {
elements[N] = new Hydrogen(N);
}

if (Z == 2) {
elements[N] = new Helium(N);
}

if (Z == 3) {
elements[N] = new Lithium(N);
}

if (Z == 4) {
elements[N] = new Beryllium(N);
}

if (Z == 5) {
elements[N] = new Boron(N);
}

aH2f.setBinContent(Z - 1, N, elements[N].getBindingEnergy());
}

}

aH2f.setTitleX("Z");
aH2f.setTitleY("N");
aH2f.setTitle("Liquid drop model binding energy per nucleon");

TCanvas canv = new TCanvas("LiquidDrop", 800, 600);

canv.draw(aH2f);
// bin position is off, no time to fix it.

}

public static void main(String[] args) {
plotHistogram();
}

}
81 changes: 81 additions & 0 deletions CANAJAVA/src/main/java/sixthclasshomeworktimo/PlotHubbleLaw.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package sixthclasshomeworktimo;

import org.jlab.groot.data.GraphErrors;
import org.jlab.groot.fitter.DataFitter;
import org.jlab.groot.math.F1D;
import org.jlab.groot.ui.TCanvas;

import domain.utils.Constants;

public class PlotHubbleLaw {

static void plotVelocitytoDistance() {

GraphErrors graphErrors = new GraphErrors();

// set data
Cluster[] clusterdata = new Cluster[6];
clusterdata[0] = new Virgo();
clusterdata[1] = new UrsaMajor();
clusterdata[2] = new CoronaBorealis();
clusterdata[3] = new Bootes();
clusterdata[4] = new Hydra();
clusterdata[5] = new Quasar();

for (int i = 0; i < 6; i++) {
graphErrors.addPoint(clusterdata[i].getDistance(), clusterdata[i].getVelocity(), 0, 0);
}

graphErrors.setTitleX("d [Mpc]");
graphErrors.setTitleY("v [km/s]");

/////////////////////////////////////////////////////////
// fit constant with least square method
double H;
double v0;
double sumvd = 0;
double sumv2 = 0;
double sumd2 = 0;
double sumv = 0;
double sumd = 0;

for (int i = 0; i < 6; i++) {
sumvd += clusterdata[i].getDistance() * clusterdata[i].getVelocity();
sumv2 += clusterdata[i].getVelocity() * clusterdata[i].getVelocity();
sumd2 += clusterdata[i].getDistance() * clusterdata[i].getDistance();
sumv += clusterdata[i].getVelocity();
sumd += clusterdata[i].getDistance();
}

H = (6 * sumvd - sumv * sumd) / (6 * sumd2 - sumd * sumd);
v0 = (sumd2 * sumv - sumd * sumvd) / (6 * sumd2 - sumd * sumd);
/////////////////////////////////////////////////////////

// plot corresponding line
F1D f1d = new F1D("f1", "[a] + [b] * x", 0, 4035);
f1d.setParameter(0, v0);
f1d.setParameter(1, H);

DataFitter.fit(f1d, graphErrors, "Q");

TCanvas canv = new TCanvas("Hubble's Law", 800, 600);

canv.draw(graphErrors);
canv.draw(f1d, "same");

///////////////////////////////////////////////////////
System.out.println("Hubble constant from linear regression: " + H + " km/(s * Mpc)");

double mpctokm = 3.086e19;
double sectoyear = 1 / Constants.yearToSeconds;
double t = 1 / H * mpctokm * sectoyear;

System.out.println("Corresponding age of universe is " + t + " years");

}

public static void main(String[] args) {
plotVelocitytoDistance();
}

}
Empty file added nano.save
Empty file.

0 comments on commit e30aa07

Please sign in to comment.