1 #include "AliHBTReaderInternal.h"
10 #include "AliHBTRun.h"
11 #include "AliHBTEvent.h"
12 #include "AliHBTParticle.h"
13 #include "AliHBTParticleCut.h"
16 ClassImp(AliHBTReaderInternal)
17 /********************************************************************/
19 AliHBTReaderInternal::AliHBTReaderInternal()
26 /********************************************************************/
28 AliHBTReaderInternal::AliHBTReaderInternal(const char *filename):fFileName(filename)
31 //filename - name of file to open
32 fParticles = new AliHBTRun();
33 fTracks = new AliHBTRun();
36 /********************************************************************/
38 AliHBTReaderInternal::AliHBTReaderInternal(TObjArray* dirs, const char *filename):
39 AliHBTReader(dirs),fFileName(filename)
42 //dirs contains strings with directories to look data in
43 //filename - name of file to open
44 fParticles = new AliHBTRun();
45 fTracks = new AliHBTRun();
48 /********************************************************************/
50 AliHBTReaderInternal::~AliHBTReaderInternal()
56 /********************************************************************/
58 AliHBTEvent* AliHBTReaderInternal::GetParticleEvent(Int_t n)
60 //returns Nth event with simulated particles
62 if(Read(fParticles,fTracks))
64 Error("GetParticleEvent","Error in reading");
67 return fParticles->GetEvent(n);
69 /********************************************************************/
71 AliHBTEvent* AliHBTReaderInternal::GetTrackEvent(Int_t n)
73 //returns Nth event with reconstructed tracks
75 if(Read(fParticles,fTracks))
77 Error("GetTrackEvent","Error in reading");
80 return fTracks->GetEvent(n);
82 /********************************************************************/
84 Int_t AliHBTReaderInternal::GetNumberOfPartEvents()
86 //returns number of events of particles
88 if ( Read(fParticles,fTracks))
90 Error("GetNumberOfPartEvents","Error in reading");
93 return fParticles->GetNumberOfEvents();
96 /********************************************************************/
97 Int_t AliHBTReaderInternal::GetNumberOfTrackEvents()
99 //returns number of events of tracks
101 if(Read(fParticles,fTracks))
103 Error("GetNumberOfTrackEvents","Error in reading");
106 return fTracks->GetNumberOfEvents();
108 /********************************************************************/
110 Int_t AliHBTReaderInternal::Read(AliHBTRun* particles, AliHBTRun *tracks)
112 //reads data and puts put to the particles and tracks objects
113 //reurns 0 if everything is OK
116 Int_t i; //iterator and some temprary values
117 Int_t totalnevents = 0; //total number of read events
119 Int_t currentdir = 0;
122 TFile *aFile;//file with tracks
123 AliHBTParticle* tpart = 0x0, *ttrack = 0x0;
125 if (!particles) //check if an object is instatiated
127 Error("Read"," particles object must instatiated before passing it to the reader");
129 if (!tracks) //check if an object is instatiated
131 Error("Read"," tracks object must instatiated before passing it to the reader");
133 particles->Reset();//clear runs == delete all old events
136 if (fDirs) //if array with directories is supplied by user
138 Ndirs = fDirs->GetEntries(); //get the number if directories
142 Ndirs = 0; //if the array is not supplied read only from current directory
145 TClonesArray* pbuffer = new TClonesArray("AliHBTParticle",15000);
146 TClonesArray* tbuffer = new TClonesArray("AliHBTParticle",15000);
147 // pbuffer->BypassStreamer(kFALSE);
148 // tbuffer->BypassStreamer(kFALSE);
150 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
153 if( (i=OpenFile(aFile, currentdir)) )
155 Error("Read","Exiting due to problems with opening files. Errorcode %d",i);
158 /***************************/
159 /***************************/
160 /***************************/
162 TTree* tree = (TTree*)aFile->Get("data");
165 Error("Read","Can not get the tree");
169 TBranch *trackbranch=tree->GetBranch("tracks");//get the branch with tracks
170 if (trackbranch == 0x0) ////check if we got the branch
171 {//if not return with error
172 Warning("Read","Can't find a branch with tracks !\n");
176 trackbranch->SetAddress(&tbuffer);
179 TBranch *partbranch=tree->GetBranch("particles");//get the branch with particles
180 if (partbranch == 0x0) ////check if we got the branch
181 {//if not return with error
182 Warning("Read","Can't find a branch with particles !\n");
186 partbranch->SetAddress(&pbuffer);
189 nevents = (Int_t)tree->GetEntries();
190 Info("Read","________________________________________________________");
191 Info("Read","Found %d event(s) in directory %s",nevents,GetDirName(currentdir).Data());
193 for (Int_t currentEvent =0; currentEvent<nevents;currentEvent++)
195 Info("Read","Event %d",currentEvent);
196 tree->GetEvent(currentEvent);
199 if (partbranch && trackbranch)
201 for(i = 0; i < pbuffer->GetEntries(); i++)
203 tpart = dynamic_cast<AliHBTParticle*>(pbuffer->At(i));
204 ttrack = dynamic_cast<AliHBTParticle*>(tbuffer->At(i));
206 if( tpart == 0x0 ) continue; //if returned pointer is NULL
207 if( tpart->GetPDG()==0x0 ) continue; //if particle has crezy PDG code (not known to our database)
208 if( Pass(tpart) ) continue; //check if we are intersted with particles of this type
209 //if not take next partilce
210 AliHBTParticle* part = new AliHBTParticle(*tpart);
211 AliHBTParticle* track = new AliHBTParticle(*ttrack);
212 particles->AddParticle(totalnevents,part);//put track and particle on the run
213 tracks->AddParticle(totalnevents,track);
216 Info("Read"," Read: %d particles and tracks.",counter);
222 Info("Read","Found %d particles in total.",pbuffer->GetEntries());
223 for(i = 0; i < pbuffer->GetEntries(); i++)
225 tpart = dynamic_cast<AliHBTParticle*>(pbuffer->At(i));
226 if(tpart == 0x0) continue; //if returned pointer is NULL
227 if(tpart->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
228 if(Pass(tpart)) continue; //check if we are intersted with particles of this type
229 //if not take next partilce
230 AliHBTParticle* part = new AliHBTParticle(*tpart);
231 particles->AddParticle(totalnevents,part);//put track and particle on the run
234 Info("Read"," Read: %d particles.",counter);
236 else Info("Read"," Read: 0 particles.");
240 for(i = 0; i < tbuffer->GetEntries(); i++)
242 tpart = dynamic_cast<AliHBTParticle*>(tbuffer->At(i));
243 if(tpart == 0x0) continue; //if returned pointer is NULL
244 if(tpart->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
245 if(Pass(tpart)) continue; //check if we are intersted with particles of this type
246 //if not take next partilce
247 AliHBTParticle* part = new AliHBTParticle(*tpart);
248 tracks->AddParticle(totalnevents,part);//put track and particle on the run
251 Info("Read"," Read: %d tracks",counter);
253 else Info("Read"," Read: 0 tracks.");
258 /***************************/
259 /***************************/
260 /***************************/
267 }while(currentdir < Ndirs);
275 /********************************************************************/
277 Int_t AliHBTReaderInternal::OpenFile(TFile*& aFile,Int_t event)
280 const TString& dirname = GetDirName(event);
283 Error("OpenFile","Can not get directory name");
287 TString filename = dirname +"/"+ fFileName;
288 aFile = TFile::Open(filename.Data());
291 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
294 if (!aFile->IsOpen())
296 Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
301 /********************************************************************/
303 Int_t AliHBTReaderInternal::Write(AliHBTReader* reader,const char* outfile)
305 //reads tracks from reader and writes runs to file
308 ::Info("AliHBTReaderInternal::Write","________________________________________________________");
309 ::Info("AliHBTReaderInternal::Write","________________________________________________________");
310 ::Info("AliHBTReaderInternal::Write","________________________________________________________");
312 TFile *histoOutput = TFile::Open(outfile,"recreate");
314 if (!histoOutput->IsOpen())
316 ::Error("AliHBTReaderInternal::Write","File is not opened");
320 TTree *tracktree = new TTree("data","Tree with tracks");
322 TClonesArray* pbuffer = new TClonesArray("AliHBTParticle",15000);
323 TClonesArray* tbuffer = new TClonesArray("AliHBTParticle",15000);
324 // pbuffer->BypassStreamer(kFALSE);
325 // tbuffer->BypassStreamer(kFALSE);
327 TClonesArray &particles = *pbuffer;
328 TClonesArray &tracks = *tbuffer;
330 TString name("Tracks");
332 Int_t NT = reader->GetNumberOfTrackEvents();
333 Int_t NP = reader->GetNumberOfPartEvents();
335 Bool_t trck = (NT > 0) ? kTRUE : kFALSE;
336 Bool_t part = (NP > 0) ? kTRUE : kFALSE;
338 TBranch *trackbranch = 0x0, *partbranch = 0x0;
340 if (trck) trackbranch = tracktree->Branch("tracks",&tbuffer,32000,0);
341 if (part) partbranch = tracktree->Branch("particles",&pbuffer,32000,0);
343 if ( (trck) && (part) && (NP != NT))
345 ::Warning("AliHBTReaderInternal::Write","Number of track and particle events is different");
349 if (NT >= NP ) N = NT; else N = NP;
351 for ( i =0;i< N; i++)
353 ::Info("AliHBTReaderInternal::Write","Event %d",i+1);
356 AliHBTEvent* trackev = reader->GetTrackEvent(i);
357 for ( j = 0; j< trackev->GetNumberOfParticles();j++)
359 const AliHBTParticle& t= *(trackev->GetParticle(j));
360 new (tracks[j]) AliHBTParticle(t);
362 ::Info("AliHBTReaderInternal::Write"," Tracks: %d",j);
363 }else ::Info("AliHBTReaderInternal::Write","NO TRACKS");
367 AliHBTEvent* partev = reader->GetParticleEvent(i);
368 for ( j = 0; j< partev->GetNumberOfParticles();j++)
370 const AliHBTParticle& part= *(partev->GetParticle(j));
371 new (particles[j]) AliHBTParticle(part);
373 ::Info("AliHBTReaderInternal::Write"," Particles: %d",j);
374 }else ::Info("AliHBTReaderInternal::Write","NO PARTICLES");
378 tracktree->AutoSave();
384 tracktree->Write(0,TObject::kOverwrite);
392 histoOutput->Close();