#include "AliHBTReaderInternal.h"
+//_________________________________________________________________________
+///////////////////////////////////////////////////////////////////////////
+// //
+// class AliHBTReaderInternal //
+// //
+// Multi file reader for Internal Data Format //
+// //
+// This reader reads data created by itself //
+// (method AliHBTReaderInternal::Write) //
+// Data are stored in form of tree of TClonesArray of AliHBTParticle's //
+// //
+// Piotr.Skowronski@cern.ch //
+// more info: http://aliweb.cern.ch/people/skowron/analyzer/index.html //
+// //
+///////////////////////////////////////////////////////////////////////////
#include <TTree.h>
#include <TFile.h>
#include "AliHBTParticle.h"
#include "AliHBTParticleCut.h"
-
ClassImp(AliHBTReaderInternal)
/********************************************************************/
-AliHBTReaderInternal::AliHBTReaderInternal()
+AliHBTReaderInternal::AliHBTReaderInternal():
+ fFileName(),
+ fPartBranch(0x0),
+ fTrackBranch(0x0),
+ fTree(0x0),
+ fFile(0x0),
+ fPartBuffer(0x0),
+ fTrackBuffer(0x0)
{
//Defalut constructor
- fParticles = 0x0;
- fTracks = 0x0;
- fIsRead = kFALSE;
}
/********************************************************************/
-AliHBTReaderInternal::AliHBTReaderInternal(const char *filename):fFileName(filename)
+AliHBTReaderInternal::AliHBTReaderInternal(const char *filename):
+ fFileName(filename),
+ fPartBranch(0x0),
+ fTrackBranch(0x0),
+ fTree(0x0),
+ fFile(0x0),
+ fPartBuffer(0x0),
+ fTrackBuffer(0x0)
{
//constructor
//filename - name of file to open
- fParticles = new AliHBTRun();
- fTracks = new AliHBTRun();
- fIsRead = kFALSE;
}
/********************************************************************/
AliHBTReaderInternal::AliHBTReaderInternal(TObjArray* dirs, const char *filename):
- AliHBTReader(dirs),fFileName(filename)
+ AliHBTReader(dirs),
+ fFileName(filename),
+ fPartBranch(0x0),
+ fTrackBranch(0x0),
+ fTree(0x0),
+ fFile(0x0),
+ fPartBuffer(0x0),
+ fTrackBuffer(0x0)
{
//ctor
//dirs contains strings with directories to look data in
//filename - name of file to open
- fParticles = new AliHBTRun();
- fTracks = new AliHBTRun();
- fIsRead = kFALSE;
}
/********************************************************************/
-AliHBTReaderInternal::~AliHBTReaderInternal()
- {
- //desctructor
- delete fParticles;
- delete fTracks;
- }
-/********************************************************************/
-
-AliHBTEvent* AliHBTReaderInternal::GetParticleEvent(Int_t n)
- {
- //returns nth event with simulated particles
- if (!fIsRead)
- if(Read(fParticles,fTracks))
- {
- Error("GetParticleEvent","Error in reading");
- return 0x0;
- }
- return fParticles->GetEvent(n);
- }
+AliHBTReaderInternal::AliHBTReaderInternal(const AliHBTReaderInternal& in):
+ AliHBTReader(in),
+ fFileName(in.fFileName),
+ fPartBranch(0x0),
+ fTrackBranch(0x0),
+ fTree(0x0),
+ fFile(0x0),
+ fPartBuffer(0x0),
+ fTrackBuffer(0x0)
+{
+ //cpy constructor
+}
/********************************************************************/
-AliHBTEvent* AliHBTReaderInternal::GetTrackEvent(Int_t n)
- {
- //returns nth event with reconstructed tracks
- if (!fIsRead)
- if(Read(fParticles,fTracks))
- {
- Error("GetTrackEvent","Error in reading");
- return 0x0;
- }
- return fTracks->GetEvent(n);
- }
+AliHBTReaderInternal& AliHBTReaderInternal::operator=(const AliHBTReaderInternal& in)
+{
+ //Assigment operator
+ if (this == &in) return *this;
+ Rewind();//close current session
+ AliHBTReader::operator=((const AliHBTReader&)in);
+ fFileName = in.fFileName;
+ return *this;
+}
/********************************************************************/
-
-Int_t AliHBTReaderInternal::GetNumberOfPartEvents()
+AliHBTReaderInternal::~AliHBTReaderInternal()
{
- //returns number of events of particles
- if (!fIsRead)
- if ( Read(fParticles,fTracks))
- {
- Error("GetNumberOfPartEvents","Error in reading");
- return 0;
- }
- return fParticles->GetNumberOfEvents();
+ //desctructor
+ delete fTree;
+ delete fFile;
}
-
/********************************************************************/
-Int_t AliHBTReaderInternal::GetNumberOfTrackEvents()
- {
- //returns number of events of tracks
- if (!fIsRead)
- if(Read(fParticles,fTracks))
- {
- Error("GetNumberOfTrackEvents","Error in reading");
- return 0;
- }
- return fTracks->GetNumberOfEvents();
- }
+
+void AliHBTReaderInternal::Rewind()
+{
+ delete fTree;
+ fTree = 0x0;
+ delete fFile;
+ fFile = 0x0;
+ fCurrentDir = 0;
+ fNEventsRead= 0;
+}
/********************************************************************/
-Int_t AliHBTReaderInternal::Read(AliHBTRun* particles, AliHBTRun *tracks)
+Int_t AliHBTReaderInternal::ReadNext()
{
//reads data and puts put to the particles and tracks objects
//reurns 0 if everything is OK
//
- Info("Read","");
+ Info("ReadNext","");
Int_t i; //iterator and some temprary values
- Int_t totalnevents = 0; //total number of read events
- Int_t nevents = 0;
- Int_t currentdir = 0;
- Int_t Ndirs;
Int_t counter;
- TFile *aFile;//file with tracks
AliHBTParticle* tpart = 0x0, *ttrack = 0x0;
+
TDatabasePDG* pdgdb = TDatabasePDG::Instance();
if (pdgdb == 0x0)
{
- Error("Read","Can not get PDG Particles Data Base");
+ Error("ReadNext","Can not get PDG Particles Data Base");
return 1;
}
- if (!particles) //check if an object is instatiated
- {
- Error("Read"," particles object must instatiated before passing it to the reader");
- return 1;
- }
- if (!tracks) //check if an object is instatiated
- {
- Error("Read"," tracks object must instatiated before passing it to the reader");
- return 1;
- }
- particles->Reset();//clear runs == delete all old events
- tracks->Reset();
-
- if (fDirs) //if array with directories is supplied by user
- {
- Ndirs = fDirs->GetEntries(); //get the number if directories
- }
- else
- {
- Ndirs = 0; //if the array is not supplied read only from current directory
- }
-
- TClonesArray* pbuffer = new TClonesArray("AliHBTParticle",15000);
- TClonesArray* tbuffer = new TClonesArray("AliHBTParticle",15000);
-// pbuffer->BypassStreamer(kFALSE);
-// tbuffer->BypassStreamer(kFALSE);
+
+ if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
+ if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
+
+ fParticlesEvent->Reset();
+ fTracksEvent->Reset();
do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
{
-
- if( (i=OpenFile(aFile, currentdir)) )
+ if (fTree == 0x0)
+ if( (i=OpenNextFile()) )
+ {
+ Error("ReadNext","Skipping directory due to problems with opening files. Errorcode %d",i);
+ fCurrentDir++;
+ continue;
+ }
+ if (fCurrentEvent == (Int_t)fTree->GetEntries())
{
- Error("Read","Skippimg directory due to problems with opening files. Errorcode %d",i);
- currentdir++;
+ delete fTree;
+ fTree = 0x0;
+ delete fFile;
+ fFile = 0x0;
+ fPartBranch = 0x0;
+ fTrackBranch= 0x0;
+ fCurrentDir++;
continue;
}
/***************************/
/***************************/
/***************************/
- TTree* tree = (TTree*)aFile->Get("data");
- if (tree == 0x0)
- {
- Error("Read","Can not get the tree");
- currentdir++;
- continue;
- }
-
- TBranch *trackbranch=tree->GetBranch("tracks");//get the branch with tracks
- if (trackbranch == 0x0) ////check if we got the branch
- {//if not return with error
- Warning("Read","Can't find a branch with tracks !\n");
- }
- else
- {
- trackbranch->SetAddress(&tbuffer);
- }
+
+ Info("ReadNext","Event %d",fCurrentEvent);
+ fTree->GetEvent(fCurrentEvent);
- TBranch *partbranch=tree->GetBranch("particles");//get the branch with particles
- if (partbranch == 0x0) ////check if we got the branch
- {//if not return with error
- Warning("Read","Can't find a branch with particles !\n");
- }
- else
- {
- partbranch->SetAddress(&pbuffer);
- }
-
- nevents = (Int_t)tree->GetEntries();
- Info("Read","________________________________________________________");
- Info("Read","Found %d event(s) in directory %s",nevents,GetDirName(currentdir).Data());
-
- for (Int_t currentEvent =0; currentEvent<nevents;currentEvent++)
- {
- Info("Read","Event %d",currentEvent);
- tree->GetEvent(currentEvent);
-
- counter = 0;
- if (partbranch && trackbranch)
- {
- for(i = 0; i < pbuffer->GetEntries(); i++)
+ counter = 0;
+ if (fPartBranch && fTrackBranch)
+ {
+ Info("ReadNext","Found %d tracks in total.",fTrackBuffer->GetEntries());
+ Info("ReadNext","Found %d particles in total.",fPartBuffer->GetEntries());
+ for(i = 0; i < fPartBuffer->GetEntries(); i++)
+ {
+ tpart = dynamic_cast<AliHBTParticle*>(fPartBuffer->At(i));
+ ttrack = dynamic_cast<AliHBTParticle*>(fTrackBuffer->At(i));
+
+ if( tpart == 0x0 ) continue; //if returned pointer is NULL
+ if( ttrack == 0x0 ) continue; //if returned pointer is NULL
+
+ if (AliHBTParticle::GetDebug() > 9)
+ {
+ Info("ReadNext","Particle:");
+ tpart->Print();
+ Info("ReadNext","Track:");
+ ttrack->Print();
+ }
+ if (ttrack->GetUID() != tpart->GetUID())
{
- tpart = dynamic_cast<AliHBTParticle*>(pbuffer->At(i));
- ttrack = dynamic_cast<AliHBTParticle*>(tbuffer->At(i));
-
- if( tpart == 0x0 ) continue; //if returned pointer is NULL
-
- if (ttrack->GetUID() != tpart->GetUID())
- {
- Error("Read","Sth. is wrong: Track and Particle has different UID.");
- Error("Read","They probobly do not correspond to each other.");
- }
-
- for (Int_t s = 0; s < tpart->GetNumberOfPids(); s++)
+ Error("ReadNext","Sth. is wrong: Track and Particle has different UID.");
+ Error("ReadNext","They probobly do not correspond to each other.");
+ }
+
+ for (Int_t s = 0; s < ttrack->GetNumberOfPids(); s++)
+ {
+ //check if we are intersted with particles of this type
+ //if not take next partilce
+ if( Rejected(ttrack->GetNthPid(s)) )
+ {
+ if (AliHBTParticle::GetDebug() > 9)
+ Info("ReadNext","Track Incarnation %d did not pass PID cut.",ttrack->GetNthPid(s));
+ continue;
+ }
+ TParticlePDG* pdgp = pdgdb->GetParticle(ttrack->GetNthPid(s));
+ if (pdgp == 0x0)//PDG part corresponding to new incarnation
+ {
+ Error("ReadNext","Particle code unknown to PDG DB.");
+ continue;
+ }
+
+ AliHBTParticle* track = new AliHBTParticle(*ttrack);
+
+ //apart of setting PDG code of an incarnation
+ //it is necessary tu recalculate energy on the basis of
+ //new PDG code (mass) hypothesis
+ Double_t mass = pdgp->Mass();//mass of new incarnation
+ Double_t tEtot = TMath::Sqrt( ttrack->Px()*ttrack->Px() +
+ ttrack->Py()*ttrack->Py() +
+ ttrack->Pz()*ttrack->Pz() +
+ mass*mass);//total energy of the new incarnation
+ //update Energy and Calc Mass
+ track->SetMomentum(ttrack->Px(),ttrack->Py(),ttrack->Pz(),tEtot);
+ track->SetCalcMass(mass);
+ track->SetPdgCode(ttrack->GetNthPid(s),ttrack->GetNthPidProb(s));
+
+ if( Rejected(track) )
{
- if( pdgdb->GetParticle(tpart->GetNthPid(s)) == 0x0 ) continue; //if particle has crazy PDG code (not known to our database)
- if( Pass(tpart->GetNthPid(s)) ) continue; //check if we are intersted with particles of this type
- //if not take next partilce
- AliHBTParticle* part = new AliHBTParticle(*tpart);
- part->SetPdgCode(tpart->GetNthPid(s),tpart->GetNthPidProb(s));
- if( Pass(part) )
- {
- delete part;
- continue;
- }
- AliHBTParticle* track = new AliHBTParticle(*ttrack);
-
- particles->AddParticle(totalnevents,part);//put track and particle on the run
- tracks->AddParticle(totalnevents,track);
- counter++;
+ if (AliHBTParticle::GetDebug() > 9)
+ Info("ReadNext","Track Incarnation %d did not pass cut.",ttrack->GetNthPid(s));
+ delete track;
+ continue;
}
- }
- Info("Read"," Read: %d particles and tracks.",counter);
- }
- else
- {
- if (partbranch)
- {
- Info("Read","Found %d particles in total.",pbuffer->GetEntries());
- for(i = 0; i < pbuffer->GetEntries(); i++)
- {
- tpart = dynamic_cast<AliHBTParticle*>(pbuffer->At(i));
- if(tpart == 0x0) continue; //if returned pointer is NULL
-
- for (Int_t s = 0; s < tpart->GetNumberOfPids(); s++)
+ AliHBTParticle* part = new AliHBTParticle(*tpart);//particle has only 1 incarnation (real)
+
+ fParticlesEvent->AddParticle(part);
+ fTracksEvent->AddParticle(track);
+
+ counter++;
+ }
+ }
+ Info("ReadNext"," Read: %d particles and tracks.",counter);
+ }
+ else
+ {
+ if (fPartBranch)
+ {
+ Info("ReadNext","Found %d particles in total.",fPartBuffer->GetEntries());
+ for(i = 0; i < fPartBuffer->GetEntries(); i++)
+ {
+ tpart = dynamic_cast<AliHBTParticle*>(fPartBuffer->At(i));
+ if(tpart == 0x0) continue; //if returned pointer is NULL
+
+ for (Int_t s = 0; s < tpart->GetNumberOfPids(); s++)
+ {
+ if( pdgdb->GetParticle(tpart->GetNthPid(s)) == 0x0 ) continue; //if particle has crazy PDG code (not known to our database)
+ if( Rejected(tpart->GetNthPid(s)) ) continue; //check if we are intersted with particles of this type
+ AliHBTParticle* part = new AliHBTParticle(*tpart);
+ part->SetPdgCode(tpart->GetNthPid(s),tpart->GetNthPidProb(s));
+ if( Rejected(part) )
{
- if( pdgdb->GetParticle(tpart->GetNthPid(s)) == 0x0 ) continue; //if particle has crazy PDG code (not known to our database)
- if( Pass(tpart->GetNthPid(s)) ) continue; //check if we are intersted with particles of this type
-
- AliHBTParticle* part = new AliHBTParticle(*tpart);
- part->SetPdgCode(tpart->GetNthPid(s),tpart->GetNthPidProb(s));
- if( Pass(part) )
- {
- delete part;
- continue;
- }
- particles->AddParticle(totalnevents,part);//put track and particle on the run
- counter++;
+ delete part;
+ continue;
}
- }
- Info("Read"," Read: %d particles.",counter);
- }
- else Info("Read"," Read: 0 particles.");
-
- if (trackbranch)
- {
- for(i = 0; i < tbuffer->GetEntries(); i++)
- {
- tpart = dynamic_cast<AliHBTParticle*>(tbuffer->At(i));
- if(tpart == 0x0) continue; //if returned pointer is NULL
- for (Int_t s = 0; s < tpart->GetNumberOfPids(); s++)
+ fParticlesEvent->AddParticle(part);
+ counter++;
+ }
+ }
+ Info("ReadNext"," Read: %d particles.",counter);
+ }
+ else Info("ReadNext"," Read: 0 particles.");
+
+ if (fTrackBranch)
+ {
+ Info("ReadNext","Found %d tracks in total.",fTrackBuffer->GetEntries());
+ for(i = 0; i < fTrackBuffer->GetEntries(); i++)
+ {
+ ttrack = dynamic_cast<AliHBTParticle*>(fTrackBuffer->At(i));
+ if( ttrack == 0x0 ) continue; //if returned pointer is NULL
+
+ for (Int_t s = 0; s < ttrack->GetNumberOfPids(); s++)
+ {
+ if( Rejected(ttrack->GetNthPid(s)) ) continue; //check if we are intersted with particles of this type
+ //if not take next partilce
+ TParticlePDG* pdgp = pdgdb->GetParticle(ttrack->GetNthPid(s));
+ if (pdgp == 0x0)//PDG part corresponding to new incarnation
+ {
+ Error("ReadNext","Particle code unknown to PDG DB.");
+ continue;
+ }
+ AliHBTParticle* track = new AliHBTParticle(*ttrack);
+
+ //apart of setting PDG code of an incarnation
+ //it is necessary tu recalculate energy on the basis of
+ //new PDG code (mass) hypothesis
+ Double_t mass = pdgp->Mass();//mass of new incarnation
+ Double_t tEtot = TMath::Sqrt( ttrack->Px()*ttrack->Px() +
+ ttrack->Py()*ttrack->Py() +
+ ttrack->Pz()*ttrack->Pz() +
+ mass*mass);//total energy of the new incarnation
+ //update Energy and Calc Mass
+ track->SetMomentum(ttrack->Px(),ttrack->Py(),ttrack->Pz(),tEtot);
+ track->SetCalcMass(mass);
+ track->SetPdgCode(ttrack->GetNthPid(s),ttrack->GetNthPidProb(s));
+
+ if( Rejected(track) )
{
- if( pdgdb->GetParticle(tpart->GetNthPid(s)) == 0x0 ) continue; //if particle has crazy PDG code (not known to our database)
- if( Pass(tpart->GetNthPid(s)) ) continue; //check if we are intersted with particles of this type
-
- AliHBTParticle* part = new AliHBTParticle(*tpart);
- part->SetPdgCode(tpart->GetNthPid(s),tpart->GetNthPidProb(s));
- if( Pass(part) )
- {
- delete part;
- continue;
- }
- tracks->AddParticle(totalnevents,part);//put track and particle on the run
- counter++;
+ delete track;
+ continue;
}
- }
- Info("Read"," Read: %d tracks",counter);
- }
- else Info("Read"," Read: 0 tracks.");
- }
- totalnevents++;
- }
-
- /***************************/
- /***************************/
- /***************************/
- currentdir++;
- delete tree;
- aFile->Close();
- delete aFile;
- aFile = 0x0;
-
- }while(currentdir < Ndirs);
+ fTracksEvent->AddParticle(track);
- delete pbuffer;
- delete tbuffer;
- fIsRead = kTRUE;
- return 0;
+ counter++;
+ }
+ }
+ Info("ReadNext"," Read: %d tracks",counter);
+ }
+ else Info("ReadNext"," Read: 0 tracks.");
+ }
+
+ if (fPartBuffer) fPartBuffer->Delete();
+ if (fTrackBuffer) fTrackBuffer->Delete();
+
+ fCurrentEvent++;
+ fNEventsRead++;
+
+ return 0;
+
+ }while(fCurrentDir < GetNumberOfDirs());
+
+ return 1;//no more directories to read
}
/********************************************************************/
-Int_t AliHBTReaderInternal::OpenFile(TFile*& aFile,Int_t event)
+Int_t AliHBTReaderInternal::OpenNextFile()
{
-
- const TString& dirname = GetDirName(event);
+ //open file in current directory
+ const TString& dirname = GetDirName(fCurrentDir);
if (dirname == "")
{
- Error("OpenFile","Can not get directory name");
+ Error("OpenNextFile","Can not get directory name");
return 4;
}
TString filename = dirname +"/"+ fFileName;
- aFile = TFile::Open(filename.Data());
- if ( aFile == 0x0 )
+ fFile = TFile::Open(filename.Data());
+ if ( fFile == 0x0 )
{
- Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
+ Error("OpenNextFile","Can't open file named %s",filename.Data());
return 1;
}
- if (!aFile->IsOpen())
+ if (fFile->IsOpen() == kFALSE)
{
- Error("OpenFiles","Can't open file with tacks named %s",filename.Data());
+ Error("OpenNextFile","Can't open filenamed %s",filename.Data());
return 1;
}
+
+ fTree = (TTree*)fFile->Get("data");
+ if (fTree == 0x0)
+ {
+ Error("OpenNextFile","Can not get the tree.");
+ return 1;
+ }
+
+
+ fTrackBranch = fTree->GetBranch("tracks");//get the branch with tracks
+ if (fTrackBranch == 0x0) ////check if we got the branch
+ {//if not return with error
+ Info("OpenNextFile","Can't find a branch with tracks !\n");
+ }
+ else
+ {
+ if (fTrackBuffer == 0x0)
+ fTrackBuffer = new TClonesArray("AliHBTParticle",15000);
+ fTrackBranch->SetAddress(&fTrackBuffer);
+ }
+
+ fPartBranch = fTree->GetBranch("particles");//get the branch with particles
+ if (fPartBranch == 0x0) ////check if we got the branch
+ {//if not return with error
+ Info("OpenNextFile","Can't find a branch with particles !\n");
+ }
+ else
+ {
+ if (fPartBuffer == 0x0)
+ fPartBuffer = new TClonesArray("AliHBTParticle",15000);
+ fPartBranch->SetAddress(&fPartBuffer);
+ }
+
+ Info("OpenNextFile","________________________________________________________");
+ Info("OpenNextFile","Found %d event(s) in directory %s",
+ (Int_t)fTree->GetEntries(),GetDirName(fCurrentDir).Data());
+
+ fCurrentEvent = 0;
+
return 0;
}
/********************************************************************/
TClonesArray* pbuffer = new TClonesArray("AliHBTParticle",15000);
TClonesArray* tbuffer = new TClonesArray("AliHBTParticle",15000);
-// pbuffer->BypassStreamer(kFALSE);
-// tbuffer->BypassStreamer(kFALSE);
TClonesArray &particles = *pbuffer;
TClonesArray &tracks = *tbuffer;