File indexing completed on 2025-06-30 07:55:29
0001
0002
0003
0004
0005
0006
0007 #include "HepMC3/GenEvent.h"
0008 #include "HepMC3/Print.h"
0009 #include "HepMC3/ReaderAscii.h"
0010 #include "HepMC3/WriterAscii.h"
0011
0012 #include "TMath.h"
0013 #include "TRandom.h"
0014
0015 #include <cmath>
0016 #include <iostream>
0017 #include <math.h>
0018 #include <random>
0019 #include <fmt/core.h>
0020
0021 #include "emcal_barrel_common_functions.h"
0022
0023 using namespace HepMC3;
0024
0025 void emcal_barrel_particles_gen(std::string out_fname, int n_events = 1e6, double e_start = 0.0, double e_end = 20.0, std::string particle_name = "electron") {
0026 WriterAscii hepmc_output(out_fname);
0027 int events_parsed = 0;
0028 GenEvent evt(Units::GEV, Units::MM);
0029
0030
0031 TRandom* r1 = new TRandom();
0032
0033
0034
0035
0036
0037 double cos_theta_min = std::cos(M_PI * (45.0 / 180.0));
0038 double cos_theta_max = std::cos(M_PI * (135.0 / 180.0));
0039
0040 for (events_parsed = 0; events_parsed < n_events; events_parsed++) {
0041
0042
0043
0044
0045 GenParticlePtr p1 = std::make_shared<GenParticle>(FourVector(0.0, 0.0, 10.0, 10.0), 11, 4);
0046 GenParticlePtr p2 = std::make_shared<GenParticle>(FourVector(0.0, 0.0, 0.0, 0.938), 2212, 4);
0047
0048
0049 Double_t p = r1->Uniform(e_start, e_end);
0050 Double_t phi = r1->Uniform(0.0, 2.0 * M_PI);
0051 Double_t costheta = r1->Uniform(cos_theta_min, cos_theta_max);
0052 Double_t theta = std::acos(costheta);
0053 Double_t px = p * std::cos(phi) * std::sin(theta);
0054 Double_t py = p * std::sin(phi) * std::sin(theta);
0055 Double_t pz = p * std::cos(theta);
0056
0057
0058 auto [id, mass] = extract_particle_parameters(particle_name);
0059 GenParticlePtr p3 = std::make_shared<GenParticle>(FourVector(px, py, pz, sqrt(p * p + (mass * mass))), id, 1);
0060
0061 GenVertexPtr v1 = std::make_shared<GenVertex>();
0062 v1->add_particle_in(p1);
0063 v1->add_particle_in(p2);
0064 v1->add_particle_out(p3);
0065 evt.add_vertex(v1);
0066
0067 if (events_parsed == 0) {
0068 std::cout << "First event: " << std::endl;
0069 Print::listing(evt);
0070 }
0071
0072 hepmc_output.write_event(evt);
0073 if (events_parsed % 10000 == 0) {
0074 std::cout << "Event: " << events_parsed << std::endl;
0075 }
0076 evt.clear();
0077 }
0078 hepmc_output.close();
0079 std::cout << "Events parsed and written: " << events_parsed << std::endl;
0080 }
0081