New macros to run fast simulation
[u/mrichter/AliRoot.git] / MUON / fastMUONGen.C
CommitLineData
9c090011 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id: */
17
18//H. Woehri, A. De Falco, INFN Cagliari, April 2007
19//an example how to use the AliGenMUONCocktailpp generator
20//without GEANT simulation of the detector
21//The macro switches on all decay modes for the resonances,
22//while for the minimum bias Pythia event we additionally
23//switch on the muonic decays of pions and Kaons
24//Its outcome can be further processed by the macro
25//"fastMUONSim.C
26
27#if !defined(__CINT__) || defined(__MAKECINT__)
28#include "AliGenerator.h"
29#include "AliRunLoader.h"
30#include "AliRun.h"
31#include "AliHeader.h"
32#include "AliStack.h"
33#include "AliGenCocktail.h"
34#include "AliDecayerPythia.h"
35#include "AliPDG.h"
36#include "AliGenMUONCocktailpp.h"
37
38#include "TParticle.h"
39#endif
40
41AliGenerator* CreateGeneratorMC(Int_t mult);
42Int_t SetupOutputDirectory();
43
44//the third argument "mult" allows to select at a "pre-trigger" level
45//events with "mult" muons in the MUON detector's phase space
46//window, which is defined in the method "CreateGeneratorMC(Int_t mult)"
47//note that in this routine also a cut on the muon's origin
48//should be placed in order not to trigger on muons from pi/K decays
49//that were decayed by Pythia way inside the absorber or in the muon
50//spectrometer itself
51void fastMUONGen(Int_t nev = 1, char* filename = "galice.root", Int_t mult = 2)
52{
53 Int_t runNumber = SetupOutputDirectory();
54 gAlice->SetRunNumber(runNumber);
55 printf("\n\n\n\nsetting run number to %d\n\n\n\n", runNumber);
56
57 // Update data base
58 AliPDG::AddParticlesToPdgDataBase();
59 //
60 AliRunLoader* rl = AliRunLoader::Open(filename,"FASTRUN","recreate");
61 rl->SetCompressionLevel(2);
62 rl->SetNumberOfEventsPerFile(10000);
63 rl->LoadKinematics("RECREATE");
64 rl->MakeTree("E");
65 gAlice->SetRunLoader(rl);
66 //
67 rl->MakeStack();
68 AliStack* stack = rl->Stack();
69 AliHeader* header = rl->GetHeader();
70 //
71 // Create and Initialize Generator
72 AliGenerator *gener = CreateGeneratorMC(mult);
73 gener->SetStack(stack);
74 gener->Init();
75 //
76 for (int iev = 0; iev < nev; iev++) {
77
78 if(iev%1000 == 0) printf("Event %d\n", iev);
79 // Initialize event
80 header->Reset(0,iev);
81 rl->SetEventNumber(iev);
82 stack->Reset();
83 rl->MakeTree("K");
84
85 gener->Generate();
86/*
87 // Printing
88 Int_t npart = stack->GetNprimary();
89 for (Int_t part=0; part<npart; part++) {
90 TParticle *MPart = stack->Particle(part);
91 Int_t mpart = MPart->GetPdgCode();
92 printf("Particle %5d %5d %5d\n", part, mpart, MPart->GetFirstMother());
93 }
94*/
95
96 // Finish event
97 header->SetNprimary(stack->GetNprimary());
98 header->SetNtrack(stack->GetNtrack());
99 // I/O
100 //
101 stack->FinishEvent();
102 header->SetStack(stack);
103 rl->TreeE()->Fill();
104 rl->WriteKinematics("OVERWRITE");
105 } // event loop
106
107 gener->FinishRun();
108 stack->FinishRun();
109 rl->WriteHeader("OVERWRITE");
110 gener->Write();
111 rl->Write();
112}
113//===============================================
114AliGenerator* CreateGeneratorMC(Int_t mult)
115{
116 AliGenMUONCocktailpp* gener = new AliGenMUONCocktailpp();
117 gener->SetPtRange(0.,100.);
118 gener->SetYRange(-4.,-2.4);
119 gener->SetPhiRange(0., 360.);
120 gener->SetMuonMultiplicity(mult);
121 gener->SetMuonPtCut(0.5);
122 gener->SetMuonThetaRange(171.,178.);
123 gener->SetOrigin(0.,0.,0.);
124 gener->SetSigma(0.,0.,5.);
125 gener->SetVertexSmear(kPerEvent);
126 //for resonances: "kAll" all decay modes are openend
127 gener->SetDecayModeResonance(kAll);
128 //for MC Pythia events: all decays, including muonic decays from pion and Kaons are opened
129 gener->SetDecayModePythia(kAllMuonic);
130 gener->SetMuonOriginCut(-130.); //prevent the trigger muon(s) from decaying after 130 cm
131 AliDecayerPythia* decayer = new AliDecayerPythia();
132 gener->SetDecayer(decayer);
133 return gener;
134}
135//===============================================
136Int_t SetupOutputDirectory(){
137
138 //Setting up the name for the output directory:
139 static Int_t sseed = 0; // Set 0 to use the current time
140 gRandom->SetSeed(sseed);
141 UInt_t theSeed = gRandom->GetSeed();
142 Int_t labIndex = 5; //1 subatech, 2 clermont, 3 Torino, 4 Orsay
143 // 5 Cagliari, etc...
144 Int_t runNumber = (theSeed%100000000 + 100000000*labIndex);
145
146 Char_t name[100];
147 sprintf(name, "touch run_%d", runNumber);
148 gSystem->Exec(name);
149
150 return runNumber;
151}