+ //
+ // Stack filling loop
+ //
+ fNprimaries = 0;
+ for (i = 0; i < nTracks; i++) {
+ TParticle* jparticle = fReader->NextParticle();
+ Bool_t selected = KinematicSelection(jparticle,0);
+ if (!selected) continue;
+ p[0] = jparticle->Px();
+ p[1] = jparticle->Py();
+ p[2] = jparticle->Pz();
+ p[3] = jparticle->Energy();
+
+ Int_t idpart = jparticle->GetPdgCode();
+ if(fVertexSmear==kPerTrack)
+ {
+ Rndm(random,6);
+ for (j = 0; j < 3; j++) {
+ origin[j]=fOrigin[j]+
+ fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
+ TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
+ }
+ } else {
+ origin[0] = fVertex[0] + jparticle->Vx();
+ origin[1] = fVertex[1] + jparticle->Vy();
+ origin[2] = fVertex[2] + jparticle->Vz();
+ }
+ Double_t tof = jparticle->T();
+ Int_t doTracking = fTrackIt && selected && (jparticle->TestBit(kTransportBit));
+ Int_t parent = jparticle->GetFirstMother();
+
+ PushTrack(doTracking, parent, idpart,
+ p[0], p[1], p[2], p[3], origin[0], origin[1], origin[2], tof,
+ polar[0], polar[1], polar[2],
+ kPPrimary, nt, 1., jparticle->GetStatusCode());
+
+ KeepTrack(nt);
+ fNprimaries++;
+ } // track loop
+
+ // Generated event header
+
+ AliGenEventHeader * header = new AliGenEventHeader();
+ header->SetNProduced(fNprimaries);
+ header->SetPrimaryVertex(fVertex);
+ AddHeader(header);
+ break;
+
+ } // event loop
+
+ SetHighWaterMark(nt);
+ CdEventFile();
+}