Warning, file /detector_benchmarks/benchmarks/insert_muon/analysis/gen_particles.cxx was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #include "HepMC3/GenEvent.h"
0002 #include "HepMC3/ReaderAscii.h"
0003 #include "HepMC3/WriterAscii.h"
0004 #include "HepMC3/Print.h"
0005
0006 #include "TRandom3.h"
0007 #include "TVector3.h"
0008
0009 #include <iostream>
0010 #include <random>
0011 #include <cmath>
0012 #include <math.h>
0013 #include <TMath.h>
0014 #include <TDatabasePDG.h>
0015 #include <TParticlePDG.h>
0016
0017 using namespace HepMC3;
0018
0019
0020
0021
0022
0023
0024
0025 void gen_particles(
0026 int n_events = 1000,
0027 const char* out_fname = "gen_particles.hepmc",
0028 TString particle_name = "e-",
0029 double th_min = 3.,
0030 double th_max = 3.,
0031 double phi_min = 0.,
0032 double phi_max = 360.,
0033 double p = 10.,
0034 int dist = 0,
0035 int useCrossingAngle=1
0036 )
0037 {
0038 WriterAscii hepmc_output(out_fname);
0039 int events_parsed = 0;
0040 GenEvent evt(Units::GEV, Units::MM);
0041
0042
0043 TRandom3 *r1 = new TRandom3(0);
0044
0045
0046 TDatabasePDG *pdg = new TDatabasePDG();
0047 TParticlePDG *particle = pdg->GetParticle(particle_name);
0048 const double mass = particle->Mass();
0049 const int pdgID = particle->PdgCode();
0050
0051 for (events_parsed = 0; events_parsed < n_events; events_parsed++) {
0052
0053
0054 evt.set_event_number(events_parsed);
0055
0056
0057
0058
0059
0060
0061 GenParticlePtr p1 =
0062 std::make_shared<GenParticle>(FourVector(0.0, 0.0, 10.0, 10.0), 11, 4);
0063 GenParticlePtr p2 = std::make_shared<GenParticle>(
0064 FourVector(0.0, 0.0, 0.0, 0.938), 2212, 4);
0065
0066
0067 double phi = r1->Uniform(phi_min*TMath::DegToRad(),phi_max*TMath::DegToRad());
0068 double th = r1->Uniform(th_min*TMath::DegToRad(),th_max*TMath::DegToRad());
0069
0070
0071 double pevent = -1;
0072 if(dist==0){
0073 pevent = p;
0074 }
0075 else if(dist==1){
0076 pevent = p*(1. + r1->Uniform(-0.5,0.5) );
0077 }
0078 else if(dist==2){
0079 while(pevent<0)
0080 pevent = r1->Gaus(p,0.1*p);
0081 }
0082
0083 double px = pevent * std::cos(phi) * std::sin(th);
0084 double py = pevent * std::sin(phi) * std::sin(th);
0085 double pz = pevent * std::cos(th);
0086 TVector3 pvec(px,py,pz);
0087
0088
0089 double cross_angle = -25./1000.*useCrossingAngle;
0090 TVector3 pbeam_dir(sin(cross_angle),0,cos(cross_angle));
0091 pvec.RotateY(-pbeam_dir.Theta());
0092
0093
0094 GenParticlePtr p3 = std::make_shared<GenParticle>(
0095 FourVector(
0096 pvec.X(), pvec.Y(), pvec.Z(),
0097 sqrt(pevent*pevent + (mass * mass))),
0098 pdgID, 1);
0099
0100
0101 double vx = 0.;
0102 double vy = 0.;
0103 double vz = 0.;
0104 double vt = 0.;
0105
0106 GenVertexPtr v1 = std::make_shared<GenVertex>();
0107 evt.shift_position_by(FourVector(vx, vy, vz, vt));
0108 v1->add_particle_in(p1);
0109 v1->add_particle_in(p2);
0110
0111 v1->add_particle_out(p3);
0112 evt.add_vertex(v1);
0113
0114 if (events_parsed == 0) {
0115 std::cout << "First event: " << std::endl;
0116 Print::listing(evt);
0117 }
0118
0119 hepmc_output.write_event(evt);
0120 if (events_parsed % 100 == 0) {
0121 std::cout << "Event: " << events_parsed << std::endl;
0122 }
0123 evt.clear();
0124 }
0125 hepmc_output.close();
0126 std::cout << "Events parsed and written: " << events_parsed << std::endl;
0127 }