Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //***********************************************************************************************************
0002 // LocateInterruption_ProtonAtExit.C
0003 // Root command file
0004 // Type: root LocateInterruption_ProtonAtExit.C
0005 //
0006 // It is used by reading ProtonAtExit.dat file to locate at which projection the interruption is
0007 //
0008 //
0009 // More information is available in UserGuide
0010 // Created by Z.LI LP2i Bordeaux 2022
0011 //***********************************************************************************************************
0012 
0013 #include <math.h>
0014 #include <stdint.h>
0015 #include <stdio.h>
0016 #include <string.h>
0017 
0018 #include <vector>
0019 
0020 struct ParticleInfo
0021 {
0022   float energy_keV;
0023   float mx;
0024   float my;
0025   float mz;
0026 };
0027 
0028 // struct ParticleInfo
0029 // {
0030 // float energy_keV;
0031 // float mx;
0032 // float my;
0033 // float mz;
0034 // float x;
0035 // float y;
0036 // float z;
0037 // };
0038 
0039 struct RunInfo
0040 {
0041   // uint_16t
0042   uint8_t projectionIndex;  // 1 byte
0043   uint16_t sliceIndex;  //
0044   uint16_t pixelIndex;
0045   uint32_t nbParticle;  // 4 bytes int
0046 };
0047 
0048 void LocateInterruption_ProtonAtExit()
0049 {
0050   FILE* input = fopen("../build/ProtonAtExit_1.dat", "rb");
0051   if (input == NULL) {
0052     printf("error for opening the input file\n");
0053     return;
0054   }
0055 
0056   RunInfo runInfo;
0057   int projection = 0;  // the projection when interruption occurs
0058 
0059   //***********************************************************************
0060   //**************************Detection parameters (begin)*****************
0061   //***********************************************************************
0062 
0063   const int nbProjection = 10;
0064   const int nbSlice = 128;
0065   const int nbPixel = 20;
0066 
0067   //***********************************************************************
0068   //**************************Detection parameters (end)*******************
0069   //***********************************************************************
0070 
0071   int runID = -1;
0072   while (fread(&runInfo, sizeof(RunInfo), 1, input)) {
0073     runID++;
0074 
0075     runInfo.projectionIndex = runID / (nbSlice * nbPixel);
0076     int remain = runID % (nbSlice * nbPixel);
0077     runInfo.sliceIndex = remain / nbPixel;
0078     runInfo.pixelIndex = remain % nbPixel;
0079 
0080     int nbParticle = runInfo.nbParticle;
0081     std::vector<ParticleInfo> protonAtExit(nbParticle);
0082     fread(&protonAtExit[0], sizeof(ParticleInfo), nbParticle, input);
0083 
0084     printf("---------ProjectionIndex=%d, SliceIndex=%d, PixelIndex=%d, nbParticle = %d\n",
0085            runInfo.projectionIndex, runInfo.sliceIndex, runInfo.pixelIndex, nbParticle);
0086 
0087     projection = runInfo.projectionIndex;
0088   }
0089 
0090   printf("-----------------------It is interrupted at ProjectionIndex = %d--------------------\n",
0091          projection);
0092   fclose(input);
0093 }