config-file to generate the geometry setup for 2012
[u/mrichter/AliRoot.git] / macros / g4menu.C
... / ...
CommitLineData
1// $Id$
2//
3// Root macro that opens a mini GUI for running aliroot with Geant4.
4//
5// To run aliroot with Geant4 using the g4menu.C:
6// aliroot
7// root [0] .x g4menu.C
8// --> First select "Geometry" to build geometry.root file
9// --> Then re-run aliroot and select "Run" button
10//
11// The Init button is kept for debugging purposes,
12// it itializes MonteCarlo but it does not itialize
13// completely ALICE framework. That's why to run simulation,
14// you have to re-run aliroot and select Run button.
15//
16// The menu enables to start Geant4 interactive session:
17// --> Select "Geant4UI" button and use Geant4 interactive commands;
18// To go back to Root UI, type exit.
19//
20// By I. Hrivnacova, IPN Orsay
21
22
23#include <iostream>
24
25void g4menu()
26{
27
28 // Load Geant4 libraries
29 if (!gInterpreter->IsLoaded("$ALICE/geant4_vmc/examples/macro/g4libs.C"))
30 gROOT->LoadMacro("$ALICE/geant4_vmc/examples/macro/g4libs.C");
31 gInterpreter->ProcessLine("g4libs()");
32
33 // Load ALICE Geant4 library
34 //cout << "Loading g4alice library ..." << endl;
35 //gSystem->Load("libg4alice");
36
37 // Menu
38 TControlBar* menu = new TControlBar("vertical","Alice Geant4 menu");
39
40 menu->AddButton("Geometry", "MakeGeometry()", "Generate Root geometry file");
41 menu->AddButton("Run G4", "RunG4Simulation()", "Process Alice run");
42 menu->AddButton("Run G4 batch", "RunG4Simulation(); >& g4.out", "Process Alice run");
43 menu->AddButton("Run G3", "RunG3Simulation()", "Process Alice run");
44 menu->AddButton("Run G3 batch", "RunG3Simulation(); >& g3.out", "Process Alice run");
45 menu->AddButton("Init", "Init();", "Initialize Alice for G4 simulation");
46 menu->AddButton("Init batch","Init(); >& g4init.out", "Initialize Alice for G4 simulation");
47 menu->AddButton("Geant4UI", "StartGeant4UI()","Go to Geant4 Interactive session");
48 menu->AddButton("AGDD", "GenerateAGDD()","Generate XML (AGDD) file with geometry description");
49 //menu->AddButton("GDML", "GenerateGDML()","Generate XML (GDML) file with geometry description");
50 menu->AddButton("Quit", "Quit()", "Quit aliroot");
51 gROOT->SaveContext();
52
53 cout << endl
54 << "**************************************************************" << endl
55 << " To run simulation:" << endl
56 << " First select <Geometry> to build geometry.root file." << endl
57 << " Then re-run aliroot and select <Run> button" << endl
58 << endl
59 << " The <Init> button is kept for debugging purposes," << endl
60 << " it itializes MonteCarlo but it does not itialize" << endl
61 << " completely ALICE framework. That's why to run simulation," << endl
62 << " you have to re-run aliroot and select Run button." << endl
63 << endl
64 << " The menu enables to start Geant4 interactive session:" << endl
65 << " Select <Geant4UI> button and use Geant4 interactive commands" << endl
66 << " To go back to Root UI, type exit." << endl
67 << "**************************************************************" << endl
68 << endl;
69
70 menu->Show();
71}
72
73void MakeGeometry()
74{
75 AliCDBManager* man = AliCDBManager::Instance();
76 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
77 man->SetRun(1);
78
79 // MC application initialization
80 TString configFileName = "$ALICE_ROOT/macros/g4ConfigGeometry.C";
81 gROOT->LoadMacro(configFileName.Data());
82 gInterpreter->ProcessLine(gAlice->GetConfigFunction());
83 gAlice->GetMCApp()->Init();
84
85 // Generate geometry file
86 //
87 gGeoManager->Export("geometry.root");
88
89 cout << endl
90 << "Geometry file geometry.root has been generated." << endl
91 << "You have to re-run aliroot and choose Run in g4menu." << endl;
92
93 exit(0);
94}
95
96
97void Init()
98{
99 AliCDBManager* man = AliCDBManager::Instance();
100 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
101 man->SetRun(0);
102
103 // MC application initialization
104 TString configFileName = "$ALICE_ROOT/macros/g4Config.C";
105 gROOT->LoadMacro(configFileName.Data());
106 gInterpreter->ProcessLine(gAlice->GetConfigFunction());
107 gAlice->GetMCApp()->Init();
108
109 ((TGeant4*)gMC)->ProcessGeantCommand("/mcDet/printMedia");
110
111 cout << endl
112 << "Only MonteCarlo initialization has been performed. " << endl
113 << "To run simulation you have to re-run aliroot and choose Run in g4menu." << endl;
114}
115
116
117void RunG4Simulation()
118{
119 AliSimulation sim("$ALICE_ROOT/macros/g4Config.C");
120 sim.SetMakeSDigits("");
121 sim.SetMakeDigits("");
122 //sim.SetMakeDigitsFromHits("ITS TPC");
123 //sim.SetMakeDigitsFromHits("ITS");
124 sim.SetMakeDigitsFromHits("");
125 sim.SetRunHLT("");
126 sim.SetNumberOfEvents(1000);
127 TStopwatch timer;
128 timer.Start();
129 sim.Run(1);
130 timer.Stop();
131 timer.Print();
132}
133
134void RunG3Simulation()
135{
136 AliSimulation sim("$ALICE_ROOT/macros/g3Config.C");
137 sim.SetMakeSDigits("");
138 sim.SetMakeDigits("");
139 //sim.SetMakeDigitsFromHits("ITS TPC");
140 //sim.SetMakeDigitsFromHits("ITS");
141 sim.SetMakeDigitsFromHits("");
142 sim.SetRunHLT("");
143 sim.SetNumberOfEvents(1000);
144 TStopwatch timer;
145 timer.Start();
146 sim.Run(1);
147 timer.Stop();
148 timer.Print();
149}
150
151void StartGeant4UI()
152{
153 if (gMC) {
154 // release Root terminal control
155
156 // go into non-raw term mode
157 Getlinem(kCleanUp, 0);
158
159 // add test if gMC is TGeant4
160 TGeant4* g4 = (TGeant4*)gMC;
161
162 g4->StartGeantUI();
163
164 // new Root prompt
165 Getlinem(kInit, ((TRint*)gROOT->GetApplication())->GetPrompt());
166 }
167 else {
168 cout << "Monte Carlo has not been yet created." << endl;
169 }
170}
171
172void GenerateAGDD()
173{
174 if (gMC) {
175 // release Root terminal control
176
177 // go into non-raw term mode
178 //Getlinem(kCleanUp, 0);
179
180 // add test if gMC is TGeant4
181 TGeant4* g4 = (TGeant4*)gMC;
182
183 g4->ProcessGeantCommand("/vgm/generateAGDD");
184
185 // new Root prompt
186 //Getlinem(kInit, ((TRint*)gROOT->GetApplication())->GetPrompt());
187 }
188 else {
189 cout << "Monte Carlo has not been yet created." << endl;
190 }
191}
192/*
193void GenerateGDML()
194{
195 if (gMC) {
196 // release Root terminal control
197
198 // go into non-raw term mode
199 //Getlinem(kCleanUp, 0);
200
201 // add test if gMC is TGeant4
202 TGeant4* g4 = (TGeant4*)gMC;
203
204 g4->ProcessGeantCommand("/vgm/generateGDML");
205
206 // new Root prompt
207 //Getlinem(kInit, ((TRint*)gROOT->GetApplication())->GetPrompt());
208 }
209 else {
210 cout << "Monte Carlo has not been yet created." << endl;
211 }
212}
213*/
214void Quit()
215{
216 delete AliRunLoader::Instance();
217 delete gAlice;
218
219 exit(0);
220}