-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolidCapillary.cc
More file actions
320 lines (256 loc) · 9.55 KB
/
SolidCapillary.cc
File metadata and controls
320 lines (256 loc) · 9.55 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
// $Id: exampleN06.cc,v 1.18 2010-10-23 19:33:55 gum Exp $
// GEANT4 tag $Name: not supported by cvs2svn $
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//
// Description: Test of Continuous Process G4Cerenkov
// and RestDiscrete Process G4Scintillation
// -- Generation Cerenkov Photons --
// -- Generation Scintillation Photons --
// -- Transport of optical Photons --
// Version: 5.0
// Created: 1996-04-30
// Author: Juliet Armstrong
// mail: gum@triumf.ca
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include "TString.h"
#include "TRandom3.h"
#include "TCint.h"
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4PhysListFactory.hh"
#include "G4EmUserPhysics.hh"
#include "G4EmStandardPhysics.hh"
#include "G4VModularPhysicsList.hh"
#include "QGSP_BERT.hh"
#include "PrimaryGeneratorAction.hh"
#include "DetectorConstruction.hh"
#include "RunAction.hh"
#include "TrackingAction.hh"
#include "SteppingAction.hh"
#include "EventAction.hh"
#include "SteppingVerbose.hh"
#include "CreateTree.hh"
#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif
#ifdef G4UI_USE
#include "G4UIExecutive.hh"
#endif
using namespace CLHEP;
long int CreateSeed();
int main(int argc,char** argv)
{
if (argc != 3 && argc != 2)
{
cout << "Syntax for exec: crystal <configuration file> <output file>" << endl;
cout << "Syntax for viz: crystal <configuration file>" << endl;
return 0;
}
string file;
string filename;
TFile* outfile = NULL;
if(argc == 3)
{
cout << "Starting exec mode..." << endl;
file = argv[2];
filename = file + ".root";
G4cout << "Writing data to file '" << filename << "' ..." << G4endl;
outfile = new TFile((TString)filename,"RECREATE");
outfile -> cd();
}
if (argc == 2)
{
cout<<"Starting viz mode..."<<endl;
}
cout<<"=====> C O N F I G U R A T I O N <====\n"<<endl;
G4cout << "Configuration file: '" << argv[1] << "'" << G4endl;
ConfigFile config(argv[1]);
// Seed the random number generator manually
//
G4long myseed = config.read<long int>("seed");
if( myseed == -1 )
{
G4cout << "Creating random seed..." << G4endl;
myseed = CreateSeed();
}
G4cout << "Random seed : " << myseed << G4endl;
CLHEP::HepRandom::setTheSeed(myseed);
// Create output tree
//
CreateTree* mytree = new CreateTree ("tree");
// Get runtime options
//
G4int printModulo = config.read<int> ("printModulo");
G4int switchOnScintillation = config.read<int> ("switchOnScintillation");
G4int switchOnCerenkov = config.read<int> ("switchOnCerenkov");
G4int propagateScintillation = config.read<int> ("propagateScintillation");
G4int propagateCerenkov = config.read<int> ("propagateCerenkov");
// User Verbose output class
//
G4VSteppingVerbose* verbosity = new SteppingVerbose;
G4VSteppingVerbose::SetInstance(verbosity);
// Run manager
//
G4RunManager* runManager = new G4RunManager;
//Physics list defined using PhysListFactory
//
std::string physName("");
G4PhysListFactory factory;
const std::vector<G4String>& names = factory.AvailablePhysLists();
for(unsigned n = 0; n != names.size(); n++)
G4cout << "PhysicsList: " << names[n] << G4endl;
if( physName == "")
{
char* path = getenv("PHYSLIST");
if( path ) physName = G4String(path);
}
if ( physName == "" || factory.IsReferencePhysList(physName))
{
//physName = "FTFP_BERT";
physName = "FTFP_BERT_EMV"; // less precise, but supposed to be faster
// it might be the one used by CMS
}
std::cout << "Using physics list: " << physName << std::endl;
// UserInitialization classes - mandatory
//
G4cout << ">>> Define physics list::begin <<<" << G4endl;
G4VModularPhysicsList* physics = factory.GetReferencePhysList(physName);
physics->RegisterPhysics(new G4EmUserPhysics(switchOnScintillation,switchOnCerenkov));
runManager-> SetUserInitialization(physics);
G4cout << ">>> Define physics list::end <<<" << G4endl;
G4cout << ">>> Define DetectorConstruction::begin <<<" << G4endl;
DetectorConstruction* detector = new DetectorConstruction(argv[1]);
runManager-> SetUserInitialization(detector);
G4cout << ">>> Define DetectorConstruction::end <<<" << G4endl;
G4cout << ">>> Define PrimaryGeneratorAction::begin <<<" << G4endl;
G4double fibre_length = config.read<double> ("fibre_length");
G4double source_dist = config.read<double> ("source_dist");
G4double z_0 = 0.5*fibre_length - source_dist;
G4VUserPrimaryGeneratorAction* gen_action = new PrimaryGeneratorAction(z_0);
runManager->SetUserAction(gen_action);
G4cout << ">>> Define PrimaryGeneratorAction::end <<<" << G4endl;
// UserAction classes
//
G4cout << ">>> Define RunAction::begin <<<" << G4endl;
G4UserRunAction* run_action = new RunAction;
runManager->SetUserAction(run_action);
G4cout << ">>> Define RunAction::end <<<" << G4endl;
G4cout << ">>> Define EventAction::begin <<<" << G4endl;
G4UserEventAction* event_action = new EventAction(printModulo);
runManager->SetUserAction(event_action);
G4cout << ">>> Define EventAction::end <<<" << G4endl;
G4cout << ">>> Define TrackingAction::begin <<<" << G4endl;
TrackingAction* tracking_action = new TrackingAction;
runManager->SetUserAction(tracking_action);
G4cout << ">>> Define TrackingAction::end <<<" << G4endl;
G4cout << ">>> Define SteppingAction::begin <<<" << G4endl;
SteppingAction* stepping_action = new SteppingAction(detector,propagateScintillation,propagateCerenkov);
runManager->SetUserAction(stepping_action);
G4cout << ">>> Define SteppingAction::end <<<" << G4endl;
string gps_instructions_file = "" ;
if (argc == 2) // Define UI session for interactive mode
{
// Initialize G4 kernel
//
runManager -> Initialize();
#ifdef G4VIS_USE
G4VisManager* visManager = new G4VisExecutive;
visManager -> Initialize();
#endif
G4UImanager* UImanager = G4UImanager::GetUIpointer();
#ifdef G4UI_USE
G4UIExecutive * ui = new G4UIExecutive(argc,argv);
#ifdef G4VIS_USE
UImanager -> ApplyCommand("/control/execute vis.mac");
#endif
ui -> SessionStart();
delete ui;
#endif
#ifdef G4VIS_USE
delete visManager;
#endif
}
else
{
runManager -> Initialize();
G4UImanager* UImanager = G4UImanager::GetUIpointer();
config.readInto (gps_instructions_file, "gps_instructions_file") ;
UImanager -> ApplyCommand("/control/execute " + gps_instructions_file);
}
//
// Job termination
// Free the store: user actions, physics_list and detector_description are
// owned and deleted by the run manager, so they should not
// be deleted in the main() program !
delete runManager;
delete verbosity;
if(argc == 3)
{
G4cout << "Writing tree to file " << filename << " ..." << G4endl;
mytree->Write (outfile) ;
outfile->Close () ;
}
return 0;
}
long int CreateSeed()
{
TRandom3 rangen;
long int sec = time(0);
G4cout << "Time : " << sec << G4endl;
sec += getpid();
G4cout << "PID : " << getpid() << G4endl;
FILE* fp = fopen ("/proc/uptime", "r");
int upsecs = 0;
if( fp != NULL )
{
char buf[BUFSIZ];
char *b = fgets(buf,BUFSIZ,fp);
if( b == buf )
{
/* The following sscanf must use the C locale. */
setlocale(LC_NUMERIC, "C");
setlocale(LC_NUMERIC, "");
}
fclose(fp);
}
G4cout << "Upsecs: " << upsecs << G4endl;
sec += upsecs;
G4cout << "Seed for srand: " << sec << G4endl;
srand(sec);
rangen.SetSeed(rand());
long int seed = round(1000000*rangen.Uniform());
return seed;
}