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_Slice()
0033 {
0034   int start_slice = 0;  // start_slice: the first slice you would like to select
0035   int end_slice = 0;  // end_slice: the last slice you would like to select
0036 
0037   FILE* in = fopen("../build/PixeEvent_std_AtCreation.DAT", "rb");
0038   // FILE *in =fopen("PixeEvent_std_AtExit.DAT.DAT","rb");
0039 
0040   FILE* out = fopen("../build/PixeEvent_std_AtCreation_slice.DAT", "wb");
0041   // FILE* out = fopen("PixeEvent_std_AtExit_slice.DAT","wb");
0042 
0043   if (in == NULL) {
0044     printf("error for opening the intput file\n");
0045     return;
0046   }
0047 
0048   PixeEvent p;
0049   PixeEvent pp;
0050 
0051   while (fread(&p, 7, 1, in)) {
0052     if (p.sliceIndex >= start_slice && p.sliceIndex <= end_slice) {
0053       pp.energy_10eV = p.energy_10eV;
0054       pp.projectionIndex = p.projectionIndex;
0055       pp.sliceIndex =
0056         p.sliceIndex - start_slice;  // index of slices should be reset, starting from 0
0057       pp.pixelIndex = p.pixelIndex;
0058       pp.pixelIndex = p.pixelIndex;
0059       // printf("__ProjectionIndex=%d, SliceIndex=%d, PixelIndex=%d, Energy_10eV=%d\n",
0060       // pp.projectionIndex, pp.sliceIndex, pp.pixelIndex, pp.energy_10eV);
0061       fwrite(&pp, 7, 1, out);
0062     }
0063   }
0064   fclose(in);
0065   fclose(out);
0066 }