Message: generate particles from macro Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question generate particles from macro 

Forum: Particles
Date: 27 Jul, 2016
From: Maryam AL Qassimi <Maryam AL Qassimi>

hello, I am a student and 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 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: /////////////////

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 kaon+" << endl; 
      cout << "/run/beamOn 1" << endl; 
      cout << endl; 
      }
//////////////    
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

 Add Message Add Message
to: "generate particles from macro"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]