File indexing completed on 2024-09-27 07:02:36
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(int n_events = 1e6, double e_start = 0.0, double e_end = 20.0, std::string particle_name = "electron") {
0026 std::string out_fname = fmt::format("./data/{}", std::getenv("JUGGLER_GEN_FILE"));
0027 WriterAscii hepmc_output(out_fname);
0028 int events_parsed = 0;
0029 GenEvent evt(Units::GEV, Units::MM);
0030
0031
0032 TRandom* r1 = new TRandom();
0033
0034
0035
0036
0037
0038 double cos_theta_min = std::cos(M_PI * (45.0 / 180.0));
0039 double cos_theta_max = std::cos(M_PI * (135.0 / 180.0));
0040
0041 for (events_parsed = 0; events_parsed < n_events; events_parsed++) {
0042
0043
0044
0045
0046 GenParticlePtr p1 = std::make_shared<GenParticle>(FourVector(0.0, 0.0, 10.0, 10.0), 11, 4);
0047 GenParticlePtr p2 = std::make_shared<GenParticle>(FourVector(0.0, 0.0, 0.0, 0.938), 2212, 4);
0048
0049
0050 Double_t p = r1->Uniform(e_start, e_end);
0051 Double_t phi = r1->Uniform(0.0, 2.0 * M_PI);
0052 Double_t costheta = r1->Uniform(cos_theta_min, cos_theta_max);
0053 Double_t theta = std::acos(costheta);
0054 Double_t px = p * std::cos(phi) * std::sin(theta);
0055 Double_t py = p * std::sin(phi) * std::sin(theta);
0056 Double_t pz = p * std::cos(theta);
0057
0058
0059 auto [id, mass] = extract_particle_parameters(particle_name);
0060 GenParticlePtr p3 = std::make_shared<GenParticle>(FourVector(px, py, pz, sqrt(p * p + (mass * mass))), id, 1);
0061
0062 GenVertexPtr v1 = std::make_shared<GenVertex>();
0063 v1->add_particle_in(p1);
0064 v1->add_particle_in(p2);
0065 v1->add_particle_out(p3);
0066 evt.add_vertex(v1);
0067
0068 if (events_parsed == 0) {
0069 std::cout << "First event: " << std::endl;
0070 Print::listing(evt);
0071 }
0072
0073 hepmc_output.write_event(evt);
0074 if (events_parsed % 10000 == 0) {
0075 std::cout << "Event: " << events_parsed << std::endl;
0076 }
0077 evt.clear();
0078 }
0079 hepmc_output.close();
0080 std::cout << "Events parsed and written: " << events_parsed << std::endl;
0081 }
0082