Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:17:04

0001 //***********************************************************************************************************
0002 // Extract_Slice.C
0003 // Root command file
0004 // Use it by typing in the command line of Root terminal: root Extract_Slice.C
0005 //
0006 //
0007 // More information is available in UserGuide
0008 // Created by Z.LI LP2i Bordeaux 2022
0009 //***********************************************************************************************************
0010 
0011 #include <math.h>
0012 #include <stdint.h>
0013 #include <stdio.h>
0014 #include <string.h>
0015 
0016 #include <vector>
0017 // using namespace std;
0018 
0019 #define PI 3.14159265f
0020 
0021 // Define a structure to read and write each event in the required binary format
0022 struct PixeEvent
0023 {
0024   uint16_t energy_10eV;
0025   uint16_t pixelIndex;
0026   uint16_t sliceIndex;
0027   uint8_t projectionIndex;
0028 };
0029 
0030 // to extract a certain slice or slices
0031 
0032 void Extract_Projection()
0033 {
0034   // FILE *in =fopen("PixeEvent_std_AtCreation.DAT","rb");
0035   FILE* in = fopen("../build/PixeEvent_std_AtExit_Detector135_Aperture70.DAT", "rb");
0036 
0037   // FILE* out = fopen("PixeEvent_std_AtCreation_50Projections.DAT","wb");
0038   FILE* out = fopen("../build/PixeEvent_std_AtExit_Detector135_Aperture70_50Projections.DAT", "wb");
0039 
0040   if (in == NULL) {
0041     printf("error for opening the intput file\n");
0042     return;
0043   }
0044 
0045   PixeEvent p;
0046   PixeEvent pp;
0047   vector<int> valid_projections;
0048   for (int i = 0; i < 50; ++i) {
0049     int p = 2 * i;
0050     valid_projections.push_back(p);
0051   }
0052 
0053   while (fread(&p, 7, 1, in)) {
0054     int key = p.projectionIndex;
0055 
0056     if (std::find(valid_projections.begin(), valid_projections.end(), key)
0057         != valid_projections.end()) {
0058       pp.energy_10eV = p.energy_10eV;
0059       pp.projectionIndex = p.projectionIndex / 2;
0060       pp.sliceIndex = p.sliceIndex;  // index of slices should be reset, starting from 0
0061       pp.pixelIndex = p.pixelIndex;
0062       pp.pixelIndex = p.pixelIndex;
0063       // printf("__ProjectionIndex=%d, SliceIndex=%d, PixelIndex=%d, Energy_10eV=%d\n",
0064       // pp.projectionIndex, pp.sliceIndex, pp.pixelIndex, pp.energy_10eV);
0065       fwrite(&pp, 7, 1, out);
0066     }
0067   }
0068   fclose(in);
0069   fclose(out);
0070 }