1 #include "AliHBTReaderInternal.h"
4 //#include <Riostream.h>
12 #include "AliHBTRun.h"
13 #include "AliHBTEvent.h"
14 #include "AliHBTParticle.h"
15 #include "AliHBTParticleCut.h"
18 ClassImp(AliHBTReaderInternal)
19 /********************************************************************/
21 AliHBTReaderInternal::AliHBTReaderInternal()
27 /********************************************************************/
29 AliHBTReaderInternal::AliHBTReaderInternal(const char *filename):fFileName(filename)
31 fParticles = new AliHBTRun();
32 fTracks = new AliHBTRun();
35 /********************************************************************/
36 AliHBTReaderInternal::AliHBTReaderInternal(TObjArray* dirs, const char *filename):
37 AliHBTReader(dirs),fFileName(filename)
39 fParticles = new AliHBTRun();
40 fTracks = new AliHBTRun();
43 AliHBTReaderInternal::~AliHBTReaderInternal()
49 /********************************************************************/
50 AliHBTEvent* AliHBTReaderInternal::GetParticleEvent(Int_t n)
52 //returns Nth event with simulated particles
54 if(Read(fParticles,fTracks))
56 Error("GetParticleEvent","Error in reading");
59 return fParticles->GetEvent(n);
61 /********************************************************************/
62 AliHBTEvent* AliHBTReaderInternal::GetTrackEvent(Int_t n)
64 //returns Nth event with reconstructed tracks
66 if(Read(fParticles,fTracks))
68 Error("GetTrackEvent","Error in reading");
71 return fTracks->GetEvent(n);
73 /********************************************************************/
75 Int_t AliHBTReaderInternal::GetNumberOfPartEvents()
77 //returns number of events of particles
79 if ( Read(fParticles,fTracks))
81 Error("GetNumberOfPartEvents","Error in reading");
84 return fParticles->GetNumberOfEvents();
87 /********************************************************************/
88 Int_t AliHBTReaderInternal::GetNumberOfTrackEvents()
90 //returns number of events of tracks
92 if(Read(fParticles,fTracks))
94 Error("GetNumberOfTrackEvents","Error in reading");
97 return fTracks->GetNumberOfEvents();
99 /********************************************************************/
102 Int_t AliHBTReaderInternal::Read(AliHBTRun* particles, AliHBTRun *tracks)
104 //reads data and puts put to the particles and tracks objects
105 //reurns 0 if everything is OK
107 cout<<"AliHBTReaderInternal::Read()"<<endl;
108 Int_t i; //iterator and some temprary values
109 Int_t totalNevents = 0; //total number of read events
111 Int_t currentdir = 0;
114 TFile *aFile;//file with tracks
115 AliHBTParticle* tpart = 0x0, *ttrack = 0x0;
117 if (!particles) //check if an object is instatiated
119 Error("Read"," particles object must instatiated before passing it to the reader");
121 if (!tracks) //check if an object is instatiated
123 Error("Read"," tracks object must instatiated before passing it to the reader");
125 particles->Reset();//clear runs == delete all old events
128 if (fDirs) //if array with directories is supplied by user
130 Ndirs = fDirs->GetEntries(); //get the number if directories
134 Ndirs = 0; //if the array is not supplied read only from current directory
137 TClonesArray* pbuffer = new TClonesArray("AliHBTParticle",15000);
138 TClonesArray* tbuffer = new TClonesArray("AliHBTParticle",15000);
140 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
143 if( (i=OpenFile(aFile, currentdir)) )
145 Error("Read","Exiting due to problems with opening files. Errorcode %d",i);
148 /***************************/
149 /***************************/
150 /***************************/
152 TTree* tree = (TTree*)aFile->Get("data");
155 Error("Read","Can not get the tree");
159 TBranch *trackbranch=tree->GetBranch("tracks");//get the branch with tracks
160 if (trackbranch == 0x0) ////check if we got the branch
161 {//if not return with error
162 Warning("Read","Can't find a branch with tracks !\n");
166 trackbranch->SetAddress(&tbuffer);
169 TBranch *partbranch=tree->GetBranch("particles");//get the branch with particles
170 if (partbranch == 0x0) ////check if we got the branch
171 {//if not return with error
172 Warning("Read","Can't find a branch with particles !\n");
176 partbranch->SetAddress(&pbuffer);
179 Nevents = (Int_t)tree->GetEntries();
180 cout<<"________________________________________________________\n";
181 cout<<"Found "<<Nevents<<" event(s) in directory "<<GetDirName(currentdir)<<endl;
183 for (Int_t currentEvent =0; currentEvent<Nevents;currentEvent++)
185 cout<<"Event "<<currentEvent<<"\n";
186 tree->GetEvent(currentEvent);
188 if (partbranch && trackbranch)
190 for(i = 0; i < pbuffer->GetEntries(); i++)
193 tpart = dynamic_cast<AliHBTParticle*>(pbuffer->At(i));
194 ttrack = dynamic_cast<AliHBTParticle*>(tbuffer->At(i));
196 if( (tpart == 0x0) || (ttrack == 0x0) ) continue; //if returned pointer is NULL
197 if( (tpart->GetPDG()==0x0)||(ttrack->GetPDG()==0x0) ) continue; //if particle has crezy PDG code (not known to our database)
198 if((Pass(tpart))||(Pass(ttrack))) continue; //check if we are intersted with particles of this type
199 //if not take next partilce
200 AliHBTParticle* part = new AliHBTParticle(*tpart);
201 AliHBTParticle* track = new AliHBTParticle(*ttrack);
202 particles->AddParticle(totalNevents,part);//put track and particle on the run
203 tracks->AddParticle(totalNevents,track);
205 cout<<"Read: "<<particles->GetNumberOfParticlesInEvent(totalNevents)<<" particles and tracks \n";
211 for(i = 0; i < pbuffer->GetEntries(); i++)
214 tpart = dynamic_cast<AliHBTParticle*>(pbuffer->At(i));
215 if(tpart == 0x0) continue; //if returned pointer is NULL
216 if(tpart->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
217 if(Pass(tpart)) continue; //check if we are intersted with particles of this type
218 //if not take next partilce
220 AliHBTParticle* part = new AliHBTParticle(*tpart);
221 particles->AddParticle(totalNevents,part);//put track and particle on the run
223 cout<<"\nRead: "<<particles->GetNumberOfParticlesInEvent(totalNevents)<<" particles \n";
225 else cout<<"Read: 0 particles \n";
229 for(i = 0; i < tbuffer->GetEntries(); i++)
232 tpart = dynamic_cast<AliHBTParticle*>(tbuffer->At(i));
233 if(tpart == 0x0) continue; //if returned pointer is NULL
234 if(tpart->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
235 if(Pass(tpart)) continue; //check if we are intersted with particles of this type
236 //if not take next partilce
237 AliHBTParticle* part = new AliHBTParticle(*tpart);
238 tracks->AddParticle(totalNevents,part);//put track and particle on the run
240 cout<<"\nRead: "<<tracks->GetNumberOfParticlesInEvent(totalNevents)<<" tracks"<<endl;
242 else cout<<" 0 tracks"<<endl;
248 /***************************/
249 /***************************/
250 /***************************/
255 }while(currentdir < Ndirs);
261 /********************************************************************/
263 Int_t AliHBTReaderInternal::OpenFile(TFile*& aFile,Int_t event)
266 const TString& dirname = GetDirName(event);
269 Error("OpenFile","Can not get directory name");
273 TString filename = dirname +"/"+ fFileName;
274 aFile = TFile::Open(filename.Data());
277 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
280 if (!aFile->IsOpen())
282 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
291 Int_t AliHBTReaderInternal::Write(AliHBTReader* reader,const char* outfile)
293 //reads tracks from runs and writes them to file
297 cout<<"________________________________________________________\n";
298 cout<<"________________________________________________________\n";
299 cout<<"________________________________________________________\n";
301 TFile *histoOutput = TFile::Open(outfile,"recreate");
303 if (!histoOutput->IsOpen())
305 cout<<"File is not opened"<<endl;
310 TTree *tracktree = new TTree("data","Tree with tracks");
312 TClonesArray* pbuffer = new TClonesArray("AliHBTParticle",15000);
313 TClonesArray* tbuffer = new TClonesArray("AliHBTParticle",15000);
315 TClonesArray &particles = *pbuffer;
316 TClonesArray &tracks = *tbuffer;
318 TString name("Tracks");
321 Int_t NT = reader->GetNumberOfTrackEvents();
322 Int_t NP = reader->GetNumberOfPartEvents();
324 Bool_t trck = (NT > 0) ? kTRUE : kFALSE;
325 Bool_t part = (NP > 0) ? kTRUE : kFALSE;
327 TBranch *trackbranch = 0x0, *partbranch = 0x0;
330 if (trck) trackbranch = tracktree->Branch("tracks","TClonesArray",&tbuffer);
331 if (part) partbranch = tracktree->Branch("particles","TClonesArray",&pbuffer);
335 if ( (trck) && (part) && (NP != NT))
337 cerr<<"Warning number of track and particle events is different"<<endl;
341 if (NT >= NP ) N = NT; else N = NP;
343 for ( i =0;i< N; i++)
345 cout<<"Event "<<i+1<<"\n";
349 AliHBTEvent* trackev = reader->GetTrackEvent(i);
350 for ( j = 0; j< trackev->GetNumberOfParticles();j++)
353 const AliHBTParticle& t= *(trackev->GetParticle(j));
354 new (tracks[j]) AliHBTParticle(t);
357 }else cout<<"NO TRACKS";
363 cout<<"Particles: \n";
364 AliHBTEvent* partev = reader->GetParticleEvent(i);
365 for ( j = 0; j< partev->GetNumberOfParticles();j++)
367 const AliHBTParticle& part= *(partev->GetParticle(j));
369 new (particles[j]) AliHBTParticle(part);
371 }else cout<<"NO PARTICLES";
376 tracktree->AutoSave();
382 tracktree->Write(0,TObject::kOverwrite);
390 histoOutput->Close();