-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
214 lines (168 loc) · 6.76 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file persistency/gdml/G01/load_gdml.cc
/// \brief Main program of the persistency/gdml/G01 example
//
//
//
//
// --------------------------------------------------------------
// GEANT 4 - load_gdml
//
// --------------------------------------------------------------
#include <vector>
#include "G4Types.hh"
#include "G4RunManagerFactory.hh"
#include "G4UImanager.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4TransportationManager.hh"
#include "G01PrimaryGeneratorAction.hh"
#include "G01ActionInitialization.hh"
#include "G01DetectorConstruction.hh"
#include "SteppingAction.hh"
#include "EventAction.hh"
#include "RunAction.hh"
#include "FTFP_BERT.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"
#include "G4GDMLParser.hh"
void print_aux(const G4GDMLAuxListType* auxInfoList, G4String prepend="|")
{
for(std::vector<G4GDMLAuxStructType>::const_iterator
iaux = auxInfoList->begin(); iaux != auxInfoList->end(); iaux++ )
{
G4String str=iaux->type;
G4String val=iaux->value;
G4String unit=iaux->unit;
G4cout << prepend << str << " : " << val << " " << unit << G4endl;
if (iaux->auxList) print_aux(iaux->auxList, prepend + "|");
}
return;
}
// --------------------------------------------------------------
int main(int argc,char** argv)
{
G4cout << G4endl;
G4cout << "Usage: load_gdml <intput_gdml_file:mandatory>"
<< " <output_gdml_file:optional>" << G4endl;
G4cout << G4endl;
if (argc<2)
{
G4cout << "Error! Mandatory input file is not specified!" << G4endl;
G4cout << G4endl;
return -1;
}
G4GDMLParser parser;
// Uncomment the following if wish to avoid names stripping
// parser.SetStripFlag(false);
parser.SetOverlapCheck(true);
parser.Read(argv[1]);
if (argc>4)
{
G4cout << "Error! Too many arguments!" << G4endl;
G4cout << G4endl;
return -1;
}
auto* runManager = G4RunManagerFactory::CreateRunManager();
// Mandatory user initialization classes
if(parser.GetVolume ("IRON")==NULL)
G4cout<<"Error finding IRON_1"<<G4endl;
runManager->SetUserInitialization(new G01DetectorConstruction(parser.GetWorldVolume()));
runManager->SetUserInitialization(new FTFP_BERT);
runManager->SetUserInitialization(new G01ActionInitialization(argc)); //argc will choose the appropriate particle gun
runManager->Initialize();
// Initialize visualization
G4VisManager* visManager = new G4VisExecutive;
visManager->Initialize();
// Get the pointer to the User Interface manager
G4UImanager* UImanager = G4UImanager::GetUIpointer();
///////////////////////////////////////////////////////////////////////
//
// Example how to retrieve Auxiliary Information
//
G4cout << std::endl;
const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
std::vector<G4LogicalVolume*>::const_iterator lvciter;
for( lvciter = lvs->begin(); lvciter != lvs->end(); lvciter++ )
{
G4GDMLAuxListType auxInfo = parser.GetVolumeAuxiliaryInformation(*lvciter);
if (auxInfo.size()>0)
G4cout << "Auxiliary Information is found for Logical Volume : "
<< (*lvciter)->GetName() << G4endl;
print_aux(&auxInfo);
}
// now the 'global' auxiliary info
G4cout << std::endl;
G4cout << "Global auxiliary info:" << std::endl;
G4cout << std::endl;
print_aux(parser.GetAuxList());
G4cout << std::endl;
//
// End of Auxiliary Information block
//
////////////////////////////////////////////////////////////////////////
runManager->BeamOn(0);
// example of writing out
// if (argc>=3)
// {
// /*
// G4GDMLAuxStructType mysubaux = {"mysubtype", "mysubvalue", "mysubunit", 0};
// G4GDMLAuxListType* myauxlist = new G4GDMLAuxListType();
// myauxlist->push_back(mysubaux);
// G4GDMLAuxStructType myaux = {"mytype", "myvalue", "myunit", myauxlist};
// parser.AddAuxiliary(myaux);
// // example of setting auxiliary info for world volume
// // (can be set for any volume)
// G4GDMLAuxStructType mylocalaux = {"sometype", "somevalue", "someunit", 0};
// parser.AddVolumeAuxiliary(mylocalaux,
// G4TransportationManager::GetTransportationManager()
// ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
// */
// parser.SetRegionExport(true);
// // parser.SetEnergyCutsExport(true);
// // parser.SetOutputFileOverwrite(true);
// parser.Write(argv[2], G4TransportationManager::GetTransportationManager()
// ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
// }
if (argc==3) // batch mode
{
G4String command = "/control/execute ";
G4String fileName = argv[2];
UImanager->ApplyCommand(command+fileName);
}
else // interactive mode
{
G4UIExecutive* ui = new G4UIExecutive(argc, argv);
UImanager->ApplyCommand("vis/viewer/set/autorefresh True");
UImanager->ApplyCommand("vis/scene/add/trajectories smooth");
UImanager->ApplyCommand("/control/execute vis.mac");
ui->SessionStart();
delete ui;
}
delete visManager;
delete runManager;
return 0;
}