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.

140 lines
4.3 KiB

  1. #define analyse2_cxx
  2. #include "analyse2.h"
  3. #include <TH2.h>
  4. #include <TStyle.h>
  5. #include <TCanvas.h>
  6. #include <string.h>
  7. #include <stdio.h>
  8. #include <iostream>
  9. #include <vector>
  10. #include <utility>
  11. #include <TFile.h>
  12. #include <TTree.h>
  13. #include <TSystemDirectory.h>
  14. #include <gsl/gsl_statistics.h>
  15. using namespace std;
  16. void analyse2::Loop()
  17. {
  18. // In a ROOT session, you can do:
  19. // Root > .L analyse2.C
  20. // Root > analyse2 t
  21. // Root > t.GetEntry(12); // Fill t data members with entry number 12
  22. // Root > t.Show(); // Show values of entry 12
  23. // Root > t.Show(16); // Read and show values of entry 16
  24. // Root > t.Loop(); // Loop on all entries
  25. //
  26. // This is the loop skeleton where:
  27. // jentry is the global entry number in the chain
  28. // ientry is the entry number in the current Tree
  29. // Note that the argument to GetEntry must be:
  30. // jentry for TChain::GetEntry
  31. // ientry for TTree::GetEntry and TBranch::GetEntry
  32. //
  33. // To read only selected branches, Insert statements like:
  34. // METHOD1:
  35. // fChain->SetBranchStatus("*",0); // disable all branches
  36. // fChain->SetBranchStatus("branchname",1); // activate branchname
  37. // METHOD2: replace line
  38. // fChain->GetEntry(jentry); //read all branches
  39. //by b_branchname->GetEntry(ientry); //read only this branch
  40. if (fChain == 0) return;
  41. Long64_t nentries = fChain->GetEntriesFast();
  42. Long64_t nbytes = 0, nb = 0;
  43. for (Long64_t jentry=0; jentry<nentries;jentry++) {
  44. Long64_t ientry = LoadTree(jentry);
  45. if (ientry < 0) break;
  46. nb = fChain->GetEntry(jentry); nbytes += nb;
  47. // if (Cut(ientry) < 0) continue;
  48. time_1 = time;
  49. ic1_1 = ic1;
  50. ic2_1 = ic2;
  51. mw1_focusx_1 = mw1_focusx;
  52. mw1_focusy_1 = mw1_focusy;
  53. mw2_focusx_1 = mw2_focusx;
  54. mw2_focusy_1 = mw2_focusy;
  55. mw1_posx_1 = mw1_posx;
  56. mw1_posy_1 = mw1_posy;
  57. mw2_posx_1 = mw2_posx;
  58. mw2_posy_1= mw2_posy;
  59. // calculate mean and integral
  60. beamSignal_1 = 0.;
  61. /*
  62. for (int ch = 0; ch < 64; ch++){
  63. beamSignal_1 += channels[ch] - baseline[ch];
  64. beamPosX_1 += (channels[ch] - baseline[ch]) * double(ch);
  65. }
  66. beamPosX_1/= beamSignal_1;
  67. // calculate FWHM from RMS
  68. beamFocusX_1 = 0.;
  69. for (int ch = 0; ch < 64; ch++){
  70. beamFocusX_1 += (channels[ch] - baseline[ch]) * (ch-beamPosX_1)* (ch-beamPosX_1);
  71. }
  72. beamFocusX_1 /= beamSignal_1;
  73. beamFocusX_1 = sqrt(beamFocusX_1); //correct this Variance = sigma*sigma / b
  74. */
  75. for (int ch = 0; ch < 64; ch++){
  76. channels[ch]-=baseline[ch]; //subtract the baseline
  77. beamSignal_1 += channels[ch]; //integrate the signal
  78. }
  79. beamPosX_1 = gsl_stats_wmean(channels,1,channellist,1,64); //calculate the weighted mean
  80. beamFocusX_1 = 2.355* gsl_stats_wsd(channels,1,channellist,1,64); //FWHM
  81. beamSkewX_1 = gsl_stats_wskew(channels,1,channellist,1,64); //skewness (symmetry)
  82. beamKurtX_1 = gsl_stats_wkurtosis(channels,1,channellist,1,64); //excess kurtosis (well behaved tails)
  83. th2f_mw1_beamPosX->Fill(mw1_posx_1,beamPosX_1);
  84. newdata->Fill();
  85. }
  86. th2f_mw1_beamPosX->Write();
  87. newdata->Write();
  88. }
  89. int main(int argc, char **argv)
  90. {
  91. // Working directories
  92. const char *dirname = "/work/leverington/beamprofilemonitor/hitdata/HIT_26-11-2016/with_timestamp/";
  93. const char *pin_dirname = "/work/leverington/beamprofilemonitor/hitdata/HIT_26-11-2016/with_timestamp/pin/";
  94. const char *ext = ".root";
  95. TSystemDirectory pin_dir(pin_dirname, pin_dirname);
  96. if (true)
  97. {
  98. TSystemFile* file;
  99. TString fname = argv[1];
  100. // fname = file->GetName();
  101. // execute single PiN_run***.root
  102. if ( fname.EndsWith(ext) && !fname.BeginsWith("SAVE") && fname.BeginsWith("PiN_run"))
  103. {
  104. analyse2 *mon = new analyse2();
  105. printf("File name: %s \n", fname.Data());
  106. // Main part
  107. // Initialize(DIRName, FileName, baselineEvents, prelimEvents, beamLevel, firstFibermat, readOutFrequency in Hz, integrationTime in us)
  108. mon->Initialize(dirname, fname.Data(), 5000, 10000, 1., true, 3000., 312.);
  109. mon->Baseline(false,1000);
  110. mon->Loop(); //analysis loop
  111. // cout << th2f_mw1_beamPosX->GetCorrelationFactor() << endl;
  112. mon->Save();//save output tree file
  113. // mon->Close();//close output tree file
  114. delete mon;
  115. }
  116. }
  117. return 0;
  118. }