2 #include "AliStHbtEventReader.h"
9 #include "StPhysicalHelixD.hh"
11 #include "SystemOfUnits.h"
13 #include "StIOMaker/StIOMaker.h"
22 #include "StHbtMaker/Infrastructure/StExceptions.hh"
23 #include "StHbtMaker/Infrastructure/StHbtTrackCollection.hh"
24 #include "StHbtMaker/Infrastructure/StHbtEvent.hh"
26 #include "StHbtMaker/Infrastructure/StHbtVector.hh"
28 #include "StHbtMaker/Reader/AliStHbtEvent.h"
29 #include "StHbtMaker/Reader/AliStHbtTrack.h"
31 #include "StarClassLibrary/StMemoryInfo.hh"
35 #if !(ST_NO_NAMESPACES)
36 using namespace units;
41 AliStHbtEventReader::AliStHbtEventReader(StHbtIOMode mode,
StIOMaker* io,
42 const char* dirName,
const char* fileName,
43 const char* filter,
int maxFiles)
44 : mIOMaker(io), mIOMode(mode), mMaxFiles(maxFiles), mDebug(0), mCurrentFile(0),
46 if (mDebug) cout <<
"AliStHbtEventReader::AliStHbtEventReader(...)"<< endl;
48 mDir = string(dirName);
49 mFile = string(fileName);
50 mFilter = string(filter);
53 if (mDebug) cout <<
"AliStHbtEventReader::AliStHbtEventReader(...) - leaving"<< endl;
57 AliStHbtEventReader::~AliStHbtEventReader(){
58 if (mCurrentFile) { mCurrentFile->Close();
delete mCurrentFile; mCurrentFile = 0;}
62 StHbtString AliStHbtEventReader::Report(){
63 StHbtString temp =
"\n This is the AliStHbtEventReader\n";
68 StHbtEvent* AliStHbtEventReader::ReturnHbtEvent(){
69 if (mDebug) cout <<
"AliStHbtEventReader::ReturnHbtEvent()" << endl;
87 if (!hbtEvent) cout <<
"AliStHbtEventReader::ReturnHbtEvent() - no hbtEvent" << endl;
96 cout << initRead(mDir,mFile,mFilter,mMaxFiles) <<
" files to analyse " << endl;
105 unsigned int nEvents = (
unsigned int)mTChain->GetEntries();
106 if (!nEvents)
throw StException(
"AliStHbtEventReader::read() - no events to read ");
109 int iBytes= mTChain->GetEntry(mEventIndex++);
111 if (nEvents<mEventIndex)
throw StExceptionEOF(
"AliStHbtEventReader::read()");
112 if (!iBytes)
throw StException(
"AliStHbtEventReader::read() - no event ");
120 hbtEvent->SetEventNumber(mEvent->GetEventNumber());
121 hbtEvent->SetRunNumber(mEvent->GetRunNumber());
122 hbtEvent->SetCtbMult(0);
123 hbtEvent->SetZdcAdcEast(0);
124 hbtEvent->SetZdcAdcWest(0);
125 hbtEvent->SetNumberOfTpcHits(0);
126 hbtEvent->SetNumberOfTracks(mEvent->GetMultiplicity());
127 hbtEvent->SetNumberOfGoodTracks(0);
128 hbtEvent->SetUncorrectedNumberOfPositivePrimaries(0);
129 hbtEvent->SetUncorrectedNumberOfNegativePrimaries(0);
130 hbtEvent->SetUncorrectedNumberOfPrimaries(0);
131 hbtEvent->SetReactionPlane(0,0);
132 hbtEvent->SetReactionPlaneError(0, 0);
133 hbtEvent->SetReactionPlaneSubEventDifference(0, 0);
134 hbtEvent->SetTriggerWord(mEvent->GetTrigger());
135 hbtEvent->SetTriggerActionWord(0);
136 hbtEvent->SetL3TriggerAlgorithm(0, 0);
137 hbtEvent->SetUncorrectedNumberOfPrimaries(mEvent->GetMultiplicity());
139 hbtEvent->SetPrimVertPos(
vertex);
141 StHbtTrackCollection *mTrackCollection = hbtEvent->TrackCollection();
143 TClonesArray *tracks = 0;
145 tracks = mEvent->Tracks();
149 int nTracks = tracks->GetEntries();
150 for (
int i=0; i<nTracks; i++)
155 trackCopy->SetHiddenInfo(0);
157 trackCopy->SetCharge(track->GetCharge());
158 trackCopy->SetNHits(track->GetNTpcHits());
162 trackCopy->SetNHitsDedx(0);
163 trackCopy->SetNSigmaElectron(0.);
164 trackCopy->SetNSigmaPion(0.);
165 trackCopy->SetNSigmaKaon(0.);
166 trackCopy->SetNSigmaProton(0.);
168 sumofpid = track->GetPidProbElectron() + track->GetPidProbPion() + track->GetPidProbKaon() + track->GetPidProbProton();
170 trackCopy->SetPidProbElectron(
float(track->GetPidProbElectron()/sumofpid));
171 trackCopy->SetPidProbPion(
float(track->GetPidProbPion()/sumofpid));
172 trackCopy->SetPidProbKaon(
float(track->GetPidProbKaon()/sumofpid));
173 trackCopy->SetPidProbProton(
float(track->GetPidProbProton()/sumofpid));
174 trackCopy->SetdEdx(track->GetdEdx());
175 trackCopy->SetDCAxy(track->GetImpactParameterXY());
176 trackCopy->SetDCAz(track->GetImpactParameterZ());
177 trackCopy->SetDCAxyGlobal(0.);
178 trackCopy->SetDCAzGlobal(0.);
179 trackCopy->SetChiSquaredXY(0.);
180 trackCopy->SetChiSquaredZ(0.);
184 float px = track->GetPx();
185 float py = track->GetPy();
186 float pz = track->GetPz();
191 trackCopy->SetPt(sqrt(px*px+py*py));
196 const StThreeVectorD origin((
double)mEvent->GetVertexX(),(double)mEvent->GetVertexY(),(double)mEvent->GetVertexZ());
198 StPhysicalHelixD helix(p,origin,(
double)(mEvent->GetMagField())*kilogauss,(
double)(track->GetCharge()));
200 trackCopy->SetHelix(helix);
202 trackCopy->SetTopologyMap(0,track->GetTopologyMap(0));
203 trackCopy->SetTopologyMap(1,track->GetTopologyMap(1));
204 trackCopy->SetTopologyMap(2,track->GetTopologyMap(2));
205 trackCopy->SetTopologyMap(3,track->GetTopologyMap(3));
206 trackCopy->SetTopologyMap(4,track->GetTopologyMap(4));
207 trackCopy->SetTopologyMap(5,track->GetTopologyMap(4));
209 mTrackCollection->push_back(trackCopy);
218 int AliStHbtEventReader::initRead(
string dir,
string file,
string filter,
int mMaxFiles){
220 mTChain =
new TChain(
"AliStHbtTree",
"AliStHbtTree");
224 if( strstr(file.c_str(),
".lis") || strstr(file.c_str(),
".list") ) {
226 nFiles = fillChain(mTChain, (dir+file).c_str(), mMaxFiles);
233 mTChain->Add((dir+file).c_str());
239 nFiles = fillChain(mTChain,dir.c_str(), filter.c_str(), mMaxFiles);
246 mTChain->SetBranchAddress(
"AliStHbtEvent",&mEvent);
251 int AliStHbtEventReader::uninitRead(){
252 if (mEvent)
delete mEvent;
253 if (mTChain)
delete mTChain;
259 int AliStHbtEventReader::fillChain(TChain* chain,
const char* fileList,
const int maxFiles) {
260 ifstream* inputStream =
new ifstream;
261 inputStream->open(fileList);
262 if (!(inputStream))
throw StException(
"AliStHbtEventReader::fillChain(string dir) - can not open directory");
265 if (mDebug>1) cout <<
" AliStHbtEventReader::fillChain(...)- inputStream->good() : " << inputStream->good() << endl;
266 for (;inputStream->good();) {
267 temp =
new char[200];
268 inputStream->getline(temp,200);
270 TString fileName(temp);
271 if(fileName.Contains(
"root")) {
276 if (count>maxFiles)
break;
279 if (mDebug) cout <<
"AliStHbtEventReader::(string dir)(string dir) - Added " << count <<
" files to the chain" << endl;
283 int AliStHbtEventReader::fillChain(TChain* chain,
const char* dir,
const char* filter,
const int maxFiles) {
285 void *pDir = gSystem->OpenDirectory(dir);
286 if(!pDir)
throw StException(
"AliStHbtEventReader::fillChain(string dir) - can not open directory");
288 const char* fileName(0);
290 while((fileName = gSystem->GetDirEntry(pDir))){
291 if(strcmp(fileName,
".")==0 || strcmp(fileName,
"..")==0)
continue;
292 if(strstr(fileName,filter) ) {
293 char* fullFile = gSystem->ConcatFileName(dir,fileName);
295 cout <<
"AliStHbtEventReader::fillChain(string dir) - Adding " << fullFile <<
" to the chain" << endl;
296 chain->Add(fullFile);
299 if (count>maxFiles)
break;
302 cout <<
"AliStHbtEventReader::(string dir)(string dir) - Added " << count <<
" files to the chain" << endl;