X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=EVGEN%2FAliGenCocktail.cxx;h=b6d3b2c47dbafe3df5760a7b98a4fc41557aba4d;hb=cdcf01d23ba81f038d3578b7ecbad227220275c7;hp=2edcaba00499268bf035a9f20a7118dc7f6405d7;hpb=c8f7f6f998ce8749eccbbe3a2178d0f1fc582f30;p=u%2Fmrichter%2FAliRoot.git diff --git a/EVGEN/AliGenCocktail.cxx b/EVGEN/AliGenCocktail.cxx index 2edcaba0049..b6d3b2c47db 100644 --- a/EVGEN/AliGenCocktail.cxx +++ b/EVGEN/AliGenCocktail.cxx @@ -13,56 +13,7 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ -/* -$Log$ -Revision 1.18 2003/03/24 16:38:40 morsch -Bug corrected. - -Revision 1.17 2003/03/24 15:58:27 morsch -FinishRun() implemented. - -Revision 1.16 2003/01/14 10:50:18 alibrary -Cleanup of STEER coding conventions - -Revision 1.15 2003/01/07 14:13:22 morsch -Communication between generators provising and requesting collision -geometries. - -Revision 1.14 2002/02/08 16:50:50 morsch -Add name and title in constructor. - -Revision 1.13 2001/10/21 18:35:56 hristov -Several pointers were set to zero in the default constructors to avoid memory management problems - -Revision 1.12 2001/06/18 13:07:30 morsch -Forward kinematic ranges to entries only if not set by user. - -Revision 1.11 2001/01/30 09:23:12 hristov -Streamers removed (R.Brun) - -Revision 1.10 2001/01/26 19:55:49 hristov -Major upgrade of AliRoot code - -Revision 1.9 2000/12/21 16:24:06 morsch -Coding convention clean-up - -Revision 1.8 2000/10/27 13:53:29 morsch -AddGenerator: check testbit before setting the pT and momentum range -(D.Y. Peressounko) - -Revision 1.7 2000/10/02 15:15:41 morsch -Use default streamer for AliGenCocktail - -Revision 1.6 2000/09/07 17:04:31 morsch -In Streamer: TIter() after R__b << fEntries (Dmitri Yurevitch Peressounko) - -Revision 1.5 2000/06/09 20:28:51 morsch -All coding rule violations except RS3 corrected (AM) - -Revision 1.4 1999/09/29 09:24:12 fca -Introduction of the Copyright and cvs Log - -*/ +/* $Id$ */ // Container class for AliGenerator through recursion. // Container is itself an AliGenerator. @@ -74,41 +25,53 @@ Introduction of the Copyright and cvs Log #include #include +#include #include "AliGenCocktail.h" #include "AliGenCocktailEntry.h" #include "AliCollisionGeometry.h" #include "AliRun.h" +#include "AliLog.h" +#include "AliMC.h" +#include "AliGenCocktailEventHeader.h" ClassImp(AliGenCocktail) AliGenCocktail::AliGenCocktail() - :AliGenerator() + :AliGenerator(), + fNGenerators(0), + fTotalRate(0.), + fRandom(kFALSE), + fUsePerEventRate(kFALSE), + fProb(0), + fEntries(0), + flnk1(0), + flnk2(0), + fHeader(0) { // Constructor fName = "Cocktail"; fTitle= "Particle Generator using cocktail of generators"; - fEntries = new TList; - flnk1 = 0; - flnk2 = 0; - fNGenerators=0; -} - -AliGenCocktail::AliGenCocktail(const AliGenCocktail & cocktail) -{ -// copy constructor } AliGenCocktail::~AliGenCocktail() { // Destructor delete fEntries; + fEntries = 0; + // delete fHeader; // It is removed in AliRunLoader + fHeader = 0; } void AliGenCocktail:: -AddGenerator(AliGenerator *Generator, char* Name, Float_t RateExp) +AddGenerator(AliGenerator *Generator, const char* Name, Float_t RateExp, TFormula* formula) { // +// Add a generator to the list +// First check that list exists + if (!fEntries) fEntries = new TList(); + fTotalRate += RateExp; +// // Forward parameters to the new generator if(TestBit(kPtRange) && !(Generator->TestBit(kPtRange)) && !(Generator->TestBit(kMomentumRange))) Generator->SetPtRange(fPtMin,fPtMax); @@ -119,23 +82,34 @@ AddGenerator(AliGenerator *Generator, char* Name, Float_t RateExp) Generator->SetYRange(fYMin,fYMax); if (!(Generator->TestBit(kPhiRange))) Generator->SetPhiRange(fPhiMin*180/TMath::Pi(),fPhiMax*180/TMath::Pi()); - if (!(Generator->TestBit(kThetaRange))) + if (!(Generator->TestBit(kThetaRange)) && !(Generator->TestBit(kEtaRange))) Generator->SetThetaRange(fThetaMin*180/TMath::Pi(),fThetaMax*180/TMath::Pi()); - if (!(Generator->TestBit(kVertexRange))) + if (!(Generator->TestBit(kVertexRange))) { Generator->SetOrigin(fOrigin[0], fOrigin[1], fOrigin[2]); - - Generator->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]); - Generator->SetVertexSmear(fVertexSmear); - Generator->SetVertexSource(kContainer); + Generator->SetSigma(fOsigma[0], fOsigma[1], fOsigma[2]); + Generator->SetVertexSmear(fVertexSmear); + Generator->SetVertexSource(kContainer); + } Generator->SetTrackingFlag(fTrackIt); + Generator->SetContainer(this); + + // // Add generator to list - + char theName[256]; + snprintf(theName, 256, "%s_%d",Name, fNGenerators); + Generator->SetName(theName); + AliGenCocktailEntry *entry = new AliGenCocktailEntry(Generator, Name, RateExp); + if (formula) entry->SetFormula(formula); fEntries->Add(entry); fNGenerators++; - } + flnk1 = 0; + flnk2 = 0; + fRandom = kFALSE; + fHeader = 0; +} void AliGenCocktail::Init() { @@ -145,8 +119,29 @@ AddGenerator(AliGenerator *Generator, char* Name, Float_t RateExp) // // Loop over generators and initialize while((entry = (AliGenCocktailEntry*)next())) { + if (fStack) entry->Generator()->SetStack(fStack); entry->Generator()->Init(); } + + next.Reset(); + + if (fRandom) { + fProb.Set(fNGenerators); + next.Reset(); + Float_t sum = 0.; + while((entry = (AliGenCocktailEntry*)next())) { + sum += entry->Rate(); + } + + next.Reset(); + Int_t i = 0; + Float_t psum = 0.; + while((entry = (AliGenCocktailEntry*)next())) { + psum += entry->Rate() / sum; + fProb[i++] = psum; + } + } + next.Reset(); } void AliGenCocktail::FinishRun() @@ -168,46 +163,117 @@ AddGenerator(AliGenerator *Generator, char* Name, Float_t RateExp) TIter next(fEntries); AliGenCocktailEntry *entry = 0; AliGenCocktailEntry *preventry = 0; + AliGenCocktailEntry *collentry = 0; AliGenerator* gen = 0; + if (fHeader) delete fHeader; + + + fHeader = new AliGenCocktailEventHeader("Cocktail Header"); - TObjArray *partArray = gAlice->Particles(); + const TObjArray *partArray = gAlice->GetMCApp()->Particles(); // // Generate the vertex position used by all generators // if(fVertexSmear == kPerEvent) Vertex(); - - // - // Loop over generators and generate events - Int_t igen=0; - - while((entry = (AliGenCocktailEntry*)next())) { - igen++; - if (igen ==1) { + TArrayF eventVertex; + eventVertex.Set(3); + for (Int_t j=0; j < 3; j++) eventVertex[j] = fVertex[j]; + + if (!fRandom) { + // + // Loop over generators and generate events + Int_t igen = 0; + while((entry = (AliGenCocktailEntry*)next())) { + Int_t ntimes = 1; + if (fUsePerEventRate && (gRandom->Rndm() > entry->Rate())) continue; + + igen++; + if (igen ==1) { entry->SetFirst(0); - } else { + } else { entry->SetFirst((partArray->GetEntriesFast())+1); - } -// -// Handle case in which current generator needs collision geometry from previous generator -// - gen = entry->Generator(); - if (gen->NeedsCollisionGeometry()) - { - if (preventry && preventry->Generator()->ProvidesCollisionGeometry()) + } + gen = entry->Generator(); + if (gen->ProvidesCollisionGeometry()) collentry = entry; + // + // Handle case in which current generator needs collision geometry from previous generator + // + if (gen->NeedsCollisionGeometry() && (entry->Formula() == 0)) { - gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry()); - } else { + if (preventry && preventry->Generator()->ProvidesCollisionGeometry()) + { + gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry()); + } else { Fatal("Generate()", "No Collision Geometry Provided"); + } } + // + // Number of signals is calculated from Collision Geometry + // and entry with given centrality bin is selected + // + if (entry->Formula() != 0) + { + if (!collentry) { + Fatal("Generate()", "No Collision Geometry Provided"); + return; + } + AliCollisionGeometry* coll = (collentry->Generator())->CollisionGeometry(); + Float_t b = coll->ImpactParameter(); + Int_t nsig = Int_t(entry->Formula()->Eval(b)); + Int_t bin = entry->Bin() - 100; + if (bin > 0) { + if (bin != nsig) continue; + } else { + if (nsig < 1) nsig = 1; + AliInfo(Form("Signal Events %13.3f %5d %5d\n", b, coll->HardScatters(), nsig)); + ntimes = nsig; + } + } + + gen->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2)); + + for (Int_t i = 0; i < ntimes; i++) gen->Generate(); + entry->SetLast(partArray->GetEntriesFast()); + preventry = entry; + } + } else if (fRandom) { + // + // Select a generator randomly + // + Int_t i; + Float_t p0 = gRandom->Rndm(); + + for (i = 0; i < fNGenerators; i++) { + if (p0 < fProb[i]) break; } - entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2)); - entry->Generator()->Generate(); + + entry = (AliGenCocktailEntry*) fEntries->At(i); + entry->SetFirst(0); + gen = entry->Generator(); + gen->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2)); + gen->Generate(); entry->SetLast(partArray->GetEntriesFast()); - preventry = entry; - } + } + next.Reset(); + +// Event Vertex + fHeader->SetPrimaryVertex(eventVertex); + fHeader->CalcNProduced(); + gAlice->SetGenEventHeader(fHeader); +} + +void AliGenCocktail::SetVertexSmear(VertexSmear_t smear) +{ +// Set vertex smearing and propagate it to the generators + + AliGenerator::SetVertexSmear(smear); + TIter next(fEntries); + while (AliGenCocktailEntry* entry = (AliGenCocktailEntry*)next()) { + entry->Generator()->SetVertexSmear(smear); + } } AliGenCocktailEntry * AliGenCocktail::FirstGenerator() @@ -264,10 +330,12 @@ NextGeneratorPair(AliGenCocktailEntry*& e1, AliGenCocktailEntry*& e2) } } -AliGenCocktail& AliGenCocktail::operator=(const AliGenCocktail& rhs) +void AliGenCocktail::AddHeader(AliGenEventHeader* header) { -// Assignment operator - return *this; +// Add a header to the list + if (fHeader) fHeader->AddHeader(header); } + +