Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-09 10:46:03

0001 // Convert the first N events of a HepMC3 ROOT tree to HepMC3 ASCII.
0002 // usage: tree2ascii IN.hepmc3.tree.root OUT.hepmc N
0003 #include <HepMC3/GenEvent.h>
0004 #include <HepMC3/ReaderRootTree.h>
0005 #include <HepMC3/WriterAscii.h>
0006 #include <cstdio>
0007 #include <cstdlib>
0008 
0009 int main(int argc, char** argv) {
0010   if (argc < 4) { std::fprintf(stderr, "usage: %s IN OUT N\n", argv[0]); return 1; }
0011   HepMC3::ReaderRootTree in(argv[1]);
0012   HepMC3::WriterAscii out(argv[2], in.run_info());
0013   const long n = std::atol(argv[3]);
0014   long i = 0;
0015   for (; i < n; ++i) {
0016     HepMC3::GenEvent evt;
0017     if (!in.read_event(evt) || in.failed()) break;
0018     out.write_event(evt);
0019   }
0020   out.close();
0021   in.close();
0022   std::printf("wrote %ld events to %s\n", i, argv[2]);
0023 }