StHbtMuDstReader.cxx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /***************************************************************************
  2. *
  3. * $Id: StHbtMuDstReader.cxx,v 1.10 2005/07/18 16:33:20 kopytin Exp $
  4. * Author: Frank Laue, BNL, laue@bnl.gov
  5. *
  6. **************************************************************************/
  7. #include "StChain.h"
  8. #include "StEvent/StEventTypes.h"
  9. #include "StEventUtilities/StuRefMult.hh"
  10. #include "StEventUtilities/StuProbabilityPidAlgorithm.h"
  11. #include "StarClassLibrary/StPhysicalHelixD.hh"
  12. #include "StarClassLibrary/StTimer.hh"
  13. #include "StIOMaker/StIOMaker.h"
  14. #include "StStrangeMuDstMaker/StStrangeMuDstMaker.h"
  15. #include "StStrangeMuDstMaker/StStrangeEvMuDst.hh"
  16. #include "StStrangeMuDstMaker/StV0MuDst.hh"
  17. #include "StStrangeMuDstMaker/StV0Mc.hh"
  18. #include "StStrangeMuDstMaker/StXiMuDst.hh"
  19. #include "StStrangeMuDstMaker/StXiMc.hh"
  20. #include "StStrangeMuDstMaker/StKinkMuDst.hh"
  21. #include "StStrangeMuDstMaker/StKinkMc.hh"
  22. #include "StMuDSTMaker/COMMON/StMuException.hh"
  23. #include "StMuDSTMaker/COMMON/StMuEvent.h"
  24. #include "StMuDSTMaker/COMMON/StMuTrack.h"
  25. #include "StMuDSTMaker/COMMON/StMuDebug.h"
  26. #include "StMuDSTMaker/COMMON/StMuCut.h"
  27. #include "StMuDSTMaker/COMMON/StMuDst.h"
  28. #include "StHbtMuDstReader.h"
  29. #include "Infrastructure/StHbtEvent.hh"
  30. #include "StHbtMaker/Base/StHbtEventCut.h"
  31. #include "TFile.h"
  32. #include "TTree.h"
  33. #include "TClass.h"
  34. #include "TChain.h"
  35. #include "TStreamerInfo.h"
  36. #include "TClonesArray.h"
  37. ClassImp(StHbtMuDstReader)
  38. #if !(ST_NO_NAMESPACES)
  39. using namespace units;
  40. #endif
  41. //_________________
  42. StHbtMuDstReader::StHbtMuDstReader(int mode, int nameMode, const char* dirName,
  43. const char* fileName, const char* filter, int maxFiles) :
  44. mStEvent(0), mStStrangeMuDstMaker(0), mIOMaker(0),
  45. mIoMode((ioMode)mode), mIoNameMode((ioNameMode)nameMode),
  46. mDirName(dirName), mFileName(fileName), mFilter(filter), mMaxFiles(maxFiles),
  47. mTrackType(primary), mReadTracks(1),
  48. mReadV0s(1), mReadXis(1), mReadKinks(1), mFinish(0),
  49. mSplit(99), mCompress(9), mBufferSize(65536*4), mHbtEvent(0)
  50. {
  51. mReaderStatus = 0;
  52. mEventCounter=0;
  53. mStMuDst = new StMuDst();
  54. /// from muDst
  55. for ( int i=0; i<__NARRAYS__; i++) {
  56. arrays[i] = 0;
  57. mArrays[i]= clonesArray(arrays[i],StMuArrays::arrayTypes[i],StMuArrays::arraySizes[i],StMuArrays::arrayCounters[i]);
  58. }
  59. /// from strangeness group
  60. for ( int i=0; i<__NSTRANGEARRAYS__; i++) {
  61. strangeArrays[i] = 0;
  62. mStrangeArrays[i]= clonesArray(strangeArrays[i],StMuArrays::strangeArrayTypes[i],StMuArrays::strangeArraySizes[i],StMuArrays::strangeArrayCounters[i]);
  63. }
  64. mStMuDst->set(arrays,strangeArrays);
  65. if (mIoMode==ioRead) openRead();
  66. if (mIoMode==ioWrite) mProbabilityPidAlgorithm = new StuProbabilityPidAlgorithm();
  67. }
  68. //_________________
  69. StHbtMuDstReader::~StHbtMuDstReader() {
  70. }
  71. //_________________
  72. void StHbtMuDstReader::clear() {
  73. DEBUGMESSAGE1("");
  74. // if (mHbtEvent) { delete mHbtEvent; mHbtEvent=0;}
  75. /// from muDst
  76. for ( int i=0; i<__NARRAYS__; i++) {
  77. clear(mArrays[i],StMuArrays::arrayCounters[i]);
  78. }
  79. for ( int i=0; i<__NSTRANGEARRAYS__; i++) {
  80. clear(mStrangeArrays[i],StMuArrays::strangeArrayCounters[i]);
  81. }
  82. }
  83. //_________________
  84. void StHbtMuDstReader::clear(TClonesArray* t, int& counter){
  85. if (t) t->Clear(""); counter=0;
  86. }
  87. //_________________
  88. TClonesArray* StHbtMuDstReader::clonesArray(TClonesArray* p, const char* type,
  89. int size, int& counter) {
  90. DEBUGMESSAGE1("");
  91. if (!p) {
  92. DEBUGVALUE2(type);
  93. p = new TClonesArray(type, size);
  94. counter=0;
  95. }
  96. if (!p) throw StMuExceptionNullPointer("could not create TClonesArray",__PRETTYF__);
  97. return p;
  98. }
  99. //_________________
  100. int StHbtMuDstReader::Init() {
  101. DEBUGMESSAGE1("");
  102. // mIOMaker = (StIOMaker*)GetMaker("IOMaker");
  103. // mStStrangeMuDstMaker = (StStrangeMuDstMaker*)GetMaker("StrangeMaker");
  104. return 0;
  105. }
  106. //_________________
  107. void StHbtMuDstReader::Clear(){
  108. DEBUGMESSAGE1("");
  109. clear();
  110. }
  111. //_________________
  112. StHbtEvent* StHbtMuDstReader::ReturnHbtEvent() {
  113. DEBUGMESSAGE1("");
  114. StTimer timer;
  115. timer.start();
  116. clear();
  117. try {
  118. if (mIoMode == ioRead) read();
  119. }
  120. catch(StMuExceptionEOF e) {
  121. e.print();
  122. mReaderStatus = 2;
  123. return 0;
  124. }
  125. catch(StMuException e) {
  126. e.print();
  127. mReaderStatus = 1;
  128. return 0;
  129. }
  130. DEBUGVALUE1(timer.elapsedTime());
  131. if (mStMuDst) {
  132. mStMuDst->fixTrackIndices();
  133. mHbtEvent = new StHbtEvent(mStMuDst, mTrackType);
  134. }
  135. if (mEventCut){
  136. if (!(mEventCut->Pass(mHbtEvent))){
  137. delete mHbtEvent;
  138. mHbtEvent = 0;
  139. return 0;
  140. }
  141. }
  142. return mHbtEvent;
  143. }
  144. //_________________
  145. void StHbtMuDstReader::fill() {
  146. DEBUGMESSAGE1("");
  147. // mStEvent = (StEvent*) GetInputDS("StEvent");
  148. if (!mStEvent) {
  149. DEBUGMESSAGE1("no StEvent");
  150. return;
  151. }
  152. /// once per event the pid algorithm has to be set up
  153. /// we make it static for the StMuTrack, because all tracks use the same instance
  154. if (mProbabilityPidAlgorithm) delete mProbabilityPidAlgorithm;
  155. mProbabilityPidAlgorithm = new StuProbabilityPidAlgorithm(*mStEvent);
  156. StMuTrack::setProbabilityPidAlgorithm(mProbabilityPidAlgorithm);
  157. StMuTrack::setProbabilityPidCentrality(uncorrectedNumberOfNegativePrimaries(*mStEvent));
  158. try {
  159. fillTrees(mStEvent);
  160. }
  161. catch(StMuException e) {
  162. e.print();
  163. throw e;
  164. }
  165. }
  166. //_________________
  167. void StHbtMuDstReader::write() {
  168. DEBUGMESSAGE1("");
  169. try {
  170. fill();
  171. }
  172. catch (StMuException e) {
  173. return;
  174. }
  175. // filename
  176. string ioMakerFileName;
  177. if (mIOMaker) { // if the ioMaker is specified, we take the output filename from the ioMaker
  178. ioMakerFileName = string(mIOMaker->GetFile());
  179. }
  180. else { // if not then construct the filename
  181. ioMakerFileName = mDirName+mFileName;
  182. }
  183. DEBUGVALUE1(ioMakerFileName.c_str());
  184. string theFileName = buildFileName(mDirName,basename(ioMakerFileName),".MuDst.root");
  185. if (theFileName != mCurrentFileName) {
  186. closeWrite();
  187. openWrite(theFileName);
  188. mCurrentFileName = theFileName;
  189. }
  190. DEBUGMESSAGE2("now fill tree");
  191. mTTree->Fill();
  192. DEBUGMESSAGE2("tree filled");
  193. return;
  194. }
  195. //_________________
  196. void StHbtMuDstReader::Finish() {
  197. if (mFinish) {
  198. for ( int i=0; i<10; i++) {
  199. cout << "why are you calling the Finish() again ???????" << endl;
  200. cout << "are you the stupid chain destructor ???????????" << endl;
  201. }
  202. }
  203. else {
  204. if (mIoMode== ioWrite ) closeWrite();
  205. if (mIoMode== ioRead ) closeRead();
  206. mFinish = true;
  207. }
  208. return;
  209. }
  210. //_________________
  211. void StHbtMuDstReader::openRead() {
  212. DEBUGVALUE1(mDirName.c_str());
  213. DEBUGVALUE1(mFileName.c_str());
  214. DEBUGVALUE1(mFilter.c_str());
  215. makeChain(mDirName.c_str(), mFilter.c_str(),mMaxFiles);
  216. // muDst stuff
  217. for ( int i=0; i<__NARRAYS__; i++) {
  218. mChain->SetBranchAddress(StMuArrays::arrayNames[i],&mArrays[i]);
  219. }
  220. // strange stuff
  221. for ( int i=0; i<__NSTRANGEARRAYS__; i++) {
  222. mChain->SetBranchAddress(StMuArrays::strangeArrayNames[i],&mStrangeArrays[i]);
  223. }
  224. (void*)mChain->GetBranch(""); /// this dummy call returns 0, but magically after calling it, I get a the tree in the next call
  225. mTTree = mChain->GetTree();
  226. mStMuDst->set(mArrays,mStrangeArrays);
  227. }
  228. //_________________
  229. void StHbtMuDstReader::read() {
  230. DEBUGMESSAGE1("");
  231. if ( !(mEventCounter<mChain->GetEntries()) ) throw StMuExceptionEOF("end of input",__PRETTYF__);
  232. mChain->GetEntry(mEventCounter);
  233. DEBUGVALUE2(mChain->GetCurrentFile()->GetName());
  234. mEventCounter++;
  235. return;
  236. }
  237. //_________________
  238. void StHbtMuDstReader::closeRead(){
  239. }
  240. //_________________
  241. void StHbtMuDstReader::openWrite(string fileName) {
  242. DEBUGVALUE1(fileName.c_str());
  243. // creat a Picoevent and and output file
  244. DEBUGMESSAGE2("now create file");
  245. mCurrentFile = new TFile(fileName.c_str(),"RECREATE","StMuDst");
  246. if (!mCurrentFile) throw StMuExceptionNullPointer("no file openend",__PRETTYF__);
  247. mCurrentFile->SetCompressionLevel(mCompress);
  248. // Create a ROOT Tree and one superbranch
  249. DEBUGMESSAGE2("now create trees and branches");
  250. TBranch* branch;
  251. int bufsize = mBufferSize;
  252. if (mSplit) bufsize /= 4;
  253. // muDst stuff
  254. mTTree = new TTree("MuDst", "StMuDst",mSplit);
  255. if (!mTTree) throw StMuExceptionNullPointer("can not create tree",__PRETTYF__);
  256. mTTree->SetAutoSave(1000000); // autosave when 1 Mbyte written
  257. DEBUGMESSAGE("arrays");
  258. for ( int i=0; i<__NARRAYS__; i++) {
  259. DEBUGVALUE2(i);
  260. branch = mTTree->Branch(StMuArrays::arrayNames[i],&mArrays[i], bufsize, mSplit);
  261. }
  262. // strange stuff
  263. DEBUGMESSAGE("strange arrays");
  264. for ( int i=0; i<__NSTRANGEARRAYS__; i++) {
  265. DEBUGVALUE2(i);
  266. branch = mTTree->Branch(StMuArrays::strangeArrayNames[i],&mStrangeArrays[i], bufsize, mSplit);
  267. }
  268. mCurrentFileName = fileName;
  269. }
  270. //_________________
  271. void StHbtMuDstReader::closeWrite() {
  272. if (mTTree) mTTree->AutoSave();
  273. if (mCurrentFile) mCurrentFile->Close();
  274. mTTree = 0;
  275. mCurrentFile = 0;
  276. }
  277. //_________________
  278. void StHbtMuDstReader::fillTrees(StEvent* ev, StMuCut* cut) {
  279. DEBUGMESSAGE1("");
  280. try {
  281. fillEvent(ev);
  282. fillL3AlgorithmInfo(ev);
  283. fillDetectorStates(ev);
  284. }
  285. catch(StMuException e) {
  286. e.print();
  287. }
  288. try {
  289. fillTracks(ev,mTrackFilter);
  290. }
  291. catch(StMuException e) {
  292. e.print();
  293. }
  294. try {
  295. fillL3Tracks(ev, mL3TrackFilter);
  296. }
  297. catch(StMuException e) {
  298. e.print();
  299. }
  300. try {
  301. fillStrange(mStStrangeMuDstMaker);
  302. }
  303. catch(StMuException e) {
  304. e.print();
  305. }
  306. }
  307. //_________________
  308. void StHbtMuDstReader::fillEvent(StEvent* ev, StMuCut* cut) {
  309. DEBUGMESSAGE1("");
  310. StMuEvent typeOfEvent;
  311. if (!ev) throw StMuExceptionNullPointer("no StEvent",__PRETTYF__);
  312. StTimer timer;
  313. timer.start();
  314. if (!cut || cut->pass(ev)) {
  315. DEBUGMESSAGE3("");
  316. addType(mArrays[muEvent],ev,typeOfEvent);
  317. }
  318. timer.stop();
  319. DEBUGVALUE2(timer.elapsedTime());
  320. }
  321. //_________________
  322. void StHbtMuDstReader::fillL3AlgorithmInfo(StEvent* ev) {
  323. DEBUGMESSAGE1("");
  324. if ( !ev->l3Trigger() ) return;
  325. if ( !ev->l3Trigger()->l3EventSummary()) return;
  326. StTimer timer;
  327. timer.start();
  328. StL3EventSummary* l3 = ev->l3Trigger()->l3EventSummary();
  329. int n = l3->numberOfAlgorithms();
  330. for (int i=0; i<n; i++) {
  331. if (l3->algorithms()[i]->accept())
  332. addType( mArrays[muAccept], *l3->algorithms()[i] );
  333. else
  334. addType( mArrays[muReject], *l3->algorithms()[i] );
  335. }
  336. timer.stop();
  337. DEBUGVALUE2(timer.elapsedTime());
  338. }
  339. //_________________
  340. void StHbtMuDstReader::fillTracks(StEvent* ev, StMuCut* cut) {
  341. DEBUGMESSAGE1("");
  342. StTimer timer;
  343. timer.start();
  344. StSPtrVecTrackNode& nodes= ev->trackNodes();
  345. DEBUGVALUE2(nodes.size());
  346. for (StSPtrVecTrackNodeConstIterator iter=nodes.begin(); iter!=nodes.end(); iter++) {
  347. addTrackNode(ev, *iter, cut, mArrays[muGlobal], mArrays[muPrimary], mArrays[muOther], false);
  348. }
  349. timer.stop();
  350. DEBUGVALUE2(timer.elapsedTime());
  351. }
  352. //_________________
  353. void StHbtMuDstReader::fillL3Tracks(StEvent* ev, StMuCut* cut) {
  354. DEBUGMESSAGE1("");
  355. if (!ev->l3Trigger()) return;
  356. StTimer timer;
  357. timer.start();
  358. StSPtrVecTrackNode& nodes= ev->l3Trigger()->trackNodes();
  359. DEBUGVALUE2(nodes.size());
  360. for (StSPtrVecTrackNodeConstIterator iter=nodes.begin(); iter!=nodes.end(); iter++) {
  361. addTrackNode(ev, *iter, cut, mArrays[muL3], 0, 0, true );
  362. }
  363. timer.stop();
  364. DEBUGVALUE2(timer.elapsedTime());
  365. }
  366. //_________________
  367. void StHbtMuDstReader::fillDetectorStates(StEvent* ev) {
  368. DEBUGMESSAGE1("");
  369. StTimer timer;
  370. timer.start();
  371. for (int i=0; i<StMuArrays::arraySizes[muState]; i++) {
  372. StDetectorState* state = ev->detectorState((StDetectorId) i);
  373. if (state)
  374. addType( mArrays[muState], ev->detectorState((StDetectorId)i) );
  375. }
  376. timer.stop();
  377. DEBUGVALUE2(timer.elapsedTime());
  378. }
  379. //_________________
  380. void StHbtMuDstReader::addTrackNode(const StEvent* ev, const StTrackNode* node, StMuCut* cut,
  381. TClonesArray* gTCA, TClonesArray* pTCA, TClonesArray* oTCA,
  382. bool l3) {
  383. DEBUGMESSAGE3("");
  384. const StTrack* tr=0;
  385. /// do global track
  386. int index2Global =-1;
  387. if (gTCA) {
  388. tr= node->track(global);
  389. if (tr ) index2Global = addTrack(gTCA, ev, tr, cut, -1, l3);
  390. }
  391. /// do primary track track
  392. int index;
  393. if (pTCA) {
  394. tr = node->track(primary);
  395. if (tr) index = addTrack(pTCA, ev, tr, cut, index2Global, l3);
  396. }
  397. /// all other tracks
  398. if (oTCA) {
  399. size_t nEntries = node->entries();
  400. for (size_t j=0; j<nEntries; j++) { /// loop over all tracks in tracknode
  401. tr = node->track(j);
  402. if (tr && (tr->type()!=global) && (tr->type()!=primary) ) { /// exclude global and primary tracks
  403. index = addTrack(oTCA, ev, tr, cut, index2Global, l3);
  404. }
  405. }
  406. }
  407. }
  408. //_________________
  409. int StHbtMuDstReader::addTrack(TClonesArray* tca, const StEvent* event, const StTrack* track,
  410. StMuCut* cut, int index2Global, bool l3) {
  411. DEBUGMESSAGE3("");
  412. StRichSpectra typeOfStRichSpectra;
  413. int index = -1;
  414. int index2RichSpectra=-1;
  415. /// if (!tca || !track) return index; /// I made sure that the array anf the track is there
  416. int counter = tca->GetEntries();
  417. try{
  418. if (cut && !cut->pass(track)) throw StMuExceptionBadValue("failed track cut",__PRETTYF__);
  419. // add StRichSpectra if StRichPidTraits are found
  420. // we have to do this more elegant
  421. StRichSpectra* rich = richSpectra(track);
  422. if (rich) {
  423. index2RichSpectra = addType( mArrays[muRich], *rich );
  424. }
  425. new((*tca)[counter]) StMuTrack(event, track, 0, index2Global, index2RichSpectra, l3);
  426. index = counter;
  427. }
  428. catch (StMuException e) {
  429. IFDEBUG3(e.print());
  430. }
  431. return index; /// return index to self if newly created, else return -1;
  432. }
  433. //_________________
  434. StRichSpectra* StHbtMuDstReader::richSpectra(const StTrack* track) {
  435. DEBUGMESSAGE3("");
  436. const StPtrVecTrackPidTraits& traits = track->pidTraits(kRichId);
  437. for (StPtrVecTrackPidTraitsConstIterator traitIter=traits.begin();traitIter!=traits.end();++traitIter) {
  438. StRichPidTraits* pid = dynamic_cast<StRichPidTraits*>(*traitIter);
  439. if (pid) return pid->getRichSpectra();
  440. }
  441. return 0;
  442. }
  443. //_________________
  444. void StHbtMuDstReader::fillStrange(StStrangeMuDstMaker* maker) {
  445. DEBUGMESSAGE2("");
  446. /// now fill the strangeness stuff
  447. if (!maker) throw StMuExceptionNullPointer("no StrangeMuDstMaker",__PRETTYF__);
  448. StStrangeEvMuDst ev;
  449. StV0MuDst v0;
  450. StStrangeAssoc assoc;
  451. StXiMuDst xi;
  452. StKinkMuDst kink;
  453. StV0Mc v0Mc;
  454. StXiMc xiMc;
  455. StKinkMc kinkMc;
  456. addType(maker->GetEvClonesArray(), mStrangeArrays[0],ev);
  457. addType(maker->GetEvMcArray(), mStrangeArrays[1],ev);
  458. addType(maker->GetV0ClonesArray(), mStrangeArrays[2],v0);
  459. addType(maker->GetV0McArray(), mStrangeArrays[3],v0Mc);
  460. addType(maker->GetV0AssocArray(), mStrangeArrays[4],assoc);
  461. addType(maker->GetXiClonesArray(), mStrangeArrays[5],xi);
  462. addType(maker->GetXiMcArray(), mStrangeArrays[6],xiMc);
  463. addType(maker->GetXiAssocArray(), mStrangeArrays[7],assoc);
  464. addType(maker->GetKinkClonesArray(),mStrangeArrays[8],kink);
  465. addType(maker->GetKinkMcArray(), mStrangeArrays[9],kinkMc);
  466. addType(maker->GetKinkAssocArray(), mStrangeArrays[10],assoc);
  467. }
  468. //_________________
  469. template <class T>
  470. void StHbtMuDstReader::addType(TClonesArray* tcaFrom, TClonesArray* tcaTo , T t) {
  471. if (tcaFrom && tcaTo) {
  472. int n = tcaFrom->GetEntries();
  473. int counter = tcaTo->GetEntries();
  474. for (int i=0; i<n;i++) {
  475. new((*tcaTo)[counter++]) T( (T&)*tcaFrom->UncheckedAt(i) );
  476. }
  477. }
  478. }
  479. //_________________
  480. template <class T>
  481. int StHbtMuDstReader::addType(TClonesArray* tcaTo , T t) {
  482. int counter =-1;
  483. if (tcaTo) {
  484. counter = tcaTo->GetEntries();
  485. new((*tcaTo)[counter]) T( t );
  486. }
  487. return counter;
  488. }
  489. //_________________
  490. template <class T, class U>
  491. int StHbtMuDstReader::addType(TClonesArray* tcaTo , U u, T t) {
  492. int counter =-1;
  493. if (tcaTo) {
  494. counter = tcaTo->GetEntries();
  495. DEBUGMESSAGE("");
  496. new((*tcaTo)[counter]) T(u);
  497. }
  498. return counter;
  499. }
  500. //_________________
  501. string StHbtMuDstReader::buildFileName(string dir, string fileName, string extention) {
  502. DEBUGMESSAGE1("");
  503. fileName = dir + "/" + fileName + extention;
  504. return fileName;
  505. }
  506. //_________________
  507. string StHbtMuDstReader::basename(string s) {
  508. string name(s);
  509. while ( name.find("/") != string::npos ) {
  510. string::size_type pos = name.find("/");
  511. name.erase(0, pos+1 );
  512. }
  513. string::size_type pos = name.find(".event.root");
  514. if (pos != string::npos) name.erase(pos,pos+11);
  515. return name;
  516. }
  517. //_________________
  518. void StHbtMuDstReader::makeChain(const char* dir, const char* filter, int maxFiles) {
  519. DEBUGMESSAGE1("");
  520. mChain = new TChain("MuDst");
  521. // TChain* mChain2 = new TChain("StrangeMuDst");
  522. // read directory
  523. // now find the files that end in the specified extention
  524. int fileCount(0);
  525. if(strncmp(dir+strlen(dir)-4,".lis",4)==0){
  526. ifstream tF(dir);
  527. char tFileName[500];
  528. int tNFile =0;
  529. tF >> tFileName;
  530. while ((!tF.eof()) && (tNFile<=maxFiles)){
  531. cout << "Add file " << tFileName << endl;
  532. mChain->Add(tFileName);
  533. tNFile++;
  534. tF >> tFileName;
  535. }
  536. fileCount = tNFile;
  537. }
  538. else{
  539. const char* fileName(0);
  540. void *pDir = gSystem->OpenDirectory(dir);
  541. while((fileName = gSystem->GetDirEntry(pDir))){
  542. if(strcmp(fileName,".")==0 || strcmp(fileName,"..")==0) continue;
  543. if(strcmp(fileName,".event.root")==0 || strcmp(fileName,"..")==0) continue;
  544. // if( !strcmp(fileName,".MuDst.root") ) continue;
  545. if(strstr(fileName,filter) && strstr(fileName,".MuDst.root") ){ // found a match
  546. char* fullFile = gSystem->ConcatFileName(dir,fileName);
  547. // add it to the chain
  548. cout << fileCount << " " << fullFile << endl;
  549. mChain->Add(fullFile);
  550. // mChain2->Add(mChain2);
  551. delete fullFile;
  552. if(++fileCount >= maxFiles) break;
  553. }
  554. }
  555. }
  556. DEBUGVALUE2(fileCount);
  557. }
  558. void StHbtMuDstReader::setProbabilityPidFile(const char* file) {
  559. if (mProbabilityPidAlgorithm)
  560. mProbabilityPidAlgorithm->readParametersFromFile(file);
  561. }
  562. /***************************************************************************
  563. *
  564. * $Log: StHbtMuDstReader.cxx,v $
  565. * Revision 1.10 2005/07/18 16:33:20 kopytin
  566. * Brought addTrack in corresponce with MvL's new StMuTrack constructor list of arguments
  567. *
  568. * Revision 1.9 2005/07/01 00:23:15 chajecki
  569. * fix of potential memory leak in ReturnHbtEvent method
  570. * added 'delete mHbtEvent' if this method returns 0
  571. * (can happend if an even didn't pass an event cut)
  572. *
  573. * Revision 1.8 2004/10/12 13:52:46 kisiel
  574. * Properly hadle mReaderStatus to make frontLoadedEventCut work
  575. *
  576. * Revision 1.7 2004/02/24 19:45:34 magestro
  577. * reverted to 1.5 code
  578. *
  579. * Revision 1.5 2004/02/17 16:46:38 jeromel
  580. * PF to PRETTYF
  581. *
  582. * Revision 1.4 2002/12/13 11:27:58 kisiel
  583. * List files support for StHbtMuDstReader
  584. *
  585. * Revision 1.3 2002/05/24 16:08:03 rcwells
  586. * Added event cut to StHbtMuDstReader
  587. *
  588. * Revision 1.2 2002/03/22 14:17:49 laue
  589. * minor changes for RH 7.2
  590. *
  591. * Revision 1.1 2002/03/20 19:32:24 laue
  592. * new reader for common MuDsts
  593. *
  594. *
  595. **************************************************************************/