LUND2ParticleGun.C
Jump to navigation
Jump to search
#include <math.h>
#include <TRandom3.h>
#include <stdio.h>
#include <stdlib.h>
void LUND2ParticleGun()
{
int nlines,file_parts,step;
char LUND_file[200];
char path[200];
char Run_file[20];
char mac[20]="Run";
double Px,Py,Pz,E;
double px,py,pz,e;
double weight;
double M,X,Y,Z;
double m,x,y,z;
double Number_of_particles,Number_of_target_nucleons,Number_of_target_protons,Target_polarization,Beam_polarization,W,Q2,v;
double Index1,Charge1,Type1,PID1,Parent_Index1,Daughter_Index1;
double Index2,Charge2,Type2,PID2,Parent_Index2,Daughter_Index2;
double extra;
cout << "Number of LUND files to convert?" << endl;
cin >> file_parts ;
cout << "Path?" << endl;
cin >> path;
step=0;
for(int i=0;i<file_parts;i++)
{
ifstream in;
if(step<10)
{
sprintf(LUND_file,"%s_00%d.LUND",path,step);
in.open(LUND_file);
}
if(step>9 && step<100)
{
sprintf(LUND_file,"%s_0%d.LUND",path,step);
in.open(LUND_file);
}
if(step>99 && step<1000)
{
sprintf(LUND_file,"%s_%d.LUND",path,step);
in.open(LUND_file);
}
ofstream out;
if(step<10)
{
sprintf(Run_file,"%s00%d.mac",mac,step);
out.open(Run_file);
}
if(step>9 && step<100)
{
sprintf(Run_file,"%s0%d.mac",mac,step);
out.open(Run_file);
}
if(step>99 && step<1000)
{
sprintf(Run_file,"%s%d.mac",mac,step);
out.open(Run_file);
}
out << "random/setSeeds 12345679" << endl;
for(nlines=0;nlines<1000;nlines++)
{
//Read in LUND variables
in >> Number_of_particles >> Number_of_target_nucleons >> Number_of_target_protons >> extra >> Target_polarization >> Beam_polarization >> weight >>
y >> W >> Q2 >> v ;
in >> Index1 >> Charge1 >> Type1 >> PID1 >> Parent_Index1 >> Daughter_Index1 >> Px >> Py >> Pz >> E >> M >> X >> Y >> Z;
in >> Index2 >> Charge2 >> Type2 >> PID2 >> Parent_Index2 >> Daughter_Index2 >> px >> py >> pz >> e >> m >> x >> y >> z;
//Write particle gun macro
out << "/event/verbose 1" << endl;
out << "/tracking/verbose 1" << endl;
out << "/gun/particle e-" << endl;
out << "/gun/energy "<< e << endl;
out << "/gun/position " << x << "\t" << y << "\t" << z << "\t" << "cm" << endl;
out << "/gun/momentum " << px << "\t" << py << "\t" << pz << "\t" << "MeV" << endl;
out << "/run/beamOn 1" << endl;
}//End individual LUND loop
step=step+1;
in.close();
out.close();
}//End loop over all LUNDS
}//End main