1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
20 //-------------------------------------------------------------
21 // Generate Beam-Gas-Events
22 // Default: underlying event: pO @ 7 TeV (fixed target)
24 // underlying event can be changed by adding generators
25 // in the same way as to AliGenCocktail before calling
27 // Author: Jochen Klein
28 //-------------------------------------------------------------
31 #include <TObjArray.h>
32 #include <TParticle.h>
34 #include "AliGenBeamGasNew.h"
35 #include "AliGenCocktail.h"
36 #include "AliGenCocktailEntry.h"
37 #include "AliGenCocktailEventHeader.h"
38 #include "AliGenHijing.h"
39 #include "AliCollisionGeometry.h"
45 #include "AliHeader.h"
46 #include "AliGenEventHeader.h"
48 ClassImp(AliGenBeamGasNew)
50 Float_t EtaToTheta(Float_t arg) { return (180./TMath::Pi())*2.*atan(exp(-arg)); }
52 AliGenBeamGasNew::AliGenBeamGasNew() :
59 // Default constructor
62 AliGenBeamGasNew::~AliGenBeamGasNew()
66 void AliGenBeamGasNew::SetTimeWindow(Float_t twindow) { fTwindow = twindow; }
68 bool AliGenBeamGasNew::SetRate(Float_t rate) {
77 void AliGenBeamGasNew::SetZWindow(Float_t zwindow) { fZwindow = zwindow; }
79 void AliGenBeamGasNew::Init()
81 // Initialisation of the class
82 // if no generators were added before calling Init()
83 // AliGenHijing is added configured for pO
85 fVertexSmear = kPerEvent;
86 fVertexSource = kInternal;
89 // Adding default underlying event in case none was specified
90 // p-O-collision at 7 TeV (fixed target)
92 AliGenHijing *gen = new AliGenHijing(-1);
93 gen->SetReferenceFrame("LAB");
94 gen->SetEnergyCMS(7000);
95 gen->SetProjectile("P",1,1);
96 gen->SetTarget("A",16,8);
97 gen->SetPhiRange(0,360);
98 Float_t thmin = EtaToTheta(8);
99 Float_t thmax = EtaToTheta(-8);
100 gen->SetThetaRange(thmin, thmax);
101 gen->SetOrigin(0,0,0);
102 gen->SetSigma(0,0,0);
103 gen->KeepFullEvent();
104 gen->SetShadowing(1);
105 gen->SetDecaysOff(1);
106 gen->SetSpectators(1);
107 gen->SetSelectAll(1);
108 gen->SetRandomPz(kFALSE);
109 gen->SetPileUpTimeWindow(0.);
110 AddGenerator(gen,"Hijing pO",1);
113 TIter next(fEntries);
114 AliGenCocktailEntry *entry;
116 // Loop over generators and initialize
117 while((entry = (AliGenCocktailEntry*)next())) {
118 if (fStack) entry->Generator()->SetStack(fStack);
119 entry->Generator()->Init();
125 fProb.Set(fNGenerators);
128 while((entry = (AliGenCocktailEntry*)next())) {
129 sum += entry->Rate();
135 while((entry = (AliGenCocktailEntry*)next())) {
136 psum += entry->Rate() / sum;
143 void AliGenBeamGasNew::VertexInternal()
145 // calculation of the interaction vertex for the beam gas event
146 // both spatial and time coordinate are adjusted.
152 gRandom->RndmArray(2,random);
153 fVertex[0] = fVertex[1] = 0;
154 fVertex[2] = random[0] * 2 * fZwindow - fZwindow;
155 nbunch = fTwindow/25e-9;
156 bunch = floor(2*nbunch * random[1] - nbunch);
157 fItime = fVertex[2] / 100 / 3e8 + bunch * 25e-9;
158 AliInfo(Form("fItime: %13.3e \n", fItime));
161 void AliGenBeamGasNew::Generate()
164 // Generate the collisions for one event
166 Int_t numbg = gRandom->Poisson(fRate*fZwindow/100*2*fTwindow);
167 if (numbg == 0) return;
169 TIter next(fEntries);
170 AliGenCocktailEntry *entry = 0;
171 AliGenCocktailEntry *preventry = 0;
172 AliGenerator* gen = 0;
178 if (fHeader) delete fHeader;
179 fHeader = new AliGenCocktailEventHeader("Beamgas Header");
181 const TObjArray *partArray = gAlice->GetMCApp()->Particles();
182 AliStack *stack = AliRunLoader::Instance()->Stack();
184 for (Int_t l = 0; l < numbg; l++) {
186 sign = (gRandom->Rndm() < 0.5)? -1. : 1.;
188 for (Int_t j=0; j < 3; j++) eventVertex[j] = fVertex[j];
192 while((entry = (AliGenCocktailEntry*)next())) {
193 if (fUsePerEventRate && (gRandom->Rndm() > entry->Rate())) continue;
197 entry->SetFirst(lastpart);
199 entry->SetFirst((partArray->GetEntriesFast())+1);
202 // Handle case in which current generator needs collision geometry from previous generator
204 gen = entry->Generator();
205 if (gen->NeedsCollisionGeometry())
207 if (preventry && preventry->Generator()->ProvidesCollisionGeometry())
209 gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry());
211 Fatal("Generate()", "No Collision Geometry Provided");
214 entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
215 entry->Generator()->Generate();
216 entry->SetLast(partArray->GetEntriesFast());
221 // Select a generator randomly
224 Float_t p0 = gRandom->Rndm();
226 for (i = 0; i < fNGenerators; i++) {
227 if (p0 < fProb[i]) break;
230 entry = (AliGenCocktailEntry*) fEntries->At(i);
231 entry->SetFirst(lastpart);
232 gen = entry->Generator();
233 gen->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
235 entry->SetLast(partArray->GetEntriesFast());
238 for (Int_t k = lastpart; k < stack->GetNprimary(); k++) {
239 stack->Particle(k)->ProductionVertex(v);
241 eventVertex[2] *= sign;
242 v[3] = fItime; // ??? +=
243 stack->Particle(k)->SetProductionVertex(v);
244 stack->Particle(k)->Momentum(v);
246 stack->Particle(k)->SetMomentum(v);
249 ((AliGenEventHeader*) fHeader->GetHeaders()->Last())->SetPrimaryVertex(eventVertex);
251 lastpart = stack->GetNprimary();
255 fHeader->CalcNProduced();
258 fContainer->AddHeader(fHeader);
260 gAlice->SetGenEventHeader(fHeader);