so I have this code which outputs a macro file for geant4
I want it to generate different particles where 90% are pions and the rest(10 %) are kaons
#include <iostream>
#include "TMath.h"
#include <fstream>
#include <cmath>
#include <sstream>
#include <stdio.h>
#include "TRandom3.h"
#include "TF2.h"
using namespace std;
void main(int argc, char** argv)
{
//Written to give out new TORCH macros with correct event and run ID.
//Assume only one runID.
int N_particles = 1000;
//relevant settings
ostringstream output_file_name;
output_file_name << "modular_x=0_y=-575.in";
freopen (output_file_name.str().c_str(),"w",stdout);
double pos_start_x = 0.;
double pos_start_y = -575.;
double theta_t = 5./(180/TMath::Pi());
//end of settings
double direction_x = 0.;
double direction_y = sin(theta_t);
double direction_z = cos(theta_t);
cout << "/control/verbose 0" << endl;
cout << "/tracking/verbose 0" << endl;
cout << "/event/verbose 0" << endl;
cout << "/run/verbose 0 " << endl;
cout << "/gun/particle proton" << endl;
cout << "/gun/energy 180 GeV" << endl;
cout << "/mysetrun/SetRunID 1" << endl;
cout << "/gun/direction " << direction_x << " " << direction_y << " " << direction_z << endl;
cout << "/gun/position " << pos_start_x << " " << pos_start_y << " -0.00001 mm" << endl;
//#5 deg tilt
//double xt0[3] = {0., 0., 0.};
//double vt0[3] = {0., 0.0871557, 0.99619647};
//#7.5 deg tilt
//double xt0[3] = {-30., -13.8, 0.};
//double vt0[3] = {0., 0.130526, 0.991445};
for(int w=0; w<N_particles; w++)
{
cout << "/mysetevent/SetEventID " << w << endl;
cout << "/run/beamOn 1" << endl;
cout << endl;
}
//system("pause");
}
so what I did is change the loop to be like this:
[code]
for (int w=0; w<900; w++)
{ cout << "/mysetevent/SetEventID " << w << endl;
cout << “/gun/particle pi+” << endl;
cout << “/run/beamOn 1” << endl;
cout << endl;
}
for (int x=0; x<100; x++)
{
cout << "/mysetevent/SetEventID " << w << endl;
cout << “/gun/particle pi+” << endl;
cout << “/run/beamOn 1” << endl;
cout << endl;
}
[/code]
is that a correct way of doing it ?
and another thing, if I want it to generate random particles, how can I do that?
any comment is appreciated . Thank you.