File indexing completed on 2025-01-18 09:17:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <math.h>
0013 #include <stdint.h>
0014 #include <stdio.h>
0015 #include <string.h>
0016
0017 #include <vector>
0018
0019
0020 struct PixeEvent
0021 {
0022 uint16_t energy_10eV;
0023 uint16_t pixelIndex;
0024 uint16_t sliceIndex;
0025 uint8_t projectionIndex;
0026 };
0027
0028 void Plot(int nbChannels, vector<int>& X, vector<int>& Y)
0029 {
0030 gROOT->Reset();
0031
0032 auto mycanvas = new TCanvas("canvas", "canvas", 800, 50, 600, 600);
0033 mycanvas->ToggleEventStatus();
0034
0035 gPad->SetLeftMargin(0.15);
0036
0037 auto graph = new TGraph(nbChannels, X.data(), Y.data());
0038 graph->SetLineColor(8);
0039
0040 graph->Draw("AL");
0041
0042 graph->SetLineColor(8);
0043 graph->SetTitle("TOMO Energy Spectrum");
0044 graph->GetXaxis()->SetTitle("ADC channels");
0045 graph->GetYaxis()->SetTitle("Nb events");
0046 graph->GetXaxis()->CenterTitle();
0047 graph->GetYaxis()->CenterTitle();
0048
0049 mycanvas->Print("TomoSpectrum.png");
0050 }
0051
0052 void TomoSpectrum()
0053 {
0054 FILE* input = fopen("../build/PixeEvent_std_AtExit_Detector135_Aperture70.DAT", "rb");
0055
0056 if (input == NULL) {
0057 printf("----------error for opening the input file--------------\n");
0058 return;
0059 }
0060
0061
0062
0063
0064 const int nbProjection = 10;
0065 const int nbSlice = 1;
0066 const int nbPixel = 20;
0067
0068 int projection_index_begin = 0;
0069 int projection_index_end = 0;
0070
0071 int slice_index_begin = 0;
0072 int slice_index_end = 0;
0073
0074
0075
0076
0077
0078 int nbChannels = 4096;
0079 vector<int> X(nbChannels);
0080 vector<int> Y(nbChannels);
0081 PixeEvent p;
0082
0083 while (fread(&p, 7, 1, input)) {
0084 if (p.projectionIndex >= projection_index_begin && p.projectionIndex <= projection_index_end) {
0085 if (p.sliceIndex >= slice_index_begin && p.sliceIndex <= slice_index_end) {
0086
0087 Y[p.energy_10eV - 1] = Y[p.energy_10eV - 1] + 1;
0088 }
0089 }
0090 }
0091 fclose(input);
0092 for (int i = 0; i < nbChannels; ++i) {
0093 X[i] = 1 + i;
0094 }
0095
0096 FILE* out = fopen("Spectrum.txt", "wb");
0097 for (int i = 0; i < nbChannels; ++i) {
0098 fprintf(out, "%d\t%d\n", X[i], Y[i]);
0099 }
0100
0101 fclose(out);
0102 Plot(nbChannels, X, Y);
0103 }