123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- // Do not forget to source setPicoDst.sh script
- #include <iostream>
- #include <TStopwatch.h>
- #include <TChain.h>
- #include <TFile.h>
- #include <TClonesArray.h>
- #include <TMath.h>
- #include <TVector3.h>
- #include <TH2F.h>
- #include <TProfile.h>
- #include <TProfile2D.h>
- #include <TDatabasePDG.h>
- #define MAX_TRACKS 10000
- #include <Utils.C>
- // R__LOAD_LIBRARY(libPicoDst.so)
- const std::vector<float> vResTpc = {0.224964, 0.349906, 0.368124, 0.336364, 0.28126, 0.224188, 0.190761, 0.19178};
- void get_flow_model(TString inputFileName, TString outputFileName)
- {
- TStopwatch timer;
- timer.Start();
- // Configure input information
- TChain *chain = new TChain("mctree");
- chain->Add(inputFileName.Data());
- Float_t bimp;
- Float_t phi2;
- Float_t phi3;
- Float_t ecc2;
- Float_t ecc3;
- Int_t npart;
- Int_t nh;
- Float_t momx[MAX_TRACKS]; //[nh]
- Float_t momy[MAX_TRACKS]; //[nh]
- Float_t momz[MAX_TRACKS]; //[nh]
- Float_t ene[MAX_TRACKS]; //[nh]
- Int_t hid[MAX_TRACKS]; //[nh]
- Int_t pdg[MAX_TRACKS]; //[nh]
- Short_t charge[MAX_TRACKS]; //[nh]
- // List of branches
- TBranch *b_bimp; //!
- TBranch *b_phi2; //!
- TBranch *b_phi3; //!
- TBranch *b_ecc2; //!
- TBranch *b_ecc3; //!
- TBranch *b_npart; //!
- TBranch *b_nh; //!
- TBranch *b_momx; //!
- TBranch *b_momy; //!
- TBranch *b_momz; //!
- TBranch *b_ene; //!
- TBranch *b_hid; //!
- TBranch *b_pdg; //!
- TBranch *b_charge; //!
- chain->SetBranchAddress("bimp", &bimp, &b_bimp);
- chain->SetBranchAddress("phi2", &phi2, &b_phi2);
- chain->SetBranchAddress("phi3", &phi3, &b_phi3);
- chain->SetBranchAddress("ecc2", &ecc2, &b_ecc2);
- chain->SetBranchAddress("ecc3", &ecc3, &b_ecc3);
- chain->SetBranchAddress("npart", &npart, &b_npart);
- chain->SetBranchAddress("nh", &nh, &b_nh);
- chain->SetBranchAddress("momx", momx, &b_momx);
- chain->SetBranchAddress("momy", momy, &b_momy);
- chain->SetBranchAddress("momz", momz, &b_momz);
- chain->SetBranchAddress("ene", ene, &b_ene);
- chain->SetBranchAddress("hid", hid, &b_hid);
- chain->SetBranchAddress("pdg", pdg, &b_pdg);
- chain->SetBranchAddress("charge", charge, &b_charge);
- // Configure output information
- TFile *fo = new TFile(outputFileName.Data(),"recreate");
- TProfile *pResMcTPC = new TProfile("pResTPC","Resolution for TPC EP MODEL", NcentBins, centBinMin, centBinMax);
- TProfile2D *pv2mcTPC[Npid];
- for (int i=0; i < Npid; i++)
- {
- 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);
- }
- TH2F *hQx_L_mc = new TH2F("hQx_L","Qx from Left TPC MODEL", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
- TH2F *hQy_L_mc = new TH2F("hQy_L","Qy from Left TPC MODEL", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
- TH2F *hQx_R_mc = new TH2F("hQx_R","Qx from Right TPC MODEL", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
- TH2F *hQy_R_mc = new TH2F("hQy_R","Qy from Right TPC MODEL", NcentBins, centBinMin, centBinMax, NQvBins, QvBinMin, QvBinMax);
- // Start event loop
- int n_entries = chain->GetEntries();
- for (int iEv=0; iEv<n_entries; iEv++)
- {
- if (iEv%1000==0) std::cout << "Event [" << iEv << "/" << n_entries << "]" << std::endl;
- chain->GetEntry(iEv);
- // Get centrality
- float cent = CentB(bimp);
- if (cent == -1) continue;
- Int_t mc_num_particles = nh;
- // Read MC tracks
- float Qx_L_mc = 0., Qy_L_mc = 0., W_L_mc = 0.;
- float Qx_R_mc = 0., Qy_R_mc = 0., W_R_mc = 0.;
- int Mult_L_mc = 0, Mult_R_mc = 0;
- float PsiEP_L_mc = 0., PsiEP_R_mc = 0.;
- for (int iTr=0; iTr<mc_num_particles; iTr++)
- {
- TVector3 vect(momx[iTr], momy[iTr], momz[iTr]);
- float pt = vect.Pt();
- float eta = vect.Eta();
- float phi = vect.Phi();
- // Main track cuts
- if (pt < pt_min_cut) continue;
- if (pt > pt_max_cut) continue;
- if (abs(eta) > eta_cut) continue;
- if (abs(eta) < eta_gap) continue;
-
- // PID-related cut (or to cut out neutral particles)
- auto particle = (TParticlePDG*) TDatabasePDG::Instance()->GetParticle(pdg[iTr]);
- if (!particle) continue;
- float charge = 1./3.*particle->Charge();
- if (charge == 0) continue;
- // TPC Left EP
- if (eta < 0)
- {
- Qx_L_mc += pt * cos(2.* phi);
- Qy_L_mc += pt * sin(2.* phi);
- W_L_mc += pt;
- Mult_L_mc++;
- }
- // TPC Right EP
- if (eta > 0)
- {
- Qx_R_mc += pt * cos(2.* phi);
- Qy_R_mc += pt * sin(2.* phi);
- W_R_mc += pt;
- Mult_R_mc++;
- }
- } // end of mc track loop
- if (Mult_L_mc > mult_EP_cut && Mult_R_mc > mult_EP_cut)
- {
- Qx_L_mc /= W_L_mc;
- Qy_L_mc /= W_L_mc;
- Qx_R_mc /= W_R_mc;
- Qy_R_mc /= W_R_mc;
- hQx_L_mc->Fill(cent, Qx_L_mc);
- hQy_L_mc->Fill(cent, Qy_L_mc);
- hQx_R_mc->Fill(cent, Qx_R_mc);
- hQy_R_mc->Fill(cent, Qy_R_mc);
- PsiEP_L_mc = 0.5 * atan2(Qy_L_mc, Qx_L_mc);
- PsiEP_R_mc = 0.5 * atan2(Qy_R_mc, Qx_R_mc);
- }
- else
- {
- PsiEP_L_mc = -999.;
- PsiEP_R_mc = -999.;
- }
- float res_mc = cos(2. * (PsiEP_R_mc - PsiEP_L_mc) );
- if (PsiEP_L_mc != -999. && PsiEP_R_mc != -999.)
- {
- pResMcTPC->Fill(cent, res_mc);
- }
- ////////////////////////////////////////////////////////////////////
- //
- // FLOW CALCULATIONS
- //
- ////////////////////////////////////////////////////////////////////
-
- float res_v2TPC_mc = vResTpc.at(GetCentBin(cent));
- // Read MC tracks
- for (int iTr=0; iTr<mc_num_particles; iTr++)
- {
- TVector3 vect(momx[iTr], momy[iTr], momz[iTr]);
- float pt = vect.Pt();
- float eta = vect.Eta();
- float phi = vect.Phi();
- // Main track cuts
- if (pt < pt_min_cut) continue;
- if (pt > pt_max_cut) continue;
- if (abs(eta) > eta_cut) continue;
- if (abs(eta) < eta_gap) continue;
- // EP-related cut
- if (PsiEP_L_mc == -999.) continue;
- if (PsiEP_R_mc == -999.) continue;
- // PID-related cut
- auto particle = (TParticlePDG*) TDatabasePDG::Instance()->GetParticle(pdg[iTr]);
- if (!particle) continue;
-
- float v2TPC = 0.;
- if (eta < 0)
- {
- v2TPC = cos( 2. * (phi - PsiEP_R_mc) );
- }
- if (eta > 0)
- {
- v2TPC = cos( 2. * (phi - PsiEP_L_mc) );
- }
- v2TPC /= res_v2TPC_mc;
- int pidID = -1;
- float charge = 1./3.*particle->Charge();
- for (int ipid=0; ipid < Npid; ipid++)
- {
- if (abs(pdgCodes.at(ipid)) == 999) continue;
- if (pdgCodes.at(ipid) == pdg[iTr]) pidID = ipid;
- }
- if (charge > 0)
- pv2mcTPC[0]->Fill(pt, cent, v2TPC);
- if (charge < 0)
- pv2mcTPC[4]->Fill(pt, cent, v2TPC);
- if (pidID == -1) continue;
- pv2mcTPC[pidID]->Fill(pt, cent, v2TPC);
- } // end mc tracks loop
- } // end event loop
- //Writing output
- fo->cd();
- pResMcTPC->Write();
- for (int ipid=0; ipid < Npid; ipid++)
- {
- pv2mcTPC[ipid]->Write();
- }
-
- hQx_L_mc->Write();
- hQy_L_mc->Write();
- hQx_R_mc->Write();
- hQy_R_mc->Write();
- fo->Close();
- timer.Stop();
- timer.Print();
- }
|