get_flow_model.C 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // Do not forget to source setPicoDst.sh script
  2. #include <iostream>
  3. #include <TStopwatch.h>
  4. #include <TChain.h>
  5. #include <TFile.h>
  6. #include <TClonesArray.h>
  7. #include <TMath.h>
  8. #include <TVector3.h>
  9. #include <TH2F.h>
  10. #include <TProfile.h>
  11. #include <TProfile2D.h>
  12. #include <TDatabasePDG.h>
  13. #define MAX_TRACKS 10000
  14. #include <Utils.C>
  15. // R__LOAD_LIBRARY(libPicoDst.so)
  16. const std::vector<float> vResTpc = {0.224964, 0.349906, 0.368124, 0.336364, 0.28126, 0.224188, 0.190761, 0.19178};
  17. void get_flow_model(TString inputFileName, TString outputFileName)
  18. {
  19. TStopwatch timer;
  20. timer.Start();
  21. // Configure input information
  22. TChain *chain = new TChain("mctree");
  23. chain->Add(inputFileName.Data());
  24. Float_t bimp;
  25. Float_t phi2;
  26. Float_t phi3;
  27. Float_t ecc2;
  28. Float_t ecc3;
  29. Int_t npart;
  30. Int_t nh;
  31. Float_t momx[MAX_TRACKS]; //[nh]
  32. Float_t momy[MAX_TRACKS]; //[nh]
  33. Float_t momz[MAX_TRACKS]; //[nh]
  34. Float_t ene[MAX_TRACKS]; //[nh]
  35. Int_t hid[MAX_TRACKS]; //[nh]
  36. Int_t pdg[MAX_TRACKS]; //[nh]
  37. Short_t charge[MAX_TRACKS]; //[nh]
  38. // List of branches
  39. TBranch *b_bimp; //!
  40. TBranch *b_phi2; //!
  41. TBranch *b_phi3; //!
  42. TBranch *b_ecc2; //!
  43. TBranch *b_ecc3; //!
  44. TBranch *b_npart; //!
  45. TBranch *b_nh; //!
  46. TBranch *b_momx; //!
  47. TBranch *b_momy; //!
  48. TBranch *b_momz; //!
  49. TBranch *b_ene; //!
  50. TBranch *b_hid; //!
  51. TBranch *b_pdg; //!
  52. TBranch *b_charge; //!
  53. chain->SetBranchAddress("bimp", &bimp, &b_bimp);
  54. chain->SetBranchAddress("phi2", &phi2, &b_phi2);
  55. chain->SetBranchAddress("phi3", &phi3, &b_phi3);
  56. chain->SetBranchAddress("ecc2", &ecc2, &b_ecc2);
  57. chain->SetBranchAddress("ecc3", &ecc3, &b_ecc3);
  58. chain->SetBranchAddress("npart", &npart, &b_npart);
  59. chain->SetBranchAddress("nh", &nh, &b_nh);
  60. chain->SetBranchAddress("momx", momx, &b_momx);
  61. chain->SetBranchAddress("momy", momy, &b_momy);
  62. chain->SetBranchAddress("momz", momz, &b_momz);
  63. chain->SetBranchAddress("ene", ene, &b_ene);
  64. chain->SetBranchAddress("hid", hid, &b_hid);
  65. chain->SetBranchAddress("pdg", pdg, &b_pdg);
  66. chain->SetBranchAddress("charge", charge, &b_charge);
  67. // Configure output information
  68. TFile *fo = new TFile(outputFileName.Data(),"recreate");
  69. TProfile *pResMcTPC = new TProfile("pResTPC","Resolution for TPC EP MODEL", NcentBins, centBinMin, centBinMax);
  70. TProfile2D *pv2mcTPC[Npid];
  71. for (int i=0; i < Npid; i++)
  72. {
  73. pv2mcTPC[i] = new TProfile2D(Form("pv2TPC_pid%i", i), Form("v2(TPC EP) MODEL of %s", pidNames.at(i).Data()), NptBins, ptBinMin, ptBinMax, NcentBins, centBinMin, centBinMax);
  74. }
  75. TH2F *hQx_L_mc = new TH2F("hQx_L","Qx from Left TPC MODEL", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
  76. TH2F *hQy_L_mc = new TH2F("hQy_L","Qy from Left TPC MODEL", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
  77. TH2F *hQx_R_mc = new TH2F("hQx_R","Qx from Right TPC MODEL", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
  78. TH2F *hQy_R_mc = new TH2F("hQy_R","Qy from Right TPC MODEL", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
  79. // Start event loop
  80. int n_entries = chain->GetEntries();
  81. for (int iEv=0; iEv<n_entries; iEv++)
  82. {
  83. if (iEv%1000==0) std::cout << "Event [" << iEv << "/" << n_entries << "]" << std::endl;
  84. chain->GetEntry(iEv);
  85. // Get centrality
  86. float cent = CentB(bimp);
  87. if (cent == -1) continue;
  88. Int_t mc_num_particles = nh;
  89. // Read MC tracks
  90. float Qx_L_mc = 0., Qy_L_mc = 0., W_L_mc = 0.;
  91. float Qx_R_mc = 0., Qy_R_mc = 0., W_R_mc = 0.;
  92. int Mult_L_mc = 0, Mult_R_mc = 0;
  93. float PsiEP_L_mc = 0., PsiEP_R_mc = 0.;
  94. for (int iTr=0; iTr<mc_num_particles; iTr++)
  95. {
  96. TVector3 vect(momx[iTr], momy[iTr], momz[iTr]);
  97. float pt = vect.Pt();
  98. float eta = vect.Eta();
  99. float phi = vect.Phi();
  100. // Main track cuts
  101. if (pt < pt_min_cut) continue;
  102. if (pt > pt_max_cut) continue;
  103. if (abs(eta) > eta_cut) continue;
  104. if (abs(eta) < eta_gap) continue;
  105. // PID-related cut (or to cut out neutral particles)
  106. auto particle = (TParticlePDG*) TDatabasePDG::Instance()->GetParticle(pdg[iTr]);
  107. if (!particle) continue;
  108. float charge = 1./3.*particle->Charge();
  109. if (charge == 0) continue;
  110. // TPC Left EP
  111. if (eta < 0)
  112. {
  113. Qx_L_mc += pt * cos(2.* phi);
  114. Qy_L_mc += pt * sin(2.* phi);
  115. W_L_mc += pt;
  116. Mult_L_mc++;
  117. }
  118. // TPC Right EP
  119. if (eta > 0)
  120. {
  121. Qx_R_mc += pt * cos(2.* phi);
  122. Qy_R_mc += pt * sin(2.* phi);
  123. W_R_mc += pt;
  124. Mult_R_mc++;
  125. }
  126. } // end of mc track loop
  127. if (Mult_L_mc > mult_EP_cut && Mult_R_mc > mult_EP_cut)
  128. {
  129. Qx_L_mc /= W_L_mc;
  130. Qy_L_mc /= W_L_mc;
  131. Qx_R_mc /= W_R_mc;
  132. Qy_R_mc /= W_R_mc;
  133. hQx_L_mc->Fill(cent, Qx_L_mc);
  134. hQy_L_mc->Fill(cent, Qy_L_mc);
  135. hQx_R_mc->Fill(cent, Qx_R_mc);
  136. hQy_R_mc->Fill(cent, Qy_R_mc);
  137. PsiEP_L_mc = 0.5 * atan2(Qy_L_mc, Qx_L_mc);
  138. PsiEP_R_mc = 0.5 * atan2(Qy_R_mc, Qx_R_mc);
  139. }
  140. else
  141. {
  142. PsiEP_L_mc = -999.;
  143. PsiEP_R_mc = -999.;
  144. }
  145. float res_mc = cos(2. * (PsiEP_R_mc - PsiEP_L_mc) );
  146. if (PsiEP_L_mc != -999. && PsiEP_R_mc != -999.)
  147. {
  148. pResMcTPC->Fill(cent, res_mc);
  149. }
  150. ////////////////////////////////////////////////////////////////////
  151. //
  152. // FLOW CALCULATIONS
  153. //
  154. ////////////////////////////////////////////////////////////////////
  155. float res_v2TPC_mc = vResTpc.at(GetCentBin(cent));
  156. // Read MC tracks
  157. for (int iTr=0; iTr<mc_num_particles; iTr++)
  158. {
  159. TVector3 vect(momx[iTr], momy[iTr], momz[iTr]);
  160. float pt = vect.Pt();
  161. float eta = vect.Eta();
  162. float phi = vect.Phi();
  163. // Main track cuts
  164. if (pt < pt_min_cut) continue;
  165. if (pt > pt_max_cut) continue;
  166. if (abs(eta) > eta_cut) continue;
  167. if (abs(eta) < eta_gap) continue;
  168. // EP-related cut
  169. if (PsiEP_L_mc == -999.) continue;
  170. if (PsiEP_R_mc == -999.) continue;
  171. // PID-related cut
  172. auto particle = (TParticlePDG*) TDatabasePDG::Instance()->GetParticle(pdg[iTr]);
  173. if (!particle) continue;
  174. float v2TPC = 0.;
  175. if (eta < 0)
  176. {
  177. v2TPC = cos( 2. * (phi - PsiEP_R_mc) );
  178. }
  179. if (eta > 0)
  180. {
  181. v2TPC = cos( 2. * (phi - PsiEP_L_mc) );
  182. }
  183. v2TPC /= res_v2TPC_mc;
  184. int pidID = -1;
  185. float charge = 1./3.*particle->Charge();
  186. for (int ipid=0; ipid < Npid; ipid++)
  187. {
  188. if (abs(pdgCodes.at(ipid)) == 999) continue;
  189. if (pdgCodes.at(ipid) == pdg[iTr]) pidID = ipid;
  190. }
  191. if (charge > 0)
  192. pv2mcTPC[0]->Fill(pt, cent, v2TPC);
  193. if (charge < 0)
  194. pv2mcTPC[4]->Fill(pt, cent, v2TPC);
  195. if (pidID == -1) continue;
  196. pv2mcTPC[pidID]->Fill(pt, cent, v2TPC);
  197. } // end mc tracks loop
  198. } // end event loop
  199. //Writing output
  200. fo->cd();
  201. pResMcTPC->Write();
  202. for (int ipid=0; ipid < Npid; ipid++)
  203. {
  204. pv2mcTPC[ipid]->Write();
  205. }
  206. hQx_L_mc->Write();
  207. hQy_L_mc->Write();
  208. hQx_R_mc->Write();
  209. hQy_R_mc->Write();
  210. fo->Close();
  211. timer.Stop();
  212. timer.Print();
  213. }