//*********************************************************************************************************** // TomoSpectrum_HIST.C // Root command file // Type: root TomoSpectrum_HIST.C // // It visualizes the spectrum of X-rays and plots a histogram by reading PixeEvent data // // More information is available in UserGuide // Created by Z.LI LP2i Bordeaux 2022 //*********************************************************************************************************** #include #include #include #include #include // using namespace std; struct PixeEvent { uint16_t energy_10eV; uint16_t pixelIndex; uint16_t sliceIndex; uint8_t projectionIndex; }; void Plot(vector& energies, int bin, double eMin, double eMax) { gROOT->Reset(); auto mycanvas = new TCanvas("canvas", "canvas", 800, 50, 600, 600); mycanvas->ToggleEventStatus(); gPad->SetLeftMargin(0.15); auto hist = new TH1D("HIST", "Spectrum", bin, eMin, eMax); for (int i = 0; i < energies.size(); ++i) { hist->Fill(energies[i]); } hist->Draw(); hist->SetTitle("TOMO Energy Spectrum"); hist->GetXaxis()->SetTitle("ADC channels"); hist->GetYaxis()->SetTitle("Nb events"); hist->GetXaxis()->CenterTitle(); hist->GetYaxis()->CenterTitle(); // hist->GetYaxis()->SetTitleOffset(2); mycanvas->Print("TomoSpectrum_hist.png"); } void TomoSpectrum_HIST() { FILE* input = fopen("../build/PixeEvent_std_AtExit_Detector135_Aperture70.DAT", "rb"); if (input == NULL) { printf("----------error for opening the input file--------------\n"); return; } //*********************************************************************** //**************************Selection parameters (begin)***************** //*********************************************************************** const int nbProjection = 10; const int nbSlice = 1; const int nbPixel = 20; int projection_index_begin = 0; // starter of the projection selected int projection_index_end = 0; // end of the projection selected int slice_index_begin = 0; // starter of the slice selected int slice_index_end = 0; // end of the slice selected //********************Parameters for spectrum*************************** int nbChannels = 4096; double eMin = 0; // initialization double eMax = 0; // //*********************************************************************** //**************************Selection parameters (end)******************* //*********************************************************************** vector energies; PixeEvent p; while (fread(&p, 7, 1, input)) { if (p.projectionIndex >= projection_index_begin && p.projectionIndex <= projection_index_end) { if (p.sliceIndex >= slice_index_begin && p.sliceIndex <= slice_index_end) { energies.push_back(p.energy_10eV); if (p.energy_10eV > eMax) eMax = p.energy_10eV; } } } fclose(input); long int size = energies.size(); vector X(nbChannels); // save channels 1-4096 vector Y(nbChannels); for (long int i = 0; i < size; ++i) { int energy = energies[i]; Y[energy - 1] = Y[energy - 1] + 1; } for (int i = 0; i < nbChannels; ++i) { X[i] = 1 + i; } FILE* out = fopen("Spectrum_hist.txt", "wb"); for (int i = 0; i < nbChannels; ++i) { fprintf(out, "%d\t%d\n", X[i], Y[i]); } fclose(out); Plot(energies, nbChannels, 0, nbChannels); }