1 #include "AliHBTReaderInternal.h"
12 #include "AliHBTRun.h"
13 #include "AliHBTEvent.h"
14 #include "AliHBTParticle.h"
15 #include "AliHBTParticleCut.h"
18 AliHBTReaderInternal nnn;
20 ClassImp(AliHBTReaderInternal)
21 /********************************************************************/
23 AliHBTReaderInternal::AliHBTReaderInternal()
29 /********************************************************************/
31 AliHBTReaderInternal::AliHBTReaderInternal(const char *filename):fFileName(filename)
33 fParticles = new AliHBTRun();
34 fTracks = new AliHBTRun();
37 /********************************************************************/
38 AliHBTReaderInternal::AliHBTReaderInternal(TObjArray* dirs, const char *filename):
39 AliHBTReader(dirs),fFileName(filename)
41 fParticles = new AliHBTRun();
42 fTracks = new AliHBTRun();
45 AliHBTReaderInternal::~AliHBTReaderInternal()
51 /********************************************************************/
52 AliHBTEvent* AliHBTReaderInternal::GetParticleEvent(Int_t n)
54 //returns Nth event with simulated particles
56 if(Read(fParticles,fTracks))
58 Error("GetParticleEvent","Error in reading");
61 return fParticles->GetEvent(n);
63 /********************************************************************/
64 AliHBTEvent* AliHBTReaderInternal::GetTrackEvent(Int_t n)
66 //returns Nth event with reconstructed tracks
68 if(Read(fParticles,fTracks))
70 Error("GetTrackEvent","Error in reading");
73 return fTracks->GetEvent(n);
75 /********************************************************************/
77 Int_t AliHBTReaderInternal::GetNumberOfPartEvents()
79 //returns number of events of particles
81 if ( Read(fParticles,fTracks))
83 Error("GetNumberOfPartEvents","Error in reading");
86 return fParticles->GetNumberOfEvents();
89 /********************************************************************/
90 Int_t AliHBTReaderInternal::GetNumberOfTrackEvents()
92 //returns number of events of tracks
94 if(Read(fParticles,fTracks))
96 Error("GetNumberOfTrackEvents","Error in reading");
99 return fTracks->GetNumberOfEvents();
101 /********************************************************************/
104 Int_t AliHBTReaderInternal::Read(AliHBTRun* particles, AliHBTRun *tracks)
106 //reads data and puts put to the particles and tracks objects
107 //reurns 0 if everything is OK
109 cout<<"AliHBTReaderInternal::Read()"<<endl;
110 Int_t i; //iterator and some temprary values
112 TFile *aFile;//file with tracks
113 AliHBTParticle* p = 0x0;
115 if (!particles) //check if an object is instatiated
117 Error("Read"," particles object must instatiated before passing it to the reader");
119 if (!tracks) //check if an object is instatiated
121 Error("Read"," tracks object must instatiated before passing it to the reader");
123 particles->Reset();//clear runs == delete all old events
126 Int_t currentdir = 0;
129 if (fDirs) //if array with directories is supplied by user
131 Ndirs = fDirs->GetEntries(); //get the number if directories
135 Ndirs = 0; //if the array is not supplied read only from current directory
138 TClonesArray* pbuffer = new TClonesArray("AliHBTParticle",15000);
139 TClonesArray* tbuffer = new TClonesArray("AliHBTParticle",15000);
141 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
144 if( (i=OpenFile(aFile, currentdir)) )
146 Error("Read","Exiting due to problems with opening files. Errorcode %d",i);
149 /***************************/
150 /***************************/
151 /***************************/
153 TTree* tree = (TTree*)aFile->Get("data");
156 Error("Read","Can not get the tree");
160 TBranch *trackbranch=tree->GetBranch("tracks");//get the branch with tracks
161 if (trackbranch == 0x0) ////check if we got the branch
162 {//if not return with error
163 Warning("Read","Can't find a branch with tracks !\n");
167 trackbranch->SetAddress(&tbuffer);
170 TBranch *partbranch=tree->GetBranch("particles");//get the branch with particles
171 if (partbranch == 0x0) ////check if we got the branch
172 {//if not return with error
173 Warning("Read","Can't find a branch with particles !\n");
177 partbranch->SetAddress(&pbuffer);
180 Nevents = (Int_t)tree->GetEntries();
181 cout<<"________________________________________________________\n";
182 cout<<"Found "<<Nevents<<" event(s) in directory "<<GetDirName(currentdir)<<endl;
184 for (Int_t currentEvent =0; currentEvent<Nevents;currentEvent++)
186 tree->GetEvent(currentEvent);
189 for(i = 0; i < pbuffer->GetEntries(); i++)
191 p = dynamic_cast<AliHBTParticle*>(pbuffer->At(i));
192 if(p == 0x0) continue; //if returned pointer is NULL
193 if(p->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
194 if(Pass(p)) continue; //check if we are intersted with particles of this type
195 //if not take next partilce
196 AliHBTParticle* part = new AliHBTParticle(*p);
197 particles->AddParticle(currentEvent,part);//put track and particle on the run
199 cout<<"Read: "<<particles->GetNumberOfParticlesInEvent(currentEvent)<<" particles ";
201 else cout<<"Read: 0 particles ";
205 for(i = 0; i < tbuffer->GetEntries(); i++)
207 p = dynamic_cast<AliHBTParticle*>(tbuffer->At(i));
208 if(p == 0x0) continue; //if returned pointer is NULL
209 if(p->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
210 if(Pass(p)) continue; //check if we are intersted with particles of this type
211 //if not take next partilce
212 AliHBTParticle* part = new AliHBTParticle(*p);
213 tracks->AddParticle(currentEvent,part);//put track and particle on the run
215 cout<<tracks->GetNumberOfParticlesInEvent(currentEvent)<<" tracks"<<endl;
217 else cout<<" 0 tracks"<<endl;
224 /***************************/
225 /***************************/
226 /***************************/
230 }while(currentdir < Ndirs);
236 /********************************************************************/
238 Int_t AliHBTReaderInternal::OpenFile(TFile*& aFile,Int_t event)
241 const TString& dirname = GetDirName(event);
244 Error("OpenFile","Can not get directory name");
248 TString filename = dirname +"/"+ fFileName;
249 aFile = TFile::Open(filename.Data());
252 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
255 if (!aFile->IsOpen())
257 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
266 Int_t AliHBTReaderInternal::Write(AliHBTReader* reader,const char* outfile)
268 //reads tracks from runs and writes them to file
272 TFile *histoOutput = TFile::Open(outfile,"recreate");
274 if (!histoOutput->IsOpen())
276 cout<<"File is not opened"<<endl;
281 TTree *tracktree = new TTree("data","Tree with tracks");
283 TClonesArray* pbuffer = new TClonesArray("AliHBTParticle",15000);
284 TClonesArray* tbuffer = new TClonesArray("AliHBTParticle",15000);
288 TClonesArray &particles = *pbuffer;
289 TClonesArray &tracks = *tbuffer;
291 TString name("Tracks");
294 Int_t NT = reader->GetNumberOfTrackEvents();
295 Int_t NP = reader->GetNumberOfPartEvents();
297 Bool_t trck = (NT > 0) ? kTRUE : kFALSE;
298 Bool_t part = (NP > 0) ? kTRUE : kFALSE;
300 TBranch *trackbranch = 0x0, *partbranch = 0x0;
303 if (trck) trackbranch = tracktree->Branch("tracks","TClonesArray",&tbuffer);
304 if (part) partbranch = tracktree->Branch("particles","TClonesArray",&pbuffer);
308 if ( (trck) && (part) && (NP != NT))
310 cerr<<"Warning number of track and particle events is different"<<endl;
314 if (NT >= NP ) N = NT; else N = NP;
316 for ( i =0;i< N; i++)
320 AliHBTEvent* trackev = reader->GetTrackEvent(i);
321 for ( j = 0; j< trackev->GetNumberOfParticles();j++)
324 new (tracks[j]) AliHBTParticle(*(trackev->GetParticle(j)));
332 AliHBTEvent* partev = reader->GetParticleEvent(i);
333 for ( j = 0; j< partev->GetNumberOfParticles();j++)
336 new (particles[j]) AliHBTParticle(*(partev->GetParticle(j)));
351 tracktree->Write(0,TObject::kOverwrite);
352 histoOutput->Close();