FemtoDstAnalyzer_BBC_Gain.C 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. #include <vector>
  16. #include <map>
  17. // ROOT headers
  18. #include "TROOT.h"
  19. #include "TFile.h"
  20. #include "TChain.h"
  21. #include "TVector2.h"
  22. #include "TVector3.h"
  23. #include "TTree.h"
  24. #include "TSystem.h"
  25. #include "TH1.h"
  26. #include "TH2.h"
  27. #include "TMath.h"
  28. #include "TProfile2D.h"
  29. #include "TStopwatch.h"
  30. #include "TRandom3.h"
  31. // FemtoDst headers
  32. #include "StFemtoDstReader.h"
  33. #include "StFemtoDst.h"
  34. #include "StFemtoEvent.h"
  35. #include "StFemtoTrack.h"
  36. // Load libraries (for ROOT_VERSTION_CODE >= 393215)
  37. #if ROOT_VERSION_CODE >= ROOT_VERSION(6, 0, 0)
  38. R__LOAD_LIBRARY(/mnt/pool/rhic/4/parfenovpeter/STAR/build/libStFemtoDst.so)
  39. #endif
  40. #include "Constants.h"
  41. // inFile - is a name of name.FemtoDst.root file or a name
  42. // of a name.lis(t) files, that contains a list of
  43. // name1.FemtoDst.root, name2.FemtoDst.root, ... files
  44. //Used functions (see them below)
  45. Bool_t isGoodEvent(StFemtoEvent *const &event);
  46. Int_t GetVzBin(Double_t vtxZ);
  47. //_________________
  48. void FemtoDstAnalyzer_BBC_Gain(const Char_t *inFile = "st_physics_12150008_raw_4030001.femtoDst.root",
  49. const Char_t *outFile = "./oReCenteringTest.root")
  50. {
  51. std::cout << "Hi! Lets do some physics, Master!" << std::endl;
  52. TStopwatch timer;
  53. timer.Start();
  54. #if ROOT_VERSION_CODE < ROOT_VERSION(6, 0, 0)
  55. gSystem->Load("../libStFemtoDst.so");
  56. #endif
  57. StFemtoDstReader *femtoReader = new StFemtoDstReader(inFile);
  58. femtoReader->Init();
  59. // This is a way if you want to spead up IO
  60. std::cout << "Explicit read status for some branches" << std::endl;
  61. femtoReader->SetStatus("*", 0);
  62. femtoReader->SetStatus("Event", 1);
  63. femtoReader->SetStatus("Track", 1);
  64. std::cout << "Status has been set" << std::endl;
  65. std::cout << "Now I know what to read, Master!" << std::endl;
  66. if (!femtoReader->chain())
  67. {
  68. std::cout << "No chain has been found." << std::endl;
  69. }
  70. Long64_t eventsInTree = femtoReader->tree()->GetEntries();
  71. std::cout << "eventsInTree: " << eventsInTree << std::endl;
  72. Long64_t events2read = femtoReader->chain()->GetEntries();
  73. std::cout << "Number of events to read: " << events2read << std::endl;
  74. //Manage ReCentering output
  75. TProfile2D *BBCgain_East[fArraySize];
  76. TProfile2D *BBCgain_West[fArraySize];
  77. for (int iVtx=0; iVtx<fArraySize; iVtx++)
  78. {
  79. BBCgain_East[iVtx] = new TProfile2D(Form("p_gainBBC_East_Vtx%i",iVtx),Form("p_gainBBC_East_Vtx%i",iVtx),fNBins,runId_min-0.5,runId_max+0.5,16,-0.5,15.5);
  80. BBCgain_West[iVtx] = new TProfile2D(Form("p_gainBBC_West_Vtx%i",iVtx),Form("p_gainBBC_West_Vtx%i",iVtx),fNBins,runId_min-0.5,runId_max+0.5,16,-0.5,15.5);
  81. }
  82. Int_t VtxSign;
  83. Long64_t goodEventCounter = 0;
  84. // Loop over events
  85. for (Long64_t iEvent = 0; iEvent < events2read; iEvent++)
  86. {
  87. if ((iEvent+1) % 1000 == 0){
  88. std::cout << "Working on event #[" << (iEvent + 1)
  89. << "/" << events2read << "]" << std::endl;
  90. }
  91. Bool_t readEvent = femtoReader->readFemtoEvent(iEvent);
  92. if (!readEvent)
  93. {
  94. std::cout << "Something went wrong, Master! Nothing to analyze..." << std::endl;
  95. break;
  96. }
  97. // Retrieve femtoDst
  98. StFemtoDst *dst = femtoReader->femtoDst();
  99. // Retrieve event information
  100. StFemtoEvent *event = dst->event();
  101. if (!event)
  102. {
  103. std::cout << "Something went wrong, Master! Event is hiding from me..." << std::endl;
  104. break;
  105. }
  106. // Event selection
  107. if ( !isGoodEvent(event) ) continue;
  108. goodEventCounter++;
  109. TVector3 pVtx = event->primaryVertex();
  110. // Vertex sign
  111. VtxSign = GetVzBin(pVtx.Z());
  112. if (VtxSign == -1) continue;
  113. for (int iModule=0; iModule<24; iModule++)
  114. {
  115. BBCgain_East[VtxSign]->Fill(event->runId(),iModule,event->bbcAdcEast(iModule));
  116. BBCgain_West[VtxSign]->Fill(event->runId(),iModule,event->bbcAdcWest(iModule));
  117. }
  118. } //for(Long64_t iEvent=0; iEvent<events2read; iEvent++)
  119. femtoReader->Finish();
  120. TFile *output = new TFile(outFile,"recreate");
  121. for (int iVtx=0; iVtx<fArraySize; iVtx++)
  122. {
  123. BBCgain_East[iVtx]->Write();
  124. BBCgain_West[iVtx]->Write();
  125. }
  126. output->Close();
  127. std::cout << "I'm done with analysis. We'll have a Nobel Prize, Master!"
  128. << std::endl;
  129. std::cout << "Good events: " << goodEventCounter << std::endl;
  130. timer.Stop();
  131. timer.Print();
  132. }
  133. Bool_t isGoodEvent(StFemtoEvent *const &event)
  134. {
  135. if (!event) return false;
  136. if (event == nullptr) return false;
  137. if (event->primaryVertex().Perp() > cutVtxR) return false;
  138. if (TMath::Abs(event->primaryVertex().Z()) > cutVtxZEnergy.at(energy)) return false;
  139. if ((energy == 200.) && TMath::Abs(event->primaryVertex().Z() - event->vpdVz()) > cutVpdVz) return false;
  140. return true;
  141. }
  142. Int_t GetVzBin(Double_t vtxZ)
  143. {
  144. for (Int_t i=0; i<fArraySize;i++)
  145. {
  146. if (vtxZ >= VtxBins[i] && vtxZ < VtxBins[i+1]) return i;
  147. }
  148. return -1;
  149. }