FemtoDstAnalyzer.C 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /**
  2. * \brief Example of how to read a file (list of files) using StFemtoEvent classes
  3. *
  4. * RunFemtoDstAnalyzer.C is an example of reading FemtoDst format.
  5. * One can use either FemtoDst file or a list of femtoDst files (inFile.lis or
  6. * inFile.list) as an input, and preform physics analysis
  7. *
  8. * \author Grigory Nigmatkulov
  9. * \date May 29, 2018
  10. */
  11. // This is needed for calling standalone classes
  12. #define _VANILLA_ROOT_
  13. // C++ headers
  14. #include <iostream>
  15. // ROOT headers
  16. #include "TROOT.h"
  17. #include "TFile.h"
  18. #include "TChain.h"
  19. #include "TTree.h"
  20. #include "TSystem.h"
  21. #include "TH1.h"
  22. #include "TH2.h"
  23. #include "TMath.h"
  24. // FemtoDst headers
  25. #include "../StFemtoDstReader.h"
  26. #include "../StFemtoDst.h"
  27. #include "../StFemtoEvent.h"
  28. #include "../StFemtoTrack.h"
  29. // Load libraries (for ROOT_VERSTION_CODE >= 393215)
  30. #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
  31. R__LOAD_LIBRARY(../build/libStFemtoDst.so)
  32. #endif
  33. // inFile - is a name of name.FemtoDst.root file or a name
  34. // of a name.lis(t) files, that contains a list of
  35. // name1.FemtoDst.root, name2.FemtoDst.root, ... files
  36. //_________________
  37. void FemtoDstAnalyzer(const Char_t *inFile = "st_physics_12150008_raw_4030001.femtoDst.root", const Char_t *outFile = "./star_basic_hists.root") {
  38. std::cout << "Hi! Lets do some physics, Master!" << std::endl;
  39. #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
  40. gSystem->Load("../libStFemtoDst.so");
  41. #endif
  42. StFemtoDstReader* femtoReader = new StFemtoDstReader(inFile);
  43. femtoReader->Init();
  44. // This is a way if you want to spead up IO
  45. std::cout << "Explicit read status for some branches" << std::endl;
  46. femtoReader->SetStatus("*",0);
  47. femtoReader->SetStatus("Event",1);
  48. femtoReader->SetStatus("Track",1);
  49. std::cout << "Status has been set" << std::endl;
  50. std::cout << "Now I know what to read, Master!" << std::endl;
  51. if( !femtoReader->chain() ) {
  52. std::cout << "No chain has been found." << std::endl;
  53. }
  54. Long64_t eventsInTree = femtoReader->tree()->GetEntries();
  55. std::cout << "eventsInTree: " << eventsInTree << std::endl;
  56. Long64_t events2read = femtoReader->chain()->GetEntries();
  57. std::cout << "Number of events to read: " << events2read << std::endl;
  58. // Init output file and histograms
  59. TFile *fo = new TFile(outFile, "recreate");
  60. // Vertex position
  61. TH1D *hVtxX = new TH1D("hVtxX", "hVtxX", 200, -10., 10.);
  62. TH1D *hVtxY = new TH1D("hVtxY", "hVtxY", 200, -10., 10.);
  63. TH1D *hVtxZ = new TH1D("hVtxZ", "hVtxZ", 200, -100., 100.);
  64. TH1D *hVpdZ = new TH1D("hVpdZ", "hVpdZ", 200, -100., 100.);
  65. // Energy from BBCs
  66. TH1D *hBbcEastE = new TH1D("hBbcEastE", "hBbcEastE", 200, 0., 2000.);
  67. TH1D *hBbcWestE = new TH1D("hBbcWestE", "hBbcWestE", 200, 0., 2000.);
  68. // Energy from ZDC-SMDs
  69. TH1D *hZdcEastE = new TH1D("hZdcEastE", "hZdcEastE", 200, 0., 2000.);
  70. TH1D *hZdcWestE = new TH1D("hZdcWestE", "hZdcWestE", 200, 0., 2000.);
  71. // Centrality (16 bins in total covering 0-80%)
  72. TH1D *hCent16 = new TH1D("hCent16", "hCent16", 16, 0., 80.);
  73. // refMults
  74. TH1D *hRefMult = new TH1D("hRefMult", "hRefMult", 1000., 0., 1000.);
  75. TH1D *hRefMult2 = new TH1D("hRefMult2", "hRefMult2", 1000., 0., 1000.);
  76. TH1D *hRefMultCorr = new TH1D("hRefMultCorr", "hRefMultCorr", 1000., 0., 1000.);
  77. TH1D *hRefMultCorrW = new TH1D("hRefMultCorrW", "hRefMultCorrW", 1000., 0., 1000.);
  78. TH1D *hNTofHit = new TH1D("hNTofHit", "hNTofHit", 2000., 0., 2000.);
  79. // Track information
  80. TH1D *hPt = new TH1D("hPt", "hPt", 300, 0., 3.); // pt
  81. TH1D *hPhi = new TH1D("hPhi", "hPhi", 360, -1.*TMath::Pi(), TMath::Pi()); // phi
  82. TH1D *hEta = new TH1D("hEta", "hEta", 240, -1.2, 1.2); // eta
  83. TH1D *hChi2 = new TH1D("hChi2", "hChi2", 100, 0., 10.); // Chi2 of track (track quality)
  84. TH1D *hNhits = new TH1D("hNhits", "hNhits", 100, 0., 100.); // N_hits
  85. TH1D *hNhitsFit = new TH1D("hNhitsFit", "hNhitsFit", 100, 0., 100.); // fitted N_hits
  86. TH1D *hNhitsPoss = new TH1D("hNhitsPoss", "hNhitsPoss", 100, 0., 100.); // maximum possible N_hits
  87. TH1D *hDedx = new TH1D("hDedx", "hDedx", 500, 0., 1e-4); // dE/dx
  88. TH1D *hTofM2 = new TH1D("hTofM2", "hTofM2", 600, -1., 5.); // mass^2 from TOF+TPC
  89. TH1D *hNsigEl = new TH1D("hNsigEl", "hNsigEl", 200, -10., 10.); // possibility of track being electron calculated from dE/dx in sigmas
  90. TH1D *hNsigPi = new TH1D("hNsigPi", "hNsigPi", 200, -10., 10.); // possibility of track being pion calculated from dE/dx in sigmas
  91. TH1D *hNsigKa = new TH1D("hNsigKa", "hNsigKa", 200, -10., 10.); // possibility of track being kaon calculated from dE/dx in sigmas
  92. TH1D *hNsigPr = new TH1D("hNsigPr", "hNsigPr", 200, -10., 10.); // possibility of track being proton calculated from dE/dx in sigmas
  93. TH1D *hDCA = new TH1D("hDCA", "hDCA", 100, 0., 5.); // abs value of DCA (sqrt(dcax^2+dcay^2+dcaz^2))
  94. TH1D *hCharge = new TH1D("hCharge", "hCharge", 4, -2., 2.); // charge
  95. // Loop over events
  96. for(Long64_t iEvent=0; iEvent<events2read; iEvent++) {
  97. std::cout << "Working on event #[" << (iEvent+1)
  98. << "/" << events2read << "]" << std::endl;
  99. Bool_t readEvent = femtoReader->readFemtoEvent(iEvent);
  100. if( !readEvent ) {
  101. std::cout << "Something went wrong, Master! Nothing to analyze..." << std::endl;
  102. break;
  103. }
  104. // Retrieve femtoDst
  105. StFemtoDst *dst = femtoReader->femtoDst();
  106. // Retrieve event information
  107. StFemtoEvent *event = dst->event();
  108. if( !event ) {
  109. std::cout << "Something went wrong, Master! Event is hiding from me..." << std::endl;
  110. break;
  111. }
  112. // Return primary vertex position
  113. TVector3 pVtx = event->primaryVertex();
  114. hVtxX->Fill(pVtx.X());
  115. hVtxY->Fill(pVtx.Y());
  116. hVtxZ->Fill(pVtx.Z());
  117. hVpdZ->Fill(event->vpdVz());
  118. // Reject vertices that are far from the central membrane along the beam
  119. if( TMath::Abs( pVtx.Z() ) > 200. ) continue;
  120. // Get centrality from 16 bins:
  121. /// 15 = 0-5%
  122. /// 14 = 5-10%
  123. /// 13 = 10-15%
  124. /// 12 = 15-20%
  125. /// 11 = 20-25%
  126. /// 10 = 25-30%
  127. /// 9 = 30-35%
  128. /// 8 = 35-40%
  129. /// 7 = 40-45%
  130. /// 6 = 45-50%
  131. /// 5 = 50-55%
  132. /// 4 = 55-60%
  133. /// 3 = 60-65%
  134. /// 2 = 65-70%
  135. /// 1 = 70-75%
  136. /// 0 = 75-80%
  137. hCent16->Fill( (15.-(double)event->cent16())*5.+2.5 ); // (15 - CentBin)*5 + 2.5 - formula for translating centrality bin to centrality
  138. hRefMult->Fill(event->refMult());
  139. hRefMult2->Fill(event->refMult2());
  140. hRefMultCorr->Fill(event->refMultCorr());
  141. hRefMultCorrW->Fill(event->refMultCorrWeight());
  142. hNTofHit->Fill(event->numberOfBTofHit());
  143. // Fill information from BBCs
  144. Double_t BbcE_ene = 0.;
  145. Double_t BbcW_ene = 0.;
  146. for (int i=0; i<16; i++)
  147. {
  148. BbcE_ene += event->bbcAdcEast(i);
  149. BbcW_ene += event->bbcAdcWest(i);
  150. }
  151. hBbcEastE->Fill(BbcE_ene);
  152. hBbcWestE->Fill(BbcW_ene);
  153. // Fill information from ZDC-SMDs
  154. Double_t ZdcE_ene_horizontal = 0.;
  155. Double_t ZdcE_ene_vertical = 0.;
  156. Double_t ZdcW_ene_horizontal = 0.;
  157. Double_t ZdcW_ene_vertical = 0.;
  158. for (int i=0; i<8; i++)
  159. {
  160. ZdcE_ene_horizontal += event->zdcSmdEastHorizontal(i);
  161. ZdcW_ene_horizontal += event->zdcSmdWestHorizontal(i);
  162. }
  163. for (int i=0; i<7; i++)
  164. {
  165. ZdcE_ene_vertical += event->zdcSmdEastVertical(i);
  166. ZdcW_ene_vertical += event->zdcSmdWestVertical(i);
  167. }
  168. hZdcEastE->Fill(ZdcE_ene_horizontal+ZdcE_ene_vertical);
  169. hZdcWestE->Fill(ZdcW_ene_horizontal+ZdcW_ene_vertical);
  170. // Track analysis
  171. Int_t nTracks = dst->numberOfTracks();
  172. // Track loop
  173. for(Int_t iTrk=0; iTrk<nTracks; iTrk++) {
  174. // Retrieve i-th femto track
  175. StFemtoTrack *femtoTrack = dst->track(iTrk);
  176. if (!femtoTrack) continue;
  177. // Must be a primary track
  178. if ( !femtoTrack->isPrimary() ) continue;
  179. TVector3 mom = femtoTrack->gMom();
  180. TVector3 dca = femtoTrack->gDCA(pVtx);
  181. hPt->Fill(mom.Pt());
  182. hPhi->Fill(mom.Phi());
  183. hEta->Fill(mom.Eta());
  184. hChi2->Fill(femtoTrack->chi2());
  185. hNhits->Fill(femtoTrack->nHits());
  186. hNhitsFit->Fill(femtoTrack->nHitsFit());
  187. hNhitsPoss->Fill(femtoTrack->nHitsPoss());
  188. hDedx->Fill(femtoTrack->dEdx());
  189. hTofM2->Fill(femtoTrack->massSqr());
  190. hCharge->Fill(femtoTrack->charge());
  191. hNsigEl->Fill(femtoTrack->nSigmaElectron());
  192. hNsigPi->Fill(femtoTrack->nSigmaPion());
  193. hNsigKa->Fill(femtoTrack->nSigmaKaon());
  194. hNsigPr->Fill(femtoTrack->nSigmaProton());
  195. hDCA->Fill(dca.Mag());
  196. // Simple single-track cut
  197. if( femtoTrack->gMom().Mag() < 0.1 || femtoTrack->gDCA(pVtx).Mag() > 3. ) {
  198. continue;
  199. }
  200. // Check if track has TOF signal
  201. if ( femtoTrack->isTofTrack() ) {
  202. } //if( isTofTrack() )
  203. } //for(Int_t iTrk=0; iTrk<nTracks; iTrk++)
  204. } //for(Long64_t iEvent=0; iEvent<events2read; iEvent++)
  205. femtoReader->Finish();
  206. fo->cd();
  207. // Vertex position
  208. hVtxX->Write();
  209. hVtxY->Write();
  210. hVtxZ->Write();
  211. hVpdZ->Write();
  212. // Energy from BBCs
  213. hBbcEastE->Write();
  214. hBbcWestE->Write();
  215. // Energy from ZDC-SMDs
  216. hZdcEastE->Write();
  217. hZdcWestE->Write();
  218. // Centrality (16 bins in total covering 0-80%)
  219. hCent16->Write();
  220. // refMults
  221. hRefMult->Write();
  222. hRefMult2->Write();
  223. hRefMultCorr->Write();
  224. hRefMultCorrW->Write();
  225. hNTofHit->Write();
  226. // Track information
  227. hPt->Write();
  228. hPhi->Write();
  229. hEta->Write();
  230. hChi2->Write();
  231. hNhits->Write();
  232. hNhitsFit->Write();
  233. hNhitsPoss->Write();
  234. hDedx->Write();
  235. hTofM2->Write();
  236. hNsigEl->Write();
  237. hNsigPi->Write();
  238. hNsigKa->Write();
  239. hNsigPr->Write();
  240. hDCA->Write();
  241. hCharge->Write();
  242. fo->Close();
  243. std::cout << "I'm done with analysis. We'll have a Nobel Prize, Master!"
  244. << std::endl;
  245. }