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