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)
5 // To be able to compile, please add -I<ALIROOT_INSTALL_PATH>/include
7 #if !defined(__CINT__) || defined(__MAKECINT__)
10 #include <TStopwatch.h>
13 #include <TDatabasePDG.h>
14 #include <TParticle.h>
18 #include "AliGenerator.h"
20 #include "AliRunLoader.h"
23 #include "AliHeader.h"
24 #include "AliGenPythia.h"
25 #include "AliPythia.h"
28 Float_t EtaToTheta(Float_t arg);
29 void GetFinalDecayProducts(Int_t ind, AliStack & stack , TArrayI & ar);
31 void fastGen(Int_t nev = 1, const char* filename = "galice.root")
33 AliPDG::AddParticlesToPdgDataBase();
34 TDatabasePDG::Instance();
39 AliRunLoader* rl = AliRunLoader::Open("galice.root","FASTRUN","recreate");
41 rl->SetCompressionLevel(2);
42 rl->SetNumberOfEventsPerFile(nev);
43 rl->LoadKinematics("RECREATE");
45 gAlice->SetRunLoader(rl);
49 AliStack* stack = rl->Stack();
52 AliHeader* header = rl->GetHeader();
54 // Create and Initialize Generator
56 // Example of charm generation taken from Config_PythiaHeavyFlavours.C
57 AliGenPythia *gener = new AliGenPythia(-1);
58 gener->SetEnergyCMS(14000.);
59 gener->SetMomentumRange(0,999999);
60 gener->SetPhiRange(0., 360.);
61 gener->SetThetaRange(0.,180.);
62 // gener->SetProcess(kPyCharmppMNR); // Correct Pt distribution, wrong mult
63 gener->SetProcess(kPyMb); // Correct multiplicity, wrong Pt
64 gener->SetStrucFunc(kCTEQ4L);
65 gener->SetPtHard(2.1,-1.0);
66 gener->SetFeedDownHigherFamily(kFALSE);
67 gener->SetStack(stack);
73 // Forbid some decays. Do it after gener->Init(0, because
74 // the initialization of the generator includes reading of the decay table.
76 AliPythia * py= AliPythia::Instance();
77 py->SetMDME(737,1,0); //forbid D*+->D+ + pi0
78 py->SetMDME(738,1,0);//forbid D*+->D+ + gamma
80 // Forbid all D0 decays except D0->K- pi+
81 for(Int_t d=747; d<=762; d++){
84 // decay 763 is D0->K- pi+
85 for(Int_t d=764; d<=807; d++){
95 for (Int_t iev = 0; iev < nev; iev++) {
97 cout <<"Event number "<< iev << endl;
100 header->Reset(0,iev);
101 rl->SetEventNumber(iev);
112 //-------------------------------------------------------------------------------------
115 // Selection of events with D*
117 stack->ConnectTree(rl->TreeK());
120 nprim = stack->GetNprimary();
122 for(Int_t ipart =0; ipart < nprim; ipart++){
123 TParticle * part = stack->Particle(ipart);
126 if (TMath::Abs(part->GetPdgCode())== 413) {
130 GetFinalDecayProducts(ipart,*stack,daughtersId);
132 Bool_t kineOK = kTRUE;
134 Double_t thetaMin = TMath::Pi()/4;
135 Double_t thetaMax = 3*TMath::Pi()/4;
137 for (Int_t id=1; id<=daughtersId[0]; id++) {
138 TParticle * daughter = stack->Particle(daughtersId[id]);
144 Double_t theta = daughter->Theta();
145 if (theta<thetaMin || theta>thetaMax) {
151 if (!kineOK) continue;
161 cout << "Number of particles " << nprim << endl;
162 cout << "Number of trials " << ntrial << endl;
165 header->SetNprimary(stack->GetNprimary());
166 header->SetNtrack(stack->GetNtrack());
169 stack->FinishEvent();
170 header->SetStack(stack);
172 rl->WriteKinematics("OVERWRITE");
182 rl->WriteHeader("OVERWRITE");
189 Float_t EtaToTheta(Float_t arg){
190 return (180./TMath::Pi())*2.*atan(exp(-arg));
194 void GetFinalDecayProducts(Int_t ind, AliStack & stack , TArrayI & ar){
196 // Recursive algorithm to get the final decay products of a particle
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
203 if (ind<0 || ind>stack.GetNtrack()) {
204 cerr << "Invalid index of the particle " << ind << endl;
207 if (ar.GetSize()==0) {
212 TParticle * part = stack.Particle(ind);
214 Int_t iFirstDaughter = part->GetFirstDaughter();
215 if( iFirstDaughter<0) {
216 // This particle is a final decay product, add its index to the array
218 if (ar.GetSize() <= ar[0]) ar.Set(ar.GetSize()+10); // resize if needed
223 Int_t iLastDaughter = part->GetLastDaughter();
225 for (Int_t id=iFirstDaughter; id<=iLastDaughter;id++) {
226 // Now search for final decay products of the daughters
227 GetFinalDecayProducts(id,stack,ar);