00001
00002
00003
00004
00005
00006
00007 #include "TRegexp.h"
00008 #include "Stiostream.h"
00009 #include "Stsstream.h"
00010 #include "StChain.h"
00011 #include "THack.h"
00012 #include "StEvent/StEvent.h"
00013 #include "StEvent/StTrack.h"
00014 #include "StEvent/StTrackNode.h"
00015 #include "StEvent/StRichSpectra.h"
00016 #include "StEvent/StDetectorState.h"
00017 #include "StEvent/StEventTypes.h"
00018 #include "StEvent/StRunInfo.h"
00019 #include "StEvent/StEventInfo.h"
00020 #include "StEvent/StDcaGeometry.h"
00021 #include "StEventUtilities/StuRefMult.hh"
00022 #include "StEventUtilities/StuProbabilityPidAlgorithm.h"
00023
00024 #include "StarClassLibrary/StPhysicalHelixD.hh"
00025 #include "StarClassLibrary/StTimer.hh"
00026 #include "StarClassLibrary/StMatrixF.hh"
00027
00028 #include "StIOMaker/StIOMaker.h"
00029 #include "StTreeMaker/StTreeMaker.h"
00030 #ifndef __NO_STRANGE_MUDST__
00031 #include "StStrangeMuDstMaker/StStrangeMuDstMaker.h"
00032 #include "StStrangeMuDstMaker/StStrangeEvMuDst.hh"
00033 #include "StStrangeMuDstMaker/StV0MuDst.hh"
00034 #include "StStrangeMuDstMaker/StV0Mc.hh"
00035 #include "StStrangeMuDstMaker/StXiMuDst.hh"
00036 #include "StStrangeMuDstMaker/StXiMc.hh"
00037 #include "StStrangeMuDstMaker/StKinkMuDst.hh"
00038 #include "StStrangeMuDstMaker/StKinkMc.hh"
00039 #include "StStrangeMuDstMaker/StStrangeCuts.hh"
00040 #endif
00041
00042 #include "StMuException.hh"
00043 #include "StMuEvent.h"
00044 #include "StMuPrimaryVertex.h"
00045 #include "StMuRpsCollection.h"
00046 #include "StMuMtdCollection.h"
00047 #include "StMuTrack.h"
00048 #include "StMuDebug.h"
00049 #include "StMuCut.h"
00050 #include "StMuFilter.h"
00051 #include "StMuL3Filter.h"
00052 #include "StMuChainMaker.h"
00053 #include "StMuEmcCollection.h"
00054 #include "StMuEmcUtil.h"
00055 #include "StMuFmsCollection.h"
00056 #include "StMuFmsUtil.h"
00057 #include "StMuFmsHit.h"
00058 #include "StMuPmdCollection.h"
00059 #include "StMuPmdUtil.h"
00060 #include "StMuPmdHit.h"
00061 #include "StMuPmdCluster.h"
00062 #include "StMuTofHit.h"
00063 #include "StMuTofHitCollection.h"
00064 #include "StMuTofUtil.h"
00066 #include "StEvent/StBTofCollection.h"
00067 #include "StEvent/StBTofRawHit.h"
00068 #include "StEvent/StBTofHeader.h"
00069 #include "StMuBTofHit.h"
00070 #include "StMuBTofHitCollection.h"
00071 #include "StMuBTofUtil.h"
00072 #include "StMuPrimaryTrackCovariance.h"
00073 #include "StMuEzTree.h"
00074 #include "EztEventHeader.h"
00075 #include "EztEmcRawData.h"
00076 #include "EztTrigBlob.h"
00077 #include "EztFpdBlob.h"
00078
00079 #include "StMuDstMaker.h"
00080 #include "StMuDst.h"
00081
00082 #include "TFile.h"
00083 #include "TTree.h"
00084 #include "TClass.h"
00085 #include "TChain.h"
00086 #include "TStreamerInfo.h"
00087 #include "TClonesArray.h"
00088 #include "TEventList.h"
00089
00090 #include "THack.h"
00091 #include "StMuMcVertex.h"
00092 #include "StMuMcTrack.h"
00093 #include "StG2TrackVertexMap.h"
00094
00095 ClassImp(StMuDstMaker)
00096
00097 #if !(ST_NO_NAMESPACES)
00098 using namespace units;
00099 #endif
00100
00101
00102
00103
00113 StMuDstMaker::StMuDstMaker(const char* name) : StIOInterFace(name),
00114 mStEvent(0), mStMuDst(0),
00115 #ifndef __NO_STRANGE_MUDST__
00116 mStStrangeMuDstMaker(0),
00117 #endif
00118 mIOMaker(0), mTreeMaker(0),
00119 mIoMode(1), mIoNameMode((int)ioTreeMaker), mEventList(0),
00120 mTrackType(256), mReadTracks(1),
00121 mReadV0s(1), mReadXis(1), mReadKinks(1), mFinish(0),
00122 mTrackFilter(0), mL3TrackFilter(0),
00123 mCurrentFile(0),
00124 mChain (0), mTTree(0),
00125 mSplit(99), mCompression(9), mBufferSize(65536*4), mVtxList(100),
00126 mProbabilityPidAlgorithm(0), mEmcCollectionArray(0), mEmcCollection(0),
00127 mFmsCollection(0), mPmdCollectionArray(0), mPmdCollection(0)
00128
00129 {
00130 assignArrays();
00131
00132 mDirName="./";
00133 mFileName="";
00134 streamerOff();
00135 zeroArrays();
00136 if (mIoMode==ioRead) openRead();
00137 if (mIoMode==ioWrite) mProbabilityPidAlgorithm = new StuProbabilityPidAlgorithm();
00138
00139 mEventCounter=0;
00140 mStMuDst = new StMuDst();
00141 mEmcUtil = new StMuEmcUtil();
00142 mFmsUtil = new StMuFmsUtil();
00143 mPmdUtil = new StMuPmdUtil();
00144 mTofUtil = new StMuTofUtil();
00145 mBTofUtil = new StMuBTofUtil();
00146 mEzTree = new StMuEzTree();
00147 if ( ! mStMuDst || ! mEmcUtil || ! mFmsUtil || ! mPmdUtil || ! mTofUtil || ! mBTofUtil || ! mEzTree )
00148 throw StMuExceptionNullPointer("StMuDstMaker:: constructor. Something went horribly wrong, cannot allocate pointers",__PRETTYF__);
00149
00150
00151 createArrays();
00152
00153
00154 setProbabilityPidFile();
00155 StMuL3Filter* l3Filter = new StMuL3Filter(); setL3TrackFilter(l3Filter);
00156 StMuFilter* filter = new StMuFilter(); setTrackFilter(filter);
00157 FORCEDDEBUGMESSAGE("ATTENTION: use standard MuFilter");
00158 FORCEDDEBUGMESSAGE("ATTENTION: use standard l3 MuFilter");
00159
00160
00161 }
00162
00170 void StMuDstMaker::assignArrays()
00171 {
00172 mArrays = mAArrays + 0;
00173 #ifndef __NO_STRANGE_MUDST__
00174 mStrangeArrays = mArrays + __NARRAYS__;
00175 mMCArrays = mStrangeArrays + __NSTRANGEARRAYS__;
00176 #else
00177 mMCArrays = mArrays + __NARRAYS__;
00178 #endif
00179 mEmcArrays = mMCArrays + __NMCARRAYS__;
00180 mPmdArrays = mEmcArrays + __NEMCARRAYS__;
00181 mFmsArrays = mPmdArrays + __NPMDARRAYS__;
00182 mTofArrays = mFmsArrays + __NFMSARRAYS__;
00183 mBTofArrays = mTofArrays + __NTOFARRAYS__;
00184 mEztArrays = mBTofArrays + __NBTOFARRAYS__;
00185 }
00186
00187 void StMuDstMaker::clearArrays()
00188 {
00189 const int ezIndex=__NARRAYS__+
00190 #ifndef __NO_STRANGE_MUDST__
00191 __NSTRANGEARRAYS__+
00192 #endif
00193 __NMCARRAYS__+
00194 __NEMCARRAYS__+
00195 __NPMDARRAYS__+__NFMSARRAYS__+__NTOFARRAYS__+__NBTOFARRAYS__;
00196 for ( int i=0; i<ezIndex; i++) {
00197 mAArrays[i]->Clear();
00198 StMuArrays::arrayCounters[i]=0;
00199 }
00200
00201 for ( int i=ezIndex; i<__NALLARRAYS__; i++) {
00202 mAArrays[i]->Delete();
00203 StMuArrays::arrayCounters[i]=0;
00204 }
00205 }
00206
00207 void StMuDstMaker::zeroArrays()
00208 {
00209 memset(mAArrays,0,sizeof(void*)*__NALLARRAYS__);
00210 memset(mStatusArrays,(char)1,sizeof(mStatusArrays) );
00211
00212 memset(&mStatusArrays[__NARRAYS__+
00213 #ifndef __NO_STRANGE_MUDST__
00214 __NSTRANGEARRAYS__+
00215 #endif
00216 __NMCARRAYS__+
00217 __NEMCARRAYS__+
00218 __NPMDARRAYS__+__NFMSARRAYS__+__NTOFARRAYS__+__NBTOFARRAYS__],(char)0,__NEZTARRAYS__);
00219
00220 }
00221
00222
00223
00248 void StMuDstMaker::SetStatus(const char *arrType,int status)
00249 {
00250 #ifndef __NO_STRANGE_MUDST__
00251 static const char *specNames[]={"MuEventAll","StrangeAll","MCAll" ,"EmcAll","PmdAll","FMSAll","TofAll","BTofAll","EztAll",0};
00252 #else
00253 static const char *specNames[]={"MuEventAll","MCAll" ,"EmcAll","PmdAll","FMSAll","TofAll","BTofAll","EztAll",0};
00254 #endif
00255 static const int specIndex[]={
00256 0,
00257 __NARRAYS__,
00258 #ifndef __NO_STRANGE_MUDST__
00259 __NARRAYS__+__NSTRANGEARRAYS__,
00260 __NARRAYS__+__NSTRANGEARRAYS__+__NMCARRAYS__,
00261 __NARRAYS__+__NSTRANGEARRAYS__+__NMCARRAYS__+__NEMCARRAYS__,
00262 __NARRAYS__+__NSTRANGEARRAYS__+__NMCARRAYS__+__NEMCARRAYS__+__NPMDARRAYS__,
00263 __NARRAYS__+__NSTRANGEARRAYS__+__NMCARRAYS__+__NEMCARRAYS__+__NPMDARRAYS__+__NFMSARRAYS__,
00264 __NARRAYS__+__NSTRANGEARRAYS__+__NMCARRAYS__+__NEMCARRAYS__+__NPMDARRAYS__+__NFMSARRAYS__+__NTOFARRAYS__,
00265 __NARRAYS__+__NSTRANGEARRAYS__+__NMCARRAYS__+__NEMCARRAYS__+__NPMDARRAYS__+__NFMSARRAYS__+__NTOFARRAYS__+__NBTOFARRAYS__,
00266 __NARRAYS__+__NSTRANGEARRAYS__+__NMCARRAYS__+__NEMCARRAYS__+__NPMDARRAYS__+__NFMSARRAYS__+__NTOFARRAYS__+__NBTOFARRAYS__+__NEZTARRAYS__,
00267 #else
00268 __NARRAYS__+__NMCARRAYS__,
00269 __NARRAYS__+__NMCARRAYS__+__NEMCARRAYS__,
00270 __NARRAYS__+__NMCARRAYS__+__NEMCARRAYS__+__NPMDARRAYS__,
00271 __NARRAYS__+__NMCARRAYS__+__NEMCARRAYS__+__NPMDARRAYS__+__NFMSARRAYS__,
00272 __NARRAYS__+__NMCARRAYS__+__NEMCARRAYS__+__NPMDARRAYS__+__NFMSARRAYS__+__NTOFARRAYS__,
00273 __NARRAYS__+__NMCARRAYS__+__NEMCARRAYS__+__NPMDARRAYS__+__NFMSARRAYS__+__NTOFARRAYS__+__NBTOFARRAYS__,
00274 __NARRAYS__+__NMCARRAYS__+__NEMCARRAYS__+__NPMDARRAYS__+__NFMSARRAYS__+__NTOFARRAYS__+__NBTOFARRAYS__+__NEZTARRAYS__,
00275 #endif
00276 -1};
00277
00278 if (strncmp(arrType,"St",2)==0) arrType+=2;
00279 for (int i=0;specNames[i];i++) {
00280 if (strcmp(arrType,specNames[i])) continue;
00281 char *sta=mStatusArrays+specIndex[i];
00282 int num=specIndex[i+1]-specIndex[i];
00283 memset(sta,status,num);
00284 LOG_INFO << "StMuDstMaker::SetStatus " << status << " to " << specNames[i] << endm;
00285 if (mIoMode==ioRead)
00286 setBranchAddresses(mChain);
00287 return;
00288 }
00289
00290 TRegexp re(arrType,1);
00291 for (int i=0;i<__NALLARRAYS__;i++) {
00292 Ssiz_t len;
00293 if (re.Index(StMuArrays::arrayNames[i],&len) < 0) continue;
00294 LOG_INFO << "StMuDstMaker::SetStatus " << status << " to " << StMuArrays::arrayNames[i] << endm;
00295 mStatusArrays[i]=status;
00296 }
00297 if (mIoMode==ioRead)
00298 setBranchAddresses(mChain);
00299 }
00300
00301
00302
00303 StMuDstMaker::StMuDstMaker(int mode, int nameMode, const char* dirName, const char* fileName, const char* filter, int maxFiles, const char* name) :
00304 StIOInterFace(name),
00305 mStEvent(0), mStMuDst(0),
00306 #ifndef __NO_STRANGE_MUDST__
00307 mStStrangeMuDstMaker(0),
00308 #endif
00309 mIOMaker(0), mTreeMaker(0),
00310 mIoMode(mode), mIoNameMode(nameMode),
00311 mDirName(dirName), mFileName(fileName), mFilter(filter),
00312 mMaxFiles(maxFiles), mEventList(0),
00313 mTrackType(256), mReadTracks(1),
00314 mReadV0s(1), mReadXis(1), mReadKinks(1), mFinish(0),
00315 mTrackFilter(0), mL3TrackFilter(0), mCurrentFile(0),
00316 mSplit(99), mCompression(9), mBufferSize(65536*4),
00317 mProbabilityPidAlgorithm(0), mEmcCollectionArray(0), mEmcCollection(0),
00318 mFmsCollection(0), mPmdCollectionArray(0), mPmdCollection(0)
00319 {
00320 assignArrays();
00321 streamerOff();
00322 zeroArrays();
00323 createArrays();
00324 if (mIoMode==ioRead) openRead();
00325 if (mIoMode==ioWrite) mProbabilityPidAlgorithm = new StuProbabilityPidAlgorithm();
00326
00327 setProbabilityPidFile();
00328
00329 mEventCounter=0;
00330 mStMuDst = new StMuDst();
00331 mEmcUtil = new StMuEmcUtil();
00332 mFmsUtil = new StMuFmsUtil();
00333 mPmdUtil = new StMuPmdUtil();
00334 mTofUtil = new StMuTofUtil();
00335 mBTofUtil= new StMuBTofUtil();
00336 mEzTree = new StMuEzTree();
00337 }
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375 StMuDstMaker::~StMuDstMaker() {
00376 DEBUGMESSAGE1("");
00377
00378 if (mStMuDst && mStMuDst->TestBit(kCanDelete)) SafeDelete(mStMuDst);
00379 SafeDelete(mTofUtil);
00380 SafeDelete(mBTofUtil);
00381 DEBUGMESSAGE3("after arrays");
00382 saveDelete(mProbabilityPidAlgorithm);
00383 saveDelete(mTrackFilter);
00384 saveDelete(mL3TrackFilter);
00385 DEBUGMESSAGE3("after filter");
00386 if (mIoMode== ioWrite ) closeWrite();
00387 if (mIoMode== ioRead ) closeRead();
00388 DEBUGMESSAGE3("after close");
00389 saveDelete(mChain);
00390
00391 SafeDelete(mEmcCollectionArray);
00392 SafeDelete(mPmdCollectionArray);
00393 DEBUGMESSAGE3("out");
00394 }
00395
00396
00397
00402 void StMuDstMaker::streamerOff() {
00403 StMuEvent::Class()->IgnoreTObjectStreamer();
00404 StMuL3EventSummary::Class()->IgnoreTObjectStreamer();
00405 #ifndef __NO_STRANGE_MUDST__
00406 StStrangeMuDst::Class()->IgnoreTObjectStreamer();
00407 StV0MuDst::Class()->IgnoreTObjectStreamer();
00408 StXiMuDst::Class()->IgnoreTObjectStreamer();
00409 StKinkMuDst::Class()->IgnoreTObjectStreamer();
00410 StV0Mc::Class()->IgnoreTObjectStreamer();
00411 StXiMc::Class()->IgnoreTObjectStreamer();
00412 StKinkMc::Class()->IgnoreTObjectStreamer();
00413 #endif
00414 StMuMcVertex::Class()->IgnoreTObjectStreamer();
00415 StMuMcTrack::Class()->IgnoreTObjectStreamer();
00416 StMuTrack::Class()->IgnoreTObjectStreamer();
00417 StMuPrimaryVertex::Class()->IgnoreTObjectStreamer();
00418
00419 StMuPrimaryTrackCovariance::Class()->IgnoreTObjectStreamer();
00420 StMuHelix::Class()->IgnoreTObjectStreamer();
00421 StMuEmcHit::Class()->IgnoreTObjectStreamer();
00422 StMuEmcTowerData::Class()->IgnoreTObjectStreamer();
00423 StMuFmsHit::Class()->IgnoreTObjectStreamer();
00424 StMuPmdHit::Class()->IgnoreTObjectStreamer();
00425 StMuPmdCluster::Class()->IgnoreTObjectStreamer();
00426 EztEventHeader::Class()->IgnoreTObjectStreamer();
00427 EztTrigBlob::Class()->IgnoreTObjectStreamer();
00428 EztFpdBlob::Class()->IgnoreTObjectStreamer();
00429 EztEmcRawData::Class()->IgnoreTObjectStreamer();
00430 }
00431
00432
00433
00434 void StMuDstMaker::createArrays() {
00436 for ( int i=0; i<__NALLARRAYS__; i++) {
00437 DEBUGVALUE2(mAArrays[i]);
00438 clonesArray(mAArrays[i],StMuArrays::arrayTypes[i],StMuArrays::arraySizes[i],StMuArrays::arrayCounters[i]);
00439 DEBUGVALUE2(mAArrays[i]);
00440 }
00441 mStMuDst->set(this);
00442
00443
00444 }
00445
00446
00447
00448 TClonesArray* StMuDstMaker::clonesArray(TClonesArray*& p, const char* type, int size, int& counter) {
00449 DEBUGMESSAGE2("");
00450 if (p) return p;
00451 DEBUGVALUE2(type);
00452 p = new TClonesArray(type, size);
00453 counter=0;
00454 return p;
00455 }
00456
00457
00458
00467 int StMuDstMaker::Init(){
00468 DEBUGMESSAGE2("");
00469 mIOMaker = (StIOMaker*)GetMaker("IOMaker");
00470 mTreeMaker = (StTreeMaker*)GetMaker("outputStream");
00471 #ifndef __NO_STRANGE_MUDST__
00472 mStStrangeMuDstMaker = (StStrangeMuDstMaker*)GetMaker("strangeMuDst");
00473 #endif
00474 TDataSet *muDstSet = AddObj(mStMuDst,".const");
00475 if (muDstSet ) muDstSet ->SetName("muDst");
00476
00477 return 0;
00478 }
00479
00480
00481
00482 void StMuDstMaker::Clear(const char *){
00483 DEBUGMESSAGE2("");
00484 if (mIoMode==ioRead)
00485 return;
00486 clearArrays();
00487 if(mStMuDst->event()) mStMuDst->event()->fmsTriggerDetector().clearFlag();
00488
00489 DEBUGMESSAGE3("out");
00490 }
00491
00492
00493
00500 int StMuDstMaker::Make(){
00501
00502 DEBUGMESSAGE2("");
00503 int returnStarCode = kStOK;
00504 StTimer timer;
00505 timer.start();
00506 if (mIoMode == ioWrite) returnStarCode = MakeWrite();
00507 else if (mIoMode == ioRead) returnStarCode = MakeRead();
00508 DEBUGVALUE2(timer.elapsedTime());
00509 return returnStarCode;
00510
00511
00512 }
00513
00514
00515
00516 Int_t StMuDstMaker::MakeRead(const StUKey &RunEvent)
00517 {
00518 return MakeRead();
00519 }
00520
00521
00522
00523 Int_t StMuDstMaker::MakeRead()
00524 {
00525 int returnStarCode = kStOK;
00526 if (mIoMode == ioRead) {
00527 try {
00528 read();
00529 }
00530 catch(StMuExceptionEOF e) {
00531 e.print();
00532 returnStarCode = kStEOF;
00533 }
00534 catch(StMuException e) {
00535 e.print();
00536 returnStarCode = kStERR;
00537 }
00538 }
00539 return returnStarCode;
00540 }
00541
00542
00543
00544
00545 Int_t StMuDstMaker::MakeWrite(){
00546 int returnStarCode = kStOK;
00547 if (mIoMode == ioWrite) {
00548 try {
00549 write();
00550 }
00551 catch(StMuExceptionEOF e) {
00552 e.print();
00553 returnStarCode = kStEOF;
00554 }
00555 catch(StMuException e) {
00556 e.print();
00557 returnStarCode = kStERR;
00558 }
00559 }
00560 return returnStarCode;
00561 }
00562
00563
00564
00565 void StMuDstMaker::fill(){
00566 DEBUGMESSAGE2("");
00567 mStEvent = (StEvent*) GetInputDS("StEvent");
00568 if (!mStEvent) {
00569 DEBUGMESSAGE2("no StEvent");
00570 throw StMuExceptionNullPointer("no StEvent",__PRETTYF__);
00571 }
00574 if (mProbabilityPidAlgorithm) SafeDelete(mProbabilityPidAlgorithm);
00575 mProbabilityPidAlgorithm = new StuProbabilityPidAlgorithm(*mStEvent);
00576 StMuTrack::setProbabilityPidAlgorithm(mProbabilityPidAlgorithm);
00577 StMuTrack::setProbabilityPidCentrality(uncorrectedNumberOfNegativePrimaries(*mStEvent));
00578 try {
00579 fillTrees(mStEvent);
00580 }
00581 catch(StMuException e) {
00582 e.print();
00583 throw e;
00584 }
00585 }
00586
00587
00588
00589 void StMuDstMaker::write(){
00590 DEBUGMESSAGE2("");
00591 try {
00592 fill();
00593 }
00594 catch (StMuException e) {
00595 e.print();
00596 return;
00597 }
00598
00599 string ioMakerFileName;
00600 string theFileName("/dev/null");
00601 DEBUGVALUE2(mIoNameMode);
00602 switch (mIoNameMode) {
00603 case ioFix:
00604 DEBUGMESSAGE2("===> ioFix\n");
00605 theFileName = buildFileName( mDirName+"/", basename(mFileName),".MuDst.root");
00606 break;
00607 case ioIOMaker:
00608 DEBUGMESSAGE2("===> ioIOMaker\n");
00609 ioMakerFileName = string(mIOMaker->GetFile());
00610 DEBUGVALUE2(ioMakerFileName);
00611 theFileName = buildFileName( mDirName+"/", basename(ioMakerFileName),".MuDst.root");
00612 break;
00613 case ioTreeMaker:
00614
00615 ioMakerFileName = mTreeMaker->GetTree()->GetBaseName();
00616 theFileName = buildFileName(dirname(ioMakerFileName),basename(ioMakerFileName),".MuDst.root");
00617 break;
00618 default:
00619 DEBUGMESSAGE("do not know where to get the filename from");
00620 }
00621
00622 DEBUGVALUE2(theFileName.c_str());
00623
00624 if (theFileName != mCurrentFileName) {
00625 closeWrite();
00626 openWrite(theFileName);
00627 mCurrentFileName = theFileName;
00628 }
00629
00630 DEBUGMESSAGE2("now fill tree");
00631 mTTree->Fill(); THack::IsTreeWritable(mTTree);
00632 DEBUGMESSAGE2("tree filled");
00633
00634 return;
00635 }
00636
00637
00638
00639 int StMuDstMaker::Finish() {
00640 DEBUGMESSAGE2("");
00641 if (mFinish) {
00642 for ( int i=0; i<10; i++) {
00643 LOG_INFO << "why are you calling the Finish() again ???????" << endl;
00644 LOG_INFO << "are you the stupid chain destructor ???????????" << endl;
00645 }
00646 }
00647 else {
00648 if (mIoMode== ioWrite ) closeWrite();
00649 if (mIoMode== ioRead ) closeRead();
00650 mFinish = true;
00651 }
00652 DEBUGMESSAGE3("out");
00653 return 0;
00654 }
00655
00656 const char* StMuDstMaker::GetFile() const {
00657 if (mIoMode== ioWrite ) return mCurrentFileName.c_str();
00658 if (mIoMode== ioRead && mChain && mChain->GetFile())
00659 return mChain->GetFile()->GetName();
00660 return 0;
00661 }
00662
00663
00664 void StMuDstMaker::setBranchAddresses() {
00665 setBranchAddresses(mChain);
00666 }
00667
00668 void StMuDstMaker::setBranchAddresses(TChain* chain) {
00669
00670 if (!chain) return;
00671 chain->SetBranchStatus("*",0);
00672 TString ts;
00673 Int_t emc_oldformat=0;
00674 Int_t pmd_oldformat=0;
00675 for ( int i=0; i<__NALLARRAYS__; i++) {
00676 if (mStatusArrays[i]==0) continue;
00677 const char *bname=StMuArrays::arrayNames[i];
00678 TBranch *tb = chain->GetBranch(bname);
00679 if(!tb) {
00680 #ifndef __NO_STRANGE_MUDST__
00681 if (i >= __NARRAYS__+__NSTRANGEARRAYS__+__NMCARRAYS__ &&
00682 i < __NARRAYS__+__NSTRANGEARRAYS__+__NMCARRAYS__+__NEMCARRAYS__) {
00683 emc_oldformat=1;
00684 continue;
00685 }
00686
00687 if (i >= __NARRAYS__+__NSTRANGEARRAYS__+__NMCARRAYS__+__NEMCARRAYS__ &&
00688 i < __NARRAYS__+__NSTRANGEARRAYS__+__NMCARRAYS__+__NEMCARRAYS__+__NPMDARRAYS__) {
00689 pmd_oldformat=1;
00690 continue;
00691 }
00692 #else
00693 if (i >= __NARRAYS__+__NMCARRAYS__ &&
00694 i < __NARRAYS__+__NMCARRAYS__+__NEMCARRAYS__) {
00695 emc_oldformat=1;
00696 continue;
00697 }
00698
00699 if (i >= __NARRAYS__+__NMCARRAYS__+__NEMCARRAYS__ &&
00700 i < __NARRAYS__+__NMCARRAYS__+__NEMCARRAYS__+__NPMDARRAYS__) {
00701 pmd_oldformat=1;
00702 continue;
00703 }
00704 #endif
00705 Warning("setBranchAddresses","Branch name %s does not exist",bname);
00706 continue;
00707 }
00708 ts = bname; ts +="*";
00709 chain->SetBranchStatus (ts,1);
00710 if (strstr("MuEvent",bname) && mChain->GetBranch("MuEvent.mQA.fX")) {
00711
00712
00713 mChain->SetBranchStatus("MuEvent.mQA*",0);
00714 mChain->SetBranchStatus("MuEvent.mQB*",0);
00715 mChain->SetBranchStatus("MuEvent.mQNegEastA*",0);
00716 mChain->SetBranchStatus("MuEvent.mQNegEastB*",0);
00717 mChain->SetBranchStatus("MuEvent.mQPosEastA*",0);
00718 mChain->SetBranchStatus("MuEvent.mQPosEastB*",0);
00719 mChain->SetBranchStatus("MuEvent.mQNegWestA*",0);
00720 mChain->SetBranchStatus("MuEvent.mQNegWestB*",0);
00721 mChain->SetBranchStatus("MuEvent.mQPosWestA*",0);
00722 mChain->SetBranchStatus("MuEvent.mQPosWestB*",0);
00723 }
00724 chain->SetBranchAddress(bname,mAArrays+i);
00725 assert(tb->GetAddress() == (char*)(mAArrays+i));
00726 }
00727 if (emc_oldformat) {
00728 TBranch *branch=chain->GetBranch("EmcCollection");
00729 if (branch) {
00730 Warning("setBranchAddresses","Using backward compatibility mode for EMC");
00731 if (!mEmcCollectionArray) {
00732 mEmcCollectionArray=new TClonesArray("StMuEmcCollection",1);
00733 }
00734 chain->SetBranchStatus("EmcCollection*",1);
00735 chain->SetBranchAddress("EmcCollection",&mEmcCollectionArray);
00736 StMuEmcHit::Class()->IgnoreTObjectStreamer(0);
00737 mStMuDst->set(this);
00738 }
00739 }
00740 else if (!mEmcCollection) {
00741 mEmcCollection=new StMuEmcCollection();
00742 connectEmcCollection();
00743 mStMuDst->set(this);
00744 }
00745
00746 if (!mFmsCollection) {
00747 mFmsCollection=new StMuFmsCollection();
00748 connectFmsCollection();
00749 mStMuDst->set(this);
00750 }
00751
00752 if (pmd_oldformat) {
00753 TBranch *branch=chain->GetBranch("PmdCollection");
00754 if (branch) {
00755 Warning("setBranchAddresses","Using backward compatibility mode for PMD");
00756 if (!mPmdCollectionArray) {
00757 mPmdCollectionArray=new TClonesArray("StMuPmdCollection",1);
00758 }
00759 chain->SetBranchStatus("PmdCollection*",1);
00760 chain->SetBranchAddress("PmdCollection",&mPmdCollectionArray);
00761 StMuPmdCluster::Class()->IgnoreTObjectStreamer(0);
00762 mStMuDst->set(this);
00763 }
00764 }
00765 else if (!mPmdCollection) {
00766 mPmdCollection=new StMuPmdCollection();
00767 connectPmdCollection();
00768 mStMuDst->set(this);
00769 }
00770 mTTree = mChain->GetTree();
00771 }
00772
00773
00774
00775 int StMuDstMaker::openRead() {
00776 DEBUGVALUE2(mDirName.c_str());
00777 DEBUGVALUE2(mFileName.c_str());
00778 DEBUGVALUE2(mFilter.c_str());
00779
00780 StMuChainMaker chainMaker("MuDst");
00781 mChain = chainMaker.make(mDirName, mFileName, mFilter, mMaxFiles);
00782
00783 if (mChain){
00784 DEBUGVALUE3(mChain);
00785 setBranchAddresses(mChain);
00786
00787 mStMuDst->set(this);
00788 }
00789
00790 return 0;
00791 }
00792
00793
00794
00795 void StMuDstMaker::read(){
00796 if (!mChain){
00797 DEBUGMESSAGE2("ATTENTION: No StMuChain ... results won't be exciting (nothing to do)");
00798 throw StMuExceptionNullPointer("No input files",__PRETTYF__);
00799 return;
00800 }
00801
00802 DEBUGMESSAGE2("");
00803 if (mChain->GetCurrentFile()) {
00804 DEBUGVALUE2(mChain->GetCurrentFile()->GetName());
00805 }
00806
00807 if ( !mEventList ) {
00808 int bytes = mChain->GetEntry(mEventCounter++);
00809 while (bytes<=0 ) {
00810 DEBUGVALUE3(mEventCounter);
00811 if ( mEventCounter >= mChain->GetEntriesFast() ) throw StMuExceptionEOF("end of input",__PRETTYF__);
00812 bytes = mChain->GetEntry(mEventCounter++);
00813 DEBUGVALUE3(bytes);
00814 }
00815 }
00816 else {
00817 int bytes = mChain->GetEntry( mEventList->GetEntry( mEventCounter++ ) );
00818 while ( bytes<=0 ) {
00819 DEBUGVALUE3(mEventCounter);
00820 if ( mEventCounter >= mEventList->GetN() ) throw StMuExceptionEOF("end of event list",__PRETTYF__);
00821 bytes = mChain->GetEntry( mEventList->GetEntry( mEventCounter++ ) );
00822 DEBUGVALUE3(bytes);
00823 }
00824 }
00825 if (GetDebug()>1) printArrays();
00826 mStMuDst->set(this);
00827 fillHddr();
00828 mStMuDst->setVertexIndex(0);
00829 mStMuDst->collectVertexTracks();
00830 return;
00831 }
00832
00833
00834
00835 void StMuDstMaker::closeRead(){
00836 DEBUGMESSAGE2("");
00837 if (mChain) mChain->Delete();
00838 mChain = 0;
00839 }
00840
00841
00842
00843 void StMuDstMaker::openWrite(string fileName) {
00844 DEBUGVALUE2(fileName.c_str());
00845
00846 DEBUGMESSAGE2("now create file");
00847 mCurrentFile = new TFile(fileName.c_str(),"RECREATE","StMuDst");
00848
00849 if (mCurrentFile->IsZombie()) throw StMuExceptionNullPointer("no file openend",__PRETTYF__);
00850
00851 mCurrentFile->SetCompressionLevel(mCompression);
00852
00853
00854 DEBUGMESSAGE2("now create trees and branches");
00855
00856 TBranch* branch;
00857 int bufsize = mBufferSize;
00858 if (mSplit) bufsize /= 4;
00859
00860 mTTree = new TTree("MuDst", "StMuDst",mSplit);
00861 #if ROOT_VERSION_CODE < ROOT_VERSION(5,26,0)
00862 Long64_t MAXLONG=100000000000LL;
00863 LOG_INFO << "Tree size MAX will be " << (float) MAXLONG/1000/1000/1000 << " GB " << endm;
00864 mTTree->SetMaxTreeSize(MAXLONG);
00865 #endif
00866
00867 DEBUGMESSAGE2("all arrays");
00868 for ( int i=0; i<__NALLARRAYS__; i++) {
00869 if (mStatusArrays[i]==0) continue;
00870 branch = mTTree->Branch(StMuArrays::arrayNames[i],&mAArrays[i], bufsize, mSplit);
00871 }
00872 mCurrentFileName = fileName;
00873 }
00874
00875
00876
00877 void StMuDstMaker::closeWrite(){
00878 DEBUGMESSAGE(__PRETTYF__);
00879 if (mTTree && mCurrentFile) {
00880 LOG_INFO << " ##### " << __PRETTYF__ << endm;
00881 LOG_INFO << " ##### File=" << mCurrentFile->GetName() << " ";
00882 LOG_INFO << " NumberOfEvents= " << mTTree->GetEntries() << " ";
00883 LOG_INFO << " ##### " << endm;
00884 }
00885
00886
00887 if (mCurrentFile) {
00888 mCurrentFile->Write();
00889 mCurrentFile->Close();
00890 }
00891 mTTree = 0;
00892 mCurrentFile = 0;
00893 }
00894
00895
00896
00897 void StMuDstMaker::fillTrees(StEvent* ev, StMuCut* cut){
00898
00899 DEBUGMESSAGE2("");
00900 try {
00901 fillMC();
00902 }
00903 catch(StMuException e) {
00904 e.print();
00905 throw e;
00906 }
00907
00908 try {
00909 fillEvent(ev);
00910 fillL3AlgorithmInfo(ev);
00911 fillDetectorStates(ev);
00912 fillEmc(ev);
00913 fillPmd(ev);
00914 fillFms(ev);
00915 fillTof(ev);
00916 fillBTof(ev);
00917 fillEzt(ev);
00918 }
00919 catch(StMuException e) {
00920 e.print();
00921 throw e;
00922 }
00923
00924 try {
00925 fillVertices(ev);
00926 }
00927 catch(StMuException e) {
00928 e.print();
00929 throw e;
00930 }
00931
00932 try {
00933 fillpp2pp(ev);
00934 }
00935 catch(StMuException e) {
00936 e.print();
00937 throw e;
00938 }
00939 try {
00940 fillmtd(ev);
00941 }
00942 catch(StMuException e) {
00943 e.print();
00944 throw e;
00945 }
00946 try {
00947 fillTracks(ev,mTrackFilter);
00948 }
00949 catch(StMuException e) {
00950 e.print();
00951 throw e;
00952 }
00953 try {
00954 fillL3Tracks(ev, mL3TrackFilter);
00955 }
00956 catch(StMuException e) {
00957 e.print();
00958 throw e;
00959 }
00960 #ifndef __NO_STRANGE_MUDST__
00961 if (mStStrangeMuDstMaker) {
00962 try {
00963 fillStrange(mStStrangeMuDstMaker);
00964 }
00965 catch(StMuException e) {
00966 e.print();
00967 throw e;
00968 }
00969 }
00970 #endif
00971 mStMuDst->set(this);
00972 mStMuDst->fixTofTrackIndices();
00973 mStMuDst->fixTrackIndicesG(mStMuDst->numberOfPrimaryVertices());
00974 }
00975
00976
00977
00978
00979
00980
00981 void StMuDstMaker::fillEvent(StEvent* ev, StMuCut* cut) {
00982 DEBUGMESSAGE2("");
00983 StMuEvent *typeOfEvent=0;
00984 if (!ev) throw StMuExceptionNullPointer("no StEvent",__PRETTYF__);
00985 StTimer timer;
00986 timer.start();
00987 if (!cut || cut->pass(ev)) {
00988 DEBUGMESSAGE3("");
00989 addType(mArrays[muEvent],ev,typeOfEvent);
00990 }
00991 timer.stop();
00992 DEBUGVALUE2(timer.elapsedTime());
00993 }
00994
00995
00996
00997 void StMuDstMaker::fillEmc(StEvent* ev) {
00998 DEBUGMESSAGE2("");
00999 StEmcCollection* emccol=(StEmcCollection*)ev->emcCollection();
01000 if (!emccol) return;
01001 StTimer timer;
01002 timer.start();
01003
01004 TClonesArray *tca = mEmcArrays[muEmcTow];
01005 new((*tca)[0]) StMuEmcTowerData();
01006 if (!mEmcCollection) {
01007 mEmcCollection=new StMuEmcCollection();
01008 connectEmcCollection();
01009 mStMuDst->set(this);
01010 }
01011 mEmcUtil->fillMuEmc(mEmcCollection,emccol);
01012
01013 timer.stop();
01014 DEBUGVALUE2(timer.elapsedTime());
01015 }
01016
01017
01018 void StMuDstMaker::fillFms(StEvent* ev) {
01019 DEBUGMESSAGE2("");
01020 StFmsCollection* fmscol=(StFmsCollection*)ev->fmsCollection();
01021 if (!fmscol) return;
01022 StTimer timer;
01023 timer.start();
01024
01025 if (!mFmsCollection) {
01026 mFmsCollection=new StMuFmsCollection();
01027 connectFmsCollection();
01028 mStMuDst->set(this);
01029 }
01030 mFmsUtil->fillMuFms(mFmsCollection,fmscol);
01031
01032 timer.stop();
01033 DEBUGVALUE2(timer.elapsedTime());
01034 }
01035
01036
01037 void StMuDstMaker::fillPmd(StEvent* ev) {
01038 DEBUGMESSAGE2("");
01039 StPhmdCollection* phmdColl=(StPhmdCollection*)ev->phmdCollection();
01040 if (!phmdColl) return;
01041 StTimer timer;
01042 timer.start();
01043
01044 if (!mPmdCollection) {
01045 mPmdCollection=new StMuPmdCollection();
01046 connectPmdCollection();
01047 mStMuDst->set(this);
01048 }
01049 mPmdUtil->fillMuPmd(phmdColl,mPmdCollection);
01050
01051 timer.stop();
01052 DEBUGVALUE2(timer.elapsedTime());
01053 }
01054
01055
01056
01057
01058 void StMuDstMaker::fillTof(StEvent* ev) {
01059 DEBUGMESSAGE2("");
01060 StTofCollection *tofcol = ev->tofCollection();
01061
01062 if( !ev || !tofcol || (!tofcol->dataPresent()&&!tofcol->rawdataPresent()) )
01063 return;
01064 StTimer timer;
01065 timer.start();
01066
01067
01068 StMuTofHitCollection muTofHitColl;
01069 mTofUtil->fillMuTofHit(&muTofHitColl, tofcol);
01070 for(size_t i=0; i < muTofHitColl.size(); i++) {
01071 StMuTofHit* tofMuHit = (StMuTofHit *)muTofHitColl.getHit(i);
01072 addType( mTofArrays[muTofHit], *tofMuHit );
01073 }
01074
01075
01076 StSPtrVecTofData &tofData = tofcol->tofData();
01077 for(size_t i=0; i < tofData.size(); i++) {
01078 addType( mTofArrays[muTofData], *tofData[i] );
01079 }
01080
01081
01082
01083 StSPtrVecTofRawData &tofRawData = tofcol->tofRawData();
01084 for(size_t i=0; i < tofRawData.size(); i++) {
01085 addType( mTofArrays[muTofRawData], *tofRawData[i] );
01086 }
01087
01088 timer.stop();
01089 DEBUGVALUE2(timer.elapsedTime());
01090 }
01091
01092
01093
01095 void StMuDstMaker::fillBTof(StEvent* ev) {
01096 DEBUGMESSAGE2("");
01097 StBTofCollection *btofcol = ev->btofCollection();
01098 if( !ev || !btofcol || !btofcol->rawHitsPresent() )
01099 return;
01100 StTimer timer;
01101 timer.start();
01102
01103
01104 StMuBTofHitCollection muBTofHitColl;
01105 mBTofUtil->fillMuBTofHit(&muBTofHitColl, btofcol);
01106 for(size_t i=0; i < muBTofHitColl.size(); i++) {
01107 StMuBTofHit* btofMuHit = (StMuBTofHit *)muBTofHitColl.getHit(i);
01108 addType( mBTofArrays[muBTofHit], *btofMuHit );
01109 }
01110
01111
01112 StSPtrVecBTofRawHit &btofRawHits = btofcol->tofRawHits();
01113 for(size_t i=0; i < btofRawHits.size(); i++) {
01114 addType( mBTofArrays[muBTofRawHit], *btofRawHits[i] );
01115 }
01116
01117
01118 StBTofHeader *btofHeader = btofcol->tofHeader();
01119 addType( mBTofArrays[muBTofHeader], *btofHeader);
01120
01121 timer.stop();
01122 DEBUGVALUE2(timer.elapsedTime());
01123 }
01124
01125
01126
01127 void StMuDstMaker::fillEzt(StEvent* ev) {
01128 if (ev==0) return;
01129 #ifndef __NO_STRANGE_MUDST__
01130 char *eztArrayStatus=&mStatusArrays[__NARRAYS__+__NSTRANGEARRAYS__+__NMCARRAYS__+
01131 __NEMCARRAYS__+__NPMDARRAYS__+__NFMSARRAYS__+
01132 __NTOFARRAYS__+__NBTOFARRAYS__];
01133 #else
01134 char *eztArrayStatus=&mStatusArrays[__NARRAYS__+__NMCARRAYS__+
01135 __NEMCARRAYS__+__NPMDARRAYS__+__NFMSARRAYS__+
01136 __NTOFARRAYS__+__NBTOFARRAYS__];
01137 #endif
01138 if(eztArrayStatus[muEztHead]){
01139 EztEventHeader* header = mEzTree->copyHeader(ev);
01140 addType(mEztArrays[muEztHead], *header);
01141 }
01142
01143 if(eztArrayStatus[muEztTrig]) {
01144 EztTrigBlob* trig = mEzTree->copyTrig(ev);
01145 if (trig)
01146 addType(mEztArrays[muEztTrig], *trig);
01147 }
01148
01149 if(eztArrayStatus[muEztFpd]) {
01150 EztFpdBlob* fpd = mEzTree->copyFpd(ev);
01151 addType(mEztArrays[muEztFpd], *fpd);
01152 }
01153
01154 if(eztArrayStatus[muEztETow] || eztArrayStatus[muEztESmd]) {
01155 StEmcCollection* emcCol=(StEmcCollection*)ev->emcCollection();
01156 if(emcCol==0){
01157 gMessMgr->Message("","W") << GetName()<<"::fillEzt(), missing StEmcCollection, EEMC raw data NOT saved in muDst" <<endm;
01158 } else {
01159 StEmcRawData *eeRaw=emcCol->eemcRawData();
01160
01161 if(eztArrayStatus[muEztETow]) {
01162 EztEmcRawData* ETow = mEzTree->copyETow(eeRaw);
01163 addType(mEztArrays[muEztETow], *ETow);
01164 }
01165
01166 if(eztArrayStatus[muEztESmd]) {
01167 EztEmcRawData* ESmd = mEzTree->copyESmd(eeRaw);
01168 addType(mEztArrays[muEztESmd], *ESmd);
01169 }
01170 }
01171 }
01172 }
01173
01174
01175
01176 void StMuDstMaker::fillL3AlgorithmInfo(StEvent* ev) {
01177 DEBUGMESSAGE2("");
01178 if ( !ev->l3Trigger() ) return;
01179 if ( !ev->l3Trigger()->l3EventSummary()) return;
01180
01181 StTimer timer;
01182 timer.start();
01183 StL3EventSummary* l3 = ev->l3Trigger()->l3EventSummary();
01184 int n = l3->numberOfAlgorithms();
01185 for (int i=0; i<n; i++) {
01186 if (l3->algorithms()[i]->accept())
01187 addType( mArrays[muAccept], *l3->algorithms()[i] );
01188 else
01189 addType( mArrays[muReject], *l3->algorithms()[i] );
01190 }
01191 timer.stop();
01192 DEBUGVALUE2(timer.elapsedTime());
01193 }
01194
01195
01196
01197 void StMuDstMaker::fillVertices(StEvent* ev) {
01198 DEBUGMESSAGE2("");
01199 StTimer timer;
01200 timer.start();
01201
01202 StMuPrimaryVertex *typeOfVertex=0;
01203 Int_t n_vtx = ev->numberOfPrimaryVertices();
01204 DEBUGVALUE2(n_vtx);
01205 mVtxList.Clear();
01206 for (Int_t i_vtx=0; i_vtx < n_vtx; i_vtx++) {
01207 const StPrimaryVertex *vtx=ev->primaryVertex(i_vtx);
01208 addType( mArrays[muPrimaryVertex], vtx, typeOfVertex );
01209 mVtxList.AddAtAndExpand(ev->primaryVertex(i_vtx),i_vtx);
01210 }
01211 timer.stop();
01212 DEBUGVALUE2(timer.elapsedTime());
01213 }
01214
01215
01216 void StMuDstMaker::fillpp2pp(StEvent* ev) {
01217 DEBUGMESSAGE2("");
01218 StTimer timer;
01219 timer.start();
01220
01221 StMuRpsCollection *typeOfRps=0;
01222
01223 const StRpsCollection *rps=ev->rpsCollection();
01224 if (rps) addType( mArrays[mupp2pp], *rps, typeOfRps );
01225 timer.stop();
01226 DEBUGVALUE2(timer.elapsedTime());
01227 }
01228
01229 void StMuDstMaker::fillmtd(StEvent* ev) {
01230 DEBUGMESSAGE2("");
01231 StTimer timer;
01232 timer.start();
01233
01234 StMuMtdCollection *typeOfMtd=0;
01235
01236 const StMtdCollection *mtd=ev->mtdCollection();
01237 if (mtd) addType( mArrays[muMtd], *mtd, typeOfMtd );
01238 timer.stop();
01239 DEBUGVALUE2(timer.elapsedTime());
01240 }
01241
01242
01243
01244
01245 void StMuDstMaker::fillTracks(StEvent* ev, StMuCut* cut) {
01246 DEBUGMESSAGE2("");
01247 StTimer timer;
01248 timer.start();
01249
01250 StSPtrVecTrackNode& nodes= ev->trackNodes();
01251 DEBUGVALUE2(nodes.size());
01252 for (StSPtrVecTrackNodeConstIterator iter=nodes.begin(); iter!=nodes.end(); iter++) {
01253 addTrackNode(ev, *iter, cut, mArrays[muGlobal], mArrays[muPrimary], mArrays[muOther], mArrays[muCovGlobTrack], mArrays[muCovPrimTrack], false);
01254 }
01255 timer.stop();
01256 DEBUGVALUE2(timer.elapsedTime());
01257 }
01258
01259
01260
01261 void StMuDstMaker::fillL3Tracks(StEvent* ev, StMuCut* cut) {
01262 DEBUGMESSAGE2("");
01263 if (!ev->l3Trigger()) return;
01264
01265 StTimer timer;
01266 timer.start();
01267 StSPtrVecTrackNode& nodes= ev->l3Trigger()->trackNodes();
01268 DEBUGVALUE2(nodes.size());
01269 for (StSPtrVecTrackNodeConstIterator iter=nodes.begin(); iter!=nodes.end(); iter++) {
01270 addTrackNode(ev, *iter, cut, mArrays[muL3], 0, 0, 0, 0, true );
01271 }
01272 timer.stop();
01273 DEBUGVALUE2(timer.elapsedTime());
01274 }
01275
01276
01277
01278 void StMuDstMaker::fillDetectorStates(StEvent* ev) {
01279 DEBUGMESSAGE2("");
01280 StTimer timer;
01281 timer.start();
01282 for (int i=0; i<StMuArrays::arraySizes[muState]; i++) {
01283 StDetectorState* state = ev->detectorState((StDetectorId) i);
01284 if (state) {
01285 addType( mArrays[muState], *state );
01286 }
01287 }
01288 timer.stop();
01289 DEBUGVALUE2(timer.elapsedTime());
01290 }
01291
01292
01293
01294 void StMuDstMaker::addTrackNode(const StEvent* ev, const StTrackNode* node, StMuCut* cut,
01295 TClonesArray* gTCA, TClonesArray* pTCA, TClonesArray* oTCA, TClonesArray* covgTCA, TClonesArray* covpTCA, bool l3) {
01296 DEBUGMESSAGE3("");
01297 const StTrack* tr=0;
01298
01300 int index2Global =-1;
01301 if (gTCA) {
01302 const StTrack *pr_tr = node->track(primary);
01303 const StVertex *vtx = 0;
01304 if (pr_tr)
01305 vtx = pr_tr->vertex();
01306 if (vtx==0)
01307 vtx = ev->primaryVertex();
01308
01309 tr= node->track(global);
01310 if (tr && !tr->bad()) index2Global = addTrack(gTCA, ev, tr, vtx, cut, -1, l3, covgTCA, covpTCA);
01311 }
01313 int index;
01314 if (pTCA) {
01315 tr = node->track(primary);
01316 if (tr && !tr->bad()) index = addTrack(pTCA, ev, tr, tr->vertex(), cut, index2Global, l3, covgTCA, covpTCA);
01317 }
01319 if (oTCA) {
01320 size_t nEntries = node->entries();
01321 for (size_t j=0; j<nEntries; j++) {
01322 tr = node->track(j);
01323 if (tr && !tr->bad() && (tr->type()!=global) && (tr->type()!=primary) ) {
01324 index = addTrack(oTCA, ev, tr, tr->vertex(), cut, index2Global, l3);
01325 }
01326 }
01327 }
01328 }
01329
01330
01331
01332 int StMuDstMaker::addTrack(TClonesArray* tca, const StEvent*event, const StTrack* track, const StVertex *vtx, StMuCut* cut, int index2Global, bool l3,
01333 TClonesArray* covgTCA, TClonesArray* covpTCA) {
01334 DEBUGMESSAGE3("");
01335 StRichSpectra typeOfStRichSpectra;
01336 int index = -1;
01337 int index2RichSpectra=-1;
01339 int counter = tca->GetEntries();
01340 try{
01341 if (cut && !cut->pass(track)) throw StMuExceptionBadValue("failed track cut",__PRETTYF__);
01342
01343
01344 StRichSpectra* rich = richSpectra(track);
01345 if (rich) {
01346 index2RichSpectra = addType( mArrays[muRich], *rich );
01347 }
01348 StMuTrack *muTrack = new((*tca)[counter]) StMuTrack(event, track, vtx, index2Global, index2RichSpectra, l3, &mVtxList);
01349 if (track->type() == primary) {
01350 if (covpTCA) {
01351 Int_t countCOVPTCA = covpTCA->GetEntries();
01352 #if 0
01353 const StMatrixF covMatrix = track->fitTraits().covariantMatrix();
01354 new((*covpTCA)[countCOVPTCA]) StMuPrimaryTrackCovariance(covMatrix);
01355 #else
01356
01357 const Float_t* cov = track->fitTraits().covariance();
01358 new((*covpTCA)[countCOVPTCA]) StMuPrimaryTrackCovariance(cov);
01359 #endif
01360 muTrack->setIndex2Cov(countCOVPTCA);
01361 }
01362 }
01363 else {
01364 if (track->type() == global) {
01365 if (covgTCA) {
01366 Int_t countCOVGTCA = covgTCA->GetEntries();
01367 const StDcaGeometry *dcaGeometry = ((StGlobalTrack *)track)->dcaGeometry();
01368 if (dcaGeometry) {
01369 new((*covgTCA)[countCOVGTCA]) StDcaGeometry(*dcaGeometry);
01370 muTrack->setIndex2Cov(countCOVGTCA);
01371 }
01372 }
01373 }
01374 }
01375 index = counter;
01376 }
01377 catch (StMuException e) {
01378 IFDEBUG3(e.print());
01379 }
01380 return index;
01381 }
01382
01383
01384
01385 StRichSpectra* StMuDstMaker::richSpectra(const StTrack* track) {
01386 DEBUGMESSAGE3("");
01387 const StPtrVecTrackPidTraits& traits = track->pidTraits(kRichId);
01388 for (StPtrVecTrackPidTraitsConstIterator traitIter=traits.begin();traitIter!=traits.end();++traitIter) {
01389 StRichPidTraits* pid = dynamic_cast<StRichPidTraits*>(*traitIter);
01390 if (pid) return pid->getRichSpectra();
01391 }
01392 return 0;
01393 }
01394 #ifndef __NO_STRANGE_MUDST__
01395 void StMuDstMaker::fillStrange(StStrangeMuDstMaker* maker) {
01396 DEBUGMESSAGE2("");
01398 if (!maker) throw StMuExceptionNullPointer("no StrangeMuDstMaker",__PRETTYF__);
01399
01400 StStrangeEvMuDst *ev=0;
01401 StV0MuDst *v0=0;
01402 StStrangeAssoc *assoc=0;
01403 StXiMuDst *xi=0;
01404 StKinkMuDst *kink=0;
01405 StV0Mc *v0Mc=0;
01406 StXiMc *xiMc=0;
01407 StKinkMc *kinkMc=0;
01408 TCut *strangeCut=0;
01409
01410 addType(maker->GetEvClonesArray(), mStrangeArrays[0],ev);
01411 addType(maker->GetEvMcArray(), mStrangeArrays[1],ev);
01412
01413 addType(maker->GetV0ClonesArray(), mStrangeArrays[2],v0);
01414 addType(maker->GetV0McArray(), mStrangeArrays[3],v0Mc);
01415 addType(maker->GetV0AssocArray(), mStrangeArrays[4],assoc);
01416
01417 addType(maker->GetXiClonesArray(), mStrangeArrays[5],xi);
01418 addType(maker->GetXiMcArray(), mStrangeArrays[6],xiMc);
01419 addType(maker->GetXiAssocArray(), mStrangeArrays[7],assoc);
01420
01421 addType(maker->GetKinkClonesArray(),mStrangeArrays[8],kink);
01422 addType(maker->GetKinkMcArray(), mStrangeArrays[9],kinkMc);
01423 addType(maker->GetKinkAssocArray(), mStrangeArrays[10],assoc);
01424
01425 addType(maker->GetCutsArray(), mStrangeArrays[11],strangeCut);
01426
01427 }
01428 #endif
01429
01430 void StMuDstMaker::fillMC() {
01431 St_g2t_track *g2t_track = (St_g2t_track *) GetDataSet("geant/g2t_track"); if (!g2t_track) return;
01432 St_g2t_vertex *g2t_vertex = (St_g2t_vertex *) GetDataSet("geant/g2t_vertex"); if (!g2t_vertex) return;
01433 StG2TrackVertexMap::instance(g2t_track,g2t_vertex);
01434 mStEvent->setIdTruth();
01435 StMuMcVertex *mcvx = 0;
01436 StMuMcTrack *mctr = 0;
01437 g2t_vertex_st *vertex = g2t_vertex->GetTable();
01438 UInt_t NV = g2t_vertex->GetNRows();
01439 for (UInt_t i = 0; i < NV; i++) addType(mMCArrays[MCVertex], vertex[i], mcvx);
01440 g2t_track_st *track = g2t_track->GetTable();
01441 UInt_t NT = g2t_track->GetNRows();
01442 for (UInt_t i = 0; i < NT; i++) addType(mMCArrays[MCTrack], track[i], mctr);
01443
01444 }
01445
01446
01447
01448 template <class T>
01449 int StMuDstMaker::addType(TClonesArray* tcaFrom, TClonesArray* &tcaTo ,T *t) {
01450 if (tcaFrom && tcaTo) {
01451 int n = tcaFrom->GetEntries();
01452 int counter = tcaTo->GetEntries();
01453 for (int i=0; i<n;i++) {
01454
01455 new((*tcaTo)[counter++]) T( *(T*)(void*)tcaFrom->UncheckedAt(i) );
01456 }
01457 }
01458 return 0;
01459 }
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475 template <class T>
01476 int StMuDstMaker::addType(TClonesArray* tcaTo ,T &t) {
01477 int counter =-1;
01478 if (tcaTo) {
01479 counter = tcaTo->GetEntries();
01480 new((*tcaTo)[counter]) T( t );
01481 }
01482 return counter;
01483 }
01484
01485
01486
01487 template <class T, class U>
01488 int StMuDstMaker::addType(TClonesArray* tcaTo ,U &u,T *t) {
01489 int counter =-1;
01490 if (tcaTo) {
01491 counter = tcaTo->GetEntries();
01492 DEBUGMESSAGE2("");
01493 new((*tcaTo)[counter]) T(u);
01494 }
01495 return counter;
01496 }
01497
01498
01499
01500 string StMuDstMaker::buildFileName(string dir, string fileName, string extention){
01501 DEBUGMESSAGE3(dir.c_str());
01502 DEBUGMESSAGE3(fileName.c_str());
01503 DEBUGMESSAGE3(extention.c_str());
01504 fileName = dir + fileName + extention;
01505 while (fileName.find("//")!=string::npos) {
01506 int pos = fileName.find("//");
01507 fileName.erase(pos,1);
01508 }
01509 return fileName;
01510 }
01511
01512
01513
01514 string StMuDstMaker::basename(string s){
01515 DEBUGVALUE3(s.c_str());
01516 string name(s);
01517 DEBUGVALUE3(name.c_str());
01518 size_t pos;
01519 pos = name.find_last_of("/");
01520 if (pos!=string::npos ) name.erase(0, pos );
01521 DEBUGVALUE3(name.c_str());
01522 pos = name.find_last_of(".");
01523 if (pos!=string::npos ) name.erase(pos,name.length()-pos );
01524 DEBUGVALUE3(name.c_str());
01525 pos = name.find_last_of(".");
01526 if (pos!=string::npos ) name.erase(pos,name.length()-pos );
01527 DEBUGVALUE3(name.c_str());
01528 return name;
01529 }
01530
01531
01532
01533 string StMuDstMaker::dirname(string s){
01534 string name(s);
01535 DEBUGVALUE3(name.c_str());
01536 size_t pos;
01537 pos = name.find_last_of("/");
01538
01539 if (pos != string::npos ) name.erase(pos, name.length());
01540 if (name == s) name =".";
01541
01542 name=name+"/";
01543 DEBUGVALUE3(name);
01544 return name;
01545 }
01546
01547 void StMuDstMaker::setProbabilityPidFile(const char* file) {
01548 ostrstream flnm;
01549
01550 if ( ! file ){
01551 const char *PIDtable="PIDTableP01gl.root";
01552
01553 flnm << getenv("STAR") << "/StarDb/dEdxModel/" << PIDtable << ends;
01554 FORCEDDEBUGMESSAGE("ATTENTION: pid table hardwired to " << flnm.str() );
01555
01556 } else {
01557 flnm << file << ends;
01558 FORCEDDEBUGMESSAGE("Using pid table to user value " << flnm.str() );
01559 }
01560
01561
01562 if (mProbabilityPidAlgorithm)
01563 mProbabilityPidAlgorithm->readParametersFromFile(flnm.str());
01564 }
01565
01566
01567
01568 void StMuDstMaker::printArrays()
01569 {
01570
01571 TClonesArray *tcl;
01572 for ( int i=0; i<__NALLARRAYS__; i++) {
01573 if (mStatusArrays[i]==0) continue;
01574 tcl = mAArrays[i];
01575 printf(" Array %s\t = %s::%s(%d)\n",
01576 StMuArrays::arrayNames[i],
01577 tcl->ClassName(),tcl->GetName(),tcl->GetEntriesFast());
01578 }
01579
01580 }
01581
01582 void StMuDstMaker::fillHddr()
01583 {
01584 StMuEvent *me = mStMuDst->event();
01585 if (me==0)
01586 return;
01587 StEventInfo &ei = me->eventInfo();
01588 StRunInfo &ri = me->runInfo();
01589 StEvtHddr *hd = GetEvtHddr();
01590
01591 hd->SetRunNumber(ei.runId()) ;
01592 hd->SetEventType(ei.type().Data());
01593 hd->SetTriggerMask(ei.triggerMask()) ;
01594
01595 hd->SetBunchCrossingNumber(ei.bunchCrossingNumber(0),ei.bunchCrossingNumber(1));
01596 hd->SetCenterOfMassEnergy(ri.centerOfMassEnergy());
01597
01598
01599
01600
01601
01602
01603
01604
01605 hd->SetGMTime((unsigned int)ei.time());
01606 hd->SetProdDateTime(ri.productionTime());
01607
01608 hd->SetEventSize(ei.eventSize());
01609 hd->SetEventNumber(ei.id()) ;
01610
01611 }
01612
01613
01614 void StMuDstMaker::connectEmcCollection() {
01615 mEmcCollection->setTowerData((StMuEmcTowerData*)(*(mEmcArrays[muEmcTow]))[0]);
01616 mEmcCollection->setPrsArray(2,mEmcArrays[muEmcPrs]);
01617 mEmcCollection->setSmdArray(3,mEmcArrays[muEmcSmde]);
01618 mEmcCollection->setSmdArray(4,mEmcArrays[muEmcSmdp]);
01619 mEmcCollection->setPrsArray(6,mEmcArrays[muEEmcPrs]);
01620 mEmcCollection->setSmdArray(7,mEmcArrays[muEEmcSmdu]);
01621 mEmcCollection->setSmdArray(8,mEmcArrays[muEEmcSmdv]);
01622 }
01623
01624 void StMuDstMaker::connectFmsCollection() {
01625 mFmsCollection->setFmsHitArray(mFmsArrays[muFmsHit]);
01626 }
01627
01628 void StMuDstMaker::connectPmdCollection() {
01629 mPmdCollection->setPmdHitArray(mPmdArrays[muPmdHit]);
01630 mPmdCollection->setCpvHitArray(mPmdArrays[muCpvHit]);
01631 mPmdCollection->setPmdClusterArray(mPmdArrays[muPmdCluster]);
01632 mPmdCollection->setCpvClusterArray(mPmdArrays[muCpvCluster]);
01633 }
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027