File indexing completed on 2025-01-18 09:17:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <math.h>
0015 #include <stdint.h>
0016 #include <stdio.h>
0017 #include <string.h>
0018
0019 #include <vector>
0020
0021
0022
0023 struct PixeEvent
0024 {
0025 uint16_t energy_10eV;
0026 uint16_t pixelIndex;
0027 uint16_t sliceIndex;
0028 uint8_t projectionIndex;
0029 };
0030 struct ParticleInfo
0031 {
0032 float energy_keV;
0033 float mx;
0034 float my;
0035 float mz;
0036 };
0037
0038 struct RunInfo
0039 {
0040
0041 uint8_t projectionIndex;
0042 uint16_t sliceIndex;
0043 uint16_t pixelIndex;
0044 uint32_t nbParticle;
0045 };
0046 struct Point
0047 {
0048 double m_x;
0049 double m_y;
0050 double m_z;
0051 };
0052
0053
0054
0055 bool IsDetected(Point poi1, Point poi2, double theta)
0056 {
0057 double a = (poi1.m_x * poi2.m_x + poi1.m_y * poi2.m_y + poi1.m_z * poi2.m_z)
0058 / sqrt(poi1.m_x * poi1.m_x + poi1.m_y * poi1.m_y + poi1.m_z * poi1.m_z)
0059 / sqrt(poi2.m_x * poi2.m_x + poi2.m_y * poi2.m_y + poi2.m_z * poi2.m_z);
0060 if (a > 1.0) a = 1;
0061 if (a < -1.0) a = -1;
0062 double r = acos(a);
0063 if (r > theta)
0064 return false;
0065 else
0066 return true;
0067 }
0068 void BinToStd_GammaAtCreation()
0069 {
0070
0071
0072
0073
0074 const int nbProjection = 10;
0075 const int nbSlice = 1;
0076 const int nbPixel = 20;
0077 double totalAngleSpan = 180.;
0078
0079 double angleOfDetector = 135.;
0080
0081 double distanceObjectDetector = 22.;
0082 double radiusOfDetector = 5.;
0083
0084
0085 double theta = 70 * TMath::DegToRad();
0086
0087
0088
0089
0090
0091 FILE* input = fopen("../build/GammaAtCreation.dat", "rb");
0092 FILE* out = fopen("../build/PixeEvent_std_AtCreation.DAT", "wb");
0093
0094 if (input == NULL) {
0095 printf("error for opening the input GammaAtCreation.dat file\n");
0096 return;
0097 }
0098
0099 RunInfo runInfo;
0100 PixeEvent pixeEvent;
0101 Point centerOfDetector;
0102 Point gammaMomentum;
0103 long long count = 0;
0104 int runID = -1;
0105
0106
0107 while (fread(&runInfo, sizeof(RunInfo), 1, input)) {
0108 runID++;
0109
0110 int nbParticle = runInfo.nbParticle;
0111
0112
0113
0114
0115
0116 runInfo.projectionIndex = runID / (nbSlice * nbPixel);
0117 int remain = runID % (nbSlice * nbPixel);
0118 runInfo.sliceIndex = remain / nbPixel;
0119 runInfo.pixelIndex = remain % nbPixel;
0120
0121
0122
0123
0124
0125
0126 printf(
0127 "---------RunID=%d:\nProjectionIndex=%d, SliceIndex=%d, PixelIndex=%d,"
0128 "nbParticle = %d\n",
0129 runID, runInfo.projectionIndex, runInfo.sliceIndex, runInfo.pixelIndex, nbParticle);
0130
0131
0132
0133
0134
0135 if (!nbParticle) continue;
0136 std::vector<ParticleInfo> gammaAtCreation(nbParticle);
0137 fread(&gammaAtCreation[0], sizeof(ParticleInfo), nbParticle, input);
0138
0139
0140
0141
0142 double ra = TMath::DegToRad()
0143 * (angleOfDetector + totalAngleSpan / nbProjection * runInfo.projectionIndex);
0144 centerOfDetector.m_x = distanceObjectDetector * cos(ra);
0145 centerOfDetector.m_y = distanceObjectDetector * sin(ra);
0146 centerOfDetector.m_z = 0;
0147
0148 for (int i = 0; i < nbParticle; ++i) {
0149
0150 if (gammaAtCreation[i].energy_keV >= 40.95 || gammaAtCreation[i].energy_keV <= 0.9)
0151 continue;
0152
0153 gammaMomentum.m_x = gammaAtCreation[i].mx;
0154 gammaMomentum.m_y = gammaAtCreation[i].my;
0155 gammaMomentum.m_z = gammaAtCreation[i].mz;
0156
0157 if (!IsDetected(centerOfDetector, gammaMomentum, theta))
0158 continue;
0159 else {
0160 pixeEvent.energy_10eV = floor(100 * gammaAtCreation[i].energy_keV + 0.5);
0161 pixeEvent.projectionIndex = runInfo.projectionIndex;
0162 pixeEvent.sliceIndex = runInfo.sliceIndex;
0163 pixeEvent.pixelIndex = runInfo.pixelIndex;
0164 fwrite(&pixeEvent, 7, 1, out);
0165 count++;
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178 }
0179 }
0180 }
0181 printf(
0182 "---------------Number of PixeEvent in total: "
0183 "%lld------------------------\n",
0184 count);
0185 fclose(input);
0186 fclose(out);
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199 }