htree.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #define htree_cxx
  2. #include "htree.h"
  3. #include <TH2.h>
  4. #include <TStyle.h>
  5. #include <TCanvas.h>
  6. #include <math.h>
  7. #include <cstdio>
  8. void htree::Loop()
  9. {
  10. // In a ROOT session, you can do:
  11. // Root > .L htree.C
  12. // Root > htree t
  13. // Root > t.GetEntry(12); // Fill t data members with entry number 12
  14. // Root > t.Show(); // Show values of entry 12
  15. // Root > t.Show(16); // Read and show values of entry 16
  16. // Root > t.Loop(); // Loop on all entries
  17. //
  18. // This is the loop skeleton where:
  19. // jentry is the global entry number in the chain
  20. // ientry is the entry number in the current Tree
  21. // Note that the argument to GetEntry must be:
  22. // jentry for TChain::GetEntry
  23. // ientry for TTree::GetEntry and TBranch::GetEntry
  24. //
  25. // To read only selected branches, Insert statements like:
  26. // METHOD1:
  27. // fChain->SetBranchStatus("*",0); // disable all branches
  28. // fChain->SetBranchStatus("branchname",1); // activate branchname
  29. // METHOD2: replace line
  30. // fChain->GetEntry(jentry); //read all branches
  31. //by b_branchname->GetEntry(ientry); //read only this branch
  32. if (fChain == 0) return;
  33. TH1F *dtof[2]; // east, west
  34. dtof[0] = new TH1F("tof_east", "TOF resolution uncorrected EAST;#Delta t, ns;dN/dt", 300,-3,3);
  35. dtof[1] = new TH1F("tof_west", "TOF resolution uncorrected WEST;#Delta t, ns;dN/dt", 300,-3,3);
  36. TH2F *dtof_slat[2]; // east, west per slat
  37. dtof_slat[0] = new TH2F("tofslat_east", "TOF resolution uncorrected EAST;slat number;#Delta t, ns;dN/dt", 1000,0,999, 300,-3,3);
  38. dtof_slat[1] = new TH2F("tofslat_west", "TOF resolution uncorrected WEST;slat number;#Delta t, ns;dN/dt", 1000,0,999, 300,-3,3);
  39. float t_exp, beta, pt, dt; // expected time
  40. Long64_t nentries = fChain->GetEntriesFast();
  41. // activate only required branches
  42. fChain->SetBranchStatus("*",0);
  43. fChain->SetBranchStatus("nh",1);
  44. fChain->SetBranchStatus("tofdz",1);
  45. fChain->SetBranchStatus("tofdphi",1);
  46. fChain->SetBranchStatus("p",1);
  47. fChain->SetBranchStatus("pltof",1);
  48. fChain->SetBranchStatus("dcarm",1);
  49. fChain->SetBranchStatus("ttof",1);
  50. fChain->SetBranchStatus("slat",1);
  51. fChain->SetBranchStatus("the0",1);
  52. for (Long64_t jentry=0; jentry<nentries;jentry++)
  53. {
  54. // skip entry if read failed
  55. if (fChain->GetEntry(jentry) == -1)
  56. break;
  57. // loop through all tracks
  58. for (int i=0; i<nh; i++)
  59. {
  60. if (fabs(tofdz[i])>1.0 || fabs(tofdphi[i])>1.0 ||
  61. dcarm[i]<0 || dcarm[i]>1)
  62. continue;
  63. pt = p[i] * sin(the0[i]);
  64. if (pt < 1.1 || pt > 1.9)
  65. continue;
  66. beta = p[i] / sqrt(0.0194795 + p[i]*p[i]);
  67. t_exp = pltof[i] / (29.9792458 * beta);
  68. dt = ttof[i] - t_exp;
  69. dtof[dcarm[i]] -> Fill(dt);
  70. dtof_slat[dcarm[i]] -> Fill(slat[i], dt);
  71. }
  72. }
  73. output->Write();
  74. puts("Processing finished.");
  75. }