gregsStHbtMuDstReader.cxx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. #include "StChain.h"
  2. #include "StEvent/StEventTypes.h"
  3. #include "StEventUtilities/StuRefMult.hh"
  4. #include "StEventUtilities/StuProbabilityPidAlgorithm.h"
  5. #include "StarClassLibrary/StPhysicalHelixD.hh"
  6. #include "StMuDSTMaker/COMMON/StMuException.hh"
  7. #include "StMuDSTMaker/COMMON/StMuTrack.h"
  8. #include "StMuDSTMaker/COMMON/StMuDebug.h"
  9. #include "StMuDSTMaker/COMMON/StMuCut.h"
  10. #include "StMuDSTMaker/COMMON/StMuDst.h"
  11. #include "StBTofHeader.h"
  12. #include "gregsStHbtMuDstReader.h"
  13. #include "StHbtMaker/Infrastructure/StHbtEvent.hh"
  14. #include "StHbtMaker/Base/StHbtEventCut.h"
  15. #include "TFile.h"
  16. #include "TTree.h"
  17. #include "TClass.h"
  18. #include "TChain.h"
  19. #include "TStreamerInfo.h"
  20. #include "TClonesArray.h"
  21. ClassImp(gregsStHbtMuDstReader)
  22. #if !(ST_NO_NAMESPACES)
  23. using namespace units;
  24. #endif
  25. //_________________
  26. gregsStHbtMuDstReader::gregsStHbtMuDstReader(StMuDstMaker* maker) :
  27. mMuDstMaker(maker), mTrackType(1), mReadTracks(1),
  28. mReadV0s(0) {
  29. mEventCounter=0;
  30. mReaderStatus = 0;
  31. mProcessAllVertices = false;
  32. mFinish = false;
  33. mHbtEvent = 0;
  34. }
  35. //_________________
  36. gregsStHbtMuDstReader::~gregsStHbtMuDstReader() {
  37. /* empty */
  38. }
  39. //_________________
  40. void gregsStHbtMuDstReader::clear(){
  41. DEBUGMESSAGE1("");
  42. // if (mHbtEvent) { delete mHbtEvent; mHbtEvent=0; }
  43. }
  44. //_________________
  45. int gregsStHbtMuDstReader::Init(){
  46. DEBUGMESSAGE1("");
  47. // if (!ioMaker) mIOMaker = (StIOMaker*)GetMaker("IOMaker");
  48. // if (!mStStrangeMuDstMaker) mStStrangeMuDstMaker = (StStrangeMuDstMaker*)GetMaker("StrangeMaker");
  49. // if (!mFlowMaker) = (StFlowMaker*)GetMaker("FlowMaker");
  50. return 0;
  51. }
  52. //_________________
  53. void gregsStHbtMuDstReader::Clear(){
  54. DEBUGMESSAGE1("");
  55. clear();
  56. }
  57. //_________________
  58. StHbtEvent* gregsStHbtMuDstReader::ReturnHbtEvent(){
  59. DEBUGMESSAGE1("");
  60. clear();
  61. mMuDst=mMuDstMaker->muDst();
  62. if(!mMuDst) {
  63. std::cout << "gregsStHbtMuDstReader::ReturnHbtEvent [WARNING] - No MuDst file found"
  64. << std::endl;
  65. return 0;
  66. }
  67. mHbtEvent = 0;
  68. mPrimVert = 0;
  69. //Event processing
  70. if (mMuDst && mMuDst->event()) {
  71. DEBUGVALUE3(mMuDst);
  72. mMuDst->fixTrackIndices();
  73. StMuEvent* mMuEvent = mMuDst->event();
  74. StBTofHeader *mTofHeader = mMuDst->btofHeader();
  75. float mVpdVz;
  76. //If trigger collection is not empty then check the trigger list
  77. bool mTriggerIsPassed = IsGoodTrigger(mMuEvent);
  78. if(mTriggerIsPassed == false) {
  79. return 0;
  80. }
  81. //Get number of primary vertices and tracks
  82. Int_t mPrimVertNum = mMuDst->numberOfPrimaryVertices();
  83. Int_t mPrimTracksNum = mMuDst->numberOfPrimaryTracks();
  84. Int_t mGlobTracksNum = mMuDst->numberOfGlobalTracks();
  85. //There should be some tracks and vertices in the event
  86. if(mPrimTracksNum<0 || mPrimTracksNum>10000 ||
  87. mGlobTracksNum<0 || mGlobTracksNum>50000 ||
  88. mPrimVertNum<0) {
  89. return 0;
  90. }
  91. //Primary vertex loop
  92. for(int iVert=0; iVert<mPrimVertNum; iVert++) {
  93. mHbtEvent = 0;
  94. //std::cout << "iVert: " << iVert << std::endl;
  95. //Process only the first primary vertex if it is set
  96. if(iVert!=0 && mProcessAllVertices==false) continue;
  97. //std::cout << "Processing vertex: " << iVert << std::endl;
  98. //Get the current primary vertex
  99. mPrimVert = mMuDst->primaryVertex(iVert);
  100. if(mTofHeader) {
  101. mVpdVz = mTofHeader->vpdVz();
  102. }
  103. else {
  104. mVpdVz = mPrimVert->position().z();
  105. }
  106. bool mVertexPassed = IsGoodPrimaryVertex(mPrimVert, mVpdVz);
  107. if(mVertexPassed == false) {
  108. //std::cout << "Is bad vertex" << std::endl;
  109. continue;
  110. }
  111. //Create new StHbtEvent
  112. mHbtEvent = new StHbtEvent();
  113. //Fill StHbtEvent
  114. mHbtEvent->SetEventNumber(mMuEvent->eventNumber());
  115. mHbtEvent->SetRunNumber(mMuEvent->runNumber());
  116. mHbtEvent->SetCtbMult( (unsigned int) mMuEvent->ctbMultiplicity() );
  117. mHbtEvent->SetZdcAdcEast( (unsigned int) mMuEvent->zdcAdcAttentuatedSumEast() );
  118. mHbtEvent->SetZdcAdcWest( (unsigned int) mMuEvent->zdcAdcAttentuatedSumWest() );
  119. mHbtEvent->SetNumberOfTpcHits( 0 );
  120. mHbtEvent->SetNumberOfTracks( mMuEvent->eventSummary().numberOfTracks() );
  121. mHbtEvent->SetNumberOfGoodTracks( mMuEvent->eventSummary().numberOfGoodTracks() );
  122. mHbtEvent->SetUncorrectedNumberOfPositivePrimaries( mMuEvent->refMultPos() );
  123. mHbtEvent->SetUncorrectedNumberOfNegativePrimaries( mMuEvent->refMultNeg() );
  124. mHbtEvent->SetUncorrectedNumberOfPrimaries( mMuEvent->refMult() ); //This is the refMult()
  125. mHbtEvent->SetReactionPlane(0., 0);
  126. mHbtEvent->SetReactionPlane(0., 1);
  127. mHbtEvent->SetReactionPlaneError(0., 0);
  128. mHbtEvent->SetReactionPlaneError(0., 1);
  129. mHbtEvent->SetPrimVertPos( mPrimVert->position() );
  130. mHbtEvent->SetMagneticField( mMuEvent->magneticField() );
  131. mHbtEvent->SetZdcCoincidenceRate( mMuEvent->runInfo().zdcCoincidenceRate() );
  132. mHbtEvent->SetBbcCoincidenceRate( mMuEvent->runInfo().bbcCoincidenceRate() );
  133. mHbtEvent->SetTriggerWord( mMuEvent->l0Trigger().triggerWord() );
  134. mHbtEvent->SetTriggerActionWord( mMuEvent->l0Trigger().triggerActionWord() );
  135. mHbtEvent->SetVpdVz( mVpdVz );
  136. StMuTrack *mPrimTrack = 0;
  137. StMuTrack *mGlobTrack = 0;
  138. //Fill tracks
  139. if(mReadTracks) {
  140. TObjArray* tracks=0;
  141. switch(mTrackType) {
  142. case 0: tracks = mMuDst->globalTracks(); break;
  143. case 1: tracks = mMuDst->primaryTracks(); break;
  144. default: DEBUGMESSAGE("don't know how to handle this track type");
  145. }
  146. if(!tracks) {
  147. DEBUGMESSAGE("No tracks have been found");
  148. delete mHbtEvent;
  149. mHbtEvent = 0;
  150. return 0;
  151. }
  152. int mNTracks = tracks->GetEntries();
  153. for(int iTrk=0; iTrk<mNTracks; iTrk++) {
  154. bool mTrackPassed = false;
  155. if(mTrackType == 0) {
  156. mGlobTrack = mMuDst->globalTracks(iTrk);
  157. mTrackPassed = IsGoodTrack(mGlobTrack, iVert);
  158. }
  159. else if(mTrackType == 1) {
  160. mPrimTrack = mMuDst->primaryTracks(iTrk);
  161. mTrackPassed = IsGoodTrack(mPrimTrack, iVert);
  162. }
  163. if( mTrackPassed == false ) continue;
  164. StHbtTrack *trackCopy = new StHbtTrack(mMuDst, (StMuTrack*)tracks->UncheckedAt(iTrk));
  165. mHbtEvent->TrackCollection()->push_back(trackCopy);
  166. } //for(int iTrk=0; iTrk<mNTracks; iTrk++)
  167. } //if(mReadTracks)
  168. //Fill V0s
  169. if(mReadV0s) {
  170. //Should be filled for V0s
  171. } //if(mReadV0s)
  172. // Apply event cut, if available
  173. if(mEventCut) {
  174. //std::cout << "Why am I here?" << std::endl;
  175. if (!(mEventCut->Pass(mHbtEvent))){
  176. delete mHbtEvent;
  177. mHbtEvent = 0;
  178. return 0;
  179. }
  180. }
  181. return mHbtEvent;
  182. } //for(Int_t iVert=0; iVert<mPrimVertNum; iVert++)
  183. } //if (mMuDst && mMuDst->event() )
  184. else {
  185. // DTSMaker returned NULL, so we are not OK
  186. mReaderStatus = 1;
  187. }
  188. return mHbtEvent;
  189. }
  190. //_________________
  191. void gregsStHbtMuDstReader::Finish() {
  192. if (mFinish) {
  193. for ( int i=0; i<10; i++) {
  194. cout << "why are you calling the Finish() again ???????" << endl;
  195. cout << "are you the stupid chain destructor ???????????" << endl;
  196. }
  197. }
  198. else {
  199. mFinish = true;
  200. }
  201. return;
  202. }
  203. //_________________
  204. void gregsStHbtMuDstReader::setProbabilityPidFile(const char* file) {
  205. if (mProbabilityPidAlgorithm)
  206. mProbabilityPidAlgorithm->readParametersFromFile(file);
  207. }
  208. //_________________
  209. bool gregsStHbtMuDstReader::IsGoodTrigger(StMuEvent *event) {
  210. bool isGood = true;
  211. if(!mTriggerIdCollection.empty()) {
  212. isGood = false;
  213. for(unsigned int i=0; i<mTriggerIdCollection.size(); i++) {
  214. if(event->triggerIdCollection().nominal().isTrigger(mTriggerIdCollection[i])) {
  215. isGood = true;
  216. break;
  217. }
  218. }
  219. } //if(!mTriggerIdCollection.empty())
  220. return isGood;
  221. }
  222. //_________________
  223. bool gregsStHbtMuDstReader::IsGoodPrimaryVertex(StMuPrimaryVertex *vertex,
  224. Float_t vpdVz) {
  225. bool isGood = false;
  226. float x = vertex->position().x();
  227. float y = vertex->position().y();
  228. float z = vertex->position().z();
  229. float r = ::sqrt(x*x + y*y);
  230. float vpdVzDiff = z - vpdVz;
  231. if( (z >= -80.) && (z <= 80.) && (r <= 3.) &&
  232. (vpdVzDiff >= -10.) && (vpdVzDiff <= 10.) &&
  233. (vertex->ranking() > 0) ) {
  234. isGood = true;
  235. }
  236. /*
  237. if( (::abs(x)<1e-6) &&
  238. (::abs(y)<1e-6) &&
  239. (::abs(z)<1e-6) ) {
  240. isGood = false;
  241. }
  242. */
  243. return isGood;
  244. }
  245. //_________________
  246. bool gregsStHbtMuDstReader::IsGoodTrack(StMuTrack *trk, unsigned short vertInd) {
  247. bool isGood = false;
  248. if( trk->vertexIndex() == vertInd &&
  249. trk->momentum().mag() >= 0.1 &&
  250. trk->momentum().mag() <= 1.7 &&
  251. trk->eta() >= -1.1 &&
  252. trk->eta() <= 1.1 &&
  253. trk->nHits() >= 5 &&
  254. trk->nHits() <= 50 &&
  255. trk->flag() >= 0 &&
  256. trk->flag() <= 1000 &&
  257. trk->dca(vertInd).perp() >= -0.0001 &&
  258. trk->dca(vertInd).perp() <= 3. &&
  259. trk->dcaGlobal(vertInd).perp() >= 0. &&
  260. trk->dcaGlobal(vertInd).perp() <= 3.) {
  261. isGood = true;
  262. }
  263. return isGood;
  264. }