/*
$Log$
+Revision 1.24 2002/10/21 09:20:51 alibrary
+Introduce Riostream.h and remove unused variables
+
+Revision 1.23 2002/10/14 14:55:35 hristov
+Merging the VirtualMC branch to the main development branch (HEAD)
+
+Revision 1.20.4.1 2002/06/10 14:57:41 hristov
+Merged with v3-08-02
+
+Revision 1.22 2002/05/15 11:59:49 morsch
+CdEventFile() method added.
+
+Revision 1.21 2002/04/26 10:39:31 morsch
+AliGenExtFile derives from AliGenMC. Generate() uses methods from AliGenMC (N. Carrer)
+
+Revision 1.20 2002/03/22 09:43:28 morsch
+Don't delete the TParticle.
+
+Revision 1.19 2002/02/08 16:50:50 morsch
+Add name and title in constructor.
+
Revision 1.18 2001/11/12 14:31:00 morsch
Memory leaks fixed. (M. Bondila)
// Event generator that using an instance of type AliGenReader
// reads particles from a file and applies cuts.
-#include <iostream.h>
+#include <Riostream.h>
#include "AliGenExtFile.h"
#include "AliRun.h"
ClassImp(AliGenExtFile)
- AliGenExtFile::AliGenExtFile()
- :AliGenerator(-1)
+
+AliGenExtFile::AliGenExtFile()
+ :AliGenMC()
{
// Constructor
//
}
AliGenExtFile::AliGenExtFile(Int_t npart)
- :AliGenerator(npart)
+ :AliGenMC(npart)
{
// Constructor
fName = "ExtFile";
}
}
- Int_t nTracks = fReader->NextEvent();
- if (nTracks == 0) {
- printf("\n No more events !!! !\n");
+ while(1) {
+ Int_t nTracks = fReader->NextEvent();
+ if (nTracks == 0) {
+ // printf("\n No more events !!! !\n");
+ Warning("AliGenExtFile::Generate","\nNo more events in external file!!!\nLast event may be empty or incomplete.\n");
return;
- }
+ }
+
+ //
+ // Particle selection loop
+ //
+ // The selction criterium for the external file generator is as follows:
+ //
+ // 1) All tracs are subjects to the cuts defined by AliGenerator, i.e.
+ // fThetaMin, fThetaMax, fPhiMin, fPhiMax, fPMin, fPMax, fPtMin, fPtMax,
+ // fYMin, fYMax.
+ // If the particle does not satisfy these cuts, it is not put on the
+ // stack.
+ // 2) If fCutOnChild and some specific child is selected (e.g. if
+ // fForceDecay==kSemiElectronic) the event is rejected if NOT EVEN ONE
+ // child falls into the child-cuts.
+ if(fCutOnChild) {
+ // Count the selected children
+ Int_t nSelected = 0;
+
+ for (i = 0; i < nTracks; i++) {
+ TParticle* iparticle = fReader->NextParticle();
+ Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
+ kf = TMath::Abs(kf);
+ if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
+ nSelected++;
+ }
+ }
+ if (!nSelected) continue; // No particle selected: Go to next event
+ fReader->RewindEvent();
+ }
+
+ //
+ // Stack filling loop
+ //
+ for (i = 0; i < nTracks; i++) {
- for (i = 0; i < nTracks; i++) {
TParticle* iparticle = fReader->NextParticle();
- Double_t theta = iparticle->Theta();
- Double_t phi = iparticle->Phi();
- if (phi > TMath::Pi()) phi -= 2.*TMath::Pi();
- Double_t pmom = iparticle->P();
- Double_t pz = iparticle->Pz();
- Double_t e = iparticle->Energy();
- Double_t pt = iparticle->Pt();
- Double_t y;
-
- if ((e-pz) == 0) {
+ if (!KinematicSelection(iparticle,0)) {
+ Double_t pz = iparticle->Pz();
+ Double_t e = iparticle->Energy();
+ Double_t y;
+ if ((e-pz) == 0) {
y = 20.;
- } else if ((e+pz) == 0.) {
+ } else if ((e+pz) == 0.) {
y = -20.;
- } else {
+ } else {
y = 0.5*TMath::Log((e+pz)/(e-pz));
- }
-
- if(theta < fThetaMin || theta > fThetaMax ||
- phi < fPhiMin || phi > fPhiMax ||
- pmom < fPMin || pmom > fPMax ||
- pt < fPtMin || pt > fPtMax ||
- y < fYMin || y > fYMax )
- {
- printf("\n Not selected %d %f %f %f %f %f", i, theta, phi, pmom, pt, y);
- delete iparticle;
- continue;
+ }
+ printf("\n Not selected %d %f %f %f %f %f", i,
+ iparticle->Theta(),
+ iparticle->Phi(),
+ iparticle->P(),
+ iparticle->Pt(),
+ y);
+ //PH delete iparticle;
+ continue;
}
p[0] = iparticle->Px();
p[1] = iparticle->Py();
TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
}
}
- SetTrack(fTrackIt,-1,idpart,p,origin,polar,0,kPPrimary,nt);
- delete iparticle;
- }
+ Int_t decayed = iparticle->GetFirstDaughter();
+ Int_t doTracking = fTrackIt && (decayed < 0) &&
+ (TMath::Abs(idpart) > 10);
+ // printf("*** pdg, first daughter, trk = %d, %d, %d\n",
+ // idpart,decayed, doTracking);
+ SetTrack(doTracking,-1,idpart,p,origin,polar,0,kPPrimary,nt);
+ KeepTrack(nt);
+ } // track loop
+
+ break;
+
+ } // event loop
+
+ SetHighWaterMark(nt);
+ CdEventFile();
+}
+
+void AliGenExtFile::CdEventFile()
+{
+// CD back to the event file
TFile *pFile=0;
-// Get AliRun object or create it
if (!gAlice) {
gAlice = (AliRun*)pFile->Get("gAlice");
if (gAlice) printf("AliRun object found on file\n");
}
TTree *fAli=gAlice->TreeK();
if (fAli) pFile =fAli->GetCurrentFile();
- pFile->cd();
+ pFile->cd();
}