#include <TFile.h>
#include <TParticle.h>
#include <TDatabasePDG.h>
#include <TTree.h>
#include <TVirtualMC.h>
#include "AliGenReaderCwn.h"
ClassImp(AliGenReaderCwn)
AliGenReaderCwn::AliGenReaderCwn():
fNcurrent(0),
fNparticle(0),
fNparticleMax(0),
fTreeNtuple(0),
fNihead(0),
fNrhead(0),
fIdpart(0),
fTheta(0.),
fPhi(0.),
fP(0.),
fE(0.)
{
Int_t i;
for (i = 0; i < 6; i++) fRhead[i] = 0.;
for (i = 0; i < 12; i++) fIhead[i] = 0;
}
AliGenReaderCwn::AliGenReaderCwn(const AliGenReaderCwn &reader):
AliGenReader(reader),
fNcurrent(0),
fNparticle(0),
fNparticleMax(0),
fTreeNtuple(0),
fNihead(0),
fNrhead(0),
fIdpart(0),
fTheta(0.),
fPhi(0.),
fP(0.),
fE(0.)
{
Int_t i;
for (i = 0; i < 6; i++) fRhead[i] = 0.;
for (i = 0; i < 12; i++) fIhead[i] = 0;
reader.Copy(*this);
}
AliGenReaderCwn::~AliGenReaderCwn()
{
delete fTreeNtuple;
}
void AliGenReaderCwn::Init()
{
TFile *pFile=0;
if (!pFile) {
pFile = new TFile(fFileName);
pFile->cd();
printf("\n I have opened %s file \n", fFileName);
}
fTreeNtuple = (TTree*)gDirectory->Get("h888");
TTree *h2=fTreeNtuple;
h2->SetBranchAddress("Nihead",&fNihead);
h2->SetBranchAddress("Ihead",fIhead);
h2->SetBranchAddress("Nrhead",&fNrhead);
h2->SetBranchAddress("Rhead",fRhead);
h2->SetBranchAddress("Idpart",&fIdpart);
h2->SetBranchAddress("Theta",&fTheta);
h2->SetBranchAddress("Phi",&fPhi);
h2->SetBranchAddress("P",&fP);
h2->SetBranchAddress("E",&fE);
}
Int_t AliGenReaderCwn::NextEvent()
{
Int_t nTracks;
fNparticle = 0;
TFile* pFile = fTreeNtuple->GetCurrentFile();
pFile->cd();
Int_t nentries = (Int_t) fTreeNtuple->GetEntries();
if (fNcurrent < nentries) {
fNcurrent++;
Int_t i5=fIhead[4];
Int_t i6=fIhead[5];
if (i5==0) {
printf("\n This should never happen !\n");
nTracks = 0;
} else {
printf("\n Next event contains %d tracks! \n", i6);
nTracks = i6;
}
fNparticleMax = nTracks;
return nTracks;
}
return 0;
}
TParticle* AliGenReaderCwn::NextParticle()
{
Float_t prwn;
Float_t p[4];
if (fCode == kGEANT3) fIdpart=TVirtualMC::GetMC()->PDGFromId(fIdpart);
Double_t amass = TDatabasePDG::Instance()->GetParticle(fIdpart)->Mass();
if(fE<=amass) {
Warning("Generate","Particle %d E = %f mass = %f %f %f \n",
fIdpart,fE,amass, fPhi, fTheta);
prwn=0;
} else {
prwn=sqrt((fE+amass)*(fE-amass));
}
fTheta *= TMath::Pi()/180.;
fPhi = (fPhi-180)*TMath::Pi()/180.;
p[0] = prwn*TMath::Sin(fTheta)*TMath::Cos(fPhi);
p[1] = prwn*TMath::Sin(fTheta)*TMath::Sin(fPhi);
p[2] = prwn*TMath::Cos(fTheta);
p[3] = fE;
TParticle* particle = new TParticle(fIdpart, 0, -1, -1, -1, -1, p[0], p[1], p[2], p[3], 0., 0., 0., 0.);
fNcurrent++;
fNparticle++;
return particle;
}
AliGenReaderCwn& AliGenReaderCwn::operator=(const AliGenReaderCwn& rhs)
{
rhs.Copy(*this);
return *this;
}
void AliGenReaderCwn::Copy(TObject&) const
{
Fatal("Copy","Not implemented!\n");
}