Geant4 Cross Reference |
1 //*********************************************************************************************************** 2 // Extract_Slice.C 3 // Root command file 4 // Use it by typing in the command line of Root terminal: root Extract_Slice.C 5 // 6 // 7 // More information is available in UserGuide 8 // Created by Z.LI LP2i Bordeaux 2022 9 //*********************************************************************************************************** 10 11 #include <math.h> 12 #include <stdint.h> 13 #include <stdio.h> 14 #include <string.h> 15 16 #include <vector> 17 // using namespace std; 18 19 #define PI 3.14159265f 20 21 // Define a structure to read and write each event in the required binary format 22 struct PixeEvent 23 { 24 uint16_t energy_10eV; 25 uint16_t pixelIndex; 26 uint16_t sliceIndex; 27 uint8_t projectionIndex; 28 }; 29 30 // to extract a certain slice or slices 31 32 void Extract_Projection() 33 { 34 // FILE *in =fopen("PixeEvent_std_AtCreation.DAT","rb"); 35 FILE* in = fopen("../build/PixeEvent_std_AtExit_Detector135_Aperture70.DAT", "rb"); 36 37 // FILE* out = fopen("PixeEvent_std_AtCreation_50Projections.DAT","wb"); 38 FILE* out = fopen("../build/PixeEvent_std_AtExit_Detector135_Aperture70_50Projections.DAT", "wb"); 39 40 if (in == NULL) { 41 printf("error for opening the intput file\n"); 42 return; 43 } 44 45 PixeEvent p; 46 PixeEvent pp; 47 vector<int> valid_projections; 48 for (int i = 0; i < 50; ++i) { 49 int p = 2 * i; 50 valid_projections.push_back(p); 51 } 52 53 while (fread(&p, 7, 1, in)) { 54 int key = p.projectionIndex; 55 56 if (std::find(valid_projections.begin(), valid_projections.end(), key) 57 != valid_projections.end()) { 58 pp.energy_10eV = p.energy_10eV; 59 pp.projectionIndex = p.projectionIndex / 2; 60 pp.sliceIndex = p.sliceIndex; // index of slices should be reset, starting from 0 61 pp.pixelIndex = p.pixelIndex; 62 pp.pixelIndex = p.pixelIndex; 63 // printf("__ProjectionIndex=%d, SliceIndex=%d, PixelIndex=%d, Energy_10eV=%d\n", 64 // pp.projectionIndex, pp.sliceIndex, pp.pixelIndex, pp.energy_10eV); 65 fwrite(&pp, 7, 1, out); 66 } 67 } 68 fclose(in); 69 fclose(out); 70 } 71