Geant4 Cross Reference |
1 //*********************************************************************************************************** 2 // GPSPointLoop.C 3 // Root command file 4 // Type: root GPSPointLoop.C 5 // 6 // It generates a macro file to run the simulation. 7 // 8 // More information is available in UserGuide 9 // Created by Z.LI LP2i Bordeaux 2022 10 //*********************************************************************************************************** 11 12 // include <stdio.h> 13 // include <string.h> 14 // include <stdint.h> 15 // include <vector> 16 // include <math.h> 17 // using namespace std; 18 19 void GPSPointLoop() 20 { 21 gSystem->CopyFile("pixe3d_initial.mac", "pixe3d.mac", true); 22 FILE* pfile = fopen("pixe3d.mac", "a+"); 23 24 // gSystem->CopyFile("pixe3d_initial.mac", "pixe3d_stim.mac", true); 25 // FILE* pfile = fopen("pixe3d_stim.mac", "a+"); 26 27 //*********************************************** 28 //***(begin)** Define scan parameters************ 29 //*********************************************** 30 //*********************************************** 31 int NumberOfProjections = 10; // Define the number of Projections from zero to TotalAngleSpan 32 // (last value "TotalAngleSpan" is excluded) 33 int NumberOfSlices = 1; // Define the number of Slices 34 int NumberOfPixels = 20; // Define the number of Pixels for square YZ Scan 35 double TotalAngleSpan = 180; // scan angular range in degrees 36 double ScanSize = 40 * 1.8; // unit um, scan size for cube of 40 um 37 // double ScanSize = 42.48*1.8; // unit um, scan size for C.elegans 38 // double ScanSize = 500; // unit um, scan size for GDP 39 double ScanHeight = ScanSize; // Height of the scan, it depends on the need 40 // double ScanHeight = 201.127; //Height of the scan for STIM-T simulatio of C. elegans, for 128 41 // slices 42 int NbParticles = 1000000; 43 double energy = 1.5; // MeV 44 char typeParticle[10] = "proton"; 45 46 double PixelWidth = 1. * ScanSize / NumberOfPixels; // Width of each pixel 47 double SliceHeight = 1. * ScanHeight / NumberOfSlices; // Height of each 48 // slice 49 double AngleStep = 50 1. * TotalAngleSpan / NumberOfProjections; // angular increment (in degrees) 51 // between two consecutive projections 52 // 53 // The beam position is at the center of each pixel 54 // Starting position of the beam = StartScan + 0.5 x PixelWidth 55 // The scan starts from the bottom left of the square 56 // 57 double StartScanXY = -0.5 * ScanSize; 58 double StartScanZ = -0.5 * ScanHeight; 59 // double StartScanZ = 0; 60 61 bool isInterrupted = false; 62 int P_interrupt = 0; // the start of projection index to resume a simulation 63 64 //*********************************************** 65 //***(end)** Define scan parameters************** 66 //*********************************************** 67 68 //************************************ 69 //***(begin)** SCAN IMPLEMENTATION *** 70 //************************************ 71 fprintf(pfile, "/tomography/run/scanParameters %d %d %d\n", NumberOfProjections, NumberOfSlices, 72 NumberOfPixels); 73 fprintf(pfile, "#\n"); 74 75 if (isInterrupted) { 76 fprintf(pfile, "/tomography/run/resumeSimulation true\n"); 77 fprintf(pfile, "/tomography/run/resumeProjectionIndex %d\n", P_interrupt); 78 fprintf(pfile, "#\n"); 79 } 80 fprintf(pfile, "/run/initialize\n"); 81 fprintf(pfile, "#\n"); 82 // fprintf(pfile, "/run/printProgress 500000\n"); 83 // fprintf(pfile, "#\n"); 84 fprintf(pfile, "# Source definition : energy, type\n"); 85 fprintf(pfile, "#\n"); 86 fprintf(pfile, "/gps/energy %.2f MeV\n", energy); 87 fprintf(pfile, "/gps/particle %s\n", typeParticle); 88 fprintf(pfile, "#\n"); 89 fprintf(pfile, "# SOURCE POSITION AND DIRECTION\n"); 90 fprintf(pfile, "#\n"); 91 for (int projectionIndex = 0; projectionIndex < NumberOfProjections; 92 ++projectionIndex) // projections 93 { 94 if (isInterrupted) { 95 if (projectionIndex < P_interrupt) continue; 96 } 97 98 for (int sliceIndex = 0; sliceIndex < NumberOfSlices; ++sliceIndex) // slices 99 { 100 // if(sliceIndex<15) continue; 101 for (int pixelIndex = 0; pixelIndex < NumberOfPixels; ++pixelIndex) // pixels 102 { 103 double px = cos(projectionIndex * AngleStep * TMath::DegToRad()); // beam direction 104 double py = sin(projectionIndex * AngleStep * TMath::DegToRad()); 105 double pz = 0.0; 106 double x = 107 StartScanXY * px - (StartScanXY + (pixelIndex + 0.5) * PixelWidth) * py; // beam position 108 double y = StartScanXY * py + (StartScanXY + (pixelIndex + 0.5) * PixelWidth) * px; 109 double z = StartScanZ + (sliceIndex + 0.5) * SliceHeight; 110 // z = 18.07; //if z is fixed 111 // z = z + 1.953125; 112 // z = z + 3.90625; 113 fprintf(pfile, "/gps/direction %f %f %f\n", px, py, pz); 114 // fprintf(pfile, "/gps/pos/centre %.6f %.6f %.6f um\n",x, y, z ); 115 fprintf(pfile, "/gps/pos/centre %f %f %f um\n", x, y, z); 116 fprintf(pfile, "/run/beamOn %d\n", NbParticles); 117 fprintf(pfile, "#\n"); 118 } 119 } 120 } 121 fclose(pfile); 122 123 //************************************ 124 //***(end)** SCAN IMPLEMENTATION *** 125 //************************************ 126 } 127