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