data analysis scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
2.9 KiB

  1. #include "hitreader.h"
  2. #include <string>
  3. #include <stdio.h>
  4. #include <iostream>
  5. #include <numeric>
  6. #include <vector>
  7. #include <algorithm> // std::count
  8. #include <utility>
  9. #include <TH2.h>
  10. #include <TF1.h>
  11. #include <TStyle.h>
  12. #include <TCanvas.h>
  13. #include <TFile.h>
  14. #include <TTree.h>
  15. #include <TSystemDirectory.h>
  16. #include <gsl/gsl_statistics.h>
  17. #include <math.h>
  18. #include <gsl/gsl_errno.h>
  19. #include <gsl/gsl_fft_complex.h>
  20. #include <TF1.h>
  21. #include <TGraphErrors.h>
  22. #include <gsl/gsl_sort.h>
  23. #include <TVector.h>
  24. #include "TStopwatch.h"
  25. #include "Math/MinimizerOptions.h"
  26. #include "TVirtualFitter.h"
  27. #include "TMatrixD.h"
  28. #include "TApplication.h"
  29. #include "TRint.h"
  30. #include "TSystem.h"
  31. #include "TMultiGraph.h"
  32. #include "TObject.h"
  33. #include <fstream>
  34. #include <iomanip> // std::setprecision
  35. //function declarations
  36. int analyse(int argc, char **argv);
  37. int opendatafiles(int argc, char ** argv);
  38. void histograms(int argc, char ** argv);
  39. double * timealign();
  40. int closedatafiles();
  41. int set_background_v2(int start_frame, int frames);
  42. void readethercat();
  43. //////global variables
  44. //opendatafiles
  45. long int fileframesize;
  46. char * filename;
  47. ifstream file;
  48. TFile *rootFile; //output root file
  49. TTree *rootTree;
  50. char * rootfilename;
  51. char * offsetfilename;
  52. ifstream offsetfile;
  53. ofstream outfile;
  54. char * ethercat_ts_filename;
  55. char * bpm_ts_filename;
  56. char * ethercat_ic1_filename;
  57. char * ethercat_ic2_filename;
  58. ifstream ethercat_ts_file, bpm_ts_file, ethercat_ic2_file, ethercat_ic1_file;;
  59. struct bpm_frame_v2 {
  60. double channel_amp[320];
  61. double channel_position[320];
  62. double avg_position;
  63. double avg_width;
  64. double integratedsignalamp;
  65. double maxchannel_amp;
  66. int maxchannel;
  67. int nrChannels;
  68. int board_number;
  69. int sma_state;
  70. };
  71. bpm_frame_v2 board_b[4];
  72. bpm_frame_v2 board_b_bkg[4];
  73. bpm_frame_v2 readboard(Fullframe frame, int boardnumber);
  74. int framestart = 0;
  75. struct beamRecon {
  76. double Position;
  77. double Focus;
  78. double Peak;
  79. double Rsqr;
  80. double Skew;
  81. double Kurtosis;
  82. double Sum;
  83. int n_channels;
  84. };
  85. struct ethercatdata{
  86. double ic1;
  87. double ic2;
  88. };
  89. ethercatdata ethercat;
  90. vector<double> vec_ic1;
  91. vector<double> vec_ic2;
  92. beamRecon beamreconstruction(bpm_frame_v2 frametoanalyse, double threshold);
  93. beamRecon BPMbeamrecon_0,BPMbeamrecon_1,BPMbeamrecon_2,BPMbeamrecon_3;
  94. beamRecon BPMbeamrecon_Zeroed;
  95. TGraph * board_graph = new TGraph(320);
  96. TF1 * beamrecon_function1 = new TF1("beamrecon_function1", "gaus(0)",0.,320.);
  97. class Channel{
  98. public:
  99. double amplitude;;
  100. double position;
  101. int chnumber;
  102. int last_neighbour;
  103. int next_neighbour;
  104. };
  105. bool CompareChannels(Channel A, Channel B);
  106. double avg ( vector<Channel> v );
  107. double variance ( vector<Channel> v , double mean );
  108. bool visualize = false;
  109. int eventID;
  110. ////histograms
  111. TH2D * TH2D_b0_signal_vs_channel;
  112. TH2D * TH2D_b1_signal_vs_channel;
  113. TH2D * TH2D_b2_signal_vs_channel;
  114. TH2D * TH2D_b3_signal_vs_channel;