X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=EVGEN%2FAliGenExtFile.cxx;h=b56a2e123688c9b532dae19b7577135be2de805e;hb=c840ffa40f771457c9f9cba81e0c3716cd70bece;hp=71c06a26652838a7a7610a0a68a204cfa45837cc;hpb=506ef218b6dab2a763a013c83601d07a694511f5;p=u%2Fmrichter%2FAliRoot.git diff --git a/EVGEN/AliGenExtFile.cxx b/EVGEN/AliGenExtFile.cxx index 71c06a26652..b56a2e12368 100644 --- a/EVGEN/AliGenExtFile.cxx +++ b/EVGEN/AliGenExtFile.cxx @@ -31,34 +31,42 @@ #include +#include "AliLog.h" #include "AliGenExtFile.h" #include "AliRunLoader.h" #include "AliHeader.h" #include "AliStack.h" #include "AliGenEventHeader.h" +#include "AliGenReader.h" #include #include #include +using std::cout; +using std::endl; +using std::map; + ClassImp(AliGenExtFile) AliGenExtFile::AliGenExtFile() :AliGenMC(), fFileName(0), - fReader(0) + fReader(0), + fStartEvent(0) { // Constructor // // Read all particles - fNpart =- 1; + fNpart = -1; } AliGenExtFile::AliGenExtFile(Int_t npart) :AliGenMC(npart), fFileName(0), - fReader(0) + fReader(0), + fStartEvent(0) { // Constructor fName = "ExtFile"; @@ -79,21 +87,38 @@ void AliGenExtFile::Init() if (fReader) fReader->Init(); } - +//___________________________________________________________ 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 time = 0.; + Double_t p[4]; Float_t random[6]; Int_t i = 0, j, nt; // // if (fVertexSmear == kPerEvent) Vertex(); + // Fast forward up to start Event + for (Int_t ie=0; ieNextEvent(); + 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 (Int_t i=0; iNextParticle()) + AliFatal("Error while skipping tracks"); + } + cout << "Skipping event " << ie << endl; + } + fStartEvent = 0; // do not skip events the second time + while(1) { Int_t nTracks = fReader->NextEvent(); if (nTracks == 0) { @@ -131,17 +156,91 @@ void AliGenExtFile::Generate() fReader->RewindEvent(); } + // + // Stack selection loop + // + class SelectorLogic { // need to do recursive back tracking, requires a "nested" function + private: + Int_t idCount; + map firstMotherMap; + map secondMotherMap; + map selectedIdMap; + map newIdMap; + void selectMothersToo(Int_t particleId) { + Int_t mum1 = firstMotherMap[particleId]; + if (mum1 > -1 && !selectedIdMap[mum1]) { + selectedIdMap[mum1] = true; + selectMothersToo(mum1); + } + Int_t mum2 = secondMotherMap[particleId]; + if (mum2 > -1 && !selectedIdMap[mum2]) { + selectedIdMap[mum2] = true; + selectMothersToo(mum2); + } + } + public: + void init() { + idCount = 0; + } + void setData(Int_t id, Int_t mum1, Int_t mum2, Bool_t selected) { + idCount++; // we know that this function is called in succession of ids, so counting is fine to determine max id + firstMotherMap[id] = mum1; + secondMotherMap[id] = mum2; + selectedIdMap[id] = selected; + } + void reselectCuttedMothersAndRemapIDs() { + for (Int_t id = 0; id < idCount; ++id) { + if (selectedIdMap[id]) { + selectMothersToo(id); + } + } + Int_t newId = 0; + for (Int_t id = 0; id < idCount; id++) { + if (selectedIdMap[id]) { + newIdMap[id] = newId; ++newId; + } else { + newIdMap[id] = -1; + } + } + } + Bool_t isSelected(Int_t id) { + return selectedIdMap[id]; + } + Int_t newId(Int_t id) { + if (id == -1) return -1; + return newIdMap[id]; + } + }; + SelectorLogic selector; + selector.init(); + for (Int_t i = 0; i < nTracks; i++) { + TParticle* jparticle = fReader->NextParticle(); + selector.setData(i, + jparticle->GetFirstMother(), + jparticle->GetSecondMother(), + KinematicSelection(jparticle,0)); + } + selector.reselectCuttedMothersAndRemapIDs(); + 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; + TParticle* jparticle = fReader->NextParticle(); + Bool_t selected = selector.isSelected(i); + if (!selected) { + continue; + } + Int_t parent = selector.newId(jparticle->GetFirstMother()); +// printf("particle %d -> %d, with mother %d -> %d\n", i, selector.newId(i), jparticle->GetFirstMother(), parent); + p[0] = jparticle->Px(); p[1] = jparticle->Py(); p[2] = jparticle->Pz(); + p[3] = jparticle->Energy(); + Int_t idpart = jparticle->GetPdgCode(); if(fVertexSmear==kPerTrack) { @@ -151,25 +250,33 @@ void AliGenExtFile::Generate() fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())* TMath::Sqrt(-2*TMath::Log(random[2*j+1])); } + Rndm(random,2); + time = fTimeOrigin + fOsigma[2]/TMath::Ccgs()* + TMath::Cos(2*random[0]*TMath::Pi())* + TMath::Sqrt(-2*TMath::Log(random[1])); } else { origin[0] = fVertex[0] + jparticle->Vx(); origin[1] = fVertex[1] + jparticle->Vy(); origin[2] = fVertex[2] + jparticle->Vz(); + time = fTime + jparticle->T(); } + Int_t doTracking = fTrackIt && selected && (jparticle->TestBit(kTransportBit)); - Int_t doTracking = fTrackIt && selected && !(jparticle->TestBit(kTransportBit)); - Int_t parent = jparticle->GetFirstMother(); - - PushTrack(doTracking, parent, idpart, p, origin, polar, 0, kPPrimary, nt); + PushTrack(doTracking, parent, idpart, + p[0], p[1], p[2], p[3], origin[0], origin[1], origin[2], time, + polar[0], polar[1], polar[2], + kPPrimary, nt, 1., jparticle->GetStatusCode()); + KeepTrack(nt); fNprimaries++; } // track loop // Generated event header - - AliGenEventHeader * header = new AliGenEventHeader(); + AliGenEventHeader * header = fReader->GetGenEventHeader(); + if (!header) header = new AliGenEventHeader(); header->SetNProduced(fNprimaries); header->SetPrimaryVertex(fVertex); + header->SetInteractionTime(fTime); AddHeader(header); break; @@ -179,6 +286,7 @@ void AliGenExtFile::Generate() CdEventFile(); } +//___________________________________________________________ void AliGenExtFile::CdEventFile() { // CD back to the event file