get_multiplicity.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #include <TMath.h>
  2. #include <TSystem.h>
  3. #include <TFile.h>
  4. #include <TTree.h>
  5. #include <TChain.h>
  6. #include <TString.h>
  7. #include "TROOT.h"
  8. #include <FairMCEventHeader.h>
  9. #include <MpdEvent.h>
  10. #include <TClonesArray.h>
  11. #include <MpdTrack.h>
  12. #include <FairMCTrack.h>
  13. #include <TH1.h>
  14. #include <TF1.h>
  15. #include <iostream>
  16. //#define WEIGHT_B
  17. using namespace std;
  18. void get_multiplicity(TString inFileName, TString outFileName, TString dcaFileName)
  19. {
  20. const float pt_bins[] = {0., 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3.};
  21. const int n_pt_bin = 12;
  22. const float eta_bins[] = {-1.5, -1.2, -1., -0.8, -0.6, -0.4, -0.2, 0., 0.2, 0.4, 0.6, 0.8, 1., 1.2, 1.5};
  23. const int n_eta_bin = 14;
  24. const Int_t n_proj = 3;
  25. const Int_t n_hit_cut = 32;
  26. TH1F *h_multiplicity = new TH1F("h_multiplicity", "multiplicity in TPC after cuts;N_{tracks} in TPC;N_{events};", 1600, 0., 1600.);
  27. TH1F *h_mult_compare = new TH1F("h_mult_compare", "Normalized multiplicity in TPC after cuts;N_{tracks} in TPC;N_{events};", 1600, 0., 1600.);
  28. TH1F *h_mult_old = new TH1F("h_mult_old", "multiplicity in TPC before cuts;N_{tracks} in TPC;N_{events};", 1600, 0., 1600.);
  29. TChain *dstTree = new TChain("cbmsim");
  30. dstTree->Add(inFileName.Data());
  31. TFile *outFile = new TFile(outFileName.Data(), "RECREATE");
  32. //TFile *dcaFile = new TFile("/lustre/nyx/hades/user/parfenov/dca_out_file_TDR.root","READ");
  33. TFile *dcaFile = new TFile(dcaFileName.Data(), "READ");
  34. MpdEvent *MPDEvent = nullptr;
  35. dstTree->SetBranchAddress("MPDEvent.", &MPDEvent);
  36. TClonesArray *MpdGlobalTracks = 0;
  37. TClonesArray *MCTracks = 0;
  38. dstTree->SetBranchAddress("MCTrack", &MCTracks);
  39. #ifdef WEIGHT_B
  40. FairMCEventHeader *MCHeader = 0;
  41. dstTree->SetBranchAddress("MCEventHeader.", &MCHeader);
  42. #endif
  43. //TF1* f_dca[n_proj][n_pt_bin][n_eta_bin];
  44. TF1 *f_pt_fit[n_proj][n_eta_bin];
  45. for (Int_t i_proj = 0; i_proj < n_proj; i_proj++)
  46. {
  47. //for (Int_t i_pt=0;i_pt<n_pt_bin;i_pt++){
  48. for (Int_t i_eta = 0; i_eta < n_eta_bin; i_eta++)
  49. {
  50. //f_dca[i_proj][i_pt][i_eta] = (TF1*) dcaFile->Get(Form("dca_fit[%i][%i][%i]",i_proj,i_pt,i_eta));
  51. f_pt_fit[i_proj][i_eta] = (TF1 *)dcaFile->Get(Form("sigma_pt_fit%i%i", i_proj, i_eta));
  52. }
  53. //}
  54. }
  55. Int_t n_events = dstTree->GetEntries();
  56. //Int_t n_events = 50;
  57. Int_t pt_bin;
  58. Int_t eta_bin;
  59. Double_t wB,B,dB;
  60. for (int event = 0; event < n_events; ++event)
  61. {
  62. cout << "EVENT N " << event << endl;
  63. dstTree->GetEntry(event);
  64. MpdGlobalTracks = MPDEvent->GetGlobalTracks();
  65. #ifdef WEIGHT_B
  66. B = MCHeader->GetB();
  67. dB = 0.25;
  68. wB = 2*TMath::Pi()*B*dB;
  69. #else
  70. B = 0.; dB = 0.; wB = 1.;
  71. #endif
  72. h_mult_old->Fill(MpdGlobalTracks->GetEntriesFast(),wB);
  73. Long_t n_tracks_mpd = 0;
  74. Long_t n_tracks_for_FlowQA = 0;
  75. for (Int_t track = 0; track < MpdGlobalTracks->GetEntriesFast(); track++)
  76. {
  77. MpdTrack *mpdtrack = (MpdTrack *)MpdGlobalTracks->UncheckedAt(track);
  78. pt_bin = -1;
  79. eta_bin = -1;
  80. if (mpdtrack->GetNofHits() < n_hit_cut)
  81. continue;
  82. for (Int_t i_pt = 0; i_pt < n_pt_bin; i_pt++)
  83. if (TMath::Abs(mpdtrack->GetPt()) >= pt_bins[i_pt] && TMath::Abs(mpdtrack->GetPt()) <= pt_bins[i_pt + 1])
  84. pt_bin = i_pt;
  85. for (Int_t i_eta = 0; i_eta < n_eta_bin; i_eta++)
  86. if (mpdtrack->GetEta() > eta_bins[i_eta] && mpdtrack->GetEta() <= eta_bins[i_eta + 1])
  87. eta_bin = i_eta;
  88. if (pt_bin == -1)
  89. continue;
  90. if (eta_bin == -1)
  91. continue;
  92. Double_t Pt = TMath::Abs(mpdtrack->GetPt());
  93. TF1 sigma_fit_X = *f_pt_fit[0][eta_bin];
  94. TF1 sigma_fit_Y = *f_pt_fit[1][eta_bin];
  95. TF1 sigma_fit_Z = *f_pt_fit[2][eta_bin];
  96. if (mpdtrack->GetDCAX()*mpdtrack->GetDCAX()+
  97. mpdtrack->GetDCAY()*mpdtrack->GetDCAY()+
  98. mpdtrack->GetDCAZ()*mpdtrack->GetDCAZ() < 0.04 &&
  99. TMath::Abs(mpdtrack->GetPt()) >= 0.2 &&
  100. TMath::Abs(mpdtrack->GetPt()) <= 3 &&
  101. TMath::Abs(mpdtrack->GetEta()) <= 1.5)
  102. n_tracks_for_FlowQA++;
  103. if (TMath::Abs(mpdtrack->GetDCAX()) >= sigma_fit_X(Pt) * 2)
  104. continue;
  105. if (TMath::Abs(mpdtrack->GetDCAY()) >= sigma_fit_Y(Pt) * 2)
  106. continue;
  107. if (TMath::Abs(mpdtrack->GetDCAZ()) >= sigma_fit_Z(Pt) * 2)
  108. continue;
  109. if (TMath::Abs(mpdtrack->GetEta()) > 1.5)
  110. continue;
  111. if (TMath::Abs(mpdtrack->GetPt()) < 0 && TMath::Abs(mpdtrack->GetPt()) > 3)
  112. continue;
  113. n_tracks_mpd++;
  114. }
  115. if (n_tracks_mpd > 0)
  116. {
  117. h_multiplicity->Fill(n_tracks_mpd,wB);
  118. h_mult_compare->Fill((Float_t)(n_tracks_mpd * 1.5),wB);
  119. h_mult_old ->Fill(n_tracks_for_FlowQA,wB);
  120. }
  121. }
  122. outFile->cd();
  123. h_multiplicity->Write();
  124. //h_mult_compare->Write();
  125. h_mult_old->Write();
  126. outFile->Close();
  127. }
  128. int main(int argc, char **argv)
  129. {
  130. TString iFileName, oFileName, dcaFileName;
  131. if (argc < 3)
  132. {
  133. std::cerr << "./get_multiplicity -i inputfile -o outputfile -dca dcafile" << std::endl;
  134. return 1;
  135. }
  136. for (int i = 1; i < argc; i++)
  137. {
  138. if (std::string(argv[i]) != "-i" &&
  139. std::string(argv[i]) != "-o" &&
  140. std::string(argv[i]) != "-dca")
  141. {
  142. std::cerr << "\n[ERROR]: Unknown parameter " << i << ": " << argv[i] << std::endl;
  143. return 1;
  144. }
  145. else
  146. {
  147. if (std::string(argv[i]) == "-i" && i != argc - 1)
  148. {
  149. iFileName = argv[++i];
  150. continue;
  151. }
  152. if (std::string(argv[i]) == "-i" && i == argc - 1)
  153. {
  154. std::cerr << "\n[ERROR]: Input file name was not specified " << std::endl;
  155. return 1;
  156. }
  157. if (std::string(argv[i]) == "-o" && i != argc - 1)
  158. {
  159. oFileName = argv[++i];
  160. continue;
  161. }
  162. if (std::string(argv[i]) == "-o" && i == argc - 1)
  163. {
  164. std::cerr << "\n[ERROR]: Output file name was not specified " << std::endl;
  165. return 1;
  166. }
  167. if (std::string(argv[i]) == "-dca" && i != argc - 1)
  168. {
  169. dcaFileName = argv[++i];
  170. continue;
  171. }
  172. if (std::string(argv[i]) == "-dca" && i == argc - 1)
  173. {
  174. std::cerr << "\n[ERROR]: DCA file name was not specified " << std::endl;
  175. return 1;
  176. }
  177. }
  178. }
  179. if (iFileName == "" || oFileName == "" || dcaFileName == "")
  180. {
  181. std::cerr << "\n[ERROR]: One of the need file is absent " << std::endl;
  182. std::cerr << "./get_multiplicity -i inputfile -o outputfile -dca dcafile" << std::endl;
  183. return 1;
  184. }
  185. get_multiplicity(iFileName, oFileName, dcaFileName);
  186. return 0;
  187. }