From ebcafd3244dc743ed9669ac1d026d72de8bf0956 Mon Sep 17 00:00:00 2001
From: Whitney Armstrong <warmstrong@anl.gov>
Date: Mon, 19 Oct 2020 21:20:43 -0500
Subject: [PATCH] Removed dummies and moved scripts around.

- Each benchmark or set ofcommon benchmarks will have their own
directory.
---
 .gitlab-ci.yml                          |  87 +++++++---------
 clustering/.gitignore                   |   0
 clustering/dummy_fail_test.sh           |   7 --
 clustering/dummy_test.sh                |   7 --
 clustering/dummy_test2.sh               |   7 --
 dummy/.gitignore                        |   0
 dummy/dummy_fail_test.sh                |   7 --
 dummy/dummy_test.sh                     |   7 --
 dummy/dummy_test2.sh                    |   7 --
 ecal/ecal_config.yml                    |   1 +
 ecal/emcal_electrons.sh                 |  20 ++--
 ecal/scripts/emcal_electrons.cxx        |  79 +++++++++++++++
 ecal/scripts/emcal_electrons_reader.cxx | 126 ++++++++++++++++++++++++
 {scripts => ecal/scripts}/makeplot.C    |   0
 14 files changed, 249 insertions(+), 106 deletions(-)
 delete mode 100644 clustering/.gitignore
 delete mode 100644 clustering/dummy_fail_test.sh
 delete mode 100644 clustering/dummy_test.sh
 delete mode 100644 clustering/dummy_test2.sh
 delete mode 100644 dummy/.gitignore
 delete mode 100644 dummy/dummy_fail_test.sh
 delete mode 100644 dummy/dummy_test.sh
 delete mode 100644 dummy/dummy_test2.sh
 create mode 100644 ecal/scripts/emcal_electrons.cxx
 create mode 100644 ecal/scripts/emcal_electrons_reader.cxx
 rename {scripts => ecal/scripts}/makeplot.C (100%)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6e04b98d..aa49676f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,8 +1,10 @@
 image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:latest
 
 default:
+  tags:
+    - silicon
   artifacts:
-    expire_in: 60 mins
+    expire_in: 3 days
     paths:
       - config/
       - results/
@@ -27,75 +29,52 @@ stages:
   - data_init
   - config
   - run
+  - benchmarks1
+  - benchmarks2
   - finish
 
 get_data:
   stage: data_init
-  tags:
-    - silicon
   script:
     - mkdir -p results
-    - mkdir -p sim_output
-
-generate_config:
-  stage: config
-  needs: ["get_data"]
-  tags:
-    - silicon
-  script:
-    - mkdir -p config && ./bin/gen_ci_config -p test_ -i dummy > config/dummy_config.yml
-    - mkdir -p config && ./bin/gen_ci_config -p clustering_ -i clustering > config/clustering_config.yml
+    - mkdir -p config
 
-dummy-pipeline:
-  stage: run
-  needs: ["generate_config"]
-  trigger:
-    include:
-      - artifact: config/dummy_config.yml
-        job: generate_config
-    strategy: depend
-
-clustering-pipeline:
-  stage: run
-  needs: ["generate_config"]
-  trigger:
-    include:
-      - artifact: config/clustering_config.yml
-        job: generate_config
-    strategy: depend
+      #generate_config:
+      #  stage: config
+      #  needs: ["get_data"]
+      #  tags:
+      #    - silicon
+      #  script:
+      #    - mkdir -p config && ./bin/gen_ci_config -p test_ -i dummy > config/dummy_config.yml
+      #    - mkdir -p config && ./bin/gen_ci_config -p clustering_ -i clustering > config/clustering_config.yml
+      #
+      #dummy-pipeline:
+      #  stage: run
+      #  needs: ["generate_config"]
+      #  trigger:
+      #    include:
+      #      - artifact: config/dummy_config.yml
+      #        job: generate_config
+      #    strategy: depend
+      #
+      #clustering-pipeline:
+      #  stage: run
+      #  needs: ["generate_config"]
+      #  trigger:
+      #    include:
+      #      - artifact: config/clustering_config.yml
+      #        job: generate_config
+      #    strategy: depend
 
 include: 
   - local: 'ecal/ecal_config.yml'
 
-    #ecal-pipeline:
-    #  stage: run
-    #  needs: ["get_data"]
-    #  trigger:
-    #    include:
-    #      - artifact: config/ecal_config.yml
-    #        job: generate_config
-    #    strategy: depend
-
-    #crystal_electron_simulation:
-    #  stage: run
-    #  needs: ["get_data"]
-    #  tags:
-    #    - sodium
-    #  script:
-    #    - git clone https://eicweb.phy.anl.gov/EIC/datasets.git datasets
-    #    - ln -s datasets/data
-    #    - ls -lrth
-    #    - root -b -q "datasets/emcal_electrons.cxx(1e7, \"emcal_uniform_electrons.hepmc\")"
-    #    - cd topside && ls -l
-    #    - npsim --runType batch --numberOfEvents 100000 --compactFile topside.xml --inputFiles ../emcal_uniform_electrons.hepmc --outputFile  ../sim_output/sim_electron_0GeVto30GeV_100k_input.root
-    #    - run gaudirun.py ./options/example_crystal.py
-    #    - root -b -q ./scripts/makeplot.C 
 
 final_report:
   stage: finish
   tags:
     - silicon
-  needs: ["clustering-pipeline","dummy-pipeline"]
+  needs: ["ecal_1_emcal_electrons"]
   script:
     - echo "It was a success!"
 
diff --git a/clustering/.gitignore b/clustering/.gitignore
deleted file mode 100644
index e69de29b..00000000
diff --git a/clustering/dummy_fail_test.sh b/clustering/dummy_fail_test.sh
deleted file mode 100644
index f8c506b3..00000000
--- a/clustering/dummy_fail_test.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-echo "Dummy Test..."
-echo "..."
-echo "Fails!"
-
-exit 1
diff --git a/clustering/dummy_test.sh b/clustering/dummy_test.sh
deleted file mode 100644
index 5af1dc34..00000000
--- a/clustering/dummy_test.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-echo "Dummy Test..."
-echo "..."
-echo "Passes!"
-
-#exit 1
diff --git a/clustering/dummy_test2.sh b/clustering/dummy_test2.sh
deleted file mode 100644
index dfede272..00000000
--- a/clustering/dummy_test2.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-echo "Dummy Test number 2..."
-echo "..."
-echo "Passes!"
-
-#exit 1
diff --git a/dummy/.gitignore b/dummy/.gitignore
deleted file mode 100644
index e69de29b..00000000
diff --git a/dummy/dummy_fail_test.sh b/dummy/dummy_fail_test.sh
deleted file mode 100644
index f8c506b3..00000000
--- a/dummy/dummy_fail_test.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-echo "Dummy Test..."
-echo "..."
-echo "Fails!"
-
-exit 1
diff --git a/dummy/dummy_test.sh b/dummy/dummy_test.sh
deleted file mode 100644
index 5af1dc34..00000000
--- a/dummy/dummy_test.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-echo "Dummy Test..."
-echo "..."
-echo "Passes!"
-
-#exit 1
diff --git a/dummy/dummy_test2.sh b/dummy/dummy_test2.sh
deleted file mode 100644
index dfede272..00000000
--- a/dummy/dummy_test2.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-echo "Dummy Test number 2..."
-echo "..."
-echo "Passes!"
-
-#exit 1
diff --git a/ecal/ecal_config.yml b/ecal/ecal_config.yml
index c661e028..d445eb8c 100644
--- a/ecal/ecal_config.yml
+++ b/ecal/ecal_config.yml
@@ -2,6 +2,7 @@ ecal_1_emcal_electrons:
   image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:latest
   tags:
     - silicon
+  needs: ["get_data"]
   timeout: 12 hours 30 minutes
   artifacts:
     expire_in: 20 weeks
diff --git a/ecal/emcal_electrons.sh b/ecal/emcal_electrons.sh
index 4404dab5..eefa87ad 100644
--- a/ecal/emcal_electrons.sh
+++ b/ecal/emcal_electrons.sh
@@ -1,6 +1,5 @@
 #!/bin/bash
 
-
 if [[ ! -n  "${JUGGLER_DETECTOR}" ]] ; then 
   export JUGGLER_DETECTOR="topside"
 fi
@@ -18,15 +17,19 @@ export JUGGLER_REC_FILE="rec_${JUGGLER_FILE_NAME_TAG}.root"
 echo "JUGGLER_N_EVENTS = ${JUGGLER_N_EVENTS}"
 echo "JUGGLER_DETECTOR = ${JUGGLER_DETECTOR}"
 
-git clone https://eicweb.phy.anl.gov/EIC/datasets.git datasets
-root -b -q "datasets/emcal_electrons.cxx(${JUGGLER_N_EVENTS}, \"${JUGGLER_FILE_NAME_TAG}.hepmc\")"
 
+# Build the detector constructors.
 git clone https://eicweb.phy.anl.gov/EIC/detectors/${JUGGLER_DETECTOR}.git
 mkdir ${JUGGLER_DETECTOR}/build
 pushd ${JUGGLER_DETECTOR}/build
 cmake ../. -DCMAKE_INSTALL_PREFIX=/usr/local && make -j30 install
 popd
 
+# generate the input events
+# note datasets is now only used to develop datasets.
+#git clone https://eicweb.phy.anl.gov/EIC/datasets.git datasets
+root -b -q "ecal/scripts/emcal_electrons.cxx(${JUGGLER_N_EVENTS}, \"${JUGGLER_FILE_NAME_TAG}.hepmc\")"
+
 pushd ${JUGGLER_DETECTOR}
 ls -l
 # run geant4 simulations
@@ -37,18 +40,15 @@ npsim --runType batch \
       --inputFiles ../${JUGGLER_FILE_NAME_TAG}.hepmc \
       --outputFile  ${JUGGLER_SIM_FILE}
 # Need to figure out how to pass file name to juggler from the commandline
-
 xenv -x /usr/local/Juggler.xenv gaudirun.py ../ecal/options/example_crystal.py
 ls -l
-
 popd
-ls -l
 
 pwd
 mkdir -p results
-root -b -q "./scripts/makeplot.C(\"${JUGGLER_DETECTOR}/${JUGGLER_REC_FILE}\")"
+root -b -q "ecal/scripts/makeplot.C(\"${JUGGLER_DETECTOR}/${JUGGLER_REC_FILE}\")"
 
-mkdir -p sim_output
-cp "${JUGGLER_DETECTOR}/${JUGGLER_REC_FILE}" sim_output/.
-cp "${JUGGLER_DETECTOR}/${JUGGLER_SIM_FILE}" sim_output/.
+#mkdir -p sim_output
+#cp "${JUGGLER_DETECTOR}/${JUGGLER_REC_FILE}" sim_output/.
+#cp "${JUGGLER_DETECTOR}/${JUGGLER_SIM_FILE}" sim_output/.
 
diff --git a/ecal/scripts/emcal_electrons.cxx b/ecal/scripts/emcal_electrons.cxx
new file mode 100644
index 00000000..ca45a209
--- /dev/null
+++ b/ecal/scripts/emcal_electrons.cxx
@@ -0,0 +1,79 @@
+//////////////////////////////////////////////////////////////
+// Crystal EMCAL detector 
+// Single Electron dataset
+// J.KIM 07/20/2020
+//
+// 10/4/2020 
+// Changed to have isotropic distribution in momentum sphere
+//////////////////////////////////////////////////////////////
+#include "HepMC3/GenEvent.h"
+#include "HepMC3/ReaderAscii.h"
+#include "HepMC3/WriterAscii.h"
+#include "HepMC3/Print.h"
+
+#include <iostream>
+#include<random>
+#include<cmath>
+#include <math.h>
+#include <TMath.h>
+
+using namespace HepMC3;
+
+void emcal_electrons(int n_events = 1e6, const char* out_fname = "./data/emcal_electron_0GeVto30GeV_100kEvt.hepmc")
+{
+  WriterAscii hepmc_output(out_fname);
+  int events_parsed = 0;
+  GenEvent evt(Units::GEV, Units::MM);
+
+  // Random number generator
+  TRandom *r1 = new TRandom();
+
+  for (events_parsed = 0; events_parsed < n_events; events_parsed++) {
+    // FourVector(px,py,pz,e,pdgid,status)
+    // type 4 is beam
+    // pdgid 11 - electron
+    // pdgid 111 - pi0
+    // pdgid 2212 - proton
+    GenParticlePtr p1 =
+        std::make_shared<GenParticle>(FourVector(0.0, 0.0, 10.0, 10.0), 11, 4);
+    GenParticlePtr p2 = std::make_shared<GenParticle>(
+        FourVector(0.0, 0.0, 0.0, 0.938), 2212, 4);
+
+    // Define momentum
+    Double_t p = r1->Uniform(0.0, 30.0);
+    Double_t px;
+    Double_t py;
+    Double_t pz;
+    // Generates random vectors, uniformly distributed over the surface of a
+    // sphere of given radius, in this case momentum.
+    r1->Sphere(px, py, pz, p);
+
+    // type 1 is final state
+    // pdgid 11 - electron 0.510 MeV/c^2
+    GenParticlePtr p3 = std::make_shared<GenParticle>(
+        FourVector(
+            px, py, pz,
+            sqrt(p*p + (0.000511 * 0.000511))),
+        11, 1);
+
+    GenVertexPtr v1 = std::make_shared<GenVertex>();
+    v1->add_particle_in(p1);
+    v1->add_particle_in(p2);
+
+    v1->add_particle_out(p3);
+    evt.add_vertex(v1);
+
+    if (events_parsed == 0) {
+      std::cout << "First event: " << std::endl;
+      Print::listing(evt);
+    }
+
+    hepmc_output.write_event(evt);
+    if (events_parsed % 10000 == 0) {
+      std::cout << "Event: " << events_parsed << std::endl;
+    }
+    evt.clear();
+  }
+  hepmc_output.close();
+  std::cout << "Events parsed and written: " << events_parsed << std::endl;
+}
diff --git a/ecal/scripts/emcal_electrons_reader.cxx b/ecal/scripts/emcal_electrons_reader.cxx
new file mode 100644
index 00000000..5537e3b8
--- /dev/null
+++ b/ecal/scripts/emcal_electrons_reader.cxx
@@ -0,0 +1,126 @@
+//////////////////////////
+// Crystal EMCAL detector 
+// Electron dataset
+// J.KIM 07/20/2020
+//////////////////////////
+#include "HepMC3/GenEvent.h"
+#include "HepMC3/ReaderAscii.h"
+#include "HepMC3/WriterAscii.h"
+#include "HepMC3/Print.h"
+
+#include "TH1F.h"
+#include <iostream>
+#include "TStyle.h"
+
+using namespace HepMC3;
+
+void emcal_electrons_reader(){
+
+      	// Setting for graphs
+  	gROOT->SetStyle("Plain");
+ 	gStyle->SetOptFit(1);
+  	gStyle->SetLineWidth(2);
+  	gStyle->SetPadTickX(1);
+  	gStyle->SetPadTickY(1);
+  	gStyle->SetPadGridX(1);
+  	gStyle->SetPadGridY(1);
+  	gStyle->SetPadLeftMargin(0.14);
+	gStyle->SetPadRightMargin(0.14);
+
+	ReaderAscii hepmc_input("./data/emcal_electron_0GeVto30GeV_100kEvt.hepmc");
+	int         events_parsed = 0;
+	GenEvent    evt(Units::GEV, Units::MM);
+
+	// Histograms
+	TH1F* h_electrons_energy = new TH1F("h_electron_energy",  "electron energy;E [GeV];Events",         100,-0.5,30.5);
+	TH1F* h_electrons_eta    = new TH1F("h_electron_eta",     "electron #eta;#eta;Events",              100,-10.0,10.0);
+	TH1F* h_electrons_theta  = new TH1F("h_electron_theta",   "electron #theta;#theta [degree];Events", 100,-0.5,180.5);
+	TH1F* h_electrons_phi    = new TH1F("h_electron_phi",     "electron #phi;#phi [degree];Events",     100,-180.5,180.5);
+	TH2F* h_electrons_pzpt   = new TH2F("h_electrons_pzpt",   "electron pt vs pz;pt [GeV];pz [GeV]",    100,-0.5,30.5,100,-30.5,30.5);
+	TH2F* h_electrons_pxpy   = new TH2F("h_electrons_pxpy",   "electron px vs py;px [GeV];py [GeV]",    100,-30.5,30.5,100,-30.5,30.5);
+	TH3F* h_electrons_p      = new TH3F("h_electron_p",       "electron p;px [GeV];py [GeV];pz [GeV]",  100,-30.5,30.5,100,-30.5,30.5,100,-30.5,30.5);
+
+	while(!hepmc_input.failed()) {
+		// Read event from input file
+		hepmc_input.read_event(evt);
+		// If reading failed - exit loop
+    		if( hepmc_input.failed() ) break;
+
+    		for(const auto& v : evt.vertices() ) {
+      			for(const auto& p : v->particles_out() ) {
+        			if(p->pid() == 11) {
+          			h_electrons_energy->Fill(p->momentum().e());
+				h_electrons_eta->Fill(p->momentum().eta());
+				h_electrons_theta->Fill(p->momentum().theta()*TMath::RadToDeg());
+				h_electrons_phi->Fill(p->momentum().phi()*TMath::RadToDeg());
+				h_electrons_pzpt->Fill(TMath::Sqrt(p->momentum().px()*p->momentum().px() + p->momentum().py()*p->momentum().py()),p->momentum().pz());
+				h_electrons_pxpy->Fill(p->momentum().px(),p->momentum().py());
+				h_electrons_p->Fill(p->momentum().px(),p->momentum().py(),p->momentum().pz());
+				}
+      			}
+    		}
+    		evt.clear();
+    		events_parsed++;
+  	}
+  	std::cout << "Events parsed and written: " << events_parsed << std::endl;
+
+  	TCanvas* c = new TCanvas("c","c", 500, 500);
+	h_electrons_energy->GetYaxis()->SetTitleOffset(1.8);
+	h_electrons_energy->SetLineWidth(2);
+	h_electrons_energy->SetLineColor(kBlue);
+  	h_electrons_energy->DrawClone();
+  	c->SaveAs("results/emcal_electrons_energy_0GeVto30GeV.png");
+  	c->SaveAs("results/emcal_electrons_energy_0GeVto30GeV.pdf");
+
+        TCanvas* c1 = new TCanvas("c1","c1", 500, 500);
+	h_electrons_eta->GetYaxis()->SetTitleOffset(1.9);
+	h_electrons_eta->SetLineWidth(2);
+	h_electrons_eta->SetLineColor(kBlue);
+        h_electrons_eta->DrawClone();
+        c1->SaveAs("results/emcal_electrons_eta_0GeVto30GeV.png");
+        c1->SaveAs("results/emcal_electrons_eta_0GeVto30GeV.pdf");
+
+        TCanvas* c2 = new TCanvas("c2","c2", 500, 500);
+	h_electrons_theta->GetYaxis()->SetTitleOffset(1.8);
+	h_electrons_theta->SetLineWidth(2);
+	h_electrons_theta->SetLineColor(kBlue);
+        h_electrons_theta->DrawClone();
+	c2->SaveAs("results/emcal_electrons_theta_0GeVto30GeV.png");
+	c2->SaveAs("results/emcal_electrons_theta_0GeVto30GeV.pdf");
+
+        TCanvas* c3 = new TCanvas("c3","c3", 500, 500);
+	h_electrons_phi->GetYaxis()->SetTitleOffset(1.8);
+	h_electrons_phi->SetLineWidth(2);
+	h_electrons_phi->GetYaxis()->SetRangeUser(0.0,h_electrons_phi->GetMaximum()+100.0);
+	h_electrons_phi->SetLineColor(kBlue);
+        h_electrons_phi->DrawClone();
+	c3->SaveAs("results/emcal_electrons_phi_0GeVto30GeV.png");
+	c3->SaveAs("results/emcal_electrons_phi_0GeVto30GeV.pdf");
+
+	TCanvas* c4 = new TCanvas("c4","c4", 500, 500);
+	h_electrons_pzpt->GetYaxis()->SetTitleOffset(1.4);
+	h_electrons_pzpt->SetLineWidth(2);
+	h_electrons_pzpt->SetLineColor(kBlue);
+	h_electrons_pzpt->DrawClone("COLZ");
+	c4->SaveAs("results/emcal_electrons_pzpt_0GeVto30GeV.png");
+	c4->SaveAs("results/emcal_electrons_pzpt_0GeVto30GeV.pdf");
+
+	TCanvas* c5 = new TCanvas("c5","c5", 500, 500);
+	h_electrons_pxpy->GetYaxis()->SetTitleOffset(1.4);
+	h_electrons_pxpy->SetLineWidth(2);
+	h_electrons_pxpy->SetLineColor(kBlue);
+	h_electrons_pxpy->DrawClone("COLZ");
+	c5->SaveAs("results/emcal_electrons_pxpy_0GeVto30GeV.png");
+	c5->SaveAs("results/emcal_electrons_pxpy_0GeVto30GeV.pdf");
+
+ 	TCanvas* c6 = new TCanvas("c6","c6", 500, 500);
+	h_electrons_p->GetYaxis()->SetTitleOffset(1.8);
+	h_electrons_p->GetXaxis()->SetTitleOffset(1.6);
+	h_electrons_p->GetZaxis()->SetTitleOffset(1.6);
+	h_electrons_p->SetLineWidth(2);
+	h_electrons_p->SetLineColor(kBlue);
+        h_electrons_p->DrawClone();
+	c6->SaveAs("results/emcal_electrons_p_0GeVto30GeV.png");
+	c6->SaveAs("results/emcal_electrons_p_0GeVto30GeV.pdf");
+
+}
diff --git a/scripts/makeplot.C b/ecal/scripts/makeplot.C
similarity index 100%
rename from scripts/makeplot.C
rename to ecal/scripts/makeplot.C
-- 
GitLab