#include <TVirtualMC.h>
#include <TDatabasePDG.h>
#include <TParticle.h>
#include "AliLog.h"
#include "AliGenReaderSL.h"
#include "AliRun.h"
#include "AliStack.h"
ClassImp(AliGenReaderSL)
AliGenReaderSL& AliGenReaderSL::operator=(const AliGenReaderSL& rhs)
{
rhs.Copy(*this);
return *this;
}
void AliGenReaderSL::Copy(TObject&) const
{
Fatal("Copy","Not implemented!\n");
}
void AliGenReaderSL::Init()
{
if( !(fFile = fopen(fFileName,"r")) ) {
printf("Couldn't open input file: %s \n", fFileName);
} else {
printf("File %s opened \n", fFileName);
}
}
Int_t AliGenReaderSL::NextEvent()
{
if (fFormat == 0) {
fNParticles = 4;
return (fNParticles);
}
char linelabel[20];
int i1 = 0;
int i2 = 0;
int i3 = 0;
double x1 = 0.0;
double x2 = 0.0;
double x3 = 0.0;
double x4 = 0.0;
int ntrk = 0;
int nvtx = 0;
Float_t eGamma1, eGamma2;
eGamma2 = 0.;
Int_t nb;
nb = fscanf(fFile,"%6s %d %d %d ",linelabel, &i1, &ntrk, &i2);
if (nb <= 0) return (0);
if (nb != 4) AliFatal("malformed EVENT line");
fNParticles = ntrk;
if (fFormat == 1) {
nb = fscanf(fFile, "%14s %f ",linelabel, &eGamma1);
if (nb <= 0) return (0);
if (nb != 2) AliFatal("malformed GAMMA1 line");
} else if (fFormat == 2) {
nb = fscanf(fFile, "%14s %f %f ",linelabel, &eGamma1, &eGamma2);
if (nb <= 0) return (0);
if (nb != 3) AliFatal("malformed GAMMA1,GAMMA2 line");
}
nb = fscanf(fFile, "%7s %lf %lf %lf %lf %d %d %d %d",
linelabel, &x1, &x2, &x3, &x4, &i1, &i2, &i3, &nvtx);
if (nb <= 0) return (0);
if (nb != 9) AliFatal("malformed VERTEX line");
if(ntrk != nvtx) printf("ERROR: ntrk = %5d nvtx = %5d \n", ntrk, nvtx);
return (fNParticles);
}
TParticle* AliGenReaderSL::NextParticle()
{
Float_t px, py, pz;
Int_t pdg;
static TParticle particle;
Int_t nb;
if (fFormat == 0) {
Int_t ievent;
Int_t ipart;
nb = fscanf(fFile, "%d %d %d %f %f %f ", &ievent, &ipart, &pdg, &px, &py, &pz);
if (nb <= 0) return NULL;
if (nb != 6) AliFatal("malformed TRACK line");
if (pdg == 8) pdg = 211;
if (pdg == 9) pdg = -211;
} else {
char tracklabel[20];
int i1 = 0;
int i2 = 0;
int i3 = 0;
int i4 = 0;
nb = fscanf(fFile,"%6s %d %f %f %f %d %d %d %d",
tracklabel, &i1, &px, &py, &pz, &i2, &i3, &i4, &pdg);
if (nb <= 0) return NULL;
if (nb != 9) AliFatal("malformed TRACK line");
}
const Double_t mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
const Float_t e = TMath::Sqrt(px * px + py * py + pz * pz + mass * mass);
particle.SetMomentum(px, py, pz, e);
particle.SetPdgCode(pdg);
particle.SetFirstMother(-1);
particle.SetLastMother(-1);
particle.SetBit(kTransportBit);
return &particle;
}
void AliGenReaderSL::RewindEvent()
{
AliFatal("AliGenReaderSL::RewindEvent() is not implemented");
}