get_flow_pico.C 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 <TH2F.h>
  9. #include <TProfile.h>
  10. #include <TProfile2D.h>
  11. #include <TDatabasePDG.h>
  12. #include <PicoDstMCEvent.h>
  13. #include <PicoDstRecoEvent.h>
  14. #include <PicoDstMCTrack.h>
  15. #include <PicoDstRecoTrack.h>
  16. #include <PicoDstFHCal.h>
  17. #include <Utils.C>
  18. // R__LOAD_LIBRARY(libPicoDst.so)
  19. const std::vector<float> vResMcTpc = {0.226827, 0.347749, 0.369009, 0.336583, 0.281697, 0.224447, 0.18955, 0.186935};
  20. const std::vector<float> vResRecoTpc = {0.211611, 0.329277, 0.350632, 0.319347, 0.269741, 0.21128, 0.181021, 0.176676};
  21. void get_flow_pico(TString inputFileName, TString outputFileName)
  22. {
  23. TStopwatch timer;
  24. timer.Start();
  25. // Configure input information
  26. TChain *chain = new TChain("picodst");
  27. chain->Add(inputFileName.Data());
  28. PicoDstMCEvent *mcEvent = nullptr;
  29. PicoDstRecoEvent *recoEvent = nullptr;
  30. TClonesArray *recoTracks = nullptr;
  31. TClonesArray *mcTracks = nullptr;
  32. TClonesArray *fhcalmodules = nullptr;
  33. chain->SetBranchAddress("mcevent.", &mcEvent);
  34. chain->SetBranchAddress("recoevent.", &recoEvent);
  35. chain->SetBranchAddress("mctracks",&mcTracks);
  36. chain->SetBranchAddress("recotracks",&recoTracks);
  37. chain->SetBranchAddress("FHCalModules",&fhcalmodules);
  38. // Configure output information
  39. TFile *fo = new TFile(outputFileName.Data(),"recreate");
  40. TProfile *pResMcTPC = new TProfile("pResMcTPC","Resolution for TPC EP MC", NcentBins, centBinMin, centBinMax);
  41. TProfile *pResRecoTPC = new TProfile("pResRecoTPC","Resolution for TPC EP RECO", NcentBins, centBinMin, centBinMax);
  42. TProfile2D *pv2mcTPC[Npid];
  43. TProfile2D *pv2recoTPC[Npid];
  44. for (int i=0; i < Npid; i++)
  45. {
  46. pv2mcTPC[i] = new TProfile2D(Form("pv2mcTPC_pid%i", i), Form("v2(TPC EP) MC of %s", pidNames.at(i).Data()), NptBins, ptBinMin, ptBinMax, NcentBins, centBinMin, centBinMax);
  47. pv2recoTPC[i] = new TProfile2D(Form("pv2recoTPC_pid%i", i), Form("v2(TPC EP) RECO of %s", pidNames.at(i).Data()), NptBins, ptBinMin, ptBinMax, NcentBins, centBinMin, centBinMax);
  48. }
  49. TH2F *hQx_L_mc = new TH2F("hQx_L_mc","Qx from Left TPC MC", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
  50. TH2F *hQy_L_mc = new TH2F("hQy_L_mc","Qy from Left TPC MC", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
  51. TH2F *hQx_R_mc = new TH2F("hQx_R_mc","Qx from Right TPC MC", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
  52. TH2F *hQy_R_mc = new TH2F("hQy_R_mc","Qy from Right TPC MC", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
  53. TH2F *hQx_L_reco = new TH2F("hQx_L_reco","Qx from Left TPC RECO", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
  54. TH2F *hQy_L_reco = new TH2F("hQy_L_reco","Qy from Left TPC RECO", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
  55. TH2F *hQx_R_reco = new TH2F("hQx_R_reco","Qx from Right TPC RECO", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
  56. TH2F *hQy_R_reco = new TH2F("hQy_R_reco","Qy from Right TPC RECO", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
  57. // Start event loop
  58. int n_entries = chain->GetEntries();
  59. for (int iEv=0; iEv<n_entries; iEv++)
  60. {
  61. if (iEv%1000==0) std::cout << "Event [" << iEv << "/" << n_entries << "]" << std::endl;
  62. chain->GetEntry(iEv);
  63. // Get centrality
  64. float cent = CentB(mcEvent->GetB());
  65. if (cent == -1) continue;
  66. Int_t mc_num_particles = mcTracks->GetEntriesFast();
  67. // Read Reco event
  68. Int_t reco_mult = recoTracks->GetEntriesFast();
  69. // Read MC tracks
  70. float Qx_L_mc = 0., Qy_L_mc = 0., W_L_mc = 0.;
  71. float Qx_R_mc = 0., Qy_R_mc = 0., W_R_mc = 0.;
  72. int Mult_L_mc = 0, Mult_R_mc = 0;
  73. float PsiEP_L_mc = 0., PsiEP_R_mc = 0.;
  74. for (int iTr=0; iTr<mc_num_particles; iTr++)
  75. {
  76. auto mcTrack = (PicoDstMCTrack*) mcTracks->UncheckedAt(iTr);
  77. if (!mcTrack) continue;
  78. float pt = mcTrack->GetPt();
  79. float eta = mcTrack->GetEta();
  80. float phi = mcTrack->GetPhi();
  81. // Main track cuts
  82. if (pt < pt_min_cut) continue;
  83. if (pt > pt_max_cut) continue;
  84. if (abs(eta) > eta_cut) continue;
  85. if (abs(eta) < eta_gap) continue;
  86. // PID-related cut (or to cut out neutral particles)
  87. auto particle = (TParticlePDG*) TDatabasePDG::Instance()->GetParticle(mcTrack->GetPdg());
  88. if (!particle) continue;
  89. float charge = 1./3.*particle->Charge();
  90. if (charge == 0) continue;
  91. // Mc-specific track cuts
  92. if (mcTrack->GetMotherId() != motherId_cut) continue;
  93. // TPC Left EP
  94. if (eta < 0)
  95. {
  96. Qx_L_mc += pt * cos(2.* phi);
  97. Qy_L_mc += pt * sin(2.* phi);
  98. W_L_mc += pt;
  99. Mult_L_mc++;
  100. }
  101. // TPC Right EP
  102. if (eta > 0)
  103. {
  104. Qx_R_mc += pt * cos(2.* phi);
  105. Qy_R_mc += pt * sin(2.* phi);
  106. W_R_mc += pt;
  107. Mult_R_mc++;
  108. }
  109. } // end of mc track loop
  110. if (Mult_L_mc > mult_EP_cut && Mult_R_mc > mult_EP_cut)
  111. {
  112. Qx_L_mc /= W_L_mc;
  113. Qy_L_mc /= W_L_mc;
  114. Qx_R_mc /= W_R_mc;
  115. Qy_R_mc /= W_R_mc;
  116. hQx_L_mc->Fill(cent, Qx_L_mc);
  117. hQy_L_mc->Fill(cent, Qy_L_mc);
  118. hQx_R_mc->Fill(cent, Qx_R_mc);
  119. hQy_R_mc->Fill(cent, Qy_R_mc);
  120. PsiEP_L_mc = 0.5 * atan2(Qy_L_mc, Qx_L_mc);
  121. PsiEP_R_mc = 0.5 * atan2(Qy_R_mc, Qx_R_mc);
  122. }
  123. else
  124. {
  125. PsiEP_L_mc = -999.;
  126. PsiEP_R_mc = -999.;
  127. }
  128. // Read Reco tracks
  129. float Qx_L_reco = 0., Qy_L_reco = 0., W_L_reco = 0.;
  130. float Qx_R_reco = 0., Qy_R_reco = 0., W_R_reco = 0.;
  131. int Mult_L_reco = 0, Mult_R_reco = 0;
  132. float PsiEP_L_reco = 0., PsiEP_R_reco = 0.;
  133. for (int iTr=0; iTr<reco_mult; iTr++)
  134. {
  135. auto recoTrack = (PicoDstRecoTrack*) recoTracks->UncheckedAt(iTr);
  136. if (!recoTrack) continue;
  137. auto mcTrack = (PicoDstMCTrack*) mcTracks->UncheckedAt(recoTrack->GetMcId());
  138. if (!mcTrack) continue;
  139. float pt = recoTrack->GetPt();
  140. float eta = recoTrack->GetEta();
  141. float phi = recoTrack->GetPhi();
  142. // Main track cuts
  143. if (pt < pt_min_cut) continue;
  144. if (pt > pt_max_cut) continue;
  145. if (abs(eta) > eta_cut) continue;
  146. if (abs(eta) < eta_gap) continue;
  147. // Reco-specific track cuts
  148. if (recoTrack->GetNhits() < Nhits_cut) continue;
  149. //if (abs(recoTrack->GetDCAx()) > dca_cut) continue;
  150. //if (abs(recoTrack->GetDCAy()) > dca_cut) continue;
  151. //if (abs(recoTrack->GetDCAz()) > dca_cut) continue;
  152. if (mcTrack->GetMotherId() != motherId_cut) continue;
  153. // TPC Left EP
  154. if (eta < 0)
  155. {
  156. Qx_L_reco += pt * cos(2.* phi);
  157. Qy_L_reco += pt * sin(2.* phi);
  158. W_L_reco += pt;
  159. Mult_L_reco++;
  160. }
  161. // TPC Right EP
  162. if (eta > 0)
  163. {
  164. Qx_R_reco += pt * cos(2.* phi);
  165. Qy_R_reco += pt * sin(2.* phi);
  166. W_R_reco += pt;
  167. Mult_R_reco++;
  168. }
  169. } // end of reco track loop
  170. if (Mult_L_reco > mult_EP_cut && Mult_R_reco > mult_EP_cut)
  171. {
  172. Qx_L_reco /= W_L_reco;
  173. Qy_L_reco /= W_L_reco;
  174. Qx_R_reco /= W_R_reco;
  175. Qy_R_reco /= W_R_reco;
  176. hQx_L_reco->Fill(cent, Qx_L_reco);
  177. hQy_L_reco->Fill(cent, Qy_L_reco);
  178. hQx_R_reco->Fill(cent, Qx_R_reco);
  179. hQy_R_reco->Fill(cent, Qy_R_reco);
  180. PsiEP_L_reco = 0.5 * atan2(Qy_L_reco, Qx_L_reco);
  181. PsiEP_R_reco = 0.5 * atan2(Qy_R_reco, Qx_R_reco);
  182. }
  183. else
  184. {
  185. PsiEP_L_reco = -999.;
  186. PsiEP_R_reco = -999.;
  187. }
  188. float res_mc = cos(2. * (PsiEP_R_mc - PsiEP_L_mc) );
  189. float res_reco = cos(2. * (PsiEP_R_reco - PsiEP_L_reco) );
  190. if (PsiEP_L_mc != -999. && PsiEP_R_mc != -999.)
  191. {
  192. pResMcTPC->Fill(cent, res_mc);
  193. }
  194. if (PsiEP_L_reco != -999. && PsiEP_R_reco != -999.)
  195. {
  196. pResRecoTPC->Fill(cent, res_reco);
  197. }
  198. ////////////////////////////////////////////////////////////////////
  199. //
  200. // FLOW CALCULATIONS
  201. //
  202. ////////////////////////////////////////////////////////////////////
  203. float res_v2TPC_mc = vResMcTpc.at(GetCentBin(cent));
  204. float res_v2TPC_reco = vResRecoTpc.at(GetCentBin(cent));
  205. // Read MC tracks
  206. for (int iTr=0; iTr<mc_num_particles; iTr++)
  207. {
  208. auto mcTrack = (PicoDstMCTrack*) mcTracks->UncheckedAt(iTr);
  209. if (!mcTrack) continue;
  210. float pt = mcTrack->GetPt();
  211. float eta = mcTrack->GetEta();
  212. float phi = mcTrack->GetPhi();
  213. // Main track cuts
  214. if (pt < pt_min_cut) continue;
  215. if (pt > pt_max_cut) continue;
  216. if (abs(eta) > eta_cut) continue;
  217. if (abs(eta) < eta_gap) continue;
  218. // Mc-specific track cuts
  219. if (mcTrack->GetMotherId() != motherId_cut) continue;
  220. // EP-related cut
  221. if (PsiEP_L_mc == -999.) continue;
  222. if (PsiEP_R_mc == -999.) continue;
  223. // PID-related cut
  224. auto particle = (TParticlePDG*) TDatabasePDG::Instance()->GetParticle(mcTrack->GetPdg());
  225. if (!particle) continue;
  226. float v2TPC = 0.;
  227. if (eta < 0)
  228. {
  229. v2TPC = cos( 2. * (phi - PsiEP_R_mc) );
  230. }
  231. if (eta > 0)
  232. {
  233. v2TPC = cos( 2. * (phi - PsiEP_L_mc) );
  234. }
  235. v2TPC /= res_v2TPC_mc;
  236. int pidID = -1;
  237. float charge = 1./3.*particle->Charge();
  238. for (int ipid=0; ipid < Npid; ipid++)
  239. {
  240. if (abs(pdgCodes.at(ipid)) == 999) continue;
  241. if (pdgCodes.at(ipid) == mcTrack->GetPdg()) pidID = ipid;
  242. }
  243. if (charge > 0)
  244. pv2mcTPC[0]->Fill(pt, cent, v2TPC);
  245. if (charge < 0)
  246. pv2mcTPC[4]->Fill(pt, cent, v2TPC);
  247. if (pidID == -1) continue;
  248. pv2mcTPC[pidID]->Fill(pt, cent, v2TPC);
  249. } // end mc tracks loop
  250. // Read Reco tracks
  251. for (int iTr=0; iTr<reco_mult; iTr++)
  252. {
  253. auto recoTrack = (PicoDstRecoTrack*) recoTracks->UncheckedAt(iTr);
  254. if (!recoTrack) continue;
  255. auto mcTrack = (PicoDstMCTrack*) mcTracks->UncheckedAt(recoTrack->GetMcId());
  256. if (!mcTrack) continue;
  257. float pt = recoTrack->GetPt();
  258. float eta = recoTrack->GetEta();
  259. float phi = recoTrack->GetPhi();
  260. // Main track cuts
  261. if (pt < pt_min_cut) continue;
  262. if (pt > pt_max_cut) continue;
  263. if (abs(eta) > eta_cut) continue;
  264. if (abs(eta) < eta_gap) continue;
  265. // Reco-specific track cuts
  266. if (recoTrack->GetNhits() < Nhits_cut) continue;
  267. //if (abs(recoTrack->GetDCAx()) > dca_cut) continue;
  268. //if (abs(recoTrack->GetDCAy()) > dca_cut) continue;
  269. //if (abs(recoTrack->GetDCAz()) > dca_cut) continue;
  270. if (mcTrack->GetMotherId() != motherId_cut) continue;
  271. // EP-related cut
  272. if (PsiEP_L_reco == -999.) continue;
  273. if (PsiEP_R_reco == -999.) continue;
  274. float v2TPC = 0.;
  275. if (eta < 0)
  276. {
  277. v2TPC = cos( 2. * (phi - PsiEP_R_reco) );
  278. }
  279. if (eta > 0)
  280. {
  281. v2TPC = cos( 2. * (phi - PsiEP_L_reco) );
  282. }
  283. v2TPC /= res_v2TPC_reco;
  284. int pidID = -1;
  285. // PID-related cut
  286. auto particle = (TParticlePDG*) TDatabasePDG::Instance()->GetParticle(mcTrack->GetPdg());
  287. if (!particle) continue;
  288. float charge = 1./3.*particle->Charge();
  289. for (int ipid=0; ipid < Npid; ipid++)
  290. {
  291. if (abs(pdgCodes.at(ipid)) == 999) continue;
  292. if (pdgCodes.at(ipid) == mcTrack->GetPdg()) pidID = ipid;
  293. }
  294. //float charge = recoTrack->GetCharge();
  295. //if (recoTrack->GetPidProbPion() > PidProb_cut && charge > 0) pidID = 1;
  296. //if (recoTrack->GetPidProbKaon() > PidProb_cut && charge > 0) pidID = 2;
  297. //if (recoTrack->GetPidProbProton() > PidProb_cut && charge > 0) pidID = 3;
  298. //if (recoTrack->GetPidProbPion() > PidProb_cut && charge < 0) pidID = 5;
  299. //if (recoTrack->GetPidProbKaon() > PidProb_cut && charge < 0) pidID = 6;
  300. //if (recoTrack->GetPidProbProton() > PidProb_cut && charge < 0) pidID = 7;
  301. if (charge > 0)
  302. pv2recoTPC[0]->Fill(pt, cent, v2TPC);
  303. if (charge < 0)
  304. pv2recoTPC[4]->Fill(pt, cent, v2TPC);
  305. if (pidID == -1) continue;
  306. pv2recoTPC[pidID]->Fill(pt, cent, v2TPC);
  307. } // end reco tracks loop
  308. } // end event loop
  309. //Writing output
  310. fo->cd();
  311. pResMcTPC->Write();
  312. pResRecoTPC->Write();
  313. for (int ipid=0; ipid < Npid; ipid++)
  314. {
  315. pv2mcTPC[ipid]->Write();
  316. }
  317. for (int ipid=0; ipid < Npid; ipid++)
  318. {
  319. pv2recoTPC[ipid]->Write();
  320. }
  321. hQx_L_mc->Write();
  322. hQy_L_mc->Write();
  323. hQx_R_mc->Write();
  324. hQy_R_mc->Write();
  325. hQx_L_reco->Write();
  326. hQy_L_reco->Write();
  327. hQx_R_reco->Write();
  328. hQy_R_reco->Write();
  329. fo->Close();
  330. timer.Stop();
  331. timer.Print();
  332. }