1mm scintillating fibre tracker
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.

205 lines
6.4 KiB

3 years ago
  1. #define myanalysis_cxx
  2. #include "myanalysis.h"
  3. #include <TH2.h>
  4. #include <TStyle.h>
  5. #include <TCanvas.h>
  6. #include <TTree.h>
  7. #include <TFrame.h>
  8. #include <TH1F.h>
  9. #include <TBenchmark.h>
  10. #include <TRandom.h>
  11. #include <TSystem.h>
  12. #include <iostream>
  13. void myanalysis::Loop()
  14. {
  15. // In a ROOT session, you can do:
  16. // root> .L myanalysis.C
  17. // root> myanalysis t
  18. // root> t.GetEntry(12); // Fill t data members with entry number 12
  19. // root> t.Show(); // Show values of entry 12
  20. // root> t.Show(16); // Read and show values of entry 16
  21. // root> t.Loop(); // Loop on all entries
  22. //
  23. // This is the loop skeleton where:
  24. // jentry is the global entry number in the chain
  25. // ientry is the entry number in the current Tree
  26. // Note that the argument to GetEntry must be:
  27. // jentry for TChain::GetEntry
  28. // ientry for TTree::GetEntry and TBranch::GetEntry
  29. //
  30. // To read only selected branches, Insert statements like:
  31. // METHOD1:
  32. // fChain->SetBranchStatus("*",0); // disable all branches
  33. // fChain->SetBranchStatus("branchname",1); // activate branchname
  34. // METHOD2: replace line
  35. // fChain->GetEntry(jentry); //read all branches
  36. //by b_branchname->GetEntry(ientry); //read only this branch
  37. if (fChain == 0) return;
  38. Long64_t nentries = fChain->GetEntriesFast();
  39. int lasteventID = 0;
  40. int nPhotoelectrons = 0;
  41. bool sameEvent_bool = true;
  42. std::vector<int> unique_detectorCopy_vec;
  43. std::vector<int> hits_detectorCopy_vec;
  44. TFile * outfile = new TFile("myanalysis_out.root", "RECREATE");
  45. if ( outfile->IsOpen() ) printf("OUTPUT file opened successfully\n");
  46. // Create a TTree
  47. TTree *t = new TTree("tvec","Tree with vectors");
  48. t->Branch("runID_vec",&runID_vec);
  49. t->Branch("eventID_vec",&eventID_vec);
  50. t->Branch("detNumb_vec",&detNumb_vec);
  51. t->Branch("xPixel_vec",&xPixel_vec);
  52. t->Branch("yPixel_vec",&yPixel_vec);
  53. t->Branch("energy_vec",&energy_vec);
  54. t->Branch("wavelength_vec",&wavelength_vec);
  55. t->Branch("localtime_vec",&localtime_vec);
  56. t->Branch("abstime_vec",&abstime_vec);
  57. t->Branch("length_vec",&length_vec);
  58. t->Branch("x_vec",&x_vec);
  59. t->Branch("y_vec",&y_vec);
  60. t->Branch("z_vec",&z_vec);
  61. t->Branch("px_vec",&px_vec);
  62. t->Branch("py_vec",&py_vec);
  63. t->Branch("pz_vec",&pz_vec);
  64. t->Branch("vertexX_vec",&vertexX_vec);
  65. t->Branch("vertexY_vec",&vertexY_vec);
  66. t->Branch("vertexZ_vec",&vertexZ_vec);
  67. t->Branch("vertexPx_vec",&vertexPx_vec);
  68. t->Branch("vertexPy_vec",&vertexPy_vec);
  69. t->Branch("vertexPz_vec",&vertexPz_vec);
  70. t->Branch("gpsPosX_vec",&gpsPosX_vec);
  71. t->Branch("gpsPosY_vec",&gpsPosY_vec);
  72. t->Branch("gpsPosZ_vec",&gpsPosZ_vec);
  73. t->Branch("runId_vec",&runId_vec);
  74. t->Branch("eventId_vec",&eventId_vec);
  75. t->Branch("trackId_vec",&trackId_vec);
  76. t->Branch("creatorProcess_vec",&creatorProcess_vec);
  77. t->Branch("parentId_vec",&parentId_vec);
  78. t->Branch("lengthInCore_vec",&lengthInCore_vec);
  79. t->Branch("lengthInInnerCladding_vec",&lengthInInnerCladding_vec);
  80. t->Branch("lengthInOuterCladding_vec",&lengthInOuterCladding_vec);
  81. // t->Branch("detectorCopy_vec",&detectorCopy_vec);
  82. // t->Branch("subdetectorCopy_vec",&subdetectorCopy_vec);
  83. Long64_t nbytes = 0, nb = 0;
  84. for (Long64_t jentry=0; jentry<nentries;jentry++) {
  85. Long64_t ientry = LoadTree(jentry);
  86. if (ientry < 0) break;
  87. nb = fChain->GetEntry(jentry); nbytes += nb;
  88. // if (Cut(ientry) < 0) continue;
  89. if (ientry==0) {lasteventID = eventID;}
  90. if(eventID == lasteventID) {sameEvent_bool = true;}
  91. else { sameEvent_bool = false; }
  92. if (sameEvent_bool == false ){
  93. lasteventID = eventID;
  94. std::cout << xPixel_vec.size() << " " << uniqCnt << ": ";
  95. std::cout << std::endl;
  96. t->Fill();
  97. runID_vec.clear();
  98. eventID_vec.clear();
  99. detNumb_vec.clear();
  100. xPixel_vec.clear();
  101. yPixel_vec.clear();
  102. energy_vec.clear();
  103. wavelength_vec.clear();
  104. localtime_vec.clear();
  105. abstime_vec.clear();
  106. length_vec.clear();
  107. x_vec.clear();
  108. y_vec.clear();
  109. z_vec.clear();
  110. px_vec.clear();
  111. py_vec.clear();
  112. pz_vec.clear();
  113. vertexX_vec.clear();
  114. vertexY_vec.clear();
  115. vertexZ_vec.clear();
  116. vertexPx_vec.clear();
  117. vertexPy_vec.clear();
  118. vertexPz_vec.clear();
  119. gpsPosX_vec.clear();
  120. gpsPosY_vec.clear();
  121. gpsPosZ_vec.clear();
  122. gpsDirX_vec.clear();
  123. gpsDirY_vec.clear();
  124. gpsDirZ_vec.clear();
  125. runId_vec.clear();
  126. eventId_vec.clear();
  127. trackId_vec.clear();
  128. creatorProcess_vec.clear();
  129. parentId_vec.clear();
  130. lengthInCore_vec.clear();
  131. lengthInInnerCladding_vec.clear();
  132. lengthInOuterCladding_vec.clear();
  133. // detectorCopy_vec.clear();
  134. // subdetectorCopy_vec.clear();
  135. sameEvent_bool = true;
  136. }
  137. if (sameEvent_bool == true){
  138. runID_vec.push_back(runID);
  139. eventID_vec.push_back(eventID);
  140. detNumb_vec.push_back(detNumb);
  141. xPixel_vec.push_back(xPixel);
  142. yPixel_vec.push_back(yPixel);
  143. energy_vec.push_back(energy);
  144. wavelength_vec.push_back(wavelength);
  145. localtime_vec.push_back(localtime);
  146. abstime_vec.push_back(abstime);
  147. length_vec.push_back(length);
  148. x_vec.push_back(x);
  149. y_vec.push_back(y);
  150. z_vec.push_back(z);
  151. px_vec.push_back(px);
  152. py_vec.push_back(py);
  153. pz_vec.push_back(pz);
  154. vertexX_vec.push_back(vertexX);
  155. vertexY_vec.push_back(vertexY);
  156. vertexZ_vec.push_back(vertexZ);
  157. vertexPx_vec.push_back(vertexPx);
  158. vertexPy_vec.push_back(vertexPy);
  159. vertexPz_vec.push_back(vertexPz);
  160. gpsPosX_vec.push_back(gpsPosX);
  161. gpsPosY_vec.push_back(gpsPosY);
  162. gpsPosZ_vec.push_back(gpsPosZ);
  163. gpsDirX_vec.push_back(gpsDirX);
  164. gpsDirY_vec.push_back(gpsDirY);
  165. gpsDirZ_vec.push_back(gpsDirZ);
  166. runId_vec.push_back(runId);
  167. eventId_vec.push_back(eventId);
  168. trackId_vec.push_back(trackId);
  169. creatorProcess_vec.push_back(creatorProcess);
  170. parentId_vec.push_back(parentId);
  171. lengthInCore_vec.push_back(lengthInCore);
  172. lengthInInnerCladding_vec.push_back(lengthInInnerCladding);
  173. lengthInOuterCladding_vec.push_back(lengthInOuterCladding);
  174. // detectorCopy_vec.push_back(detectorCopy);
  175. // subdetectorCopy_vec.push_back(subdetectorCopy);
  176. }
  177. }//end of loop
  178. outfile->Write();
  179. delete outfile;
  180. }