From 54bc4b3619bbb33cfb186070aa1990d26b95b64e Mon Sep 17 00:00:00 2001
From: Louis Lemair <lemair@lpccaen.in2p3.fr>
Date: Wed, 13 Jul 2022 18:17:32 +0200
Subject: [PATCH] *Adding to Nebula a few root data-analysis scripts

        - macro/live/NebulaWall.C is the one for dynamic hit bar display
---
 Projects/Nebula/macro/CalcEn.C                |   9 ++
 Projects/Nebula/macro/ChargeDraw.C            |  35 +++++
 Projects/Nebula/macro/Colorbyprocess.C        |  49 +++++++
 Projects/Nebula/macro/DrawEn_and_Efficiency.C |  39 ++++++
 Projects/Nebula/macro/EnDraw.C                |  34 +++++
 Projects/Nebula/macro/EnvsLight.C             |  26 ++++
 Projects/Nebula/macro/GetTBrowser.C           |  19 +++
 .../Nebula/macro/PlasticBarTimeAndPosition.C  |  26 ++++
 Projects/Nebula/macro/draw/EnvsLight.C        |  33 +++++
 Projects/Nebula/macro/draw/PositionZ.C        |  29 ++++
 Projects/Nebula/macro/draw/ProcVsKinEn2D.C    | 125 ++++++++++++++++++
 Projects/Nebula/macro/draw/ProcVsKinEn3D.C    |  59 +++++++++
 Projects/Nebula/macro/draw/ProcessGraph.C     |  51 +++++++
 Projects/Nebula/macro/live/NebulaWall.C       |  82 ++++++++++++
 14 files changed, 616 insertions(+)
 create mode 100644 Projects/Nebula/macro/CalcEn.C
 create mode 100644 Projects/Nebula/macro/ChargeDraw.C
 create mode 100644 Projects/Nebula/macro/Colorbyprocess.C
 create mode 100644 Projects/Nebula/macro/DrawEn_and_Efficiency.C
 create mode 100644 Projects/Nebula/macro/EnDraw.C
 create mode 100644 Projects/Nebula/macro/EnvsLight.C
 create mode 100644 Projects/Nebula/macro/GetTBrowser.C
 create mode 100644 Projects/Nebula/macro/PlasticBarTimeAndPosition.C
 create mode 100644 Projects/Nebula/macro/draw/EnvsLight.C
 create mode 100644 Projects/Nebula/macro/draw/PositionZ.C
 create mode 100644 Projects/Nebula/macro/draw/ProcVsKinEn2D.C
 create mode 100644 Projects/Nebula/macro/draw/ProcVsKinEn3D.C
 create mode 100644 Projects/Nebula/macro/draw/ProcessGraph.C
 create mode 100644 Projects/Nebula/macro/live/NebulaWall.C

diff --git a/Projects/Nebula/macro/CalcEn.C b/Projects/Nebula/macro/CalcEn.C
new file mode 100644
index 000000000..d80bbef51
--- /dev/null
+++ b/Projects/Nebula/macro/CalcEn.C
@@ -0,0 +1,9 @@
+void CalcEn(double PosY, double PosZ, double TOF){
+  double c_light = 299.795;
+  double mass_neutron = 939.57;
+  double distance = sqrt(pow(PosY,2)+pow(PosZ,2));
+  double speed = distance/TOF;
+  double gamma = 1/sqrt(1-pow(speed,2)/pow(c_light,2));
+  double energy = (gamma-1)*mass_neutron;
+  std::cout << "Energy is : " << energy << " MeV" << std::endl;
+ }
diff --git a/Projects/Nebula/macro/ChargeDraw.C b/Projects/Nebula/macro/ChargeDraw.C
new file mode 100644
index 000000000..e3164ca73
--- /dev/null
+++ b/Projects/Nebula/macro/ChargeDraw.C
@@ -0,0 +1,35 @@
+#include "/local/lemair/nptool/NPLib/Detectors/Nebula/TNebulaPhysics.h"
+
+void ChargeDraw(){
+  TFile* f = TFile::Open("root/analysis/PhysicsTree.root");
+  TTree* t = (TTree*)f->Get("PhysicsTree");
+
+  TNebulaPhysics *Neb_Phys = new TNebulaPhysics();
+  std::vector<double> Charge;
+  //std::vector<int>* Efficiency = 0;
+  double Ch, counter;
+  //int Eff;
+
+  //TBranch* branch_Eff;
+  TBranch* branch ;
+  //TH1F *h_Eff = new TH1F("h_Eff","test");
+  TH1F *h_En = new TH1F("h_En","Charge",160,0,160);
+  //t->SetBranchAddress("Efficiency",&Efficiency,&branch_Eff);
+  t->SetBranchAddress("Nebula",&Neb_Phys,&branch);
+  //int nentries_Eff = branch_Eff->GetEntries();
+  int nentries_Neb = branch->GetEntries();
+  
+  for(int i = 0; i < nentries_Neb ; i++){
+    t->GetEntry(i);
+    Charge = Neb_Phys->Charge;
+    int vec_size = Charge.size();
+    for(int j = 0; j < vec_size; j++){
+      Ch = Charge[j];
+      if(Ch>160) cout << "Ch " << Ch << endl;
+      h_En->Fill(Ch);
+    }
+  }
+
+  TCanvas *c2 = new TCanvas("c2","Charge",1080,720); 
+  h_En->Draw("");
+}
diff --git a/Projects/Nebula/macro/Colorbyprocess.C b/Projects/Nebula/macro/Colorbyprocess.C
new file mode 100644
index 000000000..a8495407a
--- /dev/null
+++ b/Projects/Nebula/macro/Colorbyprocess.C
@@ -0,0 +1,49 @@
+void Colorbyprocess(){
+  TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
+  TTree *t = (TTree*)f->Get("SimulatedTree");
+  //new TCanvas;
+  //t->Draw("Process");
+  //new TCanvas;
+  //t->Draw("El_is_1_and_InEl_is_2");
+  //new TCanvas;
+  //t->Draw("Efficiency");
+
+  std::vector<std::string>* processname = 0;
+  const char* name;
+  std::vector<double>* pos_z_vec = 0;
+  double pos_z;
+
+  TBranch* branch;
+  TH1F *Inel = new TH1F("Inel","test",3000,10500,12500);
+  TH1F *El = new TH1F("El","test",3000,10500,12500);
+  Inel->SetStats(0);
+  t->SetBranchAddress("Pos_Z",&pos_z_vec);
+  t->SetBranchAddress("Process",&processname,&branch);
+  int nentries = branch->GetEntries();
+    
+  for(int i = 0; i < nentries ; i++){
+    
+    t->GetEntry(i);
+    int vec_size = (*processname).size();
+    
+    for(int j = 0; j < vec_size; j++){
+      name = ((*processname)[j]).c_str();
+      pos_z = (*pos_z_vec)[j];
+      if(strcmp(name,"hadElastic")==0){
+        El->Fill(pos_z);
+      }
+      else if(strcmp(name,"neutronInelastic")==0){
+        Inel->Fill(pos_z);
+      }
+    }
+  }
+
+
+  TCanvas* c = new TCanvas();
+
+  Inel->SetLineColor(kRed);
+  El->SetLineColor(kBlue);
+
+  El->Draw();
+  Inel->Draw("SAME");
+}
diff --git a/Projects/Nebula/macro/DrawEn_and_Efficiency.C b/Projects/Nebula/macro/DrawEn_and_Efficiency.C
new file mode 100644
index 000000000..0c97cd3da
--- /dev/null
+++ b/Projects/Nebula/macro/DrawEn_and_Efficiency.C
@@ -0,0 +1,39 @@
+#include "TNebulaPhysics.h"
+
+void DrawEn_and_Efficiency(){
+  TFile* f = TFile::Open("root/analysis/PhysicsTree.root");
+  TTree* t = (TTree*)f->Get("PhysicsTree");
+  TCanvas *c1 = new TCanvas("c1","Efficiency",1080,720); 
+  t->Draw("Efficiency");
+
+  TNebulaPhysics *Neb_Phys = new TNebulaPhysics();
+  std::vector<double> NeutronEnergy;
+  //std::vector<int>* Efficiency = 0;
+  double En, counter;
+  //int Eff;
+
+  //TBranch* branch_Eff;
+  TBranch* branch_Nebula;
+  //TH1F *h_Eff = new TH1F("h_Eff","test");
+  TH1F *h_En = new TH1F("h_En","Neutrons Retrieved Energy",140,140,210);
+  //t->SetBranchAddress("Efficiency",&Efficiency,&branch_Eff);
+  t->SetBranchAddress("Nebula",&Neb_Phys,&branch_Nebula);
+  //int nentries_Eff = branch_Eff->GetEntries();
+  int nentries_Neb = branch_Nebula->GetEntries();
+  
+  for(int i = 0; i < nentries_Neb ; i++){
+    t->GetEntry(i);
+    NeutronEnergy = Neb_Phys->NeutronEn;
+    int vec_size = NeutronEnergy.size();
+    for(int j = 0; j < vec_size; j++){
+      En = NeutronEnergy[j];
+      h_En->Fill(En);
+    }
+  }
+
+  TCanvas *c2 = new TCanvas("c2","Neutron Energy",1080,720); 
+  h_En->SetLineWidth(6);
+  h_En->SetLineColor(6);
+  c2->SetFrameLineColor(0);
+  h_En->Draw("C9");
+}
diff --git a/Projects/Nebula/macro/EnDraw.C b/Projects/Nebula/macro/EnDraw.C
new file mode 100644
index 000000000..5a7a938ae
--- /dev/null
+++ b/Projects/Nebula/macro/EnDraw.C
@@ -0,0 +1,34 @@
+#include "/local/lemair/nptool/NPLib/Detectors/Nebula/TNebulaPhysics.h"
+
+void EnDraw(){
+  TFile* f = TFile::Open("root/analysis/PhysicsTree.root");
+  TTree* t = (TTree*)f->Get("PhysicsTree");
+
+  TNebulaPhysics *Neb_Phys = new TNebulaPhysics();
+  std::vector<double> NeutronEnergy;
+  //std::vector<int>* Efficiency = 0;
+  double En, counter;
+  //int Eff;
+
+  //TBranch* branch_Eff;
+  TBranch* branch_Nebula;
+  //TH1F *h_Eff = new TH1F("h_Eff","test");
+  TH1F *h_En = new TH1F("h_En","Retrieved Neutron Energy",140,140,210);
+  //t->SetBranchAddress("Efficiency",&Efficiency,&branch_Eff);
+  t->SetBranchAddress("Nebula",&Neb_Phys,&branch_Nebula);
+  //int nentries_Eff = branch_Eff->GetEntries();
+  int nentries_Neb = branch_Nebula->GetEntries();
+  
+  for(int i = 0; i < nentries_Neb ; i++){
+    t->GetEntry(i);
+    NeutronEnergy = Neb_Phys->NeutronEn;
+    int vec_size = NeutronEnergy.size();
+    for(int j = 0; j < vec_size; j++){
+      En = NeutronEnergy[j];
+      h_En->Fill(En);
+    }
+  }
+
+  TCanvas *c2 = new TCanvas("c2","Neutron Energy",1080,720); 
+  h_En->Draw("");
+}
diff --git a/Projects/Nebula/macro/EnvsLight.C b/Projects/Nebula/macro/EnvsLight.C
new file mode 100644
index 000000000..ff9d89c51
--- /dev/null
+++ b/Projects/Nebula/macro/EnvsLight.C
@@ -0,0 +1,26 @@
+void EnvsLight(){
+  TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
+  TTree* t = (TTree*)f->Get("SimulatedTree");
+  TCanvas *c1 = new TCanvas("c1","Energy vs Light",1080,720); 
+
+  double En, Light;
+
+  TBranch* branch_En;
+  TBranch* branch_Light;
+
+  TH1F *h_En = new TH1F("h_En","Energy",10,0.1,2);
+  TH1F *h_Light = new TH1F("h_Light","Light",10,0.1,2);
+  t->SetBranchAddress("Energy", &En, &branch_En);
+  t->SetBranchAddress("Light", &Light, &branch_Light);
+  
+  int nentries = t->GetEntries();
+  for(int i=0 ; i<nentries ; i++){
+    t->GetEntry(i);
+    h_En->Fill(En);
+    h_Light->Fill(Light);
+  }
+
+  h_Light->SetLineColor(2);
+  h_En->Draw();
+  h_Light->Draw("SAME");
+}
diff --git a/Projects/Nebula/macro/GetTBrowser.C b/Projects/Nebula/macro/GetTBrowser.C
new file mode 100644
index 000000000..70d5948c8
--- /dev/null
+++ b/Projects/Nebula/macro/GetTBrowser.C
@@ -0,0 +1,19 @@
+void GetTBrowser(){
+  
+  TH1F *h1 = new TH1F("h1","Somme des Temps",100,-4,4);
+
+  TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
+  TTree *t = (TTree*)f->Get("SimulatedTree");
+  TBranch *b = (TBranch*)t->GetBranch("Nebula");
+  TLeaf *tu = b->GetLeaf("fNebula_Tu_Time");
+  //Float_t td;
+  //b->SetAddress("fNebula_Td_Time", &td);
+  Int_t len = b->GetEntries();
+  Float_t sum;
+  for(int i = 0; i < len; i++){
+    sum = 0;
+    sum += tu->GetValue(i);
+    //sum += td;
+    h1->Fill(sum);
+  }
+}
diff --git a/Projects/Nebula/macro/PlasticBarTimeAndPosition.C b/Projects/Nebula/macro/PlasticBarTimeAndPosition.C
new file mode 100644
index 000000000..5bfe47abb
--- /dev/null
+++ b/Projects/Nebula/macro/PlasticBarTimeAndPosition.C
@@ -0,0 +1,26 @@
+#include "/local/lemair/nptool/NPLib/Detectors/Nebula/TNebulaPhysics.h"
+
+void PlasticBarTimeAndPosition(){
+  TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
+  TTree* t = (TTree*)f->Get("SimulatedTree");
+
+  double Time;
+  //int Eff;
+
+  //TBranch* branch_Eff;
+  TBranch* branch;
+  //TH1F *h_Eff = new TH1F("h_Eff","test");
+  TH1F *h_Time = new TH1F("h_Time","PlasticBar_Time",500,55,65);
+  //t->SetBranchAddress("Efficiency",&Efficiency,&branch_Eff);
+  t->SetBranchAddress("PlasticBar_Time",&Time,&branch);
+  //int nentries_Eff = branch_Eff->GetEntries();
+  int nentries = branch->GetEntries();
+  
+  for(int i = 0; i < nentries ; i++){
+    t->GetEntry(i);
+    h_Time->Fill(Time);
+  }
+
+  TCanvas *c2 = new TCanvas("c2","Neutron Energy",1080,720); 
+  h_Time->Draw("");
+}
diff --git a/Projects/Nebula/macro/draw/EnvsLight.C b/Projects/Nebula/macro/draw/EnvsLight.C
new file mode 100644
index 000000000..ac4a78811
--- /dev/null
+++ b/Projects/Nebula/macro/draw/EnvsLight.C
@@ -0,0 +1,33 @@
+#include "/local/lemair/nptool/NPLib/Detectors/Nebula/TNebulaPhysics.h"
+#include <iostream>     // std::cout
+#include <algorithm>    // std::find
+#include <vector>   
+
+
+void EnvsLight(){
+  TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
+  TTree* t = (TTree*)f->Get("SimulatedTree");
+  TCanvas *c1 = new TCanvas("c1","Position Z",1920,1200);
+
+  double Energy, Light;
+  TBranch* branch_En;
+  TBranch* branch_Li;
+  
+  TH1F *h_en = new TH1F("h_en","Deposited Energy",100,1,200);
+  TH1F *h_li = new TH1F("h_li","Deposited Light",100,1,200);
+  t->SetBranchAddress("PlasticBar_Energy", &Energy, &branch_En);
+  t->SetBranchAddress("PlasticBar_Light", &Light, &branch_Li);
+  
+  int nentries = t->GetEntries();
+  for(int i=0 ; i<nentries ; i++){
+    t->GetEntry(i);
+    h_en->Fill(Energy);
+    h_li->Fill(Light);
+  }
+  
+  h_en->SetLineColor(kBlue-7);
+  h_en->Draw();
+  h_li->SetLineColor(kRed-7);
+  h_li->Draw("SAME");
+}
+ 
diff --git a/Projects/Nebula/macro/draw/PositionZ.C b/Projects/Nebula/macro/draw/PositionZ.C
new file mode 100644
index 000000000..c2624a21a
--- /dev/null
+++ b/Projects/Nebula/macro/draw/PositionZ.C
@@ -0,0 +1,29 @@
+#include "/local/lemair/nptool/NPLib/Detectors/Nebula/TNebulaPhysics.h"
+#include <iostream>     // std::cout
+#include <algorithm>    // std::find
+#include <vector>   
+
+
+void PositionZ(){
+  TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
+  TTree* t = (TTree*)f->Get("SimulatedTree");
+  TCanvas *c1 = new TCanvas("c1","Position Z",1080,720);
+
+  vector<double>* PosZ;
+  int vec_size;
+  TBranch* branch;
+  
+  TH1F *h = new TH1F("h","Position Z",2400,10800,12200);
+  t->SetBranchAddress("Pos_Z", &PosZ, &branch);
+  
+  int nentries = t->GetEntries();
+  for(int i=0 ; i<nentries ; i++){
+    t->GetEntry(i);
+    vec_size = (*PosZ).size();
+    for(int j = 0 ; j<vec_size ; j++)
+      h->Fill((*PosZ)[j]);
+  }
+  
+  h->Draw("SAME");
+}
+ 
diff --git a/Projects/Nebula/macro/draw/ProcVsKinEn2D.C b/Projects/Nebula/macro/draw/ProcVsKinEn2D.C
new file mode 100644
index 000000000..b926ceae9
--- /dev/null
+++ b/Projects/Nebula/macro/draw/ProcVsKinEn2D.C
@@ -0,0 +1,125 @@
+void ProcVsKinEn2D(bool DoPads = 1, const char* PartPara = "all"){
+  
+  TFile *f = TFile::Open("root/simulation/SimulatedTree.root");
+  TTree *t = (TTree*)f->Get("SimulatedTree");
+
+  std::vector<double>* v_kinen = 0;
+  std::vector<std::string>* v_partname = 0;
+  std::vector<std::string>* v_procname = 0;
+  const char* procname;
+  const char* partname;
+  double kinEn, prevkinEn;
+  double kinDiff;
+
+  TBranch* branch_kin;
+  TBranch* branch_proc;
+  TBranch* branch_part;
+
+  TCanvas* c = new TCanvas("c", "Processes by Kinetic Energy", 1920, 1200);
+  c->SetLeftMargin(0.15);
+  c->SetRightMargin(0.1);
+  c->SetTopMargin(0.1);
+  c->SetBottomMargin(0.1);
+
+  int NbBin = 100;
+  int Xmax = 200;
+  int Xmin = 0;
+  int Ymin = 1;
+  int Ymax = 1e7; 
+
+  THStack *hs = new THStack("hs","Process CS according to Kinetic Energy");
+
+  TH1F *h_neutIn = new TH1F("h_neutIn","Neutron Inelastic",NbBin,Xmin,Xmax);
+  h_neutIn->GetYaxis()->SetRangeUser(Ymin, Ymax);
+  TH1F *h_hadEl = new TH1F("h_hadEl","Hadron Elastic",NbBin,Xmin,Xmax);
+  h_hadEl->GetYaxis()->SetRangeUser(Ymin, Ymax);
+  TH1F *h_ionIoni = new TH1F("h_ionIoni","Ion Ionization",NbBin,Xmin,Xmax);
+  h_ionIoni->GetYaxis()->SetRangeUser(Ymin, Ymax);
+  TH1F *h_hIoni = new TH1F("h_hIoni","Hadron Ionization",NbBin,Xmin,Xmax);
+  h_hIoni->GetYaxis()->SetRangeUser(Ymin, Ymax);
+
+  t->SetBranchAddress("KinEn", &v_kinen, &branch_kin);
+  t->SetBranchAddress("Process", &v_procname, &branch_proc);
+  t->SetBranchAddress("Particle", &v_partname, &branch_part);
+  int nentries = branch_kin->GetEntries();
+
+  for(int i = 0; i < nentries ; i++){
+    kinDiff = 0;
+    t->GetEntry(i);
+    int vec_size = (*v_kinen).size();
+
+    for(int j = 1; j < vec_size; j++){
+      procname = ((*v_procname)[j]).c_str();;
+      partname = ((*v_partname)[j]).c_str();;
+      prevkinEn = (*v_kinen)[j-1];
+      kinDiff = prevkinEn - kinEn;
+      if((strcmp(PartPara, "all")==0 || strcmp(partname, PartPara)==0) && 
+         strcmp(procname, "Transportation")!=0 &&
+         kinDiff>0){
+           if(strcmp(procname, "neutronInelastic")==0) h_neutIn->Fill(kinDiff);
+           else if(strcmp(procname, "hadElastic")==0) h_hadEl->Fill(kinDiff);
+           else if(strcmp(procname, "ionIoni")==0) h_ionIoni->Fill(kinDiff);
+           else if(strcmp(procname, "hIoni")==0) h_hIoni->Fill(kinDiff);
+      }
+    }
+  }
+  h_neutIn->GetYaxis()->SetTitle("Nb of Hits");
+  h_neutIn->GetXaxis()->SetTitle("Kinetic Energy (MeV)");
+
+  h_hadEl->GetYaxis()->SetTitle("Nb of Hits");
+  h_hadEl->GetXaxis()->SetTitle("Kinetic Energy (MeV)");
+
+  h_hIoni->GetYaxis()->SetTitle("Nb of Hits");
+  h_hIoni->GetXaxis()->SetTitle("Kinetic Energy (MeV)");
+
+  h_ionIoni->GetYaxis()->SetTitle("Nb of Hits");
+  h_ionIoni->GetXaxis()->SetTitle("Kinetic Energy (MeV)");
+
+  hs->Add(h_neutIn);
+  hs->Add(h_hadEl);
+  hs->Add(h_ionIoni);
+  hs->Add(h_hIoni);
+
+  if(DoPads){
+    h_neutIn->SetFillColor(kBlue-7);
+    h_hadEl->SetFillColor(kRed-7);
+    h_hIoni->SetFillColor(kYellow-7);
+    h_ionIoni->SetFillColor(kGreen-7);
+
+    hs->Draw("pads");
+
+    gPad->Update();
+    c->cd(1);
+      gPad->SetLogy(1);
+
+      gStyle->SetHistTopMargin(0.);
+      gStyle->SetOptStat(0);
+
+    c->cd(2);
+      gPad->SetLogy(1);
+
+      gStyle->SetHistTopMargin(0.);
+      gStyle->SetOptStat(0);
+
+    c->cd(3);
+      gPad->SetLogy(1);
+
+      gStyle->SetHistTopMargin(0.);
+      gStyle->SetOptStat(0);
+
+    c->cd(4);
+      gPad->SetLogy(1);
+
+      gStyle->SetHistTopMargin(0.);
+      gStyle->SetOptStat(0);
+  }
+  else{
+    gStyle->SetPalette(60);
+    hs->Draw("plc");
+    gPad->SetLogy(1);
+    hs->SetMinimum(1);
+    hs->SetMaximum(1e6);
+    hs->GetYaxis()->SetLimits(1,1e6);
+    //hs->Draw("plc");
+  }
+}
diff --git a/Projects/Nebula/macro/draw/ProcVsKinEn3D.C b/Projects/Nebula/macro/draw/ProcVsKinEn3D.C
new file mode 100644
index 000000000..cebba7d31
--- /dev/null
+++ b/Projects/Nebula/macro/draw/ProcVsKinEn3D.C
@@ -0,0 +1,59 @@
+void ProcVsKinEn3D(){
+
+  TFile *f = TFile::Open("root/simulation/SimulatedTree.root");
+  TTree *t = (TTree*)f->Get("SimulatedTree");
+
+  std::vector<double>* v_kinen = 0;
+  std::vector<std::string>* v_partname = 0;
+  std::vector<std::string>* v_procname = 0;
+  const char* procname;
+  const char* partname;
+  double kinEn, prevkinEn;
+  double kinDiff;
+
+  TBranch* branch_kin;
+  TBranch* branch_proc;
+  TBranch* branch_part;
+
+  TCanvas* c = new TCanvas("c", "Processes by Kinetic Energy", 1920, 1200);
+  c->SetLeftMargin(0.15);
+  c->SetRightMargin(0.1);
+  c->SetTopMargin(0.1);
+  c->SetBottomMargin(0.1);
+
+  TH2F *h_process_kin = new TH2F("h_process_kin","Processes by Kinetic Energy",80,0,200,1,0,1);
+  //h_process_kin->SetCanExtend(TH1::kAllAxes);
+  h_process_kin->SetStats(0);
+
+  t->SetBranchAddress("KinEn", &v_kinen, &branch_kin);
+  t->SetBranchAddress("Process", &v_procname, &branch_proc);
+  t->SetBranchAddress("Particle", &v_partname, &branch_part);
+  int nentries = branch_kin->GetEntries();
+
+  for(int i = 0; i < nentries ; i++){
+    kinDiff = 0;
+    t->GetEntry(i);
+    int vec_size = (*v_kinen).size();
+
+    for(int j = 1; j < vec_size; j++){
+      procname = ((*v_procname)[j]).c_str();;
+      partname = ((*v_partname)[j]).c_str();;
+      prevkinEn = (*v_kinen)[j-1];
+      kinDiff = prevkinEn - kinEn;
+      if(/*strcmp(partname, "neutron")==0 && */
+        strcmp(procname, "Transportation")!=0 &&
+        kinDiff>0){
+        h_process_kin->Fill(kinDiff,procname,1);
+      }
+    }
+  }
+  //h_process_kin->SetMinimum(-1);
+  //h_process_kin->SetMaximum();
+  h_process_kin->GetYaxis()->SetTitle("Process Name");
+  h_process_kin->GetXaxis()->SetTitle("Kinetic Energy (MeV)");
+  //gStyle->SetPalette(60);
+  //gStyle->SetPalette(53);
+  c->SetFrameFillColor(kAzure-6);
+  h_process_kin->Draw("COLZ");
+  c->SetLogz();
+}
diff --git a/Projects/Nebula/macro/draw/ProcessGraph.C b/Projects/Nebula/macro/draw/ProcessGraph.C
new file mode 100644
index 000000000..c5940c0ae
--- /dev/null
+++ b/Projects/Nebula/macro/draw/ProcessGraph.C
@@ -0,0 +1,51 @@
+void DrawProcessGraph(){
+  TFile* f = TFile::Open("root/simulation/SimulatedTree.root");
+  TTree *t = (TTree*)f->Get("SimulatedTree");
+  //new TCanvas;
+  //t->Draw("Process");
+  //new TCanvas;
+  //t->Draw("El_is_1_and_InEl_is_2");
+  //new TCanvas;
+  //t->Draw("Efficiency");
+
+
+  std::vector<std::string>* processname = 0;
+  const char* name;
+  std::vector<double>* pos_z_vec = 0;
+  double pos_z;
+
+  TBranch* branch;
+  TCanvas* c = new TCanvas();
+  c->SetLeftMargin(0.18);
+  c->SetRightMargin(0.13);
+  c->SetTopMargin(0.1);
+  c->SetBottomMargin(0.08);
+  TH2F *h = new TH2F("h","test",500,9900,10100,2,0,2);
+  h->SetCanExtend(TH1::kAllAxes);
+  h->SetStats(0);
+  t->SetBranchAddress("Pos_Z",&pos_z_vec);
+  t->SetBranchAddress("Process",&processname,&branch);
+  int nentries = branch->GetEntries();
+    
+  for(int i = 0; i < nentries ; i++){
+    
+    t->GetEntry(i);
+    int vec_size = (*processname).size();
+    
+    for(int j = 0; j < vec_size; j++){
+      name = ((*processname)[j]).c_str();
+      pos_z = (*pos_z_vec)[j];
+      if(strcmp(name,"Transportation")!=0){
+        h->Fill(pos_z,name,1);
+      }
+    }
+  }
+
+  //h->SetMaximum(5000);
+  h->SetMinimum(-1);
+  h->LabelsDeflate("X");
+  h->LabelsDeflate("Y");
+  h->LabelsOption("v");
+  //h->Draw("LEGO2");
+  h->Draw("SCAT");
+}
diff --git a/Projects/Nebula/macro/live/NebulaWall.C b/Projects/Nebula/macro/live/NebulaWall.C
new file mode 100644
index 000000000..5ca5b0030
--- /dev/null
+++ b/Projects/Nebula/macro/live/NebulaWall.C
@@ -0,0 +1,82 @@
+#include "/local/lemair/nptool/NPLib/Detectors/Nebula/TNebulaPhysics.h"
+#include <iostream>     // std::cout
+#include <algorithm>    // std::find
+#include <vector>   
+
+void BuildBox(double Z, double X, double Zsize, double Xsize, Color_t color){
+  TBox* box = new TBox(Z,X,Zsize,Xsize); //(Position of bottom-left corner, Position of top-right corner)
+  box->SetFillStyle(1001);
+  box->SetFillColor(color);
+  box->SetLineColor(kBlack);
+  box->SetLineWidth(1);
+
+  box->Draw("l");
+}
+
+void DrawWall(std::vector<int> v_ID){
+  vector<double> RefZ = {11060, 11181, 11910, 12031};
+  double RefX = 0;
+  double Z,X;
+  int ID;
+  Color_t color;
+
+  for(int sublayer = 0; sublayer < 4; sublayer ++){
+    for(int XOffset = -15; XOffset<15; XOffset++){
+      //CHECK IF BAR WAS HIT
+      ID = 30*sublayer + (XOffset+16);
+      if(std::find(v_ID.begin(), v_ID.end(), ID)!=v_ID.end()){
+        color = kOrange-8;
+      }else{
+        color = kCyan-8;
+      }
+
+      //DRAW BAR
+      Z = RefZ[sublayer];
+      X = RefX + XOffset*121;
+      BuildBox(Z,X,Z+120,X+120, color);
+    }
+  }
+}
+
+void NebulaWall(){
+  //SETTING THE VISUAL INTERFACE
+  TCanvas* c = new TCanvas("c", "Nebula Walls", 1920, 1200);
+  gPad->SetPad("pad", "New Pad", 0, 0, 1, 1, /*backgrd color*/ 0, /*line thickness*/ 0, /*stamping style*/ 0);
+  gPad->DrawFrame(10000,-2000,13500,2000);
+  c->SetGrid();
+  c->SetTopMargin(0.05);
+  c->SetBottomMargin(0.1);
+  c->SetLeftMargin(0.1);
+  c->SetRightMargin(0.05);
+  TFrame* frame = new TFrame(0,0,100,100);
+
+
+  //CONNECTING TO TREE AND DATA ANALYSIS
+  TFile *f = TFile::Open("root/analysis/PhysicsTree.root");
+  TTree *t = (TTree*)f->Get("PhysicsTree");
+
+  TNebulaPhysics *Neb_Phys = new TNebulaPhysics();
+  std::vector<int> v_ID;
+  int vec_size;
+  TBranch* branch;
+  t->SetBranchAddress("Nebula", &Neb_Phys, &branch);
+  int nentries = branch->GetEntries();
+
+  for(int i = 0; i < nentries; i++){
+    t->GetEntry(i);
+    v_ID = Neb_Phys->DetectorNumber;
+    vec_size = v_ID.size(); 
+
+    if(vec_size>=4){
+      DrawWall(v_ID);
+      gPad->Modified(); gPad->Update(); // make sure it is (re)drawn
+      gSystem->ProcessEvents(); gSystem->ProcessEvents();
+      gSystem->Sleep(1000);
+      
+      cout << "size " << vec_size << endl;
+      cout << "event " << i << endl << endl;
+
+      //for(int j = 0 ; j < vec_size ; j++)
+    }
+  }
+}
-- 
GitLab