00001
00002 #include "AliStHbtEventReader.h"
00003 #include <stdlib.h>
00004 #include "StChain.h"
00005 #include "TChain.h"
00006 #include "TFile.h"
00007 #include "TTree.h"
00008
00009 #include "StPhysicalHelixD.hh"
00010
00011 #include "SystemOfUnits.h"
00012
00013 #include "StIOMaker/StIOMaker.h"
00014
00015 #include "TVector3.h"
00016 #include "TString.h"
00017
00018 #include <math.h>
00019 #include <string>
00020 #include <typeinfo>
00021
00022 #include "StHbtMaker/Infrastructure/StExceptions.hh"
00023 #include "StHbtMaker/Infrastructure/StHbtTrackCollection.hh"
00024 #include "StHbtMaker/Infrastructure/StHbtEvent.hh"
00025
00026 #include "StHbtMaker/Infrastructure/StHbtVector.hh"
00027
00028 #include "StHbtMaker/Reader/AliStHbtEvent.h"
00029 #include "StHbtMaker/Reader/AliStHbtTrack.h"
00030
00031 #include "StarClassLibrary/StMemoryInfo.hh"
00032
00033 ClassImp(AliStHbtEventReader)
00034
00035 #if !(ST_NO_NAMESPACES)
00036 using namespace units;
00037 #endif
00038
00039
00040
00041 AliStHbtEventReader::AliStHbtEventReader(StHbtIOMode mode, StIOMaker* io,
00042 const char* dirName, const char* fileName,
00043 const char* filter, int maxFiles)
00044 : mIOMaker(io), mIOMode(mode), mMaxFiles(maxFiles), mDebug(0), mCurrentFile(0),
00045 mTTree(0) {
00046 if (mDebug) cout << "AliStHbtEventReader::AliStHbtEventReader(...)"<< endl;
00047
00048 mDir = string(dirName);
00049 mFile = string(fileName);
00050 mFilter = string(filter);
00051 mReaderStatus = 0;
00052 mEvent = new AliStHbtEvent;
00053 if (mDebug) cout << "AliStHbtEventReader::AliStHbtEventReader(...) - leaving"<< endl;
00054 }
00055
00056
00057 AliStHbtEventReader::~AliStHbtEventReader(){
00058 if (mCurrentFile) { mCurrentFile->Close(); delete mCurrentFile; mCurrentFile = 0;}
00059 }
00060
00061
00062 StHbtString AliStHbtEventReader::Report(){
00063 StHbtString temp = "\n This is the AliStHbtEventReader\n";
00064 return temp;
00065 }
00066
00067
00068 StHbtEvent* AliStHbtEventReader::ReturnHbtEvent(){
00069 if (mDebug) cout << "AliStHbtEventReader::ReturnHbtEvent()" << endl;
00070
00071 StHbtEvent* hbtEvent = 0;
00072
00073 try {
00074 hbtEvent = read();
00075 }
00076 catch(StExceptionEOF e) {
00077 e.print();
00078 mReaderStatus = 2;
00079 return 0;
00080 }
00081 catch(StException e) {
00082 e.print();
00083 mReaderStatus = 1;
00084 return 0;
00085 }
00086
00087 if (!hbtEvent) cout << "AliStHbtEventReader::ReturnHbtEvent() - no hbtEvent" << endl;
00088
00089 return hbtEvent;
00090 }
00091
00092
00093 StHbtEvent* AliStHbtEventReader::read(){
00094 if (!mTChain) {
00095 try {
00096 cout << initRead(mDir,mFile,mFilter,mMaxFiles) << " files to analyse " << endl;
00097 }
00098 catch(StException e) {
00099 e.print();
00100 return 0;
00101 }
00102 }
00103 float sumofpid;
00104
00105 unsigned int nEvents = (unsigned int)mTChain->GetEntries();
00106 if (!nEvents) throw StException("AliStHbtEventReader::read() - no events to read ");
00107
00108 mEvent->Clear("");
00109 int iBytes= mTChain->GetEntry(mEventIndex++);
00110
00111 if (nEvents<mEventIndex) throw StExceptionEOF("AliStHbtEventReader::read()");
00112 if (!iBytes) throw StException("AliStHbtEventReader::read() - no event ");
00113
00114 StHbtEvent *hbtEvent = 0;
00115
00116 if(mEvent)
00117 {
00118 hbtEvent = new StHbtEvent;
00119
00120 hbtEvent->SetEventNumber(mEvent->GetEventNumber());
00121 hbtEvent->SetRunNumber(mEvent->GetRunNumber());
00122 hbtEvent->SetCtbMult(0);
00123 hbtEvent->SetZdcAdcEast(0);
00124 hbtEvent->SetZdcAdcWest(0);
00125 hbtEvent->SetNumberOfTpcHits(0);
00126 hbtEvent->SetNumberOfTracks(mEvent->GetMultiplicity());
00127 hbtEvent->SetNumberOfGoodTracks(0);
00128 hbtEvent->SetUncorrectedNumberOfPositivePrimaries(0);
00129 hbtEvent->SetUncorrectedNumberOfNegativePrimaries(0);
00130 hbtEvent->SetUncorrectedNumberOfPrimaries(0);
00131 hbtEvent->SetReactionPlane(0,0);
00132 hbtEvent->SetReactionPlaneError(0, 0);
00133 hbtEvent->SetReactionPlaneSubEventDifference(0, 0);
00134 hbtEvent->SetTriggerWord(mEvent->GetTrigger());
00135 hbtEvent->SetTriggerActionWord(0);
00136 hbtEvent->SetL3TriggerAlgorithm(0, 0);
00137 hbtEvent->SetUncorrectedNumberOfPrimaries(mEvent->GetMultiplicity());
00138 StThreeVectorF vertex(mEvent->GetVertexX(),mEvent->GetVertexY(),mEvent->GetVertexZ());
00139 hbtEvent->SetPrimVertPos(vertex);
00140
00141 StHbtTrackCollection *mTrackCollection = hbtEvent->TrackCollection();
00142
00143 TClonesArray *tracks = 0;
00144
00145 tracks = mEvent->Tracks();
00146
00147 if (tracks)
00148 {
00149 int nTracks = tracks->GetEntries();
00150 for ( int i=0; i<nTracks; i++)
00151 {
00152 sumofpid=0;
00153 AliStHbtTrack *track = (AliStHbtTrack*) tracks->UncheckedAt(i);
00154 StHbtTrack* trackCopy = new StHbtTrack;
00155 trackCopy->SetHiddenInfo(0);
00156
00157 trackCopy->SetCharge(track->GetCharge());
00158 trackCopy->SetNHits(track->GetNTpcHits());
00159
00160
00161
00162 trackCopy->SetNHitsDedx(0);
00163 trackCopy->SetNSigmaElectron(0.);
00164 trackCopy->SetNSigmaPion(0.);
00165 trackCopy->SetNSigmaKaon(0.);
00166 trackCopy->SetNSigmaProton(0.);
00167
00168 sumofpid = track->GetPidProbElectron() + track->GetPidProbPion() + track->GetPidProbKaon() + track->GetPidProbProton();
00169
00170 trackCopy->SetPidProbElectron(float(track->GetPidProbElectron()/sumofpid));
00171 trackCopy->SetPidProbPion(float(track->GetPidProbPion()/sumofpid));
00172 trackCopy->SetPidProbKaon(float(track->GetPidProbKaon()/sumofpid));
00173 trackCopy->SetPidProbProton(float(track->GetPidProbProton()/sumofpid));
00174 trackCopy->SetdEdx(track->GetdEdx());
00175 trackCopy->SetDCAxy(track->GetImpactParameterXY());
00176 trackCopy->SetDCAz(track->GetImpactParameterZ());
00177 trackCopy->SetDCAxyGlobal(0.);
00178 trackCopy->SetDCAzGlobal(0.);
00179 trackCopy->SetChiSquaredXY(0.);
00180 trackCopy->SetChiSquaredZ(0.);
00181
00182
00183
00184 float px = track->GetPx();
00185 float py = track->GetPy();
00186 float pz = track->GetPz();
00187
00188 StHbtThreeVector v(px,py,pz);
00189
00190 trackCopy->SetP(v);
00191 trackCopy->SetPt(sqrt(px*px+py*py));
00192
00193
00194
00195 const StThreeVectorD p((double)px,(double)py,(double)pz);
00196 const StThreeVectorD origin((double)mEvent->GetVertexX(),(double)mEvent->GetVertexY(),(double)mEvent->GetVertexZ());
00197
00198 StPhysicalHelixD helix(p,origin,(double)(mEvent->GetMagField())*kilogauss,(double)(track->GetCharge()));
00199
00200 trackCopy->SetHelix(helix);
00201
00202 trackCopy->SetTopologyMap(0,track->GetTopologyMap(0));
00203 trackCopy->SetTopologyMap(1,track->GetTopologyMap(1));
00204 trackCopy->SetTopologyMap(2,track->GetTopologyMap(2));
00205 trackCopy->SetTopologyMap(3,track->GetTopologyMap(3));
00206 trackCopy->SetTopologyMap(4,track->GetTopologyMap(4));
00207 trackCopy->SetTopologyMap(5,track->GetTopologyMap(4));
00208
00209 mTrackCollection->push_back(trackCopy);
00210 }
00211 }
00212
00213 }
00214
00215 return hbtEvent;
00216 }
00217
00218 int AliStHbtEventReader::initRead(string dir, string file, string filter, int mMaxFiles){
00219 mEventIndex =0;
00220 mTChain = new TChain("AliStHbtTree","AliStHbtTree");
00221
00222 int nFiles =0;
00223 if (file!="") {
00224 if( strstr(file.c_str(),".lis") || strstr(file.c_str(),".list") ) {
00225 try {
00226 nFiles = fillChain(mTChain, (dir+file).c_str(), mMaxFiles);
00227 }
00228 catch(StException e) {
00229 throw e;
00230 }
00231 }
00232 else {
00233 mTChain->Add((dir+file).c_str());
00234 nFiles++;
00235 }
00236 }
00237 else {
00238 try {
00239 nFiles = fillChain(mTChain,dir.c_str(), filter.c_str(), mMaxFiles);
00240 }
00241 catch(StException e) {
00242 throw e;
00243 }
00244 }
00245
00246 mTChain->SetBranchAddress("AliStHbtEvent",&mEvent);
00247 return nFiles;
00248 }
00249
00250
00251 int AliStHbtEventReader::uninitRead(){
00252 if (mEvent) delete mEvent;
00253 if (mTChain) delete mTChain;
00254 mEvent = 0;
00255 mTChain = 0;
00256 return 0;
00257 }
00258
00259 int AliStHbtEventReader::fillChain(TChain* chain, const char* fileList, const int maxFiles) {
00260 ifstream* inputStream = new ifstream;
00261 inputStream->open(fileList);
00262 if (!(inputStream)) throw StException("AliStHbtEventReader::fillChain(string dir) - can not open directory");
00263 char* temp;
00264 int count=0;
00265 if (mDebug>1) cout << " AliStHbtEventReader::fillChain(...)- inputStream->good() : " << inputStream->good() << endl;
00266 for (;inputStream->good();) {
00267 temp = new char[200];
00268 inputStream->getline(temp,200);
00269
00270 TString fileName(temp);
00271 if(fileName.Contains("root")) {
00272 chain->Add(temp);
00273 ++count;
00274 }
00275 delete temp;
00276 if (count>maxFiles) break;
00277 }
00278 delete inputStream;
00279 if (mDebug) cout << "AliStHbtEventReader::(string dir)(string dir) - Added " << count << " files to the chain" << endl;
00280 return count;
00281 }
00282
00283 int AliStHbtEventReader::fillChain(TChain* chain, const char* dir, const char* filter, const int maxFiles) {
00284
00285 void *pDir = gSystem->OpenDirectory(dir);
00286 if(!pDir) throw StException("AliStHbtEventReader::fillChain(string dir) - can not open directory");
00287
00288 const char* fileName(0);
00289 int count(0);
00290 while((fileName = gSystem->GetDirEntry(pDir))){
00291 if(strcmp(fileName,".")==0 || strcmp(fileName,"..")==0) continue;
00292 if(strstr(fileName,filter) ) {
00293 char* fullFile = gSystem->ConcatFileName(dir,fileName);
00294
00295 cout << "AliStHbtEventReader::fillChain(string dir) - Adding " << fullFile << " to the chain" << endl;
00296 chain->Add(fullFile);
00297 delete fullFile;
00298 ++count;
00299 if (count>maxFiles) break;
00300 }
00301 }
00302 cout << "AliStHbtEventReader::(string dir)(string dir) - Added " << count << " files to the chain" << endl;
00303 return count;
00304 }
00305
00306
00307
00308
00309
00310
00311
00312