StFlow.cxx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. #include "StFlow.h"
  2. #include "StBTofHeader.h"
  3. #include "TBranch.h"
  4. ClassImp(StFlow)
  5. //
  6. // Set maximum file size to 1.9 GB (Root has a 2GB limit)
  7. //
  8. #define MAXFILESIZE 1900000000
  9. //_________________
  10. StFlow::StFlow(StMuDstMaker *muMaker, const Char_t *oFileName)
  11. {
  12. std::cout << "StFlow::StFlow - Creating an instance...";
  13. mMuDstMaker = muMaker;
  14. mEventIsGood = false;
  15. mNEventsIn = 0;
  16. mNEventsPassed = 0;
  17. mIsGoodTrack = false;
  18. mCurrentTrigger = 0;
  19. mFileName = oFileName;
  20. //
  21. // Initialize event cut variables
  22. //
  23. mPrimVtxZ[0] = -30.;
  24. mPrimVtxZ[1] = 30.;
  25. mPrimVtxR[0] = 0.;
  26. mPrimVtxR[1] = 2.;
  27. mPrimVtxVpdVzDiff[0] = -5.;
  28. mPrimVtxVpdVzDiff[1]= 5.;
  29. mPrimVtxXShift = 0.;
  30. mPrimVtxYShift = 0.;
  31. //
  32. // Initialize single-particle cut variables
  33. //
  34. mTrackP[0] = 0.1;
  35. mTrackP[1] = 2.;
  36. mTrackDca[0] = 0.;
  37. mTrackDca[1] = 2.;
  38. mTrackDcaGlobal[0] = 0.;
  39. mTrackDcaGlobal[1] = 2.;
  40. mTrackNHits[0] = 15;
  41. mTrackNHits[1] = 50;
  42. mTrackNHitsFit[0] = 15;
  43. mTrackNHitsFit[1] = 50;
  44. mTrackEta[0] = -1.;
  45. mTrackEta[1] = 1.;
  46. mTrackFlag[0] = 0;
  47. mTrackFlag[1] = 1000;
  48. mRefMultCorrUtil = new StRefMultCorr("refmult");
  49. std::cout << "\t[DONE]" << std::endl;
  50. }
  51. //_________________
  52. StFlow::~StFlow()
  53. {
  54. /* nothing to do */
  55. }
  56. //_________________
  57. Int_t StFlow::Init()
  58. {
  59. std::cout << "StFlow::Init - Initializing the maker" << std::endl;
  60. //
  61. // Create histograms and output file
  62. //
  63. mOutFile = new TFile(mFileName, "RECREATE");
  64. hdV2vsCent = new TProfile("hdV2vsCent", ";Centrality (%);v_{2}",
  65. 10, 0., 100.);
  66. hV2vsCent = new TH2F("hV2vsCent", ";Centrality (%);v_{2}",
  67. 10, 0., 100.,
  68. 100, -1., 1.);
  69. std::cout << "StFlow::Init - Initialization has been finished" << std::endl;
  70. return StMaker::Init();
  71. }
  72. //________________
  73. void StFlow::Clear(Option_t *option)
  74. {
  75. StMaker::Clear();
  76. }
  77. //________________
  78. Int_t StFlow::Make()
  79. {
  80. mNEventsIn++;
  81. mMuDst = NULL;
  82. mMuEvent = NULL;
  83. //MuDstMaker initialization
  84. mMuDstMaker = (StMuDstMaker*)GetMaker("MuDst");
  85. if(!mMuDstMaker)
  86. {
  87. LOG_ERROR << "StFlow::Make [ERROR] - Cannot find StMuDstMaker"
  88. << std::endl;
  89. return kStOk;
  90. }
  91. //Obtaining MuDst
  92. mMuDst = (StMuDst*)GetInputDS("MuDst");
  93. if(!mMuDst)
  94. {
  95. gMessMgr->Warning() << "StFlow::Make [WARNING] - No MuDst has been found"
  96. << endm;
  97. return kStOk;
  98. }
  99. //Obtaining MuEvent
  100. mMuEvent = (StMuEvent*)mMuDst->event();
  101. if(!AcceptTrigger(mMuEvent))
  102. { //If trigger is not found
  103. return kStOk;
  104. }
  105. //Multiplicity cannot be negative
  106. unsigned short refMult = mMuEvent->refMult();
  107. unsigned short refMultPos = 0;
  108. unsigned short refMultNeg = 0;
  109. if(refMult < 0)
  110. {
  111. return kStOk;
  112. }
  113. int mNVertices = mMuDst->numberOfPrimaryVertices();
  114. int mNPrimTracks = mMuDst->numberOfPrimaryTracks();
  115. int mNGlobTracks = mMuDst->numberOfGlobalTracks();
  116. //Some initializations of local variables
  117. mPrimVertex = NULL;
  118. StThreeVectorF mVertPosition;
  119. Float_t mVpdVz = 0.;
  120. Int_t mPrimVertIndex = -999;
  121. Float_t mRanking = -999.;
  122. //Clean index vectors
  123. CleanVariables();
  124. //Vertex loop
  125. for(Int_t iVert=0; iVert<mNVertices; iVert++)
  126. {
  127. mEventIsGood = false;
  128. if(iVert!=0) continue; // Not first primary vertex does not contain tracks with fast detectors (TOF)
  129. mPrimVertex = mMuDst->primaryVertex(iVert);
  130. //Positive ranking only
  131. if(mPrimVertex->ranking() <= 0) continue;
  132. //Not (0,0,0) position of the primary vertex
  133. if(mPrimVertex->position().x() == 0 &&
  134. mPrimVertex->position().y() == 0 &&
  135. mPrimVertex->position().z() == 0) continue;
  136. //Reasonable amount of tracks
  137. if(mNPrimTracks < 0 || mNPrimTracks > 10000) continue;
  138. mPrimVertIndex = iVert;
  139. mVertPosition = mPrimVertex->position();
  140. mVpdVz = mMuDst->btofHeader()->vpdVz();
  141. if( !AcceptPrimVtx(mVertPosition, mVpdVz) ) continue;
  142. Int_t mCent9;
  143. Int_t mCent16;
  144. mRefMultCorrUtil->init(mMuEvent->runId());
  145. mRefMultCorrUtil->initEvent(mMuEvent->refMult(),
  146. mVertPosition.z(),
  147. mMuEvent->runInfo().zdcCoincidenceRate());
  148. mCent9 = mRefMultCorrUtil->getCentralityBin9();
  149. if(mCent9<0) continue; //Some AuAu collisions have -1 value
  150. float centBin = 0;
  151. if (mCent9 == 8 || mCent9 == 7)
  152. centBin = 0;
  153. else
  154. centBin = 8 - (mCent9 + 1);
  155. centBin = 5 + centBin*10.;
  156. mEventIsGood = true;
  157. //
  158. //Loop over primary tracks
  159. //
  160. float v2 = 0.;
  161. unsigned long steps = 0;
  162. for (int iTrk1 = 0; iTrk1 < mNPrimTracks - 1; iTrk1++)
  163. {
  164. mPrimTrack = mMuDst->primaryTracks(iTrk1);
  165. mGlobTrack = mMuDst->globalTracks(mPrimTrack->index2Global());
  166. float phi1 = mPrimTrack->phi();
  167. if( !AcceptTrack(mPrimTrack, iVert) ) continue;
  168. for (int iTrk2 = iTrk1 + 1; iTrk2 < mNPrimTracks; iTrk2++)
  169. {
  170. mPrimTrack = mMuDst->primaryTracks(iTrk2);
  171. if( !AcceptTrack(mPrimTrack, iVert) ) continue;
  172. float phi2 = mPrimTrack->phi();
  173. float dv2 = cos(2*(phi1 - phi2));
  174. v2 += dv2;
  175. steps++;
  176. hdV2vsCent->Fill(centBin, dv2);
  177. }
  178. } //for(Int_t iTrk=0; iTrk<mNPrimTracks; iTrk++)
  179. v2 /= (float)steps;
  180. hV2vsCent->Fill(centBin, v2);
  181. } //for(Int_t iVert=0; iVert<mNVertices; iVert++)
  182. return kStOk;
  183. }
  184. //_________________
  185. Bool_t StFlow::AcceptTrigger(StMuEvent *muEvent)
  186. {
  187. Bool_t mIsGoodTrigger = false;
  188. if(mTriggerIdCollection.empty()) {
  189. mIsGoodTrigger = true;
  190. }
  191. else {
  192. for(UInt_t iTrg=0; iTrg<mTriggerIdCollection.size(); iTrg++) {
  193. if(muEvent->triggerIdCollection().nominal().isTrigger(mTriggerIdCollection.at(iTrg))) {
  194. mIsGoodTrigger = true;
  195. mCurrentTrigger = mTriggerIdCollection.at(iTrg);
  196. break;
  197. }
  198. } //for(UInt_t iTrg=0; iTrg<mTriggerIdCollection.size(); iTrg++)
  199. }
  200. return mIsGoodTrigger;
  201. }
  202. //_________________
  203. Bool_t StFlow::AcceptPrimVtx(StThreeVectorF vtxPos,
  204. Float_t vpdVz)
  205. {
  206. Float_t mVtxX = vtxPos.x() - mPrimVtxXShift;
  207. Float_t mVtxY = vtxPos.y() - mPrimVtxYShift;
  208. Float_t mVtxZ = vtxPos.z();
  209. Float_t vtxR = TMath::Sqrt(mVtxX*mVtxX + mVtxY*mVtxY);
  210. Float_t vpdDiff = mVtxZ - vpdVz;
  211. return ( vtxPos.z() >= mPrimVtxZ[0] &&
  212. vtxPos.z() <= mPrimVtxZ[1] &&
  213. vtxR >= mPrimVtxR[0] &&
  214. vtxR <= mPrimVtxR[1] &&
  215. vpdDiff >= mPrimVtxVpdVzDiff[0] &&
  216. vpdDiff <= mPrimVtxVpdVzDiff[1] );
  217. }
  218. //_________________
  219. Bool_t StFlow::AcceptTrack(StMuTrack *trk, UShort_t vtxInd)
  220. {
  221. float mom = trk->momentum().mag();
  222. float eta = trk->eta();
  223. unsigned short nHitsFit = trk->nHitsFit();
  224. float ratioH = (float)trk->nHitsFit()/(float)trk->nHitsPoss();
  225. short flag = trk->flag();
  226. float dca = trk->dcaGlobal(vtxInd).perp();
  227. bool isMomOk = ( mom >= mTrackP[0] &&
  228. mom <= mTrackP[1] );
  229. bool isEtaOk = ( eta >= mTrackEta[0] &&
  230. eta <= mTrackEta[1] );
  231. bool isNHitsFitOk = ( nHitsFit >= mTrackNHitsFit[0] &&
  232. nHitsFit <= mTrackNHitsFit[1] &&
  233. ratioH >= 0.51 );
  234. bool isFlagOk = ( flag >= mTrackFlag[0] &&
  235. flag <= mTrackFlag[1] );
  236. bool isDcaOk = ( dca >= mTrackDcaGlobal[0] &&
  237. dca <= mTrackDcaGlobal[1] );
  238. return ( isMomOk && isEtaOk && isNHitsFitOk && isFlagOk && isDcaOk );
  239. }
  240. //_________________
  241. Int_t StFlow::Finish()
  242. {
  243. std::cout << "*************************************" << std::endl
  244. << "StFlow has been finished" << std::endl
  245. << "\t nEventsPassed : " << mNEventsPassed << std::endl
  246. << "\t nEventsProcessed: " << mNEventsIn << std::endl
  247. << "*************************************" << std::endl;
  248. mOutFile->cd();
  249. mOutFile->Write();
  250. mOutFile->Close();
  251. return kStOk;
  252. }
  253. //_________________
  254. void StFlow::CleanVariables()
  255. {
  256. mEventIsGood = false;
  257. }
  258. //_________________
  259. void StFlow::SetTriggerId(unsigned int id)
  260. {
  261. mTriggerIdCollection.push_back(id);
  262. }
  263. //_________________
  264. void StFlow::SetMuDstMaker(StMuDstMaker *maker)
  265. {
  266. mMuDstMaker = maker;
  267. }
  268. //_________________
  269. void StFlow::SetVtxZCut(float lo, float hi)
  270. {
  271. mPrimVtxZ[0] = lo;
  272. mPrimVtxZ[1] = hi;
  273. }
  274. //_________________
  275. void StFlow::SetVtxRCut(float lo, float hi)
  276. {
  277. mPrimVtxR[0] = lo;
  278. mPrimVtxR[1] = hi;
  279. }
  280. //_________________
  281. void StFlow::SetVtxShift(float xShift, float yShift)
  282. {
  283. mPrimVtxXShift = xShift;
  284. mPrimVtxYShift = yShift;
  285. }
  286. //_________________
  287. void StFlow::SetVtxVpdVzDiffCut(float lo, float hi)
  288. {
  289. mPrimVtxVpdVzDiff[0] = lo;
  290. mPrimVtxVpdVzDiff[1] = hi;
  291. }
  292. //_________________
  293. void StFlow::SetP(float lo, float hi)
  294. {
  295. mTrackP[0] = lo;
  296. mTrackP[1] = hi;
  297. }
  298. //_________________
  299. void StFlow::SetPt(float lo, float hi)
  300. {
  301. mTrackPt[0] = lo;
  302. mTrackPt[1] = hi;
  303. }
  304. //_________________
  305. void StFlow::SetTrackNHits(int lo, int hi)
  306. {
  307. mTrackNHits[0] = lo;
  308. mTrackNHits[1] = hi;
  309. }
  310. //_________________
  311. void StFlow::SetTrackNHitsFit(int lo, int hi)
  312. {
  313. mTrackNHitsFit[0] = lo;
  314. mTrackNHitsFit[1] = hi;
  315. }
  316. //_________________
  317. void StFlow::SetTrackEta(float lo, float hi)
  318. {
  319. mTrackEta[0] = lo;
  320. mTrackEta[1] = hi;
  321. }
  322. //_________________
  323. void StFlow::SetTrackFlag(short lo, short hi)
  324. {
  325. mTrackFlag[0] = lo;
  326. mTrackFlag[1] = hi;
  327. }
  328. //_________________
  329. void StFlow::SetTrackDCA(float lo, float hi)
  330. {
  331. mTrackDcaGlobal[0] = lo;
  332. mTrackDcaGlobal[1] = hi;
  333. }
  334. //_________________
  335. Bool_t StFlow::IsTofTrack(StMuTrack *trk)
  336. { //Only for globals
  337. Bool_t isTofHit = false;
  338. if(trk->btofPidTraits().beta() > 0 &&
  339. trk->btofPidTraits().timeOfFlight() > 0)
  340. {
  341. isTofHit = true;
  342. }
  343. return isTofHit;
  344. }