X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=EVGEN%2FAliGenExtFile.cxx;h=bc35f381073284fff7bb77af4475d121102f6114;hb=c6fd869890f35f1d363f880dc23975f0a376b2b1;hp=cc1631846aa197e0493eba38a559aeef74261a6c;hpb=14412d0b464ad6587c22838c5089298545382c46;p=u%2Fmrichter%2FAliRoot.git diff --git a/EVGEN/AliGenExtFile.cxx b/EVGEN/AliGenExtFile.cxx index cc1631846aa..bc35f381073 100644 --- a/EVGEN/AliGenExtFile.cxx +++ b/EVGEN/AliGenExtFile.cxx @@ -13,96 +13,58 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ -/* -$Log$ -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) - -Revision 1.17 2001/11/09 09:12:58 morsch -Generalization by using AliGenReader object to read particles from file. - -Revision 1.16 2001/07/27 17:09:35 morsch -Use local SetTrack, KeepTrack and SetHighWaterMark methods -to delegate either to local stack or to stack owned by AliRun. -(Piotr Skowronski, A.M.) - -Revision 1.15 2001/01/23 13:29:37 morsch -Add method SetParticleCode and enum type Code_t to handle both PDG (new ntuples) -and GEANT3 codes (old ntuples) in input file. - -Revision 1.14 2000/12/21 16:24:06 morsch -Coding convention clean-up - -Revision 1.13 2000/11/30 07:12:50 alibrary -Introducing new Rndm and QA classes - -Revision 1.12 2000/10/27 13:54:45 morsch -Remove explicite reference to input file from constuctor. - -Revision 1.11 2000/10/02 21:28:06 fca -Removal of useless dependecies via forward declarations - -Revision 1.10 2000/07/11 18:24:55 fca -Coding convention corrections + few minor bug fixes - -Revision 1.9 2000/06/14 15:20:09 morsch -Include clean-up (IH) - -Revision 1.8 2000/06/09 20:36:44 morsch -All coding rule violations except RS3 corrected - -Revision 1.7 2000/02/16 14:56:27 morsch -Convert geant particle code into pdg code before putting particle on the stack. - -Revision 1.6 1999/11/09 07:38:48 fca -Changes for compatibility with version 2.23 of ROOT - -Revision 1.5 1999/09/29 09:24:12 fca -Introduction of the Copyright and cvs Log - -*/ - +/* $Id$ */ // Event generator that using an instance of type AliGenReader -// reads particles from a file and applies cuts. +// reads particles from a file and applies cuts. +// Example: In your Config.C you can include the following lines +// AliGenExtFile *gener = new AliGenExtFile(-1); +// gener->SetMomentumRange(0,999); +// gener->SetPhiRange(-180.,180.); +// gener->SetThetaRange(0,180); +// gener->SetYRange(-999,999); +// AliGenReaderTreeK * reader = new AliGenReaderTreeK(); +// reader->SetFileName("myFileWithTreeK.root"); +// gener->SetReader(reader); +// gener->Init(); -#include + +#include #include "AliGenExtFile.h" -#include "AliRun.h" +#include "AliRunLoader.h" +#include "AliHeader.h" +#include "AliStack.h" +#include "AliGenEventHeader.h" #include #include #include - ClassImp(AliGenExtFile) - AliGenExtFile::AliGenExtFile() - :AliGenerator(-1) +ClassImp(AliGenExtFile) + +AliGenExtFile::AliGenExtFile() + :AliGenMC(), + fFileName(0), + fReader(0) { // Constructor // // Read all particles fNpart =- 1; - fReader = 0; } AliGenExtFile::AliGenExtFile(Int_t npart) - :AliGenerator(npart) + :AliGenMC(npart), + fFileName(0), + fReader(0) { // Constructor fName = "ExtFile"; fTitle = "Primaries from ext. File"; - fReader = 0; } -AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile) -{ -// copy constructor -} //____________________________________________________________ AliGenExtFile::~AliGenExtFile() { @@ -122,95 +84,114 @@ void AliGenExtFile::Generate() { // Generate particles - Float_t polar[3] = {0,0,0}; + Double_t polar[3] = {0,0,0}; // - Float_t origin[3] = {0,0,0}; - Float_t p[3]; + Double_t origin[3] = {0,0,0}; + Double_t p[4]; Float_t random[6]; - Int_t i, j, nt; + Int_t i = 0, j, nt; // - for (j=0;j<3;j++) origin[j]=fOrigin[j]; - if(fVertexSmear == kPerTrack) { - Rndm(random,6); - for (j = 0; j < 3; j++) { - origin[j] += fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())* - TMath::Sqrt(-2*TMath::Log(random[2*j+1])); - } - } + // + if (fVertexSmear == kPerEvent) Vertex(); - 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; - } - - 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) { - y = 20.; - } else if ((e+pz) == 0.) { - y = -20.; - } 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; - } - p[0] = iparticle->Px(); - p[1] = iparticle->Py(); - p[2] = iparticle->Pz(); - Int_t idpart = iparticle->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])); + } + + // + // Particle selection loop + // + // The selection criterium for the external file generator is as follows: + // + // 1) All tracks are subject 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. + TParticle* iparticle = 0x0; + + if(fCutOnChild) { + // Count the selected children + Int_t nSelected = 0; + while ((iparticle=fReader->NextParticle()) ) { + Int_t kf = CheckPDGCode(iparticle->GetPdgCode()); + kf = TMath::Abs(kf); + if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) { + nSelected++; } } - SetTrack(fTrackIt,-1,idpart,p,origin,polar,0,kPPrimary,nt); - } - 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"); - if (!gAlice) gAlice = new AliRun("gAlice","Alice test program"); - } - TTree *fAli=gAlice->TreeK(); - if (fAli) pFile =fAli->GetCurrentFile(); - pFile->cd(); -} + if (!nSelected) continue; // No particle selected: Go to next event + fReader->RewindEvent(); + } + // + // 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(); +} -AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs) +void AliGenExtFile::CdEventFile() { -// Assignment operator - return *this; +// CD back to the event file + AliRunLoader::Instance()->CdGAFile(); } - - -