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 #if !defined(__CINT__) || defined(__MAKECINT__)
8 #include <TStopwatch.h>
11 #include <TDatabasePDG.h>
12 #include <TParticle.h>
15 #include "AliGenerator.h"
17 #include "AliRunLoader.h"
20 #include "AliHeader.h"
21 #include "PYTHIA6/AliGenPythia.h"
22 #include "PYTHIA6/AliPythia.h"
25 Float_t EtaToTheta(Float_t arg);
26 void GetFinalDecayProducts(Int_t ind, AliStack & stack , TArrayI & ar);
28 void fastGen(Int_t nev = 1, char* filename = "galice.root")
30 AliPDG::AddParticlesToPdgDataBase();
31 TDatabasePDG::Instance();
36 AliRunLoader* rl = AliRunLoader::Open("galice.root","FASTRUN","recreate");
38 rl->SetCompressionLevel(2);
39 rl->SetNumberOfEventsPerFile(nev);
40 rl->LoadKinematics("RECREATE");
42 gAlice->SetRunLoader(rl);
46 AliStack* stack = rl->Stack();
49 AliHeader* header = rl->GetHeader();
51 // Create and Initialize Generator
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);
70 // Forbid some decays. Do it after gener->Init(0, because
71 // the initialization of the generator includes reading of the decay table.
73 AliPythia * py= AliPythia::Instance();
74 py->SetMDME(737,1,0); //forbid D*+->D+ + pi0
75 py->SetMDME(738,1,0);//forbid D*+->D+ + gamma
77 // Forbid all D0 decays except D0->K- pi+
78 for(Int_t d=747; d<=762; d++){
81 // decay 763 is D0->K- pi+
82 for(Int_t d=764; d<=807; d++){
92 for (Int_t iev = 0; iev < nev; iev++) {
94 cout <<"Event number "<< iev << endl;
98 rl->SetEventNumber(iev);
109 //-------------------------------------------------------------------------------------
112 // Selection of events with D*
114 stack->ConnectTree(rl->TreeK());
117 nprim = stack->GetNprimary();
119 for(Int_t ipart =0; ipart < nprim; ipart++){
120 TParticle * part = stack->Particle(ipart);
123 if (TMath::Abs(part->GetPdgCode())== 413) {
127 GetFinalDecayProducts(ipart,*stack,daughtersId);
129 Bool_t kineOK = kTRUE;
131 Double_t thetaMin = TMath::Pi()/4;
132 Double_t thetaMax = 3*TMath::Pi()/4;
134 for (Int_t id=1; id<=daughtersId[0]; id++) {
135 TParticle * daughter = stack->Particle(daughtersId[id]);
141 Double_t theta = daughter->Theta();
142 if (theta<thetaMin || theta>thetaMax) {
148 if (!kineOK) continue;
158 cout << "Number of particles " << nprim << endl;
159 cout << "Number of trials " << ntrial << endl;
162 header->SetNprimary(stack->GetNprimary());
163 header->SetNtrack(stack->GetNtrack());
166 stack->FinishEvent();
167 header->SetStack(stack);
169 rl->WriteKinematics("OVERWRITE");
179 rl->WriteHeader("OVERWRITE");
186 Float_t EtaToTheta(Float_t arg){
187 return (180./TMath::Pi())*2.*atan(exp(-arg));
191 void GetFinalDecayProducts(Int_t ind, AliStack & stack , TArrayI & ar){
193 // Recursive algorithm to get the final decay products of a particle
195 // ind is the index of the particle in the AliStack
196 // stack is the particle stack from the generator
197 // ar contains the indexes of the final decay products
198 // ar[0] is the number of final decay products
200 if (ind<0 || ind>stack.GetNtrack()) {
201 cerr << "Invalid index of the particle " << ind << endl;
204 if (ar.GetSize()==0) {
209 TParticle * part = stack.Particle(ind);
211 Int_t iFirstDaughter = part->GetFirstDaughter();
212 if( iFirstDaughter<0) {
213 // This particle is a final decay product, add its index to the array
215 if (ar.GetSize() <= ar[0]) ar.Set(ar.GetSize()+10); // resize if needed
220 Int_t iLastDaughter = part->GetLastDaughter();
222 for (Int_t id=iFirstDaughter; id<=iLastDaughter;id++) {
223 // Now search for final decay products of the daughters
224 GetFinalDecayProducts(id,stack,ar);