From 8582d3345bc7859a5645a7926f9bdee95727da37 Mon Sep 17 00:00:00 2001
From: Whitney Armstrong <warmstrong@anl.gov>
Date: Mon, 20 Jul 2020 16:28:46 -0500
Subject: [PATCH] 	new file:   results/.gitignore 	renamed:   
 neutrons_zdc.cxx -> zdc_neutrons.cxx 	new file:   zdc_neutrons_reader.cxx

---
 results/.gitignore                   |  0
 neutrons_zdc.cxx => zdc_neutrons.cxx |  0
 zdc_neutrons_reader.cxx              | 44 ++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+)
 create mode 100644 results/.gitignore
 rename neutrons_zdc.cxx => zdc_neutrons.cxx (100%)
 create mode 100644 zdc_neutrons_reader.cxx

diff --git a/results/.gitignore b/results/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/neutrons_zdc.cxx b/zdc_neutrons.cxx
similarity index 100%
rename from neutrons_zdc.cxx
rename to zdc_neutrons.cxx
diff --git a/zdc_neutrons_reader.cxx b/zdc_neutrons_reader.cxx
new file mode 100644
index 0000000..d6e8c5e
--- /dev/null
+++ b/zdc_neutrons_reader.cxx
@@ -0,0 +1,44 @@
+#include "HepMC3/GenEvent.h"
+#include "HepMC3/ReaderAscii.h"
+#include "HepMC3/WriterAscii.h"
+#include "HepMC3/Print.h"
+
+#include "TH1F.h"
+#include <iostream>
+using namespace HepMC3;
+
+void zdc_neutrons_reader(){
+
+  //-------------------------------------
+  ReaderAscii hepmc_input("data/neutrons_zdc.hepmc");
+  int        events_parsed = 0;
+  GenEvent   evt(Units::GEV, Units::MM);
+
+  TH1F* h_neutron_energy = new TH1F("n energy","; E [GeV]",100,0,200);
+
+  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() == 2112) {
+          h_neutron_energy->Fill(p->momentum().e());
+        }
+      }
+    }
+    evt.clear();
+    events_parsed++;
+  }
+  std::cout << "Events parsed and written: " << events_parsed << std::endl;
+
+  TCanvas* c = new TCanvas();
+  h_neutron_energy->Draw();
+  c->SaveAs("results/zdc_neutrons_reader.png");
+  c->SaveAs("results/zdc_neutrons_reader.pdf");
+}
+
+
-- 
GitLab