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 "../THijing/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) {
76 void AliGenBeamGasNew::SetZWindow(Float_t zwindow) { fZwindow = zwindow; }
78 void AliGenBeamGasNew::Init()
80 // Initialisation of the class
81 // if no generators were added before calling Init()
82 // AliGenHijing is added configured for pO
84 fVertexSmear = kPerEvent;
85 fVertexSource = kInternal;
88 // Adding default underlying event in case none was specified
89 // p-O-collision at 7 TeV (fixed target)
91 AliGenHijing *gen = new AliGenHijing(-1);
92 gen->SetReferenceFrame("LAB");
93 gen->SetEnergyCMS(7000);
94 gen->SetProjectile("P",1,1);
95 gen->SetTarget("A",16,8);
96 gen->SetPhiRange(0,360);
97 Float_t thmin = EtaToTheta(8);
98 Float_t thmax = EtaToTheta(-8);
99 gen->SetThetaRange(thmin, thmax);
100 gen->SetOrigin(0,0,0);
101 gen->SetSigma(0,0,0);
102 gen->KeepFullEvent();
103 gen->SetShadowing(1);
104 gen->SetDecaysOff(1);
105 gen->SetSpectators(1);
106 gen->SetSelectAll(1);
107 gen->SetRandomPz(kFALSE);
108 gen->SetPileUpTimeWindow(0.);
109 AddGenerator(gen,"Hijing pO",1);
112 TIter next(fEntries);
113 AliGenCocktailEntry *entry;
115 // Loop over generators and initialize
116 while((entry = (AliGenCocktailEntry*)next())) {
117 if (fStack) entry->Generator()->SetStack(fStack);
118 entry->Generator()->Init();
124 fProb.Set(fNGenerators);
127 while((entry = (AliGenCocktailEntry*)next())) {
128 sum += entry->Rate();
134 while((entry = (AliGenCocktailEntry*)next())) {
135 psum += entry->Rate() / sum;
142 void AliGenBeamGasNew::VertexInternal()
144 // calculation of the interaction vertex for the beam gas event
145 // both spatial and time coordinate are adjusted.
151 gRandom->RndmArray(2,random);
152 fVertex[0] = fVertex[1] = 0;
153 fVertex[2] = random[0] * 2 * fZwindow - fZwindow;
154 nbunch = fTwindow/25e-9;
155 bunch = floor(2*nbunch * random[1] - nbunch);
156 fItime = fVertex[2] / 100 / 3e8 + bunch * 25e-9;
157 AliInfo(Form("fItime: %13.3e \n", fItime));
160 void AliGenBeamGasNew::Generate()
163 // Generate the collisions for one event
165 Int_t numbg = gRandom->Poisson(fRate*fZwindow/100*2*fTwindow);
166 if (numbg == 0) return;
168 TIter next(fEntries);
169 AliGenCocktailEntry *entry = 0;
170 AliGenCocktailEntry *preventry = 0;
171 AliGenerator* gen = 0;
177 if (fHeader) delete fHeader;
178 fHeader = new AliGenCocktailEventHeader("Beamgas Header");
180 TObjArray *partArray = gAlice->GetMCApp()->Particles();
181 AliStack *stack = gAlice->GetRunLoader()->Stack();
183 for (Int_t l = 0; l < numbg; l++) {
185 sign = (gRandom->Rndm() < 0.5)? -1. : 1.;
187 for (Int_t j=0; j < 3; j++) eventVertex[j] = fVertex[j];
191 while((entry = (AliGenCocktailEntry*)next())) {
192 if (fUsePerEventRate && (gRandom->Rndm() > entry->Rate())) continue;
196 entry->SetFirst(lastpart);
198 entry->SetFirst((partArray->GetEntriesFast())+1);
201 // Handle case in which current generator needs collision geometry from previous generator
203 gen = entry->Generator();
204 if (gen->NeedsCollisionGeometry())
206 if (preventry && preventry->Generator()->ProvidesCollisionGeometry())
208 gen->SetCollisionGeometry(preventry->Generator()->CollisionGeometry());
210 Fatal("Generate()", "No Collision Geometry Provided");
213 entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
214 entry->Generator()->Generate();
215 entry->SetLast(partArray->GetEntriesFast());
220 // Select a generator randomly
223 Float_t p0 = gRandom->Rndm();
225 for (i = 0; i < fNGenerators; i++) {
226 if (p0 < fProb[i]) break;
229 entry = (AliGenCocktailEntry*) fEntries->At(i);
230 entry->SetFirst(lastpart);
231 gen = entry->Generator();
232 entry->Generator()->SetVertex(fVertex.At(0), fVertex.At(1), fVertex.At(2));
233 entry->Generator()->Generate();
234 entry->SetLast(partArray->GetEntriesFast());
237 for (Int_t k = lastpart; k < stack->GetNprimary(); k++) {
238 stack->Particle(k)->ProductionVertex(v);
240 eventVertex[2] *= sign;
241 v[3] = fItime; // ??? +=
242 stack->Particle(k)->SetProductionVertex(v);
243 stack->Particle(k)->Momentum(v);
245 stack->Particle(k)->SetMomentum(v);
248 ((AliGenEventHeader*) fHeader->GetHeaders()->Last())->SetPrimaryVertex(eventVertex);
250 lastpart = stack->GetNprimary();
254 fHeader->CalcNProduced();
257 fContainer->AddHeader(fHeader);
259 gAlice->SetGenEventHeader(fHeader);