]> git.uio.no Git - u/mrichter/AliRoot.git/blame - test/genkine/gen/fastGen.C
Ignoring the files produced by the tests
[u/mrichter/AliRoot.git] / test / genkine / gen / fastGen.C
CommitLineData
3928b038 1// Example: generation of kinematics tree with selected properties.
2// Below we select events containing the decays D* -> D0 pi, D0 -> K- pi+
3// inside the barrel part of the ALICE detector (45 < theta < 135)
4
5#if !defined(__CINT__) || defined(__MAKECINT__)
6#include <Riostream.h>
7#include <TH1F.h>
8#include <TStopwatch.h>
9#include <TDatime.h>
10#include <TRandom.h>
11#include <TDatabasePDG.h>
12#include <TParticle.h>
13#include <TArrayI.h>
14
15#include "AliGenerator.h"
16#include "AliPDG.h"
17#include "AliRunLoader.h"
18#include "AliRun.h"
19#include "AliStack.h"
20#include "AliHeader.h"
21#include "PYTHIA6/AliGenPythia.h"
22#include "PYTHIA6/AliPythia.h"
23#endif
24
25Float_t EtaToTheta(Float_t arg);
26void GetFinalDecayProducts(Int_t ind, AliStack & stack , TArrayI & ar);
27
28void fastGen(Int_t nev = 1, char* filename = "galice.root")
29{
30 AliPDG::AddParticlesToPdgDataBase();
31 TDatabasePDG* pPdg = TDatabasePDG::Instance();
32
33
34
35 // Run loader
36 AliRunLoader* rl = AliRunLoader::Open("galice.root","FASTRUN","recreate");
37
38 rl->SetCompressionLevel(2);
39 rl->SetNumberOfEventsPerFile(nev);
40 rl->LoadKinematics("RECREATE");
41 rl->MakeTree("E");
42 gAlice->SetRunLoader(rl);
43
44 // Create stack
45 rl->MakeStack();
46 AliStack* stack = rl->Stack();
47
48 // Header
49 AliHeader* header = rl->GetHeader();
50
51 // Create and Initialize Generator
52
53 // Example of charm generation taken from Config_PythiaHeavyFlavours.C
54 AliGenPythia *gener = new AliGenPythia(-1);
55 gener->SetEnergyCMS(14000.);
56 gener->SetMomentumRange(0,999999);
57 gener->SetPhiRange(0., 360.);
58 gener->SetThetaRange(0.,180.);
59 // gener->SetProcess(kPyCharmppMNR); // Correct Pt distribution, wrong mult
60 gener->SetProcess(kPyMb); // Correct multiplicity, wrong Pt
61 gener->SetStrucFunc(kCTEQ4L);
62 gener->SetPtHard(2.1,-1.0);
63 gener->SetFeedDownHigherFamily(kFALSE);
64 gener->SetStack(stack);
65 gener->Init();
66
67 // Go to galice.root
68 rl->CdGAFile();
69
70 // Forbid some decays. Do it after gener->Init(0, because
71 // the initialization of the generator includes reading of the decay table.
72
73 AliPythia * py= AliPythia::Instance();
74 py->SetMDME(731,1,0); //forbid D*+->D+ + pi0
75 py->SetMDME(732,1,0);//forbid D*+->D+ + gamma
76
77 // Forbid all D0 decays except D0->K- pi+
78 for(Int_t d=741; d<=756; d++){
79 py->SetMDME(d,1,0);
80 }
81 // decay 757 is D0->K- pi+
82 for(Int_t d=758; d<=801; d++){
83 py->SetMDME(d,1,0);
84 }
85
86 //
87 // Event Loop
88 //
89
90 TStopwatch timer;
91 timer.Start();
92 for (Int_t iev = 0; iev < nev; iev++) {
93
94 cout <<"Event number "<< iev << endl;
95
96 // Initialize event
97 header->Reset(0,iev);
98 rl->SetEventNumber(iev);
99 stack->Reset();
100 rl->MakeTree("K");
101
102 // Generate event
103 Int_t nprim = 0;
104 Int_t ntrial = 0;
105 Int_t minmult = 1000;
106 Int_t ndstar = 0;
107
108
109
110 //-------------------------------------------------------------------------------------
111
112 while(!ndstar) {
113 // Selection of events with multiplicity
114 // bigger than "minmult"
115 stack->Reset();
116 gener->Generate();
117 ntrial++;
118 nprim = stack->GetNprimary();
119
120 for(Int_t ipart =0; ipart < nprim; ipart++){
121 TParticle * part = stack->Particle(ipart);
122 if(part) {
123
124 if (TMath::Abs(part->GetPdgCode())== 413) {
125
126 TArrayI daughtersId;
127
128 GetFinalDecayProducts(ipart,*stack,daughtersId);
129
130 Bool_t kineOK = kTRUE;
131
132 Double_t thetaMin = TMath::Pi()/4;
133 Double_t thetaMax = 3*TMath::Pi()/4;
134
135 for (Int_t id=1; id<=daughtersId[0]; id++) {
136 TParticle * daughter = stack->Particle(daughtersId[id]);
137 if (!daughter) {
138 kineOK = kFALSE;
139 break;
140 }
141
142 Double_t theta = daughter->Theta();
143 if (theta<thetaMin || theta>thetaMax) {
144 kineOK = kFALSE;
145 break;
146 }
147 }
148
149 if (!kineOK) continue;
150
151 part->Print();
152 ndstar++;
153
154 }
155 }
156 }
157 }
158
159 cout << "Number of particles " << nprim << endl;
160 cout << "Number of trials " << ntrial << endl;
161
162 // Finish event
163 header->SetNprimary(stack->GetNprimary());
164 header->SetNtrack(stack->GetNtrack());
165
166 // I/O
167 stack->FinishEvent();
168 header->SetStack(stack);
169 rl->TreeE()->Fill();
170 rl->WriteKinematics("OVERWRITE");
171
172 } // event loop
173 timer.Stop();
174 timer.Print();
175
176 // Termination
177 // Generator
178 gener->FinishRun();
179 // Stack
180 stack->FinishRun();
181 // Write file
182 rl->WriteHeader("OVERWRITE");
183 gener->Write();
184 rl->Write();
185}
186
187
188
189Float_t EtaToTheta(Float_t arg){
190 return (180./TMath::Pi())*2.*atan(exp(-arg));
191}
192
193
194void GetFinalDecayProducts(Int_t ind, AliStack & stack , TArrayI & ar){
195
196 // Recursive algorithm to get the final decay products of a particle
197 //
198 // ind is the index of the particle in the AliStack
199 // stack is the particle stack from the generator
200 // ar contains the indexes of the final decay products
201 // ar[0] is the number of final decay products
202
203 if (ind<0 || ind>stack.GetNtrack()) {
204 cerr << "Invalid index of the particle " << ind << endl;
205 return;
206 }
207 if (ar.GetSize()==0) {
208 ar.Set(10);
209 ar[0] = 0;
210 }
211
212 TParticle * part = stack.Particle(ind);
213
214 Int_t iFirstDaughter = part->GetFirstDaughter();
215 if( iFirstDaughter<0) {
216 // This particle is a final decay product, add its index to the array
217 ar[0]++;
218 if (ar.GetSize() <= ar[0]) ar.Set(ar.GetSize()+10); // resize if needed
219 ar[ar[0]] = ind;
220 return;
221 }
222
223 Int_t iLastDaughter = part->GetLastDaughter();
224
225 for (Int_t id=iFirstDaughter; id<=iLastDaughter;id++) {
226 // Now search for final decay products of the daughters
227 GetFinalDecayProducts(id,stack,ar);
228 }
229}