Dear Experts
I have hepmc file can you Please suggest How can i plot x y and z distributions using this file. File can be downloaded from
I have this code which is suppose to convert hepmc file to root file:
#include <iostream>
#include <fstream>
#include "HepMC/IO_GenEvent.h"
#include "TFile.h"
#include "TTree.h"
int main() {
// Open the input HepMC file
HepMC::IO_GenEvent input("input.hepmc", std::ios::in);
// Create the output ROOT file
TFile output("output.root", "RECREATE");
// Create a ROOT tree to store the event information
TTree tree("Events", "Event data");
// Define variables for event information
Int_t nParticles;
Float_t px[10000], py[10000], pz[10000], E[10000], m[10000], vx[10000], vy[10000], vz[10000];
Int_t pdgId[10000], status[10000], parentIndex[10000];
// Set branch addresses for the tree
tree.Branch("nParticles", &nParticles, "nParticles/I");
tree.Branch("px", px, "px[nParticles]/F");
tree.Branch("py", py, "py[nParticles]/F");
tree.Branch("pz", pz, "pz[nParticles]/F");
tree.Branch("E", E, "E[nParticles]/F");
tree.Branch("m", m, "m[nParticles]/F");
tree.Branch("vx", vx, "vx[nParticles]/F");
tree.Branch("vy", vy, "vy[nParticles]/F");
tree.Branch("vz", vz, "vz[nParticles]/F");
tree.Branch("pdgId", pdgId, "pdgId[nParticles]/I");
tree.Branch("status", status, "status[nParticles]/I");
tree.Branch("parentIndex", parentIndex, "parentIndex[nParticles]/I");
// Loop over each event in the HepMC file
HepMC::GenEvent* event;
while ((event = input.read_next_event()) != nullptr) {
// Clear the event variables
nParticles = 0;
// Loop over each particle in the event
for (auto particle = event->particles_begin(); particle != event->particles_end(); ++particle) {
// Store particle information in arrays
px[nParticles] = (*particle)->momentum().px();
py[nParticles] = (*particle)->momentum().py();
pz[nParticles] = (*particle)->momentum().pz();
E[nParticles] = (*particle)->momentum().e();
m[nParticles] = (*particle)->momentum().m();
vx[nParticles] = (*particle)->production_vertex()->position().x();
vy[nParticles] = (*particle)->production_vertex()->position().y();
vz[nParticles] = (*particle)->production_vertex()->position().z();
pdgId[nParticles] = (*particle)->pdg_id();
status[nParticles] = (*particle)->status();
parentIndex[nParticles] = (*particle)->production_vertex()->particles_in_size();
// Increment the particle counter
nParticles++;
}
// Fill the tree with event information
tree.Fill();
// Delete the current event
delete event;
}
// Write the tree to the ROOT file
tree.Write();
// Close the ROOT file
output.Close();
std::cout << "Conversion complete." << std::endl;
return 0;
}
but it gives error of:
/home/yasir/eic/treeReaderExample.C:3:10: fatal error: 'HepMC/IO_GenEvent.h' file not found
#include "HepMC/IO_GenEvent.h"